diff --git a/.gitmodules b/.gitmodules index 0dcbd0c8..f3ef8bbd 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,7 @@ [submodule "extern/SDL"] path = extern/SDL url = https://github.com/libsdl-org/SDL.git + branch = release-2.28.x [submodule "extern/libsndfile"] path = extern/libsndfile url = https://github.com/libsndfile/libsndfile.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 3e2f5ee5..a5e91fb0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,12 +54,34 @@ else() set(WITH_JACK_DEFAULT OFF) endif() +set(WITH_RENDER_SDL_DEFAULT ON) +if (APPLE) + set(WITH_RENDER_OPENGL_DEFAULT OFF) +else() + set(WITH_RENDER_OPENGL_DEFAULT ON) +endif() +if (WIN32) + set(WITH_RENDER_DX11_DEFAULT ON) +else() + set(WITH_RENDER_DX11_DEFAULT OFF) +endif() + +if (ANDROID) + set(USE_GLES_DEFAULT ON) +else() + set(USE_GLES_DEFAULT OFF) +endif() + option(BUILD_GUI "Build the tracker (disable to build only a headless player)" ${BUILD_GUI_DEFAULT}) option(USE_RTMIDI "Build with MIDI support using RtMidi." ${USE_RTMIDI_DEFAULT}) option(USE_SDL2 "Build with SDL2. Required to build with GUI." ${USE_SDL2_DEFAULT}) option(USE_SNDFILE "Build with libsndfile. Required in order to work with audio files." ${USE_SNDFILE_DEFAULT}) option(USE_BACKWARD "Use backward-cpp to print a backtrace on crash/abort." ${USE_BACKWARD_DEFAULT}) option(WITH_JACK "Whether to build with JACK support. Auto-detects if JACK is available" ${WITH_JACK_DEFAULT}) +option(WITH_RENDER_SDL "Whether to build with the SDL_Renderer render backend." ${WITH_RENDER_SDL_DEFAULT}) +option(WITH_RENDER_OPENGL "Whether to build with the OpenGL render backend." ${WITH_RENDER_OPENGL_DEFAULT}) +option(WITH_RENDER_DX11 "Whether to build with the DirectX 11 render backend." ${WITH_RENDER_DX11_DEFAULT}) +option(USE_GLES "Use OpenGL ES for the OpenGL render backend." ${USE_GLES_DEFAULT}) option(SYSTEM_FFTW "Use a system-installed version of FFTW instead of the vendored one" OFF) option(SYSTEM_FMT "Use a system-installed version of fmt instead of the vendored one" OFF) option(SYSTEM_LIBSNDFILE "Use a system-installed version of libsndfile instead of the vendored one" OFF) @@ -92,12 +114,19 @@ set(DEPENDENCIES_LIBRARY_DIRS "") set(DEPENDENCIES_LINK_OPTIONS "") set(DEPENDENCIES_LEGACY_LDFLAGS "") -if (BUILD_GUI) +if (BUILD_GUI AND WITH_RENDER_SDL) set(SYSTEM_SDL_MIN_VER 2.0.18) else() set(SYSTEM_SDL_MIN_VER 2.0.0) endif() +if (WIN32) + # support Windows XP + if (SUPPORT_XP) + add_compile_definitions("_WIN32_WINNT=0x0501") + endif() +endif() + list(APPEND DEPENDENCIES_INCLUDE_DIRS "extern/SAASound/include") list(APPEND DEPENDENCIES_INCLUDE_DIRS "extern/vgsound_emu-modified") @@ -278,6 +307,12 @@ else() endif() endif() +if (BUILD_GUI) + if (NOT WITH_RENDER_SDL AND NOT WITH_RENDER_OPENGL AND NOT WITH_RENDER_DX11) + message(FATAL_ERROR "No render backends selected!") + endif() +endif() + set(AUDIO_SOURCES src/audio/abstract.cpp src/audio/midi.cpp @@ -580,13 +615,15 @@ extern/imgui_patched/imgui.cpp extern/imgui_patched/imgui_draw.cpp extern/imgui_patched/imgui_tables.cpp extern/imgui_patched/imgui_widgets.cpp -extern/imgui_patched/backends/imgui_impl_sdlrenderer.cpp -extern/imgui_patched/backends/imgui_impl_sdl.cpp +extern/imgui_patched/backends/imgui_impl_sdl2.cpp extern/imgui_patched/misc/cpp/imgui_stdlib.cpp extern/igfd/ImGuiFileDialog.cpp src/gui/plot_nolerp.cpp +src/gui/render.cpp +src/gui/render/abstract.cpp + src/gui/font_exo.cpp src/gui/font_liberationSans.cpp src/gui/font_mononoki.cpp @@ -675,6 +712,47 @@ if (APPLE) list(APPEND GUI_SOURCES extern/nfd-modified/src/nfd_cocoa.mm) endif() +if (WITH_RENDER_SDL) + list(APPEND GUI_SOURCES src/gui/render/renderSDL.cpp) + list(APPEND GUI_SOURCES extern/imgui_patched/backends/imgui_impl_sdlrenderer2.cpp) + list(APPEND DEPENDENCIES_DEFINES HAVE_RENDER_SDL) + message(STATUS "UI render backend: SDL_Renderer") +endif() + +if (WITH_RENDER_OPENGL) + list(APPEND GUI_SOURCES src/gui/render/renderGL.cpp) + list(APPEND GUI_SOURCES extern/imgui_patched/backends/imgui_impl_opengl3.cpp) + list(APPEND DEPENDENCIES_DEFINES HAVE_RENDER_GL) + if (USE_GLES) + list(APPEND DEPENDENCIES_DEFINES USE_GLES) + list(APPEND DEPENDENCIES_DEFINES IMGUI_IMPL_OPENGL_ES2) + endif() + if (WIN32) + list(APPEND DEPENDENCIES_LIBRARIES opengl32) + elseif(USE_GLES) + list(APPEND DEPENDENCIES_LIBRARIES GLESv2) + else() + list(APPEND DEPENDENCIES_LIBRARIES GL) + endif() + message(STATUS "UI render backend: OpenGL") +endif() + +if (WITH_RENDER_DX11) + if (WIN32) + if (SUPPORT_XP) + message(FATAL_ERROR "SUPPORT_XP is on. cannot enable DirectX 11 backend.") + else() + list(APPEND GUI_SOURCES src/gui/render/renderDX11.cpp) + list(APPEND GUI_SOURCES extern/imgui_patched/backends/imgui_impl_dx11.cpp) + list(APPEND DEPENDENCIES_DEFINES HAVE_RENDER_DX11) + list(APPEND DEPENDENCIES_LIBRARIES d3d11) + message(STATUS "UI render backend: DirectX 11") + endif() + else() + message(FATAL_ERROR "DirectX 11 render backend only for Windows!") + endif() +endif() + if (NOT WIN32 AND NOT APPLE) CHECK_INCLUDE_FILE(sys/io.h SYS_IO_FOUND) CHECK_INCLUDE_FILE(linux/input.h LINUX_INPUT_FOUND) @@ -746,10 +824,6 @@ if (WIN32) if (NOT MSVC) list(APPEND DEPENDENCIES_LIBRARIES -static) endif() - # support Windows XP - if (SUPPORT_XP) - list(APPEND DEPENDENCIES_DEFINES "_WIN32_WINNT=0x0501") - endif() elseif (APPLE) find_library(COCOA Cocoa REQUIRED) list(APPEND DEPENDENCIES_LIBRARIES ${COCOA}) @@ -823,7 +897,8 @@ if (NOT ANDROID OR TERMUX) install(TARGETS furnace RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) install(FILES res/furnace.desktop DESTINATION ${CMAKE_INSTALL_DATADIR}/applications) install(FILES res/furnace.appdata.xml DESTINATION ${CMAKE_INSTALL_DATADIR}/metainfo) - install(DIRECTORY papers DESTINATION ${CMAKE_INSTALL_DOCDIR}) + install(DIRECTORY doc DESTINATION ${CMAKE_INSTALL_DOCDIR}) + install(DIRECTORY papers DESTINATION ${CMAKE_INSTALL_DOCDIR}/other) install(FILES LICENSE DESTINATION ${CMAKE_INSTALL_DATADIR}/licenses/furnace) if (WITH_DEMOS) install(DIRECTORY demos DESTINATION ${CMAKE_INSTALL_DATADIR}/furnace) diff --git a/README.md b/README.md index 7f2a34cf..37371239 100644 --- a/README.md +++ b/README.md @@ -119,8 +119,8 @@ check out the [Releases](https://github.com/tildearrow/furnace/releases) page. a --- # quick references -- **discussion**: see the [Discussions](https://github.com/tildearrow/furnace/discussions) section, or the [official Discord server](https://discord.gg/EfrwT2wq7z). -- **help**: check out the [documentation](papers/doc/README.md). it's incomplete, but has details on effects. +- **discussion**: see the [Discussions](https://github.com/tildearrow/furnace/discussions) section, the [official Revolt](https://rvlt.gg/GRPS6tmc) or the [official Discord server](https://discord.gg/EfrwT2wq7z). +- **help**: check out the [documentation](doc/README.md). it's incomplete though. ## packages @@ -301,7 +301,7 @@ you may need to log out and/or reboot after doing this. > where's the manual? -see [papers/](papers/doc/README.md). it's kind of incomplete, but at least the sound chips section is there. +see [doc/](doc/README.md). it's kind of incomplete though. > is there a tutorial? diff --git a/TODO.md b/TODO.md index 0b7f1cd9..20c54eb9 100644 --- a/TODO.md +++ b/TODO.md @@ -1,16 +1,12 @@ -# to-do for 0.6pre5 +# to-do for 0.6pre6 -- tutorial +- tutorial? - ease-of-use improvements... ideas: - preset compat flags - - setting to toggle the Choose a System screen on new project - maybe reduced set of presets for the sake of simplicity - a more preferable highlight/drag system - some speed/intuitive workflow improvements that go a long way - - Had a hard time finding the docs on github and in Furnace's folder. - - make .pdf manual out of papers/doc/ - - you're going too fast; please slow down - - break compatibility if it relieves complexity -- ins/wave/sample organization (folders and all) + - make .pdf manual out of doc/ + - break compatibility if it relieves complexity - multi-key binds - bug fixes diff --git a/android/app/build.gradle b/android/app/build.gradle index 483ea52c..3f3fc8bd 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -19,7 +19,7 @@ android { versionName "0.6pre5" externalNativeBuild { cmake { - arguments "-DANDROID_APP_PLATFORM=android-21", "-DANDROID_STL=c++_static" + arguments "-DANDROID_APP_PLATFORM=android-21", "-DANDROID_STL=c++_static", "-DWARNINGS_ARE_ERRORS=ON" // abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64' abiFilters 'arm64-v8a' } diff --git a/android/app/src/main/java/org/libsdl/app/HIDDeviceBLESteamController.java b/android/app/src/main/java/org/libsdl/app/HIDDeviceBLESteamController.java index 65c5a423..ee5521fd 100644 --- a/android/app/src/main/java/org/libsdl/app/HIDDeviceBLESteamController.java +++ b/android/app/src/main/java/org/libsdl/app/HIDDeviceBLESteamController.java @@ -186,7 +186,7 @@ class HIDDeviceBLESteamController extends BluetoothGattCallback implements HIDDe // Because on Chromebooks we show up as a dual-mode device, it will attempt to connect TRANSPORT_AUTO, which will use TRANSPORT_BREDR instead // of TRANSPORT_LE. Let's force ourselves to connect low energy. private BluetoothGatt connectGatt(boolean managed) { - if (Build.VERSION.SDK_INT >= 23) { + if (Build.VERSION.SDK_INT >= 23 /* Android 6.0 (M) */) { try { return mDevice.connectGatt(mManager.getContext(), managed, this, TRANSPORT_LE); } catch (Exception e) { @@ -429,7 +429,7 @@ class HIDDeviceBLESteamController extends BluetoothGattCallback implements HIDDe } }); } - } + } else if (newState == 0) { mIsConnected = false; } diff --git a/android/app/src/main/java/org/libsdl/app/HIDDeviceManager.java b/android/app/src/main/java/org/libsdl/app/HIDDeviceManager.java index cf3c9267..6f7013b2 100644 --- a/android/app/src/main/java/org/libsdl/app/HIDDeviceManager.java +++ b/android/app/src/main/java/org/libsdl/app/HIDDeviceManager.java @@ -170,7 +170,7 @@ public class HIDDeviceManager { Log.i(TAG," Interface protocol: " + mUsbInterface.getInterfaceProtocol()); Log.i(TAG," Endpoint count: " + mUsbInterface.getEndpointCount()); - // Get endpoint details + // Get endpoint details for (int epi = 0; epi < mUsbInterface.getEndpointCount(); epi++) { UsbEndpoint mEndpoint = mUsbInterface.getEndpoint(epi); @@ -251,6 +251,8 @@ public class HIDDeviceManager { 0x20d6, // PowerA 0x24c6, // PowerA 0x2c22, // Qanba + 0x2dc8, // 8BitDo + 0x9886, // ASTRO Gaming }; if (usbInterface.getInterfaceClass() == UsbConstants.USB_CLASS_VENDOR_SPEC && @@ -271,14 +273,16 @@ public class HIDDeviceManager { final int XB1_IFACE_SUBCLASS = 71; final int XB1_IFACE_PROTOCOL = 208; final int[] SUPPORTED_VENDORS = { + 0x044f, // Thrustmaster 0x045e, // Microsoft 0x0738, // Mad Catz 0x0e6f, // PDP 0x0f0d, // Hori + 0x10f5, // Turtle Beach 0x1532, // Razer Wildcat 0x20d6, // PowerA 0x24c6, // PowerA - 0x2dc8, /* 8BitDo */ + 0x2dc8, // 8BitDo 0x2e24, // Hyperkin }; @@ -353,13 +357,13 @@ public class HIDDeviceManager { private void initializeBluetooth() { Log.d(TAG, "Initializing Bluetooth"); - if (Build.VERSION.SDK_INT <= 30 && + if (Build.VERSION.SDK_INT <= 30 /* Android 11.0 (R) */ && mContext.getPackageManager().checkPermission(android.Manifest.permission.BLUETOOTH, mContext.getPackageName()) != PackageManager.PERMISSION_GRANTED) { Log.d(TAG, "Couldn't initialize Bluetooth, missing android.permission.BLUETOOTH"); return; } - if (!mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE) || (Build.VERSION.SDK_INT < 18)) { + if (!mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE) || (Build.VERSION.SDK_INT < 18 /* Android 4.3 (JELLY_BEAN_MR2) */)) { Log.d(TAG, "Couldn't initialize Bluetooth, this version of Android does not support Bluetooth LE"); return; } @@ -524,7 +528,7 @@ public class HIDDeviceManager { for (HIDDevice device : mDevicesById.values()) { device.setFrozen(frozen); } - } + } } ////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -573,7 +577,7 @@ public class HIDDeviceManager { try { final int FLAG_MUTABLE = 0x02000000; // PendingIntent.FLAG_MUTABLE, but don't require SDK 31 int flags; - if (Build.VERSION.SDK_INT >= 31) { + if (Build.VERSION.SDK_INT >= 31 /* Android 12.0 (S) */) { flags = FLAG_MUTABLE; } else { flags = 0; diff --git a/android/app/src/main/java/org/libsdl/app/HIDDeviceUSB.java b/android/app/src/main/java/org/libsdl/app/HIDDeviceUSB.java index d20fe80b..bfe0cf95 100644 --- a/android/app/src/main/java/org/libsdl/app/HIDDeviceUSB.java +++ b/android/app/src/main/java/org/libsdl/app/HIDDeviceUSB.java @@ -52,7 +52,7 @@ class HIDDeviceUSB implements HIDDevice { @Override public String getSerialNumber() { String result = null; - if (Build.VERSION.SDK_INT >= 21) { + if (Build.VERSION.SDK_INT >= 21 /* Android 5.0 (LOLLIPOP) */) { try { result = mDevice.getSerialNumber(); } @@ -74,7 +74,7 @@ class HIDDeviceUSB implements HIDDevice { @Override public String getManufacturerName() { String result = null; - if (Build.VERSION.SDK_INT >= 21) { + if (Build.VERSION.SDK_INT >= 21 /* Android 5.0 (LOLLIPOP) */) { result = mDevice.getManufacturerName(); } if (result == null) { @@ -86,7 +86,7 @@ class HIDDeviceUSB implements HIDDevice { @Override public String getProductName() { String result = null; - if (Build.VERSION.SDK_INT >= 21) { + if (Build.VERSION.SDK_INT >= 21 /* Android 5.0 (LOLLIPOP) */) { result = mDevice.getProductName(); } if (result == null) { diff --git a/android/app/src/main/java/org/libsdl/app/SDL.java b/android/app/src/main/java/org/libsdl/app/SDL.java index dafc0cb8..44c21c1c 100644 --- a/android/app/src/main/java/org/libsdl/app/SDL.java +++ b/android/app/src/main/java/org/libsdl/app/SDL.java @@ -29,6 +29,7 @@ public class SDL { // This function stores the current activity (SDL or not) public static void setContext(Context context) { + SDLAudioManager.setContext(context); mContext = context; } diff --git a/android/app/src/main/java/org/libsdl/app/SDLActivity.java b/android/app/src/main/java/org/libsdl/app/SDLActivity.java index 55b961a4..045e99c7 100644 --- a/android/app/src/main/java/org/libsdl/app/SDLActivity.java +++ b/android/app/src/main/java/org/libsdl/app/SDLActivity.java @@ -15,13 +15,9 @@ import android.content.pm.PackageManager; import android.content.res.Configuration; import android.graphics.Bitmap; import android.graphics.Color; -import android.graphics.PixelFormat; import android.graphics.PorterDuff; import android.graphics.drawable.Drawable; import android.hardware.Sensor; -import android.hardware.SensorEvent; -import android.hardware.SensorEventListener; -import android.hardware.SensorManager; import android.net.Uri; import android.os.Build; import android.os.Bundle; @@ -37,11 +33,8 @@ import android.view.Display; import android.view.Gravity; import android.view.InputDevice; import android.view.KeyEvent; -import android.view.MotionEvent; import android.view.PointerIcon; import android.view.Surface; -import android.view.SurfaceHolder; -import android.view.SurfaceView; import android.view.View; import android.view.ViewGroup; import android.view.Window; @@ -51,6 +44,7 @@ import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputConnection; import android.view.inputmethod.InputMethodManager; import android.widget.Button; +import android.widget.EditText; import android.widget.LinearLayout; import android.widget.RelativeLayout; import android.widget.TextView; @@ -65,6 +59,9 @@ import java.util.Locale; */ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityChangeListener { private static final String TAG = "SDL"; + private static final int SDL_MAJOR_VERSION = 2; + private static final int SDL_MINOR_VERSION = 28; + private static final int SDL_MICRO_VERSION = 0; /* // Display InputType.SOURCE/CLASS of events and devices // @@ -96,7 +93,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh s2 = s_copy & InputDevice.SOURCE_ANY; // keep source only, no class; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + if (Build.VERSION.SDK_INT >= 23) { tst = InputDevice.SOURCE_BLUETOOTH_STYLUS; if ((s & tst) == tst) src += " BLUETOOTH_STYLUS"; s2 &= ~tst; @@ -110,7 +107,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh if ((s & tst) == tst) src += " GAMEPAD"; s2 &= ~tst; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + if (Build.VERSION.SDK_INT >= 21) { tst = InputDevice.SOURCE_HDMI; if ((s & tst) == tst) src += " HDMI"; s2 &= ~tst; @@ -149,7 +146,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh if ((s & tst) == tst) src += " TOUCHSCREEN"; s2 &= ~tst; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { + if (Build.VERSION.SDK_INT >= 18) { tst = InputDevice.SOURCE_TOUCH_NAVIGATION; if ((s & tst) == tst) src += " TOUCH_NAVIGATION"; s2 &= ~tst; @@ -173,7 +170,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh */ public static boolean mIsResumedCalled, mHasFocus; - public static final boolean mHasMultiWindow = (Build.VERSION.SDK_INT >= 24); + public static final boolean mHasMultiWindow = (Build.VERSION.SDK_INT >= 24 /* Android 7.0 (N) */); // Cursor types // private static final int SDL_SYSTEM_CURSOR_NONE = -1; @@ -213,7 +210,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh // Main components protected static SDLActivity mSingleton; protected static SDLSurface mSurface; - protected static View mTextEdit; + protected static DummyEdit mTextEdit; protected static boolean mScreenKeyboardShown; protected static ViewGroup mLayout; protected static SDLClipboardHandler mClipboardHandler; @@ -227,9 +224,9 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh protected static SDLGenericMotionListener_API12 getMotionListener() { if (mMotionListener == null) { - if (Build.VERSION.SDK_INT >= 26) { + if (Build.VERSION.SDK_INT >= 26 /* Android 8.0 (O) */) { mMotionListener = new SDLGenericMotionListener_API26(); - } else if (Build.VERSION.SDK_INT >= 24) { + } else if (Build.VERSION.SDK_INT >= 24 /* Android 7.0 (N) */) { mMotionListener = new SDLGenericMotionListener_API24(); } else { mMotionListener = new SDLGenericMotionListener_API12(); @@ -314,6 +311,10 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh mNextNativeState = NativeState.INIT; mCurrentNativeState = NativeState.INIT; } + + protected SDLSurface createSDLSurface(Context context) { + return new SDLSurface(context); + } // Setup @Override @@ -344,8 +345,18 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh errorMsgBrokenLib = e.getMessage(); } - if (mBrokenLibraries) - { + if (!mBrokenLibraries) { + String expected_version = String.valueOf(SDL_MAJOR_VERSION) + "." + + String.valueOf(SDL_MINOR_VERSION) + "." + + String.valueOf(SDL_MICRO_VERSION); + String version = nativeGetVersion(); + if (!version.equals(expected_version)) { + mBrokenLibraries = true; + errorMsgBrokenLib = "SDL C/Java version mismatch (expected " + expected_version + ", got " + version + ")"; + } + } + + if (mBrokenLibraries) { mSingleton = this; AlertDialog.Builder dlgAlert = new AlertDialog.Builder(this); dlgAlert.setMessage("An error occurred while trying to start the application. Please try again and/or reinstall." @@ -382,7 +393,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh mHIDDeviceManager = HIDDeviceManager.acquire(this); // Set up the surface - mSurface = new SDLSurface(getApplication()); + mSurface = createSDLSurface(this); mLayout = new RelativeLayout(this); mLayout.addView(mSurface); @@ -393,7 +404,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh SDLActivity.onNativeOrientationChanged(mCurrentOrientation); try { - if (Build.VERSION.SDK_INT < 24) { + if (Build.VERSION.SDK_INT < 24 /* Android 7.0 (N) */) { mCurrentLocale = getContext().getResources().getConfiguration().locale; } else { mCurrentLocale = getContext().getResources().getConfiguration().getLocales().get(0); @@ -577,6 +588,8 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh mHIDDeviceManager = null; } + SDLAudioManager.release(this); + if (SDLActivity.mBrokenLibraries) { super.onDestroy(); return; @@ -755,7 +768,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh } break; case COMMAND_CHANGE_WINDOW_STYLE: - if (Build.VERSION.SDK_INT >= 19) { + if (Build.VERSION.SDK_INT >= 19 /* Android 4.4 (KITKAT) */) { if (context instanceof Activity) { Window window = ((Activity) context).getWindow(); if (window != null) { @@ -830,7 +843,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh msg.obj = data; boolean result = commandHandler.sendMessage(msg); - if (Build.VERSION.SDK_INT >= 19) { + if (Build.VERSION.SDK_INT >= 19 /* Android 4.4 (KITKAT) */) { if (command == COMMAND_CHANGE_WINDOW_STYLE) { // Ensure we don't return until the resize has actually happened, // or 500ms have passed. @@ -886,6 +899,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh } // C functions we call + public static native String nativeGetVersion(); public static native int nativeSetupJNI(); public static native int nativeRunMain(String library, String function, Object arguments); public static native void nativeLowMemory(); @@ -957,15 +971,18 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh /* If set, hint "explicitly controls which UI orientations are allowed". */ if (hint.contains("LandscapeRight") && hint.contains("LandscapeLeft")) { orientation_landscape = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE; - } else if (hint.contains("LandscapeRight")) { - orientation_landscape = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; } else if (hint.contains("LandscapeLeft")) { + orientation_landscape = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; + } else if (hint.contains("LandscapeRight")) { orientation_landscape = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; } - if (hint.contains("Portrait") && hint.contains("PortraitUpsideDown")) { + /* exact match to 'Portrait' to distinguish with PortraitUpsideDown */ + boolean contains_Portrait = hint.contains("Portrait ") || hint.endsWith("Portrait"); + + if (contains_Portrait && hint.contains("PortraitUpsideDown")) { orientation_portrait = ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT; - } else if (hint.contains("Portrait")) { + } else if (contains_Portrait) { orientation_portrait = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; } else if (hint.contains("PortraitUpsideDown")) { orientation_portrait = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT; @@ -1078,7 +1095,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh // thus SDK version 27. If we are in DeX mode and not API 27 or higher, as a result, // we should stick to relative mode. // - if ((Build.VERSION.SDK_INT < 27) && isDeXMode()) { + if (Build.VERSION.SDK_INT < 27 /* Android 8.1 (O_MR1) */ && isDeXMode()) { return false; } @@ -1168,7 +1185,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh * This method is called by SDL using JNI. */ public static boolean isDeXMode() { - if (Build.VERSION.SDK_INT < 24) { + if (Build.VERSION.SDK_INT < 24 /* Android 7.0 (N) */) { return false; } try { @@ -1220,8 +1237,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh } // This method is called by SDLControllerManager's API 26 Generic Motion Handler. - public static View getContentView() - { + public static View getContentView() { return mLayout; } @@ -1292,6 +1308,77 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh return event.isPrintingKey() || event.getKeyCode() == KeyEvent.KEYCODE_SPACE; } + public static boolean handleKeyEvent(View v, int keyCode, KeyEvent event, InputConnection ic) { + int deviceId = event.getDeviceId(); + int source = event.getSource(); + + if (source == InputDevice.SOURCE_UNKNOWN) { + InputDevice device = InputDevice.getDevice(deviceId); + if (device != null) { + source = device.getSources(); + } + } + +// if (event.getAction() == KeyEvent.ACTION_DOWN) { +// Log.v("SDL", "key down: " + keyCode + ", deviceId = " + deviceId + ", source = " + source); +// } else if (event.getAction() == KeyEvent.ACTION_UP) { +// Log.v("SDL", "key up: " + keyCode + ", deviceId = " + deviceId + ", source = " + source); +// } + + // Dispatch the different events depending on where they come from + // Some SOURCE_JOYSTICK, SOURCE_DPAD or SOURCE_GAMEPAD are also SOURCE_KEYBOARD + // So, we try to process them as JOYSTICK/DPAD/GAMEPAD events first, if that fails we try them as KEYBOARD + // + // Furthermore, it's possible a game controller has SOURCE_KEYBOARD and + // SOURCE_JOYSTICK, while its key events arrive from the keyboard source + // So, retrieve the device itself and check all of its sources + if (SDLControllerManager.isDeviceSDLJoystick(deviceId)) { + // Note that we process events with specific key codes here + if (event.getAction() == KeyEvent.ACTION_DOWN) { + if (SDLControllerManager.onNativePadDown(deviceId, keyCode) == 0) { + return true; + } + } else if (event.getAction() == KeyEvent.ACTION_UP) { + if (SDLControllerManager.onNativePadUp(deviceId, keyCode) == 0) { + return true; + } + } + } + + if ((source & InputDevice.SOURCE_KEYBOARD) == InputDevice.SOURCE_KEYBOARD) { + if (event.getAction() == KeyEvent.ACTION_DOWN) { + if (isTextInputEvent(event)) { + if (ic != null) { + ic.commitText(String.valueOf((char) event.getUnicodeChar()), 1); + } else { + SDLInputConnection.nativeCommitText(String.valueOf((char) event.getUnicodeChar()), 1); + } + } + onNativeKeyDown(keyCode); + return true; + } else if (event.getAction() == KeyEvent.ACTION_UP) { + onNativeKeyUp(keyCode); + return true; + } + } + + if ((source & InputDevice.SOURCE_MOUSE) == InputDevice.SOURCE_MOUSE) { + // on some devices key events are sent for mouse BUTTON_BACK/FORWARD presses + // they are ignored here because sending them as mouse input to SDL is messy + if ((keyCode == KeyEvent.KEYCODE_BACK) || (keyCode == KeyEvent.KEYCODE_FORWARD)) { + switch (event.getAction()) { + case KeyEvent.ACTION_DOWN: + case KeyEvent.ACTION_UP: + // mark the event as handled or it will be handled by system + // handling KEYCODE_BACK by system will call onBackPressed() + return true; + } + } + } + + return false; + } + /** * This method is called by SDL using JNI. */ @@ -1535,7 +1622,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh private final Runnable rehideSystemUi = new Runnable() { @Override public void run() { - if (Build.VERSION.SDK_INT >= 19) { + if (Build.VERSION.SDK_INT >= 19 /* Android 4.4 (KITKAT) */) { int flags = View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | @@ -1588,7 +1675,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh Bitmap bitmap = Bitmap.createBitmap(colors, width, height, Bitmap.Config.ARGB_8888); ++mLastCursorID; - if (Build.VERSION.SDK_INT >= 24) { + if (Build.VERSION.SDK_INT >= 24 /* Android 7.0 (N) */) { try { mCursors.put(mLastCursorID, PointerIcon.create(bitmap, hotSpotX, hotSpotY)); } catch (Exception e) { @@ -1604,7 +1691,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh * This method is called by SDL using JNI. */ public static void destroyCustomCursor(int cursorID) { - if (Build.VERSION.SDK_INT >= 24) { + if (Build.VERSION.SDK_INT >= 24 /* Android 7.0 (N) */) { try { mCursors.remove(cursorID); } catch (Exception e) { @@ -1618,7 +1705,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh */ public static boolean setCustomCursor(int cursorID) { - if (Build.VERSION.SDK_INT >= 24) { + if (Build.VERSION.SDK_INT >= 24 /* Android 7.0 (N) */) { try { mSurface.setPointerIcon(mCursors.get(cursorID)); } catch (Exception e) { @@ -1673,7 +1760,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh cursor_type = 1002; //PointerIcon.TYPE_HAND; break; } - if (Build.VERSION.SDK_INT >= 24) { + if (Build.VERSION.SDK_INT >= 24 /* Android 7.0 (N) */) { try { mSurface.setPointerIcon(PointerIcon.getSystemIcon(SDL.getContext(), cursor_type)); } catch (Exception e) { @@ -1687,7 +1774,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh * This method is called by SDL using JNI. */ public static void requestPermission(String permission, int requestCode) { - if (Build.VERSION.SDK_INT < 23) { + if (Build.VERSION.SDK_INT < 23 /* Android 6.0 (M) */) { nativePermissionResult(requestCode, true); return; } @@ -1716,7 +1803,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh i.setData(Uri.parse(url)); int flags = Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_MULTIPLE_TASK; - if (Build.VERSION.SDK_INT >= 21) { + if (Build.VERSION.SDK_INT >= 21 /* Android 5.0 (LOLLIPOP) */) { flags |= Intent.FLAG_ACTIVITY_NEW_DOCUMENT; } else { flags |= Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET; @@ -1809,455 +1896,6 @@ class SDLMain implements Runnable { } } - -/** - SDLSurface. This is what we draw on, so we need to know when it's created - in order to do anything useful. - - Because of this, that's where we set up the SDL thread -*/ -class SDLSurface extends SurfaceView implements SurfaceHolder.Callback, - View.OnKeyListener, View.OnTouchListener, SensorEventListener { - - // Sensors - protected SensorManager mSensorManager; - protected Display mDisplay; - - // Keep track of the surface size to normalize touch events - protected float mWidth, mHeight; - - // Is SurfaceView ready for rendering - public boolean mIsSurfaceReady; - - // Startup - public SDLSurface(Context context) { - super(context); - getHolder().addCallback(this); - - setFocusable(true); - setFocusableInTouchMode(true); - requestFocus(); - setOnKeyListener(this); - setOnTouchListener(this); - - mDisplay = ((WindowManager)context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); - mSensorManager = (SensorManager)context.getSystemService(Context.SENSOR_SERVICE); - - setOnGenericMotionListener(SDLActivity.getMotionListener()); - - // Some arbitrary defaults to avoid a potential division by zero - mWidth = 1.0f; - mHeight = 1.0f; - - mIsSurfaceReady = false; - } - - public void handlePause() { - enableSensor(Sensor.TYPE_ACCELEROMETER, false); - } - - public void handleResume() { - setFocusable(true); - setFocusableInTouchMode(true); - requestFocus(); - setOnKeyListener(this); - setOnTouchListener(this); - enableSensor(Sensor.TYPE_ACCELEROMETER, true); - } - - public Surface getNativeSurface() { - return getHolder().getSurface(); - } - - // Called when we have a valid drawing surface - @Override - public void surfaceCreated(SurfaceHolder holder) { - Log.v("SDL", "surfaceCreated()"); - SDLActivity.onNativeSurfaceCreated(); - } - - // Called when we lose the surface - @Override - public void surfaceDestroyed(SurfaceHolder holder) { - Log.v("SDL", "surfaceDestroyed()"); - - // Transition to pause, if needed - SDLActivity.mNextNativeState = SDLActivity.NativeState.PAUSED; - SDLActivity.handleNativeState(); - - mIsSurfaceReady = false; - SDLActivity.onNativeSurfaceDestroyed(); - } - - // Called when the surface is resized - @Override - public void surfaceChanged(SurfaceHolder holder, - int format, int width, int height) { - Log.v("SDL", "surfaceChanged()"); - - if (SDLActivity.mSingleton == null) { - return; - } - - mWidth = width; - mHeight = height; - int nDeviceWidth = width; - int nDeviceHeight = height; - try - { - if (Build.VERSION.SDK_INT >= 17) { - DisplayMetrics realMetrics = new DisplayMetrics(); - mDisplay.getRealMetrics( realMetrics ); - nDeviceWidth = realMetrics.widthPixels; - nDeviceHeight = realMetrics.heightPixels; - } - } catch(Exception ignored) { - } - - synchronized(SDLActivity.getContext()) { - // In case we're waiting on a size change after going fullscreen, send a notification. - SDLActivity.getContext().notifyAll(); - } - - Log.v("SDL", "Window size: " + width + "x" + height); - Log.v("SDL", "Device size: " + nDeviceWidth + "x" + nDeviceHeight); - SDLActivity.nativeSetScreenResolution(width, height, nDeviceWidth, nDeviceHeight, mDisplay.getRefreshRate()); - SDLActivity.onNativeResize(); - - // Prevent a screen distortion glitch, - // for instance when the device is in Landscape and a Portrait App is resumed. - boolean skip = false; - int requestedOrientation = SDLActivity.mSingleton.getRequestedOrientation(); - - if (requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT || requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) { - if (mWidth > mHeight) { - skip = true; - } - } else if (requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE || requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) { - if (mWidth < mHeight) { - skip = true; - } - } - - // Special Patch for Square Resolution: Black Berry Passport - if (skip) { - double min = Math.min(mWidth, mHeight); - double max = Math.max(mWidth, mHeight); - - if (max / min < 1.20) { - Log.v("SDL", "Don't skip on such aspect-ratio. Could be a square resolution."); - skip = false; - } - } - - // Don't skip in MultiWindow. - if (skip) { - if (Build.VERSION.SDK_INT >= 24) { - if (SDLActivity.mSingleton.isInMultiWindowMode()) { - Log.v("SDL", "Don't skip in Multi-Window"); - skip = false; - } - } - } - - if (skip) { - Log.v("SDL", "Skip .. Surface is not ready."); - mIsSurfaceReady = false; - return; - } - - /* If the surface has been previously destroyed by onNativeSurfaceDestroyed, recreate it here */ - SDLActivity.onNativeSurfaceChanged(); - - /* Surface is ready */ - mIsSurfaceReady = true; - - SDLActivity.mNextNativeState = SDLActivity.NativeState.RESUMED; - SDLActivity.handleNativeState(); - } - - // Key events - @Override - public boolean onKey(View v, int keyCode, KeyEvent event) { - - int deviceId = event.getDeviceId(); - int source = event.getSource(); - - if (source == InputDevice.SOURCE_UNKNOWN) { - InputDevice device = InputDevice.getDevice(deviceId); - if (device != null) { - source = device.getSources(); - } - } - -// if (event.getAction() == KeyEvent.ACTION_DOWN) { -// Log.v("SDL", "key down: " + keyCode + ", deviceId = " + deviceId + ", source = " + source); -// } else if (event.getAction() == KeyEvent.ACTION_UP) { -// Log.v("SDL", "key up: " + keyCode + ", deviceId = " + deviceId + ", source = " + source); -// } - - // Dispatch the different events depending on where they come from - // Some SOURCE_JOYSTICK, SOURCE_DPAD or SOURCE_GAMEPAD are also SOURCE_KEYBOARD - // So, we try to process them as JOYSTICK/DPAD/GAMEPAD events first, if that fails we try them as KEYBOARD - // - // Furthermore, it's possible a game controller has SOURCE_KEYBOARD and - // SOURCE_JOYSTICK, while its key events arrive from the keyboard source - // So, retrieve the device itself and check all of its sources - if (SDLControllerManager.isDeviceSDLJoystick(deviceId)) { - // Note that we process events with specific key codes here - if (event.getAction() == KeyEvent.ACTION_DOWN) { - if (SDLControllerManager.onNativePadDown(deviceId, keyCode) == 0) { - return true; - } - } else if (event.getAction() == KeyEvent.ACTION_UP) { - if (SDLControllerManager.onNativePadUp(deviceId, keyCode) == 0) { - return true; - } - } - } - - if ((source & InputDevice.SOURCE_KEYBOARD) == InputDevice.SOURCE_KEYBOARD) { - if (event.getAction() == KeyEvent.ACTION_DOWN) { - if (SDLActivity.isTextInputEvent(event)) { - SDLInputConnection.nativeCommitText(String.valueOf((char) event.getUnicodeChar()), 1); - } - SDLActivity.onNativeKeyDown(keyCode); - return true; - } else if (event.getAction() == KeyEvent.ACTION_UP) { - SDLActivity.onNativeKeyUp(keyCode); - return true; - } - } - - if ((source & InputDevice.SOURCE_MOUSE) == InputDevice.SOURCE_MOUSE) { - // on some devices key events are sent for mouse BUTTON_BACK/FORWARD presses - // they are ignored here because sending them as mouse input to SDL is messy - if ((keyCode == KeyEvent.KEYCODE_BACK) || (keyCode == KeyEvent.KEYCODE_FORWARD)) { - switch (event.getAction()) { - case KeyEvent.ACTION_DOWN: - case KeyEvent.ACTION_UP: - // mark the event as handled or it will be handled by system - // handling KEYCODE_BACK by system will call onBackPressed() - return true; - } - } - } - - return false; - } - - // Touch events - @Override - public boolean onTouch(View v, MotionEvent event) { - /* Ref: http://developer.android.com/training/gestures/multi.html */ - int touchDevId = event.getDeviceId(); - final int pointerCount = event.getPointerCount(); - int action = event.getActionMasked(); - int pointerFingerId; - int i = -1; - float x,y,p; - - /* - * Prevent id to be -1, since it's used in SDL internal for synthetic events - * Appears when using Android emulator, eg: - * adb shell input mouse tap 100 100 - * adb shell input touchscreen tap 100 100 - */ - if (touchDevId < 0) { - touchDevId -= 1; - } - - // 12290 = Samsung DeX mode desktop mouse - // 12290 = 0x3002 = 0x2002 | 0x1002 = SOURCE_MOUSE | SOURCE_TOUCHSCREEN - // 0x2 = SOURCE_CLASS_POINTER - if (event.getSource() == InputDevice.SOURCE_MOUSE || event.getSource() == (InputDevice.SOURCE_MOUSE | InputDevice.SOURCE_TOUCHSCREEN)) { - int mouseButton = 1; - try { - Object object = event.getClass().getMethod("getButtonState").invoke(event); - if (object != null) { - mouseButton = (Integer) object; - } - } catch(Exception ignored) { - } - - // We need to check if we're in relative mouse mode and get the axis offset rather than the x/y values - // if we are. We'll leverage our existing mouse motion listener - SDLGenericMotionListener_API12 motionListener = SDLActivity.getMotionListener(); - x = motionListener.getEventX(event); - y = motionListener.getEventY(event); - - SDLActivity.onNativeMouse(mouseButton, action, x, y, motionListener.inRelativeMode()); - } else { - switch(action) { - case MotionEvent.ACTION_MOVE: - for (i = 0; i < pointerCount; i++) { - pointerFingerId = event.getPointerId(i); - x = event.getX(i) / mWidth; - y = event.getY(i) / mHeight; - p = event.getPressure(i); - if (p > 1.0f) { - // may be larger than 1.0f on some devices - // see the documentation of getPressure(i) - p = 1.0f; - } - SDLActivity.onNativeTouch(touchDevId, pointerFingerId, action, x, y, p); - } - break; - - case MotionEvent.ACTION_UP: - case MotionEvent.ACTION_DOWN: - // Primary pointer up/down, the index is always zero - i = 0; - /* fallthrough */ - case MotionEvent.ACTION_POINTER_UP: - case MotionEvent.ACTION_POINTER_DOWN: - // Non primary pointer up/down - if (i == -1) { - i = event.getActionIndex(); - } - - pointerFingerId = event.getPointerId(i); - x = event.getX(i) / mWidth; - y = event.getY(i) / mHeight; - p = event.getPressure(i); - if (p > 1.0f) { - // may be larger than 1.0f on some devices - // see the documentation of getPressure(i) - p = 1.0f; - } - SDLActivity.onNativeTouch(touchDevId, pointerFingerId, action, x, y, p); - break; - - case MotionEvent.ACTION_CANCEL: - for (i = 0; i < pointerCount; i++) { - pointerFingerId = event.getPointerId(i); - x = event.getX(i) / mWidth; - y = event.getY(i) / mHeight; - p = event.getPressure(i); - if (p > 1.0f) { - // may be larger than 1.0f on some devices - // see the documentation of getPressure(i) - p = 1.0f; - } - SDLActivity.onNativeTouch(touchDevId, pointerFingerId, MotionEvent.ACTION_UP, x, y, p); - } - break; - - default: - break; - } - } - - return true; - } - - // Sensor events - public void enableSensor(int sensortype, boolean enabled) { - // TODO: This uses getDefaultSensor - what if we have >1 accels? - if (enabled) { - mSensorManager.registerListener(this, - mSensorManager.getDefaultSensor(sensortype), - SensorManager.SENSOR_DELAY_GAME, null); - } else { - mSensorManager.unregisterListener(this, - mSensorManager.getDefaultSensor(sensortype)); - } - } - - @Override - public void onAccuracyChanged(Sensor sensor, int accuracy) { - // TODO - } - - @Override - public void onSensorChanged(SensorEvent event) { - if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { - - // Since we may have an orientation set, we won't receive onConfigurationChanged events. - // We thus should check here. - int newOrientation; - - float x, y; - switch (mDisplay.getRotation()) { - case Surface.ROTATION_90: - x = -event.values[1]; - y = event.values[0]; - newOrientation = SDLActivity.SDL_ORIENTATION_LANDSCAPE; - break; - case Surface.ROTATION_270: - x = event.values[1]; - y = -event.values[0]; - newOrientation = SDLActivity.SDL_ORIENTATION_LANDSCAPE_FLIPPED; - break; - case Surface.ROTATION_180: - x = -event.values[0]; - y = -event.values[1]; - newOrientation = SDLActivity.SDL_ORIENTATION_PORTRAIT_FLIPPED; - break; - case Surface.ROTATION_0: - default: - x = event.values[0]; - y = event.values[1]; - newOrientation = SDLActivity.SDL_ORIENTATION_PORTRAIT; - break; - } - - if (newOrientation != SDLActivity.mCurrentOrientation) { - SDLActivity.mCurrentOrientation = newOrientation; - SDLActivity.onNativeOrientationChanged(newOrientation); - } - - SDLActivity.onNativeAccel(-x / SensorManager.GRAVITY_EARTH, - y / SensorManager.GRAVITY_EARTH, - event.values[2] / SensorManager.GRAVITY_EARTH); - - - } - } - - // Captured pointer events for API 26. - public boolean onCapturedPointerEvent(MotionEvent event) - { - int action = event.getActionMasked(); - - float x, y; - switch (action) { - case MotionEvent.ACTION_SCROLL: - x = event.getAxisValue(MotionEvent.AXIS_HSCROLL, 0); - y = event.getAxisValue(MotionEvent.AXIS_VSCROLL, 0); - SDLActivity.onNativeMouse(0, action, x, y, false); - return true; - - case MotionEvent.ACTION_HOVER_MOVE: - case MotionEvent.ACTION_MOVE: - x = event.getX(0); - y = event.getY(0); - SDLActivity.onNativeMouse(0, action, x, y, true); - return true; - - case MotionEvent.ACTION_BUTTON_PRESS: - case MotionEvent.ACTION_BUTTON_RELEASE: - - // Change our action value to what SDL's code expects. - if (action == MotionEvent.ACTION_BUTTON_PRESS) { - action = MotionEvent.ACTION_DOWN; - } else { /* MotionEvent.ACTION_BUTTON_RELEASE */ - action = MotionEvent.ACTION_UP; - } - - x = event.getX(0); - y = event.getY(0); - int button = event.getButtonState(); - - SDLActivity.onNativeMouse(button, action, x, y, true); - return true; - } - - return false; - } - -} - /* This is a fake invisible editor view that receives the input and defines the * pan&scan region */ @@ -2278,21 +1916,7 @@ class DummyEdit extends View implements View.OnKeyListener { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { - /* - * This handles the hardware keyboard input - */ - if (event.getAction() == KeyEvent.ACTION_DOWN) { - if (SDLActivity.isTextInputEvent(event)) { - ic.commitText(String.valueOf((char) event.getUnicodeChar()), 1); - return true; - } - SDLActivity.onNativeKeyDown(keyCode); - return true; - } else if (event.getAction() == KeyEvent.ACTION_UP) { - SDLActivity.onNativeKeyUp(keyCode); - return true; - } - return false; + return SDLActivity.handleKeyEvent(v, keyCode, event, ic); } // @@ -2316,9 +1940,10 @@ class DummyEdit extends View implements View.OnKeyListener { public InputConnection onCreateInputConnection(EditorInfo outAttrs) { ic = new SDLInputConnection(this, true); - outAttrs.inputType = InputType.TYPE_CLASS_TEXT; - outAttrs.imeOptions = EditorInfo.IME_FLAG_NO_EXTRACT_UI - | EditorInfo.IME_FLAG_NO_FULLSCREEN /* API 11 */; + outAttrs.inputType = InputType.TYPE_CLASS_TEXT | + InputType.TYPE_TEXT_FLAG_MULTI_LINE; + outAttrs.imeOptions = EditorInfo.IME_FLAG_NO_EXTRACT_UI | + EditorInfo.IME_FLAG_NO_FULLSCREEN /* API 11 */; return ic; } @@ -2326,9 +1951,17 @@ class DummyEdit extends View implements View.OnKeyListener { class SDLInputConnection extends BaseInputConnection { + protected EditText mEditText; + protected String mCommittedText = ""; + public SDLInputConnection(View targetView, boolean fullEditor) { super(targetView, fullEditor); + mEditText = new EditText(SDL.getContext()); + } + @Override + public Editable getEditable() { + return mEditText.getEditableText(); } @Override @@ -2351,79 +1984,96 @@ class SDLInputConnection extends BaseInputConnection { } } - return super.sendKeyEvent(event); } @Override public boolean commitText(CharSequence text, int newCursorPosition) { - - /* Generate backspaces for the text we're going to replace */ - final Editable content = getEditable(); - if (content != null) { - int a = getComposingSpanStart(content); - int b = getComposingSpanEnd(content); - if (a == -1 || b == -1) { - a = Selection.getSelectionStart(content); - b = Selection.getSelectionEnd(content); - } - if (a < 0) a = 0; - if (b < 0) b = 0; - if (b < a) { - int tmp = a; - a = b; - b = tmp; - } - int backspaces = (b - a); - - for (int i = 0; i < backspaces; i++) { - nativeGenerateScancodeForUnichar('\b'); - } + if (!super.commitText(text, newCursorPosition)) { + return false; } - - for (int i = 0; i < text.length(); i++) { - char c = text.charAt(i); - if (c == '\n') { - if (SDLActivity.onNativeSoftReturnKey()) { - return true; - } - } - nativeGenerateScancodeForUnichar(c); - } - - SDLInputConnection.nativeCommitText(text.toString(), newCursorPosition); - - return super.commitText(text, newCursorPosition); + updateText(); + return true; } @Override public boolean setComposingText(CharSequence text, int newCursorPosition) { + if (!super.setComposingText(text, newCursorPosition)) { + return false; + } + updateText(); + return true; + } - nativeSetComposingText(text.toString(), newCursorPosition); + @Override + public boolean deleteSurroundingText(int beforeLength, int afterLength) { + if (Build.VERSION.SDK_INT <= 29 /* Android 10.0 (Q) */) { + // Workaround to capture backspace key. Ref: http://stackoverflow.com/questions>/14560344/android-backspace-in-webview-baseinputconnection + // and https://bugzilla.libsdl.org/show_bug.cgi?id=2265 + if (beforeLength > 0 && afterLength == 0) { + // backspace(s) + while (beforeLength-- > 0) { + nativeGenerateScancodeForUnichar('\b'); + } + return true; + } + } - return super.setComposingText(text, newCursorPosition); + if (!super.deleteSurroundingText(beforeLength, afterLength)) { + return false; + } + updateText(); + return true; + } + + protected void updateText() { + final Editable content = getEditable(); + if (content == null) { + return; + } + + String text = content.toString(); + int compareLength = Math.min(text.length(), mCommittedText.length()); + int matchLength, offset; + + /* Backspace over characters that are no longer in the string */ + for (matchLength = 0; matchLength < compareLength; ) { + int codePoint = mCommittedText.codePointAt(matchLength); + if (codePoint != text.codePointAt(matchLength)) { + break; + } + matchLength += Character.charCount(codePoint); + } + /* FIXME: This doesn't handle graphemes, like '🌬️' */ + for (offset = matchLength; offset < mCommittedText.length(); ) { + int codePoint = mCommittedText.codePointAt(offset); + nativeGenerateScancodeForUnichar('\b'); + offset += Character.charCount(codePoint); + } + + if (matchLength < text.length()) { + String pendingText = text.subSequence(matchLength, text.length()).toString(); + for (offset = 0; offset < pendingText.length(); ) { + int codePoint = pendingText.codePointAt(offset); + if (codePoint == '\n') { + if (SDLActivity.onNativeSoftReturnKey()) { + return; + } + } + /* Higher code points don't generate simulated scancodes */ + if (codePoint < 128) { + nativeGenerateScancodeForUnichar((char)codePoint); + } + offset += Character.charCount(codePoint); + } + SDLInputConnection.nativeCommitText(pendingText, 0); + } + mCommittedText = text; } public static native void nativeCommitText(String text, int newCursorPosition); - public native void nativeGenerateScancodeForUnichar(char c); - - public native void nativeSetComposingText(String text, int newCursorPosition); - - @Override - public boolean deleteSurroundingText(int beforeLength, int afterLength) { - // Workaround to capture backspace key. Ref: http://stackoverflow.com/questions/14560344/android-backspace-in-webview-baseinputconnection - // and https://bugzilla.libsdl.org/show_bug.cgi?id=2265 - if (beforeLength > 0 && afterLength == 0) { - // backspace(s) - while (beforeLength-- > 0) { - nativeGenerateScancodeForUnichar('\b'); - } - return true; - } - - return super.deleteSurroundingText(beforeLength, afterLength); - } + public static native void nativeGenerateScancodeForUnichar(char c); } class SDLClipboardHandler implements diff --git a/android/app/src/main/java/org/libsdl/app/SDLAudioManager.java b/android/app/src/main/java/org/libsdl/app/SDLAudioManager.java index 2bfc7186..7c821a40 100644 --- a/android/app/src/main/java/org/libsdl/app/SDLAudioManager.java +++ b/android/app/src/main/java/org/libsdl/app/SDLAudioManager.java @@ -1,5 +1,8 @@ package org.libsdl.app; +import android.content.Context; +import android.media.AudioDeviceCallback; +import android.media.AudioDeviceInfo; import android.media.AudioFormat; import android.media.AudioManager; import android.media.AudioRecord; @@ -8,34 +11,67 @@ import android.media.MediaRecorder; import android.os.Build; import android.util.Log; -public class SDLAudioManager -{ +import java.util.Arrays; + +public class SDLAudioManager { protected static final String TAG = "SDLAudio"; protected static AudioTrack mAudioTrack; protected static AudioRecord mAudioRecord; + protected static Context mContext; + + private static final int[] NO_DEVICES = {}; + + private static AudioDeviceCallback mAudioDeviceCallback; public static void initialize() { mAudioTrack = null; mAudioRecord = null; + mAudioDeviceCallback = null; + + if(Build.VERSION.SDK_INT >= 24 /* Android 7.0 (N) */) + { + mAudioDeviceCallback = new AudioDeviceCallback() { + @Override + public void onAudioDevicesAdded(AudioDeviceInfo[] addedDevices) { + Arrays.stream(addedDevices).forEach(deviceInfo -> addAudioDevice(deviceInfo.isSink(), deviceInfo.getId())); + } + + @Override + public void onAudioDevicesRemoved(AudioDeviceInfo[] removedDevices) { + Arrays.stream(removedDevices).forEach(deviceInfo -> removeAudioDevice(deviceInfo.isSink(), deviceInfo.getId())); + } + }; + } + } + + public static void setContext(Context context) { + mContext = context; + if (context != null) { + registerAudioDeviceCallback(); + } + } + + public static void release(Context context) { + unregisterAudioDeviceCallback(context); } // Audio protected static String getAudioFormatString(int audioFormat) { switch (audioFormat) { - case AudioFormat.ENCODING_PCM_8BIT: - return "8-bit"; - case AudioFormat.ENCODING_PCM_16BIT: - return "16-bit"; - case AudioFormat.ENCODING_PCM_FLOAT: - return "float"; - default: - return Integer.toString(audioFormat); + case AudioFormat.ENCODING_PCM_8BIT: + return "8-bit"; + case AudioFormat.ENCODING_PCM_16BIT: + return "16-bit"; + case AudioFormat.ENCODING_PCM_FLOAT: + return "float"; + default: + return Integer.toString(audioFormat); } } - protected static int[] open(boolean isCapture, int sampleRate, int audioFormat, int desiredChannels, int desiredFrames) { + protected static int[] open(boolean isCapture, int sampleRate, int audioFormat, int desiredChannels, int desiredFrames, int deviceId) { int channelConfig; int sampleSize; int frameSize; @@ -43,14 +79,14 @@ public class SDLAudioManager Log.v(TAG, "Opening " + (isCapture ? "capture" : "playback") + ", requested " + desiredFrames + " frames of " + desiredChannels + " channel " + getAudioFormatString(audioFormat) + " audio at " + sampleRate + " Hz"); /* On older devices let's use known good settings */ - if (Build.VERSION.SDK_INT < 21) { + if (Build.VERSION.SDK_INT < 21 /* Android 5.0 (LOLLIPOP) */) { if (desiredChannels > 2) { desiredChannels = 2; } } /* AudioTrack has sample rate limitation of 48000 (fixed in 5.0.2) */ - if (Build.VERSION.SDK_INT < 22) { + if (Build.VERSION.SDK_INT < 22 /* Android 5.1 (LOLLIPOP_MR1) */) { if (sampleRate < 8000) { sampleRate = 8000; } else if (sampleRate > 48000) { @@ -59,7 +95,7 @@ public class SDLAudioManager } if (audioFormat == AudioFormat.ENCODING_PCM_FLOAT) { - int minSDKVersion = (isCapture ? 23 : 21); + int minSDKVersion = (isCapture ? 23 /* Android 6.0 (M) */ : 21 /* Android 5.0 (LOLLIPOP) */); if (Build.VERSION.SDK_INT < minSDKVersion) { audioFormat = AudioFormat.ENCODING_PCM_16BIT; } @@ -120,7 +156,7 @@ public class SDLAudioManager channelConfig = AudioFormat.CHANNEL_OUT_5POINT1 | AudioFormat.CHANNEL_OUT_BACK_CENTER; break; case 8: - if (Build.VERSION.SDK_INT >= 23) { + if (Build.VERSION.SDK_INT >= 23 /* Android 6.0 (M) */) { channelConfig = AudioFormat.CHANNEL_OUT_7POINT1_SURROUND; } else { Log.v(TAG, "Requested " + desiredChannels + " channels, getting 5.1 surround"); @@ -201,6 +237,10 @@ public class SDLAudioManager return null; } + if (Build.VERSION.SDK_INT >= 24 /* Android 7.0 (N) */ && deviceId != 0) { + mAudioRecord.setPreferredDevice(getOutputAudioDeviceInfo(deviceId)); + } + mAudioRecord.startRecording(); } @@ -224,6 +264,10 @@ public class SDLAudioManager return null; } + if (Build.VERSION.SDK_INT >= 24 /* Android 7.0 (N) */ && deviceId != 0) { + mAudioTrack.setPreferredDevice(getInputAudioDeviceInfo(deviceId)); + } + mAudioTrack.play(); } @@ -238,11 +282,73 @@ public class SDLAudioManager return results; } + private static AudioDeviceInfo getInputAudioDeviceInfo(int deviceId) { + if (Build.VERSION.SDK_INT >= 24 /* Android 7.0 (N) */) { + AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); + return Arrays.stream(audioManager.getDevices(AudioManager.GET_DEVICES_INPUTS)) + .filter(deviceInfo -> deviceInfo.getId() == deviceId) + .findFirst() + .orElse(null); + } else { + return null; + } + } + + private static AudioDeviceInfo getOutputAudioDeviceInfo(int deviceId) { + if (Build.VERSION.SDK_INT >= 24 /* Android 7.0 (N) */) { + AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); + return Arrays.stream(audioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS)) + .filter(deviceInfo -> deviceInfo.getId() == deviceId) + .findFirst() + .orElse(null); + } else { + return null; + } + } + + private static void registerAudioDeviceCallback() { + if (Build.VERSION.SDK_INT >= 24 /* Android 7.0 (N) */) { + AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); + audioManager.registerAudioDeviceCallback(mAudioDeviceCallback, null); + } + } + + private static void unregisterAudioDeviceCallback(Context context) { + if (Build.VERSION.SDK_INT >= 24 /* Android 7.0 (N) */) { + AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); + audioManager.unregisterAudioDeviceCallback(mAudioDeviceCallback); + } + } + /** * This method is called by SDL using JNI. */ - public static int[] audioOpen(int sampleRate, int audioFormat, int desiredChannels, int desiredFrames) { - return open(false, sampleRate, audioFormat, desiredChannels, desiredFrames); + public static int[] getAudioOutputDevices() { + if (Build.VERSION.SDK_INT >= 24 /* Android 7.0 (N) */) { + AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); + return Arrays.stream(audioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS)).mapToInt(AudioDeviceInfo::getId).toArray(); + } else { + return NO_DEVICES; + } + } + + /** + * This method is called by SDL using JNI. + */ + public static int[] getAudioInputDevices() { + if (Build.VERSION.SDK_INT >= 24 /* Android 7.0 (N) */) { + AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); + return Arrays.stream(audioManager.getDevices(AudioManager.GET_DEVICES_INPUTS)).mapToInt(AudioDeviceInfo::getId).toArray(); + } else { + return NO_DEVICES; + } + } + + /** + * This method is called by SDL using JNI. + */ + public static int[] audioOpen(int sampleRate, int audioFormat, int desiredChannels, int desiredFrames, int deviceId) { + return open(false, sampleRate, audioFormat, desiredChannels, desiredFrames, deviceId); } /** @@ -254,6 +360,11 @@ public class SDLAudioManager return; } + if (android.os.Build.VERSION.SDK_INT < 21 /* Android 5.0 (LOLLIPOP) */) { + Log.e(TAG, "Attempted to make an incompatible audio call with uninitialized audio! (floating-point output is supported since Android 5.0 Lollipop)"); + return; + } + for (int i = 0; i < buffer.length;) { int result = mAudioTrack.write(buffer, i, buffer.length - i, AudioTrack.WRITE_BLOCKING); if (result > 0) { @@ -326,18 +437,22 @@ public class SDLAudioManager /** * This method is called by SDL using JNI. */ - public static int[] captureOpen(int sampleRate, int audioFormat, int desiredChannels, int desiredFrames) { - return open(true, sampleRate, audioFormat, desiredChannels, desiredFrames); + public static int[] captureOpen(int sampleRate, int audioFormat, int desiredChannels, int desiredFrames, int deviceId) { + return open(true, sampleRate, audioFormat, desiredChannels, desiredFrames, deviceId); } /** This method is called by SDL using JNI. */ public static int captureReadFloatBuffer(float[] buffer, boolean blocking) { - return mAudioRecord.read(buffer, 0, buffer.length, blocking ? AudioRecord.READ_BLOCKING : AudioRecord.READ_NON_BLOCKING); + if (Build.VERSION.SDK_INT < 23 /* Android 6.0 (M) */) { + return 0; + } else { + return mAudioRecord.read(buffer, 0, buffer.length, blocking ? AudioRecord.READ_BLOCKING : AudioRecord.READ_NON_BLOCKING); + } } /** This method is called by SDL using JNI. */ public static int captureReadShortBuffer(short[] buffer, boolean blocking) { - if (Build.VERSION.SDK_INT < 23) { + if (Build.VERSION.SDK_INT < 23 /* Android 6.0 (M) */) { return mAudioRecord.read(buffer, 0, buffer.length); } else { return mAudioRecord.read(buffer, 0, buffer.length, blocking ? AudioRecord.READ_BLOCKING : AudioRecord.READ_NON_BLOCKING); @@ -346,7 +461,7 @@ public class SDLAudioManager /** This method is called by SDL using JNI. */ public static int captureReadByteBuffer(byte[] buffer, boolean blocking) { - if (Build.VERSION.SDK_INT < 23) { + if (Build.VERSION.SDK_INT < 23 /* Android 6.0 (M) */) { return mAudioRecord.read(buffer, 0, buffer.length); } else { return mAudioRecord.read(buffer, 0, buffer.length, blocking ? AudioRecord.READ_BLOCKING : AudioRecord.READ_NON_BLOCKING); @@ -391,4 +506,9 @@ public class SDLAudioManager } public static native int nativeSetupJNI(); + + public static native void removeAudioDevice(boolean isCapture, int deviceId); + + public static native void addAudioDevice(boolean isCapture, int deviceId); + } diff --git a/android/app/src/main/java/org/libsdl/app/SDLControllerManager.java b/android/app/src/main/java/org/libsdl/app/SDLControllerManager.java index 82373d9d..d6913f15 100644 --- a/android/app/src/main/java/org/libsdl/app/SDLControllerManager.java +++ b/android/app/src/main/java/org/libsdl/app/SDLControllerManager.java @@ -24,7 +24,7 @@ public class SDLControllerManager public static native int nativeAddJoystick(int device_id, String name, String desc, int vendor_id, int product_id, boolean is_accelerometer, int button_mask, - int naxes, int nhats, int nballs); + int naxes, int axis_mask, int nhats, int nballs); public static native int nativeRemoveJoystick(int device_id); public static native int nativeAddHaptic(int device_id, String name); public static native int nativeRemoveHaptic(int device_id); @@ -42,7 +42,7 @@ public class SDLControllerManager public static void initialize() { if (mJoystickHandler == null) { - if (Build.VERSION.SDK_INT >= 19) { + if (Build.VERSION.SDK_INT >= 19 /* Android 4.4 (KITKAT) */) { mJoystickHandler = new SDLJoystickHandler_API19(); } else { mJoystickHandler = new SDLJoystickHandler_API16(); @@ -50,7 +50,7 @@ public class SDLControllerManager } if (mHapticHandler == null) { - if (Build.VERSION.SDK_INT >= 26) { + if (Build.VERSION.SDK_INT >= 26 /* Android 8.0 (O) */) { mHapticHandler = new SDLHapticHandler_API26(); } else { mHapticHandler = new SDLHapticHandler(); @@ -168,6 +168,32 @@ class SDLJoystickHandler_API16 extends SDLJoystickHandler { arg1Axis = MotionEvent.AXIS_GAS; } + // Make sure the AXIS_Z is sorted between AXIS_RY and AXIS_RZ. + // This is because the usual pairing are: + // - AXIS_X + AXIS_Y (left stick). + // - AXIS_RX, AXIS_RY (sometimes the right stick, sometimes triggers). + // - AXIS_Z, AXIS_RZ (sometimes the right stick, sometimes triggers). + // This sorts the axes in the above order, which tends to be correct + // for Xbox-ish game pads that have the right stick on RX/RY and the + // triggers on Z/RZ. + // + // Gamepads that don't have AXIS_Z/AXIS_RZ but use + // AXIS_LTRIGGER/AXIS_RTRIGGER are unaffected by this. + // + // References: + // - https://developer.android.com/develop/ui/views/touch-and-input/game-controllers/controller-input + // - https://www.kernel.org/doc/html/latest/input/gamepad.html + if (arg0Axis == MotionEvent.AXIS_Z) { + arg0Axis = MotionEvent.AXIS_RZ - 1; + } else if (arg0Axis > MotionEvent.AXIS_Z && arg0Axis < MotionEvent.AXIS_RZ) { + --arg0Axis; + } + if (arg1Axis == MotionEvent.AXIS_Z) { + arg1Axis = MotionEvent.AXIS_RZ - 1; + } else if (arg1Axis > MotionEvent.AXIS_Z && arg1Axis < MotionEvent.AXIS_RZ) { + --arg1Axis; + } + return arg0Axis - arg1Axis; } } @@ -210,7 +236,7 @@ class SDLJoystickHandler_API16 extends SDLJoystickHandler { mJoysticks.add(joystick); SDLControllerManager.nativeAddJoystick(joystick.device_id, joystick.name, joystick.desc, getVendorId(joystickDevice), getProductId(joystickDevice), false, - getButtonMask(joystickDevice), joystick.axes.size(), joystick.hats.size()/2, 0); + getButtonMask(joystickDevice), joystick.axes.size(), getAxisMask(joystick.axes), joystick.hats.size()/2, 0); } } } @@ -291,6 +317,9 @@ class SDLJoystickHandler_API16 extends SDLJoystickHandler { public int getVendorId(InputDevice joystickDevice) { return 0; } + public int getAxisMask(List ranges) { + return -1; + } public int getButtonMask(InputDevice joystickDevice) { return -1; } @@ -308,6 +337,43 @@ class SDLJoystickHandler_API19 extends SDLJoystickHandler_API16 { return joystickDevice.getVendorId(); } + @Override + public int getAxisMask(List ranges) { + // For compatibility, keep computing the axis mask like before, + // only really distinguishing 2, 4 and 6 axes. + int axis_mask = 0; + if (ranges.size() >= 2) { + // ((1 << SDL_GAMEPAD_AXIS_LEFTX) | (1 << SDL_GAMEPAD_AXIS_LEFTY)) + axis_mask |= 0x0003; + } + if (ranges.size() >= 4) { + // ((1 << SDL_GAMEPAD_AXIS_RIGHTX) | (1 << SDL_GAMEPAD_AXIS_RIGHTY)) + axis_mask |= 0x000c; + } + if (ranges.size() >= 6) { + // ((1 << SDL_GAMEPAD_AXIS_LEFT_TRIGGER) | (1 << SDL_GAMEPAD_AXIS_RIGHT_TRIGGER)) + axis_mask |= 0x0030; + } + // Also add an indicator bit for whether the sorting order has changed. + // This serves to disable outdated gamecontrollerdb.txt mappings. + boolean have_z = false; + boolean have_past_z_before_rz = false; + for (InputDevice.MotionRange range : ranges) { + int axis = range.getAxis(); + if (axis == MotionEvent.AXIS_Z) { + have_z = true; + } else if (axis > MotionEvent.AXIS_Z && axis < MotionEvent.AXIS_RZ) { + have_past_z_before_rz = true; + } + } + if (have_z && have_past_z_before_rz) { + // If both these exist, the compare() function changed sorting order. + // Set a bit to indicate this fact. + axis_mask |= 0x8000; + } + return axis_mask; + } + @Override public int getButtonMask(InputDevice joystickDevice) { int button_mask = 0; @@ -743,7 +809,7 @@ class SDLGenericMotionListener_API26 extends SDLGenericMotionListener_API24 { @Override public boolean supportsRelativeMouse() { - return (!SDLActivity.isDeXMode() || (Build.VERSION.SDK_INT >= 27)); + return (!SDLActivity.isDeXMode() || Build.VERSION.SDK_INT >= 27 /* Android 8.1 (O_MR1) */); } @Override @@ -753,7 +819,7 @@ class SDLGenericMotionListener_API26 extends SDLGenericMotionListener_API24 { @Override public boolean setRelativeMouseEnabled(boolean enabled) { - if (!SDLActivity.isDeXMode() || (Build.VERSION.SDK_INT >= 27)) { + if (!SDLActivity.isDeXMode() || Build.VERSION.SDK_INT >= 27 /* Android 8.1 (O_MR1) */) { if (enabled) { SDLActivity.getContentView().requestPointerCapture(); } else { diff --git a/android/app/src/main/java/org/libsdl/app/SDLSurface.java b/android/app/src/main/java/org/libsdl/app/SDLSurface.java new file mode 100644 index 00000000..0857e4b6 --- /dev/null +++ b/android/app/src/main/java/org/libsdl/app/SDLSurface.java @@ -0,0 +1,405 @@ +package org.libsdl.app; + + +import android.content.Context; +import android.content.pm.ActivityInfo; +import android.hardware.Sensor; +import android.hardware.SensorEvent; +import android.hardware.SensorEventListener; +import android.hardware.SensorManager; +import android.os.Build; +import android.util.DisplayMetrics; +import android.util.Log; +import android.view.Display; +import android.view.InputDevice; +import android.view.KeyEvent; +import android.view.MotionEvent; +import android.view.Surface; +import android.view.SurfaceHolder; +import android.view.SurfaceView; +import android.view.View; +import android.view.WindowManager; + + +/** + SDLSurface. This is what we draw on, so we need to know when it's created + in order to do anything useful. + + Because of this, that's where we set up the SDL thread +*/ +public class SDLSurface extends SurfaceView implements SurfaceHolder.Callback, + View.OnKeyListener, View.OnTouchListener, SensorEventListener { + + // Sensors + protected SensorManager mSensorManager; + protected Display mDisplay; + + // Keep track of the surface size to normalize touch events + protected float mWidth, mHeight; + + // Is SurfaceView ready for rendering + public boolean mIsSurfaceReady; + + // Startup + public SDLSurface(Context context) { + super(context); + getHolder().addCallback(this); + + setFocusable(true); + setFocusableInTouchMode(true); + requestFocus(); + setOnKeyListener(this); + setOnTouchListener(this); + + mDisplay = ((WindowManager)context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); + mSensorManager = (SensorManager)context.getSystemService(Context.SENSOR_SERVICE); + + setOnGenericMotionListener(SDLActivity.getMotionListener()); + + // Some arbitrary defaults to avoid a potential division by zero + mWidth = 1.0f; + mHeight = 1.0f; + + mIsSurfaceReady = false; + } + + public void handlePause() { + enableSensor(Sensor.TYPE_ACCELEROMETER, false); + } + + public void handleResume() { + setFocusable(true); + setFocusableInTouchMode(true); + requestFocus(); + setOnKeyListener(this); + setOnTouchListener(this); + enableSensor(Sensor.TYPE_ACCELEROMETER, true); + } + + public Surface getNativeSurface() { + return getHolder().getSurface(); + } + + // Called when we have a valid drawing surface + @Override + public void surfaceCreated(SurfaceHolder holder) { + Log.v("SDL", "surfaceCreated()"); + SDLActivity.onNativeSurfaceCreated(); + } + + // Called when we lose the surface + @Override + public void surfaceDestroyed(SurfaceHolder holder) { + Log.v("SDL", "surfaceDestroyed()"); + + // Transition to pause, if needed + SDLActivity.mNextNativeState = SDLActivity.NativeState.PAUSED; + SDLActivity.handleNativeState(); + + mIsSurfaceReady = false; + SDLActivity.onNativeSurfaceDestroyed(); + } + + // Called when the surface is resized + @Override + public void surfaceChanged(SurfaceHolder holder, + int format, int width, int height) { + Log.v("SDL", "surfaceChanged()"); + + if (SDLActivity.mSingleton == null) { + return; + } + + mWidth = width; + mHeight = height; + int nDeviceWidth = width; + int nDeviceHeight = height; + try + { + if (Build.VERSION.SDK_INT >= 17 /* Android 4.2 (JELLY_BEAN_MR1) */) { + DisplayMetrics realMetrics = new DisplayMetrics(); + mDisplay.getRealMetrics( realMetrics ); + nDeviceWidth = realMetrics.widthPixels; + nDeviceHeight = realMetrics.heightPixels; + } + } catch(Exception ignored) { + } + + synchronized(SDLActivity.getContext()) { + // In case we're waiting on a size change after going fullscreen, send a notification. + SDLActivity.getContext().notifyAll(); + } + + Log.v("SDL", "Window size: " + width + "x" + height); + Log.v("SDL", "Device size: " + nDeviceWidth + "x" + nDeviceHeight); + SDLActivity.nativeSetScreenResolution(width, height, nDeviceWidth, nDeviceHeight, mDisplay.getRefreshRate()); + SDLActivity.onNativeResize(); + + // Prevent a screen distortion glitch, + // for instance when the device is in Landscape and a Portrait App is resumed. + boolean skip = false; + int requestedOrientation = SDLActivity.mSingleton.getRequestedOrientation(); + + if (requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT || requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) { + if (mWidth > mHeight) { + skip = true; + } + } else if (requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE || requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) { + if (mWidth < mHeight) { + skip = true; + } + } + + // Special Patch for Square Resolution: Black Berry Passport + if (skip) { + double min = Math.min(mWidth, mHeight); + double max = Math.max(mWidth, mHeight); + + if (max / min < 1.20) { + Log.v("SDL", "Don't skip on such aspect-ratio. Could be a square resolution."); + skip = false; + } + } + + // Don't skip in MultiWindow. + if (skip) { + if (Build.VERSION.SDK_INT >= 24 /* Android 7.0 (N) */) { + if (SDLActivity.mSingleton.isInMultiWindowMode()) { + Log.v("SDL", "Don't skip in Multi-Window"); + skip = false; + } + } + } + + if (skip) { + Log.v("SDL", "Skip .. Surface is not ready."); + mIsSurfaceReady = false; + return; + } + + /* If the surface has been previously destroyed by onNativeSurfaceDestroyed, recreate it here */ + SDLActivity.onNativeSurfaceChanged(); + + /* Surface is ready */ + mIsSurfaceReady = true; + + SDLActivity.mNextNativeState = SDLActivity.NativeState.RESUMED; + SDLActivity.handleNativeState(); + } + + // Key events + @Override + public boolean onKey(View v, int keyCode, KeyEvent event) { + return SDLActivity.handleKeyEvent(v, keyCode, event, null); + } + + // Touch events + @Override + public boolean onTouch(View v, MotionEvent event) { + /* Ref: http://developer.android.com/training/gestures/multi.html */ + int touchDevId = event.getDeviceId(); + final int pointerCount = event.getPointerCount(); + int action = event.getActionMasked(); + int pointerFingerId; + int i = -1; + float x,y,p; + + /* + * Prevent id to be -1, since it's used in SDL internal for synthetic events + * Appears when using Android emulator, eg: + * adb shell input mouse tap 100 100 + * adb shell input touchscreen tap 100 100 + */ + if (touchDevId < 0) { + touchDevId -= 1; + } + + // 12290 = Samsung DeX mode desktop mouse + // 12290 = 0x3002 = 0x2002 | 0x1002 = SOURCE_MOUSE | SOURCE_TOUCHSCREEN + // 0x2 = SOURCE_CLASS_POINTER + if (event.getSource() == InputDevice.SOURCE_MOUSE || event.getSource() == (InputDevice.SOURCE_MOUSE | InputDevice.SOURCE_TOUCHSCREEN)) { + int mouseButton = 1; + try { + Object object = event.getClass().getMethod("getButtonState").invoke(event); + if (object != null) { + mouseButton = (Integer) object; + } + } catch(Exception ignored) { + } + + // We need to check if we're in relative mouse mode and get the axis offset rather than the x/y values + // if we are. We'll leverage our existing mouse motion listener + SDLGenericMotionListener_API12 motionListener = SDLActivity.getMotionListener(); + x = motionListener.getEventX(event); + y = motionListener.getEventY(event); + + SDLActivity.onNativeMouse(mouseButton, action, x, y, motionListener.inRelativeMode()); + } else { + switch(action) { + case MotionEvent.ACTION_MOVE: + for (i = 0; i < pointerCount; i++) { + pointerFingerId = event.getPointerId(i); + x = event.getX(i) / mWidth; + y = event.getY(i) / mHeight; + p = event.getPressure(i); + if (p > 1.0f) { + // may be larger than 1.0f on some devices + // see the documentation of getPressure(i) + p = 1.0f; + } + SDLActivity.onNativeTouch(touchDevId, pointerFingerId, action, x, y, p); + } + break; + + case MotionEvent.ACTION_UP: + case MotionEvent.ACTION_DOWN: + // Primary pointer up/down, the index is always zero + i = 0; + /* fallthrough */ + case MotionEvent.ACTION_POINTER_UP: + case MotionEvent.ACTION_POINTER_DOWN: + // Non primary pointer up/down + if (i == -1) { + i = event.getActionIndex(); + } + + pointerFingerId = event.getPointerId(i); + x = event.getX(i) / mWidth; + y = event.getY(i) / mHeight; + p = event.getPressure(i); + if (p > 1.0f) { + // may be larger than 1.0f on some devices + // see the documentation of getPressure(i) + p = 1.0f; + } + SDLActivity.onNativeTouch(touchDevId, pointerFingerId, action, x, y, p); + break; + + case MotionEvent.ACTION_CANCEL: + for (i = 0; i < pointerCount; i++) { + pointerFingerId = event.getPointerId(i); + x = event.getX(i) / mWidth; + y = event.getY(i) / mHeight; + p = event.getPressure(i); + if (p > 1.0f) { + // may be larger than 1.0f on some devices + // see the documentation of getPressure(i) + p = 1.0f; + } + SDLActivity.onNativeTouch(touchDevId, pointerFingerId, MotionEvent.ACTION_UP, x, y, p); + } + break; + + default: + break; + } + } + + return true; + } + + // Sensor events + public void enableSensor(int sensortype, boolean enabled) { + // TODO: This uses getDefaultSensor - what if we have >1 accels? + if (enabled) { + mSensorManager.registerListener(this, + mSensorManager.getDefaultSensor(sensortype), + SensorManager.SENSOR_DELAY_GAME, null); + } else { + mSensorManager.unregisterListener(this, + mSensorManager.getDefaultSensor(sensortype)); + } + } + + @Override + public void onAccuracyChanged(Sensor sensor, int accuracy) { + // TODO + } + + @Override + public void onSensorChanged(SensorEvent event) { + if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { + + // Since we may have an orientation set, we won't receive onConfigurationChanged events. + // We thus should check here. + int newOrientation; + + float x, y; + switch (mDisplay.getRotation()) { + case Surface.ROTATION_90: + x = -event.values[1]; + y = event.values[0]; + newOrientation = SDLActivity.SDL_ORIENTATION_LANDSCAPE; + break; + case Surface.ROTATION_270: + x = event.values[1]; + y = -event.values[0]; + newOrientation = SDLActivity.SDL_ORIENTATION_LANDSCAPE_FLIPPED; + break; + case Surface.ROTATION_180: + x = -event.values[0]; + y = -event.values[1]; + newOrientation = SDLActivity.SDL_ORIENTATION_PORTRAIT_FLIPPED; + break; + case Surface.ROTATION_0: + default: + x = event.values[0]; + y = event.values[1]; + newOrientation = SDLActivity.SDL_ORIENTATION_PORTRAIT; + break; + } + + if (newOrientation != SDLActivity.mCurrentOrientation) { + SDLActivity.mCurrentOrientation = newOrientation; + SDLActivity.onNativeOrientationChanged(newOrientation); + } + + SDLActivity.onNativeAccel(-x / SensorManager.GRAVITY_EARTH, + y / SensorManager.GRAVITY_EARTH, + event.values[2] / SensorManager.GRAVITY_EARTH); + + + } + } + + // Captured pointer events for API 26. + public boolean onCapturedPointerEvent(MotionEvent event) + { + int action = event.getActionMasked(); + + float x, y; + switch (action) { + case MotionEvent.ACTION_SCROLL: + x = event.getAxisValue(MotionEvent.AXIS_HSCROLL, 0); + y = event.getAxisValue(MotionEvent.AXIS_VSCROLL, 0); + SDLActivity.onNativeMouse(0, action, x, y, false); + return true; + + case MotionEvent.ACTION_HOVER_MOVE: + case MotionEvent.ACTION_MOVE: + x = event.getX(0); + y = event.getY(0); + SDLActivity.onNativeMouse(0, action, x, y, true); + return true; + + case MotionEvent.ACTION_BUTTON_PRESS: + case MotionEvent.ACTION_BUTTON_RELEASE: + + // Change our action value to what SDL's code expects. + if (action == MotionEvent.ACTION_BUTTON_PRESS) { + action = MotionEvent.ACTION_DOWN; + } else { /* MotionEvent.ACTION_BUTTON_RELEASE */ + action = MotionEvent.ACTION_UP; + } + + x = event.getX(0); + y = event.getY(0); + int button = event.getButtonState(); + + SDLActivity.onNativeMouse(button, action, x, y, true); + return true; + } + + return false; + } +} diff --git a/demos/a2600/atari breakbeat.fur b/demos/a2600/atari breakbeat.fur index dd4183be..7dfbb0e3 100644 Binary files a/demos/a2600/atari breakbeat.fur and b/demos/a2600/atari breakbeat.fur differ diff --git a/demos/arcade/Destiny_Islands_Irem_M92.fur b/demos/arcade/Destiny_Islands_Irem_M92.fur new file mode 100644 index 00000000..36d158ec Binary files /dev/null and b/demos/arcade/Destiny_Islands_Irem_M92.fur differ diff --git a/demos/arcade/Some_Creatures_SegaPCM.fur b/demos/arcade/Some_Creatures_SegaPCM.fur new file mode 100644 index 00000000..5578b877 Binary files /dev/null and b/demos/arcade/Some_Creatures_SegaPCM.fur differ diff --git a/demos/arcade/Tubelectric_Fictional_Arcade.fur b/demos/arcade/Tubelectric_Fictional_Arcade.fur index 147c2ed3..08929edd 100644 Binary files a/demos/arcade/Tubelectric_Fictional_Arcade.fur and b/demos/arcade/Tubelectric_Fictional_Arcade.fur differ diff --git a/demos/arcade/UT99_Run_TaitoArcade.fur b/demos/arcade/UT99_Run_TaitoArcade.fur index 2bdf0242..bc46eb3a 100644 Binary files a/demos/arcade/UT99_Run_TaitoArcade.fur and b/demos/arcade/UT99_Run_TaitoArcade.fur differ diff --git a/demos/gameboy/finger.fur b/demos/gameboy/finger.fur new file mode 100644 index 00000000..eb1917a3 Binary files /dev/null and b/demos/gameboy/finger.fur differ diff --git a/demos/genesis/Fancy_Promenard.fur b/demos/genesis/Fancy_Promenard.fur new file mode 100644 index 00000000..f0ec68a9 Binary files /dev/null and b/demos/genesis/Fancy_Promenard.fur differ diff --git a/demos/genesis/Shovel_Knight_Title.fur b/demos/genesis/Shovel_Knight_Title.fur new file mode 100644 index 00000000..f16e971b Binary files /dev/null and b/demos/genesis/Shovel_Knight_Title.fur differ diff --git a/demos/genesis/Stereotactics_Rewritten.fur b/demos/genesis/Stereotactics_Rewritten.fur index 6e078724..f2190c8c 100644 Binary files a/demos/genesis/Stereotactics_Rewritten.fur and b/demos/genesis/Stereotactics_Rewritten.fur differ diff --git a/demos/misc/QSound_smile.fur b/demos/misc/QSound_smile.fur new file mode 100644 index 00000000..b3e361b4 Binary files /dev/null and b/demos/misc/QSound_smile.fur differ diff --git a/demos/msx/OPLL_High_and_Rising.fur b/demos/msx/OPLL_High_and_Rising.fur new file mode 100644 index 00000000..2ecab85b Binary files /dev/null and b/demos/msx/OPLL_High_and_Rising.fur differ diff --git a/demos/msx/Striking_Towards_Opposition.fur b/demos/msx/Striking_Towards_Opposition.fur new file mode 100644 index 00000000..40dee380 Binary files /dev/null and b/demos/msx/Striking_Towards_Opposition.fur differ diff --git a/demos/multichip/Jet_Pack_Adventure_GBAesque.fur b/demos/multichip/Jet_Pack_Adventure_GBAesque.fur index 928c4bd6..8f430813 100644 Binary files a/demos/multichip/Jet_Pack_Adventure_GBAesque.fur and b/demos/multichip/Jet_Pack_Adventure_GBAesque.fur differ diff --git a/demos/opl/Fly_to_the_Leaden_Sky_OPL3.fur b/demos/opl/Fly_to_the_Leaden_Sky_OPL3.fur new file mode 100644 index 00000000..4546a270 Binary files /dev/null and b/demos/opl/Fly_to_the_Leaden_Sky_OPL3.fur differ diff --git a/demos/opl/Sliding_on_a_Rainbow.fur b/demos/opl/Sliding_on_a_Rainbow.fur new file mode 100644 index 00000000..934fda70 Binary files /dev/null and b/demos/opl/Sliding_on_a_Rainbow.fur differ diff --git a/demos/snes/Cosmic_Warehouse.fur b/demos/snes/Cosmic_Warehouse.fur new file mode 100644 index 00000000..f5c277d6 Binary files /dev/null and b/demos/snes/Cosmic_Warehouse.fur differ diff --git a/demos/snes/MM8_Frost_Man.fur b/demos/snes/MM8_Frost_Man.fur index bad1ceee..f49221ee 100644 Binary files a/demos/snes/MM8_Frost_Man.fur and b/demos/snes/MM8_Frost_Man.fur differ diff --git a/demos/snes/changeyourheart.fur b/demos/snes/changeyourheart.fur new file mode 100644 index 00000000..7b671c3a Binary files /dev/null and b/demos/snes/changeyourheart.fur differ diff --git a/demos/x16/Cafe - 010 Editor 2.0kg.fur b/demos/x16/Cafe - 010 Editor 2.0kg.fur index 6533a384..ef1c9fea 100644 Binary files a/demos/x16/Cafe - 010 Editor 2.0kg.fur and b/demos/x16/Cafe - 010 Editor 2.0kg.fur differ diff --git a/demos/x16/her11.fur b/demos/x16/her11.fur index 1cfabac1..06c4870f 100644 Binary files a/demos/x16/her11.fur and b/demos/x16/her11.fur differ diff --git a/demos/x16/keygen19.fur b/demos/x16/keygen19.fur new file mode 100644 index 00000000..26d04ea8 Binary files /dev/null and b/demos/x16/keygen19.fur differ diff --git a/doc/1-intro/README.md b/doc/1-intro/README.md new file mode 100644 index 00000000..34658ece --- /dev/null +++ b/doc/1-intro/README.md @@ -0,0 +1,21 @@ +# introduction + +Furnace is a tool which allows you to create music using sound chips ("chiptune"), most from the 8/16-bit era. + +it has a large selection of features and sound chips. from the NES, SNES and Genesis to ES5506, VIC-20 or even Arcade, Furnace has most likely covered your target with many presets to choose from. + +every chip is emulated using many emulation cores, therefore the sound that Furnace produces is authentic to that of real hardware. + +## hexadecimal + +Furnace uses hexadecimal (abbreviated as "hex") numbers frequently. see [this guide](hex.md) for a crash course. + +## interface + +Furnace uses a music tracker interface. think of a table with music notes written on it. then that table scrolls up and plays the notes. even experienced tracker musicians might benefit from a quick review of [tracker concepts and terms](concepts.md) before using Furnace. + +due to its nature of being feature-packed, it may be technical and somewhat difficult to get around. therefore we added a basic mode, which hides several advanced features. + +it also has a flexible windowing system which you may move around and organize. + +see [2-interface](../2-interface/README.md) and [3-pattern](../3-pattern/README.md) for more information. diff --git a/doc/1-intro/concepts.md b/doc/1-intro/concepts.md new file mode 100644 index 00000000..130e2ae8 --- /dev/null +++ b/doc/1-intro/concepts.md @@ -0,0 +1,36 @@ +# concepts and terms + +- A **module** is a file for a tracker that contains at least one **song**. +- Each Furnace module involves at least one **[chip](../7-systems/README.md)**, an emulation of a specific audio processor. + +## tracking + +The **[pattern view](../3-pattern/README.md)** is like a spreadsheet that displays the following: +- Each labeled column represents a **channel** of sound provided by the chips in use. +- Each **note** starts a sound playing. Within a channel, only one note can play at a time. +- Each note is assigned an **[instrument](../4-instrument/README.md)** which describes what it will sound like. +- An **effect** is a command that changes some aspect of playback. It can alter note pitch, volume, timing, and more. +- An instrument **macro** is an automated sequence of effects that applies to every note of that instrument. + +## structure + +The **order list** is a smaller spreadsheet showing the overall song structure. +- A song is made up of a list of **orders**. +- An **order** is a set of numbered **patterns** used for each channel. +- Each channel has its own unique list of patterns. +- Each pattern contains note and effect data for that channel only. +- Patterns may be used multiple times in the order list. Changing a pattern's data in one order will affect the same pattern used in other orders. + +## time + +- Each pattern is made of the same number of **rows** as seen in the tracker view. +- During playback, Each row lasts a number of **ticks** determined by its **speed** value. +- A tick is the smallest measure of time to which all note, effect, and macro times are quantized. + +## sound + +Different chips have different capabilities. Even within the same chip, each channel may have its own ways of making sound. +- Some channels use one or more waveform **generators** (sine, square, noise...) to build up a sound. +- Of special note are **[FM (frequency modulation)](../4-instrument/fm.md)** channels, which use a number of generators called **operators** that can interact to make very complex sounds. +- Some channels use **[samples](../6-sample/README.md)** - recordings of sounds, often with defined loop points to allow a note to sustain. +- Some channels use **[wavetables](../5-wave/README.md)**, which are like very short samples of fixed length that automatically loop. \ No newline at end of file diff --git a/doc/1-intro/hex.md b/doc/1-intro/hex.md new file mode 100644 index 00000000..6139ca87 --- /dev/null +++ b/doc/1-intro/hex.md @@ -0,0 +1,97 @@ +# hexadecimal + +the hexadecimal numeral system differs from the decimal system by having 16 digits rather than 10: + +``` +hex| decimal +---|--------- + 0 | 0 + 1 | 1 + 2 | 2 + 3 | 3 + 4 | 4 + 5 | 5 + 6 | 6 + 7 | 7 + 8 | 8 + 9 | 9 + A | 10 + B | 11 + C | 12 + D | 13 + E | 14 + F | 15 +``` + +when there is more than one digit, these are multiplied by 16, 256, 4096 and so on rather than 10, 100, 1000: + +``` +hex | decimal +----|--------- + 00 | 0 + 04 | 4 + 08 | 8 + 0F | 15 + 10 | 16 + 11 | 17 + 12 | 18 + 13 | 19 + 20 | 32 + 30 | 48 + 40 | 64 +``` + +# hex to decimal + +for example, take hexadecimal number `AA`: + +``` + 2nd digit -\ /- 1st digit + A A + 16^1*10 = 16*10 = 160 + 10 = 170 +``` + +now for hexadecimal number `4C5F`: + +``` + + 3rd digit -\ /- 2nd digit + 4th digit -\ | | /- 1st digit + 4 C 5 F + | | | | + | | | 15 = 15 = 15 + + | | \16^1*5 = 16 * 5 = 80 + | \--- 16^2*12 = 256 * 12 = 3072 + \--------- 16^3*4 = 4096 * 4 = 16384 + ------- + = 19551 +``` + +# decimal to hex + +if it's less than 16, just memorize the table at the top of this document. + +otherwise find the power of 16 that is closest to the number you want to convert, but no larger than the number. +then divide, and take the remainder. +divide the remainder with the previous power of 16, until the divider is 1. + +for example, for the decimal number `220`: + +``` +220 ÷ 16 = 13 (r = 12) D + 12 ÷ 1 = 12 (stop here) C + += DC +``` + +now for decimal number `69420`: + +``` +69420 ÷ 65536 = 1 (r = 3884) 1 + 3884 ÷ 4096 = 0 (r = 3884) 0 + 3884 ÷ 256 = 15 (r = 44) F + 44 ÷ 16 = 2 (r = 12) 2 + 12 ÷ 1 = 12 (stop here) C + += 10F2C +``` diff --git a/doc/2-interface/README.md b/doc/2-interface/README.md new file mode 100644 index 00000000..2ff1ebfc --- /dev/null +++ b/doc/2-interface/README.md @@ -0,0 +1,41 @@ +# interface + +the Furnace user interface is where the job gets done. + +the default layout of Furnace is depicted below. + +![interface](interface1.png) + +primary topics: + +- [menu bar](menu-bar.md) +- [play/edit controls](play-edit-controls.md) +- [instrument/wavetable/sample list](asset-list.md) +- [song information](song-info.md) +- [pattern view](../3-pattern/README.md) +- [instrument editor](../4-instrument/README.md) +- [wavetable editor](../5-wave/README.md) +- [sample editor](../6-sample/README.md) + +advanced topics: + +- [mixer](../8-advanced/mixer.md) +- [grooves](../8-advanced/grooves.md) +- [channels](../8-advanced/channels.md) +- [pattern manager](../8-advanced/pat-manager.md) +- [chip manager](../8-advanced/chip-manager.md) +- [compatibility flags](../8-advanced/compat-flags.md) +- [song comments](../8-advanced/comments.md) +- [piano/input pad](../8-advanced/piano.md) +- [oscilloscope](../8-advanced/osc.md) +- [oscilloscope (per channel)](../8-advanced/chanosc.md) +- [clock](../8-advanced/clock.md) +- [register view](../8-advanced/regview.md) +- [log viewer](../8-advanced/log-viewer.md) +- [statistics](../8-advanced/stats.md) + +other topics: + +- [UI components](components.md) +- [global keyboard shortcuts](keyboard.md) +- [basic mode](basic-mode.md) diff --git a/doc/2-interface/asset-add.png b/doc/2-interface/asset-add.png new file mode 100644 index 00000000..f6ef5b73 Binary files /dev/null and b/doc/2-interface/asset-add.png differ diff --git a/doc/2-interface/asset-delete.png b/doc/2-interface/asset-delete.png new file mode 100644 index 00000000..d0eb8dd9 Binary files /dev/null and b/doc/2-interface/asset-delete.png differ diff --git a/doc/2-interface/asset-duplicate.png b/doc/2-interface/asset-duplicate.png new file mode 100644 index 00000000..caa740fb Binary files /dev/null and b/doc/2-interface/asset-duplicate.png differ diff --git a/doc/2-interface/asset-folderview.png b/doc/2-interface/asset-folderview.png new file mode 100644 index 00000000..8d693e0f Binary files /dev/null and b/doc/2-interface/asset-folderview.png differ diff --git a/doc/2-interface/asset-list.md b/doc/2-interface/asset-list.md new file mode 100644 index 00000000..936c4a32 --- /dev/null +++ b/doc/2-interface/asset-list.md @@ -0,0 +1,38 @@ +# instrument list + +![instruments window](instruments.png) + +Buttons from left to right: +- **Add**: Creates a new, default instrument. +- **Duplicate**: Duplicates the currently selected instrument. +- **Open**: Brings up a file dialog to load a file as a new instrument at the end of the list. +- **Save**: Brings up a file dialog to save the currently selected instrument. +- **Toggle folders/standard view**: Enables (and disables) folder view, explained below. +- **Move up**: Moves the currently selected instrument up in the list. Pattern data will automatically be adjusted to match. +- **Move down**: Same, but downward. +- **Delete**: Deletes the currently selected instrument. Pattern data will be adjusted to use the next available instrument in the list. + +## folder view + +![instruments window in folder view](instruments-folder.png) + +In folder view, the "Move up" and "Move down buttons disappear and a new one appears: +- **New folder**: Creates a new folder. + +Instruments may be dragged from folder to folder and even rearranged within folders without changing their associated numbers. + +Right-clicking on a folder allows one to rename or delete it. Deleting a folder does not remove the instruments in it. + +# wavetable list + +![wavetables window](wavetables.png) + +Everything from the instrument list applies here also, with one major difference: Moving waves around with the buttons will change their associated numbers in the list but _not_ in pattern or instrument data. Be careful! + +# sample list + +![samples window](samples.png) + +Everything from the wavetables list applies here also, with the addition of two buttons: +- **Preview**: Plays the selected sample at its default note. +- **Stop preview**: Stops the sample playback. diff --git a/doc/2-interface/asset-move.png b/doc/2-interface/asset-move.png new file mode 100644 index 00000000..fdcbca6a Binary files /dev/null and b/doc/2-interface/asset-move.png differ diff --git a/doc/2-interface/asset-newfolder.png b/doc/2-interface/asset-newfolder.png new file mode 100644 index 00000000..01540abd Binary files /dev/null and b/doc/2-interface/asset-newfolder.png differ diff --git a/doc/2-interface/asset-open.png b/doc/2-interface/asset-open.png new file mode 100644 index 00000000..eea98514 Binary files /dev/null and b/doc/2-interface/asset-open.png differ diff --git a/doc/2-interface/asset-preview.png b/doc/2-interface/asset-preview.png new file mode 100644 index 00000000..8636285c Binary files /dev/null and b/doc/2-interface/asset-preview.png differ diff --git a/doc/2-interface/asset-previewstop.png b/doc/2-interface/asset-previewstop.png new file mode 100644 index 00000000..02fe6498 Binary files /dev/null and b/doc/2-interface/asset-previewstop.png differ diff --git a/doc/2-interface/asset-save.png b/doc/2-interface/asset-save.png new file mode 100644 index 00000000..19dd03e9 Binary files /dev/null and b/doc/2-interface/asset-save.png differ diff --git a/papers/doc/2-interface/basic-mode.md b/doc/2-interface/basic-mode.md similarity index 93% rename from papers/doc/2-interface/basic-mode.md rename to doc/2-interface/basic-mode.md index a8b0402f..c764d9de 100644 --- a/papers/doc/2-interface/basic-mode.md +++ b/doc/2-interface/basic-mode.md @@ -1,6 +1,6 @@ # basic mode -Furnace comes with a "basic mode" that can be toggled through the "settings" menu. it disables certain features in Furnace that may look intimidating or confusing for newcomers. if you find that a certain feature of furnace is missing, see if this setting is enabled or not. +Furnace comes with a "basic mode" that can be toggled through the "settings" menu. it disables certain features in Furnace that may look intimidating or confusing for newcomers. if you find that a certain feature of Furnace is missing, see if this setting is enabled or not. among the features that cannot be accessed in this mode are: * file menu: diff --git a/papers/doc/2-interface/components.md b/doc/2-interface/components.md similarity index 72% rename from papers/doc/2-interface/components.md rename to doc/2-interface/components.md index 0243662b..c2fce999 100644 --- a/papers/doc/2-interface/components.md +++ b/doc/2-interface/components.md @@ -4,14 +4,14 @@ the user interface consists of several components. this paper describes some of ## windows -TODO: image +![window](window.png) windows may be moved, collapsed, closed or even docked around the workspace. to move a window, press and hold the mouse button while on title bar or any empty space on it. then drag your mouse, and release it to stop moving. -to resize a window, drag any of the bottom corners (marked by triangular tabs). +to resize a window, drag the bottom right corner (marked by a triangular tab) or the borders. to collapse a window, click on the triangle in the title bar. clicking again expands it. @@ -24,33 +24,40 @@ windows may be docked, which comes in handy. to dock a window, drag it from its title bar to another location in the workspace or to the location of another window. -while dragging, an overlay with five options will appear, allowing you to select where and how to dock that window. +while dragging, an overlay with some options will appear, allowing you to select where and how to dock that window. the options are: -``` - UP - LEFT CENTER RIGHT - DOWN -``` +![docking options](docking.png) drag your mouse cursor to any of the options to dock the window. -if you drag the window to `CENTER`, the window will be maximized to cover the workspace (if you do this on the workspace), or it will appear as another tab (if you do this on a window). +if you drag to the sides (marked with blue text), the window will cover that side of the workspace. + +if you drag it to a window or empty space (marked with yellow text), five docking positions will appear. + +if you drag the window to the center of another window, it will appear as another tab. + +if you drag the window to the center of empty space, the window will cover aforementioned empty space. otherwise the window will be split in two, with the first half covered by the window you docked and the second half covered by the other window. +![tab1](tab1.png) + when a window is docked, its title bar turns into a tab bar, and the function provided by the "collapse" triangle at the top left changes. -if this triangle is clicked, a menu will appear with a single option: "Hide tab bar". +![tab2](tab2.png) + +if this triangle is clicked, a menu will appear with a list of tabs, or a single option if there's only one tab: "Hide tab bar". selecting this option will hide the tab bar of that window. + +![tab3](tab3.png) + to bring it back, click on the top left corner. to undock a window, drag its tab away from where it is docked. then it will be floating again. ## text fields -TODO: image - text fields are able to hold... text. click on a text field to start editing, and click away to stop editing. @@ -60,24 +67,18 @@ the following keyboard shortcuts work while on a text field: - `Ctrl-X`: cut - `Ctrl-C`: copy - `Ctrl-V`: paste -- `Ctrl-Z`: undo -- `Ctrl-Y`: redo - `Ctrl-A`: select all (replace Ctrl with Command on macOS) ## number input fields -TODO: image - these work similar to text fields, but you may only input numbers. they also usually have two buttons which allow you to increase/decrease the amount when clicked (and rapidly do so when click-holding). ## sliders -TODO: image - sliders are used for controlling values in a quick manner by being dragged. alternatively, right-clicking or Ctrl-clicking or a slider (Command-click on macOS) will turn it into a number input field for a short period of time, allowing you to input fine values. diff --git a/doc/2-interface/control-edit.png b/doc/2-interface/control-edit.png new file mode 100644 index 00000000..e3e2d177 Binary files /dev/null and b/doc/2-interface/control-edit.png differ diff --git a/doc/2-interface/control-metronome.png b/doc/2-interface/control-metronome.png new file mode 100644 index 00000000..51822c0e Binary files /dev/null and b/doc/2-interface/control-metronome.png differ diff --git a/doc/2-interface/control-play-pattern.png b/doc/2-interface/control-play-pattern.png new file mode 100644 index 00000000..a11f0aab Binary files /dev/null and b/doc/2-interface/control-play-pattern.png differ diff --git a/doc/2-interface/control-play-repeat.png b/doc/2-interface/control-play-repeat.png new file mode 100644 index 00000000..fc286590 Binary files /dev/null and b/doc/2-interface/control-play-repeat.png differ diff --git a/doc/2-interface/control-play.png b/doc/2-interface/control-play.png new file mode 100644 index 00000000..c258b5fd Binary files /dev/null and b/doc/2-interface/control-play.png differ diff --git a/doc/2-interface/control-repeat.png b/doc/2-interface/control-repeat.png new file mode 100644 index 00000000..2a6a96ad Binary files /dev/null and b/doc/2-interface/control-repeat.png differ diff --git a/doc/2-interface/control-step.png b/doc/2-interface/control-step.png new file mode 100644 index 00000000..e2d86be3 Binary files /dev/null and b/doc/2-interface/control-step.png differ diff --git a/doc/2-interface/control-stop.png b/doc/2-interface/control-stop.png new file mode 100644 index 00000000..e124c60d Binary files /dev/null and b/doc/2-interface/control-stop.png differ diff --git a/doc/2-interface/controls-classic.png b/doc/2-interface/controls-classic.png new file mode 100644 index 00000000..37295e0d Binary files /dev/null and b/doc/2-interface/controls-classic.png differ diff --git a/doc/2-interface/controls-compact.png b/doc/2-interface/controls-compact.png new file mode 100644 index 00000000..7d9c7cca Binary files /dev/null and b/doc/2-interface/controls-compact.png differ diff --git a/doc/2-interface/controls-split.png b/doc/2-interface/controls-split.png new file mode 100644 index 00000000..2b3fab40 Binary files /dev/null and b/doc/2-interface/controls-split.png differ diff --git a/doc/2-interface/controls-vertical.png b/doc/2-interface/controls-vertical.png new file mode 100644 index 00000000..6dfd5770 Binary files /dev/null and b/doc/2-interface/controls-vertical.png differ diff --git a/doc/2-interface/docking.png b/doc/2-interface/docking.png new file mode 100644 index 00000000..bc8eb141 Binary files /dev/null and b/doc/2-interface/docking.png differ diff --git a/doc/2-interface/instruments-folder.png b/doc/2-interface/instruments-folder.png new file mode 100644 index 00000000..a2fbb5ab Binary files /dev/null and b/doc/2-interface/instruments-folder.png differ diff --git a/doc/2-interface/instruments.png b/doc/2-interface/instruments.png new file mode 100644 index 00000000..00102e54 Binary files /dev/null and b/doc/2-interface/instruments.png differ diff --git a/doc/2-interface/interface1.png b/doc/2-interface/interface1.png new file mode 100644 index 00000000..1c2abf07 Binary files /dev/null and b/doc/2-interface/interface1.png differ diff --git a/papers/doc/2-interface/keyboard.md b/doc/2-interface/keyboard.md similarity index 100% rename from papers/doc/2-interface/keyboard.md rename to doc/2-interface/keyboard.md diff --git a/doc/2-interface/menu-bar.md b/doc/2-interface/menu-bar.md new file mode 100644 index 00000000..8fac9e65 --- /dev/null +++ b/doc/2-interface/menu-bar.md @@ -0,0 +1,226 @@ +# menu bar + +the menu bar allows you to select five menus: file, edit, settings, window and help. + +# file + +- **new...**: create a new song. +- **open...**: opens the file picker, allowing you to select a song to open. +- **open recent**: contains a list of the songs you've opened before. + - **clear history**: this option erases the file history. +- **save**: saves the current song. + - opens the file picker if this is a new song, or a backup. +- **save as...**: opens the file picker, allowing you to save the song under a different name. +- **save as .dmf (1.1.3+)...**: opens the file picker, allowing you to save your song as a .dmf which is compatible with DefleMask 1.1.3 onwards. + - this will only work with the systems mentioned in the next option, plus: + - Sega Master System (with FM expansion) + - NES + Konami VRC7 + - Famicom Disk System + - only use this option if you really need it. there are features which DefleMask does not support, like some effects and FM macros, so these will be lost. +- **save as .dmf (1.0/legacy)...**: opens the file picker, allowing you to save your song as a .dmf which is compatible with DefleMask Legacy (0.12) or 1.0. + - this will only work on the following systems: + - Sega Genesis/Mega Drive (YM2612 + SN76489) + - Sega Genesis/Mega Drive (YM2612 + SN76489, extended channel 3) + - Sega Master System + - Game Boy + - PC Engine + - NES + - Commodore 64 + - Arcade (YM2151 + SegaPCM 5-channel compatibility) + - Neo Geo CD (DefleMask 1.0+) + - only use this option if you really need it. there are features which DefleMask does not support, like some effects and FM macros, so these will be lost. +- **export audio...**: export your song to a .wav file. see next section for more details. +- **export VGM...**: export your song to a .vgm file. see next section for more details. +- **export ZSM...**: export your song to a .zsm file. see next section for more details. + - only available when there's a YM2151 and/or VERA. +- **export command stream...**: export song data to a command stream file. see next section for more details. + - this option is for developers. +- **add chip...**: add a chip to the current song. +- **configure chip...**: set a chip's parameters. + - for a list of parameters, see [7-systems](../7-systems/README.md). +- **change chip...**: change a chip to another. + - **Preserve channel positions**: enable this option to make sure Furnace does not auto-arrange/delete channels to compensate for differing channel counts. this can be useful for doing ports, e.g. from Genesis to PC-98. +- **remove chip...**: remove a chip. + - **Preserve channel positions**: same thing as above. +- **restore backup**: restore a previously saved backup. + - Furnace keeps up to 5 backups of a song. + - the backup directory is located in: + - Windows: `%USERPROFILE%\AppData\Roaming\furnace\backups` + - macOS: `~/Library/Application Support/Furnace/backups` + - Linux/other: `~/.config/furnace/backups` + - this directory grows in size as you use Furnace. remember to delete old backups periodically to save space. +- **exit**: I think you know what this does. + +## export audio + +this option allows you to export your song in .wav format. I know I know, no .mp3 or .ogg export yet, but you can use a converter. + +there are two parameters: + +- **Loops**: sets the number of times the song will loop. + - does not have effect if the song ends with `FFxx` effect. +- **Fade out (seconds)**: sets the fade out time when the song is over. + - does not have effect if the song ends with `FFxx` effect. + +and three export choices: + +- **one file**: exports your song to one .wav file. +- **multiple files (one per chip)**: exports the output of each chip to .wav files. +- **multiple files (one per channel)**: exports the output of each channel to .wav files. + - useful for usage with a channel visualizer such as corrscope. + +## export VGM + +this option allows exporting to a VGM (Video Game Music) file. these can be played back with VGMPlay (for example). + +the following settings exist: + +- **format version**: sets the VGM format version to use. + - versions under 1.70 do not support per-chip volumes, and therefore will ignore the Mixer completely. + - other versions may not support all chips. + - use this option if you need to export for a quirky player or parser. + - for example, RYMCast is picky with format versions. if you're going to use this player, select 1.60. +- **loop**: writes loop. if disabled, the resulting file won't loop. +- **loop trail**: this option allows you to set how much of the song is written after it loops. + - the reason this exists is to work around a VGM format limitation in where post-loop state isn't recorded at all. + - this may change the song length as it appears on a player. + - **auto-detect**: detect how much to write automatically. + - **add one loop**: add one more loop. + - **custom**: allows you to specify how many ticks to add. + - `0` is effectively none, disabling loop trail completely. + - this option will not appear if the loop modality isn't set to None as there wouldn't be a need to. +- **chips to export**: select which chips are going to be exported. + - due to VGM format limitations, you can only select up to two of each chip type. + - some chips will not be available, either because VGM doesn't support these yet, or because you selected an old format version. +- **add pattern change hints**: this option adds a "hint" when a pattern change occurs. only useful if you're a developer. + - the format of the "hint" data block that gets written is: `67 66 FE ll ll ll ll 01 oo rr pp pp pp ...` + - ll: length, a 32-bit little-endian number + - oo: order + - rr: initial row (a 0Dxx effect is able to select a different row) + - pp: pattern index (one per channel) +- **direct stream mode**: this option allows DualPCM to work. don't use this for other chips. + - may or may not play well with hardware VGM players. + +click on **click to export** to begin exporting. + +## export ZSM + +ZSM (ZSound Music) is a format designed for the Commander X16 to allow hardware playback. +it may contain data for either YM2151 or VERA chips. +Calliope is one of the programs that supports playback of ZSM files. + +the following settings are available: + +- **Tick Rate (Hz)**: select the tick rate the song will run at. + - I suggest you use the same rate as the song's. + - apparently ZSM doesn't support changing the rate mid-song. +- **loop**: enables loop. if disabled, the song won't loop. + +click on **Begin Export** to... you know. + +## export command stream + +this option exports a text or binary file which contains a dump of the internal command stream produced when playing the song. + +it's not really useful, unless you're a developer and want to use a command stream dump for some reason (e.g. writing a hardware sound driver). + +- **export (binary)**: exports in Furnace's own command stream format (FCS). see `export-tech.md` in `papers/` for details. +- **export (text)**: exports the command stream as a text file. only useful for analysis, really. + +# edit + +- **undo**: reverts the last action. +- **redo**: repeats what you undid previously. +- **cut**: moves the current selection in the pattern view to clipboard. +- **copy**: copies the current selection in the pattern view to clipboard. +- **paste**: inserts the clipboard's contents in the cursor position. +- **paste special...**: variants of the paste feature. + - **paste mix**: inserts the clipboard's contents in the cursor position, but does not erase the occupied region. + - **paste mix (background)**: does the same thing as paste mix, but doesn't alter content which is already there. + - **paste with ins (foreground)**: same thing as paste mix, but changes the instrument. + - **paste with ins (background)**: same thing as paste mix (background), but changes the instrument. + - **paste flood**: inserts the clipboard's contents in the cursor position, and repeats until it hits the end of a pattern. + - **paste overflow**: paste, but it will keep pasting even if it runs over another pattern. +- **delete**: clears the contents in the selection. +- **select all**: changes the selection so it covers a larger area. + - if the selection is wide, it will select the rows in a column. + - if the selection is tall, it will select the entire column. + - if a column is already selected, it will select the entire channel. + - if a channel is already selected, it will select the entire pattern. +- **operation mask**: this is an advanced feature. see [this page](../3-pattern/opmask.md) for more information. +- **input latch**: this is an advanced feature. see [this page](../3-pattern/inputlatch.md) for more information. +- **note/octave up/down**: transposes notes in the current selection. +- **values up/down**: changes values in the current selection by ±1 or ±16. +- **transpose**: transpose notes or change values by a specific amount. +- **interpolate**: fills in gaps in the selection by interpolation between values. +- **change instrument**: changes the instrument number in a selection. +- **gradient/fade**: replace the selection with a "gradient" that goes from the beginning of the selection to the end. + - does not affect the note column. + - **Nibble mode**: when enabled, the fade will be per-nibble (0 to F) rather than per-value (00 to FF). + - use for effects like `04xy` (vibrato). +- **scale**: scales values in the selection by a specific amount. + - use to change volume in a selection for example. +- **randomize**: replaces the selection with random values. + - does not affect the note column. +- **invert values**: `00` becomes `FF`, `01` becomes `FE`, `02` becomes `FD` and so on. +- **flip selection**: flips the selection so it is backwards. +- **collapse/expand amount**: allows you to specify how much to collapse/expand in the next options. +- **collapse**: shrinks the selected contents. +- **expand**: expands the selected contents. +- **collapse pattern**: same as collapse, but affects the entire pattern. +- **expand pattern**: same as expand, but affects the entire pattern. +- **collapse song**: same as collapse, but affects the entire song. + - it also changes speeds and pattern length to compensate. +- **expand song**: same as expand, but affects the entire song. + - it also changes speeds and pattern length to compensate. +- **find/replace**: opens the Find/Replace window. see [this page](../3-pattern/find-replace.md) for more information. +- **clear**: allows you to mass-delete things like songs, instruments and the like. + +# settings + +- **full screen**: expands the Furnace window so it covers your screen. +- **lock layout**: prevents you from dragging/resizing docked windows, or docking more. +- **basic mode**: toggles [Basic Mode](basic-mode.md). +- **visualizer**: toggles pattern view particle effects when the song plays. +- **reset layout**: resets the workspace to its defaults. +- **settings...**: opens the Settings window. + +# window + +- **song information**: shows/hides the Song Information window. +- **subsongs**: shows/hides the Subsongs window. +- **speed**: shows/hides the Speed window. +- **instruments**: shows/hides the instrument list. +- **wavetables**: shows/hides the wavetable list. +- **samples**: shows/hides the sample list. +- **orders**: shows/hides the Orders window. +- **pattern**: shows/hides the pattern view. +- **mixer**: shows/hides the Mixer window. +- **grooves**: shows/hides the Grooves window. +- **channels**: shows/hides the Channels window. +- **pattern manager**: shows/hides the Pattern Manager window. +- **chip manager**: shows/hides the Chip Manager window. +- **compatibility flags**: shows/hides the Compatibility Flags window. +- **song comments**: shows/hides the Song Comments window. +- **instrument editor**: shows/hides the Instrument Editor. +- **wavetable editor**: shows/hides the Wavetable Editor. +- **sample editor**: shows/hides the Sample Editor. +- **play/edit controls**: shows/hides the Play/Edit Controls. +- **piano/input pad**: shows/hides the Piano/Input Pad window. +- **oscilloscope (master)**: shows/hides the oscilloscope. +- **oscilloscope (per-channel)**: shows/hides the per-channel oscilloscope. +- **volume meter**: shows/hides the volume meter. +- **clock**: shows/hides the clock. +- **register view**: shows/hides the Register View window. +- **log viewer**: shows/hides the log Viewer. +- **statistics**: shows/hides the Statistics window. + +# help + +- **effect list**: displays the effect list. +- **debug menu**: this menu contains various debug utilities. + - unless you are working with the Furnace codebase, it's not useful. +- **inspector**: this options opens the Dear ImGui Metrics/Debugger window. + - unless you are working with the Furnace codebase, it's not useful. +- **panic**: this resets all chips while the song is playing, effectively silencing everything. +- **about...**: displays the About screen. diff --git a/doc/2-interface/play-edit-controls.md b/doc/2-interface/play-edit-controls.md new file mode 100644 index 00000000..038c458e --- /dev/null +++ b/doc/2-interface/play-edit-controls.md @@ -0,0 +1,37 @@ +# play/edit controls + +The "Play/Edit Controls" are used to control playback and change parameters of the pattern view. + +- ![](control-play.png) **Play**: Plays from cursor position. +- ![](control-stop.png) **Stop**: Stops all playback. +- ![](control-play-pattern.png) **Play from the beginning of this pattern**: Plays from the start of current pattern. +- ![](control-play-repeat.png) **Repeat from the beginning of this pattern**: Repeats current pattern from its start. +- ![](control-step.png) **Step one row**: Plays only the row at cursor position and moves down one. +- ![](control-edit.png) **Edit**: Toggles edit mode. If off, nothing can be edited in the pattern window. (Great for playing around on the keyboard!) +- ![](control-metronome.png) **Metronome**: Toggles the metronome, which only sounds during playback. +- ![](control-repeat.png) **Repeat pattern**: Toggles pattern repeat. During playback while this is on, the current pattern will play over and over instead of following the order list. +- **Poly**: Turns on polyphony for previewing notes. Toggles to **Mono** for monophony (one note at a time only). +- **Octave**: Sets current input octave. +- **Step**: Sets edit step. If this is 1, entering a note or effect will move to the next row. If this is a larger number, rows will be skipped. If this is 0, the cursor will stay in place. +- **Follow orders**: If on, the selected order in the orders window will follow the song during playback. +- **Follow pattern**: If on, the cursor will follow playback and the song will scroll by as it plays. + +## layouts + +The layout can be changed in Settings > Appearance to one of these: + +### classic + +![classic play/edit controls](controls-classic.png) + +### compact + +![compact play/edit controls](controls-compact.png) + +### compact (vertical) + +![compact vertical play/edit controls](controls-vertical.png) + +### split + +![split play and edit controls](controls-split.png) diff --git a/doc/2-interface/samples.png b/doc/2-interface/samples.png new file mode 100644 index 00000000..2be62a9b Binary files /dev/null and b/doc/2-interface/samples.png differ diff --git a/doc/2-interface/song-info.md b/doc/2-interface/song-info.md new file mode 100644 index 00000000..7919e7be --- /dev/null +++ b/doc/2-interface/song-info.md @@ -0,0 +1,49 @@ +# song info + +- **Name**: The track's title. +- **Author**: List of contributors to a song. If the song is a cover of someone else's track, it's customary to list their name first, followed by `[cv. YourName]`. +- **Album**: The associated album name, the name of the game the song is from, or whatever. +- **System**: The game console or computer the track is designed for. This is automatically set when creating a new tune, but it can be changed to anything one wants. The **Auto** button will provide a guess based on the chips in use. + +All of this metadata will be included in a VGM export. This isn't the case for a WAV export, however. + +**Tuning (A-4)**: Set tuning based on the note A-4, which should be 440 in most cases. Opening an Amiga MOD will set it to 436 for hardware compatibility. + +# subsongs + +This window allows one to create **subsongs** - multiple individual songs within a single file. Each song has its own order list and patterns, but all songs within a file share the same chips, samples, and so forth. + +- The drop-down box selects the current subsong. +- The **`+`** button adds a new subsong. +- The **`−`** button permanently deletes the current subsong (unless it's the only one). +- **Name**: Title of the current subsong. +- The box at the bottom can store any arbitrary text, like a separate "Comments" box for the current subsong. + +# speed + +There are multiple ways to set the tempo of a song. + +**Tick Rate**: The frequency of ticks per second, thus the rate at which notes and effects are processed. +- All values are allowed for all chips, though most chips have hardware limitations that mean they should stay at either 60 (approximately NTSC) or 50 (exactly PAL). +- Clicking the Tick Rate button switches to a more traditional **Base Tempo** BPM setting. + +**Speed**: The number of ticks per row. +- Clicking the "Speed" button changes to more complex modes covered in the [grooves] page. + +**Virtual Tempo**: Simulates any arbitrary tempo without altering the tick rate. It does this by adding or skipping ticks to approximate the tempo. The two numbers represent a ratio applied to the actual tick rate. Example: +- Set tick rate to 150 BPM (60 Hz) and speed to 6. +- Set the first virtual tempo number (numerator) to 200. +- Set the second virtual tempo number (denominator) to 150. +- The track will play at 200 BPM. +- The ratio doesn't have to match BPM numbers. Set the numerator to 4 and the denominator to 5, and the virtual BPM becomes 150 × 4/5 = 120. + +**Divider**: Changes the effective tick rate. A tick rate of 60Hz and a divisor of 6 will result in ticks lasting a tenth of a second each! + +**Highlight**: Sets the pattern row highlights: +- The first value represents the number of rows per beat. +- The second value represents the number of rows per measure. +- These don't have to line up with the music's actual beats and measures. Set them as preferred for tracking. _Note:_ These values are used for the metronome and calculating BPM. + +**Pattern Length**: The length of each pattern in rows. This affects all patterns in the song, and every pattern must be the same length. (Individual patterns can be cut short by `0Bxx`, `0Dxx`, and `FFxx` commands.) + +**Song Length**: How many orders are in the order list. Decreasing it will hide the orders at the bottom. Increasing it will restore those orders; increasing it further will add new orders of all `00` patterns. diff --git a/doc/2-interface/tab1.png b/doc/2-interface/tab1.png new file mode 100644 index 00000000..156532c5 Binary files /dev/null and b/doc/2-interface/tab1.png differ diff --git a/doc/2-interface/tab2.png b/doc/2-interface/tab2.png new file mode 100644 index 00000000..18bc6b2d Binary files /dev/null and b/doc/2-interface/tab2.png differ diff --git a/doc/2-interface/tab3.png b/doc/2-interface/tab3.png new file mode 100644 index 00000000..c59d973e Binary files /dev/null and b/doc/2-interface/tab3.png differ diff --git a/doc/2-interface/wavetables.png b/doc/2-interface/wavetables.png new file mode 100644 index 00000000..4ac45f2c Binary files /dev/null and b/doc/2-interface/wavetables.png differ diff --git a/doc/2-interface/window.png b/doc/2-interface/window.png new file mode 100644 index 00000000..a812b7a8 Binary files /dev/null and b/doc/2-interface/window.png differ diff --git a/papers/doc/3-pattern/README.md b/doc/3-pattern/README.md similarity index 100% rename from papers/doc/3-pattern/README.md rename to doc/3-pattern/README.md diff --git a/doc/3-pattern/channelbar.png b/doc/3-pattern/channelbar.png new file mode 100644 index 00000000..6ef20cb4 Binary files /dev/null and b/doc/3-pattern/channelbar.png differ diff --git a/doc/3-pattern/channels.png b/doc/3-pattern/channels.png new file mode 100644 index 00000000..ab4c985f Binary files /dev/null and b/doc/3-pattern/channels.png differ diff --git a/papers/doc/3-pattern/effects.md b/doc/3-pattern/effects.md similarity index 50% rename from papers/doc/3-pattern/effects.md rename to doc/3-pattern/effects.md index 54d18000..6becb6c8 100644 --- a/papers/doc/3-pattern/effects.md +++ b/doc/3-pattern/effects.md @@ -1,78 +1,98 @@ # effect list -most of the effect numbers are from ProTracker/FastTracker 2. -however, effects are continuous, which means you only need to type it once and then stop it with an effect value of `00`. +most of the effect numbers are from ProTracker / FastTracker 2. -- `00xy`: arpeggio. after using this effect the channel will rapidly switch between `note`, `note+x` and `note+y`. -- `01xx`: slide up. -- `02xx`: slide down. -- `03xx`: note portamento. - - a note must be present for this effect to work. -- `04xy`: vibrato. `x` is the speed, while `y` is the depth. - - maximum vibrato depth is ±1 semitone. -- `07xy`: tremolo. `x` is the speed, while `y` is the depth. - - maximum tremolo depth is -60 volume steps. -- `08xy`: set panning. `x` is the left channel and `y` is the right one. - - not all chips support this effect. -- `80xx`: set panning (linear). this effect behaves more like other trackers: +however, effects are continuous, which means you only need to type it once and then stop it with an effect value of `00` or no effect value at all. + +## volume + +- `0Axy`: **Volume slide.** + - If `x` is 0 then this is a slide down. + - If `y` is 0 then this is a slide up. +- `F8xx`: **Single tick volume slide up.** +- `F9xx`: **Single tick volume slide down.** +- `F3xx`: **Fine volume slide up.** 64× slower than `0Axy`. +- `F4xx`: **Fine volume slide down.** 64× slower than `0Axy`. +- `FAxy`: **Fast volume slide.** 4× faster than `0Axy`. + - If `x` is 0 then this is a slide down. + - If `y` is 0 then this is a slide up. + +- `07xy`: **Tremolo.** changes volume to be "wavy" with a sine LFO. `x` is the speed, while `y` is the depth. + - Tremolo is downward only. + - Maximum tremolo depth is -60 volume steps. + +## pitch + +- `E5xx`: **Set pitch.** `00` is -1 semitone, `80` is base pitch, `FF` is nearly +1 semitone. +- `01xx`: **Pitch slide up.** +- `02xx`: **Pitch slide down.** +- `F1xx`: **Single tick pitch slide up.** +- `F2xx`: **Single tick pitch slide down.** + +- `03xx`: **Portamento.** slides the current note's pitch to the specified note. + - A note _must_ be present for this effect to work. +- `E1xy`: **Note slide up.** `x` is the speed, while `y` is how many semitones to slide up. +- `E2xy`: **Note slide down.** `x` is the speed, while `y` is how many semitones to slide down. +- `EAxx`: **Toggle legato.** while on, notes instantly change the pitch of the currrently playing sound instead of starting it over. +- `00xy`: **Arpeggio.** after using this effect the channel will rapidly switch between semitone values of `note`, `note + x` and `note + y`. +- `E0xx`: **Set arpeggio speed.** this sets the number of ticks between arpeggio values. + +- `04xy`: **Vibrato.** changes pitch to be "wavy" with a sine LFO. `x` is the speed, while `y` is the depth. + - Maximum vibrato depth is ±1 semitone. +- `E3xx`: **Set vibrato direction.** `xx` may be one of the following: + - `00`: Up and down. + - `01`: Up only. + - `02`: Down only. +- `E4xx`: **Set vibrato range** in 1/16th of a semitone. + +## panning + +not all chips support these effects. + +- `08xy`: **Set panning.** changes stereo volumes independently. `x` is the left channel and `y` is the right one. +- `88xy`: **Set rear panning.** changes rear channel volumes independently. `x` is the rear left channel and `y` is the rear right one. + +- `80xx`: **Set panning (linear).** this effect behaves more like other trackers: - `00` is left. - `80` is center. - `FF` is right. - - not all chips support this effect. -- `81xx`: set volume of left channel (from `00` to `FF`). - - not all chips support this effect. -- `82xx`: set volume of right channel (from `00` to `FF`). - - not all chips support this effect. -- `09xx`: set speed 1. -- `0Axy`: volume slide. - - if `x` is 0 then this is a slide down. - - if `y` is 0 then this is a slide up. -- `0Bxx`: jump to pattern. -- `0Cxx`: retrigger note every `xx` ticks. - - this effect is not continuous. -- `0Dxx`: jump to next pattern. -- `0Fxx`: set speed 2. +- `81xx`: **Set volume of left channel** (from `00` to `FF`). +- `82xx`: **Set volume of right channel** (from `00` to `FF`). +- `89xx`: **Set volume of rear left channel** (from `00` to `FF`). +- `8Axx`: **Set volume of rear right channel** (from `00` to `FF`). -- `9xxx`: set sample position to `xxx`\*0x100. - - not all chips support this effect. +## time -- `Cxxx`: change song Hz. +- `09xx`: **Set speed/groove.** if no grooves are defined, this sets speed. If alternating speeds are active, this sets the first speed. +- `0Fxx`: **Set speed 2.** during alternating speeds or a groove, this sets the second speed. + +- `Cxxx`: **Set tick rate.** changes tick rate to `xxx` Hz (ticks per second). - `xxx` may be from `000` to `3ff`. +- `F0xx`: **Set BPM.** changes tick rate according to beats per minute. -- `E0xx`: set arpeggio tick. - - this sets the number of ticks between arpeggio values. -- `E1xy`: note slide up. `x` is the speed, while `y` is how many semitones to slide up. -- `E2xy`: note slide down. `x` is the speed, while `y` is how many semitones to slide down. -- `E3xx`: set vibrato direction. `xx` may be one of the following: - - `00`: up and down. - - `01`: up only. - - `02`: down only. -- `E4xx`: set vibrato range in 1/16th of a semitone. -- `E5xx`: set pitch. `80` is 0 cents. - - range is ±1 semitone. -- `EAxx`: toggle legato. -- `EBxx`: set sample bank. - - does not apply on Amiga. -- `ECxx`: note off after `xx` ticks. -- `EDxx`: delay note by `xx` ticks. -- `EExx`: send external command. - - this effect is currently incomplete. -- `F0xx`: change song Hz by BPM value. -- `F1xx`: single tick slide up. -- `F2xx`: single tick slide down. -- `F3xx`: fine volume slide up (64x slower than `0Axy`). -- `F4xx`: fine volume slide down (64x slower than `0Axy`). -- `F5xx`: disable macro. - - see macro table at the end of this document for possible values. -- `F6xx`: enable macro. -- `F8xx`: single tick volume slide up. -- `F9xx`: single tick volume slide down. -- `FAxy`: fast volume slide (4x faster than `0Axy`). - - if `x` is 0 then this is a slide down. - - if `y` is 0 then this is a slide up. -- `FFxx`: end of song/stop playback. +- `0Bxx`: **Jump to order.** this can be used to loop a song. +- `0Dxx`: **Jump to next pattern.** this can be used to shorten the current order. +- `FFxx`: **Stop song.** stops playback and ends the song. -additionally each chip has its own effects. [click here for more details](../7-systems/README.md). +## note + +- `0Cxx`: **Retrigger.** repeats current note every `xx` ticks. + - This effect is not continuous; it must be entered on every row. +- `ECxx`: **Note cut.** ends current note after `xx` ticks. For FM instruments, it's equivalent to a "key off". +- `EDxx`: **Note delay.** delays note by `x` ticks. + +## other + +- `9xxx`: **Set sample position.** jumps current sample to position `xxx \* 0x100`. + - Not all chips support this effect. +- `EBxx`: **Set sample bank.** + - Does not apply on Amiga. +- `EExx`: **Send external command.** + - This effect is currently incomplete. +- `F5xx`: **Disable macro.** see macro table at the end of this document for possible values. +- `F6xx`: **Enable macro.** + +additionally, [each chip has its own effects](../7-systems/README.md). ## macro table @@ -98,8 +118,8 @@ ID | macro 11 | extra 6 12 | extra 7 13 | extra 8 ----|----------------------------- -20 | **operator 1 macros** - AM +| | **operator 1 macros** +20 | AM 21 | AR 22 | DR 23 | MULT @@ -119,10 +139,9 @@ ID | macro 31 | VIB 32 | WS 33 | KSR ----|----------------------------- -40 | operator 2 macros -60 | operator 3 macros -80 | operator 4 macros +40 | **operator 2 macros** +60 | **operator 3 macros** +80 | **operator 4 macros** the interpretation of duty, wave and extra macros depends on chip/instrument type: diff --git a/doc/3-pattern/keyboard.png b/doc/3-pattern/keyboard.png new file mode 100644 index 00000000..7042af1c Binary files /dev/null and b/doc/3-pattern/keyboard.png differ diff --git a/doc/3-pattern/pattern.png b/doc/3-pattern/pattern.png new file mode 100644 index 00000000..ca059faa Binary files /dev/null and b/doc/3-pattern/pattern.png differ diff --git a/doc/4-instrument/8930.md b/doc/4-instrument/8930.md new file mode 100644 index 00000000..ecb1e8ed --- /dev/null +++ b/doc/4-instrument/8930.md @@ -0,0 +1,16 @@ +# AY8930 instrument editor + +AY8930 instrument editor consists of these macros. + +- **Volume**: volume sequence +- **Arpeggio**: pitch in half-steps +- **Noise Freq**: AY8930 noise generator frequency sequence +- **Waveform**: selector of sound type: pulse wave tone, noise or envelope generator +- **Pitch**: fine pitch +- **Phase Reset**: trigger restart of waveform +- **Duty**: duty cycle of a pulse wave sequence +- **Envelope**: allows shaping an envelope +- **AutoEnv Num**: sets the envelope to the channel's frequency multiplied by numerator +- **AutoEnv Den**: sets the envelope to the channel's frequency divided by denominator +- **Noise AND Mask**: alters the shape/frequency of the noise generator, allowing to produce various interesting sound effects and even PWM phasing +- **Noise OR Mask**: see above diff --git a/doc/4-instrument/README.md b/doc/4-instrument/README.md new file mode 100644 index 00000000..4afd2a07 --- /dev/null +++ b/doc/4-instrument/README.md @@ -0,0 +1,99 @@ +# instrument list + +![instrument list](list.png) + +click on an instrument to select it. + +double-click to open the instrument editor. + +# instrument editor + +every instrument can be renamed and have its type changed. + +depending on the instrument type, there are many different types of instrument editor: + +- [FM synthesis](fm.md) - for use with YM2612, YM2151 and FM block portion of YM2610. +- [Standard](standard.md) - for use with NES and Sega Master System's PSG sound source and its derivatives. +- [Game Boy](game-boy.md) - for use with Game Boy APU. +- [PC Engine / TurboGrafx-16](pce.md) - for use with PC Engine's wavetable synthesizer. +- [WonderSwan](wonderswan.md) - for use with WonderSwan's wavetable synthesizer. +- [AY8930](8930.md) - for use with Microchip AY8930 E-PSG sound source. +- [Commodore 64](c64.md) - for use with Commodore 64 SID. +- [SAA1099](saa.md) - for use with Philips SAA1099 PSG sound source. +- [TIA](tia.md) - for use with Atari 2600 chip. +- [AY-3-8910](ay8910.md) - for use with AY-3-8910 PSG sound source and SSG portion in YM2610. +- [Amiga / sample](amiga.md) for controlling Amiga and other sample based synthsizers like YM2612's Channel 6 PCM mode, NES channel 5, Sega PCM, X1-010 and PC Engine's sample playback mode. +- [Atari Lynx](lynx.md) - for use with Atari Lynx handheld console. +- [VERA](vera.md) - for use with Commander X16 VERA. +- [Seta/Allumer X1-010](x1_010.md) - for use with Wavetable portion in Seta/Allumer X1-010. +- [Konami SCC / Bubble System WSG](scc.md) - for use with Konami SCC and Wavetable portion in Bubble System's sound hardware. +- [Namco 163](n163.md) - for use with Namco 163. +- [Konami VRC6](vrc6.md) - for use with VRC6's PSG sound source. +- [SNES](snes.md) - for use with SNES S-APU. + + +# macros + +Macros are incredibly versatile tools for automating instrument parameters. + +After creating an instrument, open the Instrument Editor and select the "Macros" tab. There may be multiple macro tabs to control individual FM operators and such. + +![macro view](macroview.png) + +The very first numeric entry sets the visible width of the bars in sequence-type macros. The scrollbar affects the view of all macros at once. There's a matching scrollbar at the bottom underneath all the macros. + +Each macro has two buttons on the left. +- Macro type (explained below). +- Timing editor, which pops up a small dialog: + - Step Length (ticks): Determines how many ticks pass before each change of value. + - Delay: Delays the start of the macro until this many ticks have passed. + +## macro types + +Every macro can be defined though one of three methods, selectable with the leftmost button under the macro type label: + +- ![](macro-button-seq.png) **Sequence:** displayed as a bar graph, this is a sequence of numeric values. +- ![](macro-button-ADSR.png) **ADSR:** this is a traditional ADSR envelope, defined by the rate of increase and decrease of value over time. +- ![](macro-button-LFO.png) **LFO:** the Low Frequency Oscillator generates a repeating wave of values. + +Some macros are "bitmap" style. They represent a number of "bits" that can be toggled individually, and the values listed represent the sum of which bits are turned on. + +### sequence + +![sequence macro editor](macro-seq.png) + +The number between the macro type label and the macro type button is the macro length in steps. The `-` and `+` buttons change the length of the macro. Start out by adding at least a few steps. + +The values of the macro can be drawn in the "bar graph box". Just beneath the box is shorter bar graph. +- Click to set the start point of a loop; the end point is the last value or release point. Right-click to remove the loop. +- Shift-click to set the release point. When played, the macro will hold here until the note is released. Right-click to remove the release point. + +Finally, the sequence of values can be directly edited in the text box at the bottom. +- The loop start is entered as a `|`. +- The release point is entered as a `/`. +- In arpeggio macros, a value starting with a `@` is an absolute note (instead of a relative shift). No matter the note played, `@` values will be played at that exact note. This is especially useful for noise instruments with preset periods. + +### ADSR + +![ADSR macro editor](macro-ADSR.png) + +- **Bottom** and **Top** determine the range of outputs generated by the macro. (Bottom can be larger than Top to invert the envelope!) All outputs will be between these two values. +- Attack, Decay, Sustain, SusDecay, and Release accept inputs between 0 to 255. These are scaled to the distance between Bottom and Top. +- **Attack** is how much the value moves toward Top with each tick. +- **Hold** sets how many ticks to stay at Top before Decay. +- **Decay** is how much the value moves to the Sustain level. +- **Sustain** is how far from Bottom the value stays while the note is held. +- **SusTime** is how many ticks to stay at Sustain until SusDecay. +- **SusDecay** is how much the value moves toward Bottom with each tick while the note is held. +- **Release** is how much the value moves toward Bottom with each tick after the note is released. + +![macro ADSR chart](macro-ADSRchart.png) + +### LFO + +![LFO macro editor](macro-LFO.png) + +- **Bottom** and **Top** determine the range of values generated by the macro. (Bottom can be larger than Top to invert the waveform!) +- **Speed** is how quickly the values change - the frequency of the oscillator. +- **Phase** is which part of the waveform the macro will start at, measured in 1/1024 increments. +- **Shape** is the waveform used. Triangle is the default, and Saw and Square are exactly as they say. diff --git a/doc/4-instrument/amiga.md b/doc/4-instrument/amiga.md new file mode 100644 index 00000000..3d7a606f --- /dev/null +++ b/doc/4-instrument/amiga.md @@ -0,0 +1,17 @@ +# Amiga/PCM sound source instrument editor + +The PCM instrument editor consists of a sample selector and several macros: + +# Amiga/sample + +- **Initial sample**: specifies which sample should be assigned to the instrument, or the first one in the sequence + +# Macros + +- **Volume**: volume sequence. _warning:_ it works only on Amiga system, as of version 0.5.5! +- **Arpeggio**: pitch sequence +- **Waveform**: sample sequence +- **Panning (left)**: output level for left channel +- **Panning (right)**: output level for right channel +- **Pitch**: fine pitch +- **Phase Reset**: trigger restart of waveform \ No newline at end of file diff --git a/doc/4-instrument/ay8910.md b/doc/4-instrument/ay8910.md new file mode 100644 index 00000000..c4a0a815 --- /dev/null +++ b/doc/4-instrument/ay8910.md @@ -0,0 +1,13 @@ +# AY-3-8910 instrument editor + +The AY-3-8910 instrument editor consists of these macros. + +- **Volume**: volume levels sequence +- **Arpeggio**: pitch sequence +- **Noise Freq**: AY-3-8910 noise generator frequency sequence +- **Waveform**: selector of sound type - square wave tone, noise or envelope generator +- **Pitch**: fine pitch +- **Phase Reset**: trigger restart of waveform +- **Envelope**: allows shaping an envelope +- **AutoEnv Num**: sets the envelope to the channel's frequency multiplied by numerator +- **AutoEnv Den**: sets the envelope to the channel's frequency multiplied by denominator diff --git a/doc/4-instrument/c64.md b/doc/4-instrument/c64.md new file mode 100644 index 00000000..5dd20408 --- /dev/null +++ b/doc/4-instrument/c64.md @@ -0,0 +1,35 @@ +# C64 SID instrument editor + +The C64 instrument editor consists of two tabs: "C64" to control various parameters of sound channels, and "Macros" containing several macros. + +## C64 + +- **Waveform**: allows selecting a waveform. NOTE: more than one waveform can be selected at once, logical AND mix of waves will be produced, with an exception of a noise waveform, it can't be mixed. +- **Attack**: determines the rising time for the sound. The bigger the value, the slower the attack. (0-15 range) +- **Decay**: Determines the diminishing time for the sound. The higher the value, the longer the decay. It's the initial amplitude decay rate. (0-15 range) +- **Sustain**: Sets the volume level at which the sound stops decaying and holds steady. (0-15 range) +- **Release**: Determines the rate at which the sound disappears after KEY-OFF. The higher the value, the longer the release. (0-15 range) +- **Ring Modulation**: enables the ring modulation affecting the instrument. +- **Duty**: specifies the width of a pulse wave. (0-4095 range) +- **Oscillator Sync**: enables the oscillator hard sync. As one oscillator finishes a cycle, it resets the period of another oscillator, forcing the latter to have the same base frequency. This can produce a harmonically rich sound, the timbre of which can be altered by varying the synced oscillator's frequency. +- **Enable filter**: enables analogue filter affecting the instrument +- **Initialize filter**: initializes the filter with the specified parameters: +- **Cutoff**: defines the "intensity" of a filter, to put in in layman terms (0-2047 range) +- **Resonance**: defines an additional controlled amplification of that cutoff frequency, creating a secondary peak forms and colors the original pitch. (0-15 range) +- **Filter mode**: determined the filter mode NOTE: SID's filter is multi-mode, you can mix different modes together (like low and high-pass filters at once) CH3-OFF disables the channel 3, for no reason whatsoever lmao +- **Volume Macro is Cutoff Macro**: turns a volume macro in a macros tab into a filter cutoff macro. +- **Absolute Cutoff Macro**: changes the behaviour of a cutoff macro from the old-style, compatible to much more define-able. +- **Absolute Duty Macro**: changes the behaviour of a duty cycle macro from the old-style, compatible to much more definable. +- **Don't test/gate before new note**: Don't reset the envelope to zero when a new note starts. (Read "Test/Gate" below for more info.) + +## Macros + +- **Volume**: volume sequence (WARNING: Volume sequence is global for ALL three channels!!) +- **Arpeggio**: pitch sequence +- **Duty**: pulse duty cycle sequence +- **Waveform**: select the waveform used by instrument +- **Pitch**: fine pitch +- **Filter mode**: select the filter mode/sequence +- **Resonance**: filter resonance sequence +- **Special**: ring and oscillator sync selector +- **Test/Gate**: When on, the TEST bit resets and locks Oscillator 1 at zero until cleared. The GATE bit controls Oscillator 1's envelope: Gate on runs through the envelope's attack, delay, and sustain; Gate off is envelope release. \ No newline at end of file diff --git a/doc/4-instrument/fm.md b/doc/4-instrument/fm.md new file mode 100644 index 00000000..08542eb3 --- /dev/null +++ b/doc/4-instrument/fm.md @@ -0,0 +1,47 @@ +# FM synthesis instrument editor + +FM editor is divided into 7 tabs: + +- **FM**: for controlling the basic parameters of FM sound source. +- **Macros (FM)**: for macros controlling algorithm, feedback and LFO +- **Macros (OP1)**: for macros controlling FM paramets of operator 1 +- **Macros (OP2)**: for macros controlling FM paramets of operator 2 +- **Macros (OP3)**: for macros controlling FM paramets of operator 3 +- **Macros (OP4)**: for macros controlling FM paramets of operator 4 +- **Macros**: for miscellaneous macros controlling volume, argeggio and YM2151 noise generator. + +## FM + +FM synthesizers Furnace supports are four-operator, meaning it takes four oscillators to produce a single sound. Each operator is controlled by a dozen sliders: + +- **Attack Rate (AR)**: determines the rising time for the sound. The bigger the value, the faster the attack. (0-31 range) +- **Decay Rate (DR)**: Determines the diminishing time for the sound. The higher the value, the shorter the decay. It's the initial amplitude decay rate. (0-31 range) +- **Secondary Decay Rate (DR2)/Sustain Rate (SR)**: Determines the diminishing time for the sound. The higher the value, the shorter the decay. This is the long "tail" of the sound that continues as long as the key is depressed. (0-31 range) +- **Release Rate (RR)**: Determines the rate at which the sound disappears after KEY-OFF. The higher the value, the shorter the release. (0-15 range) +- **Sustain Level(SL)**: Determines the point at which the sound ceases to decay and changes to a sound having a constant level. The sustain level is expressed as a fraction of the maximum level. (0-15 range) +- **Total Level (TL)**: Represents the envelope’s highest amplitude, with 0 being the largest and 127 (decimal) the smallest. A change of one unit is about 0.75 dB. +- **Envelope Scale (KSR)**: A parameter that determines the degree to which the envelope execution speed increases according to the pitch. (0-3 range) +- **Frequency Multiplier (MULT)**: Determines the operator frequency in relation to the pitch. (0-15 range) +- **Fine Detune (DT)**: Shifts the pitch a little (0-7 range) +- **Coarse Detune (DT2)**: Shifts the pitch by tens of cents (0-3 range) WARNING: this parameter affects only YM2151 sound source!!! +- **Hardware Envelope Generator (SSG-EG)**: Executes the built-in envelope, inherited from AY-3-8910 PSG. Speed of execution is controlled via Decay Rate. WARNING: this parameter affects only YM2610/YM2612 sound source!!! +- **Algorithm (AL)**: Determines how operators are connected to each other. (0-7 range) +- **Feedback (FB)**: Determines the amount of signal whick operator 1 returns to itself. (0-7 range) +- **Amplitude Modulation (AM)**: Makes the operator affected by LFO. +- **LFO Frequency Sensitivity**: Determines the amount of LFO frequency changes. (0-7 range) +- **LFO Amplitude Sensitivity (AM)**: Determines the amount of LFO frequency changes. (0-3 range) + +## Macros + +Macros define the sequence of values passed to the given parameter. Via macro, aside previously mentioned parameters, the following can be controlled: + +- **LFO Frequency** +- **LFO Waveform**: _WARNING:_ this parameter affects only YM2151 sound source! +- **Amplitude Modulation Depth**: _WARNING:_ this parameter affects only YM2151 sound source! +- **Frequency Modulation Depth**: _WARNING:_ this parameter affects only YM2151 sound source! +- **Arpeggio Macro**: Pitch change sequence in semitones. Two modes are available: + - **Absolute** (default): Executes the pitch with absolute change based on the pitch of the actual note. + - **Fixed**: Executes at the pitch specified in the sequence regardless of the note pitch. +- **Noise Frequency**: specifies the noise frequency in noise mode of YM2151's Channel 8 Operator 4 special mode. + +Looping: You can loop the execution of part of a sequence. Left-click anywhere on the Loop line at the bottom of the editor to create a loop. You can move the start and end points of the loop by dragging both ends of the loop. Rigkt-click to remove the loop. diff --git a/doc/4-instrument/game-boy.md b/doc/4-instrument/game-boy.md new file mode 100644 index 00000000..fd982615 --- /dev/null +++ b/doc/4-instrument/game-boy.md @@ -0,0 +1,25 @@ +# Game Boy instrument editor + +GB instrument editor consists of two tabs: one controlling envelope of sound channels and macro tab containing several macros. + +## Game Boy + +- **Use software envelope**: switch to volume macro instead of envelope +- **Initialize envelope on every note**: forces a volume reset on each new note +- **Volume**: initial channel volume (range 0-15) +- **Length**: envelope decay/attack duration (range 0-7) +- **Sound Length**: cuts off sound after specified length, overriding the Length value + +- **Up and Down radio buttons**: Up makes the envelope an attack, down makes it decay. _Note:_ For envelope attack to have any effect, start at a lower volume! + +- **Hardware Sequence**: (document this) + +## Macros + +- **Volume**: volume sequence. _Note:_ This only appears if "Use software envelope" is checked. +- **Arpeggio**: pitch in half-steps +- **Duty/Noise**: pulse wave duty cycle or noise mode sequence +- **Waveform**: ch3 wavetable sequence +- **Panning**: output for left and right channels +- **Pitch**: fine pitch +- **Phase Reset**: trigger restart of waveform diff --git a/doc/4-instrument/list.png b/doc/4-instrument/list.png new file mode 100644 index 00000000..e8af84a8 Binary files /dev/null and b/doc/4-instrument/list.png differ diff --git a/papers/doc/4-instrument/lynx.md b/doc/4-instrument/lynx.md similarity index 53% rename from papers/doc/4-instrument/lynx.md rename to doc/4-instrument/lynx.md index 5badd47f..43dc1734 100644 --- a/papers/doc/4-instrument/lynx.md +++ b/doc/4-instrument/lynx.md @@ -1,15 +1,18 @@ # Atari Lynx instrument editor -Atari Lynx instrument editor consists of only three macros: +Atari Lynx instrument editor consists of these macros: -- [Volume] - volume sequence -- [Arpeggio] - pitch sequencer -- [Duty/Int] - bit pattern for LFSR taps and integration. +- **Volume**: volume sequence +- **Arpeggio**: pitch in half-steps +- **Duty/Int**: bit pattern for LFSR taps and integration +- **Panning (left)**: output level for left channel +- **Panning (right)**: output level for right channel +- **Pitch**: fine pitch +- **Phase Reset**: trigger restart of waveform ## Audio generation description -Atari Lynx to generate sound uses 12-bit linear feedback shift register with configurable tap. Nine separate bits can be enable to be the source of feedback. -Namely bits 0, 1, 2, 3, 4, 5, 7, 10 and 11. To generate ANY sound at least one bit MUST be enable. +Atari Lynx generates sound using a 12-bit linear feedback shift register with configurable tap. Nine separate bits can be enabled to be the source of feedback: 0, 1, 2, 3, 4, 5, 7, 10 and 11. To generate _any_ sound at least one bit _must_ be enabled. ### Square wave diff --git a/doc/4-instrument/macro-ADSR.png b/doc/4-instrument/macro-ADSR.png new file mode 100644 index 00000000..f38d1432 Binary files /dev/null and b/doc/4-instrument/macro-ADSR.png differ diff --git a/doc/4-instrument/macro-ADSRchart.png b/doc/4-instrument/macro-ADSRchart.png new file mode 100644 index 00000000..2580426f Binary files /dev/null and b/doc/4-instrument/macro-ADSRchart.png differ diff --git a/doc/4-instrument/macro-LFO.png b/doc/4-instrument/macro-LFO.png new file mode 100644 index 00000000..90cb5c08 Binary files /dev/null and b/doc/4-instrument/macro-LFO.png differ diff --git a/doc/4-instrument/macro-button-ADSR.png b/doc/4-instrument/macro-button-ADSR.png new file mode 100644 index 00000000..6529a72c Binary files /dev/null and b/doc/4-instrument/macro-button-ADSR.png differ diff --git a/doc/4-instrument/macro-button-LFO.png b/doc/4-instrument/macro-button-LFO.png new file mode 100644 index 00000000..8ad9c24b Binary files /dev/null and b/doc/4-instrument/macro-button-LFO.png differ diff --git a/doc/4-instrument/macro-button-seq.png b/doc/4-instrument/macro-button-seq.png new file mode 100644 index 00000000..dd316c20 Binary files /dev/null and b/doc/4-instrument/macro-button-seq.png differ diff --git a/doc/4-instrument/macro-seq.png b/doc/4-instrument/macro-seq.png new file mode 100644 index 00000000..6ea2050b Binary files /dev/null and b/doc/4-instrument/macro-seq.png differ diff --git a/doc/4-instrument/macro.png b/doc/4-instrument/macro.png new file mode 100644 index 00000000..4e03bad9 Binary files /dev/null and b/doc/4-instrument/macro.png differ diff --git a/doc/4-instrument/macroview.png b/doc/4-instrument/macroview.png new file mode 100644 index 00000000..faadedb2 Binary files /dev/null and b/doc/4-instrument/macroview.png differ diff --git a/doc/4-instrument/n163.md b/doc/4-instrument/n163.md new file mode 100644 index 00000000..1ec45914 --- /dev/null +++ b/doc/4-instrument/n163.md @@ -0,0 +1,30 @@ +# Namco 163 instrument editor + +The Namco 163 instrument editor consists of two tabs: "Namco 163" for control of various waveform parameters, and "Macro" containing several macros. + +## Namco 163 + +- **Waveform**: Determines the initial waveform for playing. +- **Offset**: Determines the initial waveform position will be load to RAM. +- **Length**: Determines the initial waveform length will be load to RAM. +- **Load waveform before playback**: Determines the load initial waveform into RAM before playback. +- **Update waveforms into RAM when every waveform changes**: Determines the update every different waveform changes in playback. + + +## Macros + +- **Volume**: volume levels sequence +- **Arpeggio**: pitch sequence +- **Waveform**: sets waveform source for playback immediately or update later +- **Panning**: output for left and right channels +- **Pitch**: fine pitch +- **Phase Reset**: trigger restart of waveform + \ No newline at end of file diff --git a/doc/4-instrument/pce.md b/doc/4-instrument/pce.md new file mode 100644 index 00000000..72c87470 --- /dev/null +++ b/doc/4-instrument/pce.md @@ -0,0 +1,14 @@ +# NEC PC Engine instrument editor + +The PCE instrument editor consists of these macros: + +- **Volume**: volume sequence +- **Arpeggio**: pitch in half-steps +- **Noise**: enable noise mode (ch5 and ch6 only) +- **Waveform**: wavetable sequence +- **Panning (left)**: output level for left channel +- **Panning (right)**: output level for right channel +- **Pitch**: fine pitch +- **Phase Reset**: trigger restart of waveform + +It also has wavetable synthesizer support, but unfortunately, it clicks a lot when in use on the HuC6280. diff --git a/doc/4-instrument/saa.md b/doc/4-instrument/saa.md new file mode 100644 index 00000000..1611bd61 --- /dev/null +++ b/doc/4-instrument/saa.md @@ -0,0 +1,12 @@ +# Philips SAA1099 instrument editor + +The SAA1099 instrument editor consists of these macros: + +- **Volume**: volume sequence +- **Arpeggio**: pitch sequence +- **Duty/Noise**: noise generator frequency +- **Waveform**: selector between tone and noise +- **Panning (left)**: output level for left channel +- **Panning (right)**: output level for right channel +- **Pitch**: fine pitch +- **Envelope**: envelope generator shape diff --git a/doc/4-instrument/scc.md b/doc/4-instrument/scc.md new file mode 100644 index 00000000..fa9a9408 --- /dev/null +++ b/doc/4-instrument/scc.md @@ -0,0 +1,8 @@ +# Konami SCC/Bubble System WSG instrument editor + +The SCC/Bubble System WSG instrument editor consists of these macros: + +- **Volume**: volume sequence +- **Arpeggio**: pitch sequence +- **Waveform**: spicifies wavetables sequence +- **Pitch**: fine pitch diff --git a/doc/4-instrument/snes.md b/doc/4-instrument/snes.md new file mode 100644 index 00000000..0887e9a6 --- /dev/null +++ b/doc/4-instrument/snes.md @@ -0,0 +1,46 @@ +# SNES instrument editor + +these tabs are unique to the editor for SNES instruments. + + + +# SNES + +**Use envelope** enables the ADSR volume envelope. if it's on: + +- **A**: attack rate. +- **D**: decay rate. +- **S**: sustain level. +- **D2**: decay rate during sustain. +- **R**: release rate. +- **Sustain/release mode**: + - **Direct**: note release acts as note cut. + - **Effective (linear decrease)**: after release, volume lowers by subtractions of 1/64 steps. + - **Effective (exponential decrease)**: after release, volume decays exponentially. see [gain chart](../7-systems/snes.md). + - **Delayed (write R on release)**: after release, waits until A and D have completed before starting exponential decrease. + +if envelope is off, select gain mode as described below. + + + +# Macros + +- **Volume**: volume. +- **Arpeggio**: pitch in half-steps. +- **Noise Freq**: preset frequency of noise generator. +- **Waveform**: waveform. +- **Panning (left)**: output level of left channel. +- **Panning (right)**: output level of right channel. +- **Pitch**: fine pitch. +- **Special**: bitmap of flags. + - invert left: inverts output of left channel. + - invert right: inverts output of right channel. + - pitch mod: modulates pitch using previous channel's output. + - echo: enables echo. + - noise: enables noise generator. +- **Gain**: sets mode and value of gain. + - 0 - 127: direct gain from 0 to 127 + - 128 - 159: linear gain from -0 to -31 + - 160 - 191: exponential gain from -0 to -31 + - 192 - 223: linear gain from +0 to +31 + - 224 - 255: exponential gain from +0 to +31 diff --git a/doc/4-instrument/standard.md b/doc/4-instrument/standard.md new file mode 100644 index 00000000..2da6e160 --- /dev/null +++ b/doc/4-instrument/standard.md @@ -0,0 +1,10 @@ +# Standard instrument editor + +The instrument editor for NES and PSG (SMS, MSX, and such) consists of these macros: + +- **Volume**: volume +- **Arpeggio**: pitch in half-steps +- **Duty**: duty cycle and noise mode for NES channels. _Note:_ This has no effect on Sega Master System. +- **Panning**: output for left and right channels +- **Pitch**: fine pitch +- **Phase Reset**: trigger restart of waveform \ No newline at end of file diff --git a/doc/4-instrument/tia.md b/doc/4-instrument/tia.md new file mode 100644 index 00000000..704d3aa2 --- /dev/null +++ b/doc/4-instrument/tia.md @@ -0,0 +1,8 @@ +# Atari TIA instrument editor + +The TIA instrument editor consists of these macros: + +- **Volume**: volume sequence +- **Arpeggio**: pitch sequencr +- **Waveform**: 1-bit polynomial pattern type sequence +- **Pitch**: "fine" pitch diff --git a/doc/4-instrument/vera.md b/doc/4-instrument/vera.md new file mode 100644 index 00000000..ec76f659 --- /dev/null +++ b/doc/4-instrument/vera.md @@ -0,0 +1,10 @@ +# VERA instrument editor + +VERA instrument editor consists of these macros: + +- **Volume**: volume sequence +- **Arpeggio**: pitch sequence +- **Duty**: pulse duty cycle sequence +- **Waveform**: select the waveform used by instrument +- **Panning**: output for left and right channels +- **Pitch**: fine pitch diff --git a/papers/doc/4-instrument/vrc6.md b/doc/4-instrument/vrc6.md similarity index 61% rename from papers/doc/4-instrument/vrc6.md rename to doc/4-instrument/vrc6.md index bd87e050..17588b21 100644 --- a/papers/doc/4-instrument/vrc6.md +++ b/doc/4-instrument/vrc6.md @@ -1,10 +1,11 @@ # VRC6 instrument editor -The VRC6 (regular) instrument editor consists of only three macros: +The VRC6 (regular) instrument editor consists of these macros: -- [Volume] - volume sequence -- [Arpeggio] - pitch sequence -- [Duty cycle] - specifies duty cycle for pulse wave channels +- **Volume**: volume sequence +- **Arpeggio**: pitch sequence +- **Duty**: specifies duty cycle for pulse wave channels +- **Pitch**: fine pitch ## VRC6 (saw) instrument editor diff --git a/doc/4-instrument/wonderswan.md b/doc/4-instrument/wonderswan.md new file mode 100644 index 00000000..d43e154e --- /dev/null +++ b/doc/4-instrument/wonderswan.md @@ -0,0 +1,8 @@ +# WonderSwan instrument editor + +WS instrument editor consists of only four macros, similar to PCE but with different volume and noise range: + +- **Volume**: volume sequence +- **Arpeggio**: pitch sequencr +- **Noise**: noise LFSR tap sequence +- **Waveform**: spicifies wavetables sequence diff --git a/doc/4-instrument/x1_010.md b/doc/4-instrument/x1_010.md new file mode 100644 index 00000000..8be27f05 --- /dev/null +++ b/doc/4-instrument/x1_010.md @@ -0,0 +1,11 @@ +# X1-010 instrument editor + +X1-010 instrument editor consists of these macros. + +- **Volume**: volume levels sequence +- **Arpeggio**: pitch sequence +- **Waveform**: specifies wavetables sequence +- **Envelope Mode**: allows shaping an envelope +- **Envelope**: specifies envelope shape sequence, it's also wavetable. +- **Auto envelope numerator**: sets the envelope to the channel's frequency multiplied by numerator +- **Auto envelope denominator**: sets the envelope to the channel's frequency divided by denominator diff --git a/papers/doc/5-wave/README.md b/doc/5-wave/README.md similarity index 72% rename from papers/doc/5-wave/README.md rename to doc/5-wave/README.md index 19a07b10..e0394058 100644 --- a/papers/doc/5-wave/README.md +++ b/doc/5-wave/README.md @@ -6,9 +6,13 @@ Furnace's wavetable editor is rather simple, you can draw the waveform using mou Furnace's wavetable editor features multiple ways of creating desired waveform shape: -- Shape tab allows you to select a few predefined basic shapes and indirectly edit it via "Duty", "Exponent" and "XOR Point" sliders TODO: what the last two are doing? What is amplitude/phase for?) -- FM is for creating the waveform with frequency modulation synthesis principles: One can set carrier/modulation levels, frquency multiplier, connection between operators and FM waveforms of these operators. -- WaveTools allows user to fine-tune the waveform: scale said waveform in both X and Y axes, smoothen, amplify, normalize, convert to signed/unisgned, invert or even randomize the wavetable. +- **Shape** tab allows you to select a few predefined basic shapes and indirectly edit it via "Duty", "Exponent" and "XOR Point" sliders: + - **Duty**: Affects mainly pulse waves, determining its wisth, like on C64/VRC6 + - **Exponent**: Powers the waveform in the mathematical sense of the word (^2, ^3 and so on) + - **XOR Point**: Determines the point where the waveform gets negated. + - _TODO:_ amplitude/phase part +- **FM** for creating the waveform with frequency modulation synthesis principles: One can set carrier/modulation levels, frquency multiplier, connection between operators and FM waveforms of these operators. +- **WaveTools**: Allows user to fine-tune the waveform: scale said waveform in both X and Y axes, smoothen, amplify, normalize, convert to signed/unisgned, invert or even randomize the wavetable. ## wavetable synthesizer diff --git a/papers/doc/6-sample/README.md b/doc/6-sample/README.md similarity index 88% rename from papers/doc/6-sample/README.md rename to doc/6-sample/README.md index 05891a49..2f4fe3cd 100644 --- a/papers/doc/6-sample/README.md +++ b/doc/6-sample/README.md @@ -1,6 +1,6 @@ # samples -In the context of Furnace, a sound sample (usually just referred to as a sample) is a string of numbers that hold sampled PCM audio. +In the context of Furnace, a sound sample (usually just referred to as a sample) is a string of numbers that represent sampled PCM audio. In Furnace, these samples can be generated by importing a .wav (think of it as an higher quality MP3) file. @@ -13,6 +13,7 @@ as of Furnace 0.6, the following sound chips have sample support: - PC Engine/TurboGrafx-16/HuC6280 - Amiga/Paula - SegaPCM +- NEC PC-9801/YM2608 (ADPCM channel only) - Neo Geo/Neo Geo CD/YM2610 (ADPCM channels only) - Seta/Allumer X1-010 - Atari Lynx @@ -21,12 +22,16 @@ as of Furnace 0.6, the following sound chips have sample support: - QSound - ZX Spectrum 48k (1-bit) - RF5C68 -- WonderSwan +- SNES/S-DSP +- WonderSwan (second channel only) - tildearrow Sound Unit - VERA (last channel only) - Y8950 (last channel only) - Konami K007232 -- a few more that I've forgotten to mention +- Irem GA20 +- Ensoniq OTTO/ES5506 +- Yamaha PCMD8/YMZ280B +- MMC5 (last channel only) ## compatible sample mode @@ -45,9 +50,9 @@ due to limitations in some of those sound chips, some restrictions exist: - NES: if on DPCM mode, only a limited selection of frequencies is available, and loop position isn't supported (only entire sample). - SegaPCM: your sample can't be longer than 65535, and the maximum frequency is 31.25KHz. - QSound: your sample can't be longer than 65535, and the loop length shall not be greater than 32767. -- Neo Geo (ADPCM-A): no looping supported. your samples will play at ~18.5KHz. -- Neo Geo (ADPCM-B): no loop position supported (only entire sample), and the maximum frequency is ~55KHz. -- YM2608: the maximum frequency is ~55KHz. +- Neo Geo (ADPCM-A): no looping supported. your samples will play at 18.518KHz. +- Neo Geo (ADPCM-B): no loop position supported (only entire sample), and the maximum frequency is 55.555KHz. +- YM2608: the maximum frequency is 55.555KHz. - MSM6258/MSM6295: no arbitrary frequency. - ZX Spectrum Beeper: your sample can't be longer than 2048, and it always plays at ~55KHz. - Seta/Allumer X1-010: frequency resolution is terrible in the lower end. your sample can't be longer than 131072. diff --git a/papers/doc/7-systems/README.md b/doc/7-systems/README.md similarity index 100% rename from papers/doc/7-systems/README.md rename to doc/7-systems/README.md diff --git a/papers/doc/7-systems/amiga.md b/doc/7-systems/amiga.md similarity index 50% rename from papers/doc/7-systems/amiga.md rename to doc/7-systems/amiga.md index 41911445..8f49bd12 100644 --- a/papers/doc/7-systems/amiga.md +++ b/doc/7-systems/amiga.md @@ -4,12 +4,14 @@ a computer with a desktop OS, lifelike graphics and 4 channels of PCM sound in 1 in this very computer music trackers were born... +imported MOD files use this chip, and will set A-4 tuning to 436. + # effects -- `10xx`: toggle low-pass filter. `0` turns it off and `1` turns it on. -- `11xx`: toggle amplitude modulation with the next channel. +- `10xx`: **toggle low-pass filter.** `0` turns it off and `1` turns it on. +- `11xx`: **toggle amplitude modulation with the next channel.** - does not work on the last channel. -- `12xx`: toggle period (frequency) modulation with the next channel. +- `12xx`: **toggle period (frequency) modulation with the next channel.** - does not work on the last channel. -- `13xx`: change wave. +- `13xx`: **change wave.** - only works when "Mode" is set to "Wavetable" in the instrument. diff --git a/doc/7-systems/ay8910.md b/doc/7-systems/ay8910.md new file mode 100644 index 00000000..11fa31b3 --- /dev/null +++ b/doc/7-systems/ay8910.md @@ -0,0 +1,46 @@ +# General Instrument AY-3-8910 + +this chip was used in many home computers (ZX Spectrum, MSX, Amstrad CPC, Atari ST, etc.), video game consoles (Intellivision and Vectrex), arcade boards and even slot machines! + +it is a 3-channel square/noise/envelope sound generator. the chip's powerful sound comes from the envelope... + +the AY-3-8914 variant was used in Intellivision, which is pretty much an AY with 4 level envelope volume per channel and different register format. + +# effects + +- `20xx`: **set channel mode.** + - `0`: square + - `1`: noise + - `2`: square and noise + - `3`: envelope + - `4`: envelope and square + - `5`: envelope and noise + - `6`: envelope and square and noise + - `7`: nothing +- `21xx`: **set noise frequency.** range is `0` to `1F`. +- `22xy`: **set envelope mode.** + - `x` sets the envelope shape: + - `0`: `\___` decay + - `4`: `/___` attack once + - `8`: `\\\\` saw + - `9`: `\___` decay + - `A`: `\/\/` inverse obelisco + - `B`: `\¯¯¯` decay once + - `C`: `////` inverse saw + - `D`: `/¯¯¯` attack + - `E`: `/\/\` obelisco + - `F`: `/___` attack once + - if `y` is 1 then the envelope will affect this channel. +- `23xx`: **set envelope period low byte.** +- `24xx`: **set envelope period high byte.** +- `25xx`: **slide envelope period up.** +- `26xx`: **slide envelope period down.** +- `29xy`: **enable auto-envelope mode.** + - in this mode the envelope period is set to the channel's notes, multiplied by a fraction. + - `x` is the numerator. + - `y` is the denominator. + - if `x` or `y` are 0 this will disable auto-envelope mode. +- `2Exx`: **write to I/O port A.** + - this changes the port's mode to "write". make sure you have connected something to it. +- `2Fxx`: **write to I/O port B.** + - this changes the port's mode to "write". make sure you have connected something to it. diff --git a/doc/7-systems/ay8930.md b/doc/7-systems/ay8930.md new file mode 100644 index 00000000..6bbe0685 --- /dev/null +++ b/doc/7-systems/ay8930.md @@ -0,0 +1,55 @@ +# Microchip AY8930 + +a backwards-compatible successor to the AY-3-8910, with increased volume resolution, duty cycle control, three envelopes and highly configurable noise generator. + +sadly, this soundchip has only ever observed minimal success, and has remained rather obscure since. +it is best known for being used in the Covox Sound Master, which didn't sell well either. it also observed very minimal success in Merit's CRT-250 machines, but only as a replacement for the AY-3-8910. + +emulation of this chip in Furnace is now complete thanks to community efforts and hardware testing, which an MSX board called Darky has permitted. + +# effects + +- `12xx`: **set channel duty cycle.** + - `0`: 3.125% + - `1`: 6.25% + - `2`: 12.5% + - `3`: 25% + - `4`: 50% + - `5`: 75% + - `6`: 87.5% + - `7`: 93.75% + - `8`: 96.875% +- `20xx`: **set channel mode.** `xx` may be one of the following: + - `0`: square + - `1`: noise + - `2`: square and noise + - `3`: envelope + - `4`: envelope and square + - `5`: envelope and noise + - `6`: envelope and square and noise + - `7`: nothing +- `21xx`: **set noise frequency.** `xx` is a value between `00` and `FF`. +- `22xy`: **set envelope mode.** + - `x` sets the envelope shape, which may be one of the following: + - `0`: `\___` decay + - `4`: `/___` attack once + - `8`: `\\\\` saw + - `9`: `\___` decay + - `A`: `\/\/` inverse obelisco + - `B`: `\¯¯¯` decay once + - `C`: `////` inverse saw + - `D`: `/¯¯¯` attack + - `E`: `/\/\` obelisco + - `F`: `/___` attack once + - if `y` is 1 then the envelope will affect this channel. +- `23xx`: **set envelope period low byte.** +- `24xx`: **set envelope period high byte.** +- `25xx`: **slide envelope period up.** +- `26xx`: **slide envelope period down.** +- `27xx`: **set noise AND mask.** +- `28xx`: **set noise OR mask.** +- `29xy`: **enable auto-envelope mode.** + - in this mode the envelope period is set to the channel's notes, multiplied by a fraction. + - `x` is the numerator. + - `y` is the denominator. + - if `x` or `y` are 0 this will disable auto-envelope mode. diff --git a/papers/doc/7-systems/bubblesystem.md b/doc/7-systems/bubblesystem.md similarity index 80% rename from papers/doc/7-systems/bubblesystem.md rename to doc/7-systems/bubblesystem.md index b339b893..c04aa098 100644 --- a/papers/doc/7-systems/bubblesystem.md +++ b/doc/7-systems/bubblesystem.md @@ -6,8 +6,8 @@ however, the K005289 is just part of the logic used for pitch and wavetable ROM waveform select and volume control are tied with single AY-3-8910 IO for both channels. another AY-3-8910 IO is used for reading sound hardware status. -Furnace emulates this configuration as a "chip" with 32x16 wavetables. +Furnace emulates this configuration as a "chip" with 32×16 wavetables. # effects -- `10xx`: change wave. +- `10xx`: **change wave.** diff --git a/papers/doc/7-systems/c64.md b/doc/7-systems/c64.md similarity index 55% rename from papers/doc/7-systems/c64.md rename to doc/7-systems/c64.md index 0f8054ef..7627f3d9 100644 --- a/papers/doc/7-systems/c64.md +++ b/doc/7-systems/c64.md @@ -8,7 +8,7 @@ two versions of aforementioned chip exist - 6581 (original chip) and 8580 (impro # effects -- `10xx`: change wave. the following values are accepted: +- `10xx`: **change wave.** the following values are accepted: - `00`: nothing - `01`: triangle - `02`: saw @@ -18,14 +18,14 @@ two versions of aforementioned chip exist - 6581 (original chip) and 8580 (impro - `06`: pulse and saw - `07`: pulse and triangle and saw - `08`: noise -- `11xx`: set coarse cutoff. `xx` may be a value between 00 to 64. - - **this effect only exists for compatibility reasons, and its use is discouraged.** +- `11xx`: **set coarse cutoff.** `xx` may be a value between `00` and `64`. + - _this effect only exists for compatibility reasons, and its use is discouraged._ - use effect `4xxx` instead. -- `12xx`: set coarse duty cycle. `xx` may be a value between 00 to 64. - - **this effect only exists for compatibility reasons, and its use is discouraged.** +- `12xx`: **set coarse duty cycle.** `xx` may be a value between `00` and `64`. + - _this effect only exists for compatibility reasons, and its use is discouraged._ - use effect `3xxx` instead. -- `13xx`: set resonance. `xx` may be a value between 00 and 0F. -- `14xx`: set filter mode. the following values are accepted: +- `13xx`: **set resonance.** `xx` may be a value between `00` and `0F`. +- `14xx`: **set filter mode.** the following values are accepted: - `00`: filter off - `01`: low pass - `02`: band pass @@ -34,26 +34,26 @@ two versions of aforementioned chip exist - 6581 (original chip) and 8580 (impro - `05`: band reject/stop/notch - `06`: high+band pass - `07`: all pass -- `15xx`: set envelope reset time. +- `15xx`: **set envelope reset time.** - this is the amount of ticks the channel turns off before a note occurs in order to reset the envelope safely. - if `xx` is 0 or higher than the song speed, the envelope will not reset. -- `1Axx`: disable envelope reset for this channel. -- `1Bxy`: reset cutoff: +- `1Axx`: **disable envelope reset for this channel.** +- `1Bxy`: **reset cutoff**: - if `x` is not 0: on new note - if `y` is not 0: now - this effect is not necessary if the instrument's cutoff macro is absolute. -- `1Cxy`: reset duty cycle: +- `1Cxy`: **reset duty cycle**: - if `x` is not 0: on new note - if `y` is not 0: now - this effect is not necessary if the instrument's duty macro is absolute. -- `1Exy`: change additional parameters. +- `1Exy`: **change additional parameters.** - `x` may be one of the following: - - `0`: attack (`y` from 0 to F) - - `1`: decay (`y` from 0 to F) - - `2`: sustain (`y` from 0 to F) - - `3`: release (`y` from 0 to F) - - `4`: ring modulation (`y` is 0 or 1) - - `5`: oscillator sync (`y` is 0 or 1) - - `6`: disable channel 3 (`y` is 0 or 1) -- `3xxx`: set duty cycle. `xxx` range is 000-FFF -- `4xxx`: set cutoff. `xxx` range is 000-7FF. + - `0`: attack (`y` from `0` to `F`) + - `1`: decay (`y` from `0` to `F`) + - `2`: sustain (`y` from `0` to `F`) + - `3`: release (`y` from `0` to `F`) + - `4`: ring modulation (`y` is `0` or `1`) + - `5`: oscillator sync (`y` is `0` or `1`) + - `6`: disable channel 3 (`y` is `0` or `1`) +- `3xxx`: **set duty cycle.** `xxx` range is `000` to `FFF`. +- `4xxx`: **set cutoff.** `xxx` range is `000` to `7FF`. diff --git a/papers/doc/7-systems/dac.md b/doc/7-systems/dac.md similarity index 100% rename from papers/doc/7-systems/dac.md rename to doc/7-systems/dac.md diff --git a/doc/7-systems/es5506.md b/doc/7-systems/es5506.md new file mode 100644 index 00000000..436aca0c --- /dev/null +++ b/doc/7-systems/es5506.md @@ -0,0 +1,41 @@ +# Ensoniq ES5506 (OTTO) + +sample-based synthesis chip used in a bunch of Taito arcade machines and PC sound cards like Soundscape Elite. a variant of it was the heart of the well-known Gravis Ultrasound. + +it supports a whopping 32 channels of 16-bit PCM and: + +- real time digital filters +- frequency interpolation +- loop start and stop positions for each voice (bidirectional and reverse looping) +- internal volume multiplication and stereo panning +- hardware support for envelopes + +# effects + +- `10xx`: **set waveform.** +- `11xx`: **set filter mode.** values are `0` through `3`. +- `120x`: **set pause (bit 0).** pauses the sample until the bit is unset; it will then resume where it left off. +- `14xx`: **set filter coefficient K1 low byte.** +- `15xx`: **set filter coefficient K1 high byte.** +- `16xx`: **set filter coefficient K2 low byte.** +- `17xx`: **set filter coefficient K2 high byte.** +- `18xx`: **set filter coefficient K1 slide up.** +- `19xx`: **set filter coefficient K1 slide down.** +- `1Axx`: **set filter coefficient K2 slide up.** +- `1Bxx`: **set filter coefficient K2 slide down.** +- `20xx`: **set envelope count.** +- `22xx`: **set envelope left volume ramp.** +- `23xx`: **set envelope right volume ramp.** +- `24xx`: **set envelope filter coefficient K1 ramp.** +- `25xx`: **set envelope filter coefficient K1 ramp (slower).** +- `26xx`: **set envelope filter coefficient K2 ramp.** +- `27xx`: **set envelope filter coefficient K2 ramp (slower).** +- `3xxx`: **set coarse filter coefficient K1.** +- `4xxx`: **set coarse filter coefficient K2.** +- `81xx`: **set panning (left channel).** +- `82xx`: **set panning (right channel).** +- `88xx`: **set panning (rear channels).** +- `89xx`: **set panning (rear left channel).** +- `8Axx`: **set panning (rear right channel).** +- `9xxx`: **set sample offset.** resets sample position to `xxx * 0x100`. +- `DFxx`: **set sample playback direction.** diff --git a/papers/doc/7-systems/fds.md b/doc/7-systems/fds.md similarity index 68% rename from papers/doc/7-systems/fds.md rename to doc/7-systems/fds.md index e7bede28..8105d107 100644 --- a/papers/doc/7-systems/fds.md +++ b/doc/7-systems/fds.md @@ -1,20 +1,20 @@ # Famicom Disk System -the Famicom Disk System is an expansion device for the Famicom (known as NES outside Japan), a popular console from the '80's. +the Famicom Disk System is an expansion device for the Famicom (known as NES outside Japan), a popular console from the '80s. as it name implies, it allowed people to play games on specialized floppy disks that could be rewritten on vending machines, therefore reducing the cost of ownership and manufacturing. it also offers an additional 6-bit, 64-byte wavetable sound channel with (somewhat limited) FM capabilities, which is what Furnace supports. # effects -- `10xx`: change wave. -- `11xx`: set modulation depth. -- `12xy`: set modulation speed high byte and toggle on/off. - - `x` is the toggle. a value of 1 turns on the modulator. +- `10xx`: **change wave.** +- `11xx`: **set modulation depth.** +- `12xy`: **set modulation speed high byte and toggle on/off.** + - `x` is the toggle. a value of `1` turns on the modulator. - `y` is the speed. -- `13xx`: set modulation speed low byte. -- `14xx`: set modulator position. -- `15xx`: set modulator wave. +- `13xx`: **set modulation speed low byte.** +- `14xx`: **set modulator position.** +- `15xx`: **set modulator wave.** - `xx` points to a wavetable. it should (preferably) have a height of 7 with the values mapping to: - 0: +0 - 1: +1 diff --git a/doc/7-systems/game-boy.md b/doc/7-systems/game-boy.md new file mode 100644 index 00000000..505de282 --- /dev/null +++ b/doc/7-systems/game-boy.md @@ -0,0 +1,22 @@ +# Game Boy + +the Nintendo Game Boy is one of the most successful portable game systems ever made. + +with stereo sound, two pulse channels, a wave channel and a noise one it packed some serious punch. + +# effects + +- `10xx`: **change wave.** +- `11xx`: **set noise length.** + - `0`: long + - `1`: short +- `12xx`: **set duty cycle.** + - `0`: 12.5% + - `1`: 25% + - `2`: 50% + - `3`: 75% +- `13xy`: **setup sweep.** pulse channels only. + - `x` is the time. + - `y` is the shift. + - set to `0` to disable it. +- `14xx`: **set sweep direction.** `0` is up and `1` is down. diff --git a/doc/7-systems/genesis.md b/doc/7-systems/genesis.md new file mode 100644 index 00000000..f0b81522 --- /dev/null +++ b/doc/7-systems/genesis.md @@ -0,0 +1,37 @@ +# Sega Genesis/Mega Drive + +a video game console that showed itself as the first true rival to Nintendo's video game market near-monopoly in the US during the '80's. + +this console is powered by two sound chips: the [Yamaha YM2612](ym2612.md) and [a derivative of the SN76489](sms.md). + +# effects + +- `10xy`: **set LFO parameters.** + - `x` toggles the LFO. + - `y` sets its speed. +- `11xx`: **set feedback of channel.** +- `12xx`: **set operator 1 level.** +- `13xx`: **set operator 2 level.** +- `14xx`: **set operator 3 level.** +- `15xx`: **set operator 4 level.** +- `16xy`: **set multiplier of operator.** + - `x` is the operator (1-4). + - `y` is the multiplier. +- `17xx`: **enable PCM channel.** + - this only works on channel 6. + - _this effect is here for compatibility reasons!_ it is otherwise recommended to use Sample type instruments (which automatically enable PCM mode when used). +- `18xx`: **toggle extended channel 3 mode.** + - `0` disables it and `1` enables it. + - only in extended channel 3 chip. +- `19xx`: **set attack of all operators.** +- `1Axx`: **set attack of operator 1.** +- `1Bxx`: **set attack of operator 2.** +- `1Cxx`: **set attack of operator 3.** +- `1Dxx`: **set attack of operator 4.** +- `20xy`: **set PSG noise mode.** + - `x` controls whether to inherit frequency from PSG channel 3. + - `0`: use one of 3 preset frequencies (C: A-2; C#: A-3; D: A-4). + - `1`: use frequency of PSG channel 3. + - `y` controls whether to select noise or thin pulse. + - `0`: thin pulse. + - `1`: noise. diff --git a/papers/doc/7-systems/k007232.md b/doc/7-systems/k007232.md similarity index 64% rename from papers/doc/7-systems/k007232.md rename to doc/7-systems/k007232.md index adf7d95f..f5571e1e 100644 --- a/papers/doc/7-systems/k007232.md +++ b/doc/7-systems/k007232.md @@ -2,10 +2,10 @@ a 2-channel PCM sound chip from Konami which was used in some of their 1986-1990 arcade boards. -Its sample format is unique; the topmost bit is the end marker, and the low 7 bits are used for generating sound (unsigned format). +its sample format is unique; the topmost bit is the end marker, and the low 7 bits are used for generating sound (unsigned format). -It has 7 bit digital output per each channel and no volume register on chip, so it needs external logic to control channel volume. +it has 7 bit digital output per each channel and no volume register on chip, so it needs external logic to control channel volume. # effects -- Nothing for now +- nothing for now. diff --git a/papers/doc/7-systems/lynx.md b/doc/7-systems/lynx.md similarity index 94% rename from papers/doc/7-systems/lynx.md rename to doc/7-systems/lynx.md index e7178a61..24f32634 100644 --- a/papers/doc/7-systems/lynx.md +++ b/doc/7-systems/lynx.md @@ -15,6 +15,5 @@ the Atari Lynx has a 6502-based CPU with a sound part (this chip is known as MIK # effects -- `3xxx`: Load LFSR (0 to FFF). - - this is a bitmask. +- `3xxx`: **load LFSR.** this is a bitmask with values ranging from `000` to `FFF`. - for it to work, duty macro in instrument editor must be set to some value. without it LFSR will not be fed with any bits. diff --git a/papers/doc/7-systems/mmc5.md b/doc/7-systems/mmc5.md similarity index 74% rename from papers/doc/7-systems/mmc5.md rename to doc/7-systems/mmc5.md index d483bd57..a838dfe8 100644 --- a/papers/doc/7-systems/mmc5.md +++ b/doc/7-systems/mmc5.md @@ -8,5 +8,5 @@ additionally, it offers an 8-bit DAC which can be used to play samples. only one # effects -- `12xx`: set duty cycle or noise mode of channel. - - may be 0-3 for the pulse channels. +- `12xx`: **set duty cycle or noise mode of channel.** + - may be `0` through `3` for the pulse channels. diff --git a/papers/doc/7-systems/msm5232.md b/doc/7-systems/msm5232.md similarity index 88% rename from papers/doc/7-systems/msm5232.md rename to doc/7-systems/msm5232.md index b08875a3..0f28cb78 100644 --- a/papers/doc/7-systems/msm5232.md +++ b/doc/7-systems/msm5232.md @@ -16,11 +16,11 @@ Furnace implements this chip in a way that allows the following features: # effects -- `10xy`: set group control. +- `10xy`: **set group control.** - `x` sets sustain mode. - `y` is a 4-bit mask which toggles overtones. -- `11xx`: set noise mode. -- `12xx`: set group attack (0 to 5). +- `11xx`: **set noise mode.** +- `12xx`: **set group attack.** range is `0` to `5`. - only in internal (capacitor-based) envelope mode. -- `13xx`: set group decay (0 to 11). +- `13xx`: **set group decay.** range is `0` to `11`. - only in internal (capacitor-based) envelope mode. diff --git a/papers/doc/7-systems/msm6258.md b/doc/7-systems/msm6258.md similarity index 100% rename from papers/doc/7-systems/msm6258.md rename to doc/7-systems/msm6258.md diff --git a/doc/7-systems/msm6295.md b/doc/7-systems/msm6295.md new file mode 100644 index 00000000..3785cc62 --- /dev/null +++ b/doc/7-systems/msm6295.md @@ -0,0 +1,7 @@ +# OKI MSM6295 + +an upgrade from 6258 - it provides 4 ADPCM channels, at max 32 KHz (still no variable pitch though). between late '80s and late '90s, it was one of the most common, if not _the_ most common soundchip used in arcade machines (Capcom, Toaplan, Kaneko, Atari, Tecmo, the list can go on and on...) + +# effects + +- `20xx`: **set chip output rate.** diff --git a/doc/7-systems/n163.md b/doc/7-systems/n163.md new file mode 100644 index 00000000..cb5ff530 --- /dev/null +++ b/doc/7-systems/n163.md @@ -0,0 +1,41 @@ +# Namco 163 (also called N163, Namco C163, Namco 106 (sic), Namco 160 or Namco 129) + +this is one of Namco's NES mappers, with up to 8 wavetable channels. + +it has 256 nibbles (128 bytes) of internal RAM which is shared between channel state and waves. + +wavetables are variable in size and may be allocated anywhere in RAM. at least 128 nibbles (64 bytes) can be dedicated to waves, with more available if not all channels are used - waveform RAM area becomes smaller as more channels are activated, since channel registers consume 8 bytes for each channel. + +Namco 163 uses time-division multiplexing for its output. this means that only one channel is output per sample (like OPLL and OPN2). therefore, its sound quality gets worse as more channels are activated. + +Furnace supports loading waveforms into RAM and waveform playback simultaneously, and channel limit is dynamically changeable with effect commands. + +you must load waveform to RAM first for playback, as its load behavior auto-updates when every waveform changes. + +both waveform playback and load command work independently per each channel columns. +global commands don't care about the channel columns for work commands and its load behavior is independent with per-channel column load commands. + +# effects + +- `10xx`: **set waveform for playback.** +- `11xx`: **set waveform position in RAM for playback.** single nibble unit. +- `12xx`: **set waveform length in RAM for playback.** `04` to `FC`, 4 nibble unit. +- `130x`: **set playback waveform update behavior.** + - `0`: off. + - bit 0: update now. + - bit 1: update when every waveform is changed. +- `14xx`: **set waveform for load to RAM.** +- `15xx`: **set waveform position for load to RAM.** single nibble unit. +- `16xx`: **set waveform length for load to RAM.** `04` to `FC`, 4 nibble unit. +- `170x`: **set waveform load behavior.** + - `0`: off. + - bit 0: load now. + - bit 1: load when every waveform is changed. +- `180x`: **set channel limit.** range is `0` to `7`; 1 is added to get results of 1 through 8. +- `20xx`: **globally set waveform for load to RAM.** +- `21xx`: **globally set waveform position for load to RAM.** single nibble unit. +- `22xx`: **globally set waveform length for load to RAM.** `04` to `FC`, 4 nibble unit. +- `230x`: **globally set waveform load behavior.** + - `0`: off. + - bit 0: load now. + - bit 1: load when every waveform is changed. diff --git a/papers/doc/7-systems/namco.md b/doc/7-systems/namco.md similarity index 81% rename from papers/doc/7-systems/namco.md rename to doc/7-systems/namco.md index 0a53d15d..54d8b964 100644 --- a/papers/doc/7-systems/namco.md +++ b/doc/7-systems/namco.md @@ -6,5 +6,5 @@ everything starts with Namco WSG, which is a simple 3-channel wavetable with no # effects -- `10xx`: change waveform. -- `11xx`: toggle noise mode (WARNING: only on C30). +- `10xx`: **change waveform.** +- `11xx`: **toggle noise mode.** _warning:_ only on C30. diff --git a/doc/7-systems/nes.md b/doc/7-systems/nes.md new file mode 100644 index 00000000..c3ccb706 --- /dev/null +++ b/doc/7-systems/nes.md @@ -0,0 +1,181 @@ +# NES + +the console from Nintendo that plays Super Mario Bros. and helped revive the agonizing video game market in the US during mid-80s. + +also known as Famicom. it is a five-channel sound generator: first two channels play pulse wave with three different duty cycles, third is a fixed-volume triangle channel, fourth is a noise channel (can work in both pseudo-random and periodic modes) and fifth is a (D)PCM sample channel. + +# effects + +- `11xx`: **write to delta modulation counter.** range is `00` to `7F`. + - this may be used to attenuate the triangle and noise channels; at `7F`, they will be at about 57% volume. + - will not work if a sample is playing. +- `12xx`: **set duty cycle or noise mode of channel.** + - may be `0` to `3` for the pulse channels: + - `0`: 12.5% + - `1`: 25% + - `2`: 50% + - `3`: 75% + - may be `0` or `1` for the noise channel: + - `0`: long (15-bit LFSR, 32767-step) + - `1`: short (9-bit LFSR, 93-step) +- `13xy`: **setup sweep up.** + - `x` is the time. + - `y` is the shift. + - set to `0` to disable it. +- `14xy`: **setup sweep down.** + - `x` is the time. + - `y` is the shift. + - set to `0` to disable it. +- `15xx`: **set envelope mode.** + - `0`: envelope + length counter. volume represents envelope duration. + - `1`: length counter. volume represents output volume. + - `2`: looping envelope. volume represents envelope duration. + - `3`: constant volume. default value. volume represents output volume. + - Pulse and noise channels only. + - you may need to apply a phase reset (using the macro) to make the envelope effective. +- `16xx`: **set length counter.** + - see table below for possible values. + - this will trigger phase reset. +- `17xx`: **set frame counter mode.** + - `0`: 4-step. + - NTSC: 120Hz sweeps and lengths; 240Hz envelope. + - PAL: 100Hz sweeps and lengths; 200Hz envelope. + - Dendy: 118.9Hz sweeps and lengths; 237.8Hz envelope. + - `1`: 5-step. + - NTSC: 96Hz sweeps and lengths; 192Hz envelope. + - PAL: 80Hz sweeps and lengths; 160Hz envelope. + - Dendy: 95.1Hz sweeps and lengths; 190.2Hz envelope. +- `18xx`: **set PCM channel mode.** + - `00`: PCM (software). + - `01`: DPCM (hardware). + - when in DPCM mode, samples will sound muffled (due to its nature), availables pitches are limited, and loop point is ignored. +- `19xx`: **set triangle linear counter.** + - `00` to `7F` set the counter. + - `80` and higher halt it. +- `20xx`: **set DPCM frequency.** + - only works in DPCM mode. + - see table below for possible values. + +# tables + +## short noise frequencies (NTSC) + +note | arpeggio | fundamental | MIDI note | pitch +:---- | -------: | ----------: | --------: | :---------- +`C-0` | @0 | 4.7 Hz | -9.47 | `d_1` + 53¢ +`C#0` | @1 | 9.5 Hz | 2.53 | `D-0` + 53¢ +`D-0` | @2 | 18.9 Hz | 14.55 | `D-1` + 55¢ +`D#0` | @3 | 25.3 Hz | 19.53 | `G-1` + 53¢ +`E-0` | @4 | 37.9 Hz | 26.55 | `D-2` + 55¢ +`F-0` | @5 | 50.6 Hz | 31.57 | `G-2` + 57¢ +`F#0` | @6 | 75.8 Hz | 38.55 | `D-3` + 55¢ +`G-0` | @7 | 95.3 Hz | 42.51 | `F#3` + 51¢ +`G#0` | @8 | 120.3 Hz | 46.55 | `A#3` + 55¢ +`A-0` | @9 | 150.4 Hz | 50.41 | `D-4` + 41¢ +`A#0` | @10 | 200.5 Hz | 55.39 | `G-4` + 39¢ +`B-0` | @11 | 300.7 Hz | 62.41 | `D-5` + 41¢ +`C-1` | @12 | 601.4 Hz | 74.41 | `D-6` + 41¢ +`C#1` | @13 | 1202.8 Hz | 86.41 | `D-7` + 41¢ +`D-1` | @14 | 2405.6 Hz | 98.41 | `D-8` + 41¢ +`D#1` | @15 | 4811.2 Hz | 110.41 | `D-9` + 41¢ + +reference: [NESdev](https://www.nesdev.org/wiki/APU_Noise) + +## length counter table + + + + + +value | raw | NTSC | PAL | Dendy | NTSC 5-step | PAL 5-step | Dendy 5-step +-----:|----:|------:|------:|------:|------------:|-----------:|-------------: + `03` | 2 | 17ms | 20ms | 17ms | 21ms | 25ms | 21ms + `05` | 4 | 33ms | 40ms | 34ms | 42ms | 50ms | 42ms + `07` | 6 | 50ms | 60ms | 50ms | 63ms | 75ms | 63ms + `09` | 8 | 67ms | 80ms | 67ms | 83ms | 100ms | 84ms + `00` | 10 | 83ms | 100ms | 84ms | 104ms | 125ms | 105ms + `0B` | 10 | 83ms | 100ms | 84ms | 104ms | 125ms | 105ms + `0D` | 12 | 100ms | 120ms | 101ms | 125ms | 150ms | 126ms + `10` | 12 | 100ms | 120ms | 101ms | 125ms | 150ms | 126ms + `0C` | 14 | 117ms | 140ms | 118ms | 146ms | 175ms | 147ms + `0F` | 14 | 117ms | 140ms | 118ms | 145ms | 175ms | 147ms + `1C` | 16 | 133ms | 160ms | 135ms | 167ms | 200ms | 168ms + `11` | 16 | 133ms | 160ms | 135ms | 167ms | 200ms | 168ms + `13` | 18 | 150ms | 180ms | 151ms | 188ms | 225ms | 189ms + `02` | 20 | 166ms | 200ms | 168ms | 208ms | 250ms | 210ms + `15` | 20 | 167ms | 200ms | 168ms | 208ms | 250ms | 210ms + `17` | 22 | 183ms | 220ms | 185ms | 229ms | 275ms | 231ms + `12` | 24 | 200ms | 240ms | 202ms | 250ms | 300ms | 252ms + `19` | 24 | 200ms | 240ms | 202ms | 250ms | 300ms | 252ms + `0E` | 26 | 217ms | 260ms | 219ms | 271ms | 325ms | 273ms + `1B` | 26 | 217ms | 260ms | 219ms | 271ms | 325ms | 273ms + `1D` | 28 | 233ms | 280ms | 235ms | 292ms | 350ms | 294ms + `1F` | 30 | 250ms | 300ms | 252ms | 313ms | 375ms | 315ms + `1E` | 32 | 267ms | 320ms | 269ms | 333ms | 400ms | 336ms + `04` | 40 | 333ms | 400ms | 336ms | 417ms | 500ms | 421ms + `14` | 48 | 400ms | 480ms | 404ms | 500ms | 600ms | 505ms + `0A` | 60 | 500ms | 600ms | 505ms | 625ms | 750ms | 631ms + `1A` | 72 | 600ms | 720ms | 606ms | 750ms | 900ms | 757ms + `06` | 80 | 667ms | 800ms | 673ms | 833ms | 1.0s | 841ms + `16` | 96 | 800ms | 960ms | 807ms | 1.0s | 1.2s | 1.0s + `08` | 160 | 1.3s | 1.6s | 1.3s | 1.7s | 2.0s | 1.7s + `18` | 192 | 1.6s | 1.9s | 1.6s | 2.0s | 2.4s | 2.0s + `01` | 254 | 2.1s | 2.5s | 2.1s | 2.6s | 3.2s | 2.7s + +reference: [NESdev](https://www.nesdev.org/wiki/APU_Length_Counter) + +## DPCM frequency table + +value | NTSC | PAL +------|----------:|----------: + `00` | 4181.7Hz | 4177.4Hz + `01` | 4709.9Hz | 4696.6Hz + `02` | 5264.0Hz | 5261.4Hz + `03` | 5593.0Hz | 5579.2Hz + `04` | 6257.9Hz | 6023.9Hz + `05` | 7046.3Hz | 7044.9Hz + `06` | 7919.3Hz | 7917.2Hz + `07` | 8363.4Hz | 8397.0Hz + `08` | 9419.9Hz | 9446.6Hz + `09` | 11186.1Hz | 11233.8Hz + `0A` | 12604.0Hz | 12595.5Hz + `0B` | 13982.6Hz | 14089.9Hz + `0C` | 16884.6Hz | 16965.4Hz + `0D` | 21306.8Hz | 21315.5Hz + `0E` | 24858.0Hz | 25191.0Hz + `0F` | 33143.9Hz | 33252.1Hz diff --git a/doc/7-systems/opl.md b/doc/7-systems/opl.md new file mode 100644 index 00000000..5f7034cb --- /dev/null +++ b/doc/7-systems/opl.md @@ -0,0 +1,80 @@ +# Yamaha OPL + +a series of FM sound chips which were very popular in DOS land. it was so popular that even Yamaha made a logo for it! + +essentially a downgraded version of Yamaha's other FM chips, with only 2 operators per channel. +however, it also had a [drums mode](opll.md), and later chips in the series added more waveforms (than just the typical sine) and even a 4-operator mode. + +the original OPL (Yamaha YM3526) was present as an expansion for the Commodore 64 and MSX computers (erm, a variant of it). it only had 9 two-operator channels and drums mode. + +its successor, the OPL2 (Yamaha YM3812), added 3 more waveforms and was one of the more popular chips because it was present on the AdLib card for PC. +later Creative would borrow the chip to make the Sound Blaster, and totally destroyed AdLib's dominance. + +the OPL3 (Yamaha YMF262) added 9 more channels, 4 more waveforms, rudimentary 4-operator mode (pairing up to 12 channels to make up to six 4-operator channels), quadraphonic output (sadly Furnace only supports stereo) and some other things. + +afterwards everyone moved to Windows and software mixed PCM streaming... + +# effects + +- `10xx`: **set AM depth.** the following values are accepted: + - `0`: 1dB (shallow) + - `1`: 4.8dB (deep) + - this effect applies to all channels. +- `11xx`: **set feedback of channel.** +- `12xx`: **set operator 1 level.** +- `13xx`: **set operator 2 level.** +- `14xx`: **set operator 3 level.** + - only in 4-op mode (OPL3). +- `15xx`: **set operator 4 level.** + - only in 4-op mode (OPL3). +- `16xy`: **sSet multiplier of operator.** + - `x` is the operator (1-4; last 2 operators only in 4-op mode). + - `y` is the multiplier. +- `17xx`: **set vibrato depth.** + - `0`: normal + - `1`: double + - this effect applies to all channels. +- `18xx`: **toggle drums mode.** + - `0` disables it and `1` enables it. + - only in drums chip. +- `19xx`: **set attack of all operators.** +- `1Axx`: **set attack of operator 1.** +- `1Bxx`: **set attack of operator 2.** +- `1Cxx`: **set attack of operator 3.** + - only in 4-op mode (OPL3). +- `1Dxx`: **set attack of operator 4.** + - only in 4-op mode (OPL3). +- `2Axy`: **set waveform of operator.** + - `x` is the operator from 1 to 4; the last 2 operators only work in 4-op mode. a value of `0` means "all operators". + - `y` is the value. + - only in OPL2 or higher. +- `30xx`: **enable envelope hard reset.** + - this works by inserting a quick release and tiny delay before a new note. +- `50xy`: **set AM of operator.** + - `x` is the operator from 1 to 4; the last 2 operators only work in 4-op mode. a value of `0` means "all operators". + - `y` determines whether AM is on. +- `51xy`: **set SL of operator.** + - `x` is the operator from 1 to 4; the last 2 operators only work in 4-op mode. a value of `0` means "all operators". + - `y` is the value. +- `52xy`: **set RR of operator.** + - `x` is the operator from 1 to 4; the last 2 operators only work in 4-op mode. a value of `0` means "all operators". + - `y` is the value. +- `53xy`: **set VIB of operator.** + - `x` is the operator from 1 to 4; the last 2 operators only work in 4-op mode. a value of `0` means "all operators". + - `y` determines whether VIB is on. +- `54xy`: **set KSL of operator.** + - `x` is the operator from 1 to 4; the last 2 operators only work in 4-op mode. a value of `0` means "all operators". + - `y` is the value. +- `55xy`: **set SUS of operator.** + - `x` is the operator from 1 to 4; the last 2 operators only work in 4-op mode. a value of `0` means "all operators". + - `y` determines whether SUS is on. +- `56xx`: **set DR of all operators.** +- `57xx`: **set DR of operator 1.** +- `58xx`: **set DR of operator 2.** +- `59xx`: **set DR of operator 3.** + - only in 4-op mode (OPL3). +- `5Axx`: **set DR of operator 4.** + - only in 4-op mode (OPL3). +- `5Bxy`: **set KSR of operator.** + - `x` is the operator from 1 to 4; the last 2 operators only work in 4-op mode. a value of `0` means "all operators". + - `y` determines whether KSR is on. diff --git a/doc/7-systems/opll.md b/doc/7-systems/opll.md new file mode 100644 index 00000000..c5dd4ff6 --- /dev/null +++ b/doc/7-systems/opll.md @@ -0,0 +1,67 @@ +# Yamaha YM2413/OPLL + +the YM2413, otherwise known as OPLL, is a cost-reduced FM synthesis sound chip, based on the Yamaha YM3812 (OPL2). thought OPL was downgraded enough? :p + +OPLL also spawned a few derivative chips, the best known of these is: +- the famous Konami VRC7. used in the Japan-only video game Lagrange Point, it was **another** cost reduction on top of the OPLL! this time just 6 channels... +- Yamaha YM2423, same chip as YM2413, just a different patch set +- Yamaha YMF281, ditto + +# technical specifications + +the YM2413 is equipped with the following features: + +- 9 channels of 2 operator FM synthesis +- a drum/percussion mode, replacing the last 3 voices with 5 rhythm channels, with drum mode tones hard-defined in the chip itself, like FM instruments. only pitch might be altered. + + - drum mode works like following: FM channel 7 is for Kick Drum, which is a normal FM channel but routed through mixer twice for 2× volume, like all drum sounds. FM channel 8 splits to Snare, Drum, and Hi-Hat. Snare Drum is the carrier and it works with a special 1 bit noise generator combined with a square wave, all possible by overriding phase-generator with some different synthesis method. Hi-Hat is the modulator and it works with the noise generator and also the special synthesis. CH9 splits to Top-Cymbal and Tom-Tom, Top-Cymbal is the carrier and only has the special synthesis, while Tom-Tom is basically a 1op wave. + - special synthesis mentioned already is: 5 square waves are gathered from 4×, 64× and 128× the pitch of channel 8 and 16× and 64× the pitch of channel 9 and they go through a process where 2 HH bits OR'd together, then 1 HH and 1 TC bit OR'd, then the two TC bits OR'd together, and those 3 results get XOR'd. + +- 1 user-definable patch (this patch can be changed throughout the course of the song) +- 15 pre-defined patches which can all be used at the same time +- support for ADSR on both the modulator and the carrier +- sine and half-sine based FM synthesis +- 9 octave note control +- 4096 different frequencies for channels +- 16 unique volume levels (NOTE: volume 0 is NOT silent.) +- modulator and carrier key scaling +- built-in hardware vibrato support + +# effects + +- `11xx`: **set feedback of channel.** +- `12xx`: **set operator 1 level.** +- `13xx`: **set operator 2 level.** +- `16xy`: **set multiplier of operator.** + - `x` is the operator, either 1 or 2. + - `y` is the multiplier. +- `18xx`: **toggle drums mode.** + - `0` disables it and `1` enables it. + - only in drums chip. +- `19xx`: **set attack of all operators.** +- `1Axx`: **set attack of operator 1.** +- `1Bxx`: **set attack of operator 2.** +- `50xy`: **set AM of operator.** + - `x` is the operator, either 1 or 2. a value of `0` means "all operators". + - `y` determines whether AM is on. +- `51xy`: **set SL of operator.** + - `x` is the operator, either 1 or 2. a value of `0` means "all operators". + - `y` is the value. +- `52xy`: **set RR of operator.** + - `x` is the operator, either 1 or 2. a value of `0` means "all operators". + - `y` is the value. +- `53xy`: **set VIB of operator.** + - `x` is the operator, either 1 or 2. a value of `0` means "all operators". + - `y` determines whether VIB is on. +- `54xy`: **set KSL of operator.** + - `x` is the operator, either 1 or 2. a value of `0` means "all operators". + - `y` is the value. +- `55xy`: **set EGT of operator.** + - `x` is the operator, either 1 or 2. a value of `0` means "all operators". + - `y` determines whether EGT is on. +- `56xx`: **set DR of all operators.** +- `57xx`: **set DR of operator 1.** +- `58xx`: **set DR of operator 2.** +- `5Bxy`: **set KSR of operator.** + - `x` is the operator, either 1 or 2. a value of `0` means "all operators". + - `y` determines whether KSR is on. diff --git a/doc/7-systems/opz.md b/doc/7-systems/opz.md new file mode 100644 index 00000000..1abef5c4 --- /dev/null +++ b/doc/7-systems/opz.md @@ -0,0 +1,115 @@ +# Yamaha OPZ (YM2414) + +**disclaimer: despite the name, this has nothing to do with teenage engineering's OP-Z synth!** + +this is the YM2151's little-known successor, used in the Yamaha TX81Z and a few other Yamaha synthesizers. oh, and the Korg Z3 too. + +it adds these features on top of the YM2151: +- 8 waveforms (but they're different from the OPL ones) +- per-channel (possibly) linear volume control separate from TL +- increased multiplier precision (in 1/16ths) +- 4-step envelope generator shift (minimum TL) +- another LFO +- no per-operator key on/off +- fixed frequency mode per operator (kind of like OPN family's extended channel mode but with a bit less precision and for all 8 channels) +- "reverb" effect (actually extends release) + +unlike the YM2151, this chip is officially undocumented. very few efforts have been made to study the chip and document it... +therefore emulation of this chip in Furnace is incomplete and uncertain. + +no plans have been made for TX81Z MIDI passthrough, because: +- Furnace works with register writes rather than MIDI commands +- the MIDI protocol is slow (would not be enough). +- the TX81Z is very slow to process a note on/off or parameter change event. +- the TL range has been reduced to 0-99, but the chip goes from 0-127. + +# effects + +- `10xx`: **set noise frequency of channel 8 operator 4.** `00` disables noise while `01` to `20` enable it. +- `11xx`: **set feedback of channel.** +- `12xx`: **set operator 1 level.** +- `13xx`: **set operator 2 level.** +- `14xx`: **set operator 3 level.** +- `15xx`: **set operator 4 level.** +- `16xy`: **set multiplier of operator.** + - `x` is the operator (1-4). + - `y` is the multiplier. +- `17xx`: **set LFO speed.** +- `18xx`: **set LFO waveform.** `xx` may be one of the following: + - `00`: saw + - `01`: square + - `02`: triangle + - `03`: noise +- `19xx`: **set attack of all operators.** +- `1Axx`: **set attack of operator 1.** +- `1Bxx`: **set attack of operator 2.** +- `1Cxx`: **set attack of operator 3.** +- `1Dxx`: **set attack of operator 4.** +- `1Exx`: **set LFO AM depth.** +- `1Fxx`: **set LFO PM depth.** +- `24xx`: **set LFO 2 speed.** +- `25xx`: **set LFO 2 waveform.** `xx` may be one of the following: + - `00`: saw + - `01`: square + - `02`: triangle + - `03`: noise +- `26xx`: **set LFO 2 AM depth.** +- `27xx`: **set LFO 2 PM depth.** +- `28xy`: **set reverb of operator.** + - `x` is the operator (1-4). a value of `0` means "all operators". + - `y` is the value. +- `2Axy`: **set waveform of operator.** + - `x` is the operator (1-4). a value of `0` means "all operators". + - `y` is the value. +- `2Bxy`: **set EG shift of operator.** + - `x` is the operator (1-4). a value of `0` means "all operators". + - `y` is the value. +- `2Cxy`: **set fine multiplier of operator.** + - `x` is the operator (1-4). a value of `0` means "all operators". + - `y` is the value. +- `2Fxx`: **enable envelope hard reset.** + - this works by inserting a quick release and tiny delay before a new note. +- `3xyy`: **set fixed frequency of operator 1/2.** + - `x` is the block (`0-7` for operator 1; `8-F` for operator 2). + - `y` is the frequency. fixed frequency mode will be disabled if this is less than 8. + - the actual frequency is: `y*(2^x)`. +- `4xyy`: **set fixed frequency of operator 3/4.** + - `x` is the block (`0-7` for operator 3; `8-F` for operator 4). + - `y` is the frequency. fixed frequency mode will be disabled if this is less than 8. + - the actual frequency is: `y*(2^x)`. +- `50xy`: **set AM of operator.** + - `x` is the operator (1-4). a value of `0` means "all operators". + - `y` determines whether AM is on. +- `51xy`: **set SL of operator.** + - `x` is the operator (1-4). a value of `0` means "all operators". + - `y` is the value. +- `52xy`: **set RR of operator.** + - `x` is the operator (1-4). a value of `0` means "all operators". + - `y` is the value. +- `53xy`: **set DT of operator.** + - `x` is the operator (1-4). a value of `0` means "all operators". + - `y` is the value: + - `0`: +0 + - `1`: +1 + - `2`: +2 + - `3`: +3 + - `4`: -0 + - `5`: -3 + - `6`: -2 + - `7`: -1 +- `54xy`: **set RS of operator.** + - `x` is the operator (1-4). a value of `0` means "all operators". + - `y` is the value. +- `55xy`: **set DT2 of operator.** + - `x` is the operator (1-4). a value of `0` means "all operators". + - `y` is the value. +- `56xx`: **set DR of all operators.** +- `57xx`: **set DR of operator 1.** +- `58xx`: **set DR of operator 2.** +- `59xx`: **set DR of operator 3.** +- `5Axx`: **set DR of operator 4.** +- `5Bxx`: **set D2R/SR of all operators.** +- `5Cxx`: **set D2R/SR of operator 1.** +- `5Dxx`: **set D2R/SR of operator 2.** +- `5Exx`: **set D2R/SR of operator 3.** +- `5Fxx`: **set D2R/SR of operator 4.** diff --git a/doc/7-systems/pce.md b/doc/7-systems/pce.md new file mode 100644 index 00000000..80f4af10 --- /dev/null +++ b/doc/7-systems/pce.md @@ -0,0 +1,22 @@ +# PC Engine/TurboGrafx-16 + +a console from NEC that, depending on a region: +- attempted to enter the fierce battle between Nintendo and Sega, but because its capabilities are a mix of third and fourth generation, it failed to last long. (US and Europe) +- was Nintendo's most fearsome rival, completely defeating Sega Mega Drive and defending itself against Super Famicom (Japan) + +it has 6 wavetable channels and the last two ones also double as noise channels. +furthermore, it has some PCM and LFO! + +# effects + +- `10xx`: **change wave.** +- `11xx`: **toggle noise mode.** only available in the last two channels. +- `12xx`: **setup LFO.** the following values are accepted: + - `00`: LFO disabled. + - `01`: LFO enabled, shift 0. + - `02`: LFO enabled, shift 4. + - `03`: LFO enabled, shift 8. + - when LFO is enabled, channel 2 is muted and its output is passed to channel 1's frequency. +- `13xx`: **set LFO speed.** +- `17xx`: **toggle PCM mode.** + - _this effect is here for compatibility reasons_; it is otherwise recommended to use Sample type instruments (which automatically enable PCM mode when used). diff --git a/papers/doc/7-systems/pcspkr.md b/doc/7-systems/pcspkr.md similarity index 100% rename from papers/doc/7-systems/pcspkr.md rename to doc/7-systems/pcspkr.md diff --git a/papers/doc/7-systems/pet.md b/doc/7-systems/pet.md similarity index 89% rename from papers/doc/7-systems/pet.md rename to doc/7-systems/pet.md index f2c2c1c6..9b7e3b5b 100644 --- a/papers/doc/7-systems/pet.md +++ b/doc/7-systems/pet.md @@ -8,4 +8,4 @@ some of these didn't even have sound... # effects -- 10xx: set waveform. `xx` is a bitmask. +- `10xx`: **set waveform.** `xx` is a bitmask. diff --git a/papers/doc/7-systems/pokey.md b/doc/7-systems/pokey.md similarity index 84% rename from papers/doc/7-systems/pokey.md rename to doc/7-systems/pokey.md index b05c4367..8b08335d 100644 --- a/papers/doc/7-systems/pokey.md +++ b/doc/7-systems/pokey.md @@ -4,7 +4,7 @@ a sound and input chip developed by Atari for their 8-bit computers (Atari 400, # effects -- 10xx: set waveform. +- **`10xx`**: set waveform.** - 0: harsh noise (poly5+17) - 1: square buzz (poly5) - 2: weird noise (poly4+5) @@ -13,7 +13,7 @@ a sound and input chip developed by Atari for their 8-bit computers (Atari 400, - 5: square - 6: bass (poly4) - 7: buzz (poly4) -- 11xx: set AUDCTL. `xx` is a bitmask. +- **`11xx`**: set AUDCTL.** `xx` is a bitmask. - bit 7: 9-bit poly mode. shortens noise. - bit 6: high channel 1 clock (~1.79MHz on NTSC). - overrides 15KHz mode. @@ -32,3 +32,6 @@ a sound and input chip developed by Atari for their 8-bit computers (Atari 400, - filtered output on channel 2 (I suggest you to set channel 4 volume to 0). - use for PWM effects (not automatic!). - bit 0: 15KHz mode. +- **`12xx`**: toggle two-tone mode.** + - when enabled, channel 2 modulates channel 1. I don't know how, but it does. + - only on ASAP core. diff --git a/papers/doc/7-systems/qsound.md b/doc/7-systems/qsound.md similarity index 83% rename from papers/doc/7-systems/qsound.md rename to doc/7-systems/qsound.md index 81bfe4b9..07651a72 100644 --- a/papers/doc/7-systems/qsound.md +++ b/doc/7-systems/qsound.md @@ -12,8 +12,8 @@ there are also 3 ADPCM channels. ADPCM samples are fixed to 8012 Hz. # effects -- `10xx`: set echo feedback level. +- `10xx`: **set echo feedback level.** - this effect will apply to all channels. -- `11xx`: set echo level. -- `12xx`: toggle QSound algorithm (on by default). -- `3xxx`: set the length of the echo delay buffer. +- `11xx`: **set echo level.** +- `12xx`: **toggle QSound algorithm.** on by default. +- `3xxx`: **set echo delay buffer length.** diff --git a/papers/doc/7-systems/ricoh.md b/doc/7-systems/ricoh.md similarity index 100% rename from papers/doc/7-systems/ricoh.md rename to doc/7-systems/ricoh.md diff --git a/papers/doc/7-systems/saa1099.md b/doc/7-systems/saa1099.md similarity index 87% rename from papers/doc/7-systems/saa1099.md rename to doc/7-systems/saa1099.md index 8c58bbbb..6b2624e4 100644 --- a/papers/doc/7-systems/saa1099.md +++ b/doc/7-systems/saa1099.md @@ -1,18 +1,18 @@ # Philips SAA1099 -this was used by the Game Blaster and SAM Coupé. it's pretty similar to the AY-3-8910, but has stereo sound, twice the channels and two envelopes, both of which are highly flexible. The envelopes work like this: +this was used by the Game Blaster and SAM Coupé. it's pretty similar to the AY-3-8910, but has stereo sound, twice the channels and two envelopes, both of which are highly flexible. the envelopes work like this: - an instrument with envelope settings is placed on channel 2 or channel 5 - an instrument that is used as an "envelope output" is placed on channel 3 or channel 6 (you may want to disable wave output on the output channel) # effects -- `10xy`: set channel mode. +- `10xy`: **set channel mode.** - `x` toggles noise. - `y` toggles square. - this effect affects either the first 3 or last 3 channels, depending on where it is placed. -- `11xx`: set noise frequency. +- `11xx`: **set noise frequency.** - this effect affects either the first 3 or last 3 channels, depending on where it is placed. -- `12xx`: setup envelope. this is a bitmask. +- `12xx`: **setup envelope.** this is a bitmask. - bit 7 toggles the envelope. - bit 5 toggles whether to use a fixed frequency or lock to the frequency of channel 2 or 5. - bit 4 sets the envelope resolution. diff --git a/papers/doc/7-systems/scc.md b/doc/7-systems/scc.md similarity index 94% rename from papers/doc/7-systems/scc.md rename to doc/7-systems/scc.md index fb69a9cb..19a0736c 100644 --- a/papers/doc/7-systems/scc.md +++ b/doc/7-systems/scc.md @@ -8,4 +8,4 @@ the SCC+ fixes this issue though (while being compatible with SCC games). # effects -- `10xx`: change wave. +- `10xx`: **change wave.** diff --git a/papers/doc/7-systems/segapcm.md b/doc/7-systems/segapcm.md similarity index 76% rename from papers/doc/7-systems/segapcm.md rename to doc/7-systems/segapcm.md index ba1a8118..3272699d 100644 --- a/papers/doc/7-systems/segapcm.md +++ b/doc/7-systems/segapcm.md @@ -12,6 +12,6 @@ Furnace also has a five channel version of this chip, but it only exists for Def # effects -- `20xx`: set PCM frequency. +- `20xx`: **set PCM frequency.** - `xx` is a 256th fraction of 31250Hz. - - this effect exists for mostly DefleMask compatibility - it is otherwise recommended to use Sample type instruments. + - this effect exists mostly for DefleMask compatibility; it is otherwise recommended to use Sample type instruments. diff --git a/doc/7-systems/sm8521.md b/doc/7-systems/sm8521.md new file mode 100644 index 00000000..a5a6e024 --- /dev/null +++ b/doc/7-systems/sm8521.md @@ -0,0 +1,23 @@ +# Sharp SM8521 + +the SM8521 is the CPU and sound chip of the Game.com, a handheld console released in 1997 as a competitor to the infamous Nintendo Virtual Boy. + +ultimately, most of the games for the Game.com ended up being failures in the eyes of reviewers, thus giving the Game.com a pretty bad reputation. this was one of the reasons that the Game.com only ended up selling at least 300,000 units. for these reasons and more, the Game.com ended up being discontinued in 2000. + +however, for its time, it was a pretty competitively priced system. the Gameboy Color was to be released in a year for $79.95, while the Game.com was released for $69.99, and its later model, the Pocket Pro, was released in mid-1999 for $29.99 due to the Game.com's apparent significant decrease in value. + +in fact, most games never used the wavetable/noise mode of the chip. sonic Jam, for example, uses a sine wave with a software-controlled volume envelope on the DAC channel (see below for more information on the DAC channel). + +the sound-related features and quirks of the SM8521 are as follows: +- 2 4-bit wavetable channels +- a noise channel (which can go up to a very high pitch, creating an almost periodic noise sound) +- 5-bit volume +- a low bit-depth output (which means it distorts a lot). +- it phase resets when you switch waves +- 12-bit pitch with a wide frequency range +- a software-controlled D/A register that (potentially) requires all other registers to be stopped to play. due to this, it is currently, it is not implemented in Furnace as of version 0.6pre4. + +## effect commands + +- `10xx`: **set waveform.** + - `xx` is a value between 0 and 255 that sets the waveform of the channel you place it on. diff --git a/doc/7-systems/sms.md b/doc/7-systems/sms.md new file mode 100644 index 00000000..a560ce06 --- /dev/null +++ b/doc/7-systems/sms.md @@ -0,0 +1,15 @@ +# TI SN76489 (e.g. sega Master System) + +a relatively simple sound chip made by Texas Instruments. a derivative of it is used in Sega's Master System, the predecessor to Genesis. + +the original iteration of the SN76489 used in the TI-99/4A computer, the SN94624, could only produce tones as low as 100Hz, and was clocked at 447 KHz. all later versions (such as the one in the Master System and Genesis) had a clock divider but ran on a faster clock... except for the SN76494, which can play notes as low as 13.670 Hz (A -1). consequently, its pitch accuracy for higher notes is compromised. + +# effects + +- `20xy`: **set noise mode.** + - `x` controls whether to inherit frequency from channel 3. + - `0`: use one of 3 preset frequencies (C: A-2; C#: A-3; D: A-4). + - `1`: use frequency of channel 3. + - `y` controls whether to select noise or thin pulse. + - `0`: thin pulse. + - `1`: noise. diff --git a/doc/7-systems/snes.md b/doc/7-systems/snes.md new file mode 100644 index 00000000..9888291c --- /dev/null +++ b/doc/7-systems/snes.md @@ -0,0 +1,177 @@ +# Super Nintendo Entertainment System (SNES) / Super Famicom + +the successor to NES to compete with Genesis, packing superior graphics and sample-based audio. + +its Sony-developed audio system features a DSP chip, SPC700 CPU, and 64KB of dedicated SRAM used by both. +this whole system itself is pretty much a separate computer that the main CPU needs to upload its program and samples to. + +Furnace communicates with the DSP directly and provides a full 64KB of memory. this memory might be reduced excessively on ROM export to make up for playback engine and pattern data. you can go to window > statistics to see how much memory your samples are using. + +some notable features of the DSP are: +- pitch modulation, meaning that you can use 2 channels to make a basic FM synth without eating up too much memory. +- a built in noise generator, useful for hi-hats, cymbals, rides, effects, among other things. +- per-channel echo, which unfortunately eats up a lot of memory but can be used to save channels in songs. +- an 8-tap FIR filter for the echo, which is basically a procedural low-pass filter that you can edit however you want. +- sample loop, but the loop points have to be multiples of 16. +- left/right channel invert for surround sound. +- ADSR and gain envelope modes. +- 7-bit volume per channel. +- sample interpolation, which is basically a low-pass filter that gets affected by the pitch of the channel. + +Furnace also allows the SNES to use wavetables (and the wavetable synthesizer) in order to create more 'animated' sounds, using less memory than regular samples. this however is not a hardware feature, and might be difficult to implement on real hardware. + +# effects + +- `10xx`: **set waveform.** +- `11xx`: **toggle noise mode.** +- `12xx`: **toggle echo on this channel.** +- `13xx`: **toggle pitch modulation.** frequency modulation by the previous channel's output. no effect on channel 1. +- `14xy`: **toggle inverting the left or right channels.** `x` is left, `y` is right. +- `15xx`: **set envelope mode.** see gain chart below for `1` through `5`. + - `0`: ADSR mode. + - `1`: gain (direct). volume holds at one level. + - `2`: linear decrement. volume lowers by subtractions of 1/64. + - `3`: exponential decrement. volume lowers by multiplications of 255/256. + - `4`: linear increment. volume rises by additions of 1/64. + - `5`: bent line (inverse log) increment. volume rises by additions of 1/64 until 3/4, then additions of 1/256. +- `16xx`: **set gain.** `00` to `7F` if direct, `00` to `1F` otherwise. +- `18xx`: **enable echo buffer.** +- `19xx`: **set echo delay.** range is `0` to `F`. +- `1Axx`: **set left echo channel volume.**\ + `1Bxx`: **set right echo channel volume.**\ + `1Cxx`: **set echo feedback.** + - all of these are signed numbers. + - `00` to `7F` for 0 to 127. + - `80` to `FF` for -128 to -1. + - setting these to -128 is not recommended as it may cause echo output to overflow and therefore click. +- `1Dxx`: **set noise generator frequency.** range is `00` to `1F`. see noise frequencies chart below. +- `1Exx`: **set left dry / global volume.**\ + `1Fxx`: **set right dry / global volume.** + - these do not affect echo. +- `20xx`: **set attack.** range is `0` to `F`.\ + `21xx`: **set decay.** range is `0` to `7`.\ + `22xx`: **set sustain.** range is `0` to `7`.\ + `23xx`: **set release.** range is `00` to `1F`. + - these four are only used in ADSR envelope mode. see ADSR chart below. +- `30xx`: **set echo filter coefficient 0.**\ + `31xx`: **set echo filter coefficient 1.**\ + `32xx`: **set echo filter coefficient 2.**\ + `33xx`: **set echo filter coefficient 3.**\ + `34xx`: **set echo filter coefficient 4.**\ + `35xx`: **set echo filter coefficient 5.**\ + `36xx`: **set echo filter coefficient 6.**\ + `37xx`: **set echo filter coefficient 7.** + - all of these are signed numbers. + - `00` to `7F` for 0 to 127. + - `80` to `FF` for -128 to -1. + - _Note:_ Be sure the sum of all coefficients is between -128 and 127. sums outside that may result in overflow and therefore clicking. + - see [SnesLab](https://sneslab.net/wiki/FIR_Filter) for a full explanation and examples. + +# tables + +## ADSR + +| attack | 0→1 time | decay | 1→S time | sustain | ratio | release | S→0 time +| -----: | -------: | ----: | -------: | ------: | :---: | ------: | -------: +| `00` | 4.1s | `00` | 1.2s | `00` | 1/8 | `00` | ∞ +| `01` | 2.5s | `01` | 740ms | `01` | 2/8 | `01` | 38s +| `02` | 1.5s | `02` | 440ms | `02` | 3/8 | `02` | 28s +| `03` | 1.0s | `03` | 290ms | `03` | 4/8 | `03` | 24s +| `04` | 640ms | `04` | 180ms | `04` | 5/8 | `04` | 19s +| `05` | 380ms | `05` | 110ms | `05` | 6/8 | `05` | 14s +| `06` | 260ms | `06` | 74ms | `06` | 7/8 | `06` | 12s +| `07` | 160ms | `07` | 37ms | `07` | 1 | `07` | 9.4s +| `08` | 96ms | | | | | `08` | 7.1s +| `09` | 64ms | | | | | `09` | 5.9s +| `0A` | 40ms | | | | | `0A` | 4.7s +| `0B` | 24ms | | | | | `0B` | 3.5s +| `0C` | 16ms | | | | | `0C` | 2.9s +| `0D` | 10ms | | | | | `0D` | 2.4s +| `0E` | 6ms | | | | | `0E` | 1.8s +| `0F` | 0ms | | | | | `0F` | 1.5s +| | | | | | | `10` | 1.2s +| | | | | | | `11` | 880ms +| | | | | | | `12` | 740ms +| | | | | | | `13` | 590ms +| | | | | | | `14` | 440ms +| | | | | | | `15` | 370ms +| | | | | | | `16` | 290ms +| | | | | | | `17` | 220ms +| | | | | | | `18` | 180ms +| | | | | | | `19` | 150ms +| | | | | | | `1A` | 110ms +| | | | | | | `1B` | 92ms +| | | | | | | `1C` | 74ms +| | | | | | | `1D` | 55ms +| | | | | | | `1E` | 37ms +| | | | | | | `1F` | 18ms + +reference: [Super Famicom Development Wiki](https://wiki.superfamicom.org/spc700-reference#dsp-voice-register:-adsr-1097) + +## gain + +value | linear inc. | bent line inc. | linear dec. | exponent dec. +----: | ----------: | -------------: | ----------: | ------------: + `00` | ∞ | ∞ | ∞ | ∞ + `01` | 4.1s | 7.2s | 4.1s | 38s + `02` | 3.1s | 5.4s | 3.1s | 28s + `03` | 2.6s | 4.6s | 2.6s | 24s + `04` | 2.0s | 3.5s | 2.0s | 19s + `05` | 1.5s | 2.6s | 1.5s | 14s + `06` | 1.3s | 2.3s | 1.3s | 12s + `07` | 1.0s | 1.8s | 1.0s | 9.4s + `08` | 770ms | 1.3s | 770ms | 7.1s + `09` | 640ms | 1.1s | 640ms | 5.9s + `0A` | 510ms | 900ms | 510ms | 4.7s + `0B` | 380ms | 670ms | 380ms | 3.5s + `0C` | 320ms | 560ms | 320ms | 2.9s + `0D` | 260ms | 450ms | 260ms | 2.4s + `0E` | 190ms | 340ms | 190ms | 1.8s + `0F` | 160ms | 280ms | 160ms | 1.5s + `10` | 130ms | 220ms | 130ms | 1.2s + `11` | 96ms | 170ms | 96ms | 880ms + `12` | 80ms | 140ms | 80ms | 740ms + `13` | 64ms | 110ms | 64ms | 590ms + `14` | 48ms | 84ms | 48ms | 440ms + `15` | 40ms | 70ms | 40ms | 370ms + `16` | 32ms | 56ms | 32ms | 290ms + `17` | 24ms | 42ms | 24ms | 220ms + `18` | 20ms | 35ms | 20ms | 180ms + `19` | 16ms | 28ms | 16ms | 150ms + `1A` | 12ms | 21ms | 12ms | 110ms + `1B` | 10ms | 18ms | 10ms | 92ms + `1C` | 8ms | 14ms | 8ms | 74ms + `1D` | 6ms | 11ms | 6ms | 55ms + `1E` | 4ms | 7ms | 4ms | 37ms + `1F` | 2ms | 3.5ms | 2ms | 18ms + +reference: [Super Famicom Development Wiki](https://wiki.superfamicom.org/spc700-reference#dsp-voice-register:-gain-1156) + +## noise frequencies + +value | freq. | value | freq. +----: | -----: | ----: | -------: +`00` | 0 Hz | `10` | 500 Hz +`01` | 16 Hz | `11` | 667 Hz +`02` | 21 Hz | `12` | 800 Hz +`03` | 25 Hz | `13` | 1.0 KHz +`04` | 31 Hz | `14` | 1.3 KHz +`05` | 42 Hz | `15` | 1.6 KHz +`06` | 50 Hz | `16` | 2.0 KHz +`07` | 63 Hz | `17` | 2.7 KHz +`08` | 83 Hz | `18` | 3.2 KHz +`09` | 100 Hz | `19` | 4.0 KHz +`0A` | 125 Hz | `1A` | 5.3 KHz +`0B` | 167 Hz | `1B` | 6.4 KHz +`0C` | 200 Hz | `1C` | 8.0 KHz +`0D` | 250 Hz | `1D` | 10.7 KHz +`0E` | 333 Hz | `1E` | 16 KHz +`0F` | 400 Hz | `1F` | 32 KHz + +reference: [Super Famicom Development Wiki](https://wiki.superfamicom.org/spc700-reference#dsp-register:-flg-1318) + + + +# resources + +- [SNES-format BRR samples](https://www.smwcentral.net/?p=stion&s=brrsamples) at SMW Central diff --git a/doc/7-systems/soundunit.md b/doc/7-systems/soundunit.md new file mode 100644 index 00000000..5b483813 --- /dev/null +++ b/doc/7-systems/soundunit.md @@ -0,0 +1,56 @@ +# tildearrow Sound Unit + +a fantasy sound chip, used in the specs2 fantasy computer designed by tildearrow. + +it has the following capabilities: +- 8 channels of either waveform or sample +- stereo sound +- 8 waveforms (pulse, saw, sine, triangle, noise, periodic noise, XOR sine and XOR triangle) +- 128 widths for the pulse wave +- per-channel resonant filter +- ring modulation +- volume, frequency and cutoff sweep units (per-channel) +- phase reset timer (per-channel) + +# effects + +- `10xx`: **set waveform.** + - `0`: pulse wave + - `1`: sawtooth + - `2`: sine wave + - `3`: triangle wave + - `4`: noise + - `5`: periodic noise + - `6`: XOR sine + - `7`: XOR triangle +- `12xx`: **set pulse width.** range is `0` to `7F`. +- `13xx`: **set resonance of filter.** range is `0` to `FF`. + - despite what the internal effects list says (`0` to `F`), you can use a resonance value from `0` to `FF` (255). +- `14xx`: **set filter mode and ringmod.** + - bit 0: ring mod + - bit 1: low pass + - bit 2: high pass + - bit 3: band pass +- `15xx`: **set frequency sweep period low byte.** +- `16xx`: **set frequency sweep period high byte.** +- `17xx`: **set volume sweep period low byte.** +- `18xx`: **set volume sweep period high byte.** +- `19xx`: **set cutoff sweep period low byte.** +- `1Axx`: **set cutoff sweep period high byte.** +- `1Bxx`: **set frequency sweep boundary.** +- `1Cxx`: **set volume sweep boundary.** +- `1Dxx`: **set cutoff sweep boundary.** +- `1Exx`: **set phase reset period low byte.** +- `1Fxx`: **set phase reset period high byte.** +- `20xx`: **toggle frequency sweep.** + - bit 0-6: speed + - bit 7: up direction +- `21xx`: **toggle volume sweep.** + - bit 0-4: speed + - bit 5: up direction + - bit 6: loop + - bit 7: alternate +- `22xx`: **toggle cutoff sweep.** + - bit 0-6: speed + - bit 7: up direction +- `4xxx`: **set cutoff.** range is `0` to `FFF`. diff --git a/papers/doc/7-systems/t6w28.md b/doc/7-systems/t6w28.md similarity index 75% rename from papers/doc/7-systems/t6w28.md rename to doc/7-systems/t6w28.md index 9083cb7a..886ea63b 100644 --- a/papers/doc/7-systems/t6w28.md +++ b/doc/7-systems/t6w28.md @@ -6,6 +6,6 @@ this chip was used in Neo Geo Pocket. # effects -- `20xx`: set noise mode. - - 0: thin pulse. - - 1: noise. +- `20xx`: **set noise mode.** + - `0`: thin pulse. + - `1`: noise. diff --git a/doc/7-systems/tia.md b/doc/7-systems/tia.md new file mode 100644 index 00000000..b39d31db --- /dev/null +++ b/doc/7-systems/tia.md @@ -0,0 +1,28 @@ +# Atari 2600 (TIA) + +help me! I can't even get this character in where I want! +I've spent hours debugging the issue, counting every possible cycle and I still cannot get it right! + +only 2 channels and 31 frequencies?! + +Furnace isn't complete without this one... + +# effects + +- `10xx`: **select shape.** + - `0`: nothing + - `1`: buzzy + - `2`: low buzzy + - `3`: flangy + - `4`: square + - `5`: square + - `6`: pure buzzy + - `7`: reedy + - `8`: noise + - `9`: reedy + - `A`: pure buzzy + - `B`: nothing + - `C`: low square + - `D`: low square + - `E`: low pure buzzy + - `F`: low reedy \ No newline at end of file diff --git a/papers/doc/7-systems/vera.md b/doc/7-systems/vera.md similarity index 65% rename from papers/doc/7-systems/vera.md rename to doc/7-systems/vera.md index be610a80..8f50e0e7 100644 --- a/papers/doc/7-systems/vera.md +++ b/doc/7-systems/vera.md @@ -7,9 +7,9 @@ currently Furnace does not support the PCM channel's stereo mode, though (except # effects -- `20xx`: set waveform. the following values are accepted: - - 0: pulse - - 1: saw - - 2: triangle - - 3: noise -- `22xx`: set duty cycle. `xx` may go from 0 to 3F. +- `20xx`: **set waveform.** + - `0`: pulse + - `1`: saw + - `2`: triangle + - `3`: noise +- `22xx`: **set duty cycle.** range is `0` to `3F`. diff --git a/papers/doc/7-systems/vic20.md b/doc/7-systems/vic20.md similarity index 94% rename from papers/doc/7-systems/vic20.md rename to doc/7-systems/vic20.md index cf9a8a46..e5126c18 100644 --- a/papers/doc/7-systems/vic20.md +++ b/doc/7-systems/vic20.md @@ -15,4 +15,4 @@ these channels are not referred as "square" wave channels since a technique to p ## effect commands - - `10xx` Switch waveform (`xx` from `00` to `0F`) +- `10xx`: **switch waveform.** range is `00` to `0F`. diff --git a/papers/doc/7-systems/virtual-boy.md b/doc/7-systems/virtual-boy.md similarity index 65% rename from papers/doc/7-systems/virtual-boy.md rename to doc/7-systems/virtual-boy.md index 94a2d049..9ef6c909 100644 --- a/papers/doc/7-systems/virtual-boy.md +++ b/doc/7-systems/virtual-boy.md @@ -10,34 +10,34 @@ additionally, channel 5 offers a modulation/sweep unit. the former is similar to # effects -- `10xx`: set waveform. -- `11xx`: set noise length (0 to 7). +- `10xx`: **set waveform.** +- `11xx`: **set noise length.** range is `0` to `7`. - only in the noise channel. -- `12xy`: setup envelope. +- `12xy`: **setup envelope.** - `x` determines whether envelope is enabled or not. - - 0: disabled - - 1: enabled - - 3: enabled and loop - - yeah, the value 2 isn't useful. + - `0`: disabled + - `1`: enabled + - `3`: enabled and loop + - yeah, the value `2` isn't useful. - `y` sets the speed and direction. - - 0-7: down - - 8-F: up -- `13xy`: setup sweep. + - `0-7`: down + - `8-F`: up +- `13xy`: **setup sweep.** - `x` sets the speed. - - 0 and 8 are "speed 0" - sweep is ineffective. - - `y` sets the shift (0 to 7). - - 8 and higher will mute the channel. + - `0` and `8` are "speed 0" - sweep is ineffective. + - `y` sets the shift (`0` to `7`). + - `8` and higher will mute the channel. - only in channel 5. -- `14xy`: setup modulation. +- `14xy`: **setup modulation.** - `x` determines whether it's enabled or not. - 0: disabled - 1: enabled - 3: enabled and loop - 2 isn't useful here either. - `y` sets the speed. - - 0 and 8 are "speed 0" - modulation is ineffective. + - `0` and `8` are "speed 0" - modulation is ineffective. - no, you can't really do Yamaha FM using this. - only in channel 5. -- `15xx`: set modulation wave. - - `xx` points to a wavetable. it should have a height of 255. +- `15xx`: **set modulation wave.** + - `xx` points to a wavetable. range is `0` to `FF`. - this is an alternative to setting the modulation wave through the instrument. diff --git a/papers/doc/7-systems/vrc6.md b/doc/7-systems/vrc6.md similarity index 92% rename from papers/doc/7-systems/vrc6.md rename to doc/7-systems/vrc6.md index 0ec4c8b2..d652cc26 100644 --- a/papers/doc/7-systems/vrc6.md +++ b/doc/7-systems/vrc6.md @@ -14,5 +14,5 @@ Furnace supports this routine for PCM playback, but it consumes a lot of CPU tim these effects only are effective in the pulse channels. -- `12xx`: set duty cycle (0 to 7). -- `17xx`: toggle PCM mode. +- `12xx`: **set duty cycle.** range is `0` to `7`. +- `17xx`: **toggle PCM mode.** diff --git a/papers/doc/7-systems/wonderswan.md b/doc/7-systems/wonderswan.md similarity index 70% rename from papers/doc/7-systems/wonderswan.md rename to doc/7-systems/wonderswan.md index 21a1a926..d4bff7c1 100644 --- a/papers/doc/7-systems/wonderswan.md +++ b/doc/7-systems/wonderswan.md @@ -10,12 +10,12 @@ it has 4 wavetable channels. some of them have additional capabilities: # effects -- `10xx`: change wave. -- `11xx`: setup noise mode (channel 4 only). +- `10xx`: **change wave**. +- `11xx`: **setup noise mode.** channel 4 only. - 0: disable. - 1-8: enable and set tap preset. -- `12xx`: setup sweep period (channel 3 only). +- `12xx`: **setup sweep period.** channel 3 only. - 0: disable. - 1-32: enable and set period. -- `13xx`: setup sweep amount (channel 3 only). -- `17xx`: toggle PCM mode (channel 2 only). +- `13xx`: **setup sweep amount.** channel 3 only. +- `17xx`: **toggle PCM mode.** channel 2 only. diff --git a/papers/doc/7-systems/x1-010.md b/doc/7-systems/x1-010.md similarity index 51% rename from papers/doc/7-systems/x1-010.md rename to doc/7-systems/x1-010.md index 80b5b41a..5f110aba 100644 --- a/papers/doc/7-systems/x1-010.md +++ b/doc/7-systems/x1-010.md @@ -1,47 +1,47 @@ # Seta/Allumer X1-010 -A sound chip designed by Seta, mainly used in their own arcade hardware from the late 80s to the early 2000s. -It has 2 output channels, but there is no known hardware taking advantage of stereo sound capabilities. -Later hardware paired this with external bankswitching logic, but this isn't emulated yet. +a sound chip designed by Seta, mainly used in their own arcade hardware from the late 80s to the early 2000s. +it has 2 output channels, but there is no known hardware taking advantage of stereo sound capabilities. +later hardware paired this with external bankswitching logic, but this isn't emulated yet. Allumer rebadged it for their own arcade hardware. -It has 16 channels, which can all be switched between PCM sample or wavetable playback mode. -Wavetable playback needs to paired with envelope, similar to AY PSG, but shapes are stored in RAM and as such are user-definable. +it has 16 channels, which can all be switched between PCM sample or wavetable playback mode. +wavetable playback needs to paired with envelope, similar to AY PSG, but shapes are stored in RAM and as such are user-definable. -In Furnace, this chip can be configured for original arcade mono output or stereo output - it simulates early 'incorrect' emulation on some mono hardware, but it is also based on the assumption that each channel is connected to each output. +in Furnace, this chip can be configured for original arcade mono output or stereo output - it simulates early 'incorrect' emulation on some mono hardware, but it is also based on the assumption that each channel is connected to each output. -# Waveform types +# waveform types -This chip supports 2 types of waveforms, needs to be paired to external 8 KB RAM to access these features: +this chip supports 2 types of waveforms, needs to be paired to external 8 KB RAM to access these features: -One is a signed 8 bit mono waveform, operated like other wavetable based sound systems. -These are stored at the lower half of RAM at common case. +one is a signed 8 bit mono waveform, operated like other wavetable based sound systems. +these are stored at the lower half of RAM at common case. -The other one ("Envelope") is a 4 bit stereo waveform, multiplied with the above and calculates final output, each nibble is used for each output channel. -These are stored at the upper half of RAM at common case. +the other one ("Envelope") is a 4 bit stereo waveform, multiplied with the above and calculates final output, each nibble is used for each output channel. +these are stored at the upper half of RAM at common case. -Both waveforms are 128 bytes (fixed size), freely allocated at each half of RAM except the channel register area: each half can store total 32/31 waveforms at once. -In furnace, you can enable the envelope shape split mode. When it is set, its waveform will be split to the left and right halves for each output. Each max size is 128 bytes, total 256 bytes. +both waveforms are 128 bytes (fixed size), freely allocated at each half of RAM except the channel register area: each half can store total 32/31 waveforms at once. +in Furnace, you can enable the envelope shape split mode. when it is set, its waveform will be split to the left and right halves for each output. each max size is 128 bytes, total 256 bytes. # effects -- `10xx`: change wave. -- `11xx`: change envelope shape (also wavetable). -- `17xx`: toggle PCM mode. -- `20xx`: set PCM frequency (1 to FF). -- `22xx`: set envelope mode. +- `10xx`: **change wave.** +- `11xx`: **change envelope shape.** also wavetable. +- `17xx`: **toggle PCM mode.** +- `20xx`: **set PCM frequency.** range is `1` to `FF`. + - PCM frequency formula: `step * (clock / 8192)`. + - range is 1.95KHz to 498KHz if the chip clock is 16MHz. +- `22xx`: **set envelope mode.** - bit 0 sets whether envelope will affect this channel. - bit 1 toggles the envelope one-shot mode. when it is set, channel is halted after envelope cycle is finished. - bit 2 toggles the envelope shape split mode. when it is set, envelope shape will be split to left half and right half. - bit 3/5 sets whether the right/left shape will mirror the original one. - bit 4/6 sets whether the right/left output will mirror the original one. -- `23xx`: set envelope period. -- `25xx`: slide envelope period up. -- `26xx`: slide envelope period down. -- `29xy`: enable auto-envelope mode. +- `23xx`: **set envelope period.** +- `25xx`: **slide envelope period up.** +- `26xx`: **slide envelope period down.** +- `29xy`: **enable auto-envelope mode.** - in this mode the envelope period is set to the channel's notes, multiplied by a fraction. - `x` is the numerator. - `y` is the denominator. - if `x` or `y` are 0 this will disable auto-envelope mode. - -* PCM frequency: 255 step, formula: `step * (Chip clock / 8192)`; 1.95KHz to 498KHz if Chip clock is 16MHz. diff --git a/doc/7-systems/ym2151.md b/doc/7-systems/ym2151.md new file mode 100644 index 00000000..f9bd8751 --- /dev/null +++ b/doc/7-systems/ym2151.md @@ -0,0 +1,70 @@ +# Yamaha YM2151 + +the sound chip powering several arcade boards, the Sharp X1/X68000 and the Commander X16. eight 4-op FM channels, with overpowered LFO and almost unused noise generator. + +it also was present on several pinball machines and synthesizers of the era, and later surpassed by the YM2414 (OPZ) present in the world-famous TX81Z. + +in most arcade boards the chip was used in combination with a PCM chip, like [SegaPCM](segapcm.md) or [OKI's line of ADPCM chips](oki.md). + +# effects + +- `10xx`: **set noise frequency of channel 8 operator 4.** `00` disables noise while `01` to `20` enables it. +- `11xx`: **set feedback of channel.** +- `12xx`: **set operator 1 level.** +- `13xx`: **set operator 2 level.** +- `14xx`: **set operator 3 level.** +- `15xx`: **set operator 4 level.** +- `16xy`: **set multiplier of operator.** + - `x` is the operator (1-4). + - `y` is the multiplier. +- `17xx`: **set LFO speed.** +- `18xx`: **set LFO waveform.** + - `00`: saw + - `01`: square + - `02`: triangle + - `03`: noise +- `19xx`: **set attack of all operators.** +- `1Axx`: **set attack of operator 1.** +- `1Bxx`: **set attack of operator 2.** +- `1Cxx`: **set attack of operator 3.** +- `1Dxx`: **set attack of operator 4.** +- `1Exx`: **set LFO AM depth.** +- `1Fxx`: **set LFO PM depth.** +- `30xx`: **enable envelope hard reset.** + - this works by inserting a quick release and tiny delay before a new note. +- `50xy`: **set AM of operator.** + - `x` is the operator (1-4). a value of 0 means "all operators". + - `y` determines whether AM is on. +- `51xy`: **set SL of operator.** + - `x` is the operator (1-4). a value of 0 means "all operators". + - `y` is the value. +- `52xy`: **set RR of operator.** + - `x` is the operator (1-4). a value of 0 means "all operators". + - `y` is the value. +- `53xy`: **set DT of operator.** + - `x` is the operator (1-4). a value of 0 means "all operators". + - `y` is the value: + - `0`: +0 + - `1`: +1 + - `2`: +2 + - `3`: +3 + - `4`: -0 + - `5`: -3 + - `6`: -2 + - `7`: -1 +- `54xy`: **set RS of operator.** + - `x` is the operator (1-4). a value of 0 means "all operators". + - `y` is the value. +- `55xy`: **set DT2 of operator.** + - `x` is the operator (1-4). a value of 0 means "all operators". + - `y` is the value. +- `56xx`: **set DR of all operators.** +- `57xx`: **set DR of operator 1.** +- `58xx`: **set DR of operator 2.** +- `59xx`: **set DR of operator 3.** +- `5Axx`: **set DR of operator 4.** +- `5Bxx`: **set D2R/SR of all operators.** +- `5Cxx`: **set D2R/SR of operator 1.** +- `5Dxx`: **set D2R/SR of operator 2.** +- `5Exx`: **set D2R/SR of operator 3.** +- `5Fxx`: **set D2R/SR of operator 4.** diff --git a/doc/7-systems/ym2203.md b/doc/7-systems/ym2203.md new file mode 100644 index 00000000..03950444 --- /dev/null +++ b/doc/7-systems/ym2203.md @@ -0,0 +1,101 @@ +# Yamaha YM2203 (OPN) + +a cost-reduced version of the YM2151 (OPM). +it only has 3 FM channels instead of 8 and removes stereo, the LFO and DT2 (coarse detune). + +however it does contain an AY/SSG part which provides 3 channels of square wave with noise and envelope. + +this chip was used in the NEC PC-88/PC-98 series of computers, the Fujitsu FM-7AV and in some arcade boards. + +several variants of this chip were released as well, with more features. + +# effects + +- `11xx`: **set feedback of channel.** +- `12xx`: **set operator 1 level.** +- `13xx`: **set operator 2 level.** +- `14xx`: **set operator 3 level.** +- `15xx`: **set operator 4 level.** +- `16xy`: **set multiplier of operator.** + - `x` is the operator from 1 to 4. + - `y` is the multiplier. +- `18xx`: **toggle extended channel 3 mode.** + - `0` disables it and `1` enables it. + - only in extended channel 3 chip. +- `19xx`: **set attack of all operators.** +- `1Axx`: **set attack of operator 1.** +- `1Bxx`: **set attack of operator 2.** +- `1Cxx`: **set attack of operator 3.** +- `1Dxx`: **set attack of operator 4.** +- `20xx`: **set SSG channel mode.** `xx` may be one of the following: + - `0`: square + - `1`: noise + - `2`: square and noise + - `3`: nothing (apparently) + - `4`: envelope and square + - `5`: envelope and noise + - `6`: envelope and square and noise + - `7`: nothing +- `21xx`: **set noise frequency.** `xx` is a value between 00 and 1F. +- `22xy`: **set envelope mode.** + - `x` sets the envelope shape, which may be one of the following: + - `0`: `\___` decay + - `4`: `/___` attack once + - `8`: `\\\\` saw + - `9`: `\___` decay + - `A`: `\/\/` inverse obelisco + - `B`: `\¯¯¯` decay once + - `C`: `////` inverse saw + - `D`: `/¯¯¯` attack + - `E`: `/\/\` obelisco + - `F`: `/___` attack once + - if `y` is 1 then the envelope will affect this channel. +- `23xx`: **set envelope period low byte.** +- `24xx`: **set envelope period high byte.** +- `25xx`: **slide envelope period up.** +- `26xx`: **slide envelope period down.** +- `29xy`: **enable SSG auto-envelope mode.** + - in this mode the envelope period is set to the channel's notes, multiplied by a fraction. + - `x` is the numerator. + - `y` is the denominator. + - if `x` or `y` are 0 this will disable auto-envelope mode. +- `30xx`: **enable envelope hard reset.** + - this works by inserting a quick release and tiny delay before a new note. +- `50xy`: **set AM of operator.** + - `x` is the operator (1-4). a value of 0 means "all operators". + - `y` determines whether AM is on. +- `51xy`: **set SL of operator.** + - `x` is the operator (1-4). a value of 0 means "all operators". + - `y` is the value. +- `52xy`: **set RR of operator.** + - `x` is the operator (1-4). a value of 0 means "all operators". + - `y` is the value. +- `53xy`: **set DT of operator.** + - `x` is the operator (1-4). a value of 0 means "all operators". + - `y` is the value: + - `0`: +0 + - `1`: +1 + - `2`: +2 + - `3`: +3 + - `4`: -0 + - `5`: -3 + - `6`: -2 + - `7`: -1 +- `54xy`: **set RS of operator.** + - `x` is the operator (1-4). a value of 0 means "all operators". + - `y` is the value. +- `55xy`: **set SSG-EG of operator.** + - `x` is the operator (1-4). a value of 0 means "all operators". + - `y` is the value (0-8). + - values between 0 and 7 set SSG-EG. + - value 8 disables it. +- `56xx`: **set DR of all operators.** +- `57xx`: **set DR of operator 1.** +- `58xx`: **set DR of operator 2.** +- `59xx`: **set DR of operator 3.** +- `5Axx`: **set DR of operator 4.** +- `5Bxx`: **set D2R/SR of all operators.** +- `5Cxx`: **set D2R/SR of operator 1.** +- `5Dxx`: **set D2R/SR of operator 2.** +- `5Exx`: **set D2R/SR of operator 3.** +- `5Fxx`: **set D2R/SR of operator 4.** diff --git a/doc/7-systems/ym2608.md b/doc/7-systems/ym2608.md new file mode 100644 index 00000000..700ec9d5 --- /dev/null +++ b/doc/7-systems/ym2608.md @@ -0,0 +1,101 @@ +# Yamaha YM2608 (OPNA) + +like YM2203, but with twice the FM channels, stereo, an ADPCM channel and built-in drums ("rhythm")! + +it was one of the available sound chips for the NEC PC-88VA and PC-98 series of computers. + +the YM2610 (OPNB) and YM2610B chips are very similar to this one, but the built-in drums have been replaced with 6 sample channels. + +# effects + +- `10xy`: **set LFO parameters.** + - `x` toggles the LFO. + - `y` sets its speed. +- `11xx`: **set feedback of channel.** +- `12xx`: **set operator 1 level.** +- `13xx`: **set operator 2 level.** +- `14xx`: **set operator 3 level.** +- `15xx`: **set operator 4 level.** +- `16xy`: **set multiplier of operator.** + - `x` is the operator (1-4). + - `y` is the multiplier. +- `18xx`: **toggle extended channel 3 mode.** + - `0` disables it and `1` enables it. + - only in extended channel 3 chip. +- `19xx`: **set attack of all operators.** +- `1Axx`: **set attack of operator 1.** +- `1Bxx`: **set attack of operator 2.** +- `1Cxx`: **set attack of operator 3.** +- `1Dxx`: **set attack of operator 4.** +- `20xx`: **set SSG channel mode.** + - `00`: square + - `01`: noise + - `02`: square and noise + - `03`: nothing (apparently) + - `04`: envelope and square + - `05`: envelope and noise + - `06`: envelope and square and noise + - `07`: nothing +- `21xx`: **set noise frequency.** range is `0` to `1F`. +- `22xy`: **set envelope mode.** + - `x` sets the envelope shape, which may be one of the following: + - `0`: `\___` decay + - `4`: `/___` attack once + - `8`: `\\\\` saw + - `9`: `\___` decay + - `A`: `\/\/` inverse obelisco + - `B`: `\¯¯¯` decay once + - `C`: `////` inverse saw + - `D`: `/¯¯¯` attack + - `E`: `/\/\` obelisco + - `F`: `/___` attack once + - if `y` is 1 then the envelope will affect this channel. +- `23xx`: **set envelope period low byte.** +- `24xx`: **set envelope period high byte.** +- `25xx`: **slide envelope period up.** +- `26xx`: **slide envelope period down.** +- `29xy`: **enable SSG auto-envelope mode.** + - in this mode the envelope period is set to the channel's notes, multiplied by a fraction. + - `x` is the numerator. + - `y` is the denominator. + - if `x` or `y` are 0 this will disable auto-envelope mode. +- `30xx`: **enable envelope hard reset.** + - this works by inserting a quick release and tiny delay before a new note. +- `50xy`: **set AM of operator.** + - `x` is the operator (1-4). a value of 0 means "all operators". + - `y` determines whether AM is on. +- `51xy`: **set SL of operator.** + - `x` is the operator (1-4). a value of 0 means "all operators". + - `y` is the value. +- `52xy`: **set RR of operator.** + - `x` is the operator (1-4). a value of 0 means "all operators". + - `y` is the value. +- `53xy`: **set DT of operator.** + - `x` is the operator (1-4). a value of 0 means "all operators". + - `y` is the value: + - `0`: +0 + - `1`: +1 + - `2`: +2 + - `3`: +3 + - `4`: -0 + - `5`: -3 + - `6`: -2 + - `7`: -1 +- `54xy`: **set RS of operator.** + - `x` is the operator (1-4). a value of 0 means "all operators". + - `y` is the value. +- `55xy`: **set SSG-EG of operator.** + - `x` is the operator (1-4). a value of 0 means "all operators". + - `y` is the value (0-8). + - values between 0 and 7 set SSG-EG. + - value 8 disables it. +- `56xx`: **set DR of all operators.** +- `57xx`: **set DR of operator 1.** +- `58xx`: **set DR of operator 2.** +- `59xx`: **set DR of operator 3.** +- `5Axx`: **set DR of operator 4.** +- `5Bxx`: **set D2R/SR of all operators.** +- `5Cxx`: **set D2R/SR of operator 1.** +- `5Dxx`: **set D2R/SR of operator 2.** +- `5Exx`: **set D2R/SR of operator 3.** +- `5Fxx`: **set D2R/SR of operator 4.** diff --git a/doc/7-systems/ym2610.md b/doc/7-systems/ym2610.md new file mode 100644 index 00000000..9d714acc --- /dev/null +++ b/doc/7-systems/ym2610.md @@ -0,0 +1,99 @@ +# Neo Geo/Yamaha YM2610 + +originally an arcade board, but SNK shortly adapted it to a rather expensive video game console with the world's biggest cartridges because some people liked the system so much they wanted a home version of it. + +its soundchip is a 4-in-1: 4ch 4-op FM, YM2149 (AY-3-8910 clone) and 2 different format ADPCM in a single package! + +# effects + +- `10xy`: **set LFO parameters.** + - `x` toggles the LFO. + - `y` sets its speed. +- `11xx`: **set feedback of channel.** +- `12xx`: **set operator 1 level.** +- `13xx`: **set operator 2 level.** +- `14xx`: **set operator 3 level.** +- `15xx`: **set operator 4 level.** +- `16xy`: **set multiplier of operator.** + - `x` is the operator (1-4). + - `y` is the multiplier. +- `18xx`: **toggle extended channel 2 mode.** + - 0 disables it and 1 enables it. + - only in extended channel 2 chip. +- `19xx`: **set attack of all operators.** +- `1Axx`: **set attack of operator 1.** +- `1Bxx`: **set attack of operator 2.** +- `1Cxx`: **set attack of operator 3.** +- `1Dxx`: **set attack of operator 4.** +- `20xx`: **set SSG channel mode.** + - `0`: square + - `1`: noise + - `2`: square and noise + - `3`: nothing (apparently) + - `4`: envelope and square + - `5`: envelope and noise + - `6`: envelope and square and noise + - `7`: nothing +- `21xx`: **set noise frequency.** range is `00` to `1F`. +- `22xy`: **set envelope mode.** + - `x` sets the envelope shape: + - `0`: `\___` decay + - `4`: `/___` attack once + - `8`: `\\\\` saw + - `9`: `\___` decay + - `A`: `\/\/` inverse obelisco + - `B`: `\¯¯¯` decay once + - `C`: `////` inverse saw + - `D`: `/¯¯¯` attack + - `E`: `/\/\` obelisco + - `F`: `/___` attack once + - if `y` is 1 then the envelope will affect this channel. +- `23xx`: **set envelope period low byte.** +- `24xx`: **set envelope period high byte.** +- `25xx`: **slide envelope period up.** +- `26xx`: **slide envelope period down.** +- `29xy`: **enable SSG auto-envelope mode.** + - in this mode the envelope period is set to the channel's notes, multiplied by a fraction. + - `x` is the numerator. + - `y` is the denominator. + - if `x` or `y` are 0 this will disable auto-envelope mode. +- `30xx`: **enable envelope hard reset.** + - this works by inserting a quick release and tiny delay before a new note. +- `50xy`: **set AM of operator.** + - `x` is the operator (1-4). a value of 0 means "all operators". + - `y` determines whether AM is on. +- `51xy`: **set SL of operator.** + - `x` is the operator (1-4). a value of 0 means "all operators". + - `y` is the value. +- `52xy`: **set RR of operator.** + - `x` is the operator (1-4). a value of 0 means "all operators". + - `y` is the value. +- `53xy`: **set DT of operator.** + - `x` is the operator (1-4). a value of 0 means "all operators". + - `y` is the value: + - 0: +0 + - 1: +1 + - 2: +2 + - 3: +3 + - 4: -0 + - 5: -3 + - 6: -2 + - 7: -1 +- `54xy`: **set RS of operator.** + - `x` is the operator (1-4). a value of 0 means "all operators". + - `y` is the value. +- `55xy`: **set SSG-EG of operator.** + - `x` is the operator (1-4). a value of 0 means "all operators". + - `y` is the value (0-8). + - values between 0 and 7 set SSG-EG. + - value 8 disables it. +- `56xx`: **set DR of all operators.** +- `57xx`: **set DR of operator 1.** +- `58xx`: **set DR of operator 2.** +- `59xx`: **set DR of operator 3.** +- `5Axx`: **set DR of operator 4.** +- `5Bxx`: **set D2R/SR of all operators.** +- `5Cxx`: **set D2R/SR of operator 1.** +- `5Dxx`: **set D2R/SR of operator 2.** +- `5Exx`: **set D2R/SR of operator 3.** +- `5Fxx`: **set D2R/SR of operator 4.** diff --git a/doc/7-systems/ym2610b.md b/doc/7-systems/ym2610b.md new file mode 100644 index 00000000..7428f6fb --- /dev/null +++ b/doc/7-systems/ym2610b.md @@ -0,0 +1,98 @@ +# Taito Arcade/Yamaha YM2610B + +YM2610B is basically YM2610 with 2 extra FM channels used at some 90s Taito arcade hardware. +it is backward compatible with the original chip. + +# effects + +- `10xy`: **set LFO parameters.** + - `x` toggles the LFO. + - `y` sets its speed. +- `11xx`: **set feedback of channel.** +- `12xx`: **set operator 1 level.** +- `13xx`: **set operator 2 level.** +- `14xx`: **set operator 3 level.** +- `15xx`: **set operator 4 level.** +- `16xy`: **set multiplier of operator.** + - `x` is the operator (1-4). + - `y` is the multiplier. +- `18xx`: **toggle extended channel 3 mode.** + - 0 disables it and 1 enables it. + - only in extended channel 3 chip. +- `19xx`: **set attack of all operators.** +- `1Axx`: **set attack of operator 1.** +- `1Bxx`: **set attack of operator 2.** +- `1Cxx`: **set attack of operator 3.** +- `1Dxx`: **set attack of operator 4.** +- `20xx`: **set SSG channel mode.** + - `00`: square + - `01`: noise + - `02`: square and noise + - `03`: nothing (apparently) + - `04`: envelope and square + - `05`: envelope and noise + - `06`: envelope and square and noise + - `07`: nothing +- `21xx`: **set noise frequency.** range is `00` to `1F`. +- `22xy`: **set envelope mode.** + - `x` sets the envelope shape, which may be one of the following: + - `0`:` \___` decay + - `4`:` /___` attack once + - `8`:` \\\\` saw + - `9`:` \___` decay + - `A`:` \/\/` inverse obelisco + - `B`:` \¯¯¯` decay once + - `C`:` ////` inverse saw + - `D`:` /¯¯¯` attack + - `E`:` /\/\` obelisco + - `F`:` /___` attack once + - if `y` is 1 then the envelope will affect this channel. +- `23xx`: **set envelope period low byte.** +- `24xx`: **set envelope period high byte.** +- `25xx`: **slide envelope period up.** +- `26xx`: **slide envelope period down.** +- `29xy`: **enable SSG auto-envelope mode.** + - in this mode the envelope period is set to the channel's notes, multiplied by a fraction. + - `x` is the numerator. + - `y` is the denominator. + - if `x` or `y` are 0 this will disable auto-envelope mode. +- `30xx`: **enable envelope hard reset.** + - this works by inserting a quick release and tiny delay before a new note. +- `50xy`: **set AM of operator.** + - `x` is the operator (1-4). a value of 0 means "all operators". + - `y` determines whether AM is on. +- `51xy`: **set SL of operator.** + - `x` is the operator (1-4). a value of 0 means "all operators". + - `y` is the value. +- `52xy`: **set RR of operator.** + - `x` is the operator (1-4). a value of 0 means "all operators". + - `y` is the value. +- `53xy`: **set DT of operator.** + - `x` is the operator (1-4). a value of 0 means "all operators". + - `y` is the value: + - `0`: +0 + - `1`: +1 + - `2`: +2 + - `3`: +3 + - `4`: -0 + - `5`: -3 + - `6`: -2 + - `7`: -1 +- `54xy`: **set RS of operator.** + - `x` is the operator (1-4). a value of 0 means "all operators". + - `y` is the value. +- `55xy`: **set SSG-EG of operator.** + - `x` is the operator (1-4). a value of 0 means "all operators". + - `y` is the value (0-8). + - values between 0 and 7 set SSG-EG. + - value 8 disables it. +- `56xx`: **set DR of all operators.** +- `57xx`: **set DR of operator 1.** +- `58xx`: **set DR of operator 2.** +- `59xx`: **set DR of operator 3.** +- `5Axx`: **set DR of operator 4.** +- `5Bxx`: **set D2R/SR of all operators.** +- `5Cxx`: **set D2R/SR of operator 1.** +- `5Dxx`: **set D2R/SR of operator 2.** +- `5Exx`: **set D2R/SR of operator 3.** +- `5Fxx`: **set D2R/SR of operator 4.** diff --git a/doc/7-systems/ym2612.md b/doc/7-systems/ym2612.md new file mode 100644 index 00000000..61df5579 --- /dev/null +++ b/doc/7-systems/ym2612.md @@ -0,0 +1,67 @@ +# Yamaha YM2612 + +one of two chips that powered the Sega Genesis. it is a six-channel, four-operator FM synthesizer. channel #6 can be turned into 8-bit PCM player, that via software mixing, thanks to Z80 sound CPU, can play more than one channel of straight-shot samples at once. as of Furnace 0.6pre5, Furnace offers DualPCM, which allows 2 channels of software-mixed 8-bit PCM samples at 13750 Hz. + +# effects + +- `10xy`: **set LFO parameters.** + - `x` toggles the LFO. + - `y` sets its speed. +- `11xx`: **set feedback of channel.** +- `12xx`: **set operator 1 level.** +- `13xx`: **set operator 2 level.** +- `14xx`: **set operator 3 level.** +- `15xx`: **set operator 4 level.** +- `16xy`: **set multiplier of operator.** + - `x` is the operator (1-4). + - `y` is the multiplier. +- `17xx`: **enable PCM channel.** + - this only works on channel 6. +- `18xx`: **toggle extended channel 3 mode.** + - 0 disables it and 1 enables it. + - only in extended channel 3 chip. +- `19xx`: **set attack of all operators.** +- `1Axx`: **set attack of operator 1.** +- `1Bxx`: **set attack of operator 2.** +- `1Cxx`: **set attack of operator 3.** +- `1Dxx`: **set attack of operator 4.** +- `30xx`: **enable envelope hard reset.** + - this works by inserting a quick release and tiny delay before a new note. +- `50xy`: **set AM of operator.** + - `x` is the operator (1-4). a value of 0 means "all operators". + - `y` determines whether AM is on. +- `51xy`: **set SL of operator.** + - `x` is the operator (1-4). a value of 0 means "all operators". + - `y` is the value. +- `52xy`: **set RR of operator.** + - `x` is the operator (1-4). a value of 0 means "all operators". + - `y` is the value. +- `53xy`: **set DT of operator.** + - `x` is the operator (1-4). a value of 0 means "all operators". + - `y` is the value: + - `0`: -3 + - `1`: -2 + - `2`: -1 + - `3`: 0 + - `4`: 1 + - `5`: 2 + - `6`: 3 + - `7`: -0 +- `54xy`: **set RS of operator.** + - `x` is the operator (1-4). a value of 0 means "all operators". + - `y` is the value. +- `55xy`: **set SSG-EG of operator.** + - `x` is the operator (1-4). a value of 0 means "all operators". + - `y` is the value (0-8). + - values between 0 and 7 set SSG-EG. + - value 8 disables it. +- `56xx`: **set DR of all operators.** +- `57xx`: **set DR of operator 1.** +- `58xx`: **set DR of operator 2.** +- `59xx`: **set DR of operator 3.** +- `5Axx`: **set DR of operator 4.** +- `5Bxx`: **set D2R/SR of all operators.** +- `5Cxx`: **set D2R/SR of operator 1.** +- `5Dxx`: **set D2R/SR of operator 2.** +- `5Exx`: **set D2R/SR of operator 3.** +- `5Fxx`: **set D2R/SR of operator 4.** diff --git a/papers/doc/7-systems/ymu759.md b/doc/7-systems/ymu759.md similarity index 100% rename from papers/doc/7-systems/ymu759.md rename to doc/7-systems/ymu759.md diff --git a/papers/doc/7-systems/ymz280b.md b/doc/7-systems/ymz280b.md similarity index 100% rename from papers/doc/7-systems/ymz280b.md rename to doc/7-systems/ymz280b.md diff --git a/papers/doc/7-systems/zxbeep.md b/doc/7-systems/zxbeep.md similarity index 90% rename from papers/doc/7-systems/zxbeep.md rename to doc/7-systems/zxbeep.md index 6504ce98..6381814a 100644 --- a/papers/doc/7-systems/zxbeep.md +++ b/doc/7-systems/zxbeep.md @@ -6,8 +6,8 @@ not really - very soon talented programmers found out ways to output much more t # effects -- `12xx`: set pulse width. -- `17xx`: trigger overlay drum. +- **`12xx`**: set pulse width. +- **`17xx`**: trigger overlay drum. - `xx` is the sample number. - overlay drums are 1-bit and always play at 55930Hz (NTSC) or 55420Hz (PAL). - the maximum length is 2048! diff --git a/doc/8-advanced/README.md b/doc/8-advanced/README.md new file mode 100644 index 00000000..b1772007 --- /dev/null +++ b/doc/8-advanced/README.md @@ -0,0 +1,21 @@ +# advanced + +advanced Furnace features, as listed in the `Window` menu. + +- [mixer](mixer.md) +- [grooves](grooves.md) +- [channel manager](channels.md) +- [pattern manager](pat-manager.md) +- [chip manager](chip-manager.md) +- [compatibility flags](compat-flags.md) +- [song comments](comments.md) + +
+ +- [piano](piano.md) +- [oscilloscope](osc.md) +- [oscilloscopes (per-channel)](chanosc.md) +- [clock](clock.md) +- [register view](regview.md) +- [log viewer](log-viewer.md) +- [stats](stats.md) diff --git a/doc/8-advanced/channels.md b/doc/8-advanced/channels.md new file mode 100644 index 00000000..7bf4fbf7 --- /dev/null +++ b/doc/8-advanced/channels.md @@ -0,0 +1,11 @@ +# channels + +The "Channels" dialog allows manipulation of the song's channels. + +![channels dialog](channels.png) + +Each channel has the following options: +- **Visible**: uncheck the box to hide the channel from view. Pattern data will be kept. +- Crossed-arrows button: Click and drag to rearrange pattern data throughout the song. _Note:_ This does _not_ move channels around within a chip! It only affects pattern data. +- **Name** is the name displayed at the top of each channel in the tracker view. +- To the right of that is the abbreviation used above each channel in the order view. \ No newline at end of file diff --git a/doc/8-advanced/channels.png b/doc/8-advanced/channels.png new file mode 100644 index 00000000..e51815eb Binary files /dev/null and b/doc/8-advanced/channels.png differ diff --git a/doc/8-advanced/chanosc.md b/doc/8-advanced/chanosc.md new file mode 100644 index 00000000..55e04a19 --- /dev/null +++ b/doc/8-advanced/chanosc.md @@ -0,0 +1,16 @@ +# oscilloscope (per channel) + +The "Oscilloscope (per channel)" dialog shows an individual oscilloscope for each channel during playback. + +![oscilloscope per-channel configuration view](chanosc.png) + +Right-clicking within the view will change it to the configuration view shown above: +- **Columns**: Sets the number of columns the view will be split into. +- **Size (ms)**: Sets what length of audio is visible in each oscilloscope. +- **Center waveform**: Does its best to latch to the channel's note frequency and centers the display. +- **Gradient**: (document this) +- The color selector sets the waveform color. Right-clicking on it pops up an option dialog: + - Select between the square selector and the color wheel selector. + - **Alpha bar**: Adds a transparency selector. +- The boxes below that are for selecting colors numerically by red-green-blue-alpha, hue-saturation-value-alpha, and HTML-style RGBA in hex. +- The OK button returns from options view to regular. diff --git a/doc/8-advanced/chanosc.png b/doc/8-advanced/chanosc.png new file mode 100644 index 00000000..42c6be29 Binary files /dev/null and b/doc/8-advanced/chanosc.png differ diff --git a/doc/8-advanced/chip-manager-change.png b/doc/8-advanced/chip-manager-change.png new file mode 100644 index 00000000..0def9180 Binary files /dev/null and b/doc/8-advanced/chip-manager-change.png differ diff --git a/doc/8-advanced/chip-manager-move.png b/doc/8-advanced/chip-manager-move.png new file mode 100644 index 00000000..022eae23 Binary files /dev/null and b/doc/8-advanced/chip-manager-move.png differ diff --git a/doc/8-advanced/chip-manager-remove.png b/doc/8-advanced/chip-manager-remove.png new file mode 100644 index 00000000..aea34d9c Binary files /dev/null and b/doc/8-advanced/chip-manager-remove.png differ diff --git a/doc/8-advanced/chip-manager.md b/doc/8-advanced/chip-manager.md new file mode 100644 index 00000000..722f3a97 --- /dev/null +++ b/doc/8-advanced/chip-manager.md @@ -0,0 +1,15 @@ +# chip manager + +The **chip manager** window does exactly what it says. + +![chip manager](chip-manager.png) + +**Preserve channel order**: Make existing pattern data stay in place even when chips are rearranged. If turned off, pattern data will rearrange to match (the default, and usually the desired behavior). + +To move a chip around, click and drag the ![crossed-arrows](chip-manager-move.png) button to its left. + +To replace a chip with a different one, click the ![down-angle](chip-manager-change.png) and select the replacement. + +To remove a chip entirely, click the ![X](chip-manager-remove.png) button. + +Click a chip's name to open its options, where one can set clock rate, chip variant, and other specifics. \ No newline at end of file diff --git a/doc/8-advanced/chip-manager.png b/doc/8-advanced/chip-manager.png new file mode 100644 index 00000000..69077779 Binary files /dev/null and b/doc/8-advanced/chip-manager.png differ diff --git a/doc/8-advanced/clock.md b/doc/8-advanced/clock.md new file mode 100644 index 00000000..8c2bcc7c --- /dev/null +++ b/doc/8-advanced/clock.md @@ -0,0 +1,10 @@ +# clock + +![clock dialog](clock.png) + +The clock shows the current playback position relative to the start of the song: + +- order : row +- measure : beat (as defined by row highlight settings) +- beat +- elapsed time in minutes:seconds.hundredths diff --git a/doc/8-advanced/clock.png b/doc/8-advanced/clock.png new file mode 100644 index 00000000..c051c5fd Binary files /dev/null and b/doc/8-advanced/clock.png differ diff --git a/doc/8-advanced/comments.md b/doc/8-advanced/comments.md new file mode 100644 index 00000000..b36d65ab --- /dev/null +++ b/doc/8-advanced/comments.md @@ -0,0 +1,8 @@ +# comments + +![comments dialog](comments.png) + +Comments, credits, or any arbitrary text may be entered here. +It has no effect on the song. + +There is no word wrap; long lines must be broken manually with the Enter key. \ No newline at end of file diff --git a/doc/8-advanced/comments.png b/doc/8-advanced/comments.png new file mode 100644 index 00000000..dec7c26a Binary files /dev/null and b/doc/8-advanced/comments.png differ diff --git a/doc/8-advanced/compat-flags.md b/doc/8-advanced/compat-flags.md new file mode 100644 index 00000000..55319cc1 --- /dev/null +++ b/doc/8-advanced/compat-flags.md @@ -0,0 +1,5 @@ +# compatibility flags + +The **Compatibility Flags** window contains several tabs full of settings that change aspects of tracking and playback. A new Furnace file will leave them all at their defaults (off), while opening a DefleMask, Amiga MOD, or earlier Furnace file will automatically set the appropriate options. + +Hovering over most options will bring up additional info about them. It's not recommended to change any of these without clear reason. _There be dragons here._ diff --git a/doc/8-advanced/groove.png b/doc/8-advanced/groove.png new file mode 100644 index 00000000..ee0877c6 Binary files /dev/null and b/doc/8-advanced/groove.png differ diff --git a/doc/8-advanced/grooves.md b/doc/8-advanced/grooves.md new file mode 100644 index 00000000..d6fea075 --- /dev/null +++ b/doc/8-advanced/grooves.md @@ -0,0 +1,23 @@ +# grooves + +Grooves are macros for speed. + +A **groove** is the equivalent of repeating `0Fxx` commands on each row to get a cycle of speeds. For example, a groove of "6 4 5 3" makes the first row 6 ticks long, the next row 4 ticks, then 5, 3, 6, 4, 5, 3... + + +![groove](groove.png) + +To set the song's groove: +- Open the "Speed" window. +- Click the "Speed" button so it becomes "Speeds" (effectively a groove of two speeds). +- Click again so it becomes "Groove". +- Enter a sequence of up to 16 speeds. + + +![groove patterns](grooves.png) + +The "Grooves" window is for entering preset groove patterns. +- The **`+`** button adds a new groove pattern; click in the pattern to edit it. +- The **`×`** buttons remove them. + +A single `09xx` command will switch to the matching numbered groove pattern. diff --git a/doc/8-advanced/grooves.png b/doc/8-advanced/grooves.png new file mode 100644 index 00000000..2130dad3 Binary files /dev/null and b/doc/8-advanced/grooves.png differ diff --git a/doc/8-advanced/log-viewer.md b/doc/8-advanced/log-viewer.md new file mode 100644 index 00000000..4f1e1e4b --- /dev/null +++ b/doc/8-advanced/log-viewer.md @@ -0,0 +1,17 @@ +# log viewer + +The log viewer provides a look at Furnace's internal messages. This can be useful for chasing down problems. + +![log viewer dialog](log-viewer.png) + +If the **Follow** checkbox is enabled, the log will snap to the bottom and continually scroll to show the newest messages. If disabled, it will stay put on what's currently shown. + +The **Level** dropdown determines the minimum importance of the messages displayed. + +| level | message shown | +|---|---| +| ERROR | serious problem | +| warning | may or may not be a problem | +| info | significant information | +| debug | general info about what Furnace is doing | +| trace | detailed info useful only to developers | diff --git a/doc/8-advanced/log-viewer.png b/doc/8-advanced/log-viewer.png new file mode 100644 index 00000000..aa007650 Binary files /dev/null and b/doc/8-advanced/log-viewer.png differ diff --git a/doc/8-advanced/mixer-mixer.png b/doc/8-advanced/mixer-mixer.png new file mode 100644 index 00000000..249c6fbe Binary files /dev/null and b/doc/8-advanced/mixer-mixer.png differ diff --git a/doc/8-advanced/mixer-patchbay.png b/doc/8-advanced/mixer-patchbay.png new file mode 100644 index 00000000..52ca7ab3 Binary files /dev/null and b/doc/8-advanced/mixer-patchbay.png differ diff --git a/doc/8-advanced/mixer.md b/doc/8-advanced/mixer.md new file mode 100644 index 00000000..bafa0fe8 --- /dev/null +++ b/doc/8-advanced/mixer.md @@ -0,0 +1,25 @@ +# mixer + +The "Mixer" dialog provides options for overall sound mixing. + +## "Mixer" tab + +![mixer dialog on mixer tab](mixer-mixer.png) + +"Master Volume" controls the overall mix. + +Each chip has several options: +- **Invert**: Flips the output wave. +- **Volume**: Controls the chip's volume relative to other chips. +- **Panning**: Left-right sound control. +- **Front/Rear**: Front-read sound control. Only useful for setups with four or more speakers. + +## "Patchbay" tab + +![mixer dialog on patchbay tab](mixer-patchbay.png) + +- **Automatic patchbay**: Make appropriate connections when adding, removing, or changing chips and chip settings. +- **Display hidden ports**: Shows all available connection ports. The "System" unit actually has 16 ports; 1 maps to the left channel, and 2 maps to the right. +- **Display internal**: hows two additional units, one for sample previews and one for the metronome sound. + +The graph shows each existing unit along with their outputs, inputs, and the "patch cables" connecting them. Connections can be made by dragging between an output and an input. Right-clicking on a unit gives the option to disconnect all patches from that unit. diff --git a/doc/8-advanced/osc.md b/doc/8-advanced/osc.md new file mode 100644 index 00000000..fe90e397 --- /dev/null +++ b/doc/8-advanced/osc.md @@ -0,0 +1,9 @@ +# oscilloscope + +The Oscilloscope shows the waveform of the mix of all currently playing sounds. + +![oscilloscope view](osc.png) + +Right-clicking on the oscilloscope toggles the adjustment sliders: +- waveform height zoom +- width of viewed audio (window size) in milliseconds. diff --git a/doc/8-advanced/osc.png b/doc/8-advanced/osc.png new file mode 100644 index 00000000..4a9b728c Binary files /dev/null and b/doc/8-advanced/osc.png differ diff --git a/doc/8-advanced/pat-manager.md b/doc/8-advanced/pat-manager.md new file mode 100644 index 00000000..ea058e66 --- /dev/null +++ b/doc/8-advanced/pat-manager.md @@ -0,0 +1,22 @@ +# pattern manager + +The pattern manager is useful for cleaning up stray patterns and as an overview of pattern usage. + +![pattern manager dialog](pattern-manager.png) + +**De-duplicate patterns** looks for matching patterns, eliminates all but the first instance, and changes all references in the order list to match. + +**Re-arrange patterns** renumbers patterns to be in sequence, along with changing all references in the order list to match. + +The pattern grid shows each channel and all its patterns. These are color-coded to show how much they're used in the song; these colors can be changed in Settings. + +| default color | name in Settings | meaning | +| --- | --- | --- | +| grey | Unallocated | pattern doesn't exist yet | +| red | Unused | exists but isn't in order list | +| green | Used | used only once in order list | +| yellow | Overused | used multiple times | +| orange | Really overused | used in half or more orders | +| magenta | Combo Breaker | the only used pattern in this channel! | + +Right-clicking a pattern will permanently delete it. diff --git a/doc/8-advanced/pattern-manager.png b/doc/8-advanced/pattern-manager.png new file mode 100644 index 00000000..b64b9d29 Binary files /dev/null and b/doc/8-advanced/pattern-manager.png differ diff --git a/doc/8-advanced/piano.md b/doc/8-advanced/piano.md new file mode 100644 index 00000000..6217f847 --- /dev/null +++ b/doc/8-advanced/piano.md @@ -0,0 +1,38 @@ +# piano / input pad + +The piano serves as a non-keyboard interface to input notes. + +![piano chart](piano.png) + +The buttons at the left do the following: + +| | | | +| :---: | :---: | :---: | +| move one octave down | move one octave up | open options | +| fewer visible octaves | more visible octaves | swap buttons | + +When swapped, the bottons do the following: + +| | | | +| :---: | :---: | :---: | +| input note off | input note release | open options | +| input macro release | delete | swap buttons | + +Every C key is labelled with its octave. + +Right-clicking on the piano keys will make the buttons disappear; right-clicking again brings them back. + +## options + +Key layout: +- **Automatic** +- **Standard**: Black keys are 2/3 length. +- **Continuous**: Black keys are full length. + +Value input pad: (document this) +- **Disabled** +- **Replace piano** +- **Split (automatic)** +- **Split (always visible)** + +**Share play/edit offset/range**: (document this) diff --git a/doc/8-advanced/piano.png b/doc/8-advanced/piano.png new file mode 100644 index 00000000..9bf53cf6 Binary files /dev/null and b/doc/8-advanced/piano.png differ diff --git a/doc/8-advanced/register.png b/doc/8-advanced/register.png new file mode 100644 index 00000000..76ec9894 Binary files /dev/null and b/doc/8-advanced/register.png differ diff --git a/doc/8-advanced/regview.md b/doc/8-advanced/regview.md new file mode 100644 index 00000000..57f526fb --- /dev/null +++ b/doc/8-advanced/regview.md @@ -0,0 +1,5 @@ +# register view + +During playback, "Register View" shows the hex data involved with each chip's operation. + +![register view dialog](register.png) diff --git a/doc/8-advanced/stats.md b/doc/8-advanced/stats.md new file mode 100644 index 00000000..9f3c5f49 --- /dev/null +++ b/doc/8-advanced/stats.md @@ -0,0 +1,5 @@ +# statistics + +The Statistics dialog shows running stats such as overall audio processing load and per-chip sample memory. + +![statistics dialog](stats.png) diff --git a/doc/8-advanced/stats.png b/doc/8-advanced/stats.png new file mode 100644 index 00000000..920654e6 Binary files /dev/null and b/doc/8-advanced/stats.png differ diff --git a/papers/doc/README.md b/doc/README.md similarity index 92% rename from papers/doc/README.md rename to doc/README.md index d8a14be2..f561710c 100644 --- a/papers/doc/README.md +++ b/doc/README.md @@ -9,6 +9,7 @@ this documentation is a work in progress! expect several sections to be incomple 5. [wavetables](5-wave/README.md) 6. [samples](6-sample/README.md) 7. [list of sound chips](7-systems/README.md) +8. [advanced topics](8-advanced/README.md) # attribution @@ -22,6 +23,7 @@ writers: - host12prog - WindowxDeveloper - polluks +- Electric Keet other: diff --git a/extern/SAASound/src/SAADevice.cpp b/extern/SAASound/src/SAADevice.cpp index 9064dcab..eb88e9ac 100644 --- a/extern/SAASound/src/SAADevice.cpp +++ b/extern/SAASound/src/SAADevice.cpp @@ -316,27 +316,27 @@ void CSAADevice::_TickAndOutputStereo(unsigned int& left_mixed, unsigned int& ri m_Noise0.Tick(); m_Noise1.Tick(); m_Amp0.TickAndOutputStereo(temp_left, temp_right); - oscBuf[0]->data[oscBuf[0]->needle++]=(temp_left+temp_right)<<4; + oscBuf[0]->data[oscBuf[0]->needle++]=(temp_left+temp_right)<<5; accum_left += temp_left; accum_right += temp_right; m_Amp1.TickAndOutputStereo(temp_left, temp_right); - oscBuf[1]->data[oscBuf[1]->needle++]=(temp_left+temp_right)<<4; + oscBuf[1]->data[oscBuf[1]->needle++]=(temp_left+temp_right)<<5; accum_left += temp_left; accum_right += temp_right; m_Amp2.TickAndOutputStereo(temp_left, temp_right); - oscBuf[2]->data[oscBuf[2]->needle++]=(temp_left+temp_right)<<4; + oscBuf[2]->data[oscBuf[2]->needle++]=(temp_left+temp_right)<<5; accum_left += temp_left; accum_right += temp_right; m_Amp3.TickAndOutputStereo(temp_left, temp_right); - oscBuf[3]->data[oscBuf[3]->needle++]=(temp_left+temp_right)<<4; + oscBuf[3]->data[oscBuf[3]->needle++]=(temp_left+temp_right)<<5; accum_left += temp_left; accum_right += temp_right; m_Amp4.TickAndOutputStereo(temp_left, temp_right); - oscBuf[4]->data[oscBuf[4]->needle++]=(temp_left+temp_right)<<4; + oscBuf[4]->data[oscBuf[4]->needle++]=(temp_left+temp_right)<<5; accum_left += temp_left; accum_right += temp_right; m_Amp5.TickAndOutputStereo(temp_left, temp_right); - oscBuf[5]->data[oscBuf[5]->needle++]=(temp_left+temp_right)<<4; + oscBuf[5]->data[oscBuf[5]->needle++]=(temp_left+temp_right)<<5; accum_left += temp_left; accum_right += temp_right; } @@ -394,4 +394,4 @@ void CSAADevice::_TickAndOutputSeparate(unsigned int& left_mixed, unsigned int& } left_mixed = accum_left; right_mixed = accum_right; -} \ No newline at end of file +} diff --git a/extern/SDL b/extern/SDL index 55b03c74..ffa78e6b 160000 --- a/extern/SDL +++ b/extern/SDL @@ -1 +1 @@ -Subproject commit 55b03c7493a7abed33cf803d1380a40fa8af903f +Subproject commit ffa78e6bead23e2ba3adf8ec2367ff2218d4343c diff --git a/extern/igfd/ImGuiFileDialog.cpp b/extern/igfd/ImGuiFileDialog.cpp index 372287d0..2ccc3e9c 100644 --- a/extern/igfd/ImGuiFileDialog.cpp +++ b/extern/igfd/ImGuiFileDialog.cpp @@ -25,6 +25,10 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#ifndef IMGUI_DEFINE_MATH_OPERATORS + #define IMGUI_DEFINE_MATH_OPERATORS +#endif // IMGUI_DEFINE_MATH_OPERATORS + #include "ImGuiFileDialog.h" #include "../../src/ta-log.h" @@ -38,42 +42,28 @@ SOFTWARE. #include #include #include -// this option need c++17 -#ifdef USE_STD_FILESYSTEM - #include -#endif #if defined (__EMSCRIPTEN__) // EMSCRIPTEN - #include + #include #endif // EMSCRIPTEN #ifdef WIN32 - #define stat _stat - #define stricmp _stricmp - #include - // this option need c++17 - #ifdef USE_STD_FILESYSTEM - #include - #else - #include "dirent/dirent.h" // directly open the dirent file attached to this lib - #endif // USE_STD_FILESYSTEM - #define PATH_SEP '\\' - #ifndef PATH_MAX - #define PATH_MAX 260 - #endif // PATH_MAX + #define stricmp _stricmp + #include + #include "dirent/dirent.h" // directly open the dirent file attached to this lib + #define PATH_SEP '\\' + #define PATH_SEP_STR "\\" + #ifndef PATH_MAX + #define PATH_MAX 260 + #endif // PATH_MAX #elif defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__APPLE__) || defined (__EMSCRIPTEN__) || defined(__HAIKU__) - #define UNIX - #define stricmp strcasecmp - #include - // this option need c++17 - #ifndef USE_STD_FILESYSTEM - #include - #endif // USE_STD_FILESYSTEM - #define PATH_SEP '/' + #define UNIX + #define stricmp strcasecmp + #include + #include + #define PATH_SEP '/' + #define PATH_SEP_STR "/" #endif // defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__APPLE__) #include "imgui.h" -#ifndef IMGUI_DEFINE_MATH_OPERATORS - #define IMGUI_DEFINE_MATH_OPERATORS -#endif // IMGUI_DEFINE_MATH_OPERATORS #include "imgui_internal.h" #include @@ -132,6 +122,9 @@ namespace IGFD #ifndef resetButtonString #define resetButtonString ICON_FA_REPEAT #endif // resetButtonString +#ifndef homeButtonString +#define homeButtonString ICON_FA_HOME +#endif // bomeButtonString #ifndef drivesButtonString #define drivesButtonString ICON_FA_HDD_O #endif // drivesButtonString @@ -169,7 +162,7 @@ namespace IGFD #define buttonEditPathString "Edit path\nYou can also right click on path buttons" #endif // buttonEditPathString #ifndef buttonResetPathString -#define buttonResetPathString "Reset to current directory" +#define buttonResetPathString "Go to home directory" #endif // buttonResetPathString #ifndef buttonParentDirString #define buttonParentDirString "Go to parent directory" @@ -237,29 +230,29 @@ namespace IGFD #define DisplayMode_ThumbailsList_ImageHeight 32.0f #endif // DisplayMode_ThumbailsList_ImageHeight #ifndef IMGUI_RADIO_BUTTON - inline bool inRadioButton(const char* vLabel, bool vToggled) - { - bool pressed = false; + inline bool inRadioButton(const char* vLabel, bool vToggled) + { + bool pressed = false; - if (vToggled) - { - ImVec4 bua = ImGui::GetStyleColorVec4(ImGuiCol_ButtonActive); - ImVec4 te = ImGui::GetStyleColorVec4(ImGuiCol_Text); - ImGui::PushStyleColor(ImGuiCol_Button, te); - ImGui::PushStyleColor(ImGuiCol_ButtonActive, te); - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, te); - ImGui::PushStyleColor(ImGuiCol_Text, bua); - } + if (vToggled) + { + ImVec4 bua = ImGui::GetStyleColorVec4(ImGuiCol_ButtonActive); + ImVec4 te = ImGui::GetStyleColorVec4(ImGuiCol_Text); + ImGui::PushStyleColor(ImGuiCol_Button, te); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, te); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, te); + ImGui::PushStyleColor(ImGuiCol_Text, bua); + } - pressed = IMGUI_BUTTON(vLabel); + pressed = IMGUI_BUTTON(vLabel); - if (vToggled) - { - ImGui::PopStyleColor(4); //-V112 - } + if (vToggled) + { + ImGui::PopStyleColor(4); //-V112 + } - return pressed; - } + return pressed; + } #define IMGUI_RADIO_BUTTON inRadioButton #endif // IMGUI_RADIO_BUTTON #endif // USE_THUMBNAILS @@ -280,946 +273,903 @@ namespace IGFD #define removeBookmarkButtonString "-" #endif // removeBookmarkButtonString #ifndef IMGUI_TOGGLE_BUTTON - inline bool inToggleButton(const char* vLabel, bool* vToggled) - { - bool pressed = false; + inline bool inToggleButton(const char* vLabel, bool* vToggled) + { + bool pressed = false; - if (vToggled && *vToggled) - { - ImVec4 bua = ImGui::GetStyleColorVec4(ImGuiCol_ButtonActive); - //ImVec4 buh = ImGui::GetStyleColorVec4(ImGuiCol_ButtonHovered); - //ImVec4 bu = ImGui::GetStyleColorVec4(ImGuiCol_Button); - ImVec4 te = ImGui::GetStyleColorVec4(ImGuiCol_Text); - ImGui::PushStyleColor(ImGuiCol_Button, te); - ImGui::PushStyleColor(ImGuiCol_ButtonActive, te); - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, te); - ImGui::PushStyleColor(ImGuiCol_Text, bua); - } + if (vToggled && *vToggled) + { + ImVec4 bua = ImGui::GetStyleColorVec4(ImGuiCol_ButtonActive); + //ImVec4 buh = ImGui::GetStyleColorVec4(ImGuiCol_ButtonHovered); + //ImVec4 bu = ImGui::GetStyleColorVec4(ImGuiCol_Button); + ImVec4 te = ImGui::GetStyleColorVec4(ImGuiCol_Text); + ImGui::PushStyleColor(ImGuiCol_Button, te); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, te); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, te); + ImGui::PushStyleColor(ImGuiCol_Text, bua); + } - pressed = IMGUI_BUTTON(vLabel); + pressed = IMGUI_BUTTON(vLabel); - if (vToggled && *vToggled) - { - ImGui::PopStyleColor(4); //-V112 - } + if (vToggled && *vToggled) + { + ImGui::PopStyleColor(4); //-V112 + } - if (vToggled && pressed) - *vToggled = !*vToggled; + if (vToggled && pressed) + *vToggled = !*vToggled; - return pressed; - } + return pressed; + } #define IMGUI_TOGGLE_BUTTON inToggleButton #endif // IMGUI_TOGGLE_BUTTON #endif // USE_BOOKMARK - ///////////////////////////////////////////////////////////////////////////////////// - //// INLINE FUNCTIONS /////////////////////////////////////////////////////////////// - ///////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////////////////// + //// INLINE FUNCTIONS /////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////////////////// -#ifndef USE_STD_FILESYSTEM - inline int inAlphaSort(const struct dirent** a, const struct dirent** b) - { - return strcoll((*a)->d_name, (*b)->d_name); - } -#endif + inline int inAlphaSort(const struct dirent** a, const struct dirent** b) + { + return strcoll((*a)->d_name, (*b)->d_name); + } - ///////////////////////////////////////////////////////////////////////////////////// - //// FILE EXTENTIONS INFOS ////////////////////////////////////////////////////////// - ///////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////////////////// + //// FILE EXTENTIONS INFOS ////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////////////////// - IGFD::FileStyle::FileStyle() - : color(0, 0, 0, 0) - { + IGFD::FileStyle::FileStyle() + : color(0, 0, 0, 0) + { - } - - IGFD::FileStyle::FileStyle(const FileStyle& vStyle) - { - color = vStyle.color; - icon = vStyle.icon; - font = vStyle.font; - flags = vStyle.flags; - } + } + + IGFD::FileStyle::FileStyle(const FileStyle& vStyle) + { + color = vStyle.color; + icon = vStyle.icon; + font = vStyle.font; + flags = vStyle.flags; + } - IGFD::FileStyle::FileStyle(const ImVec4& vColor, const std::string& vIcon, ImFont* vFont) - : color(vColor), icon(vIcon), font(vFont) - { + IGFD::FileStyle::FileStyle(const ImVec4& vColor, const std::string& vIcon, ImFont* vFont) + : color(vColor), icon(vIcon), font(vFont) + { - } + } - ///////////////////////////////////////////////////////////////////////////////////// - //// FILE INFOS ///////////////////////////////////////////////////////////////////// - ///////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////////////////// + //// FILE INFOS ///////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////////////////// - // https://github.com/ocornut/imgui/issues/1720 - bool IGFD::Utils::Splitter(bool split_vertically, float thickness, float* size1, float* size2, float min_size1, float min_size2, float splitter_long_axis_size) - { - using namespace ImGui; - ImGuiContext& g = *GImGui; - ImGuiWindow* window = g.CurrentWindow; - ImGuiID id = window->GetID("##Splitter"); - ImRect bb; - bb.Min = window->DC.CursorPos + (split_vertically ? ImVec2(*size1, 0.0f) : ImVec2(0.0f, *size1)); - bb.Max = bb.Min + CalcItemSize(split_vertically ? ImVec2(thickness, splitter_long_axis_size) : ImVec2(splitter_long_axis_size, thickness), 0.0f, 0.0f); - return SplitterBehavior(bb, id, split_vertically ? ImGuiAxis_X : ImGuiAxis_Y, size1, size2, min_size1, min_size2, 1.0f); - } + // https://github.com/ocornut/imgui/issues/1720 + bool IGFD::Utils::Splitter(bool split_vertically, float thickness, float* size1, float* size2, float min_size1, float min_size2, float splitter_long_axis_size) + { + using namespace ImGui; + ImGuiContext& g = *GImGui; + ImGuiWindow* window = g.CurrentWindow; + ImGuiID id = window->GetID("##Splitter"); + ImRect bb; + bb.Min = window->DC.CursorPos + (split_vertically ? ImVec2(*size1, 0.0f) : ImVec2(0.0f, *size1)); + bb.Max = bb.Min + CalcItemSize(split_vertically ? ImVec2(thickness, splitter_long_axis_size) : ImVec2(splitter_long_axis_size, thickness), 0.0f, 0.0f); + return SplitterBehavior(bb, id, split_vertically ? ImGuiAxis_X : ImGuiAxis_Y, size1, size2, min_size1, min_size2, 1.0f); + } #ifdef WIN32 - bool IGFD::Utils::WReplaceString(std::wstring& str, const std::wstring& oldStr, const std::wstring& newStr) - { - bool found = false; - size_t pos = 0; - while ((pos = str.find(oldStr, pos)) != std::wstring::npos) - { - found = true; - str.replace(pos, oldStr.length(), newStr); - pos += newStr.length(); - } - return found; - } + bool IGFD::Utils::WReplaceString(std::wstring& str, const std::wstring& oldStr, const std::wstring& newStr) + { + bool found = false; + size_t pos = 0; + while ((pos = str.find(oldStr, pos)) != std::wstring::npos) + { + found = true; + str.replace(pos, oldStr.length(), newStr); + pos += newStr.length(); + } + return found; + } - std::vector IGFD::Utils::WSplitStringToVector(const std::wstring& text, char delimiter, bool pushEmpty) - { - std::vector arr; - if (!text.empty()) - { - std::wstring::size_type start = 0; - std::wstring::size_type end = text.find(delimiter, start); - while (end != std::wstring::npos) - { - std::wstring token = text.substr(start, end - start); - if (!token.empty() || (token.empty() && pushEmpty)) //-V728 - arr.push_back(token); - start = end + 1; - end = text.find(delimiter, start); - } - std::wstring token = text.substr(start); - if (!token.empty() || (token.empty() && pushEmpty)) //-V728 - arr.push_back(token); - } - return arr; - } + std::vector IGFD::Utils::WSplitStringToVector(const std::wstring& text, char delimiter, bool pushEmpty) + { + std::vector arr; + if (!text.empty()) + { + std::wstring::size_type start = 0; + std::wstring::size_type end = text.find(delimiter, start); + while (end != std::wstring::npos) + { + std::wstring token = text.substr(start, end - start); + if (!token.empty() || (token.empty() && pushEmpty)) //-V728 + arr.push_back(token); + start = end + 1; + end = text.find(delimiter, start); + } + std::wstring token = text.substr(start); + if (!token.empty() || (token.empty() && pushEmpty)) //-V728 + arr.push_back(token); + } + return arr; + } - std::wstring IGFD::Utils::string_to_wstring(const std::string& str) - { - std::wstring ret; - if (!str.empty()) - { - size_t sz = std::mbstowcs(nullptr, str.c_str(), str.size()); - if (sz) - { - ret.resize(sz); - std::mbstowcs((wchar_t*)ret.data(), str.c_str(), sz); - } - } - return ret; - } + std::wstring IGFD::Utils::string_to_wstring(const std::string& str) + { + std::wstring ret; + if (!str.empty()) + { + size_t sz = std::mbstowcs(nullptr, str.c_str(), str.size()); + if (sz) + { + ret.resize(sz); + std::mbstowcs((wchar_t*)ret.data(), str.c_str(), sz); + } + } + return ret; + } - std::string IGFD::Utils::wstring_to_string(const std::wstring& str) - { - std::string ret; - if (!str.empty()) - { - size_t sz = std::wcstombs(nullptr, str.c_str(), str.size()); - if (sz) - { - ret.resize(sz); - std::wcstombs((char*)ret.data(), str.c_str(), sz); - } - } - return ret; - } + std::string IGFD::Utils::wstring_to_string(const std::wstring& str) + { + std::string ret; + if (!str.empty()) + { + size_t sz = std::wcstombs(nullptr, str.c_str(), str.size()); + if (sz) + { + ret.resize(sz); + std::wcstombs((char*)ret.data(), str.c_str(), sz); + } + } + return ret; + } #endif // WIN32 - bool IGFD::Utils::ReplaceString(std::string& str, const std::string& oldStr, const std::string& newStr) - { - bool found = false; - size_t pos = 0; - while ((pos = str.find(oldStr, pos)) != std::string::npos) - { - found = true; - str.replace(pos, oldStr.length(), newStr); - pos += newStr.length(); - } - return found; - } + bool IGFD::Utils::ReplaceString(std::string& str, const std::string& oldStr, const std::string& newStr) + { + bool found = false; + size_t pos = 0; + while ((pos = str.find(oldStr, pos)) != std::string::npos) + { + found = true; + str.replace(pos, oldStr.length(), newStr); + pos += newStr.length(); + } + return found; + } - std::vector IGFD::Utils::SplitStringToVector(const std::string& text, char delimiter, bool pushEmpty) - { - std::vector arr; - if (!text.empty()) - { - size_t start = 0; - size_t end = text.find(delimiter, start); - while (end != std::string::npos) - { - auto token = text.substr(start, end - start); - if (!token.empty() || (token.empty() && pushEmpty)) //-V728 - arr.push_back(token); - start = end + 1; - end = text.find(delimiter, start); - } - auto token = text.substr(start); - if (!token.empty() || (token.empty() && pushEmpty)) //-V728 - arr.push_back(token); - } - return arr; - } + std::vector IGFD::Utils::SplitStringToVector(const std::string& text, char delimiter, bool pushEmpty) + { + std::vector arr; + if (!text.empty()) + { + size_t start = 0; + size_t end = text.find(delimiter, start); + while (end != std::string::npos) + { + auto token = text.substr(start, end - start); + if (!token.empty() || (token.empty() && pushEmpty)) //-V728 + arr.push_back(token); + start = end + 1; + end = text.find(delimiter, start); + } + auto token = text.substr(start); + if (!token.empty() || (token.empty() && pushEmpty)) //-V728 + arr.push_back(token); + } + return arr; + } - std::vector IGFD::Utils::GetDrivesList() - { - std::vector res; + std::vector IGFD::Utils::GetDrivesList() + { + std::vector res; #ifdef WIN32 - const DWORD mydrives = 2048; - char lpBuffer[2048]; + const DWORD mydrives = 2048; + char lpBuffer[2048]; #define mini(a,b) (((a) < (b)) ? (a) : (b)) - const DWORD countChars = mini(GetLogicalDriveStringsA(mydrives, lpBuffer), 2047); + const DWORD countChars = mini(GetLogicalDriveStringsA(mydrives, lpBuffer), 2047); #undef mini - if (countChars > 0) - { - std::string var = std::string(lpBuffer, (size_t)countChars); - IGFD::Utils::ReplaceString(var, "\\", ""); - res = IGFD::Utils::SplitStringToVector(var, '\0', false); - } + if (countChars > 0) + { + std::string var = std::string(lpBuffer, (size_t)countChars); + IGFD::Utils::ReplaceString(var, "\\", ""); + res = IGFD::Utils::SplitStringToVector(var, '\0', false); + } #endif // WIN32 - return res; - } + return res; + } - bool IGFD::Utils::IsDirectoryExist(const std::string& name) - { - bool bExists = false; + bool IGFD::Utils::IsDirectoryExist(const std::string& name) + { + bool bExists = false; - if (!name.empty()) - { -#ifdef USE_STD_FILESYSTEM - namespace fs = std::filesystem; + if (!name.empty()) + { + DIR* pDir = nullptr; + pDir = opendir(name.c_str()); + if (pDir != nullptr) + { + bExists = true; + (void)closedir(pDir); + } + } + + return bExists; // this is not a directory! + } + + bool IGFD::Utils::CreateDirectoryIfNotExist(const std::string& name) + { + bool res = false; + + if (!name.empty()) + { + if (!IsDirectoryExist(name)) + { #ifdef WIN32 - std::wstring wname = IGFD::Utils::string_to_wstring(name.c_str()); - fs::path pathName = fs::path(wname); -#else - fs::path pathName = fs::path(name); -#endif - bExists = fs::is_directory(pathName); -#else - DIR* pDir = nullptr; - pDir = opendir(name.c_str()); - if (pDir != nullptr) - { - bExists = true; - (void)closedir(pDir); - } -#endif // USE_STD_FILESYSTEM - } - - return bExists; // this is not a directory! - } - - bool IGFD::Utils::CreateDirectoryIfNotExist(const std::string& name) - { - bool res = false; - - if (!name.empty()) - { - if (!IsDirectoryExist(name)) - { -#ifdef WIN32 -#ifdef USE_STD_FILESYSTEM - namespace fs = std::filesystem; - std::wstring wname = IGFD::Utils::string_to_wstring(name.c_str()); - fs::path pathName = fs::path(wname); - res = fs::create_directory(pathName); -#else - std::wstring wname = IGFD::Utils::string_to_wstring(name); - if (CreateDirectoryW(wname.c_str(), nullptr)) - { - res = true; - } -#endif // USE_STD_FILESYSTEM + std::wstring wname = IGFD::Utils::string_to_wstring(name); + if (CreateDirectoryW(wname.c_str(), nullptr)) + { + res = true; + } #elif defined(__EMSCRIPTEN__) - std::string str = std::string("FS.mkdir('") + name + "');"; - emscripten_run_script(str.c_str()); - res = true; + std::string str = std::string("FS.mkdir('") + name + "');"; + emscripten_run_script(str.c_str()); + res = true; #elif defined(UNIX) - char buffer[PATH_MAX] = {}; - snprintf(buffer, PATH_MAX, "mkdir -p %s", name.c_str()); - const int dir_err = std::system(buffer); - if (dir_err != -1) - { - res = true; - } + char buffer[PATH_MAX] = {}; + snprintf(buffer, PATH_MAX, "mkdir -p %s", name.c_str()); + const int dir_err = std::system(buffer); + if (dir_err != -1) + { + res = true; + } #endif // WIN32 - if (!res) { - std::cout << "Error creating directory " << name << std::endl; - } - } - } + if (!res) { + std::cout << "Error creating directory " << name << std::endl; + } + } + } - return res; - } + return res; + } -#ifdef USE_STD_FILESYSTEM - // https://github.com/aiekick/ImGuiFileDialog/issues/54 - IGFD::Utils::PathStruct IGFD::Utils::ParsePathFileName(const std::string& vPathFileName) - { - namespace fs = std::filesystem; - PathStruct res; - if (vPathFileName.empty()) - return res; + IGFD::Utils::PathStruct IGFD::Utils::ParsePathFileName(const std::string& vPathFileName) + { + PathStruct res; - auto fsPath = fs::path(vPathFileName); + if (!vPathFileName.empty()) + { + std::string pfn = vPathFileName; + std::string separator(1u, PATH_SEP); + IGFD::Utils::ReplaceString(pfn, "\\", separator); + IGFD::Utils::ReplaceString(pfn, "/", separator); - if (fs::is_regular_file(fsPath)) { - res.name = fsPath.string(); - res.path = fsPath.parent_path().string(); - res.isOk = true; - } + size_t lastSlash = pfn.find_last_of(separator); + if (lastSlash != std::string::npos) + { + res.name = pfn.substr(lastSlash + 1); + res.path = pfn.substr(0, lastSlash); + res.isOk = true; + } - return res; - } -#else - IGFD::Utils::PathStruct IGFD::Utils::ParsePathFileName(const std::string& vPathFileName) - { - PathStruct res; - - if (!vPathFileName.empty()) - { - std::string pfn = vPathFileName; - std::string separator(1u, PATH_SEP); - IGFD::Utils::ReplaceString(pfn, "\\", separator); - IGFD::Utils::ReplaceString(pfn, "/", separator); - - size_t lastSlash = pfn.find_last_of(separator); - if (lastSlash != std::string::npos) - { - res.name = pfn.substr(lastSlash + 1); - res.path = pfn.substr(0, lastSlash); - res.isOk = true; - } - - size_t lastPoint = pfn.find_last_of('.'); - if (lastPoint != std::string::npos) - { - if (!res.isOk) - { - res.name = pfn; - res.isOk = true; - } - res.ext = pfn.substr(lastPoint + 1); - IGFD::Utils::ReplaceString(res.name, "." + res.ext, ""); - } + size_t lastPoint = pfn.find_last_of('.'); + if (lastPoint != std::string::npos) + { + if (!res.isOk) + { + res.name = pfn; + res.isOk = true; + } + res.ext = pfn.substr(lastPoint + 1); + IGFD::Utils::ReplaceString(res.name, "." + res.ext, ""); + } if (res.path.empty()) { res.path=separator; } - if (!res.isOk) - { - res.name = std::move(pfn); - res.isOk = true; - } - } + if (!res.isOk) + { + res.name = std::move(pfn); + res.isOk = true; + } + } - return res; - } -#endif // USE_STD_FILESYSTEM - void IGFD::Utils::AppendToBuffer(char* vBuffer, size_t vBufferLen, const std::string& vStr) - { - std::string st = vStr; - size_t len = vBufferLen - 1u; - size_t slen = strlen(vBuffer); + return res; + } + void IGFD::Utils::AppendToBuffer(char* vBuffer, size_t vBufferLen, const std::string& vStr) + { + std::string st = vStr; + size_t len = vBufferLen - 1u; + size_t slen = strlen(vBuffer); - if (!st.empty() && st != "\n") - { - IGFD::Utils::ReplaceString(st, "\n", ""); - IGFD::Utils::ReplaceString(st, "\r", ""); - } - vBuffer[slen] = '\0'; - std::string str = std::string(vBuffer); - //if (!str.empty()) str += "\n"; - str += vStr; - if (len > str.size()) len = str.size(); + if (!st.empty() && st != "\n") + { + IGFD::Utils::ReplaceString(st, "\n", ""); + IGFD::Utils::ReplaceString(st, "\r", ""); + } + vBuffer[slen] = '\0'; + std::string str = std::string(vBuffer); + //if (!str.empty()) str += "\n"; + str += vStr; + if (len > str.size()) len = str.size(); #ifdef MSVC - strncpy_s(vBuffer, vBufferLen, str.c_str(), len); + strncpy_s(vBuffer, vBufferLen, str.c_str(), len); #else // MSVC - strncpy(vBuffer, str.c_str(), len); + strncpy(vBuffer, str.c_str(), len); #endif // MSVC - vBuffer[len] = '\0'; - } + vBuffer[len] = '\0'; + } - void IGFD::Utils::ResetBuffer(char* vBuffer) - { - vBuffer[0] = '\0'; - } + void IGFD::Utils::ResetBuffer(char* vBuffer) + { + vBuffer[0] = '\0'; + } - void IGFD::Utils::SetBuffer(char* vBuffer, size_t vBufferLen, const std::string& vStr) - { - ResetBuffer(vBuffer); - AppendToBuffer(vBuffer, vBufferLen, vStr); - } + void IGFD::Utils::SetBuffer(char* vBuffer, size_t vBufferLen, const std::string& vStr) + { + ResetBuffer(vBuffer); + AppendToBuffer(vBuffer, vBufferLen, vStr); + } - ///////////////////////////////////////////////////////////////////////////////////// - //// FILE INFOS ///////////////////////////////////////////////////////////////////// - ///////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////////////////// + //// FILE INFOS ///////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////////////////// - bool IGFD::FileInfos::IsTagFound(const std::string& vTag) const - { - if (!vTag.empty()) - { - if (fileNameExt_optimized == "..") return true; + bool IGFD::FileInfos::IsTagFound(const std::string& vTag) const + { + if (!vTag.empty()) + { + if (fileNameExt_optimized == "..") return true; - return - fileNameExt_optimized.find(vTag) != std::string::npos || // first try wihtout case and accents - fileNameExt.find(vTag) != std::string::npos; // second if searched with case and accents - } + return + fileNameExt_optimized.find(vTag) != std::string::npos || // first try wihtout case and accents + fileNameExt.find(vTag) != std::string::npos; // second if searched with case and accents + } - // if tag is empty => its a special case but all is found - return true; - } + // if tag is empty => its a special case but all is found + return true; + } - ///////////////////////////////////////////////////////////////////////////////////// - //// SEARCH MANAGER ///////////////////////////////////////////////////////////////// - ///////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////////////////// + //// SEARCH MANAGER ///////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////////////////// - void IGFD::SearchManager::Clear() - { - puSearchTag.clear(); - IGFD::Utils::ResetBuffer(puSearchBuffer); - } + void IGFD::SearchManager::Clear() + { + puSearchTag.clear(); + IGFD::Utils::ResetBuffer(puSearchBuffer); + } - void IGFD::SearchManager::DrawSearchBar(FileDialogInternal& vFileDialogInternal) - { - // search field - if (IMGUI_BUTTON(resetButtonString "##BtnImGuiFileDialogSearchField")) - { - Clear(); - vFileDialogInternal.puFileManager.ApplyFilteringOnFileList(vFileDialogInternal); - } - if (ImGui::IsItemHovered()) - ImGui::SetTooltip(buttonResetSearchString); - ImGui::SameLine(); - ImGui::Text(searchString); - ImGui::SameLine(); - ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x); - bool edited = ImGui::InputText("##InputImGuiFileDialogSearchField", puSearchBuffer, MAX_FILE_DIALOG_NAME_BUFFER); - if (ImGui::GetItemID() == ImGui::GetActiveID()) - puSearchInputIsActive = true; - ImGui::PopItemWidth(); - if (edited) - { - puSearchTag = puSearchBuffer; - vFileDialogInternal.puFileManager.ApplyFilteringOnFileList(vFileDialogInternal); - } - } + void IGFD::SearchManager::DrawSearchBar(FileDialogInternal& vFileDialogInternal) + { + // search field + if (IMGUI_BUTTON(resetButtonString "##BtnImGuiFileDialogSearchField")) + { + Clear(); + vFileDialogInternal.puFileManager.ApplyFilteringOnFileList(vFileDialogInternal); + } + if (ImGui::IsItemHovered()) + ImGui::SetTooltip(buttonResetSearchString); + ImGui::SameLine(); + ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x); + bool edited = ImGui::InputTextWithHint("##InputImGuiFileDialogSearchField", searchString, puSearchBuffer, MAX_FILE_DIALOG_NAME_BUFFER); + if (ImGui::GetItemID() == ImGui::GetActiveID()) + puSearchInputIsActive = true; + ImGui::PopItemWidth(); + if (edited) + { + puSearchTag = puSearchBuffer; + vFileDialogInternal.puFileManager.ApplyFilteringOnFileList(vFileDialogInternal); + } + } - ///////////////////////////////////////////////////////////////////////////////////// - //// FILTER INFOS /////////////////////////////////////////////////////////////////// - ///////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////////////////// + //// FILTER INFOS /////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////////////////// - void IGFD::FilterManager::FilterInfos::clear() - { - filter.clear(); - collectionfilters.clear(); - } + void IGFD::FilterManager::FilterInfos::clear() + { + filter.clear(); + collectionfilters.clear(); + } - bool IGFD::FilterManager::FilterInfos::empty() const - { - return filter.empty() && collectionfilters.empty(); - } + bool IGFD::FilterManager::FilterInfos::empty() const + { + return filter.empty() && collectionfilters.empty(); + } - bool IGFD::FilterManager::FilterInfos::exist(const std::string& vFilter) const - { - return filter == vFilter || (collectionfilters.find(vFilter) != collectionfilters.end()); - } + bool IGFD::FilterManager::FilterInfos::exist(const std::string& vFilter) const + { + return filter == vFilter || (collectionfilters.find(vFilter) != collectionfilters.end()); + } - ///////////////////////////////////////////////////////////////////////////////////// - //// FILTER MANAGER ///////////////////////////////////////////////////////////////// - ///////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////////////////// + //// FILTER MANAGER ///////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////////////////// - void IGFD::FilterManager::ParseFilters(const char* vFilters) - { - prParsedFilters.clear(); + void IGFD::FilterManager::ParseFilters(const char* vFilters) + { + prParsedFilters.clear(); - if (vFilters) - puDLGFilters = vFilters; // file mode - else - puDLGFilters.clear(); // directory mode + if (vFilters) + puDLGFilters = vFilters; // file mode + else + puDLGFilters.clear(); // directory mode - if (!puDLGFilters.empty()) - { - // ".*,.cpp,.h,.hpp" - // "Source files{.cpp,.h,.hpp},Image files{.png,.gif,.jpg,.jpeg},.md" + if (!puDLGFilters.empty()) + { + // ".*,.cpp,.h,.hpp" + // "Source files{.cpp,.h,.hpp},Image files{.png,.gif,.jpg,.jpeg},.md" - bool currentFilterFound = false; + bool currentFilterFound = false; - size_t nan = std::string::npos; - size_t p = 0, lp = 0; - while ((p = puDLGFilters.find_first_of("{,", p)) != nan) - { - FilterInfos infos; + size_t nan = std::string::npos; + size_t p = 0, lp = 0; + while ((p = puDLGFilters.find_first_of("{,", p)) != nan) + { + FilterInfos infos; - if (puDLGFilters[p] == '{') // { - { - infos.filter = puDLGFilters.substr(lp, p - lp); - p++; - lp = puDLGFilters.find('}', p); - if (lp != nan) - { - std::string fs = puDLGFilters.substr(p, lp - p); - auto arr = IGFD::Utils::SplitStringToVector(fs, ',', false); - for (auto a : arr) - { - infos.collectionfilters.emplace(a); - } - } - p = lp + 1; - } - else // , - { - infos.filter = puDLGFilters.substr(lp, p - lp); - p++; - } + if (puDLGFilters[p] == '{') // { + { + infos.filter = puDLGFilters.substr(lp, p - lp); + p++; + lp = puDLGFilters.find('}', p); + if (lp != nan) + { + std::string fs = puDLGFilters.substr(p, lp - p); + auto arr = IGFD::Utils::SplitStringToVector(fs, ',', false); + for (auto a : arr) + { + infos.collectionfilters.emplace(a); + } + } + p = lp + 1; + } + else // , + { + infos.filter = puDLGFilters.substr(lp, p - lp); + p++; + } - if (!currentFilterFound && prSelectedFilter.filter == infos.filter) - { - currentFilterFound = true; - prSelectedFilter = infos; - } + if (!currentFilterFound && prSelectedFilter.filter == infos.filter) + { + currentFilterFound = true; + prSelectedFilter = infos; + } - lp = p; - if (!infos.empty()) - prParsedFilters.emplace_back(infos); - } + lp = p; + if (!infos.empty()) + prParsedFilters.emplace_back(infos); + } - std::string token = puDLGFilters.substr(lp); - if (!token.empty()) - { - FilterInfos infos; - infos.filter = std::move(token); - prParsedFilters.emplace_back(infos); - } + std::string token = puDLGFilters.substr(lp); + if (!token.empty()) + { + FilterInfos infos; + infos.filter = std::move(token); + prParsedFilters.emplace_back(infos); + } - if (!currentFilterFound) - if (!prParsedFilters.empty()) - prSelectedFilter = *prParsedFilters.begin(); - } - } + if (!currentFilterFound) + if (!prParsedFilters.empty()) + prSelectedFilter = *prParsedFilters.begin(); + } + } - void IGFD::FilterManager::SetSelectedFilterWithExt(const std::string& vFilter) - { - if (!prParsedFilters.empty()) - { - if (!vFilter.empty()) - { - // std::map - for (const auto& infos : prParsedFilters) - { - if (vFilter == infos.filter) - { - prSelectedFilter = infos; - } - else - { - // maybe this ext is in an extention so we will - // explore the collections is they are existing - for (const auto& filter : infos.collectionfilters) - { - if (vFilter == filter) - { - prSelectedFilter = infos; - } - } - } - } - } + void IGFD::FilterManager::SetSelectedFilterWithExt(const std::string& vFilter) + { + if (!prParsedFilters.empty()) + { + if (!vFilter.empty()) + { + // std::map + for (const auto& infos : prParsedFilters) + { + if (vFilter == infos.filter) + { + prSelectedFilter = infos; + } + else + { + // maybe this ext is in an extention so we will + // explore the collections is they are existing + for (const auto& filter : infos.collectionfilters) + { + if (vFilter == filter) + { + prSelectedFilter = infos; + } + } + } + } + } - if (prSelectedFilter.empty()) - prSelectedFilter = *prParsedFilters.begin(); - } - } + if (prSelectedFilter.empty()) + prSelectedFilter = *prParsedFilters.begin(); + } + } - void IGFD::FilterManager::SetFileStyle(const IGFD_FileStyleFlags& vFlags, const char* vCriteria, const FileStyle& vInfos) - { - std::string _criteria; - if (vCriteria) - _criteria = std::string(vCriteria); - prFilesStyle[vFlags][_criteria] = std::make_shared(vInfos); - prFilesStyle[vFlags][_criteria]->flags = vFlags; - } + void IGFD::FilterManager::SetFileStyle(const IGFD_FileStyleFlags& vFlags, const char* vCriteria, const FileStyle& vInfos) + { + std::string _criteria; + if (vCriteria) + _criteria = std::string(vCriteria); + prFilesStyle[vFlags][_criteria] = std::make_shared(vInfos); + prFilesStyle[vFlags][_criteria]->flags = vFlags; + } - // will be called internally - // will not been exposed to IGFD API - bool IGFD::FilterManager::prFillFileStyle(std::shared_ptr vFileInfos) const - { - if (vFileInfos.use_count() && !prFilesStyle.empty()) - { - for (const auto& _flag : prFilesStyle) - { - for (const auto& _file : _flag.second) - { - if (_flag.first & IGFD_FileStyleByTypeDir && vFileInfos->fileType == 'd') - { - if (_file.first.empty()) // for all dirs - { - vFileInfos->fileStyle = _file.second; - } - else if (_file.first == vFileInfos->fileNameExt) // for dirs who are equal to style criteria - { - vFileInfos->fileStyle = _file.second; - } - } - else if (_flag.first & IGFD_FileStyleByTypeFile && vFileInfos->fileType == 'f') - { - if (_file.first.empty()) // for all files - { - vFileInfos->fileStyle = _file.second; - } - else if (_file.first == vFileInfos->fileNameExt) // for files who are equal to style criteria - { - vFileInfos->fileStyle = _file.second; - } - } - else if (_flag.first & IGFD_FileStyleByTypeLink && vFileInfos->fileType == 'l') - { - if (_file.first.empty()) // for all links - { - vFileInfos->fileStyle = _file.second; - } - else if (_file.first == vFileInfos->fileNameExt) // for links who are equal to style criteria - { - vFileInfos->fileStyle = _file.second; - } - } + // will be called internally + // will not been exposed to IGFD API + bool IGFD::FilterManager::prFillFileStyle(std::shared_ptr vFileInfos) const + { + if (vFileInfos.use_count() && !prFilesStyle.empty()) + { + for (const auto& _flag : prFilesStyle) + { + for (const auto& _file : _flag.second) + { + if (_flag.first & IGFD_FileStyleByTypeDir && vFileInfos->fileType == 'd') + { + if (_file.first.empty()) // for all dirs + { + vFileInfos->fileStyle = _file.second; + } + else if (_file.first == vFileInfos->fileNameExt) // for dirs who are equal to style criteria + { + vFileInfos->fileStyle = _file.second; + } + } + else if (_flag.first & IGFD_FileStyleByTypeFile && vFileInfos->fileType == 'f') + { + if (_file.first.empty()) // for all files + { + vFileInfos->fileStyle = _file.second; + } + else if (_file.first == vFileInfos->fileNameExt) // for files who are equal to style criteria + { + vFileInfos->fileStyle = _file.second; + } + } + else if (_flag.first & IGFD_FileStyleByTypeLink && vFileInfos->fileType == 'l') + { + if (_file.first.empty()) // for all links + { + vFileInfos->fileStyle = _file.second; + } + else if (_file.first == vFileInfos->fileNameExt) // for links who are equal to style criteria + { + vFileInfos->fileStyle = _file.second; + } + } - if (_flag.first & IGFD_FileStyleByExtention) - { - if (_file.first == vFileInfos->fileExt) - { - vFileInfos->fileStyle = _file.second; - } + if (_flag.first & IGFD_FileStyleByExtention) + { + if (_file.first == vFileInfos->fileExt) + { + vFileInfos->fileStyle = _file.second; + } - // can make sense for some dirs like the hidden by ex ".git" - if (_flag.first & IGFD_FileStyleByTypeDir && vFileInfos->fileType == 'd') - { - if (_file.first == vFileInfos->fileExt) - { - vFileInfos->fileStyle = _file.second; - } - } - else if (_flag.first & IGFD_FileStyleByTypeFile && vFileInfos->fileType == 'f') - { - if (_file.first == vFileInfos->fileExt) - { - vFileInfos->fileStyle = _file.second; - } - } - else if (_flag.first & IGFD_FileStyleByTypeLink && vFileInfos->fileType == 'l') - { - if (_file.first == vFileInfos->fileExt) - { - vFileInfos->fileStyle = _file.second; - } - } - } - if (_flag.first & IGFD_FileStyleByFullName) - { - if (_file.first == vFileInfos->fileNameExt) - { - vFileInfos->fileStyle = _file.second; - } + // can make sense for some dirs like the hidden by ex ".git" + if (_flag.first & IGFD_FileStyleByTypeDir && vFileInfos->fileType == 'd') + { + if (_file.first == vFileInfos->fileExt) + { + vFileInfos->fileStyle = _file.second; + } + } + else if (_flag.first & IGFD_FileStyleByTypeFile && vFileInfos->fileType == 'f') + { + if (_file.first == vFileInfos->fileExt) + { + vFileInfos->fileStyle = _file.second; + } + } + else if (_flag.first & IGFD_FileStyleByTypeLink && vFileInfos->fileType == 'l') + { + if (_file.first == vFileInfos->fileExt) + { + vFileInfos->fileStyle = _file.second; + } + } + } + if (_flag.first & IGFD_FileStyleByFullName) + { + if (_file.first == vFileInfos->fileNameExt) + { + vFileInfos->fileStyle = _file.second; + } - if (_flag.first & IGFD_FileStyleByTypeDir && vFileInfos->fileType == 'd') - { - if (_file.first == vFileInfos->fileNameExt) - { - vFileInfos->fileStyle = _file.second; - } - } - else if (_flag.first & IGFD_FileStyleByTypeFile && vFileInfos->fileType == 'f') - { - if (_file.first == vFileInfos->fileNameExt) - { - vFileInfos->fileStyle = _file.second; - } - } - else if (_flag.first & IGFD_FileStyleByTypeLink && vFileInfos->fileType == 'l') - { - if (_file.first == vFileInfos->fileNameExt) - { - vFileInfos->fileStyle = _file.second; - } - } - } - if (_flag.first & IGFD_FileStyleByContainedInFullName) - { - if (vFileInfos->fileNameExt.find(_file.first) != std::string::npos) - { - vFileInfos->fileStyle = _file.second; - } + if (_flag.first & IGFD_FileStyleByTypeDir && vFileInfos->fileType == 'd') + { + if (_file.first == vFileInfos->fileNameExt) + { + vFileInfos->fileStyle = _file.second; + } + } + else if (_flag.first & IGFD_FileStyleByTypeFile && vFileInfos->fileType == 'f') + { + if (_file.first == vFileInfos->fileNameExt) + { + vFileInfos->fileStyle = _file.second; + } + } + else if (_flag.first & IGFD_FileStyleByTypeLink && vFileInfos->fileType == 'l') + { + if (_file.first == vFileInfos->fileNameExt) + { + vFileInfos->fileStyle = _file.second; + } + } + } + if (_flag.first & IGFD_FileStyleByContainedInFullName) + { + if (vFileInfos->fileNameExt.find(_file.first) != std::string::npos) + { + vFileInfos->fileStyle = _file.second; + } - if (_flag.first & IGFD_FileStyleByTypeDir && vFileInfos->fileType == 'd') - { - if (vFileInfos->fileNameExt.find(_file.first) != std::string::npos) - { - vFileInfos->fileStyle = _file.second; - } - } - else if (_flag.first & IGFD_FileStyleByTypeFile && vFileInfos->fileType == 'f') - { - if (vFileInfos->fileNameExt.find(_file.first) != std::string::npos) - { - vFileInfos->fileStyle = _file.second; - } - } - else if (_flag.first & IGFD_FileStyleByTypeLink && vFileInfos->fileType == 'l') - { - if (vFileInfos->fileNameExt.find(_file.first) != std::string::npos) - { - vFileInfos->fileStyle = _file.second; - } - } - } + if (_flag.first & IGFD_FileStyleByTypeDir && vFileInfos->fileType == 'd') + { + if (vFileInfos->fileNameExt.find(_file.first) != std::string::npos) + { + vFileInfos->fileStyle = _file.second; + } + } + else if (_flag.first & IGFD_FileStyleByTypeFile && vFileInfos->fileType == 'f') + { + if (vFileInfos->fileNameExt.find(_file.first) != std::string::npos) + { + vFileInfos->fileStyle = _file.second; + } + } + else if (_flag.first & IGFD_FileStyleByTypeLink && vFileInfos->fileType == 'l') + { + if (vFileInfos->fileNameExt.find(_file.first) != std::string::npos) + { + vFileInfos->fileStyle = _file.second; + } + } + } - if (vFileInfos->fileStyle.use_count()) - return true; - } - } - } + if (vFileInfos->fileStyle.use_count()) + return true; + } + } + } - return false; - } + return false; + } - void IGFD::FilterManager::SetFileStyle(const IGFD_FileStyleFlags& vFlags, const char* vCriteria, const ImVec4& vColor, const std::string& vIcon, ImFont* vFont) - { - std::string _criteria; - if (vCriteria) - _criteria = std::string(vCriteria); - prFilesStyle[vFlags][_criteria] = std::make_shared(vColor, vIcon, vFont); - prFilesStyle[vFlags][_criteria]->flags = vFlags; - } + void IGFD::FilterManager::SetFileStyle(const IGFD_FileStyleFlags& vFlags, const char* vCriteria, const ImVec4& vColor, const std::string& vIcon, ImFont* vFont) + { + std::string _criteria; + if (vCriteria) + _criteria = std::string(vCriteria); + prFilesStyle[vFlags][_criteria] = std::make_shared(vColor, vIcon, vFont); + prFilesStyle[vFlags][_criteria]->flags = vFlags; + } - // todo : to refactor this fucking function - bool IGFD::FilterManager::GetFileStyle(const IGFD_FileStyleFlags& vFlags, const std::string& vCriteria, ImVec4* vOutColor, std::string* vOutIcon, ImFont **vOutFont) - { - if (vOutColor) - { - if (!prFilesStyle.empty()) - { - if (prFilesStyle.find(vFlags) != prFilesStyle.end()) // found - { - if (vFlags & IGFD_FileStyleByContainedInFullName) - { - // search for vCriteria who are containing the criteria - for (const auto& _file : prFilesStyle.at(vFlags)) - { - if (vCriteria.find(_file.first) != std::string::npos) - { - if (_file.second.use_count()) - { - *vOutColor = _file.second->color; - if (vOutIcon) - *vOutIcon = _file.second->icon; - if (vOutFont) - *vOutFont = _file.second->font; - return true; - } - } - } - } - else - { - if (prFilesStyle.at(vFlags).find(vCriteria) != prFilesStyle.at(vFlags).end()) // found - { - *vOutColor = prFilesStyle[vFlags][vCriteria]->color; - if (vOutIcon) - *vOutIcon = prFilesStyle[vFlags][vCriteria]->icon; - if (vOutFont) - *vOutFont = prFilesStyle[vFlags][vCriteria]->font; - return true; - } - } - } - else - { - // search for flag composition - for (const auto& _flag : prFilesStyle) - { - if (_flag.first & vFlags) - { - if (_flag.first & IGFD_FileStyleByContainedInFullName) - { - // search for vCriteria who are containing the criteria - for (const auto& _file : prFilesStyle.at(_flag.first)) - { - if (vCriteria.find(_file.first) != std::string::npos) - { - if (_file.second.use_count()) - { - *vOutColor = _file.second->color; - if (vOutIcon) - *vOutIcon = _file.second->icon; - if (vOutFont) - *vOutFont = _file.second->font; - return true; - } - } - } - } - else - { - if (prFilesStyle.at(_flag.first).find(vCriteria) != prFilesStyle.at(_flag.first).end()) // found - { - *vOutColor = prFilesStyle[_flag.first][vCriteria]->color; - if (vOutIcon) - *vOutIcon = prFilesStyle[_flag.first][vCriteria]->icon; - if (vOutFont) - *vOutFont = prFilesStyle[_flag.first][vCriteria]->font; - return true; - } - } - } - } - } - } - } - return false; - } + // todo : to refactor this fucking function + bool IGFD::FilterManager::GetFileStyle(const IGFD_FileStyleFlags& vFlags, const std::string& vCriteria, ImVec4* vOutColor, std::string* vOutIcon, ImFont **vOutFont) + { + if (vOutColor) + { + if (!prFilesStyle.empty()) + { + if (prFilesStyle.find(vFlags) != prFilesStyle.end()) // found + { + if (vFlags & IGFD_FileStyleByContainedInFullName) + { + // search for vCriteria who are containing the criteria + for (const auto& _file : prFilesStyle.at(vFlags)) + { + if (vCriteria.find(_file.first) != std::string::npos) + { + if (_file.second.use_count()) + { + *vOutColor = _file.second->color; + if (vOutIcon) + *vOutIcon = _file.second->icon; + if (vOutFont) + *vOutFont = _file.second->font; + return true; + } + } + } + } + else + { + if (prFilesStyle.at(vFlags).find(vCriteria) != prFilesStyle.at(vFlags).end()) // found + { + *vOutColor = prFilesStyle[vFlags][vCriteria]->color; + if (vOutIcon) + *vOutIcon = prFilesStyle[vFlags][vCriteria]->icon; + if (vOutFont) + *vOutFont = prFilesStyle[vFlags][vCriteria]->font; + return true; + } + } + } + else + { + // search for flag composition + for (const auto& _flag : prFilesStyle) + { + if (_flag.first & vFlags) + { + if (_flag.first & IGFD_FileStyleByContainedInFullName) + { + // search for vCriteria who are containing the criteria + for (const auto& _file : prFilesStyle.at(_flag.first)) + { + if (vCriteria.find(_file.first) != std::string::npos) + { + if (_file.second.use_count()) + { + *vOutColor = _file.second->color; + if (vOutIcon) + *vOutIcon = _file.second->icon; + if (vOutFont) + *vOutFont = _file.second->font; + return true; + } + } + } + } + else + { + if (prFilesStyle.at(_flag.first).find(vCriteria) != prFilesStyle.at(_flag.first).end()) // found + { + *vOutColor = prFilesStyle[_flag.first][vCriteria]->color; + if (vOutIcon) + *vOutIcon = prFilesStyle[_flag.first][vCriteria]->icon; + if (vOutFont) + *vOutFont = prFilesStyle[_flag.first][vCriteria]->font; + return true; + } + } + } + } + } + } + } + return false; + } - void IGFD::FilterManager::ClearFilesStyle() - { - prFilesStyle.clear(); - } - - bool IGFD::FilterManager::IsCoveredByFilters(const std::string& vTag) const - { - if (!puDLGFilters.empty() && !prSelectedFilter.empty()) - { - // check if current file extention is covered by current filter - // we do that here, for avoid doing that during filelist display - // for better fps - if (prSelectedFilter.exist(vTag) || prSelectedFilter.filter == ".*") - { - return true; - } - } + void IGFD::FilterManager::ClearFilesStyle() + { + prFilesStyle.clear(); + } + + bool IGFD::FilterManager::IsCoveredByFilters(const std::string& vTag) const + { + if (!puDLGFilters.empty() && !prSelectedFilter.empty()) + { + // check if current file extention is covered by current filter + // we do that here, for avoid doing that during filelist display + // for better fps + if (prSelectedFilter.exist(vTag) || prSelectedFilter.filter == ".*") + { + return true; + } + } - return false; - } + return false; + } - bool IGFD::FilterManager::DrawFilterComboBox(FileDialogInternal& vFileDialogInternal) - { - // combobox of filters - if (!puDLGFilters.empty()) - { - ImGui::SameLine(); + bool IGFD::FilterManager::DrawFilterComboBox(FileDialogInternal& vFileDialogInternal) + { + // combobox of filters + if (!puDLGFilters.empty()) + { + ImGui::SameLine(); - bool needToApllyNewFilter = false; + bool needToApllyNewFilter = false; - ImGui::PushItemWidth(FILTER_COMBO_WIDTH*FileDialog::Instance()->DpiScale); - if (ImGui::BeginCombo("##Filters", prSelectedFilter.filter.c_str(), ImGuiComboFlags_None)) - { - intptr_t i = 0; - for (const auto& filter : prParsedFilters) - { - const bool item_selected = (filter.filter == prSelectedFilter.filter); - ImGui::PushID((void*)(intptr_t)i++); - if (ImGui::Selectable(filter.filter.c_str(), item_selected)) - { - prSelectedFilter = filter; - needToApllyNewFilter = true; - } - ImGui::PopID(); - } + ImGui::PushItemWidth(FILTER_COMBO_WIDTH*FileDialog::Instance()->DpiScale); + if (ImGui::BeginCombo("##Filters", prSelectedFilter.filter.c_str(), ImGuiComboFlags_None)) + { + intptr_t i = 0; + for (const auto& filter : prParsedFilters) + { + const bool item_selected = (filter.filter == prSelectedFilter.filter); + ImGui::PushID((void*)(intptr_t)i++); + if (ImGui::Selectable(filter.filter.c_str(), item_selected)) + { + prSelectedFilter = filter; + needToApllyNewFilter = true; + } + ImGui::PopID(); + } - ImGui::EndCombo(); - } - ImGui::PopItemWidth(); + ImGui::EndCombo(); + } + ImGui::PopItemWidth(); - if (needToApllyNewFilter) - { - vFileDialogInternal.puFileManager.OpenCurrentPath(vFileDialogInternal); - } + if (needToApllyNewFilter) + { + vFileDialogInternal.puFileManager.OpenCurrentPath(vFileDialogInternal); + } - return needToApllyNewFilter; - } + return needToApllyNewFilter; + } - return false; - } + return false; + } - IGFD::FilterManager::FilterInfos IGFD::FilterManager::GetSelectedFilter() - { - return prSelectedFilter; - } + IGFD::FilterManager::FilterInfos IGFD::FilterManager::GetSelectedFilter() + { + return prSelectedFilter; + } - std::string IGFD::FilterManager::ReplaceExtentionWithCurrentFilter(const std::string& vFile) const - { - auto result = vFile; + std::string IGFD::FilterManager::ReplaceExtentionWithCurrentFilter(const std::string& vFile) const + { + auto result = vFile; - if (!result.empty()) - { - // if not a collection we can replace the filter by the extention we want - if (prSelectedFilter.collectionfilters.empty()) - { - size_t lastPoint = vFile.find_last_of('.'); - if (lastPoint != std::string::npos) - { - result = result.substr(0, lastPoint); - } + if (!result.empty()) + { + // if not a collection we can replace the filter by the extention we want + if (prSelectedFilter.collectionfilters.empty()) + { + size_t lastPoint = vFile.find_last_of('.'); + if (lastPoint != std::string::npos) + { + result = result.substr(0, lastPoint); + } - result += prSelectedFilter.filter; - } - } + result += prSelectedFilter.filter; + } + } - return result; - } - - void IGFD::FilterManager::SetDefaultFilterIfNotDefined() - { - if (prSelectedFilter.empty() && // no filter selected - !prParsedFilters.empty()) // filter exist - prSelectedFilter = *prParsedFilters.begin(); // we take the first filter - } + return result; + } + + void IGFD::FilterManager::SetDefaultFilterIfNotDefined() + { + if (prSelectedFilter.empty() && // no filter selected + !prParsedFilters.empty()) // filter exist + prSelectedFilter = *prParsedFilters.begin(); // we take the first filter + } - ///////////////////////////////////////////////////////////////////////////////////// - //// FILE MANAGER /////////////////////////////////////////////////////////////////// - ///////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////////////////// + //// FILE MANAGER /////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////////////////// - IGFD::FileManager::FileManager() - { - puFsRoot = std::string(1u, PATH_SEP); - puSortingDirection[0]=false; - puSortingDirection[1]=false; - puSortingDirection[2]=false; - puSortingDirection[3]=false; - } + IGFD::FileManager::FileManager() + { + puFsRoot = std::string(1u, PATH_SEP); + puSortingDirection[0]=true; + for (int i=1; i<4; i++) { + puSortingDirection[i]=false; + } + } - void IGFD::FileManager::OpenCurrentPath(const FileDialogInternal& vFileDialogInternal) - { - puShowDrives = false; - ClearComposer(); - ClearFileLists(); - if (puDLGDirectoryMode) // directory mode - SetDefaultFileName("."); - else - SetDefaultFileName(""); + void IGFD::FileManager::OpenCurrentPath(const FileDialogInternal& vFileDialogInternal) + { + puShowDrives = false; + ClearComposer(); + ClearFileLists(); + if (puDLGDirectoryMode) // directory mode + SetDefaultFileName("."); + else + SetDefaultFileName(""); logV("IGFD: OpenCurrentPath()"); - ScanDir(vFileDialogInternal, GetCurrentPath()); - } + ScanDir(vFileDialogInternal, GetCurrentPath()); + } - void IGFD::FileManager::SortFields(const FileDialogInternal& vFileDialogInternal, const SortingFieldEnum& vSortingField, const bool vCanChangeOrder) - { + void IGFD::FileManager::SortFields(const FileDialogInternal& vFileDialogInternal, const SortingFieldEnum& vSortingField, const bool vCanChangeOrder) + { logV("IGFD: SortFields()"); - if (vSortingField != SortingFieldEnum::FIELD_NONE) - { - puHeaderFileName = tableHeaderFileNameString; - puHeaderFileType = tableHeaderFileTypeString; - puHeaderFileSize = tableHeaderFileSizeString; - puHeaderFileDate = tableHeaderFileDateString; + if (vSortingField != SortingFieldEnum::FIELD_NONE) + { + puHeaderFileName = tableHeaderFileNameString; + puHeaderFileType = tableHeaderFileTypeString; + puHeaderFileSize = tableHeaderFileSizeString; + puHeaderFileDate = tableHeaderFileDateString; #ifdef USE_THUMBNAILS - puHeaderFileThumbnails = tableHeaderFileThumbnailsString; + puHeaderFileThumbnails = tableHeaderFileThumbnailsString; #endif // #ifdef USE_THUMBNAILS - } else { + } else { logV("IGFD: sorting by NONE!"); } @@ -1227,2822 +1177,2825 @@ namespace IGFD logV("IGFD: with an empty file list?"); } - if (vSortingField == SortingFieldEnum::FIELD_FILENAME) - { + if (vSortingField == SortingFieldEnum::FIELD_FILENAME) + { logV("IGFD: sorting by name"); - if (vCanChangeOrder && puSortingField == vSortingField) { + if (vCanChangeOrder && puSortingField == vSortingField) { //printf("Change the sorting\n"); - puSortingDirection[0] = true;//!puSortingDirection[0]; + puSortingDirection[0] = !puSortingDirection[0]; } - if (puSortingDirection[0]) - { + if (puSortingDirection[0]) + { #ifdef USE_CUSTOM_SORTING_ICON - puHeaderFileName = tableHeaderDescendingIcon + puHeaderFileName; + puHeaderFileName = tableHeaderDescendingIcon + puHeaderFileName; #endif // USE_CUSTOM_SORTING_ICON - std::sort(prFileList.begin(), prFileList.end(), - [](const std::shared_ptr& a, const std::shared_ptr& b) -> bool - { + std::sort(prFileList.begin(), prFileList.end(), + [](const std::shared_ptr& a, const std::shared_ptr& b) -> bool + { if (a==NULL || b==NULL) return false; - if (!a.use_count() || !b.use_count()) - return false; + if (!a.use_count() || !b.use_count()) + return false; - // this code fail in c:\\Users with the link "All users". got a invalid comparator - /* - // use code from https://github.com/jackm97/ImGuiFileDialog/commit/bf40515f5a1de3043e60562dc1a494ee7ecd3571 - // strict ordering for file/directory types beginning in '.' - // common on Linux platforms - if (a->fileNameExt[0] == '.' && b->fileNameExt[0] != '.') - return false; - if (a->fileNameExt[0] != '.' && b->fileNameExt[0] == '.') - return true; - if (a->fileNameExt[0] == '.' && b->fileNameExt[0] == '.') - { - return (stricmp(a->fileNameExt.c_str(), b->fileNameExt.c_str()) < 0); // sort in insensitive case - } - */ - if (a->fileType != b->fileType) return (a->fileType == 'd'); // directory in first - return (stricmp(a->fileNameExt.c_str(), b->fileNameExt.c_str()) < 0); // sort in insensitive case - }); - } - else - { + // this code fail in c:\\Users with the link "All users". got a invalid comparator + /* + // use code from https://github.com/jackm97/ImGuiFileDialog/commit/bf40515f5a1de3043e60562dc1a494ee7ecd3571 + // strict ordering for file/directory types beginning in '.' + // common on Linux platforms + if (a->fileNameExt[0] == '.' && b->fileNameExt[0] != '.') + return false; + if (a->fileNameExt[0] != '.' && b->fileNameExt[0] == '.') + return true; + if (a->fileNameExt[0] == '.' && b->fileNameExt[0] == '.') + { + return (stricmp(a->fileNameExt.c_str(), b->fileNameExt.c_str()) < 0); // sort in insensitive case + } + */ + if (a->fileType != b->fileType) return (a->fileType == 'd'); // directory in first + return (stricmp(a->fileNameExt.c_str(), b->fileNameExt.c_str()) < 0); // sort in insensitive case + }); + } + else + { #ifdef USE_CUSTOM_SORTING_ICON - puHeaderFileName = tableHeaderAscendingIcon + puHeaderFileName; + puHeaderFileName = tableHeaderAscendingIcon + puHeaderFileName; #endif // USE_CUSTOM_SORTING_ICON - std::sort(prFileList.begin(), prFileList.end(), - [](const std::shared_ptr& a, const std::shared_ptr& b) -> bool - { + std::sort(prFileList.begin(), prFileList.end(), + [](const std::shared_ptr& a, const std::shared_ptr& b) -> bool + { if (a==NULL || b==NULL) return false; - if (!a.use_count() || !b.use_count()) - return false; + if (!a.use_count() || !b.use_count()) + return false; - // this code fail in c:\\Users with the link "All users". got a invalid comparator - /* - // use code from https://github.com/jackm97/ImGuiFileDialog/commit/bf40515f5a1de3043e60562dc1a494ee7ecd3571 - // strict ordering for file/directory types beginning in '.' - // common on Linux platforms - if (a->fileNameExt[0] == '.' && b->fileNameExt[0] != '.') - return false; - if (a->fileNameExt[0] != '.' && b->fileNameExt[0] == '.') - return true; - if (a->fileNameExt[0] == '.' && b->fileNameExt[0] == '.') - { - return (stricmp(a->fileNameExt.c_str(), b->fileNameExt.c_str()) > 0); // sort in insensitive case - } - */ - return (stricmp(a->fileNameExt.c_str(), b->fileNameExt.c_str()) > 0); // sort in insensitive case - }); - } - } - else if (vSortingField == SortingFieldEnum::FIELD_TYPE) - { + // this code fail in c:\\Users with the link "All users". got a invalid comparator + /* + // use code from https://github.com/jackm97/ImGuiFileDialog/commit/bf40515f5a1de3043e60562dc1a494ee7ecd3571 + // strict ordering for file/directory types beginning in '.' + // common on Linux platforms + if (a->fileNameExt[0] == '.' && b->fileNameExt[0] != '.') + return false; + if (a->fileNameExt[0] != '.' && b->fileNameExt[0] == '.') + return true; + if (a->fileNameExt[0] == '.' && b->fileNameExt[0] == '.') + { + return (stricmp(a->fileNameExt.c_str(), b->fileNameExt.c_str()) > 0); // sort in insensitive case + } + */ + return (stricmp(a->fileNameExt.c_str(), b->fileNameExt.c_str()) > 0); // sort in insensitive case + }); + } + } + else if (vSortingField == SortingFieldEnum::FIELD_TYPE) + { logV("IGFD: sorting by type"); - if (vCanChangeOrder && puSortingField == vSortingField) - puSortingDirection[1] = !puSortingDirection[1]; + if (vCanChangeOrder && puSortingField == vSortingField) + puSortingDirection[1] = !puSortingDirection[1]; - if (puSortingDirection[1]) - { + if (puSortingDirection[1]) + { #ifdef USE_CUSTOM_SORTING_ICON - puHeaderFileType = tableHeaderDescendingIcon + puHeaderFileType; + puHeaderFileType = tableHeaderDescendingIcon + puHeaderFileType; #endif // USE_CUSTOM_SORTING_ICON - std::sort(prFileList.begin(), prFileList.end(), - [](const std::shared_ptr& a, const std::shared_ptr& b) -> bool - { - if (!a.use_count() || !b.use_count()) - return false; + std::sort(prFileList.begin(), prFileList.end(), + [](const std::shared_ptr& a, const std::shared_ptr& b) -> bool + { + if (!a.use_count() || !b.use_count()) + return false; - if (a->fileType != b->fileType) return (a->fileType == 'd'); // directory in first - return (a->fileExt < b->fileExt); // else - }); - } - else - { + if (a->fileType != b->fileType) return (a->fileType == 'd'); // directory in first + return (a->fileExt < b->fileExt); // else + }); + } + else + { #ifdef USE_CUSTOM_SORTING_ICON - puHeaderFileType = tableHeaderAscendingIcon + puHeaderFileType; + puHeaderFileType = tableHeaderAscendingIcon + puHeaderFileType; #endif // USE_CUSTOM_SORTING_ICON - std::sort(prFileList.begin(), prFileList.end(), - [](const std::shared_ptr& a, const std::shared_ptr& b) -> bool - { + std::sort(prFileList.begin(), prFileList.end(), + [](const std::shared_ptr& a, const std::shared_ptr& b) -> bool + { if (a==NULL || b==NULL) return false; - if (!a.use_count() || !b.use_count()) - return false; + if (!a.use_count() || !b.use_count()) + return false; - if (a->fileType != b->fileType) return (a->fileType != 'd'); // directory in last - return (a->fileExt > b->fileExt); // else - }); - } - } - else if (vSortingField == SortingFieldEnum::FIELD_SIZE) - { + if (a->fileType != b->fileType) return (a->fileType != 'd'); // directory in last + return (a->fileExt > b->fileExt); // else + }); + } + } + else if (vSortingField == SortingFieldEnum::FIELD_SIZE) + { logV("IGFD: sorting by size"); - if (vCanChangeOrder && puSortingField == vSortingField) - puSortingDirection[2] = !puSortingDirection[2]; + if (vCanChangeOrder && puSortingField == vSortingField) + puSortingDirection[2] = !puSortingDirection[2]; - if (puSortingDirection[2]) - { + if (puSortingDirection[2]) + { #ifdef USE_CUSTOM_SORTING_ICON - puHeaderFileSize = tableHeaderDescendingIcon + puHeaderFileSize; + puHeaderFileSize = tableHeaderDescendingIcon + puHeaderFileSize; #endif // USE_CUSTOM_SORTING_ICON - std::sort(prFileList.begin(), prFileList.end(), - [](const std::shared_ptr& a, const std::shared_ptr& b) -> bool - { + std::sort(prFileList.begin(), prFileList.end(), + [](const std::shared_ptr& a, const std::shared_ptr& b) -> bool + { if (a==NULL || b==NULL) return false; - if (!a.use_count() || !b.use_count()) - return false; + if (!a.use_count() || !b.use_count()) + return false; - if (a->fileType != b->fileType) return (a->fileType == 'd'); // directory in first - return (a->fileSize < b->fileSize); // else - }); - } - else - { + if (a->fileType != b->fileType) return (a->fileType == 'd'); // directory in first + return (a->fileSize < b->fileSize); // else + }); + } + else + { #ifdef USE_CUSTOM_SORTING_ICON - puHeaderFileSize = tableHeaderAscendingIcon + puHeaderFileSize; + puHeaderFileSize = tableHeaderAscendingIcon + puHeaderFileSize; #endif // USE_CUSTOM_SORTING_ICON - std::sort(prFileList.begin(), prFileList.end(), - [](const std::shared_ptr& a, const std::shared_ptr& b) -> bool - { + std::sort(prFileList.begin(), prFileList.end(), + [](const std::shared_ptr& a, const std::shared_ptr& b) -> bool + { if (a==NULL || b==NULL) return false; - if (!a.use_count() || !b.use_count()) - return false; + if (!a.use_count() || !b.use_count()) + return false; - if (a->fileType != b->fileType) return (a->fileType != 'd'); // directory in last - return (a->fileSize > b->fileSize); // else - }); - } - } - else if (vSortingField == SortingFieldEnum::FIELD_DATE) - { + if (a->fileType != b->fileType) return (a->fileType != 'd'); // directory in last + return (a->fileSize > b->fileSize); // else + }); + } + } + else if (vSortingField == SortingFieldEnum::FIELD_DATE) + { logV("IGFD: sorting by date"); - if (vCanChangeOrder && puSortingField == vSortingField) - puSortingDirection[3] = !puSortingDirection[3]; + if (vCanChangeOrder && puSortingField == vSortingField) + puSortingDirection[3] = !puSortingDirection[3]; - if (puSortingDirection[3]) - { + if (puSortingDirection[3]) + { #ifdef USE_CUSTOM_SORTING_ICON - puHeaderFileDate = tableHeaderDescendingIcon + puHeaderFileDate; + puHeaderFileDate = tableHeaderDescendingIcon + puHeaderFileDate; #endif // USE_CUSTOM_SORTING_ICON - std::sort(prFileList.begin(), prFileList.end(), - [](const std::shared_ptr& a, const std::shared_ptr& b) -> bool - { + std::sort(prFileList.begin(), prFileList.end(), + [](const std::shared_ptr& a, const std::shared_ptr& b) -> bool + { if (a==NULL || b==NULL) return false; - if (!a.use_count() || !b.use_count()) - return false; + if (!a.use_count() || !b.use_count()) + return false; - if (a->fileType != b->fileType) return (a->fileType == 'd'); // directory in first - return (a->fileModifDate < b->fileModifDate); // else - }); - } - else - { + if (a->fileType != b->fileType) return (a->fileType == 'd'); // directory in first + return (a->fileModifDate < b->fileModifDate); // else + }); + } + else + { #ifdef USE_CUSTOM_SORTING_ICON - puHeaderFileDate = tableHeaderAscendingIcon + puHeaderFileDate; + puHeaderFileDate = tableHeaderAscendingIcon + puHeaderFileDate; #endif // USE_CUSTOM_SORTING_ICON - std::sort(prFileList.begin(), prFileList.end(), - [](const std::shared_ptr& a, const std::shared_ptr& b) -> bool - { + std::sort(prFileList.begin(), prFileList.end(), + [](const std::shared_ptr& a, const std::shared_ptr& b) -> bool + { if (a==NULL || b==NULL) return false; - if (!a.use_count() || !b.use_count()) - return false; + if (!a.use_count() || !b.use_count()) + return false; - if (a->fileType != b->fileType) return (a->fileType != 'd'); // directory in last - return (a->fileModifDate > b->fileModifDate); // else - }); - } - } + if (a->fileType != b->fileType) return (a->fileType != 'd'); // directory in last + return (a->fileModifDate > b->fileModifDate); // else + }); + } + } #ifdef USE_THUMBNAILS - else if (vSortingField == SortingFieldEnum::FIELD_THUMBNAILS) - { - if (vCanChangeOrder && puSortingField == vSortingField) - puSortingDirection[4] = !puSortingDirection[4]; + else if (vSortingField == SortingFieldEnum::FIELD_THUMBNAILS) + { + if (vCanChangeOrder && puSortingField == vSortingField) + puSortingDirection[4] = !puSortingDirection[4]; - // we will compare thumbnails by : - // 1) width - // 2) height + // we will compare thumbnails by : + // 1) width + // 2) height - if (puSortingDirection[4]) - { + if (puSortingDirection[4]) + { #ifdef USE_CUSTOM_SORTING_ICON - puHeaderFileThumbnails = tableHeaderDescendingIcon + puHeaderFileThumbnails; + puHeaderFileThumbnails = tableHeaderDescendingIcon + puHeaderFileThumbnails; #endif // USE_CUSTOM_SORTING_ICON - std::sort(prFileList.begin(), prFileList.end(), - [](const std::shared_ptr& a, const std::shared_ptr& b) -> bool - { - if (!a.use_count() || !b.use_count()) - return false; + std::sort(prFileList.begin(), prFileList.end(), + [](const std::shared_ptr& a, const std::shared_ptr& b) -> bool + { + if (!a.use_count() || !b.use_count()) + return false; - if (a->fileType != b->fileType) return (a->fileType == 'd'); // directory in first - if (a->thumbnailInfo.textureWidth == b->thumbnailInfo.textureWidth) - return (a->thumbnailInfo.textureHeight < b->thumbnailInfo.textureHeight); - return (a->thumbnailInfo.textureWidth < b->thumbnailInfo.textureWidth); - }); - } + if (a->fileType != b->fileType) return (a->fileType == 'd'); // directory in first + if (a->thumbnailInfo.textureWidth == b->thumbnailInfo.textureWidth) + return (a->thumbnailInfo.textureHeight < b->thumbnailInfo.textureHeight); + return (a->thumbnailInfo.textureWidth < b->thumbnailInfo.textureWidth); + }); + } - else - { + else + { #ifdef USE_CUSTOM_SORTING_ICON - puHeaderFileThumbnails = tableHeaderAscendingIcon + puHeaderFileThumbnails; + puHeaderFileThumbnails = tableHeaderAscendingIcon + puHeaderFileThumbnails; #endif // USE_CUSTOM_SORTING_ICON - std::sort(prFileList.begin(), prFileList.end(), - [](const std::shared_ptr& a, const std::shared_ptr& b) -> bool - { - if (!a.use_count() || !b.use_count()) - return false; + std::sort(prFileList.begin(), prFileList.end(), + [](const std::shared_ptr& a, const std::shared_ptr& b) -> bool + { + if (!a.use_count() || !b.use_count()) + return false; - if (a->fileType != b->fileType) return (a->fileType != 'd'); // directory in last - if (a->thumbnailInfo.textureWidth == b->thumbnailInfo.textureWidth) - return (a->thumbnailInfo.textureHeight > b->thumbnailInfo.textureHeight); - return (a->thumbnailInfo.textureWidth > b->thumbnailInfo.textureWidth); - }); - } - } + if (a->fileType != b->fileType) return (a->fileType != 'd'); // directory in last + if (a->thumbnailInfo.textureWidth == b->thumbnailInfo.textureWidth) + return (a->thumbnailInfo.textureHeight > b->thumbnailInfo.textureHeight); + return (a->thumbnailInfo.textureWidth > b->thumbnailInfo.textureWidth); + }); + } + } #endif // USE_THUMBNAILS - if (vSortingField != SortingFieldEnum::FIELD_NONE) - { - puSortingField = vSortingField; - } + if (vSortingField != SortingFieldEnum::FIELD_NONE) + { + puSortingField = vSortingField; + } logV("IGFD: applying filtering on file list"); - ApplyFilteringOnFileList(vFileDialogInternal); - } + ApplyFilteringOnFileList(vFileDialogInternal); + } - void IGFD::FileManager::ClearFileLists() - { - prFilteredFileList.clear(); - prFileList.clear(); - } + void IGFD::FileManager::ClearFileLists() + { + prFilteredFileList.clear(); + prFileList.clear(); + } - std::string IGFD::FileManager::prOptimizeFilenameForSearchOperations(const std::string& vFileNameExt) - { - auto fileNameExt = vFileNameExt; - // convert to lower case - for (char& c : fileNameExt) - c = (char)std::tolower(c); - return fileNameExt; - } + std::string IGFD::FileManager::prOptimizeFilenameForSearchOperations(const std::string& vFileNameExt) + { + auto fileNameExt = vFileNameExt; + // convert to lower case + for (char& c : fileNameExt) + c = (char)std::tolower(c); + return fileNameExt; + } - void IGFD::FileManager::AddFile(const FileDialogInternal& vFileDialogInternal, const std::string& vPath, const std::string& vFileName, const char& vFileType) - { - auto infos = std::make_shared(); + void IGFD::FileManager::AddFile(const FileDialogInternal& vFileDialogInternal, const std::string& vPath, const std::string& vFileName, const char& vFileType, void* ent) + { + auto infos = std::make_shared(); - infos->filePath = vPath; - infos->fileNameExt = vFileName; - infos->fileNameExt_optimized = prOptimizeFilenameForSearchOperations(infos->fileNameExt); - infos->fileType = vFileType; +#ifdef _WIN32 + struct dirent* dent=(struct dirent*)ent; +#endif - if (infos->fileNameExt.empty() || ((infos->fileNameExt == "." || infos->fileNameExt == "..") && !vFileDialogInternal.puFilterManager.puDLGFilters.empty())) return; // filename empty or filename is the current dir '.' //-V807 - if (infos->fileNameExt != ".." && (vFileDialogInternal.puDLGflags & ImGuiFileDialogFlags_DontShowHiddenFiles) && infos->fileNameExt[0] == '.') // dont show hidden files - if (!vFileDialogInternal.puFilterManager.puDLGFilters.empty() || (vFileDialogInternal.puFilterManager.puDLGFilters.empty() && infos->fileNameExt != ".")) // except "." if in directory mode //-V728 - return; + infos->filePath = vPath; + infos->fileNameExt = vFileName; + infos->fileNameExt_optimized = prOptimizeFilenameForSearchOperations(infos->fileNameExt); + infos->fileType = vFileType; - if (infos->fileType == 'f' || - infos->fileType == 'l') // link can have the same extention of a file - { - size_t lpt = infos->fileNameExt.find_last_of('.'); - if (lpt != std::string::npos) - { - infos->fileExt = infos->fileNameExt.substr(lpt); - } + if (infos->fileNameExt.empty() || ((infos->fileNameExt == "." || infos->fileNameExt == "..") && !vFileDialogInternal.puFilterManager.puDLGFilters.empty())) return; // filename empty or filename is the current dir '.' //-V807 + if (infos->fileNameExt != ".." && (vFileDialogInternal.puDLGflags & ImGuiFileDialogFlags_DontShowHiddenFiles) && infos->fileNameExt[0] == '.') // dont show hidden files + if (!vFileDialogInternal.puFilterManager.puDLGFilters.empty() || (vFileDialogInternal.puFilterManager.puDLGFilters.empty() && infos->fileNameExt != ".")) // except "." if in directory mode //-V728 + return; + + if (infos->fileType == 'f' || + infos->fileType == 'l') // link can have the same extention of a file + { + size_t lpt = infos->fileNameExt.find_last_of('.'); + if (lpt != std::string::npos) + { + infos->fileExt = infos->fileNameExt.substr(lpt); + } for (char& i: infos->fileExt) { if (i>='A' && i<='Z') i+='a'-'A'; } - if (!vFileDialogInternal.puFilterManager.IsCoveredByFilters(infos->fileExt)) - { - return; - } - } + if (!vFileDialogInternal.puFilterManager.IsCoveredByFilters(infos->fileExt)) + { + return; + } + } - vFileDialogInternal.puFilterManager.prFillFileStyle(infos); +#ifdef _WIN32 + SYSTEMTIME systemTime; + SYSTEMTIME localTime; + char timebuf[100]; - prCompleteFileInfos(infos); - prFileList.push_back(infos); - } + infos->fileSize=dent->dwin_size; + if (FileTimeToSystemTime(&dent->dwin_mtime,&systemTime)==TRUE) { + if (SystemTimeToTzSpecificLocalTime(NULL,&systemTime,&localTime)==TRUE) { + snprintf(timebuf,99,"%d/%.2d/%.2d %.2d:%.2d",localTime.wYear,localTime.wMonth,localTime.wDay,localTime.wHour,localTime.wMinute); + } else { + snprintf(timebuf,99,"%d/%.2d/%.2d %.2d:%.2d",systemTime.wYear,systemTime.wMonth,systemTime.wDay,systemTime.wHour,systemTime.wMinute); + } + infos->fileModifDate=timebuf; + } else { + infos->fileModifDate="???"; + } +#endif - void IGFD::FileManager::ScanDir(const FileDialogInternal& vFileDialogInternal, const std::string& vPath) - { - std::string path = vPath; + vFileDialogInternal.puFilterManager.prFillFileStyle(infos); + + prCompleteFileInfos(infos); + prFileList.push_back(infos); + } + + void IGFD::FileManager::ScanDir(const FileDialogInternal& vFileDialogInternal, const std::string& vPath) + { + std::string path = vPath; logV("IGFD: ScanDir(%s)",vPath); - if (prCurrentPathDecomposition.empty()) - { + if (prCurrentPathDecomposition.empty()) + { logV("IGFD: the current path decomposition is empty. setting."); - SetCurrentDir(path); - } + SetCurrentDir(path); + } - if (!prCurrentPathDecomposition.empty()) - { + if (!prCurrentPathDecomposition.empty()) + { logV("IGFD: the current path decomposition is not empty. trying."); #ifdef WIN32 - if (path == puFsRoot) - path += std::string(1u, PATH_SEP); + if (path == puFsRoot) + path += std::string(1u, PATH_SEP); #endif // WIN32 - ClearFileLists(); + ClearFileLists(); -#ifdef USE_STD_FILESYSTEM - //const auto wpath = IGFD::Utils::WGetString(path.c_str()); - const std::filesystem::path fspath(path); - const auto dir_iter = std::filesystem::directory_iterator(fspath); - AddFile(vFileDialogInternal, path, "..", 'd'); - for (const auto& file : dir_iter) - { - char fileType = 0; - if (file.is_symlink()) - fileType = 'l'; - else if (file.is_directory()) - fileType = 'd'; - else - fileType = 'f'; - auto fileNameExt = file.path().filename().string(); - AddFile(vFileDialogInternal, path, fileNameExt, fileType); - } -#else // dirent - struct dirent** files = nullptr; - int n = scandir(path.c_str(), &files, nullptr, inAlphaSort); + struct dirent** files = nullptr; + int n = scandir(path.c_str(), &files, nullptr, inAlphaSort); logV("IGFD: %d entries in directory",n); - if (n>0) - { - int i; + if (n>0) + { + int i; - for (i = 0; i < n; i++) - { - struct dirent* ent = files[i]; - std::string where = path + std::string("/") + std::string(ent->d_name); - char fileType = 0; -#ifdef HAVE_DIRENT_TYPE - if (ent->d_type != DT_UNKNOWN) - { - switch (ent->d_type) - { - case DT_REG: - fileType = 'f'; break; - case DT_DIR: - fileType = 'd'; break; - case DT_LNK: - DIR* dirTest = opendir(where.c_str()); - if (dirTest == NULL) - { - if (errno == ENOTDIR) - { - fileType = 'f'; - } - else - { - fileType = 'l'; - } - } - else - { - fileType = 'd'; - closedir(dirTest); - } - break; - } - } - else + for (i = 0; i < n; i++) + { + struct dirent* ent = files[i]; + std::string where = path + std::string(PATH_SEP_STR) + std::string(ent->d_name); + char fileType = 0; +#if defined(HAVE_DIRENT_TYPE) || defined(_WIN32) + if (ent->d_type != DT_UNKNOWN) + { + switch (ent->d_type) + { + case DT_REG: + fileType = 'f'; break; + case DT_DIR: + fileType = 'd'; break; + case DT_LNK: +#ifdef _WIN32 + fileType = 'f'; +#else + DIR* dirTest = opendir(where.c_str()); + if (dirTest == NULL) + { + if (errno == ENOTDIR) + { + fileType = 'f'; + } + else + { + fileType = 'l'; + } + } + else + { + fileType = 'd'; + closedir(dirTest); + } +#endif + break; + } + } + else #endif // HAVE_DIRENT_TYPE - { - struct stat filestat; - if (stat(where.c_str(), &filestat) == 0) - { - if (S_ISDIR(filestat.st_mode)) - { - fileType = 'd'; - } - else - { - fileType = 'f'; - } - } - } + { +#ifndef _WIN32 + struct stat filestat; + if (stat(where.c_str(), &filestat) == 0) + { + if (S_ISDIR(filestat.st_mode)) + { + fileType = 'd'; + } + else + { + fileType = 'f'; + } + } +#endif + } - auto fileNameExt = ent->d_name; + auto fileNameExt = ent->d_name; - AddFile(vFileDialogInternal, path, fileNameExt, fileType); - } + AddFile(vFileDialogInternal, path, fileNameExt, fileType, ent); + } - for (i = 0; i < n; i++) - { - free(files[i]); - } + for (i = 0; i < n; i++) + { + free(files[i]); + } - free(files); - } else { + free(files); + } else { logV("IGFD: it's empty"); } -#endif // USE_STD_FILESYSTEM logV("IGFD: sorting fields..."); - SortFields(vFileDialogInternal, puSortingField, false); - } else { + SortFields(vFileDialogInternal, puSortingField, false); + } else { logE("IGFD: current path decomposition is empty!"); } fileListActuallyEmpty=prFileList.empty(); - } + } - bool IGFD::FileManager::GetDrives() - { - auto drives = IGFD::Utils::GetDrivesList(); - if (!drives.empty()) - { - prCurrentPath.clear(); - prCurrentPathDecomposition.clear(); - ClearFileLists(); - for (auto& drive : drives) - { - auto info = std::make_shared(); - info->fileNameExt = drive; - info->fileNameExt_optimized = prOptimizeFilenameForSearchOperations(drive); - info->fileType = 'd'; + bool IGFD::FileManager::GetDrives() + { + auto drives = IGFD::Utils::GetDrivesList(); + if (!drives.empty()) + { + prCurrentPath.clear(); + prCurrentPathDecomposition.clear(); + ClearFileLists(); + for (auto& drive : drives) + { + auto info = std::make_shared(); + info->fileNameExt = drive; + info->fileNameExt_optimized = prOptimizeFilenameForSearchOperations(drive); + info->fileType = 'd'; - if (!info->fileNameExt.empty()) - { - prFileList.push_back(info); - } - } - puShowDrives = true; - return true; - } - return false; - } + if (!info->fileNameExt.empty()) + { + prFileList.push_back(info); + } + } + puShowDrives = true; + return true; + } + return false; + } - bool IGFD::FileManager::IsComposerEmpty() - { - return prCurrentPathDecomposition.empty(); - } - - size_t IGFD::FileManager::GetComposerSize() - { - return prCurrentPathDecomposition.size(); - } + bool IGFD::FileManager::IsComposerEmpty() + { + return prCurrentPathDecomposition.empty(); + } + + size_t IGFD::FileManager::GetComposerSize() + { + return prCurrentPathDecomposition.size(); + } - bool IGFD::FileManager::IsFileListEmpty() - { - return prFileList.empty(); - } + bool IGFD::FileManager::IsFileListEmpty() + { + return prFileList.empty(); + } - size_t IGFD::FileManager::GetFullFileListSize() - { - return prFileList.size(); - } + size_t IGFD::FileManager::GetFullFileListSize() + { + return prFileList.size(); + } - std::shared_ptr IGFD::FileManager::GetFullFileAt(size_t vIdx) - { - if (vIdx < prFileList.size()) - return prFileList[vIdx]; - return nullptr; - } + std::shared_ptr IGFD::FileManager::GetFullFileAt(size_t vIdx) + { + if (vIdx < prFileList.size()) + return prFileList[vIdx]; + return nullptr; + } - bool IGFD::FileManager::IsFilteredListEmpty() - { - return prFilteredFileList.empty(); - } + bool IGFD::FileManager::IsFilteredListEmpty() + { + return prFilteredFileList.empty(); + } - size_t IGFD::FileManager::GetFilteredListSize() - { - return prFilteredFileList.size(); - } + size_t IGFD::FileManager::GetFilteredListSize() + { + return prFilteredFileList.size(); + } - std::shared_ptr IGFD::FileManager::GetFilteredFileAt(size_t vIdx) - { - if (vIdx < prFilteredFileList.size()) - return prFilteredFileList[vIdx]; - return nullptr; - } + std::shared_ptr IGFD::FileManager::GetFilteredFileAt(size_t vIdx) + { + if (vIdx < prFilteredFileList.size()) + return prFilteredFileList[vIdx]; + return nullptr; + } - bool IGFD::FileManager::IsFileNameSelected(const std::string& vFileName) - { - return prSelectedFileNames.find(vFileName) != prSelectedFileNames.end(); - } + bool IGFD::FileManager::IsFileNameSelected(const std::string& vFileName) + { + return prSelectedFileNames.find(vFileName) != prSelectedFileNames.end(); + } - std::string IGFD::FileManager::GetBack() - { - return prCurrentPathDecomposition.back(); - } + std::string IGFD::FileManager::GetBack() + { + return prCurrentPathDecomposition.back(); + } - void IGFD::FileManager::ClearComposer() - { - prCurrentPathDecomposition.clear(); - } + void IGFD::FileManager::ClearComposer() + { + prCurrentPathDecomposition.clear(); + } - void IGFD::FileManager::ClearAll() - { - ClearComposer(); - ClearFileLists(); - } + void IGFD::FileManager::ClearAll() + { + ClearComposer(); + ClearFileLists(); + } - void IGFD::FileManager::ApplyFilteringOnFileList(const FileDialogInternal& vFileDialogInternal) - { - prFilteredFileList.clear(); - for (const auto& file : prFileList) - { - if (!file.use_count()) - continue; - bool show = true; - if (!file->IsTagFound(vFileDialogInternal.puSearchManager.puSearchTag)) // if search tag - show = false; - if (puDLGDirectoryMode && file->fileType != 'd') // directory mode - show = false; - if (show) - prFilteredFileList.push_back(file); - } - } + void IGFD::FileManager::ApplyFilteringOnFileList(const FileDialogInternal& vFileDialogInternal) + { + prFilteredFileList.clear(); + for (const auto& file : prFileList) + { + if (!file.use_count()) + continue; + bool show = true; + if (!file->IsTagFound(vFileDialogInternal.puSearchManager.puSearchTag)) // if search tag + show = false; + if (puDLGDirectoryMode && file->fileType != 'd') // directory mode + show = false; + if (show) + prFilteredFileList.push_back(file); + } + } - std::string IGFD::FileManager::prRoundNumber(double vvalue, int n) - { - std::stringstream tmp; - tmp << std::setprecision(n) << std::fixed << vvalue; - return tmp.str(); - } + std::string IGFD::FileManager::prRoundNumber(double vvalue, int n) + { + std::stringstream tmp; + tmp << std::setprecision(n) << std::fixed << vvalue; + return tmp.str(); + } - std::string IGFD::FileManager::prFormatFileSize(size_t vByteSize) - { - if (vByteSize != 0) - { - static double lo = 1024.0; - static double ko = 1024.0 * 1024.0; - static double mo = 1024.0 * 1024.0 * 1024.0; + std::string IGFD::FileManager::prFormatFileSize(size_t vByteSize) + { + if (vByteSize != 0) + { + static double lo = 1024.0; + static double ko = 1024.0 * 1024.0; + static double mo = 1024.0 * 1024.0 * 1024.0; - auto v = (double)vByteSize; + auto v = (double)vByteSize; - if (v < lo) - return prRoundNumber(v, 0); // octet - else if (v < ko) - return prRoundNumber(v / lo, 2) + "K"; // ko - else if (v < mo) - return prRoundNumber(v / ko, 2) + "M"; // Mo - else - return prRoundNumber(v / mo, 2) + "G"; // Go - } + if (v < lo) + return prRoundNumber(v, 0); // octet + else if (v < ko) + return prRoundNumber(v / lo, 2) + "K"; // ko + else if (v < mo) + return prRoundNumber(v / ko, 2) + "M"; // Mo + else + return prRoundNumber(v / mo, 2) + "G"; // Go + } - return ""; - } + return ""; + } - void IGFD::FileManager::prCompleteFileInfos(const std::shared_ptr& vInfos) - { - if (!vInfos.use_count()) - return; + void IGFD::FileManager::prCompleteFileInfos(const std::shared_ptr& vInfos) + { + if (!vInfos.use_count()) + return; - if (vInfos->fileNameExt != "." && - vInfos->fileNameExt != "..") - { - // _stat struct : - //dev_t st_dev; /* ID of device containing file */ - //ino_t st_ino; /* inode number */ - //mode_t st_mode; /* protection */ - //nlink_t st_nlink; /* number of hard links */ - //uid_t st_uid; /* user ID of owner */ - //gid_t st_gid; /* group ID of owner */ - //dev_t st_rdev; /* device ID (if special file) */ - //off_t st_size; /* total size, in bytes */ - //blksize_t st_blksize; /* blocksize for file system I/O */ - //blkcnt_t st_blocks; /* number of 512B blocks allocated */ - //time_t st_atime; /* time of last access - not sure out of ntfs */ - //time_t st_mtime; /* time of last modification - not sure out of ntfs */ - //time_t st_ctime; /* time of last status change - not sure out of ntfs */ + if (vInfos->fileNameExt != "." && + vInfos->fileNameExt != "..") + { + // _stat struct : + //dev_t st_dev; /* ID of device containing file */ + //ino_t st_ino; /* inode number */ + //mode_t st_mode; /* protection */ + //nlink_t st_nlink; /* number of hard links */ + //uid_t st_uid; /* user ID of owner */ + //gid_t st_gid; /* group ID of owner */ + //dev_t st_rdev; /* device ID (if special file) */ + //off_t st_size; /* total size, in bytes */ + //blksize_t st_blksize; /* blocksize for file system I/O */ + //blkcnt_t st_blocks; /* number of 512B blocks allocated */ + //time_t st_atime; /* time of last access - not sure out of ntfs */ + //time_t st_mtime; /* time of last modification - not sure out of ntfs */ + //time_t st_ctime; /* time of last status change - not sure out of ntfs */ - std::string fpn; +#ifdef _WIN32 + if (vInfos->fileType != 'd') + { + vInfos->formatedFileSize = prFormatFileSize(vInfos->fileSize); + } +#else + std::string fpn; - if (vInfos->fileType == 'f' || vInfos->fileType == 'l' || vInfos->fileType == 'd') // file - fpn = vInfos->filePath + std::string(1u, PATH_SEP) + vInfos->fileNameExt; + if (vInfos->fileType == 'f' || vInfos->fileType == 'l' || vInfos->fileType == 'd') // file + fpn = vInfos->filePath + std::string(1u, PATH_SEP) + vInfos->fileNameExt; - struct stat statInfos = {}; - char timebuf[100]; - int result = stat(fpn.c_str(), &statInfos); - if (result!=-1) - { - if (vInfos->fileType != 'd') - { - vInfos->fileSize = (size_t)statInfos.st_size; - vInfos->formatedFileSize = prFormatFileSize(vInfos->fileSize); - } + struct stat statInfos = {}; + char timebuf[100]; + int result = stat(fpn.c_str(), &statInfos); + if (result!=-1) + { + if (vInfos->fileType != 'd') + { + vInfos->fileSize = (size_t)statInfos.st_size; + vInfos->formatedFileSize = prFormatFileSize(vInfos->fileSize); + } - size_t len = 0; + size_t len = 0; #ifdef MSVC - struct tm _tm; - errno_t err = localtime_s(&_tm, &statInfos.st_mtime); - if (!err) len = strftime(timebuf, 99, DateTimeFormat, &_tm); + struct tm _tm; + errno_t err = localtime_s(&_tm, &statInfos.st_mtime); + if (!err) len = strftime(timebuf, 99, DateTimeFormat, &_tm); #else // MSVC - struct tm* _tm = localtime(&statInfos.st_mtime); - if (_tm) len = strftime(timebuf, 99, DateTimeFormat, _tm); + struct tm* _tm = localtime(&statInfos.st_mtime); + if (_tm) len = strftime(timebuf, 99, DateTimeFormat, _tm); #endif // MSVC - if (len) - { - vInfos->fileModifDate = std::string(timebuf, len); - } - } else { + if (len) + { + vInfos->fileModifDate = std::string(timebuf, len); + } + } else { vInfos->fileSize=0; vInfos->formatedFileSize = prFormatFileSize(vInfos->fileSize); vInfos->fileModifDate="???"; } - } - } - - void IGFD::FileManager::prRemoveFileNameInSelection(const std::string& vFileName) - { - prSelectedFileNames.erase(vFileName); - - if (prSelectedFileNames.size() == 1) - { - snprintf(puFileNameBuffer, MAX_FILE_DIALOG_NAME_BUFFER, "%s", vFileName.c_str()); - } - else - { - snprintf(puFileNameBuffer, MAX_FILE_DIALOG_NAME_BUFFER, "%zu files Selected", prSelectedFileNames.size()); - } - } - - void IGFD::FileManager::prAddFileNameInSelection(const std::string& vFileName, bool vSetLastSelectionFileName) - { - prSelectedFileNames.emplace(vFileName); - - if (prSelectedFileNames.size() == 1) - { - snprintf(puFileNameBuffer, MAX_FILE_DIALOG_NAME_BUFFER, "%s", vFileName.c_str()); - } - else - { - snprintf(puFileNameBuffer, MAX_FILE_DIALOG_NAME_BUFFER, "%zu files Selected", prSelectedFileNames.size()); - } - - if (vSetLastSelectionFileName) - prLastSelectedFileName = vFileName; - } - - void IGFD::FileManager::SetCurrentDir(const std::string& vPath) - { - std::string path = vPath; -#ifdef WIN32 - if (puFsRoot == path) - path += std::string(1u, PATH_SEP); -#endif // WIN32 - -#ifdef USE_STD_FILESYSTEM - namespace fs = std::filesystem; - bool dir_opened = fs::is_directory(vPath); - if (!dir_opened) - { - path = "."; - dir_opened = fs::is_directory(vPath); - } - if (dir_opened) -#else - DIR* dir = opendir(path.c_str()); - if (dir == nullptr) - { - path = "."; - dir = opendir(path.c_str()); - } - - if (dir != nullptr) -#endif // USE_STD_FILESYSTEM - { -#ifdef WIN32 - DWORD numchar = 0; - // numchar = GetFullPathNameA(path.c_str(), PATH_MAX, real_path, nullptr); - std::wstring wpath = IGFD::Utils::string_to_wstring(path); - numchar = GetFullPathNameW(wpath.c_str(), 0, nullptr, nullptr); - std::wstring fpath(numchar, 0); - GetFullPathNameW(wpath.c_str(), numchar, (wchar_t*)fpath.data(), nullptr); - std::string real_path = IGFD::Utils::wstring_to_string(fpath); - if (real_path.back() == '\0') // for fix issue we can have with std::string concatenation.. if there is a \0 at end - real_path = real_path.substr(0, real_path.size() - 1U); - if (!real_path.empty()) -#elif defined(UNIX) // UNIX is LINUX or APPLE - char real_path[PATH_MAX]; - char* numchar = realpath(path.c_str(), real_path); - if (numchar != nullptr) -#endif // WIN32 - { - prCurrentPath = std::move(real_path); - if (prCurrentPath[prCurrentPath.size() - 1] == PATH_SEP) - { - prCurrentPath = prCurrentPath.substr(0, prCurrentPath.size() - 1); - } - IGFD::Utils::SetBuffer(puInputPathBuffer, MAX_PATH_BUFFER_SIZE, prCurrentPath); - prCurrentPathDecomposition = IGFD::Utils::SplitStringToVector(prCurrentPath, PATH_SEP, false); -#ifdef UNIX // UNIX is LINUX or APPLE - prCurrentPathDecomposition.insert(prCurrentPathDecomposition.begin(), std::string(1u, PATH_SEP)); -#endif // UNIX - if (!prCurrentPathDecomposition.empty()) - { -#ifdef WIN32 - puFsRoot = prCurrentPathDecomposition[0]; -#endif // WIN32 - } - } -#ifndef USE_STD_FILESYSTEM - closedir(dir); #endif - } - } + } + } - bool IGFD::FileManager::CreateDir(const std::string& vPath) - { - bool res = false; + void IGFD::FileManager::prRemoveFileNameInSelection(const std::string& vFileName) + { + prSelectedFileNames.erase(vFileName); - if (!vPath.empty()) - { - std::string path = prCurrentPath + std::string(1u, PATH_SEP) + vPath; + if (prSelectedFileNames.size() == 1) + { + snprintf(puFileNameBuffer, MAX_FILE_DIALOG_NAME_BUFFER, "%s", vFileName.c_str()); + } + else + { + snprintf(puFileNameBuffer, MAX_FILE_DIALOG_NAME_BUFFER, "%zu files Selected", prSelectedFileNames.size()); + } + } + + void IGFD::FileManager::prAddFileNameInSelection(const std::string& vFileName, bool vSetLastSelectionFileName) + { + prSelectedFileNames.emplace(vFileName); - res = IGFD::Utils::CreateDirectoryIfNotExist(path); - } + if (prSelectedFileNames.size() == 1) + { + snprintf(puFileNameBuffer, MAX_FILE_DIALOG_NAME_BUFFER, "%s", vFileName.c_str()); + } + else + { + snprintf(puFileNameBuffer, MAX_FILE_DIALOG_NAME_BUFFER, "%zu files Selected", prSelectedFileNames.size()); + } - return res; - } + if (vSetLastSelectionFileName) + prLastSelectedFileName = vFileName; + } - void IGFD::FileManager::ComposeNewPath(std::vector::iterator vIter) - { - std::string res; - - while (true) - { - if (!res.empty()) - { + void IGFD::FileManager::SetCurrentDir(const std::string& vPath) + { + std::string path = vPath; #ifdef WIN32 - res = *vIter + std::string(1u, PATH_SEP) + res; -#elif defined(UNIX) // UNIX is LINUX or APPLE - if (*vIter == puFsRoot) - res = *vIter + res; - else - res = *vIter + PATH_SEP + res; + if (puFsRoot == path) + path += std::string(1u, PATH_SEP); #endif // WIN32 - } - else - res = *vIter; + + DIR* dir = opendir(path.c_str()); + if (dir == nullptr) + { + path = "."; + dir = opendir(path.c_str()); + } - if (vIter == prCurrentPathDecomposition.begin()) - { + if (dir != nullptr) + { +#ifdef WIN32 + DWORD numchar = 0; + // numchar = GetFullPathNameA(path.c_str(), PATH_MAX, real_path, nullptr); + std::wstring wpath = IGFD::Utils::string_to_wstring(path); + numchar = GetFullPathNameW(wpath.c_str(), 0, nullptr, nullptr); + std::wstring fpath(numchar, 0); + GetFullPathNameW(wpath.c_str(), numchar, (wchar_t*)fpath.data(), nullptr); + std::string real_path = IGFD::Utils::wstring_to_string(fpath); + if (real_path.back() == '\0') // for fix issue we can have with std::string concatenation.. if there is a \0 at end + real_path = real_path.substr(0, real_path.size() - 1U); + if (!real_path.empty()) +#elif defined(UNIX) // UNIX is LINUX or APPLE + char real_path[PATH_MAX]; + char* numchar = realpath(path.c_str(), real_path); + if (numchar != nullptr) +#endif // WIN32 + { + prCurrentPath = std::move(real_path); + if (prCurrentPath[prCurrentPath.size() - 1] == PATH_SEP) + { + prCurrentPath = prCurrentPath.substr(0, prCurrentPath.size() - 1); + } + IGFD::Utils::SetBuffer(puInputPathBuffer, MAX_PATH_BUFFER_SIZE, prCurrentPath); + prCurrentPathDecomposition = IGFD::Utils::SplitStringToVector(prCurrentPath, PATH_SEP, false); +#ifdef UNIX // UNIX is LINUX or APPLE + prCurrentPathDecomposition.insert(prCurrentPathDecomposition.begin(), std::string(1u, PATH_SEP)); +#endif // UNIX + if (!prCurrentPathDecomposition.empty()) + { +#ifdef WIN32 + puFsRoot = prCurrentPathDecomposition[0]; +#endif // WIN32 + } + } + closedir(dir); + } + } + + bool IGFD::FileManager::CreateDir(const std::string& vPath) + { + bool res = false; + + if (!vPath.empty()) + { + std::string path = prCurrentPath + std::string(1u, PATH_SEP) + vPath; + + res = IGFD::Utils::CreateDirectoryIfNotExist(path); + } + + return res; + } + + void IGFD::FileManager::ComposeNewPath(std::vector::iterator vIter) + { + std::string res; + + while (true) + { + if (!res.empty()) + { +#ifdef WIN32 + res = *vIter + std::string(1u, PATH_SEP) + res; +#elif defined(UNIX) // UNIX is LINUX or APPLE + if (*vIter == puFsRoot) + res = *vIter + res; + else + res = *vIter + PATH_SEP + res; +#endif // WIN32 + } + else + res = *vIter; + + if (vIter == prCurrentPathDecomposition.begin()) + { #if defined(UNIX) // UNIX is LINUX or APPLE - if (res[0] != PATH_SEP) - res = PATH_SEP + res; + if (res[0] != PATH_SEP) + res = PATH_SEP + res; #endif // defined(UNIX) - break; - } + break; + } - --vIter; - } + --vIter; + } - prCurrentPath = std::move(res); - } + prCurrentPath = std::move(res); + } - bool IGFD::FileManager::SetPathOnParentDirectoryIfAny() - { - if (prCurrentPathDecomposition.size() > 1) - { - ComposeNewPath(prCurrentPathDecomposition.end() - 2); - return true; - } - return false; - } + bool IGFD::FileManager::SetPathOnParentDirectoryIfAny() + { + if (prCurrentPathDecomposition.size() > 1) + { + ComposeNewPath(prCurrentPathDecomposition.end() - 2); + return true; + } + return false; + } - std::string IGFD::FileManager::GetCurrentPath() - { - if (prCurrentPath.empty()) - prCurrentPath = "."; - return prCurrentPath; - } + std::string IGFD::FileManager::GetCurrentPath() + { + if (prCurrentPath.empty()) + prCurrentPath = "."; + return prCurrentPath; + } - void IGFD::FileManager::SetCurrentPath(const std::string& vCurrentPath) - { - if (vCurrentPath.empty()) - prCurrentPath = "."; - else - prCurrentPath = vCurrentPath; - } + void IGFD::FileManager::SetCurrentPath(const std::string& vCurrentPath) + { + if (vCurrentPath.empty()) + prCurrentPath = "."; + else + prCurrentPath = vCurrentPath; + } - bool IGFD::FileManager::IsFileExist(const std::string& vFile) - { - std::ifstream docFile(vFile, std::ios::in); - if (docFile.is_open()) - { - docFile.close(); - return true; - } - return false; - } + bool IGFD::FileManager::IsFileExist(const std::string& vFile) + { + std::ifstream docFile(vFile, std::ios::in); + if (docFile.is_open()) + { + docFile.close(); + return true; + } + return false; + } - void IGFD::FileManager::SetDefaultFileName(const std::string& vFileName) - { - puDLGDefaultFileName = vFileName; - IGFD::Utils::SetBuffer(puFileNameBuffer, MAX_FILE_DIALOG_NAME_BUFFER, vFileName); - } + void IGFD::FileManager::SetDefaultFileName(const std::string& vFileName) + { + puDLGDefaultFileName = vFileName; + IGFD::Utils::SetBuffer(puFileNameBuffer, MAX_FILE_DIALOG_NAME_BUFFER, vFileName); + } - bool IGFD::FileManager::SelectDirectory(const std::shared_ptr& vInfos) - { - if (!vInfos.use_count()) - return false; + bool IGFD::FileManager::SelectDirectory(const std::shared_ptr& vInfos) + { + if (!vInfos.use_count()) + return false; - bool pathClick = false; + bool pathClick = false; - if (vInfos->fileNameExt == "..") - { - pathClick = SetPathOnParentDirectoryIfAny(); - } - else - { - std::string newPath; + if (vInfos->fileNameExt == "..") + { + pathClick = SetPathOnParentDirectoryIfAny(); + } + else + { + std::string newPath; - if (puShowDrives) - { - newPath = vInfos->fileNameExt + std::string(1u, PATH_SEP); - } - else - { + if (puShowDrives) + { + newPath = vInfos->fileNameExt + std::string(1u, PATH_SEP); + } + else + { #ifdef __linux__ - if (puFsRoot == prCurrentPath) - newPath = prCurrentPath + vInfos->fileNameExt; - else + if (puFsRoot == prCurrentPath) + newPath = prCurrentPath + vInfos->fileNameExt; + else #endif // __linux__ - newPath = prCurrentPath + std::string(1u, PATH_SEP) + vInfos->fileNameExt; - } + newPath = prCurrentPath + std::string(1u, PATH_SEP) + vInfos->fileNameExt; + } - if (IGFD::Utils::IsDirectoryExist(newPath)) - { - if (puShowDrives) - { - prCurrentPath = vInfos->fileNameExt; - puFsRoot = prCurrentPath; - } - else - { - prCurrentPath = newPath; //-V820 - } - pathClick = true; - } - } + if (IGFD::Utils::IsDirectoryExist(newPath)) + { + if (puShowDrives) + { + prCurrentPath = vInfos->fileNameExt; + puFsRoot = prCurrentPath; + } + else + { + prCurrentPath = newPath; //-V820 + } + pathClick = true; + } + } - return pathClick; - } + return pathClick; + } - void IGFD::FileManager::SelectFileName(const FileDialogInternal& vFileDialogInternal, const std::shared_ptr& vInfos) - { - if (!vInfos.use_count()) - return; + void IGFD::FileManager::SelectFileName(const FileDialogInternal& vFileDialogInternal, const std::shared_ptr& vInfos) + { + if (!vInfos.use_count()) + return; - if (ImGui::GetIO().KeyCtrl) - { - if (puDLGcountSelectionMax == 0) // infinite selection - { - if (prSelectedFileNames.find(vInfos->fileNameExt) == prSelectedFileNames.end()) // not found +> add - { - prAddFileNameInSelection(vInfos->fileNameExt, true); - } - else // found +> remove - { - prRemoveFileNameInSelection(vInfos->fileNameExt); - } - } - else // selection limited by size - { - if (prSelectedFileNames.size() < puDLGcountSelectionMax) - { - if (prSelectedFileNames.find(vInfos->fileNameExt) == prSelectedFileNames.end()) // not found +> add - { - prAddFileNameInSelection(vInfos->fileNameExt, true); - } - else // found +> remove - { - prRemoveFileNameInSelection(vInfos->fileNameExt); - } - } - } - } - else if (ImGui::GetIO().KeyShift) - { - if (puDLGcountSelectionMax != 1) - { - prSelectedFileNames.clear(); - // we will iterate filelist and get the last selection after the start selection - bool startMultiSelection = false; - std::string fileNameToSelect = vInfos->fileNameExt; - std::string savedLastSelectedFileName; // for invert selection mode - for (const auto& file : prFileList) - { - if (!file.use_count()) - continue; + if (ImGui::GetIO().KeyCtrl) + { + if (puDLGcountSelectionMax == 0) // infinite selection + { + if (prSelectedFileNames.find(vInfos->fileNameExt) == prSelectedFileNames.end()) // not found +> add + { + prAddFileNameInSelection(vInfos->fileNameExt, true); + } + else // found +> remove + { + prRemoveFileNameInSelection(vInfos->fileNameExt); + } + } + else // selection limited by size + { + if (prSelectedFileNames.size() < puDLGcountSelectionMax) + { + if (prSelectedFileNames.find(vInfos->fileNameExt) == prSelectedFileNames.end()) // not found +> add + { + prAddFileNameInSelection(vInfos->fileNameExt, true); + } + else // found +> remove + { + prRemoveFileNameInSelection(vInfos->fileNameExt); + } + } + } + } + else if (ImGui::GetIO().KeyShift) + { + if (puDLGcountSelectionMax != 1) + { + prSelectedFileNames.clear(); + // we will iterate filelist and get the last selection after the start selection + bool startMultiSelection = false; + std::string fileNameToSelect = vInfos->fileNameExt; + std::string savedLastSelectedFileName; // for invert selection mode + for (const auto& file : prFileList) + { + if (!file.use_count()) + continue; - bool canTake = true; - if (!file->IsTagFound(vFileDialogInternal.puSearchManager.puSearchTag)) canTake = false; - if (canTake) // if not filtered, we will take files who are filtered by the dialog - { - if (file->fileNameExt == prLastSelectedFileName) - { - startMultiSelection = true; - prAddFileNameInSelection(prLastSelectedFileName, false); - } - else if (startMultiSelection) - { - if (puDLGcountSelectionMax == 0) // infinite selection - { - prAddFileNameInSelection(file->fileNameExt, false); - } - else // selection limited by size - { - if (prSelectedFileNames.size() < puDLGcountSelectionMax) - { - prAddFileNameInSelection(file->fileNameExt, false); - } - else - { - startMultiSelection = false; - if (!savedLastSelectedFileName.empty()) - prLastSelectedFileName = savedLastSelectedFileName; - break; - } - } - } + bool canTake = true; + if (!file->IsTagFound(vFileDialogInternal.puSearchManager.puSearchTag)) canTake = false; + if (canTake) // if not filtered, we will take files who are filtered by the dialog + { + if (file->fileNameExt == prLastSelectedFileName) + { + startMultiSelection = true; + prAddFileNameInSelection(prLastSelectedFileName, false); + } + else if (startMultiSelection) + { + if (puDLGcountSelectionMax == 0) // infinite selection + { + prAddFileNameInSelection(file->fileNameExt, false); + } + else // selection limited by size + { + if (prSelectedFileNames.size() < puDLGcountSelectionMax) + { + prAddFileNameInSelection(file->fileNameExt, false); + } + else + { + startMultiSelection = false; + if (!savedLastSelectedFileName.empty()) + prLastSelectedFileName = savedLastSelectedFileName; + break; + } + } + } - if (file->fileNameExt == fileNameToSelect) - { - if (!startMultiSelection) // we are before the last Selected FileName, so we must inverse - { - savedLastSelectedFileName = prLastSelectedFileName; - prLastSelectedFileName = fileNameToSelect; - fileNameToSelect = savedLastSelectedFileName; - startMultiSelection = true; - prAddFileNameInSelection(prLastSelectedFileName, false); - } - else - { - startMultiSelection = false; - if (!savedLastSelectedFileName.empty()) - prLastSelectedFileName = savedLastSelectedFileName; - break; - } - } - } - } - } - } - else - { - prSelectedFileNames.clear(); - IGFD::Utils::ResetBuffer(puFileNameBuffer); - prAddFileNameInSelection(vInfos->fileNameExt, true); - } - } + if (file->fileNameExt == fileNameToSelect) + { + if (!startMultiSelection) // we are before the last Selected FileName, so we must inverse + { + savedLastSelectedFileName = prLastSelectedFileName; + prLastSelectedFileName = fileNameToSelect; + fileNameToSelect = savedLastSelectedFileName; + startMultiSelection = true; + prAddFileNameInSelection(prLastSelectedFileName, false); + } + else + { + startMultiSelection = false; + if (!savedLastSelectedFileName.empty()) + prLastSelectedFileName = savedLastSelectedFileName; + break; + } + } + } + } + } + } + else + { + prSelectedFileNames.clear(); + IGFD::Utils::ResetBuffer(puFileNameBuffer); + prAddFileNameInSelection(vInfos->fileNameExt, true); + } + } - void IGFD::FileManager::DrawDirectoryCreation(const FileDialogInternal& vFileDialogInternal) - { - if (vFileDialogInternal.puDLGflags & ImGuiFileDialogFlags_DisableCreateDirectoryButton) - return; + void IGFD::FileManager::DrawDirectoryCreation(const FileDialogInternal& vFileDialogInternal) + { + if (vFileDialogInternal.puDLGflags & ImGuiFileDialogFlags_DisableCreateDirectoryButton) + return; - if (IMGUI_BUTTON(createDirButtonString)) - { - if (!prCreateDirectoryMode) - { - prCreateDirectoryMode = true; - IGFD::Utils::ResetBuffer(puDirectoryNameBuffer); - } - } - if (ImGui::IsItemHovered()) - ImGui::SetTooltip(buttonCreateDirString); + if (IMGUI_BUTTON(createDirButtonString)) + { + if (!prCreateDirectoryMode) + { + prCreateDirectoryMode = true; + IGFD::Utils::ResetBuffer(puDirectoryNameBuffer); + } + } + if (ImGui::IsItemHovered()) + ImGui::SetTooltip(buttonCreateDirString); - if (prCreateDirectoryMode) - { - ImGui::SameLine(); + if (prCreateDirectoryMode) + { + ImGui::SameLine(); - ImGui::PushItemWidth(100.0f); - ImGui::InputText("##DirectoryFileName", puDirectoryNameBuffer, MAX_FILE_DIALOG_NAME_BUFFER); - ImGui::PopItemWidth(); + ImGui::PushItemWidth(100.0f); + ImGui::InputText("##DirectoryFileName", puDirectoryNameBuffer, MAX_FILE_DIALOG_NAME_BUFFER); + ImGui::PopItemWidth(); - ImGui::SameLine(); + ImGui::SameLine(); - if (IMGUI_BUTTON(okButtonString)) - { - std::string newDir = std::string(puDirectoryNameBuffer); - if (CreateDir(newDir)) - { - SetCurrentPath(prCurrentPath + std::string(1u, PATH_SEP) + newDir); - OpenCurrentPath(vFileDialogInternal); - } + if (IMGUI_BUTTON(okButtonString)) + { + std::string newDir = std::string(puDirectoryNameBuffer); + if (CreateDir(newDir)) + { + SetCurrentPath(prCurrentPath + std::string(1u, PATH_SEP) + newDir); + OpenCurrentPath(vFileDialogInternal); + } - prCreateDirectoryMode = false; - } + prCreateDirectoryMode = false; + } - ImGui::SameLine(); + ImGui::SameLine(); - if (IMGUI_BUTTON(cancelButtonString)) - { - prCreateDirectoryMode = false; - } - } - } + if (IMGUI_BUTTON(cancelButtonString)) + { + prCreateDirectoryMode = false; + } + } + } - void IGFD::FileManager::DrawPathComposer(const FileDialogInternal& vFileDialogInternal) - { - if (IMGUI_BUTTON(resetButtonString)) - { - SetCurrentPath("."); - OpenCurrentPath(vFileDialogInternal); - } - if (ImGui::IsItemHovered()) - ImGui::SetTooltip(buttonResetPathString); + void IGFD::FileManager::DrawPathComposer(const FileDialogInternal& vFileDialogInternal) + { + if (IMGUI_BUTTON(homeButtonString)) + { + SetCurrentPath(FileDialog::Instance()->homePath); + OpenCurrentPath(vFileDialogInternal); + } + if (ImGui::IsItemHovered()) + ImGui::SetTooltip(buttonResetPathString); ImGui::SameLine(); if (IMGUI_BUTTON(parentDirString)) - { - if (SetPathOnParentDirectoryIfAny()) { - OpenCurrentPath(vFileDialogInternal); + { + if (SetPathOnParentDirectoryIfAny()) { + OpenCurrentPath(vFileDialogInternal); } - } - if (ImGui::IsItemHovered()) - ImGui::SetTooltip(buttonParentDirString); + } + if (ImGui::IsItemHovered()) + ImGui::SetTooltip(buttonParentDirString); #ifdef WIN32 - ImGui::SameLine(); + ImGui::SameLine(); - if (IMGUI_BUTTON(drivesButtonString)) - { - puDrivesClicked = true; - } - if (ImGui::IsItemHovered()) - ImGui::SetTooltip(buttonDriveString); + if (IMGUI_BUTTON(drivesButtonString)) + { + puDrivesClicked = true; + } + if (ImGui::IsItemHovered()) + ImGui::SetTooltip(buttonDriveString); #endif // WIN32 - ImGui::SameLine(); - - if (IMGUI_BUTTON(editPathButtonString)) - { - puInputPathActivated = true; - } - if (ImGui::IsItemHovered()) - ImGui::SetTooltip(buttonEditPathString); + ImGui::SameLine(); + + if (IMGUI_BUTTON(editPathButtonString)) + { + puInputPathActivated = true; + } + if (ImGui::IsItemHovered()) + ImGui::SetTooltip(buttonEditPathString); - ImGui::SameLine(); + ImGui::SameLine(); - ImGui::SeparatorEx(ImGuiSeparatorFlags_Vertical); + ImGui::SeparatorEx(ImGuiSeparatorFlags_Vertical); - // show current path - if (!prCurrentPathDecomposition.empty()) - { - ImGui::SameLine(); + // show current path + if (!prCurrentPathDecomposition.empty()) + { + ImGui::SameLine(); - if (puInputPathActivated) - { - ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x); - ImGui::InputText("##pathedition", puInputPathBuffer, MAX_PATH_BUFFER_SIZE); - ImGui::PopItemWidth(); - } - else - { - int _id = 0; - for (auto itPathDecomp = prCurrentPathDecomposition.begin(); - itPathDecomp != prCurrentPathDecomposition.end(); ++itPathDecomp) - { - if (itPathDecomp != prCurrentPathDecomposition.begin()) - ImGui::SameLine(); - ImGui::PushID(_id++); - bool click = IMGUI_PATH_BUTTON((*itPathDecomp).c_str()); - ImGui::PopID(); - if (click) - { - ComposeNewPath(itPathDecomp); - puPathClicked = true; - break; - } - // activate input for path - if (ImGui::IsItemClicked(ImGuiMouseButton_Right)) - { - ComposeNewPath(itPathDecomp); - IGFD::Utils::SetBuffer(puInputPathBuffer, MAX_PATH_BUFFER_SIZE, prCurrentPath); - puInputPathActivated = true; - break; - } - } - } - } - } + if (puInputPathActivated) + { + ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x); + ImGui::InputText("##pathedition", puInputPathBuffer, MAX_PATH_BUFFER_SIZE); + ImGui::PopItemWidth(); + } + else + { + int _id = 0; + for (auto itPathDecomp = prCurrentPathDecomposition.begin(); + itPathDecomp != prCurrentPathDecomposition.end(); ++itPathDecomp) + { + if (itPathDecomp != prCurrentPathDecomposition.begin()) + ImGui::SameLine(); + ImGui::PushID(_id++); + bool click = IMGUI_PATH_BUTTON((*itPathDecomp).c_str()); + ImGui::PopID(); + if (click) + { + ComposeNewPath(itPathDecomp); + puPathClicked = true; + break; + } + // activate input for path + if (ImGui::IsItemClicked(ImGuiMouseButton_Right)) + { + ComposeNewPath(itPathDecomp); + IGFD::Utils::SetBuffer(puInputPathBuffer, MAX_PATH_BUFFER_SIZE, prCurrentPath); + puInputPathActivated = true; + break; + } + } + } + } + } - std::string IGFD::FileManager::GetResultingPath() - { - std::string path = prCurrentPath; + std::string IGFD::FileManager::GetResultingPath() + { + std::string path = prCurrentPath; - if (puDLGDirectoryMode) // if directory mode - { - std::string selectedDirectory = puFileNameBuffer; - if (!selectedDirectory.empty() && - selectedDirectory != ".") - path += std::string(1u, PATH_SEP) + selectedDirectory; - } + if (puDLGDirectoryMode) // if directory mode + { + std::string selectedDirectory = puFileNameBuffer; + if (!selectedDirectory.empty() && + selectedDirectory != ".") + path += std::string(1u, PATH_SEP) + selectedDirectory; + } - return path; - } + return path; + } - std::string IGFD::FileManager::GetResultingFileName(FileDialogInternal& vFileDialogInternal) - { - if (!puDLGDirectoryMode) // if not directory mode - { - return puFileNameBuffer; //vFileDialogInternal.puFilterManager.ReplaceExtentionWithCurrentFilter(std::string(puFileNameBuffer)); - } + std::string IGFD::FileManager::GetResultingFileName(FileDialogInternal& vFileDialogInternal) + { + if (!puDLGDirectoryMode) // if not directory mode + { + return puFileNameBuffer; //vFileDialogInternal.puFilterManager.ReplaceExtentionWithCurrentFilter(std::string(puFileNameBuffer)); + } - return ""; // directory mode - } + return ""; // directory mode + } - std::string IGFD::FileManager::GetResultingFilePathName(FileDialogInternal& vFileDialogInternal) - { - std::string result = GetResultingPath(); + std::string IGFD::FileManager::GetResultingFilePathName(FileDialogInternal& vFileDialogInternal) + { + std::string result = GetResultingPath(); - std::string filename = GetResultingFileName(vFileDialogInternal); - if (!filename.empty()) - { + std::string filename = GetResultingFileName(vFileDialogInternal); + if (!filename.empty()) + { #ifdef UNIX - if (puFsRoot != result) + if (puFsRoot != result) #endif // UNIX - result += std::string(1u, PATH_SEP); + result += std::string(1u, PATH_SEP); - result += filename; - } + result += filename; + } - return result; - } + return result; + } - std::map IGFD::FileManager::GetResultingSelection() - { - std::map res; + std::map IGFD::FileManager::GetResultingSelection() + { + std::map res; - for (auto& selectedFileName : prSelectedFileNames) - { - std::string result = GetResultingPath(); + for (auto& selectedFileName : prSelectedFileNames) + { + std::string result = GetResultingPath(); #ifdef UNIX - if (puFsRoot != result) + if (puFsRoot != result) #endif // UNIX - result += std::string(1u, PATH_SEP); + result += std::string(1u, PATH_SEP); - result += selectedFileName; + result += selectedFileName; - res[selectedFileName] = result; - } + res[selectedFileName] = result; + } - return res; - } + return res; + } - ///////////////////////////////////////////////////////////////////////////////////// - //// FILE DIALOG INTERNAL /////////////////////////////////////////////////////////// - ///////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////////////////// + //// FILE DIALOG INTERNAL /////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////////////////// - void IGFD::FileDialogInternal::NewFrame() - { - puCanWeContinue = true; // reset flag for possibily validate the dialog - puIsOk = false; // reset dialog result - puFileManager.puDrivesClicked = false; - puFileManager.puPathClicked = false; - - puNeedToExitDialog = false; + void IGFD::FileDialogInternal::NewFrame() + { + puCanWeContinue = true; // reset flag for possibily validate the dialog + puIsOk = false; // reset dialog result + puFileManager.puDrivesClicked = false; + puFileManager.puPathClicked = false; + + puNeedToExitDialog = false; #ifdef USE_DIALOG_EXIT_WITH_KEY - if (ImGui::IsKeyPressed(IGFD_EXIT_KEY)) - { - // we do that here with the data's defined at the last frame - // because escape key can quit input activation and at the end of the frame all flag will be false - // so we will detect nothing - if (!(puFileManager.puInputPathActivated || - puSearchManager.puSearchInputIsActive || - puFileInputIsActive || - puFileListViewIsActive)) - { - puNeedToExitDialog = true; // need to quit dialog - } - } - else + if (ImGui::IsKeyPressed(IGFD_EXIT_KEY)) + { + // we do that here with the data's defined at the last frame + // because escape key can quit input activation and at the end of the frame all flag will be false + // so we will detect nothing + if (!(puFileManager.puInputPathActivated || + puSearchManager.puSearchInputIsActive || + puFileInputIsActive || + puFileListViewIsActive)) + { + puNeedToExitDialog = true; // need to quit dialog + } + } + else #endif - { - puSearchManager.puSearchInputIsActive = false; - puFileInputIsActive = false; - puFileListViewIsActive = false; - } - } + { + puSearchManager.puSearchInputIsActive = false; + puFileInputIsActive = false; + puFileListViewIsActive = false; + } + } - void IGFD::FileDialogInternal::EndFrame() - { - // directory change - if (puFileManager.puPathClicked) - { - puFileManager.OpenCurrentPath(*this); - } + void IGFD::FileDialogInternal::EndFrame() + { + // directory change + if (puFileManager.puPathClicked) + { + puFileManager.OpenCurrentPath(*this); + } - if (puFileManager.puDrivesClicked) - { - if (puFileManager.GetDrives()) - { - puFileManager.ApplyFilteringOnFileList(*this); - } - } + if (puFileManager.puDrivesClicked) + { + if (puFileManager.GetDrives()) + { + puFileManager.ApplyFilteringOnFileList(*this); + } + } - if (puFileManager.puInputPathActivated) - { - auto gio = ImGui::GetIO(); - if (ImGui::IsKeyReleased(ImGuiKey_Enter)) - { - puFileManager.SetCurrentPath(std::string(puFileManager.puInputPathBuffer)); - puFileManager.OpenCurrentPath(*this); - puFileManager.puInputPathActivated = false; - } - if (ImGui::IsKeyReleased(ImGuiKey_Escape)) - { - puFileManager.puInputPathActivated = false; - } - } - } + if (puFileManager.puInputPathActivated) + { + auto gio = ImGui::GetIO(); + if (ImGui::IsKeyReleased(ImGuiKey_Enter)) + { + puFileManager.SetCurrentPath(std::string(puFileManager.puInputPathBuffer)); + puFileManager.OpenCurrentPath(*this); + puFileManager.puInputPathActivated = false; + } + if (ImGui::IsKeyReleased(ImGuiKey_Escape)) + { + puFileManager.puInputPathActivated = false; + } + } + } - void IGFD::FileDialogInternal::ResetForNewDialog() - { - puFileManager.fileListActuallyEmpty=false; - } + void IGFD::FileDialogInternal::ResetForNewDialog() + { + puFileManager.fileListActuallyEmpty=false; + } - ///////////////////////////////////////////////////////////////////////////////////// - //// THUMBNAIL FEATURE ////////////////////////////////////////////////////////////// - ///////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////////////////// + //// THUMBNAIL FEATURE ////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////////////////// - IGFD::ThumbnailFeature::ThumbnailFeature() - { + IGFD::ThumbnailFeature::ThumbnailFeature() + { #ifdef USE_THUMBNAILS - prDisplayMode = DisplayModeEnum::FILE_LIST; + prDisplayMode = DisplayModeEnum::FILE_LIST; #endif - } + } - IGFD::ThumbnailFeature::~ThumbnailFeature() = default; + IGFD::ThumbnailFeature::~ThumbnailFeature() = default; - void IGFD::ThumbnailFeature::NewThumbnailFrame(FileDialogInternal& vFileDialogInternal) - { - (void)vFileDialogInternal; + void IGFD::ThumbnailFeature::NewThumbnailFrame(FileDialogInternal& vFileDialogInternal) + { + (void)vFileDialogInternal; #ifdef USE_THUMBNAILS - prStartThumbnailFileDatasExtraction(); + prStartThumbnailFileDatasExtraction(); #endif - } + } - void IGFD::ThumbnailFeature::EndThumbnailFrame(FileDialogInternal& vFileDialogInternal) - { + void IGFD::ThumbnailFeature::EndThumbnailFrame(FileDialogInternal& vFileDialogInternal) + { #ifdef USE_THUMBNAILS - prClearThumbnails(vFileDialogInternal); + prClearThumbnails(vFileDialogInternal); #endif - } + } - void IGFD::ThumbnailFeature::QuitThumbnailFrame(FileDialogInternal& vFileDialogInternal) - { + void IGFD::ThumbnailFeature::QuitThumbnailFrame(FileDialogInternal& vFileDialogInternal) + { #ifdef USE_THUMBNAILS - prStopThumbnailFileDatasExtraction(); - prClearThumbnails(vFileDialogInternal); + prStopThumbnailFileDatasExtraction(); + prClearThumbnails(vFileDialogInternal); #endif - } + } #ifdef USE_THUMBNAILS - void IGFD::ThumbnailFeature::prStartThumbnailFileDatasExtraction() - { - const bool res = prThumbnailGenerationThread.use_count() && prThumbnailGenerationThread->joinable(); - if (!res) - { - prIsWorking = true; - prCountFiles = 0U; - prThumbnailGenerationThread = std::shared_ptr( - new std::thread(&IGFD::ThumbnailFeature::prThreadThumbnailFileDatasExtractionFunc, this), - [this](std::thread* obj) - { - prIsWorking = false; - if (obj) - obj->join(); - }); - } - } + void IGFD::ThumbnailFeature::prStartThumbnailFileDatasExtraction() + { + const bool res = prThumbnailGenerationThread.use_count() && prThumbnailGenerationThread->joinable(); + if (!res) + { + prIsWorking = true; + prCountFiles = 0U; + prThumbnailGenerationThread = std::shared_ptr( + new std::thread(&IGFD::ThumbnailFeature::prThreadThumbnailFileDatasExtractionFunc, this), + [this](std::thread* obj) + { + prIsWorking = false; + if (obj) + obj->join(); + }); + } + } - bool IGFD::ThumbnailFeature::prStopThumbnailFileDatasExtraction() - { - const bool res = prThumbnailGenerationThread.use_count() && prThumbnailGenerationThread->joinable(); - if (res) - { - prThumbnailGenerationThread.reset(); - } + bool IGFD::ThumbnailFeature::prStopThumbnailFileDatasExtraction() + { + const bool res = prThumbnailGenerationThread.use_count() && prThumbnailGenerationThread->joinable(); + if (res) + { + prThumbnailGenerationThread.reset(); + } - return res; - } - - void IGFD::ThumbnailFeature::prThreadThumbnailFileDatasExtractionFunc() - { - prCountFiles = 0U; - prIsWorking = true; + return res; + } + + void IGFD::ThumbnailFeature::prThreadThumbnailFileDatasExtractionFunc() + { + prCountFiles = 0U; + prIsWorking = true; - // infinite loop while is thread working - while(prIsWorking) - { - if (!prThumbnailFileDatasToGet.empty()) - { - std::shared_ptr file = nullptr; - prThumbnailFileDatasToGetMutex.lock(); - //get the first file in the list - file = (*prThumbnailFileDatasToGet.begin()); - prThumbnailFileDatasToGetMutex.unlock(); + // infinite loop while is thread working + while(prIsWorking) + { + if (!prThumbnailFileDatasToGet.empty()) + { + std::shared_ptr file = nullptr; + prThumbnailFileDatasToGetMutex.lock(); + //get the first file in the list + file = (*prThumbnailFileDatasToGet.begin()); + prThumbnailFileDatasToGetMutex.unlock(); - // retrieve datas of the texture file if its an image file - if (file.use_count()) - { - if (file->fileType == 'f') //-V522 - { - if (file->fileExt == ".png" - || file->fileExt == ".bmp" - || file->fileExt == ".tga" - || file->fileExt == ".jpg" || file->fileExt == ".jpeg" - || file->fileExt == ".gif" - || file->fileExt == ".psd" - || file->fileExt == ".pic" - || file->fileExt == ".ppm" || file->fileExt == ".pgm" - //|| file->fileExt == ".hdr" => format float so in few times - ) - { - auto fpn = file->filePath + std::string(1u, PATH_SEP) + file->fileNameExt; + // retrieve datas of the texture file if its an image file + if (file.use_count()) + { + if (file->fileType == 'f') //-V522 + { + if (file->fileExt == ".png" + || file->fileExt == ".bmp" + || file->fileExt == ".tga" + || file->fileExt == ".jpg" || file->fileExt == ".jpeg" + || file->fileExt == ".gif" + || file->fileExt == ".psd" + || file->fileExt == ".pic" + || file->fileExt == ".ppm" || file->fileExt == ".pgm" + //|| file->fileExt == ".hdr" => format float so in few times + ) + { + auto fpn = file->filePath + std::string(1u, PATH_SEP) + file->fileNameExt; - int w = 0; - int h = 0; - int chans = 0; - uint8_t *datas = stbi_load(fpn.c_str(), &w, &h, &chans, STBI_rgb_alpha); - if (datas) - { - if (w && h) - { - // resize with respect to glyph ratio - const float ratioX = (float)w / (float)h; - const float newX = DisplayMode_ThumbailsList_ImageHeight * ratioX; - float newY = w / ratioX; - if (newX < w) - newY = DisplayMode_ThumbailsList_ImageHeight; + int w = 0; + int h = 0; + int chans = 0; + uint8_t *datas = stbi_load(fpn.c_str(), &w, &h, &chans, STBI_rgb_alpha); + if (datas) + { + if (w && h) + { + // resize with respect to glyph ratio + const float ratioX = (float)w / (float)h; + const float newX = DisplayMode_ThumbailsList_ImageHeight * ratioX; + float newY = w / ratioX; + if (newX < w) + newY = DisplayMode_ThumbailsList_ImageHeight; - const auto newWidth = (int)newX; - const auto newHeight = (int)newY; - const auto newBufSize = (size_t)(newWidth * newHeight * 4U); //-V112 //-V1028 - auto resizedData = new uint8_t[newBufSize]; - - const int resizeSucceeded = stbir_resize_uint8( - datas, w, h, 0, - resizedData, newWidth, newHeight, 0, - 4); //-V112 + const auto newWidth = (int)newX; + const auto newHeight = (int)newY; + const auto newBufSize = (size_t)(newWidth * newHeight * 4U); //-V112 //-V1028 + auto resizedData = new uint8_t[newBufSize]; + + const int resizeSucceeded = stbir_resize_uint8( + datas, w, h, 0, + resizedData, newWidth, newHeight, 0, + 4); //-V112 - if (resizeSucceeded) - { - auto th = &file->thumbnailInfo; + if (resizeSucceeded) + { + auto th = &file->thumbnailInfo; - th->textureFileDatas = resizedData; - th->textureWidth = newWidth; - th->textureHeight = newHeight; - th->textureChannels = 4; //-V112 + th->textureFileDatas = resizedData; + th->textureWidth = newWidth; + th->textureHeight = newHeight; + th->textureChannels = 4; //-V112 - // we set that at least, because will launch the gpu creation of the texture in the main thread - th->isReadyToUpload = true; + // we set that at least, because will launch the gpu creation of the texture in the main thread + th->isReadyToUpload = true; - // need gpu loading - prAddThumbnailToCreate(file); - } - } - else - { - printf("image loading fail : w:%i h:%i c:%i\n", w, h, 4); //-V112 - } + // need gpu loading + prAddThumbnailToCreate(file); + } + } + else + { + printf("image loading fail : w:%i h:%i c:%i\n", w, h, 4); //-V112 + } - stbi_image_free(datas); - } - } - } + stbi_image_free(datas); + } + } + } - // peu importe le resultat on vire le fichicer - // remove form this list - // write => thread concurency issues - prThumbnailFileDatasToGetMutex.lock(); - prThumbnailFileDatasToGet.pop_front(); - prThumbnailFileDatasToGetMutex.unlock(); - } - } - } - } + // peu importe le resultat on vire le fichicer + // remove form this list + // write => thread concurency issues + prThumbnailFileDatasToGetMutex.lock(); + prThumbnailFileDatasToGet.pop_front(); + prThumbnailFileDatasToGetMutex.unlock(); + } + } + } + } - inline void inVariadicProgressBar(float fraction, const ImVec2& size_arg, const char* fmt, ...) - { - va_list args; - va_start(args, fmt); - char TempBuffer[512]; - const int w = vsnprintf(TempBuffer, 511, fmt, args); - va_end(args); - if (w) - { - ImGui::ProgressBar(fraction, size_arg, TempBuffer); - } - } + inline void inVariadicProgressBar(float fraction, const ImVec2& size_arg, const char* fmt, ...) + { + va_list args; + va_start(args, fmt); + char TempBuffer[512]; + const int w = vsnprintf(TempBuffer, 511, fmt, args); + va_end(args); + if (w) + { + ImGui::ProgressBar(fraction, size_arg, TempBuffer); + } + } - void IGFD::ThumbnailFeature::prDrawThumbnailGenerationProgress() - { - if (prThumbnailGenerationThread.use_count() && prThumbnailGenerationThread->joinable()) - { - if (!prThumbnailFileDatasToGet.empty()) - { - const auto p = (float)((double)prCountFiles / (double)prThumbnailFileDatasToGet.size()); // read => no thread concurency issues - inVariadicProgressBar(p, ImVec2(50, 0), "%u/%u", prCountFiles, (uint32_t)prThumbnailFileDatasToGet.size()); // read => no thread concurency issues - ImGui::SameLine(); - } - } - } + void IGFD::ThumbnailFeature::prDrawThumbnailGenerationProgress() + { + if (prThumbnailGenerationThread.use_count() && prThumbnailGenerationThread->joinable()) + { + if (!prThumbnailFileDatasToGet.empty()) + { + const auto p = (float)((double)prCountFiles / (double)prThumbnailFileDatasToGet.size()); // read => no thread concurency issues + inVariadicProgressBar(p, ImVec2(50, 0), "%u/%u", prCountFiles, (uint32_t)prThumbnailFileDatasToGet.size()); // read => no thread concurency issues + ImGui::SameLine(); + } + } + } - void IGFD::ThumbnailFeature::prAddThumbnailToLoad(const std::shared_ptr& vFileInfos) - { - if (vFileInfos.use_count()) - { - if (vFileInfos->fileType == 'f') - { - if (vFileInfos->fileExt == ".png" - || vFileInfos->fileExt == ".bmp" - || vFileInfos->fileExt == ".tga" - || vFileInfos->fileExt == ".jpg" || vFileInfos->fileExt == ".jpeg" - || vFileInfos->fileExt == ".gif" - || vFileInfos->fileExt == ".psd" - || vFileInfos->fileExt == ".pic" - || vFileInfos->fileExt == ".ppm" || vFileInfos->fileExt == ".pgm" - //|| file->fileExt == ".hdr" => format float so in few times - ) - { - // write => thread concurency issues - prThumbnailFileDatasToGetMutex.lock(); - prThumbnailFileDatasToGet.push_back(vFileInfos); - vFileInfos->thumbnailInfo.isLoadingOrLoaded = true; - prThumbnailFileDatasToGetMutex.unlock(); - } - } - } - } - - void IGFD::ThumbnailFeature::prAddThumbnailToCreate(const std::shared_ptr& vFileInfos) - { - if (vFileInfos.use_count()) - { - // write => thread concurency issues - prThumbnailToCreateMutex.lock(); - prThumbnailToCreate.push_back(vFileInfos); - prThumbnailToCreateMutex.unlock(); - } - } + void IGFD::ThumbnailFeature::prAddThumbnailToLoad(const std::shared_ptr& vFileInfos) + { + if (vFileInfos.use_count()) + { + if (vFileInfos->fileType == 'f') + { + if (vFileInfos->fileExt == ".png" + || vFileInfos->fileExt == ".bmp" + || vFileInfos->fileExt == ".tga" + || vFileInfos->fileExt == ".jpg" || vFileInfos->fileExt == ".jpeg" + || vFileInfos->fileExt == ".gif" + || vFileInfos->fileExt == ".psd" + || vFileInfos->fileExt == ".pic" + || vFileInfos->fileExt == ".ppm" || vFileInfos->fileExt == ".pgm" + //|| file->fileExt == ".hdr" => format float so in few times + ) + { + // write => thread concurency issues + prThumbnailFileDatasToGetMutex.lock(); + prThumbnailFileDatasToGet.push_back(vFileInfos); + vFileInfos->thumbnailInfo.isLoadingOrLoaded = true; + prThumbnailFileDatasToGetMutex.unlock(); + } + } + } + } + + void IGFD::ThumbnailFeature::prAddThumbnailToCreate(const std::shared_ptr& vFileInfos) + { + if (vFileInfos.use_count()) + { + // write => thread concurency issues + prThumbnailToCreateMutex.lock(); + prThumbnailToCreate.push_back(vFileInfos); + prThumbnailToCreateMutex.unlock(); + } + } - void IGFD::ThumbnailFeature::prAddThumbnailToDestroy(const IGFD_Thumbnail_Info& vIGFD_Thumbnail_Info) - { - // write => thread concurency issues - prThumbnailToDestroyMutex.lock(); - prThumbnailToDestroy.push_back(vIGFD_Thumbnail_Info); - prThumbnailToDestroyMutex.unlock(); - } + void IGFD::ThumbnailFeature::prAddThumbnailToDestroy(const IGFD_Thumbnail_Info& vIGFD_Thumbnail_Info) + { + // write => thread concurency issues + prThumbnailToDestroyMutex.lock(); + prThumbnailToDestroy.push_back(vIGFD_Thumbnail_Info); + prThumbnailToDestroyMutex.unlock(); + } - void IGFD::ThumbnailFeature::prDrawDisplayModeToolBar() - { - if (IMGUI_RADIO_BUTTON(DisplayMode_FilesList_ButtonString, - prDisplayMode == DisplayModeEnum::FILE_LIST)) - prDisplayMode = DisplayModeEnum::FILE_LIST; - if (ImGui::IsItemHovered()) ImGui::SetTooltip(DisplayMode_FilesList_ButtonHelp); - ImGui::SameLine(); - if (IMGUI_RADIO_BUTTON(DisplayMode_ThumbailsList_ButtonString, - prDisplayMode == DisplayModeEnum::THUMBNAILS_LIST)) - prDisplayMode = DisplayModeEnum::THUMBNAILS_LIST; - if (ImGui::IsItemHovered()) ImGui::SetTooltip(DisplayMode_ThumbailsList_ButtonHelp); - ImGui::SameLine(); - /* todo - if (IMGUI_RADIO_BUTTON(DisplayMode_ThumbailsGrid_ButtonString, - prDisplayMode == DisplayModeEnum::THUMBNAILS_GRID)) - prDisplayMode = DisplayModeEnum::THUMBNAILS_GRID; - if (ImGui::IsItemHovered()) ImGui::SetTooltip(DisplayMode_ThumbailsGrid_ButtonHelp); - ImGui::SameLine(); - */ - prDrawThumbnailGenerationProgress(); - } + void IGFD::ThumbnailFeature::prDrawDisplayModeToolBar() + { + if (IMGUI_RADIO_BUTTON(DisplayMode_FilesList_ButtonString, + prDisplayMode == DisplayModeEnum::FILE_LIST)) + prDisplayMode = DisplayModeEnum::FILE_LIST; + if (ImGui::IsItemHovered()) ImGui::SetTooltip(DisplayMode_FilesList_ButtonHelp); + ImGui::SameLine(); + if (IMGUI_RADIO_BUTTON(DisplayMode_ThumbailsList_ButtonString, + prDisplayMode == DisplayModeEnum::THUMBNAILS_LIST)) + prDisplayMode = DisplayModeEnum::THUMBNAILS_LIST; + if (ImGui::IsItemHovered()) ImGui::SetTooltip(DisplayMode_ThumbailsList_ButtonHelp); + ImGui::SameLine(); + /* todo + if (IMGUI_RADIO_BUTTON(DisplayMode_ThumbailsGrid_ButtonString, + prDisplayMode == DisplayModeEnum::THUMBNAILS_GRID)) + prDisplayMode = DisplayModeEnum::THUMBNAILS_GRID; + if (ImGui::IsItemHovered()) ImGui::SetTooltip(DisplayMode_ThumbailsGrid_ButtonHelp); + ImGui::SameLine(); + */ + prDrawThumbnailGenerationProgress(); + } - void IGFD::ThumbnailFeature::prClearThumbnails(FileDialogInternal& vFileDialogInternal) - { - // directory wil be changed so the file list will be erased - if (vFileDialogInternal.puFileManager.puPathClicked) - { - size_t count = vFileDialogInternal.puFileManager.GetFullFileListSize(); - for (size_t idx = 0U; idx < count; idx++) - { - auto file = vFileDialogInternal.puFileManager.GetFullFileAt(idx); - if (file.use_count()) - { - if (file->thumbnailInfo.isReadyToDisplay) //-V522 - { - prAddThumbnailToDestroy(file->thumbnailInfo); - } - } - } - } - } + void IGFD::ThumbnailFeature::prClearThumbnails(FileDialogInternal& vFileDialogInternal) + { + // directory wil be changed so the file list will be erased + if (vFileDialogInternal.puFileManager.puPathClicked) + { + size_t count = vFileDialogInternal.puFileManager.GetFullFileListSize(); + for (size_t idx = 0U; idx < count; idx++) + { + auto file = vFileDialogInternal.puFileManager.GetFullFileAt(idx); + if (file.use_count()) + { + if (file->thumbnailInfo.isReadyToDisplay) //-V522 + { + prAddThumbnailToDestroy(file->thumbnailInfo); + } + } + } + } + } - void IGFD::ThumbnailFeature::SetCreateThumbnailCallback(const CreateThumbnailFun& vCreateThumbnailFun) - { - prCreateThumbnailFun = vCreateThumbnailFun; - } + void IGFD::ThumbnailFeature::SetCreateThumbnailCallback(const CreateThumbnailFun& vCreateThumbnailFun) + { + prCreateThumbnailFun = vCreateThumbnailFun; + } - void IGFD::ThumbnailFeature::SetDestroyThumbnailCallback(const DestroyThumbnailFun& vCreateThumbnailFun) - { - prDestroyThumbnailFun = vCreateThumbnailFun; - } + void IGFD::ThumbnailFeature::SetDestroyThumbnailCallback(const DestroyThumbnailFun& vCreateThumbnailFun) + { + prDestroyThumbnailFun = vCreateThumbnailFun; + } - void IGFD::ThumbnailFeature::ManageGPUThumbnails() - { - if (prCreateThumbnailFun) - { - if (!prThumbnailToCreate.empty()) - { - for (const auto& file : prThumbnailToCreate) - { - if (file.use_count()) - { - prCreateThumbnailFun(&file->thumbnailInfo); - } - } - prThumbnailToCreateMutex.lock(); - prThumbnailToCreate.clear(); - prThumbnailToCreateMutex.unlock(); - } - } - else - { - printf("No Callback found for create texture\nYou need to define the callback with a call to SetCreateThumbnailCallback\n"); - } + void IGFD::ThumbnailFeature::ManageGPUThumbnails() + { + if (prCreateThumbnailFun) + { + if (!prThumbnailToCreate.empty()) + { + for (const auto& file : prThumbnailToCreate) + { + if (file.use_count()) + { + prCreateThumbnailFun(&file->thumbnailInfo); + } + } + prThumbnailToCreateMutex.lock(); + prThumbnailToCreate.clear(); + prThumbnailToCreateMutex.unlock(); + } + } + else + { + printf("No Callback found for create texture\nYou need to define the callback with a call to SetCreateThumbnailCallback\n"); + } - if (prDestroyThumbnailFun) - { - if (!prThumbnailToDestroy.empty()) - { - for (auto thumbnail : prThumbnailToDestroy) - { - prDestroyThumbnailFun(&thumbnail); - } - prThumbnailToDestroyMutex.lock(); - prThumbnailToDestroy.clear(); - prThumbnailToDestroyMutex.unlock(); - } - } - else - { - printf("No Callback found for destroy texture\nYou need to define the callback with a call to SetCreateThumbnailCallback\n"); - } - } + if (prDestroyThumbnailFun) + { + if (!prThumbnailToDestroy.empty()) + { + for (auto thumbnail : prThumbnailToDestroy) + { + prDestroyThumbnailFun(&thumbnail); + } + prThumbnailToDestroyMutex.lock(); + prThumbnailToDestroy.clear(); + prThumbnailToDestroyMutex.unlock(); + } + } + else + { + printf("No Callback found for destroy texture\nYou need to define the callback with a call to SetCreateThumbnailCallback\n"); + } + } #endif // USE_THUMBNAILS - ///////////////////////////////////////////////////////////////////////////////////// - //// BOOKMARK FEATURE /////////////////////////////////////////////////////////////// - ///////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////////////////// + //// BOOKMARK FEATURE /////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////////////////// - IGFD::BookMarkFeature::BookMarkFeature() - { + IGFD::BookMarkFeature::BookMarkFeature() + { #ifdef USE_BOOKMARK - prBookmarkWidth = defaultBookmarkPaneWith; + prBookmarkWidth = defaultBookmarkPaneWith; #endif // USE_BOOKMARK - } + } #ifdef USE_BOOKMARK - void IGFD::BookMarkFeature::prDrawBookmarkButton() - { - IMGUI_TOGGLE_BUTTON(bookmarksButtonString, &prBookmarkPaneShown); + void IGFD::BookMarkFeature::prDrawBookmarkButton() + { + IMGUI_TOGGLE_BUTTON(bookmarksButtonString, &prBookmarkPaneShown); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip(bookmarksButtonHelpString); - } - bool IGFD::BookMarkFeature::prDrawBookmarkPane(FileDialogInternal& vFileDialogInternal, const ImVec2& vSize) - { - bool res = false; + if (ImGui::IsItemHovered()) + ImGui::SetTooltip(bookmarksButtonHelpString); + } + bool IGFD::BookMarkFeature::prDrawBookmarkPane(FileDialogInternal& vFileDialogInternal, const ImVec2& vSize) + { + bool res = false; - ImGui::BeginChild("##bookmarkpane", vSize); + ImGui::BeginChild("##bookmarkpane", vSize); - static int selectedBookmarkForEdition = -1; + static int selectedBookmarkForEdition = -1; - if (IMGUI_BUTTON(addBookmarkButtonString "##ImGuiFileDialogAddBookmark")) - { - if (!vFileDialogInternal.puFileManager.IsComposerEmpty()) - { - BookmarkStruct bookmark; - bookmark.name = vFileDialogInternal.puFileManager.GetBack(); - bookmark.path = vFileDialogInternal.puFileManager.GetCurrentPath(); - prBookmarks.push_back(bookmark); - } - } - if (selectedBookmarkForEdition >= 0 && - selectedBookmarkForEdition < (int)prBookmarks.size()) - { - ImGui::SameLine(); - if (IMGUI_BUTTON(removeBookmarkButtonString "##ImGuiFileDialogAddBookmark")) - { - prBookmarks.erase(prBookmarks.begin() + selectedBookmarkForEdition); - if (selectedBookmarkForEdition == (int)prBookmarks.size()) - selectedBookmarkForEdition--; - } + if (IMGUI_BUTTON(addBookmarkButtonString "##ImGuiFileDialogAddBookmark")) + { + if (!vFileDialogInternal.puFileManager.IsComposerEmpty()) + { + BookmarkStruct bookmark; + bookmark.name = vFileDialogInternal.puFileManager.GetBack(); + bookmark.path = vFileDialogInternal.puFileManager.GetCurrentPath(); + prBookmarks.push_back(bookmark); + } + } + if (selectedBookmarkForEdition >= 0 && + selectedBookmarkForEdition < (int)prBookmarks.size()) + { + ImGui::SameLine(); + if (IMGUI_BUTTON(removeBookmarkButtonString "##ImGuiFileDialogAddBookmark")) + { + prBookmarks.erase(prBookmarks.begin() + selectedBookmarkForEdition); + if (selectedBookmarkForEdition == (int)prBookmarks.size()) + selectedBookmarkForEdition--; + } - if (selectedBookmarkForEdition >= 0 && - selectedBookmarkForEdition < (int)prBookmarks.size()) - { - ImGui::SameLine(); + if (selectedBookmarkForEdition >= 0 && + selectedBookmarkForEdition < (int)prBookmarks.size()) + { + ImGui::SameLine(); - ImGui::PushItemWidth(vSize.x - ImGui::GetCursorPosX()); - if (ImGui::InputText("##ImGuiFileDialogBookmarkEdit", prBookmarkEditBuffer, MAX_FILE_DIALOG_NAME_BUFFER)) - { - prBookmarks[(size_t)selectedBookmarkForEdition].name = std::string(prBookmarkEditBuffer); - } - ImGui::PopItemWidth(); - } - } + ImGui::PushItemWidth(vSize.x - ImGui::GetCursorPosX()); + if (ImGui::InputText("##ImGuiFileDialogBookmarkEdit", prBookmarkEditBuffer, MAX_FILE_DIALOG_NAME_BUFFER)) + { + prBookmarks[(size_t)selectedBookmarkForEdition].name = std::string(prBookmarkEditBuffer); + } + ImGui::PopItemWidth(); + } + } - ImGui::Separator(); + ImGui::Separator(); - if (!prBookmarks.empty()) - { - prBookmarkClipper.Begin((int)prBookmarks.size(), ImGui::GetTextLineHeightWithSpacing()); - while (prBookmarkClipper.Step()) - { - for (int i = prBookmarkClipper.DisplayStart; i < prBookmarkClipper.DisplayEnd; i++) - { - if (i < 0) continue; - const BookmarkStruct& bookmark = prBookmarks[(size_t)i]; - ImGui::PushID(i); - if (ImGui::Selectable(bookmark.name.c_str(), selectedBookmarkForEdition == i, - ImGuiSelectableFlags_AllowDoubleClick) | - (selectedBookmarkForEdition == -1 && - bookmark.path == vFileDialogInternal.puFileManager.GetCurrentPath())) // select if path is current - { - selectedBookmarkForEdition = i; - IGFD::Utils::ResetBuffer(prBookmarkEditBuffer); - IGFD::Utils::AppendToBuffer(prBookmarkEditBuffer, MAX_FILE_DIALOG_NAME_BUFFER, bookmark.name); + if (!prBookmarks.empty()) + { + prBookmarkClipper.Begin((int)prBookmarks.size(), ImGui::GetTextLineHeightWithSpacing()); + while (prBookmarkClipper.Step()) + { + for (int i = prBookmarkClipper.DisplayStart; i < prBookmarkClipper.DisplayEnd; i++) + { + if (i < 0) continue; + const BookmarkStruct& bookmark = prBookmarks[(size_t)i]; + ImGui::PushID(i); + if (ImGui::Selectable(bookmark.name.c_str(), selectedBookmarkForEdition == i, + ImGuiSelectableFlags_AllowDoubleClick) | + (selectedBookmarkForEdition == -1 && + bookmark.path == vFileDialogInternal.puFileManager.GetCurrentPath())) // select if path is current + { + selectedBookmarkForEdition = i; + IGFD::Utils::ResetBuffer(prBookmarkEditBuffer); + IGFD::Utils::AppendToBuffer(prBookmarkEditBuffer, MAX_FILE_DIALOG_NAME_BUFFER, bookmark.name); - if (ImGui::IsMouseDoubleClicked(0)) // apply path - { - vFileDialogInternal.puFileManager.SetCurrentPath(bookmark.path); - vFileDialogInternal.puFileManager.OpenCurrentPath(vFileDialogInternal); - res = true; - } - } - ImGui::PopID(); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("%s", bookmark.path.c_str()); //-V111 - } - } - prBookmarkClipper.End(); - } + if (ImGui::IsMouseDoubleClicked(0)) // apply path + { + vFileDialogInternal.puFileManager.SetCurrentPath(bookmark.path); + vFileDialogInternal.puFileManager.OpenCurrentPath(vFileDialogInternal); + res = true; + } + } + ImGui::PopID(); + if (ImGui::IsItemHovered()) + ImGui::SetTooltip("%s", bookmark.path.c_str()); //-V111 + } + } + prBookmarkClipper.End(); + } - ImGui::EndChild(); + ImGui::EndChild(); - return res; - } + return res; + } - std::string IGFD::BookMarkFeature::SerializeBookmarks() - { - std::string res; + std::string IGFD::BookMarkFeature::SerializeBookmarks() + { + std::string res; - size_t idx = 0; - for (auto& it : prBookmarks) - { - if (idx++ != 0) - res += "##"; // ## because reserved by imgui, so an input text cant have ## - res += it.name + "##" + it.path; - } + size_t idx = 0; + for (auto& it : prBookmarks) + { + if (idx++ != 0) + res += "##"; // ## because reserved by imgui, so an input text cant have ## + res += it.name + "##" + it.path; + } - return res; - } + return res; + } - void IGFD::BookMarkFeature::DeserializeBookmarks(const std::string& vBookmarks) - { - if (!vBookmarks.empty()) - { - prBookmarks.clear(); - auto arr = IGFD::Utils::SplitStringToVector(vBookmarks, '#', false); - for (size_t i = 0; i < arr.size(); i += 2) - { - BookmarkStruct bookmark; - bookmark.name = arr[i]; - if (i + 1 < arr.size()) // for avoid crash if arr size is impair due to user mistake after edition - { - // if bad format we jump this bookmark - bookmark.path = arr[i + 1]; - prBookmarks.push_back(bookmark); - } - } - } - } + void IGFD::BookMarkFeature::DeserializeBookmarks(const std::string& vBookmarks) + { + if (!vBookmarks.empty()) + { + prBookmarks.clear(); + auto arr = IGFD::Utils::SplitStringToVector(vBookmarks, '#', false); + for (size_t i = 0; i < arr.size(); i += 2) + { + BookmarkStruct bookmark; + bookmark.name = arr[i]; + if (i + 1 < arr.size()) // for avoid crash if arr size is impair due to user mistake after edition + { + // if bad format we jump this bookmark + bookmark.path = arr[i + 1]; + prBookmarks.push_back(bookmark); + } + } + } + } #endif // USE_BOOKMARK - ///////////////////////////////////////////////////////////////////////////////////// - //// KEY EXPLORER FEATURE /////////////////////////////////////////////////////////// - ///////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////////////////// + //// KEY EXPLORER FEATURE /////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////////////////// - KeyExplorerFeature::KeyExplorerFeature() = default; + KeyExplorerFeature::KeyExplorerFeature() = default; #ifdef USE_EXPLORATION_BY_KEYS - bool IGFD::KeyExplorerFeature::prLocateItem_Loop(FileDialogInternal& vFileDialogInternal, ImWchar vC) - { - bool found = false; + bool IGFD::KeyExplorerFeature::prLocateItem_Loop(FileDialogInternal& vFileDialogInternal, ImWchar vC) + { + bool found = false; - auto& fdi = vFileDialogInternal.puFileManager; - if (!fdi.IsFilteredListEmpty()) - { - auto countFiles = fdi.GetFilteredListSize(); - for (size_t i = prLocateFileByInputChar_lastFileIdx; i < countFiles; i++) - { - auto nfo = fdi.GetFilteredFileAt(i); - if (nfo.use_count()) - { - if (nfo->fileNameExt_optimized[0] == vC || // lower case search //-V522 - nfo->fileNameExt[0] == vC) // maybe upper case search - { - //float p = ((float)i) * ImGui::GetTextLineHeightWithSpacing(); - float p = (float)((double)i / (double)countFiles) * ImGui::GetScrollMaxY(); - ImGui::SetScrollY(p); - prLocateFileByInputChar_lastFound = true; - prLocateFileByInputChar_lastFileIdx = i; - prStartFlashItem(prLocateFileByInputChar_lastFileIdx); + auto& fdi = vFileDialogInternal.puFileManager; + if (!fdi.IsFilteredListEmpty()) + { + auto countFiles = fdi.GetFilteredListSize(); + for (size_t i = prLocateFileByInputChar_lastFileIdx; i < countFiles; i++) + { + auto nfo = fdi.GetFilteredFileAt(i); + if (nfo.use_count()) + { + if (nfo->fileNameExt_optimized[0] == vC || // lower case search //-V522 + nfo->fileNameExt[0] == vC) // maybe upper case search + { + //float p = ((float)i) * ImGui::GetTextLineHeightWithSpacing(); + float p = (float)((double)i / (double)countFiles) * ImGui::GetScrollMaxY(); + ImGui::SetScrollY(p); + prLocateFileByInputChar_lastFound = true; + prLocateFileByInputChar_lastFileIdx = i; + prStartFlashItem(prLocateFileByInputChar_lastFileIdx); - auto infos = fdi.GetFilteredFileAt(prLocateFileByInputChar_lastFileIdx); - if (infos.use_count()) - { - if (infos->fileType == 'd') //-V522 - { - if (fdi.puDLGDirectoryMode) // directory chooser - { - fdi.SelectFileName(vFileDialogInternal, infos); - } - } - else - { - fdi.SelectFileName(vFileDialogInternal, infos); - } + auto infos = fdi.GetFilteredFileAt(prLocateFileByInputChar_lastFileIdx); + if (infos.use_count()) + { + if (infos->fileType == 'd') //-V522 + { + if (fdi.puDLGDirectoryMode) // directory chooser + { + fdi.SelectFileName(vFileDialogInternal, infos); + } + } + else + { + fdi.SelectFileName(vFileDialogInternal, infos); + } - found = true; - break; - } - } - } - } - } + found = true; + break; + } + } + } + } + } - return found; - } + return found; + } - void IGFD::KeyExplorerFeature::prLocateByInputKey(FileDialogInternal& vFileDialogInternal) - { - ImGuiContext& g = *GImGui; - auto& fdi = vFileDialogInternal.puFileManager; - if (!g.ActiveId && !fdi.IsFilteredListEmpty()) - { - auto& queueChar = ImGui::GetIO().InputQueueCharacters; - auto countFiles = fdi.GetFilteredListSize(); + void IGFD::KeyExplorerFeature::prLocateByInputKey(FileDialogInternal& vFileDialogInternal) + { + ImGuiContext& g = *GImGui; + auto& fdi = vFileDialogInternal.puFileManager; + if (!g.ActiveId && !fdi.IsFilteredListEmpty()) + { + auto& queueChar = ImGui::GetIO().InputQueueCharacters; + auto countFiles = fdi.GetFilteredListSize(); - // point by char - if (!queueChar.empty()) - { - ImWchar c = queueChar.back(); - if (prLocateFileByInputChar_InputQueueCharactersSize != queueChar.size()) - { - if (c == prLocateFileByInputChar_lastChar) // next file starting with same char until - { - if (prLocateFileByInputChar_lastFileIdx < countFiles - 1U) - prLocateFileByInputChar_lastFileIdx++; - else - prLocateFileByInputChar_lastFileIdx = 0; - } + // point by char + if (!queueChar.empty()) + { + ImWchar c = queueChar.back(); + if (prLocateFileByInputChar_InputQueueCharactersSize != queueChar.size()) + { + if (c == prLocateFileByInputChar_lastChar) // next file starting with same char until + { + if (prLocateFileByInputChar_lastFileIdx < countFiles - 1U) + prLocateFileByInputChar_lastFileIdx++; + else + prLocateFileByInputChar_lastFileIdx = 0; + } - if (!prLocateItem_Loop(vFileDialogInternal, c)) - { - // not found, loop again from 0 this time - prLocateFileByInputChar_lastFileIdx = 0; - prLocateItem_Loop(vFileDialogInternal, c); - } + if (!prLocateItem_Loop(vFileDialogInternal, c)) + { + // not found, loop again from 0 this time + prLocateFileByInputChar_lastFileIdx = 0; + prLocateItem_Loop(vFileDialogInternal, c); + } - prLocateFileByInputChar_lastChar = c; - } - } + prLocateFileByInputChar_lastChar = c; + } + } - prLocateFileByInputChar_InputQueueCharactersSize = queueChar.size(); - } - } + prLocateFileByInputChar_InputQueueCharactersSize = queueChar.size(); + } + } - void IGFD::KeyExplorerFeature::prExploreWithkeys(FileDialogInternal& vFileDialogInternal, ImGuiID vListViewID) - { - auto& fdi = vFileDialogInternal.puFileManager; - if (!fdi.IsFilteredListEmpty()) - { - bool canWeExplore = false; - bool hasNav = (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard); - - ImGuiContext& g = *GImGui; - if (!hasNav && !g.ActiveId) // no nav and no activated inputs - canWeExplore = true; + void IGFD::KeyExplorerFeature::prExploreWithkeys(FileDialogInternal& vFileDialogInternal, ImGuiID vListViewID) + { + auto& fdi = vFileDialogInternal.puFileManager; + if (!fdi.IsFilteredListEmpty()) + { + bool canWeExplore = false; + bool hasNav = (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard); + + ImGuiContext& g = *GImGui; + if (!hasNav && !g.ActiveId) // no nav and no activated inputs + canWeExplore = true; - if (g.NavId && g.NavId == vListViewID) - { - if (ImGui::IsKeyPressedMap(IGFD_KEY_ENTER) || - ImGui::IsKeyPressedMap(ImGuiKey_KeyPadEnter) || - ImGui::IsKeyPressedMap(ImGuiKey_Space)) - { - ImGui::ActivateItem(vListViewID); - ImGui::SetActiveID(vListViewID, g.CurrentWindow); - } - } - - if (vListViewID == g.LastActiveId-1) // if listview id is the last acticated nav id (ImGui::ActivateItem(vListViewID);) - canWeExplore = true; + if (g.NavId && g.NavId == vListViewID) + { + if (ImGui::IsKeyPressedMap(IGFD_KEY_ENTER) || + ImGui::IsKeyPressedMap(ImGuiKey_KeyPadEnter) || + ImGui::IsKeyPressedMap(ImGuiKey_Space)) + { + ImGui::ActivateItem(vListViewID); + ImGui::SetActiveID(vListViewID, g.CurrentWindow); + } + } + + if (vListViewID == g.LastActiveId-1) // if listview id is the last acticated nav id (ImGui::ActivateItem(vListViewID);) + canWeExplore = true; - if (canWeExplore) - { - if (ImGui::IsKeyPressedMap(ImGuiKey_Escape)) - { - ImGui::ClearActiveID(); - g.LastActiveId = 0; - } + if (canWeExplore) + { + if (ImGui::IsKeyPressedMap(ImGuiKey_Escape)) + { + ImGui::ClearActiveID(); + g.LastActiveId = 0; + } - auto countFiles = fdi.GetFilteredListSize(); + auto countFiles = fdi.GetFilteredListSize(); - // explore - bool exploreByKey = false; - bool enterInDirectory = false; - bool exitDirectory = false; + // explore + bool exploreByKey = false; + bool enterInDirectory = false; + bool exitDirectory = false; - if ((hasNav && ImGui::IsKeyPressedMap(ImGuiKey_UpArrow)) || (!hasNav && ImGui::IsKeyPressed(IGFD_KEY_UP))) - { - exploreByKey = true; - if (prLocateFileByInputChar_lastFileIdx > 0) - prLocateFileByInputChar_lastFileIdx--; - else - prLocateFileByInputChar_lastFileIdx = countFiles - 1U; - } - else if ((hasNav && ImGui::IsKeyPressedMap(ImGuiKey_DownArrow)) || (!hasNav && ImGui::IsKeyPressed(IGFD_KEY_DOWN))) - { - exploreByKey = true; - if (prLocateFileByInputChar_lastFileIdx < countFiles - 1U) - prLocateFileByInputChar_lastFileIdx++; - else - prLocateFileByInputChar_lastFileIdx = 0U; - } - else if (ImGui::IsKeyReleased(IGFD_KEY_ENTER)) - { - exploreByKey = true; - enterInDirectory = true; - } - else if (ImGui::IsKeyReleased(IGFD_KEY_BACKSPACE)) - { - exploreByKey = true; - exitDirectory = true; - } + if ((hasNav && ImGui::IsKeyPressedMap(ImGuiKey_UpArrow)) || (!hasNav && ImGui::IsKeyPressed(IGFD_KEY_UP))) + { + exploreByKey = true; + if (prLocateFileByInputChar_lastFileIdx > 0) + prLocateFileByInputChar_lastFileIdx--; + else + prLocateFileByInputChar_lastFileIdx = countFiles - 1U; + } + else if ((hasNav && ImGui::IsKeyPressedMap(ImGuiKey_DownArrow)) || (!hasNav && ImGui::IsKeyPressed(IGFD_KEY_DOWN))) + { + exploreByKey = true; + if (prLocateFileByInputChar_lastFileIdx < countFiles - 1U) + prLocateFileByInputChar_lastFileIdx++; + else + prLocateFileByInputChar_lastFileIdx = 0U; + } + else if (ImGui::IsKeyReleased(IGFD_KEY_ENTER)) + { + exploreByKey = true; + enterInDirectory = true; + } + else if (ImGui::IsKeyReleased(IGFD_KEY_BACKSPACE)) + { + exploreByKey = true; + exitDirectory = true; + } - if (exploreByKey) - { - //float totalHeight = prFilteredFileList.size() * ImGui::GetTextLineHeightWithSpacing(); - float p = (float)((double)prLocateFileByInputChar_lastFileIdx / (double)(countFiles - 1U)) * ImGui::GetScrollMaxY();// seems not udpated in tables version outside tables - //float p = ((float)locateFileByInputChar_lastFileIdx) * ImGui::GetTextLineHeightWithSpacing(); - ImGui::SetScrollY(p); - prStartFlashItem(prLocateFileByInputChar_lastFileIdx); + if (exploreByKey) + { + //float totalHeight = prFilteredFileList.size() * ImGui::GetTextLineHeightWithSpacing(); + float p = (float)((double)prLocateFileByInputChar_lastFileIdx / (double)(countFiles - 1U)) * ImGui::GetScrollMaxY();// seems not udpated in tables version outside tables + //float p = ((float)locateFileByInputChar_lastFileIdx) * ImGui::GetTextLineHeightWithSpacing(); + ImGui::SetScrollY(p); + prStartFlashItem(prLocateFileByInputChar_lastFileIdx); - auto infos = fdi.GetFilteredFileAt(prLocateFileByInputChar_lastFileIdx); - if (infos.use_count()) - { - if (infos->fileType == 'd') //-V522 - { - if (!fdi.puDLGDirectoryMode || enterInDirectory) - { - if (enterInDirectory) - { - if (fdi.SelectDirectory(infos)) - { - // changement de repertoire - vFileDialogInternal.puFileManager.OpenCurrentPath(vFileDialogInternal); - if (prLocateFileByInputChar_lastFileIdx > countFiles - 1U) - { - prLocateFileByInputChar_lastFileIdx = 0; - } - } - } - } - else // directory chooser - { - fdi.SelectFileName(vFileDialogInternal, infos); - } - } - else - { - fdi.SelectFileName(vFileDialogInternal, infos); - } + auto infos = fdi.GetFilteredFileAt(prLocateFileByInputChar_lastFileIdx); + if (infos.use_count()) + { + if (infos->fileType == 'd') //-V522 + { + if (!fdi.puDLGDirectoryMode || enterInDirectory) + { + if (enterInDirectory) + { + if (fdi.SelectDirectory(infos)) + { + // changement de repertoire + vFileDialogInternal.puFileManager.OpenCurrentPath(vFileDialogInternal); + if (prLocateFileByInputChar_lastFileIdx > countFiles - 1U) + { + prLocateFileByInputChar_lastFileIdx = 0; + } + } + } + } + else // directory chooser + { + fdi.SelectFileName(vFileDialogInternal, infos); + } + } + else + { + fdi.SelectFileName(vFileDialogInternal, infos); + } - if (exitDirectory) - { - auto nfo = std::make_shared(); - nfo->fileNameExt = ".."; + if (exitDirectory) + { + auto nfo = std::make_shared(); + nfo->fileNameExt = ".."; - if (fdi.SelectDirectory(nfo)) - { - // changement de repertoire - vFileDialogInternal.puFileManager.OpenCurrentPath(vFileDialogInternal); - if (prLocateFileByInputChar_lastFileIdx > countFiles - 1U) - { - prLocateFileByInputChar_lastFileIdx = 0; - } - } + if (fdi.SelectDirectory(nfo)) + { + // changement de repertoire + vFileDialogInternal.puFileManager.OpenCurrentPath(vFileDialogInternal); + if (prLocateFileByInputChar_lastFileIdx > countFiles - 1U) + { + prLocateFileByInputChar_lastFileIdx = 0; + } + } #ifdef WIN32 - else - { - if (fdi.GetComposerSize() == 1U) - { - if (fdi.GetDrives()) - { - fdi.ApplyFilteringOnFileList(vFileDialogInternal); - } - } - } + else + { + if (fdi.GetComposerSize() == 1U) + { + if (fdi.GetDrives()) + { + fdi.ApplyFilteringOnFileList(vFileDialogInternal); + } + } + } #endif // WIN32 - } - } - } - } - } - } + } + } + } + } + } + } - bool IGFD::KeyExplorerFeature::prFlashableSelectable(const char* label, bool selected, - ImGuiSelectableFlags flags, bool vFlashing, const ImVec2& size_arg) - { - using namespace ImGui; + bool IGFD::KeyExplorerFeature::prFlashableSelectable(const char* label, bool selected, + ImGuiSelectableFlags flags, bool vFlashing, const ImVec2& size_arg) + { + using namespace ImGui; - ImGuiWindow* window = GetCurrentWindow(); - if (window->SkipItems) - return false; + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return false; - ImGuiContext& g = *GImGui; - const ImGuiStyle& style = g.Style; + ImGuiContext& g = *GImGui; + const ImGuiStyle& style = g.Style; - // Submit label or explicit size to ItemSize(), whereas ItemAdd() will submit a larger/spanning rectangle. - ImGuiID id = window->GetID(label); - ImVec2 label_size = CalcTextSize(label, nullptr, true); - ImVec2 size(size_arg.x != 0.0f ? size_arg.x : label_size.x, size_arg.y != 0.0f ? size_arg.y : label_size.y); //-V550 - ImVec2 pos = window->DC.CursorPos; - pos.y += window->DC.CurrLineTextBaseOffset; - ItemSize(size, 0.0f); + // Submit label or explicit size to ItemSize(), whereas ItemAdd() will submit a larger/spanning rectangle. + ImGuiID id = window->GetID(label); + ImVec2 label_size = CalcTextSize(label, nullptr, true); + ImVec2 size(size_arg.x != 0.0f ? size_arg.x : label_size.x, size_arg.y != 0.0f ? size_arg.y : label_size.y); //-V550 + ImVec2 pos = window->DC.CursorPos; + pos.y += window->DC.CurrLineTextBaseOffset; + ItemSize(size, 0.0f); - // Fill horizontal space - // We don't support (size < 0.0f) in Selectable() because the ItemSpacing extension would make explicitly right-aligned sizes not visibly match other widgets. - const bool span_all_columns = (flags & ImGuiSelectableFlags_SpanAllColumns) != 0; - const float min_x = span_all_columns ? window->ParentWorkRect.Min.x : pos.x; - const float max_x = span_all_columns ? window->ParentWorkRect.Max.x : window->WorkRect.Max.x; - if (fabs(size_arg.x) < FLT_EPSILON || (flags & ImGuiSelectableFlags_SpanAvailWidth)) - size.x = ImMax(label_size.x, max_x - min_x); + // Fill horizontal space + // We don't support (size < 0.0f) in Selectable() because the ItemSpacing extension would make explicitly right-aligned sizes not visibly match other widgets. + const bool span_all_columns = (flags & ImGuiSelectableFlags_SpanAllColumns) != 0; + const float min_x = span_all_columns ? window->ParentWorkRect.Min.x : pos.x; + const float max_x = span_all_columns ? window->ParentWorkRect.Max.x : window->WorkRect.Max.x; + if (fabs(size_arg.x) < FLT_EPSILON || (flags & ImGuiSelectableFlags_SpanAvailWidth)) + size.x = ImMax(label_size.x, max_x - min_x); - // Text stays at the submission position, but bounding box may be extended on both sides - const ImVec2 text_min = pos; - const ImVec2 text_max(min_x + size.x, pos.y + size.y); + // Text stays at the submission position, but bounding box may be extended on both sides + const ImVec2 text_min = pos; + const ImVec2 text_max(min_x + size.x, pos.y + size.y); - // Selectables are meant to be tightly packed together with no click-gap, so we extend their box to cover spacing between selectable. - ImRect bb(min_x, pos.y, text_max.x, text_max.y); - if ((flags & ImGuiSelectableFlags_NoPadWithHalfSpacing) == 0) - { - const float spacing_x = span_all_columns ? 0.0f : style.ItemSpacing.x; - const float spacing_y = style.ItemSpacing.y; - const float spacing_L = IM_FLOOR(spacing_x * 0.50f); - const float spacing_U = IM_FLOOR(spacing_y * 0.50f); - bb.Min.x -= spacing_L; - bb.Min.y -= spacing_U; - bb.Max.x += (spacing_x - spacing_L); - bb.Max.y += (spacing_y - spacing_U); - } - //if (g.IO.KeyCtrl) { GetForegroundDrawList()->AddRect(bb.Min, bb.Max, IM_COL32(0, 255, 0, 255)); } + // Selectables are meant to be tightly packed together with no click-gap, so we extend their box to cover spacing between selectable. + ImRect bb(min_x, pos.y, text_max.x, text_max.y); + if ((flags & ImGuiSelectableFlags_NoPadWithHalfSpacing) == 0) + { + const float spacing_x = span_all_columns ? 0.0f : style.ItemSpacing.x; + const float spacing_y = style.ItemSpacing.y; + const float spacing_L = IM_FLOOR(spacing_x * 0.50f); + const float spacing_U = IM_FLOOR(spacing_y * 0.50f); + bb.Min.x -= spacing_L; + bb.Min.y -= spacing_U; + bb.Max.x += (spacing_x - spacing_L); + bb.Max.y += (spacing_y - spacing_U); + } + //if (g.IO.KeyCtrl) { GetForegroundDrawList()->AddRect(bb.Min, bb.Max, IM_COL32(0, 255, 0, 255)); } - // Modify ClipRect for the ItemAdd(), faster than doing a PushColumnsBackground/PushTableBackground for every Selectable.. - const float backup_clip_rect_min_x = window->ClipRect.Min.x; - const float backup_clip_rect_max_x = window->ClipRect.Max.x; - if (span_all_columns) - { - window->ClipRect.Min.x = window->ParentWorkRect.Min.x; - window->ClipRect.Max.x = window->ParentWorkRect.Max.x; - } + // Modify ClipRect for the ItemAdd(), faster than doing a PushColumnsBackground/PushTableBackground for every Selectable.. + const float backup_clip_rect_min_x = window->ClipRect.Min.x; + const float backup_clip_rect_max_x = window->ClipRect.Max.x; + if (span_all_columns) + { + window->ClipRect.Min.x = window->ParentWorkRect.Min.x; + window->ClipRect.Max.x = window->ParentWorkRect.Max.x; + } - bool item_add; - const bool disabled_item = (flags & ImGuiSelectableFlags_Disabled) != 0; - if (disabled_item) - { - ImGuiItemFlags backup_item_flags = g.CurrentItemFlags; - g.CurrentItemFlags |= ImGuiItemFlags_Disabled; - item_add = ItemAdd(bb, id); - g.CurrentItemFlags = backup_item_flags; - } - else - { - item_add = ItemAdd(bb, id); - } + bool item_add; + const bool disabled_item = (flags & ImGuiSelectableFlags_Disabled) != 0; + if (disabled_item) + { + ImGuiItemFlags backup_item_flags = g.CurrentItemFlags; + g.CurrentItemFlags |= ImGuiItemFlags_Disabled; + item_add = ItemAdd(bb, id); + g.CurrentItemFlags = backup_item_flags; + } + else + { + item_add = ItemAdd(bb, id); + } - if (span_all_columns) - { - window->ClipRect.Min.x = backup_clip_rect_min_x; - window->ClipRect.Max.x = backup_clip_rect_max_x; - } + if (span_all_columns) + { + window->ClipRect.Min.x = backup_clip_rect_min_x; + window->ClipRect.Max.x = backup_clip_rect_max_x; + } - if (!item_add) - return false; + if (!item_add) + return false; - const bool disabled_global = (g.CurrentItemFlags & ImGuiItemFlags_Disabled) != 0; - if (disabled_item && !disabled_global) // Only testing this as an optimization - BeginDisabled(true); + const bool disabled_global = (g.CurrentItemFlags & ImGuiItemFlags_Disabled) != 0; + if (disabled_item && !disabled_global) // Only testing this as an optimization + BeginDisabled(true); - // FIXME: We can standardize the behavior of those two, we could also keep the fast path of override ClipRect + full push on render only, - // which would be advantageous since most selectable are not selected. - if (span_all_columns && window->DC.CurrentColumns) - PushColumnsBackground(); - else if (span_all_columns && g.CurrentTable) - TablePushBackgroundChannel(); + // FIXME: We can standardize the behavior of those two, we could also keep the fast path of override ClipRect + full push on render only, + // which would be advantageous since most selectable are not selected. + if (span_all_columns && window->DC.CurrentColumns) + PushColumnsBackground(); + else if (span_all_columns && g.CurrentTable) + TablePushBackgroundChannel(); - // We use NoHoldingActiveID on menus so user can click and _hold_ on a menu then drag to browse child entries - ImGuiButtonFlags button_flags = 0; - if (flags & ImGuiSelectableFlags_NoHoldingActiveID) { button_flags |= ImGuiButtonFlags_NoHoldingActiveId; } - if (flags & ImGuiSelectableFlags_SelectOnClick) { button_flags |= ImGuiButtonFlags_PressedOnClick; } - if (flags & ImGuiSelectableFlags_SelectOnRelease) { button_flags |= ImGuiButtonFlags_PressedOnRelease; } - if (flags & ImGuiSelectableFlags_AllowDoubleClick) { button_flags |= ImGuiButtonFlags_PressedOnClickRelease | ImGuiButtonFlags_PressedOnDoubleClick; } - if (flags & ImGuiSelectableFlags_AllowItemOverlap) { button_flags |= ImGuiButtonFlags_AllowItemOverlap; } + // We use NoHoldingActiveID on menus so user can click and _hold_ on a menu then drag to browse child entries + ImGuiButtonFlags button_flags = 0; + if (flags & ImGuiSelectableFlags_NoHoldingActiveID) { button_flags |= ImGuiButtonFlags_NoHoldingActiveId; } + if (flags & ImGuiSelectableFlags_SelectOnClick) { button_flags |= ImGuiButtonFlags_PressedOnClick; } + if (flags & ImGuiSelectableFlags_SelectOnRelease) { button_flags |= ImGuiButtonFlags_PressedOnRelease; } + if (flags & ImGuiSelectableFlags_AllowDoubleClick) { button_flags |= ImGuiButtonFlags_PressedOnClickRelease | ImGuiButtonFlags_PressedOnDoubleClick; } + if (flags & ImGuiSelectableFlags_AllowItemOverlap) { button_flags |= ImGuiButtonFlags_AllowItemOverlap; } - const bool was_selected = selected; - bool hovered, held; - bool pressed = ButtonBehavior(bb, id, &hovered, &held, button_flags); + const bool was_selected = selected; + bool hovered, held; + bool pressed = ButtonBehavior(bb, id, &hovered, &held, button_flags); - // Auto-select when moved into - // - This will be more fully fleshed in the range-select branch - // - This is not exposed as it won't nicely work with some user side handling of shift/control - // - We cannot do 'if (g.NavJustMovedToId != id) { selected = false; pressed = was_selected; }' for two reasons - // - (1) it would require focus scope to be set, need exposing PushFocusScope() or equivalent (e.g. BeginSelection() calling PushFocusScope()) - // - (2) usage will fail with clipped items - // The multi-select API aim to fix those issues, e.g. may be replaced with a BeginSelection() API. - if ((flags & ImGuiSelectableFlags_SelectOnNav) && g.NavJustMovedToId != 0 && g.NavJustMovedToFocusScopeId == window->DC.NavFocusScopeIdCurrent) - if (g.NavJustMovedToId == id) - selected = pressed = true; + // Auto-select when moved into + // - This will be more fully fleshed in the range-select branch + // - This is not exposed as it won't nicely work with some user side handling of shift/control + // - We cannot do 'if (g.NavJustMovedToId != id) { selected = false; pressed = was_selected; }' for two reasons + // - (1) it would require focus scope to be set, need exposing PushFocusScope() or equivalent (e.g. BeginSelection() calling PushFocusScope()) + // - (2) usage will fail with clipped items + // The multi-select API aim to fix those issues, e.g. may be replaced with a BeginSelection() API. + if ((flags & ImGuiSelectableFlags_SelectOnNav) && g.NavJustMovedToId != 0 && g.NavJustMovedToFocusScopeId == window->DC.NavFocusScopeIdCurrent) + if (g.NavJustMovedToId == id) + selected = pressed = true; - // Update NavId when clicking or when Hovering (this doesn't happen on most widgets), so navigation can be resumed with gamepad/keyboard - if (pressed || (hovered && (flags & ImGuiSelectableFlags_SetNavIdOnHover))) - { - if (!g.NavDisableMouseHover && g.NavWindow == window && g.NavLayer == window->DC.NavLayerCurrent) - { - SetNavID(id, window->DC.NavLayerCurrent, window->DC.NavFocusScopeIdCurrent, ImRect(bb.Min - window->Pos, bb.Max - window->Pos)); - g.NavDisableHighlight = true; - } - } - if (pressed) - MarkItemEdited(id); + // Update NavId when clicking or when Hovering (this doesn't happen on most widgets), so navigation can be resumed with gamepad/keyboard + if (pressed || (hovered && (flags & ImGuiSelectableFlags_SetNavIdOnHover))) + { + if (!g.NavDisableMouseHover && g.NavWindow == window && g.NavLayer == window->DC.NavLayerCurrent) + { + SetNavID(id, window->DC.NavLayerCurrent, window->DC.NavFocusScopeIdCurrent, ImRect(bb.Min - window->Pos, bb.Max - window->Pos)); + g.NavDisableHighlight = true; + } + } + if (pressed) + MarkItemEdited(id); - if (flags & ImGuiSelectableFlags_AllowItemOverlap) - SetItemAllowOverlap(); + if (flags & ImGuiSelectableFlags_AllowItemOverlap) + SetItemAllowOverlap(); - // In this branch, Selectable() cannot toggle the selection so this will never trigger. - if (selected != was_selected) //-V547 - g.LastItemData.StatusFlags |= ImGuiItemStatusFlags_ToggledSelection; + // In this branch, Selectable() cannot toggle the selection so this will never trigger. + if (selected != was_selected) //-V547 + g.LastItemData.StatusFlags |= ImGuiItemStatusFlags_ToggledSelection; - // Render - if ((held && (flags & ImGuiSelectableFlags_DrawHoveredWhenHeld)) || vFlashing) - hovered = true; - if (hovered || selected) - { - const ImU32 col = GetColorU32((held && hovered) ? ImGuiCol_HeaderActive : hovered ? ImGuiCol_HeaderHovered : ImGuiCol_Header); - RenderFrame(bb.Min, bb.Max, col, false, 0.0f); - } - RenderNavHighlight(bb, id, ImGuiNavHighlightFlags_TypeThin | ImGuiNavHighlightFlags_NoRounding); + // Render + if ((held && (flags & ImGuiSelectableFlags_DrawHoveredWhenHeld)) || vFlashing) + hovered = true; + if (hovered || selected) + { + const ImU32 col = GetColorU32((held && hovered) ? ImGuiCol_HeaderActive : hovered ? ImGuiCol_HeaderHovered : ImGuiCol_Header); + RenderFrame(bb.Min, bb.Max, col, false, 0.0f); + } + RenderNavHighlight(bb, id, ImGuiNavHighlightFlags_TypeThin | ImGuiNavHighlightFlags_NoRounding); - if (span_all_columns && window->DC.CurrentColumns) - PopColumnsBackground(); - else if (span_all_columns && g.CurrentTable) - TablePopBackgroundChannel(); + if (span_all_columns && window->DC.CurrentColumns) + PopColumnsBackground(); + else if (span_all_columns && g.CurrentTable) + TablePopBackgroundChannel(); - RenderTextClipped(text_min, text_max, label, nullptr, &label_size, style.SelectableTextAlign, &bb); + RenderTextClipped(text_min, text_max, label, nullptr, &label_size, style.SelectableTextAlign, &bb); - // Automatically close popups - if (pressed && (window->Flags & ImGuiWindowFlags_Popup) && !(flags & ImGuiSelectableFlags_DontClosePopups) && !(g.LastItemData.InFlags & ImGuiItemFlags_SelectableDontClosePopup)) - CloseCurrentPopup(); + // Automatically close popups + if (pressed && (window->Flags & ImGuiWindowFlags_Popup) && !(flags & ImGuiSelectableFlags_DontClosePopups) && !(g.LastItemData.InFlags & ImGuiItemFlags_SelectableDontClosePopup)) + CloseCurrentPopup(); - if (disabled_item && !disabled_global) - EndDisabled(); + if (disabled_item && !disabled_global) + EndDisabled(); - IMGUI_TEST_ENGINE_ITEM_INFO(id, label, g.LastItemData.StatusFlags); - return pressed; //-V1020 - } + IMGUI_TEST_ENGINE_ITEM_INFO(id, label, g.LastItemData.StatusFlags); + return pressed; //-V1020 + } - void IGFD::KeyExplorerFeature::prStartFlashItem(size_t vIdx) - { - prFlashAlpha = 1.0f; - prFlashedItem = vIdx; - } + void IGFD::KeyExplorerFeature::prStartFlashItem(size_t vIdx) + { + prFlashAlpha = 1.0f; + prFlashedItem = vIdx; + } - bool IGFD::KeyExplorerFeature::prBeginFlashItem(size_t vIdx) - { - bool res = false; + bool IGFD::KeyExplorerFeature::prBeginFlashItem(size_t vIdx) + { + bool res = false; - if (prFlashedItem == vIdx && - std::abs(prFlashAlpha - 0.0f) > 0.00001f) - { - prFlashAlpha -= prFlashAlphaAttenInSecs * ImGui::GetIO().DeltaTime; - if (prFlashAlpha < 0.0f) prFlashAlpha = 0.0f; + if (prFlashedItem == vIdx && + std::abs(prFlashAlpha - 0.0f) > 0.00001f) + { + prFlashAlpha -= prFlashAlphaAttenInSecs * ImGui::GetIO().DeltaTime; + if (prFlashAlpha < 0.0f) prFlashAlpha = 0.0f; - ImVec4 hov = ImGui::GetStyleColorVec4(ImGuiCol_HeaderHovered); - hov.w = prFlashAlpha; - ImGui::PushStyleColor(ImGuiCol_HeaderHovered, hov); - res = true; - } + ImVec4 hov = ImGui::GetStyleColorVec4(ImGuiCol_HeaderHovered); + hov.w = prFlashAlpha; + ImGui::PushStyleColor(ImGuiCol_HeaderHovered, hov); + res = true; + } - return res; - } + return res; + } - void IGFD::KeyExplorerFeature::prEndFlashItem() - { - ImGui::PopStyleColor(); - } + void IGFD::KeyExplorerFeature::prEndFlashItem() + { + ImGui::PopStyleColor(); + } - void IGFD::KeyExplorerFeature::SetFlashingAttenuationInSeconds(float vAttenValue) - { - prFlashAlphaAttenInSecs = 1.0f / ImMax(vAttenValue, 0.01f); - } + void IGFD::KeyExplorerFeature::SetFlashingAttenuationInSeconds(float vAttenValue) + { + prFlashAlphaAttenInSecs = 1.0f / ImMax(vAttenValue, 0.01f); + } #endif // USE_EXPLORATION_BY_KEYS - ///////////////////////////////////////////////////////////////////////////////////// - //// FILE DIALOG CONSTRUCTOR / DESTRUCTOR /////////////////////////////////////////// - ///////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////////////////// + //// FILE DIALOG CONSTRUCTOR / DESTRUCTOR /////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////////////////// - IGFD::FileDialog::FileDialog() : BookMarkFeature(), KeyExplorerFeature(), ThumbnailFeature() {DpiScale=1.0f; singleClickSel=false; mobileMode=false;} - IGFD::FileDialog::~FileDialog() = default; + IGFD::FileDialog::FileDialog() : BookMarkFeature(), KeyExplorerFeature(), ThumbnailFeature() {DpiScale=1.0f; singleClickSel=false; mobileMode=false;} + IGFD::FileDialog::~FileDialog() = default; - ////////////////////////////////////////////////////////////////////////////////////////////////// - ///// FILE DIALOG STANDARD DIALOG //////////////////////////////////////////////////////////////// - ////////////////////////////////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////////////////////////////////// + ///// FILE DIALOG STANDARD DIALOG //////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////////////////////////////////// - // path and fileNameExt can be specified - void IGFD::FileDialog::OpenDialog( - const std::string& vKey, - const std::string& vTitle, - const char* vFilters, - const std::string& vPath, - const std::string& vFileName, - const int& vCountSelectionMax, - UserDatas vUserDatas, - ImGuiFileDialogFlags vFlags, + // path and fileNameExt can be specified + void IGFD::FileDialog::OpenDialog( + const std::string& vKey, + const std::string& vTitle, + const char* vFilters, + const std::string& vPath, + const std::string& vFileName, + const int& vCountSelectionMax, + UserDatas vUserDatas, + ImGuiFileDialogFlags vFlags, SelectFun vSelectFun) - { - if (prFileDialogInternal.puShowDialog) // if already opened, quit - return; + { + if (prFileDialogInternal.puShowDialog) // if already opened, quit + return; - prFileDialogInternal.ResetForNewDialog(); + prFileDialogInternal.ResetForNewDialog(); - prFileDialogInternal.puDLGkey = vKey; - prFileDialogInternal.puDLGtitle = vTitle; - prFileDialogInternal.puDLGuserDatas = vUserDatas; - prFileDialogInternal.puDLGflags = vFlags; + prFileDialogInternal.puDLGkey = vKey; + prFileDialogInternal.puDLGtitle = vTitle; + prFileDialogInternal.puDLGuserDatas = vUserDatas; + prFileDialogInternal.puDLGflags = vFlags; prFileDialogInternal.puDLGselFun = vSelectFun; - prFileDialogInternal.puDLGoptionsPane = nullptr; - prFileDialogInternal.puDLGoptionsPaneWidth = 0.0f; - prFileDialogInternal.puDLGmodal = false; + prFileDialogInternal.puDLGoptionsPane = nullptr; + prFileDialogInternal.puDLGoptionsPaneWidth = 0.0f; + prFileDialogInternal.puDLGmodal = false; - prFileDialogInternal.puFilterManager.puDLGdefaultExt.clear(); - prFileDialogInternal.puFilterManager.ParseFilters(vFilters); + prFileDialogInternal.puFilterManager.puDLGdefaultExt.clear(); + prFileDialogInternal.puFilterManager.ParseFilters(vFilters); - prFileDialogInternal.puFileManager.puDLGDirectoryMode = (vFilters == nullptr); - if (vPath.empty()) - prFileDialogInternal.puFileManager.puDLGpath = prFileDialogInternal.puFileManager.GetCurrentPath(); - else - prFileDialogInternal.puFileManager.puDLGpath = vPath; - prFileDialogInternal.puFileManager.SetCurrentPath(vPath); - prFileDialogInternal.puFileManager.puDLGcountSelectionMax = (size_t)vCountSelectionMax; - prFileDialogInternal.puFileManager.SetDefaultFileName(vFileName); + prFileDialogInternal.puFileManager.puDLGDirectoryMode = (vFilters == nullptr); + if (vPath.empty()) + prFileDialogInternal.puFileManager.puDLGpath = prFileDialogInternal.puFileManager.GetCurrentPath(); + else + prFileDialogInternal.puFileManager.puDLGpath = vPath; + prFileDialogInternal.puFileManager.SetCurrentPath(vPath); + prFileDialogInternal.puFileManager.puDLGcountSelectionMax = (size_t)vCountSelectionMax; + prFileDialogInternal.puFileManager.SetDefaultFileName(vFileName); - prFileDialogInternal.puFileManager.ClearAll(); - - prFileDialogInternal.puShowDialog = true; // open dialog - } + prFileDialogInternal.puFileManager.ClearAll(); + + prFileDialogInternal.puShowDialog = true; // open dialog + } - // path and filename are obtained from filePathName - void IGFD::FileDialog::OpenDialog( - const std::string& vKey, - const std::string& vTitle, - const char* vFilters, - const std::string& vFilePathName, - const int& vCountSelectionMax, - UserDatas vUserDatas, - ImGuiFileDialogFlags vFlags, + // path and filename are obtained from filePathName + void IGFD::FileDialog::OpenDialog( + const std::string& vKey, + const std::string& vTitle, + const char* vFilters, + const std::string& vFilePathName, + const int& vCountSelectionMax, + UserDatas vUserDatas, + ImGuiFileDialogFlags vFlags, SelectFun vSelectFun) - { - if (prFileDialogInternal.puShowDialog) // if already opened, quit - return; + { + if (prFileDialogInternal.puShowDialog) // if already opened, quit + return; - prFileDialogInternal.ResetForNewDialog(); + prFileDialogInternal.ResetForNewDialog(); - prFileDialogInternal.puDLGkey = vKey; - prFileDialogInternal.puDLGtitle = vTitle; - prFileDialogInternal.puDLGoptionsPane = nullptr; - prFileDialogInternal.puDLGoptionsPaneWidth = 0.0f; - prFileDialogInternal.puDLGuserDatas = vUserDatas; - prFileDialogInternal.puDLGflags = vFlags; + prFileDialogInternal.puDLGkey = vKey; + prFileDialogInternal.puDLGtitle = vTitle; + prFileDialogInternal.puDLGoptionsPane = nullptr; + prFileDialogInternal.puDLGoptionsPaneWidth = 0.0f; + prFileDialogInternal.puDLGuserDatas = vUserDatas; + prFileDialogInternal.puDLGflags = vFlags; prFileDialogInternal.puDLGselFun = vSelectFun; - prFileDialogInternal.puDLGmodal = false; + prFileDialogInternal.puDLGmodal = false; - auto ps = IGFD::Utils::ParsePathFileName(vFilePathName); - if (ps.isOk) - { - prFileDialogInternal.puFileManager.puDLGpath = ps.path; - prFileDialogInternal.puFileManager.SetDefaultFileName(""); - prFileDialogInternal.puFilterManager.puDLGdefaultExt = "." + ps.ext; - } - else - { - prFileDialogInternal.puFileManager.puDLGpath = prFileDialogInternal.puFileManager.GetCurrentPath(); - prFileDialogInternal.puFileManager.SetDefaultFileName(""); - prFileDialogInternal.puFilterManager.puDLGdefaultExt.clear(); - } + auto ps = IGFD::Utils::ParsePathFileName(vFilePathName); + if (ps.isOk) + { + prFileDialogInternal.puFileManager.puDLGpath = ps.path; + prFileDialogInternal.puFileManager.SetDefaultFileName(""); + prFileDialogInternal.puFilterManager.puDLGdefaultExt = "." + ps.ext; + } + else + { + prFileDialogInternal.puFileManager.puDLGpath = prFileDialogInternal.puFileManager.GetCurrentPath(); + prFileDialogInternal.puFileManager.SetDefaultFileName(""); + prFileDialogInternal.puFilterManager.puDLGdefaultExt.clear(); + } - prFileDialogInternal.puFilterManager.ParseFilters(vFilters); - prFileDialogInternal.puFilterManager.SetSelectedFilterWithExt( - prFileDialogInternal.puFilterManager.puDLGdefaultExt); - - prFileDialogInternal.puFileManager.SetCurrentPath(prFileDialogInternal.puFileManager.puDLGpath); + prFileDialogInternal.puFilterManager.ParseFilters(vFilters); + prFileDialogInternal.puFilterManager.SetSelectedFilterWithExt( + prFileDialogInternal.puFilterManager.puDLGdefaultExt); + + prFileDialogInternal.puFileManager.SetCurrentPath(prFileDialogInternal.puFileManager.puDLGpath); - prFileDialogInternal.puFileManager.puDLGDirectoryMode = (vFilters == nullptr); - prFileDialogInternal.puFileManager.puDLGcountSelectionMax = vCountSelectionMax; //-V101 + prFileDialogInternal.puFileManager.puDLGDirectoryMode = (vFilters == nullptr); + prFileDialogInternal.puFileManager.puDLGcountSelectionMax = vCountSelectionMax; //-V101 - prFileDialogInternal.puFileManager.ClearAll(); - - prFileDialogInternal.puShowDialog = true; - } + prFileDialogInternal.puFileManager.ClearAll(); + + prFileDialogInternal.puShowDialog = true; + } - // with pane - // path and fileNameExt can be specified - void IGFD::FileDialog::OpenDialog( - const std::string& vKey, - const std::string& vTitle, - const char* vFilters, - const std::string& vPath, - const std::string& vFileName, - const PaneFun& vSidePane, - const float& vSidePaneWidth, - const int& vCountSelectionMax, - UserDatas vUserDatas, - ImGuiFileDialogFlags vFlags, + // with pane + // path and fileNameExt can be specified + void IGFD::FileDialog::OpenDialog( + const std::string& vKey, + const std::string& vTitle, + const char* vFilters, + const std::string& vPath, + const std::string& vFileName, + const PaneFun& vSidePane, + const float& vSidePaneWidth, + const int& vCountSelectionMax, + UserDatas vUserDatas, + ImGuiFileDialogFlags vFlags, SelectFun vSelectFun) - { - if (prFileDialogInternal.puShowDialog) // if already opened, quit - return; + { + if (prFileDialogInternal.puShowDialog) // if already opened, quit + return; - prFileDialogInternal.ResetForNewDialog(); + prFileDialogInternal.ResetForNewDialog(); - prFileDialogInternal.puDLGkey = vKey; - prFileDialogInternal.puDLGtitle = vTitle; - prFileDialogInternal.puDLGuserDatas = vUserDatas; - prFileDialogInternal.puDLGflags = vFlags; + prFileDialogInternal.puDLGkey = vKey; + prFileDialogInternal.puDLGtitle = vTitle; + prFileDialogInternal.puDLGuserDatas = vUserDatas; + prFileDialogInternal.puDLGflags = vFlags; prFileDialogInternal.puDLGselFun = vSelectFun; - prFileDialogInternal.puDLGoptionsPane = vSidePane; - prFileDialogInternal.puDLGoptionsPaneWidth = vSidePaneWidth; - prFileDialogInternal.puDLGmodal = false; + prFileDialogInternal.puDLGoptionsPane = vSidePane; + prFileDialogInternal.puDLGoptionsPaneWidth = vSidePaneWidth; + prFileDialogInternal.puDLGmodal = false; - prFileDialogInternal.puFilterManager.puDLGdefaultExt.clear(); - prFileDialogInternal.puFilterManager.ParseFilters(vFilters); + prFileDialogInternal.puFilterManager.puDLGdefaultExt.clear(); + prFileDialogInternal.puFilterManager.ParseFilters(vFilters); - prFileDialogInternal.puFileManager.puDLGcountSelectionMax = (size_t)vCountSelectionMax; - prFileDialogInternal.puFileManager.puDLGDirectoryMode = (vFilters == nullptr); - if (vPath.empty()) - prFileDialogInternal.puFileManager.puDLGpath = prFileDialogInternal.puFileManager.GetCurrentPath(); - else - prFileDialogInternal.puFileManager.puDLGpath = vPath; + prFileDialogInternal.puFileManager.puDLGcountSelectionMax = (size_t)vCountSelectionMax; + prFileDialogInternal.puFileManager.puDLGDirectoryMode = (vFilters == nullptr); + if (vPath.empty()) + prFileDialogInternal.puFileManager.puDLGpath = prFileDialogInternal.puFileManager.GetCurrentPath(); + else + prFileDialogInternal.puFileManager.puDLGpath = vPath; - prFileDialogInternal.puFileManager.SetCurrentPath(prFileDialogInternal.puFileManager.puDLGpath); + prFileDialogInternal.puFileManager.SetCurrentPath(prFileDialogInternal.puFileManager.puDLGpath); - prFileDialogInternal.puFileManager.SetDefaultFileName(vFileName); + prFileDialogInternal.puFileManager.SetDefaultFileName(vFileName); - prFileDialogInternal.puFileManager.ClearAll(); - - prFileDialogInternal.puShowDialog = true; // open dialog - } + prFileDialogInternal.puFileManager.ClearAll(); + + prFileDialogInternal.puShowDialog = true; // open dialog + } - // with pane - // path and filename are obtained from filePathName - void IGFD::FileDialog::OpenDialog( - const std::string& vKey, - const std::string& vTitle, - const char* vFilters, - const std::string& vFilePathName, - const PaneFun& vSidePane, - const float& vSidePaneWidth, - const int& vCountSelectionMax, - UserDatas vUserDatas, - ImGuiFileDialogFlags vFlags, + // with pane + // path and filename are obtained from filePathName + void IGFD::FileDialog::OpenDialog( + const std::string& vKey, + const std::string& vTitle, + const char* vFilters, + const std::string& vFilePathName, + const PaneFun& vSidePane, + const float& vSidePaneWidth, + const int& vCountSelectionMax, + UserDatas vUserDatas, + ImGuiFileDialogFlags vFlags, SelectFun vSelectFun) - { - if (prFileDialogInternal.puShowDialog) // if already opened, quit - return; + { + if (prFileDialogInternal.puShowDialog) // if already opened, quit + return; - prFileDialogInternal.ResetForNewDialog(); + prFileDialogInternal.ResetForNewDialog(); - prFileDialogInternal.puDLGkey = vKey; - prFileDialogInternal.puDLGtitle = vTitle; - prFileDialogInternal.puDLGoptionsPane = vSidePane; - prFileDialogInternal.puDLGoptionsPaneWidth = vSidePaneWidth; - prFileDialogInternal.puDLGuserDatas = vUserDatas; - prFileDialogInternal.puDLGflags = vFlags; + prFileDialogInternal.puDLGkey = vKey; + prFileDialogInternal.puDLGtitle = vTitle; + prFileDialogInternal.puDLGoptionsPane = vSidePane; + prFileDialogInternal.puDLGoptionsPaneWidth = vSidePaneWidth; + prFileDialogInternal.puDLGuserDatas = vUserDatas; + prFileDialogInternal.puDLGflags = vFlags; prFileDialogInternal.puDLGselFun = vSelectFun; - prFileDialogInternal.puDLGmodal = false; + prFileDialogInternal.puDLGmodal = false; - auto ps = IGFD::Utils::ParsePathFileName(vFilePathName); - if (ps.isOk) - { - prFileDialogInternal.puFileManager.puDLGpath = ps.path; - prFileDialogInternal.puFileManager.SetDefaultFileName(vFilePathName); - prFileDialogInternal.puFilterManager.puDLGdefaultExt = "." + ps.ext; - } - else - { - prFileDialogInternal.puFileManager.puDLGpath = prFileDialogInternal.puFileManager.GetCurrentPath(); - prFileDialogInternal.puFileManager.SetDefaultFileName(""); - prFileDialogInternal.puFilterManager.puDLGdefaultExt.clear(); - } + auto ps = IGFD::Utils::ParsePathFileName(vFilePathName); + if (ps.isOk) + { + prFileDialogInternal.puFileManager.puDLGpath = ps.path; + prFileDialogInternal.puFileManager.SetDefaultFileName(vFilePathName); + prFileDialogInternal.puFilterManager.puDLGdefaultExt = "." + ps.ext; + } + else + { + prFileDialogInternal.puFileManager.puDLGpath = prFileDialogInternal.puFileManager.GetCurrentPath(); + prFileDialogInternal.puFileManager.SetDefaultFileName(""); + prFileDialogInternal.puFilterManager.puDLGdefaultExt.clear(); + } - prFileDialogInternal.puFileManager.SetCurrentPath(prFileDialogInternal.puFileManager.puDLGpath); + prFileDialogInternal.puFileManager.SetCurrentPath(prFileDialogInternal.puFileManager.puDLGpath); - prFileDialogInternal.puFileManager.puDLGcountSelectionMax = vCountSelectionMax; //-V101 - prFileDialogInternal.puFileManager.puDLGDirectoryMode = (vFilters == nullptr); - prFileDialogInternal.puFilterManager.ParseFilters(vFilters); - prFileDialogInternal.puFilterManager.SetSelectedFilterWithExt( - prFileDialogInternal.puFilterManager.puDLGdefaultExt); + prFileDialogInternal.puFileManager.puDLGcountSelectionMax = vCountSelectionMax; //-V101 + prFileDialogInternal.puFileManager.puDLGDirectoryMode = (vFilters == nullptr); + prFileDialogInternal.puFilterManager.ParseFilters(vFilters); + prFileDialogInternal.puFilterManager.SetSelectedFilterWithExt( + prFileDialogInternal.puFilterManager.puDLGdefaultExt); - prFileDialogInternal.puFileManager.ClearAll(); + prFileDialogInternal.puFileManager.ClearAll(); - prFileDialogInternal.puShowDialog = true; - } + prFileDialogInternal.puShowDialog = true; + } - ////////////////////////////////////////////////////////////////////////////////////////////////// - ///// FILE DIALOG MODAL DIALOG /////////////////////////////////////////////////////////////////// - ////////////////////////////////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////////////////////////////////// + ///// FILE DIALOG MODAL DIALOG /////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////////////////////////////////// - void IGFD::FileDialog::OpenModal( - const std::string& vKey, - const std::string& vTitle, - const char* vFilters, - const std::string& vPath, - const std::string& vFileName, - const int& vCountSelectionMax, - UserDatas vUserDatas, - ImGuiFileDialogFlags vFlags, + void IGFD::FileDialog::OpenModal( + const std::string& vKey, + const std::string& vTitle, + const char* vFilters, + const std::string& vPath, + const std::string& vFileName, + const int& vCountSelectionMax, + UserDatas vUserDatas, + ImGuiFileDialogFlags vFlags, SelectFun vSelectFun) - { - if (prFileDialogInternal.puShowDialog) // if already opened, quit - return; + { + if (prFileDialogInternal.puShowDialog) // if already opened, quit + return; - OpenDialog( - vKey, vTitle, vFilters, - vPath, vFileName, - vCountSelectionMax, vUserDatas, vFlags, vSelectFun); + OpenDialog( + vKey, vTitle, vFilters, + vPath, vFileName, + vCountSelectionMax, vUserDatas, vFlags, vSelectFun); - prFileDialogInternal.puDLGmodal = true; - } + prFileDialogInternal.puDLGmodal = true; + } - void IGFD::FileDialog::OpenModal( - const std::string& vKey, - const std::string& vTitle, - const char* vFilters, - const std::string& vFilePathName, - const int& vCountSelectionMax, - UserDatas vUserDatas, - ImGuiFileDialogFlags vFlags, + void IGFD::FileDialog::OpenModal( + const std::string& vKey, + const std::string& vTitle, + const char* vFilters, + const std::string& vFilePathName, + const int& vCountSelectionMax, + UserDatas vUserDatas, + ImGuiFileDialogFlags vFlags, SelectFun vSelectFun) - { - if (prFileDialogInternal.puShowDialog) // if already opened, quit - return; + { + if (prFileDialogInternal.puShowDialog) // if already opened, quit + return; - OpenDialog( - vKey, vTitle, vFilters, - vFilePathName, - vCountSelectionMax, vUserDatas, vFlags, vSelectFun); + OpenDialog( + vKey, vTitle, vFilters, + vFilePathName, + vCountSelectionMax, vUserDatas, vFlags, vSelectFun); - prFileDialogInternal.puDLGmodal = true; - } + prFileDialogInternal.puDLGmodal = true; + } - // with pane - // path and fileNameExt can be specified - void IGFD::FileDialog::OpenModal( - const std::string& vKey, - const std::string& vTitle, - const char* vFilters, - const std::string& vPath, - const std::string& vFileName, - const PaneFun& vSidePane, - const float& vSidePaneWidth, - const int& vCountSelectionMax, - UserDatas vUserDatas, - ImGuiFileDialogFlags vFlags, + // with pane + // path and fileNameExt can be specified + void IGFD::FileDialog::OpenModal( + const std::string& vKey, + const std::string& vTitle, + const char* vFilters, + const std::string& vPath, + const std::string& vFileName, + const PaneFun& vSidePane, + const float& vSidePaneWidth, + const int& vCountSelectionMax, + UserDatas vUserDatas, + ImGuiFileDialogFlags vFlags, SelectFun vSelectFun) - { - if (prFileDialogInternal.puShowDialog) // if already opened, quit - return; + { + if (prFileDialogInternal.puShowDialog) // if already opened, quit + return; - OpenDialog( - vKey, vTitle, vFilters, - vPath, vFileName, - vSidePane, vSidePaneWidth, - vCountSelectionMax, vUserDatas, vFlags, vSelectFun); + OpenDialog( + vKey, vTitle, vFilters, + vPath, vFileName, + vSidePane, vSidePaneWidth, + vCountSelectionMax, vUserDatas, vFlags, vSelectFun); - prFileDialogInternal.puDLGmodal = true; - } + prFileDialogInternal.puDLGmodal = true; + } - // with pane - // path and filename are obtained from filePathName - void IGFD::FileDialog::OpenModal( - const std::string& vKey, - const std::string& vTitle, - const char* vFilters, - const std::string& vFilePathName, - const PaneFun& vSidePane, - const float& vSidePaneWidth, - const int& vCountSelectionMax, - UserDatas vUserDatas, - ImGuiFileDialogFlags vFlags, + // with pane + // path and filename are obtained from filePathName + void IGFD::FileDialog::OpenModal( + const std::string& vKey, + const std::string& vTitle, + const char* vFilters, + const std::string& vFilePathName, + const PaneFun& vSidePane, + const float& vSidePaneWidth, + const int& vCountSelectionMax, + UserDatas vUserDatas, + ImGuiFileDialogFlags vFlags, SelectFun vSelectFun) - { - if (prFileDialogInternal.puShowDialog) // if already opened, quit - return; + { + if (prFileDialogInternal.puShowDialog) // if already opened, quit + return; - OpenDialog( - vKey, vTitle, vFilters, - vFilePathName, - vSidePane, vSidePaneWidth, - vCountSelectionMax, vUserDatas, vFlags, vSelectFun); + OpenDialog( + vKey, vTitle, vFilters, + vFilePathName, + vSidePane, vSidePaneWidth, + vCountSelectionMax, vUserDatas, vFlags, vSelectFun); - prFileDialogInternal.puDLGmodal = true; - } + prFileDialogInternal.puDLGmodal = true; + } - ////////////////////////////////////////////////////////////////////////////////////////////////// - ///// FILE DIALOG DISPLAY FUNCTION /////////////////////////////////////////////////////////////// - ////////////////////////////////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////////////////////////////////// + ///// FILE DIALOG DISPLAY FUNCTION /////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////////////////////////////////// - bool IGFD::FileDialog::Display(const std::string& vKey, ImGuiWindowFlags vFlags, ImVec2 vMinSize, ImVec2 vMaxSize) - { - bool res = false; + bool IGFD::FileDialog::Display(const std::string& vKey, ImGuiWindowFlags vFlags, ImVec2 vMinSize, ImVec2 vMaxSize) + { + bool res = false; - if (prFileDialogInternal.puShowDialog && prFileDialogInternal.puDLGkey == vKey) - { - if (prFileDialogInternal.puUseCustomLocale) - setlocale(prFileDialogInternal.puLocaleCategory, prFileDialogInternal.puLocaleBegin.c_str()); + if (prFileDialogInternal.puShowDialog && prFileDialogInternal.puDLGkey == vKey) + { + if (prFileDialogInternal.puUseCustomLocale) + setlocale(prFileDialogInternal.puLocaleCategory, prFileDialogInternal.puLocaleBegin.c_str()); - auto& fdFile = prFileDialogInternal.puFileManager; - auto& fdFilter = prFileDialogInternal.puFilterManager; + auto& fdFile = prFileDialogInternal.puFileManager; + auto& fdFilter = prFileDialogInternal.puFilterManager; - static ImGuiWindowFlags flags; + static ImGuiWindowFlags flags; - // to be sure than only one dialog is displayed per frame - ImGuiContext& g = *GImGui; - if (g.FrameCount == prFileDialogInternal.puLastImGuiFrameCount) // one instance was displayed this frame before for this key +> quit - return res; - prFileDialogInternal.puLastImGuiFrameCount = g.FrameCount; // mark this instance as used this frame + // to be sure than only one dialog is displayed per frame + ImGuiContext& g = *GImGui; + if (g.FrameCount == prFileDialogInternal.puLastImGuiFrameCount) // one instance was displayed this frame before for this key +> quit + return res; + prFileDialogInternal.puLastImGuiFrameCount = g.FrameCount; // mark this instance as used this frame - std::string name = prFileDialogInternal.puDLGtitle + "##" + prFileDialogInternal.puDLGkey; - if (prFileDialogInternal.puName != name) - { - fdFile.ClearComposer(); - fdFile.ClearFileLists(); - flags = vFlags; - } + std::string name = prFileDialogInternal.puDLGtitle + "##" + prFileDialogInternal.puDLGkey; + if (prFileDialogInternal.puName != name) + { + fdFile.ClearComposer(); + fdFile.ClearFileLists(); + flags = vFlags; + } - NewFrame(); + NewFrame(); #ifdef IMGUI_HAS_VIEWPORT - if (!ImGui::GetIO().ConfigViewportsNoDecoration) - { - // https://github.com/ocornut/imgui/issues/4534 - ImGuiWindowClass window_class; - window_class.ViewportFlagsOverrideClear = ImGuiViewportFlags_NoDecoration; - ImGui::SetNextWindowClass(&window_class); - } + if (!ImGui::GetIO().ConfigViewportsNoDecoration) + { + // https://github.com/ocornut/imgui/issues/4534 + ImGuiWindowClass window_class; + window_class.ViewportFlagsOverrideClear = ImGuiViewportFlags_NoDecoration; + ImGui::SetNextWindowClass(&window_class); + } #endif // IMGUI_HAS_VIEWPORT - ImGui::SetNextWindowSizeConstraints(vMinSize, vMaxSize); + ImGui::SetNextWindowSizeConstraints(vMinSize, vMaxSize); - bool beg = false; - if (prFileDialogInternal.puDLGmodal && - !prFileDialogInternal.puOkResultToConfirm) // disable modal because the confirm dialog for overwrite is a new modal - { - ImGui::OpenPopup(name.c_str()); - beg = ImGui::BeginPopupModal(name.c_str(), (bool*)nullptr, - flags | ImGuiWindowFlags_NoScrollbar); - } - else - { - beg = ImGui::Begin(name.c_str(), (bool*)nullptr, flags | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse | ImGuiWindowFlags_NoDocking); - } - if (beg) - { + bool beg = false; + if (prFileDialogInternal.puDLGmodal && + !prFileDialogInternal.puOkResultToConfirm) // disable modal because the confirm dialog for overwrite is a new modal + { + ImGui::OpenPopup(name.c_str()); + beg = ImGui::BeginPopupModal(name.c_str(), (bool*)nullptr, + flags | ImGuiWindowFlags_NoScrollbar); + } + else + { + beg = ImGui::Begin(name.c_str(), (bool*)nullptr, flags | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse | ImGuiWindowFlags_NoDocking); + } + if (beg) + { ImGui::SetWindowPos(ImVec2((ImGui::GetMainViewport()->Size.x-ImGui::GetWindowWidth())*0.5f,(ImGui::GetMainViewport()->Size.y-ImGui::GetWindowHeight())*0.5f)); if (ImGui::GetWindowSize().xViewport->Idx != 0) - flags |= ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoTitleBar; - else - flags = vFlags; - } + // if decoration is enabled we disable the resizing feature of imgui for avoid crash with SDL2 and GLFW3 + if (ImGui::GetIO().ConfigViewportsNoDecoration) + { + flags = vFlags; + } + else + { + auto win = ImGui::GetCurrentWindowRead(); + if (win->Viewport->Idx != 0) + flags |= ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoTitleBar; + else + flags = vFlags; + } #endif // IMGUI_HAS_VIEWPORT - prFileDialogInternal.puName = name; //-V820 - puAnyWindowsHovered |= ImGui::IsWindowHovered(); + prFileDialogInternal.puName = name; //-V820 + puAnyWindowsHovered |= ImGui::IsWindowHovered(); - if (fdFile.puDLGpath.empty()) - fdFile.puDLGpath = "."; // defaut path is '.' + if (fdFile.puDLGpath.empty()) + fdFile.puDLGpath = "."; // defaut path is '.' - fdFilter.SetDefaultFilterIfNotDefined(); + fdFilter.SetDefaultFilterIfNotDefined(); - // init list of files - if (fdFile.IsFileListEmpty() && !fdFile.puShowDrives && !fdFile.fileListActuallyEmpty) - { - IGFD::Utils::ReplaceString(fdFile.puDLGDefaultFileName, fdFile.puDLGpath, ""); // local path - if (!fdFile.puDLGDefaultFileName.empty()) - { - fdFile.SetDefaultFileName(fdFile.puDLGDefaultFileName); - fdFilter.SetSelectedFilterWithExt(fdFilter.puDLGdefaultExt); - } else if (fdFile.puDLGDirectoryMode) { // directory mode - fdFile.SetDefaultFileName("."); + // init list of files + if (fdFile.IsFileListEmpty() && !fdFile.puShowDrives && !fdFile.fileListActuallyEmpty) + { + IGFD::Utils::ReplaceString(fdFile.puDLGDefaultFileName, fdFile.puDLGpath, ""); // local path + if (!fdFile.puDLGDefaultFileName.empty()) + { + fdFile.SetDefaultFileName(fdFile.puDLGDefaultFileName); + fdFilter.SetSelectedFilterWithExt(fdFilter.puDLGdefaultExt); + } else if (fdFile.puDLGDirectoryMode) { // directory mode + fdFile.SetDefaultFileName("."); } logV("IGFD: fdFile.IsFileListEmpty() and !fdFile.puShowDrives"); - fdFile.ScanDir(prFileDialogInternal, fdFile.puDLGpath); - } + fdFile.ScanDir(prFileDialogInternal, fdFile.puDLGpath); + } - // draw dialog parts - prDrawHeader(); // bookmark, directory, path - res = prDrawContent(); // bookmark, files view, side pane - bool res1 = prDrawFooter(); // file field, filter combobox, ok/cancel buttons + // draw dialog parts + prDrawHeader(); // bookmark, directory, path + res = prDrawContent(); // bookmark, files view, side pane + bool res1 = prDrawFooter(); // file field, filter combobox, ok/cancel buttons if (!res) res=res1; - EndFrame(); + EndFrame(); - // for display in dialog center, the confirm to overwrite dlg - prFileDialogInternal.puDialogCenterPos = ImGui::GetCurrentWindowRead()->ContentRegionRect.GetCenter(); + // for display in dialog center, the confirm to overwrite dlg + prFileDialogInternal.puDialogCenterPos = ImGui::GetCurrentWindowRead()->ContentRegionRect.GetCenter(); - // when the confirm to overwrite dialog will appear we need to - // disable the modal mode of the main file dialog - // see prOkResultToConfirm under - if (prFileDialogInternal.puDLGmodal && - !prFileDialogInternal.puOkResultToConfirm) - ImGui::EndPopup(); - } + // when the confirm to overwrite dialog will appear we need to + // disable the modal mode of the main file dialog + // see prOkResultToConfirm under + if (prFileDialogInternal.puDLGmodal && + !prFileDialogInternal.puOkResultToConfirm) + ImGui::EndPopup(); + } - // same things here regarding prOkResultToConfirm - if (!prFileDialogInternal.puDLGmodal || prFileDialogInternal.puOkResultToConfirm) - ImGui::End(); + // same things here regarding prOkResultToConfirm + if (!prFileDialogInternal.puDLGmodal || prFileDialogInternal.puOkResultToConfirm) + ImGui::End(); - // confirm the result and show the confirm to overwrite dialog if needed - res = prConfirm_Or_OpenOverWriteFileDialog_IfNeeded(res, vFlags); - - if (prFileDialogInternal.puUseCustomLocale) - setlocale(prFileDialogInternal.puLocaleCategory, prFileDialogInternal.puLocaleEnd.c_str()); - } + // confirm the result and show the confirm to overwrite dialog if needed + res = prConfirm_Or_OpenOverWriteFileDialog_IfNeeded(res, vFlags); + + if (prFileDialogInternal.puUseCustomLocale) + setlocale(prFileDialogInternal.puLocaleCategory, prFileDialogInternal.puLocaleEnd.c_str()); + } - return res; - } + return res; + } - void IGFD::FileDialog::NewFrame() - { - prFileDialogInternal.NewFrame(); - NewThumbnailFrame(prFileDialogInternal); - } - - void IGFD::FileDialog::EndFrame() - { - EndThumbnailFrame(prFileDialogInternal); - prFileDialogInternal.EndFrame(); - - } - void IGFD::FileDialog::QuitFrame() - { - QuitThumbnailFrame(prFileDialogInternal); - } + void IGFD::FileDialog::NewFrame() + { + prFileDialogInternal.NewFrame(); + NewThumbnailFrame(prFileDialogInternal); + } + + void IGFD::FileDialog::EndFrame() + { + EndThumbnailFrame(prFileDialogInternal); + prFileDialogInternal.EndFrame(); + + } + void IGFD::FileDialog::QuitFrame() + { + QuitThumbnailFrame(prFileDialogInternal); + } - void IGFD::FileDialog::prDrawHeader() - { + void IGFD::FileDialog::prDrawHeader() + { #ifdef USE_BOOKMARK - prDrawBookmarkButton(); - ImGui::SameLine(); + prDrawBookmarkButton(); + ImGui::SameLine(); #endif // USE_BOOKMARK - prFileDialogInternal.puFileManager.DrawDirectoryCreation(prFileDialogInternal); - ImGui::SameLine(); - ImGui::SeparatorEx(ImGuiSeparatorFlags_Vertical); - ImGui::SameLine(); - prFileDialogInternal.puFileManager.DrawPathComposer(prFileDialogInternal); + prFileDialogInternal.puFileManager.DrawDirectoryCreation(prFileDialogInternal); + ImGui::SameLine(); + ImGui::SeparatorEx(ImGuiSeparatorFlags_Vertical); + ImGui::SameLine(); + prFileDialogInternal.puFileManager.DrawPathComposer(prFileDialogInternal); #ifdef USE_THUMBNAILS - if (!(prFileDialogInternal.puDLGflags & ImGuiFileDialogFlags_DisableThumbnailMode)) - { - prDrawDisplayModeToolBar(); - ImGui::SameLine(); - ImGui::SeparatorEx(ImGuiSeparatorFlags_Vertical); - ImGui::SameLine(); - } + if (!(prFileDialogInternal.puDLGflags & ImGuiFileDialogFlags_DisableThumbnailMode)) + { + prDrawDisplayModeToolBar(); + ImGui::SameLine(); + ImGui::SeparatorEx(ImGuiSeparatorFlags_Vertical); + ImGui::SameLine(); + } #endif // USE_THUMBNAILS - prFileDialogInternal.puSearchManager.DrawSearchBar(prFileDialogInternal); - } + prFileDialogInternal.puSearchManager.DrawSearchBar(prFileDialogInternal); + } - bool IGFD::FileDialog::prDrawContent() - { + bool IGFD::FileDialog::prDrawContent() + { bool escape = false; - ImVec2 size = ImGui::GetContentRegionAvail() - ImVec2(0.0f, prFileDialogInternal.puFooterHeight); + ImVec2 size = ImGui::GetContentRegionAvail() - ImVec2(0.0f, prFileDialogInternal.puFooterHeight); #ifdef USE_BOOKMARK - if (prBookmarkPaneShown) - { - //size.x -= prBookmarkWidth; - float otherWidth = size.x - prBookmarkWidth; - ImGui::PushID("##splitterbookmark"); - IGFD::Utils::Splitter(true, 4.0f, - &prBookmarkWidth, &otherWidth, 10.0f, - 10.0f + prFileDialogInternal.puDLGoptionsPaneWidth, size.y); - ImGui::PopID(); - size.x -= otherWidth; - prDrawBookmarkPane(prFileDialogInternal, size); - ImGui::SameLine(); - } + if (prBookmarkPaneShown) + { + //size.x -= prBookmarkWidth; + float otherWidth = size.x - prBookmarkWidth; + ImGui::PushID("##splitterbookmark"); + IGFD::Utils::Splitter(true, 4.0f, + &prBookmarkWidth, &otherWidth, 10.0f, + 10.0f + prFileDialogInternal.puDLGoptionsPaneWidth, size.y); + ImGui::PopID(); + size.x -= otherWidth; + prDrawBookmarkPane(prFileDialogInternal, size); + ImGui::SameLine(); + } #endif // USE_BOOKMARK - size.x = ImGui::GetContentRegionAvail().x - prFileDialogInternal.puDLGoptionsPaneWidth; + size.x = ImGui::GetContentRegionAvail().x - prFileDialogInternal.puDLGoptionsPaneWidth; - if (prFileDialogInternal.puDLGoptionsPane) - { - ImGui::PushID("##splittersidepane"); - IGFD::Utils::Splitter(true, 4.0f, &size.x, &prFileDialogInternal.puDLGoptionsPaneWidth, 10.0f, 10.0f, size.y); - ImGui::PopID(); - } + if (prFileDialogInternal.puDLGoptionsPane) + { + ImGui::PushID("##splittersidepane"); + IGFD::Utils::Splitter(true, 4.0f, &size.x, &prFileDialogInternal.puDLGoptionsPaneWidth, 10.0f, 10.0f, size.y); + ImGui::PopID(); + } #ifdef USE_THUMBNAILS - if (prFileDialogInternal.puDLGflags & ImGuiFileDialogFlags_DisableThumbnailMode) - { - prDrawFileListView(size); - } - else - { - switch (prDisplayMode) - { - case DisplayModeEnum::FILE_LIST: - prDrawFileListView(size); - break; - case DisplayModeEnum::THUMBNAILS_LIST: - prDrawThumbnailsListView(size); - break; - case DisplayModeEnum::THUMBNAILS_GRID: - prDrawThumbnailsGridView(size); - } - } + if (prFileDialogInternal.puDLGflags & ImGuiFileDialogFlags_DisableThumbnailMode) + { + prDrawFileListView(size); + } + else + { + switch (prDisplayMode) + { + case DisplayModeEnum::FILE_LIST: + prDrawFileListView(size); + break; + case DisplayModeEnum::THUMBNAILS_LIST: + prDrawThumbnailsListView(size); + break; + case DisplayModeEnum::THUMBNAILS_GRID: + prDrawThumbnailsGridView(size); + } + } #else - escape = prDrawFileListView(size); + escape = prDrawFileListView(size); #endif // USE_THUMBNAILS - if (prFileDialogInternal.puDLGoptionsPane) - { - prDrawSidePane(size.y); - } + if (prFileDialogInternal.puDLGoptionsPane) + { + prDrawSidePane(size.y); + } return escape; - } + } - bool IGFD::FileDialog::prDrawFooter() - { - auto& fdFile = prFileDialogInternal.puFileManager; - - float posY = ImGui::GetCursorPos().y; // height of last bar calc + bool IGFD::FileDialog::prDrawFooter() + { + auto& fdFile = prFileDialogInternal.puFileManager; + + float posY = ImGui::GetCursorPos().y; // height of last bar calc - if (!fdFile.puDLGDirectoryMode) - ImGui::Text(fileNameString); - else // directory chooser - ImGui::Text(dirNameString); + if (!fdFile.puDLGDirectoryMode) + ImGui::Text(fileNameString); + else // directory chooser + ImGui::Text(dirNameString); - ImGui::SameLine(); + ImGui::SameLine(); - // Input file fields - float width = ImGui::GetContentRegionAvail().x; + // Input file fields + float width = ImGui::GetContentRegionAvail().x; // fix this! fix this! fix this! - if (!fdFile.puDLGDirectoryMode) - width -= FILTER_COMBO_WIDTH*DpiScale; - ImGui::PushItemWidth(width); - ImGui::InputText("##FileName", fdFile.puFileNameBuffer, MAX_FILE_DIALOG_NAME_BUFFER); - if (ImGui::GetItemID() == ImGui::GetActiveID()) - prFileDialogInternal.puFileInputIsActive = true; - ImGui::PopItemWidth(); + if (!fdFile.puDLGDirectoryMode) + width -= FILTER_COMBO_WIDTH*DpiScale; + ImGui::PushItemWidth(width); + ImGui::InputText("##FileName", fdFile.puFileNameBuffer, MAX_FILE_DIALOG_NAME_BUFFER); + if (ImGui::GetItemID() == ImGui::GetActiveID()) + prFileDialogInternal.puFileInputIsActive = true; + ImGui::PopItemWidth(); - // combobox of filters - prFileDialogInternal.puFilterManager.DrawFilterComboBox(prFileDialogInternal); + // combobox of filters + prFileDialogInternal.puFilterManager.DrawFilterComboBox(prFileDialogInternal); - bool res = false; + bool res = false; - // OK Button - if (prFileDialogInternal.puCanWeContinue && strlen(fdFile.puFileNameBuffer)) - { - if (IMGUI_BUTTON(okButtonString "##validationdialog")) - { - prFileDialogInternal.puIsOk = true; - res = true; - } + // OK Button + if (prFileDialogInternal.puCanWeContinue && strlen(fdFile.puFileNameBuffer)) + { + if (IMGUI_BUTTON(okButtonString "##validationdialog")) + { + prFileDialogInternal.puIsOk = true; + res = true; + } - ImGui::SameLine(); - } + ImGui::SameLine(); + } - // Cancel Button - if (IMGUI_BUTTON(cancelButtonString "##validationdialog") || - prFileDialogInternal.puNeedToExitDialog) // dialog exit asked - { - prFileDialogInternal.puIsOk = false; - res = true; - } + // Cancel Button + if (IMGUI_BUTTON(cancelButtonString "##validationdialog") || + prFileDialogInternal.puNeedToExitDialog) // dialog exit asked + { + prFileDialogInternal.puIsOk = false; + res = true; + } - prFileDialogInternal.puFooterHeight = ImGui::GetCursorPosY() - posY; + prFileDialogInternal.puFooterHeight = ImGui::GetCursorPosY() - posY; - return res; - } + return res; + } // returns 0 if not break loop, 1 if break loop, 2 if exit dialog - int IGFD::FileDialog::prSelectableItem(int vidx, std::shared_ptr vInfos, bool vSelected, const char* vFmt, ...) - { - if (!vInfos.use_count()) - return 0; + int IGFD::FileDialog::prSelectableItem(int vidx, std::shared_ptr vInfos, bool vSelected, const char* vFmt, ...) + { + if (!vInfos.use_count()) + return 0; - auto& fdi = prFileDialogInternal.puFileManager; + auto& fdi = prFileDialogInternal.puFileManager; - static ImGuiSelectableFlags selectableFlags = ImGuiSelectableFlags_AllowDoubleClick | - ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_SpanAvailWidth; + static ImGuiSelectableFlags selectableFlags = ImGuiSelectableFlags_AllowDoubleClick | + ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_SpanAvailWidth; // TODO BUG?! // YES BUG: THIS JUST CRASHED FOR SOME REASON - va_list args; - va_start(args, vFmt); - vsnprintf(fdi.puVariadicBuffer, MAX_FILE_DIALOG_NAME_BUFFER, vFmt, args); - va_end(args); + va_list args; + va_start(args, vFmt); + vsnprintf(fdi.puVariadicBuffer, MAX_FILE_DIALOG_NAME_BUFFER, vFmt, args); + va_end(args); - float h = /*mobileMode?(ImGui::GetFontSize()+10.0f*DpiScale):*/0.0f; + float h = /*mobileMode?(ImGui::GetFontSize()+10.0f*DpiScale):*/0.0f; #ifdef USE_THUMBNAILS - if (prDisplayMode == DisplayModeEnum::THUMBNAILS_LIST) - h = DisplayMode_ThumbailsList_ImageHeight; + if (prDisplayMode == DisplayModeEnum::THUMBNAILS_LIST) + h = DisplayMode_ThumbailsList_ImageHeight; #endif // USE_THUMBNAILS #ifdef USE_EXPLORATION_BY_KEYS - bool flashed = prBeginFlashItem((size_t)vidx); - bool res = prFlashableSelectable(fdi.puVariadicBuffer, vSelected, selectableFlags, - flashed, ImVec2(-1.0f, h)); - if (flashed) - prEndFlashItem(); + bool flashed = prBeginFlashItem((size_t)vidx); + bool res = prFlashableSelectable(fdi.puVariadicBuffer, vSelected, selectableFlags, + flashed, ImVec2(-1.0f, h)); + if (flashed) + prEndFlashItem(); #else // USE_EXPLORATION_BY_KEYS - (void)vidx; // remove a warnings ofr unused var + (void)vidx; // remove a warnings ofr unused var - bool res = ImGui::Selectable(fdi.puVariadicBuffer, vSelected, selectableFlags, ImVec2(-1.0f, h)); + bool res = ImGui::Selectable(fdi.puVariadicBuffer, vSelected, selectableFlags, ImVec2(-1.0f, h)); #endif // USE_EXPLORATION_BY_KEYS - if (res) - { - if (vInfos->fileType == 'd') - { + if (res) + { + if (vInfos->fileType == 'd') + { bool isSelectingDir=false; - // nav system, selectebale cause open directory or select directory - if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard) - { - if (fdi.puDLGDirectoryMode) // directory chooser - { - fdi.SelectFileName(prFileDialogInternal, vInfos); - } - else - { - fdi.puPathClicked = fdi.SelectDirectory(vInfos); + // nav system, selectebale cause open directory or select directory + if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard) + { + if (fdi.puDLGDirectoryMode) // directory chooser + { + fdi.SelectFileName(prFileDialogInternal, vInfos); + } + else + { + fdi.puPathClicked = fdi.SelectDirectory(vInfos); isSelectingDir=true; - } - } - else // no nav system => classic behavior - { - if (DOUBLE_CLICKED) // 0 -> left mouse button double click - { + } + } + else // no nav system => classic behavior + { + if (DOUBLE_CLICKED) // 0 -> left mouse button double click + { isSelectingDir=true; - fdi.puPathClicked = fdi.SelectDirectory(vInfos); - } - else if (fdi.puDLGDirectoryMode) // directory chooser - { - fdi.SelectFileName(prFileDialogInternal, vInfos); - } - } + fdi.puPathClicked = fdi.SelectDirectory(vInfos); + } + else if (fdi.puDLGDirectoryMode) // directory chooser + { + fdi.SelectFileName(prFileDialogInternal, vInfos); + } + } - return isSelectingDir; // needToBreakTheloop - } - else - { + return isSelectingDir; // needToBreakTheloop + } + else + { if (DOUBLE_CLICKED) { fdi.SelectFileName(prFileDialogInternal, vInfos); prFileDialogInternal.puIsOk = true; return 2; } else { - fdi.SelectFileName(prFileDialogInternal, vInfos); + fdi.SelectFileName(prFileDialogInternal, vInfos); if (prFileDialogInternal.puDLGselFun!=NULL) { std::string argPath; for (auto& i: GetSelection()) { @@ -4053,581 +4006,581 @@ namespace IGFD } } } - } - } + } + } - return 0; - } + return 0; + } - void IGFD::FileDialog::prBeginFileColorIconStyle(std::shared_ptr vFileInfos, bool& vOutShowColor, std::string& vOutStr, ImFont** vOutFont) - { - vOutStr.clear(); - vOutShowColor = false; + void IGFD::FileDialog::prBeginFileColorIconStyle(std::shared_ptr vFileInfos, bool& vOutShowColor, std::string& vOutStr, ImFont** vOutFont) + { + vOutStr.clear(); + vOutShowColor = false; - if (vFileInfos->fileStyle.use_count()) //-V807 //-V522 - { - vOutShowColor = true; + if (vFileInfos->fileStyle.use_count()) //-V807 //-V522 + { + vOutShowColor = true; - *vOutFont = vFileInfos->fileStyle->font; - } + *vOutFont = vFileInfos->fileStyle->font; + } - if (vOutShowColor && !vFileInfos->fileStyle->icon.empty()) vOutStr = vFileInfos->fileStyle->icon; - else if (vFileInfos->fileType == 'd') vOutStr = dirEntryString; - else if (vFileInfos->fileType == 'l') vOutStr = linkEntryString; - else if (vFileInfos->fileType == 'f') vOutStr = fileEntryString; + if (vOutShowColor && !vFileInfos->fileStyle->icon.empty()) vOutStr = vFileInfos->fileStyle->icon; + else if (vFileInfos->fileType == 'd') vOutStr = dirEntryString; + else if (vFileInfos->fileType == 'l') vOutStr = linkEntryString; + else if (vFileInfos->fileType == 'f') vOutStr = fileEntryString; - vOutStr += " " + vFileInfos->fileNameExt; + vOutStr += " " + vFileInfos->fileNameExt; - if (vOutShowColor) - ImGui::PushStyleColor(ImGuiCol_Text, vFileInfos->fileStyle->color); - if (*vOutFont) - ImGui::PushFont(*vOutFont); - } + if (vOutShowColor) + ImGui::PushStyleColor(ImGuiCol_Text, vFileInfos->fileStyle->color); + if (*vOutFont) + ImGui::PushFont(*vOutFont); + } - void IGFD::FileDialog::prEndFileColorIconStyle(const bool& vShowColor, ImFont* vFont) - { - if (vFont) - ImGui::PopFont(); - if (vShowColor) - ImGui::PopStyleColor(); - } + void IGFD::FileDialog::prEndFileColorIconStyle(const bool& vShowColor, ImFont* vFont) + { + if (vFont) + ImGui::PopFont(); + if (vShowColor) + ImGui::PopStyleColor(); + } - bool IGFD::FileDialog::prDrawFileListView(ImVec2 vSize) - { + bool IGFD::FileDialog::prDrawFileListView(ImVec2 vSize) + { bool escape = false; - auto& fdi = prFileDialogInternal.puFileManager; + auto& fdi = prFileDialogInternal.puFileManager; - ImGui::PushID(this); + ImGui::PushID(this); - static ImGuiTableFlags flags = ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_RowBg | - ImGuiTableFlags_Hideable | ImGuiTableFlags_ScrollY | - ImGuiTableFlags_NoHostExtendY + static ImGuiTableFlags flags = ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_RowBg | + ImGuiTableFlags_Hideable | ImGuiTableFlags_ScrollY | + ImGuiTableFlags_NoHostExtendY #ifndef USE_CUSTOM_SORTING_ICON - | ImGuiTableFlags_Sortable + | ImGuiTableFlags_Sortable #endif // USE_CUSTOM_SORTING_ICON - ; - auto listViewID = ImGui::GetID("##FileDialog_fileTable"); - if (ImGui::BeginTableEx("##FileDialog_fileTable", listViewID, 4, flags, vSize, 0.0f)) //-V112 - { - ImGui::TableSetupScrollFreeze(0, 1); // Make header always visible - ImGui::TableSetupColumn(fdi.puHeaderFileName.c_str(), ImGuiTableColumnFlags_WidthStretch, -1, 0); - ImGui::TableSetupColumn(fdi.puHeaderFileType.c_str(), ImGuiTableColumnFlags_WidthFixed | - ((prFileDialogInternal.puDLGflags & ImGuiFileDialogFlags_HideColumnType) ? ImGuiTableColumnFlags_DefaultHide : 0), -1, 1); - ImGui::TableSetupColumn(fdi.puHeaderFileSize.c_str(), ImGuiTableColumnFlags_WidthFixed | - ((prFileDialogInternal.puDLGflags & ImGuiFileDialogFlags_HideColumnSize) ? ImGuiTableColumnFlags_DefaultHide : 0), -1, 2); - ImGui::TableSetupColumn(fdi.puHeaderFileDate.c_str(), ImGuiTableColumnFlags_WidthFixed | - ((prFileDialogInternal.puDLGflags & ImGuiFileDialogFlags_HideColumnDate) ? ImGuiTableColumnFlags_DefaultHide : 0), -1, 3); + ; + auto listViewID = ImGui::GetID("##FileDialog_fileTable"); + if (ImGui::BeginTableEx("##FileDialog_fileTable", listViewID, 4, flags, vSize, 0.0f)) //-V112 + { + ImGui::TableSetupScrollFreeze(0, 1); // Make header always visible + ImGui::TableSetupColumn(fdi.puHeaderFileName.c_str(), ImGuiTableColumnFlags_WidthStretch, -1, 0); + ImGui::TableSetupColumn(fdi.puHeaderFileType.c_str(), ImGuiTableColumnFlags_WidthFixed | + ((prFileDialogInternal.puDLGflags & ImGuiFileDialogFlags_HideColumnType) ? ImGuiTableColumnFlags_DefaultHide : 0), -1, 1); + ImGui::TableSetupColumn(fdi.puHeaderFileSize.c_str(), ImGuiTableColumnFlags_WidthFixed | + ((prFileDialogInternal.puDLGflags & ImGuiFileDialogFlags_HideColumnSize) ? ImGuiTableColumnFlags_DefaultHide : 0), -1, 2); + ImGui::TableSetupColumn(fdi.puHeaderFileDate.c_str(), ImGuiTableColumnFlags_WidthFixed | + ((prFileDialogInternal.puDLGflags & ImGuiFileDialogFlags_HideColumnDate) ? ImGuiTableColumnFlags_DefaultHide : 0), -1, 3); #ifndef USE_CUSTOM_SORTING_ICON - // Sort our data if sort specs have been changed! - if (ImGuiTableSortSpecs* sorts_specs = ImGui::TableGetSortSpecs()) - { - if (sorts_specs->SpecsDirty && !fdi.IsFileListEmpty()) - { - if (sorts_specs->Specs->ColumnUserID == 0) - fdi.SortFields(prFileDialogInternal, IGFD::FileManager::SortingFieldEnum::FIELD_FILENAME, true); - else if (sorts_specs->Specs->ColumnUserID == 1) - fdi.SortFields(prFileDialogInternal, IGFD::FileManager::SortingFieldEnum::FIELD_TYPE, true); - else if (sorts_specs->Specs->ColumnUserID == 2) - fdi.SortFields(prFileDialogInternal, IGFD::FileManager::SortingFieldEnum::FIELD_SIZE, true); - else //if (sorts_specs->Specs->ColumnUserID == 3) => alwayd true for the moment, to uncomment if we add a fourth column - fdi.SortFields(prFileDialogInternal, IGFD::FileManager::SortingFieldEnum::FIELD_DATE, true); + // Sort our data if sort specs have been changed! + if (ImGuiTableSortSpecs* sorts_specs = ImGui::TableGetSortSpecs()) + { + if (sorts_specs->SpecsDirty && !fdi.IsFileListEmpty()) + { + if (sorts_specs->Specs->ColumnUserID == 0) + fdi.SortFields(prFileDialogInternal, IGFD::FileManager::SortingFieldEnum::FIELD_FILENAME, true); + else if (sorts_specs->Specs->ColumnUserID == 1) + fdi.SortFields(prFileDialogInternal, IGFD::FileManager::SortingFieldEnum::FIELD_TYPE, true); + else if (sorts_specs->Specs->ColumnUserID == 2) + fdi.SortFields(prFileDialogInternal, IGFD::FileManager::SortingFieldEnum::FIELD_SIZE, true); + else //if (sorts_specs->Specs->ColumnUserID == 3) => alwayd true for the moment, to uncomment if we add a fourth column + fdi.SortFields(prFileDialogInternal, IGFD::FileManager::SortingFieldEnum::FIELD_DATE, true); - sorts_specs->SpecsDirty = false; - } - } + sorts_specs->SpecsDirty = false; + } + } - ImGui::TableHeadersRow(); + ImGui::TableHeadersRow(); #else // USE_CUSTOM_SORTING_ICON - ImGui::TableNextRow(ImGuiTableRowFlags_Headers); - for (int column = 0; column < 4; column++) //-V112 - { - ImGui::TableSetColumnIndex(column); - const char* column_name = ImGui::TableGetColumnName(column); // Retrieve name passed to TableSetupColumn() - ImGui::PushID(column); - ImGui::TableHeader(column_name); - ImGui::PopID(); - if (ImGui::IsItemClicked()) - { - if (column == 0) - fdi.SortFields(prFileDialogInternal, IGFD::FileManager::SortingFieldEnum::FIELD_FILENAME, true); - else if (column == 1) - fdi.SortFields(prFileDialogInternal, IGFD::FileManager::SortingFieldEnum::FIELD_TYPE, true); - else if (column == 2) - fdi.SortFields(prFileDialogInternal, IGFD::FileManager::SortingFieldEnum::FIELD_SIZE, true); - else //if (column == 3) => alwayd true for the moment, to uncomment if we add a fourth column - fdi.SortFields(prFileDialogInternal, IGFD::FileManager::SortingFieldEnum::FIELD_DATE, true); - } - } + ImGui::TableNextRow(ImGuiTableRowFlags_Headers); + for (int column = 0; column < 4; column++) //-V112 + { + ImGui::TableSetColumnIndex(column); + const char* column_name = ImGui::TableGetColumnName(column); // Retrieve name passed to TableSetupColumn() + ImGui::PushID(column); + ImGui::TableHeader(column_name); + ImGui::PopID(); + if (ImGui::IsItemClicked()) + { + if (column == 0) + fdi.SortFields(prFileDialogInternal, IGFD::FileManager::SortingFieldEnum::FIELD_FILENAME, true); + else if (column == 1) + fdi.SortFields(prFileDialogInternal, IGFD::FileManager::SortingFieldEnum::FIELD_TYPE, true); + else if (column == 2) + fdi.SortFields(prFileDialogInternal, IGFD::FileManager::SortingFieldEnum::FIELD_SIZE, true); + else //if (column == 3) => alwayd true for the moment, to uncomment if we add a fourth column + fdi.SortFields(prFileDialogInternal, IGFD::FileManager::SortingFieldEnum::FIELD_DATE, true); + } + } #endif // USE_CUSTOM_SORTING_ICON - if (!fdi.IsFilteredListEmpty()) - { - std::string _str; - ImFont* _font = nullptr; - bool _showColor = false; - - prFileListClipper.Begin((int)fdi.GetFilteredListSize(), ImGui::GetTextLineHeightWithSpacing()); - while (prFileListClipper.Step()) - { - for (int i = prFileListClipper.DisplayStart; i < prFileListClipper.DisplayEnd; i++) - { - if (i < 0) continue; + if (!fdi.IsFilteredListEmpty()) + { + std::string _str; + ImFont* _font = nullptr; + bool _showColor = false; + + prFileListClipper.Begin((int)fdi.GetFilteredListSize(), ImGui::GetTextLineHeightWithSpacing()); + while (prFileListClipper.Step()) + { + for (int i = prFileListClipper.DisplayStart; i < prFileListClipper.DisplayEnd; i++) + { + if (i < 0) continue; - auto infos = fdi.GetFilteredFileAt((size_t)i); - if (!infos.use_count()) - continue; + auto infos = fdi.GetFilteredFileAt((size_t)i); + if (!infos.use_count()) + continue; - prBeginFileColorIconStyle(infos, _showColor, _str, &_font); - - bool selected = fdi.IsFileNameSelected(infos->fileNameExt); // found + prBeginFileColorIconStyle(infos, _showColor, _str, &_font); + + bool selected = fdi.IsFileNameSelected(infos->fileNameExt); // found - ImGui::TableNextRow(); + ImGui::TableNextRow(); - int needToBreakTheloop = false; + int needToBreakTheloop = false; - if (ImGui::TableNextColumn()) // file name - { + if (ImGui::TableNextColumn()) // file name + { // TODO BUG?!?!?! // YES BUG - needToBreakTheloop = prSelectableItem(i, infos, selected, "%s", _str.c_str()); + needToBreakTheloop = prSelectableItem(i, infos, selected, "%s", _str.c_str()); if (needToBreakTheloop==2) escape=true; - } - if (ImGui::TableNextColumn()) // file type - { - ImGui::Text("%s", infos->fileExt.c_str()); - } - if (ImGui::TableNextColumn()) // file size - { - if (infos->fileType != 'd') - { - ImGui::Text("%s ", infos->formatedFileSize.c_str()); - } - else - { - ImGui::Text("%s",""); - } - } - if (ImGui::TableNextColumn()) // file date + time - { - ImGui::Text("%s", infos->fileModifDate.c_str()); - } + } + if (ImGui::TableNextColumn()) // file type + { + ImGui::Text("%s", infos->fileExt.c_str()); + } + if (ImGui::TableNextColumn()) // file size + { + if (infos->fileType != 'd') + { + ImGui::Text("%s ", infos->formatedFileSize.c_str()); + } + else + { + ImGui::Text("%s",""); + } + } + if (ImGui::TableNextColumn()) // file date + time + { + ImGui::Text("%s", infos->fileModifDate.c_str()); + } - prEndFileColorIconStyle(_showColor, _font); + prEndFileColorIconStyle(_showColor, _font); - if (needToBreakTheloop==1) - break; - } - } - prFileListClipper.End(); - } + if (needToBreakTheloop==1) + break; + } + } + prFileListClipper.End(); + } #ifdef USE_EXPLORATION_BY_KEYS - if (!fdi.puInputPathActivated) - { - prLocateByInputKey(prFileDialogInternal); - prExploreWithkeys(prFileDialogInternal, listViewID); - } + if (!fdi.puInputPathActivated) + { + prLocateByInputKey(prFileDialogInternal); + prExploreWithkeys(prFileDialogInternal, listViewID); + } #endif // USE_EXPLORATION_BY_KEYS - ImGuiContext& g = *GImGui; - if (g.LastActiveId - 1 == listViewID || g.LastActiveId == listViewID) - { - prFileDialogInternal.puFileListViewIsActive = true; - } + ImGuiContext& g = *GImGui; + if (g.LastActiveId - 1 == listViewID || g.LastActiveId == listViewID) + { + prFileDialogInternal.puFileListViewIsActive = true; + } - ImGui::EndTable(); - } + ImGui::EndTable(); + } - ImGui::PopID(); + ImGui::PopID(); return escape; - } + } #ifdef USE_THUMBNAILS - void IGFD::FileDialog::prDrawThumbnailsListView(ImVec2 vSize) - { - auto& fdi = prFileDialogInternal.puFileManager; + void IGFD::FileDialog::prDrawThumbnailsListView(ImVec2 vSize) + { + auto& fdi = prFileDialogInternal.puFileManager; - ImGui::PushID(this); + ImGui::PushID(this); - static ImGuiTableFlags flags = ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_RowBg | - ImGuiTableFlags_Hideable | ImGuiTableFlags_ScrollY | - ImGuiTableFlags_NoHostExtendY + static ImGuiTableFlags flags = ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_RowBg | + ImGuiTableFlags_Hideable | ImGuiTableFlags_ScrollY | + ImGuiTableFlags_NoHostExtendY #ifndef USE_CUSTOM_SORTING_ICON - | ImGuiTableFlags_Sortable + | ImGuiTableFlags_Sortable #endif // USE_CUSTOM_SORTING_ICON - ; - auto listViewID = ImGui::GetID("##FileDialog_fileTable"); - if (ImGui::BeginTableEx("##FileDialog_fileTable", listViewID, 5, flags, vSize, 0.0f)) - { - ImGui::TableSetupScrollFreeze(0, 1); // Make header always visible - ImGui::TableSetupColumn(fdi.puHeaderFileName.c_str(), ImGuiTableColumnFlags_WidthStretch, -1, 0); - ImGui::TableSetupColumn(fdi.puHeaderFileType.c_str(), ImGuiTableColumnFlags_WidthFixed | - ((prFileDialogInternal.puDLGflags & ImGuiFileDialogFlags_HideColumnType) ? ImGuiTableColumnFlags_DefaultHide : 0), -1, 1); - ImGui::TableSetupColumn(fdi.puHeaderFileSize.c_str(), ImGuiTableColumnFlags_WidthFixed | - ((prFileDialogInternal.puDLGflags & ImGuiFileDialogFlags_HideColumnSize) ? ImGuiTableColumnFlags_DefaultHide : 0), -1, 2); - ImGui::TableSetupColumn(fdi.puHeaderFileDate.c_str(), ImGuiTableColumnFlags_WidthFixed | - ((prFileDialogInternal.puDLGflags & ImGuiFileDialogFlags_HideColumnDate) ? ImGuiTableColumnFlags_DefaultHide : 0), -1, 3); - // not needed to have an option for hide the thumbnails since this is why this view is used - ImGui::TableSetupColumn(fdi.puHeaderFileThumbnails.c_str(), ImGuiTableColumnFlags_WidthFixed, -1, 4); //-V112 + ; + auto listViewID = ImGui::GetID("##FileDialog_fileTable"); + if (ImGui::BeginTableEx("##FileDialog_fileTable", listViewID, 5, flags, vSize, 0.0f)) + { + ImGui::TableSetupScrollFreeze(0, 1); // Make header always visible + ImGui::TableSetupColumn(fdi.puHeaderFileName.c_str(), ImGuiTableColumnFlags_WidthStretch, -1, 0); + ImGui::TableSetupColumn(fdi.puHeaderFileType.c_str(), ImGuiTableColumnFlags_WidthFixed | + ((prFileDialogInternal.puDLGflags & ImGuiFileDialogFlags_HideColumnType) ? ImGuiTableColumnFlags_DefaultHide : 0), -1, 1); + ImGui::TableSetupColumn(fdi.puHeaderFileSize.c_str(), ImGuiTableColumnFlags_WidthFixed | + ((prFileDialogInternal.puDLGflags & ImGuiFileDialogFlags_HideColumnSize) ? ImGuiTableColumnFlags_DefaultHide : 0), -1, 2); + ImGui::TableSetupColumn(fdi.puHeaderFileDate.c_str(), ImGuiTableColumnFlags_WidthFixed | + ((prFileDialogInternal.puDLGflags & ImGuiFileDialogFlags_HideColumnDate) ? ImGuiTableColumnFlags_DefaultHide : 0), -1, 3); + // not needed to have an option for hide the thumbnails since this is why this view is used + ImGui::TableSetupColumn(fdi.puHeaderFileThumbnails.c_str(), ImGuiTableColumnFlags_WidthFixed, -1, 4); //-V112 #ifndef USE_CUSTOM_SORTING_ICON - // Sort our data if sort specs have been changed! - if (ImGuiTableSortSpecs* sorts_specs = ImGui::TableGetSortSpecs()) - { - if (sorts_specs->SpecsDirty && !fdi.IsFileListEmpty()) - { - if (sorts_specs->Specs->ColumnUserID == 0) - fdi.SortFields(prFileDialogInternal, IGFD::FileManager::SortingFieldEnum::FIELD_FILENAME, true); - else if (sorts_specs->Specs->ColumnUserID == 1) - fdi.SortFields(prFileDialogInternal, IGFD::FileManager::SortingFieldEnum::FIELD_TYPE, true); - else if (sorts_specs->Specs->ColumnUserID == 2) - fdi.SortFields(prFileDialogInternal, IGFD::FileManager::SortingFieldEnum::FIELD_SIZE, true); - else if (sorts_specs->Specs->ColumnUserID == 3) - fdi.SortFields(prFileDialogInternal, IGFD::FileManager::SortingFieldEnum::FIELD_DATE, true); - else // if (sorts_specs->Specs->ColumnUserID == 4) = > always true for the moment, to uncomment if we add another column - fdi.SortFields(prFileDialogInternal, IGFD::FileManager::SortingFieldEnum::FIELD_THUMBNAILS, true); - sorts_specs->SpecsDirty = false; - } - } + // Sort our data if sort specs have been changed! + if (ImGuiTableSortSpecs* sorts_specs = ImGui::TableGetSortSpecs()) + { + if (sorts_specs->SpecsDirty && !fdi.IsFileListEmpty()) + { + if (sorts_specs->Specs->ColumnUserID == 0) + fdi.SortFields(prFileDialogInternal, IGFD::FileManager::SortingFieldEnum::FIELD_FILENAME, true); + else if (sorts_specs->Specs->ColumnUserID == 1) + fdi.SortFields(prFileDialogInternal, IGFD::FileManager::SortingFieldEnum::FIELD_TYPE, true); + else if (sorts_specs->Specs->ColumnUserID == 2) + fdi.SortFields(prFileDialogInternal, IGFD::FileManager::SortingFieldEnum::FIELD_SIZE, true); + else if (sorts_specs->Specs->ColumnUserID == 3) + fdi.SortFields(prFileDialogInternal, IGFD::FileManager::SortingFieldEnum::FIELD_DATE, true); + else // if (sorts_specs->Specs->ColumnUserID == 4) = > always true for the moment, to uncomment if we add another column + fdi.SortFields(prFileDialogInternal, IGFD::FileManager::SortingFieldEnum::FIELD_THUMBNAILS, true); + sorts_specs->SpecsDirty = false; + } + } - ImGui::TableHeadersRow(); + ImGui::TableHeadersRow(); #else // USE_CUSTOM_SORTING_ICON - ImGui::TableNextRow(ImGuiTableRowFlags_Headers); - for (int column = 0; column < 5; column++) - { - ImGui::TableSetColumnIndex(column); - const char* column_name = ImGui::TableGetColumnName(column); // Retrieve name passed to TableSetupColumn() - ImGui::PushID(column); - ImGui::TableHeader(column_name); - ImGui::PopID(); - if (ImGui::IsItemClicked()) - { - if (column == 0) - fdi.SortFields(prFileDialogInternal, IGFD::FileManager::SortingFieldEnum::FIELD_FILENAME, true); - else if (column == 1) - fdi.SortFields(prFileDialogInternal, IGFD::FileManager::SortingFieldEnum::FIELD_TYPE, true); - else if (column == 2) - fdi.SortFields(prFileDialogInternal, IGFD::FileManager::SortingFieldEnum::FIELD_SIZE, true); - else if (column == 3) - fdi.SortFields(prFileDialogInternal, IGFD::FileManager::SortingFieldEnum::FIELD_DATE, true); - else // if (column == 4) = > always true for the moment, to uncomment if we add another column - fdi.SortFields(prFileDialogInternal, IGFD::FileManager::SortingFieldEnum::FIELD_THUMBNAILS, true); - } - } + ImGui::TableNextRow(ImGuiTableRowFlags_Headers); + for (int column = 0; column < 5; column++) + { + ImGui::TableSetColumnIndex(column); + const char* column_name = ImGui::TableGetColumnName(column); // Retrieve name passed to TableSetupColumn() + ImGui::PushID(column); + ImGui::TableHeader(column_name); + ImGui::PopID(); + if (ImGui::IsItemClicked()) + { + if (column == 0) + fdi.SortFields(prFileDialogInternal, IGFD::FileManager::SortingFieldEnum::FIELD_FILENAME, true); + else if (column == 1) + fdi.SortFields(prFileDialogInternal, IGFD::FileManager::SortingFieldEnum::FIELD_TYPE, true); + else if (column == 2) + fdi.SortFields(prFileDialogInternal, IGFD::FileManager::SortingFieldEnum::FIELD_SIZE, true); + else if (column == 3) + fdi.SortFields(prFileDialogInternal, IGFD::FileManager::SortingFieldEnum::FIELD_DATE, true); + else // if (column == 4) = > always true for the moment, to uncomment if we add another column + fdi.SortFields(prFileDialogInternal, IGFD::FileManager::SortingFieldEnum::FIELD_THUMBNAILS, true); + } + } #endif // USE_CUSTOM_SORTING_ICON - if (!fdi.IsFilteredListEmpty()) - { - std::string _str; - ImFont* _font = nullptr; - bool _showColor = false; + if (!fdi.IsFilteredListEmpty()) + { + std::string _str; + ImFont* _font = nullptr; + bool _showColor = false; - ImGuiContext& g = *GImGui; - const float itemHeight = ImMax(g.FontSize, DisplayMode_ThumbailsList_ImageHeight) + g.Style.ItemSpacing.y; + ImGuiContext& g = *GImGui; + const float itemHeight = ImMax(g.FontSize, DisplayMode_ThumbailsList_ImageHeight) + g.Style.ItemSpacing.y; - prFileListClipper.Begin((int)fdi.GetFilteredListSize(), itemHeight); - while (prFileListClipper.Step()) - { - for (int i = prFileListClipper.DisplayStart; i < prFileListClipper.DisplayEnd; i++) - { - if (i < 0) continue; + prFileListClipper.Begin((int)fdi.GetFilteredListSize(), itemHeight); + while (prFileListClipper.Step()) + { + for (int i = prFileListClipper.DisplayStart; i < prFileListClipper.DisplayEnd; i++) + { + if (i < 0) continue; - auto infos = fdi.GetFilteredFileAt((size_t)i); - if (!infos.use_count()) - continue; + auto infos = fdi.GetFilteredFileAt((size_t)i); + if (!infos.use_count()) + continue; - prBeginFileColorIconStyle(infos, _showColor, _str, &_font); + prBeginFileColorIconStyle(infos, _showColor, _str, &_font); - bool selected = fdi.IsFileNameSelected(infos->fileNameExt); // found + bool selected = fdi.IsFileNameSelected(infos->fileNameExt); // found - ImGui::TableNextRow(); + ImGui::TableNextRow(); - bool needToBreakTheloop = false; + bool needToBreakTheloop = false; - if (ImGui::TableNextColumn()) // file name - { - needToBreakTheloop = prSelectableItem(i, infos, selected, _str.c_str()); - } - if (ImGui::TableNextColumn()) // file type - { - ImGui::Text("%s", infos->fileExt.c_str()); - } - if (ImGui::TableNextColumn()) // file size - { - if (infos->fileType != 'd') - { - ImGui::Text("%s ", infos->formatedFileSize.c_str()); - } - else - { - ImGui::Text(""); - } - } - if (ImGui::TableNextColumn()) // file date + time - { - ImGui::Text("%s", infos->fileModifDate.c_str()); - } - if (ImGui::TableNextColumn()) // file thumbnails - { - auto th = &infos->thumbnailInfo; + if (ImGui::TableNextColumn()) // file name + { + needToBreakTheloop = prSelectableItem(i, infos, selected, _str.c_str()); + } + if (ImGui::TableNextColumn()) // file type + { + ImGui::Text("%s", infos->fileExt.c_str()); + } + if (ImGui::TableNextColumn()) // file size + { + if (infos->fileType != 'd') + { + ImGui::Text("%s ", infos->formatedFileSize.c_str()); + } + else + { + ImGui::Text(""); + } + } + if (ImGui::TableNextColumn()) // file date + time + { + ImGui::Text("%s", infos->fileModifDate.c_str()); + } + if (ImGui::TableNextColumn()) // file thumbnails + { + auto th = &infos->thumbnailInfo; - if (!th->isLoadingOrLoaded) - { - prAddThumbnailToLoad(infos); - } - if (th->isReadyToDisplay && - th->textureID) - { - ImGui::Image((ImTextureID)th->textureID, - ImVec2((float)th->textureWidth, - (float)th->textureHeight)); - } - } + if (!th->isLoadingOrLoaded) + { + prAddThumbnailToLoad(infos); + } + if (th->isReadyToDisplay && + th->textureID) + { + ImGui::Image((ImTextureID)th->textureID, + ImVec2((float)th->textureWidth, + (float)th->textureHeight)); + } + } - prEndFileColorIconStyle(_showColor, _font); + prEndFileColorIconStyle(_showColor, _font); - if (needToBreakTheloop) - break; - } - } - prFileListClipper.End(); - } + if (needToBreakTheloop) + break; + } + } + prFileListClipper.End(); + } #ifdef USE_EXPLORATION_BY_KEYS - if (!fdi.puInputPathActivated) - { - prLocateByInputKey(prFileDialogInternal); - prExploreWithkeys(prFileDialogInternal, listViewID); - } + if (!fdi.puInputPathActivated) + { + prLocateByInputKey(prFileDialogInternal); + prExploreWithkeys(prFileDialogInternal, listViewID); + } #endif // USE_EXPLORATION_BY_KEYS - ImGuiContext& g = *GImGui; - if (g.LastActiveId - 1 == listViewID || g.LastActiveId == listViewID) - { - prFileDialogInternal.puFileListViewIsActive = true; - } + ImGuiContext& g = *GImGui; + if (g.LastActiveId - 1 == listViewID || g.LastActiveId == listViewID) + { + prFileDialogInternal.puFileListViewIsActive = true; + } - ImGui::EndTable(); - } + ImGui::EndTable(); + } - ImGui::PopID(); - } + ImGui::PopID(); + } - void IGFD::FileDialog::prDrawThumbnailsGridView(ImVec2 vSize) - { - if (ImGui::BeginChild("##thumbnailsGridsFiles", vSize)) - { - // todo - } + void IGFD::FileDialog::prDrawThumbnailsGridView(ImVec2 vSize) + { + if (ImGui::BeginChild("##thumbnailsGridsFiles", vSize)) + { + // todo + } - ImGui::EndChild(); - } + ImGui::EndChild(); + } #endif - void IGFD::FileDialog::prDrawSidePane(float vHeight) - { - ImGui::SameLine(); + void IGFD::FileDialog::prDrawSidePane(float vHeight) + { + ImGui::SameLine(); - ImGui::BeginChild("##FileTypes", ImVec2(0, vHeight)); + ImGui::BeginChild("##FileTypes", ImVec2(0, vHeight)); - prFileDialogInternal.puDLGoptionsPane( - prFileDialogInternal.puFilterManager.GetSelectedFilter().filter.c_str(), - prFileDialogInternal.puDLGuserDatas, &prFileDialogInternal.puCanWeContinue); + prFileDialogInternal.puDLGoptionsPane( + prFileDialogInternal.puFilterManager.GetSelectedFilter().filter.c_str(), + prFileDialogInternal.puDLGuserDatas, &prFileDialogInternal.puCanWeContinue); - ImGui::EndChild(); - } + ImGui::EndChild(); + } - void IGFD::FileDialog::Close() - { - prFileDialogInternal.puDLGkey.clear(); - prFileDialogInternal.puShowDialog = false; - } + void IGFD::FileDialog::Close() + { + prFileDialogInternal.puDLGkey.clear(); + prFileDialogInternal.puShowDialog = false; + } - bool IGFD::FileDialog::WasOpenedThisFrame(const std::string& vKey) const - { - bool res = prFileDialogInternal.puShowDialog && prFileDialogInternal.puDLGkey == vKey; - if (res) - { - ImGuiContext& g = *GImGui; - res &= prFileDialogInternal.puLastImGuiFrameCount == g.FrameCount; // return true if a dialog was displayed in this frame - } - return res; - } + bool IGFD::FileDialog::WasOpenedThisFrame(const std::string& vKey) const + { + bool res = prFileDialogInternal.puShowDialog && prFileDialogInternal.puDLGkey == vKey; + if (res) + { + ImGuiContext& g = *GImGui; + res &= prFileDialogInternal.puLastImGuiFrameCount == g.FrameCount; // return true if a dialog was displayed in this frame + } + return res; + } - bool IGFD::FileDialog::WasOpenedThisFrame() const - { - bool res = prFileDialogInternal.puShowDialog; - if (res) - { - ImGuiContext& g = *GImGui; - res &= prFileDialogInternal.puLastImGuiFrameCount == g.FrameCount; // return true if a dialog was displayed in this frame - } - return res; - } + bool IGFD::FileDialog::WasOpenedThisFrame() const + { + bool res = prFileDialogInternal.puShowDialog; + if (res) + { + ImGuiContext& g = *GImGui; + res &= prFileDialogInternal.puLastImGuiFrameCount == g.FrameCount; // return true if a dialog was displayed in this frame + } + return res; + } - bool IGFD::FileDialog::IsOpened(const std::string& vKey) const - { - return (prFileDialogInternal.puShowDialog && prFileDialogInternal.puDLGkey == vKey); - } + bool IGFD::FileDialog::IsOpened(const std::string& vKey) const + { + return (prFileDialogInternal.puShowDialog && prFileDialogInternal.puDLGkey == vKey); + } - bool IGFD::FileDialog::IsOpened() const - { - return prFileDialogInternal.puShowDialog; - } + bool IGFD::FileDialog::IsOpened() const + { + return prFileDialogInternal.puShowDialog; + } - std::string IGFD::FileDialog::GetOpenedKey() const - { - if (prFileDialogInternal.puShowDialog) - return prFileDialogInternal.puDLGkey; - return ""; - } + std::string IGFD::FileDialog::GetOpenedKey() const + { + if (prFileDialogInternal.puShowDialog) + return prFileDialogInternal.puDLGkey; + return ""; + } - std::string IGFD::FileDialog::GetFilePathName() - { - return prFileDialogInternal.puFileManager.GetResultingFilePathName(prFileDialogInternal); - } + std::string IGFD::FileDialog::GetFilePathName() + { + return prFileDialogInternal.puFileManager.GetResultingFilePathName(prFileDialogInternal); + } - std::string IGFD::FileDialog::GetCurrentPath() - { - return prFileDialogInternal.puFileManager.GetResultingPath(); - } + std::string IGFD::FileDialog::GetCurrentPath() + { + return prFileDialogInternal.puFileManager.GetResultingPath(); + } - std::string IGFD::FileDialog::GetCurrentFileName() - { - return prFileDialogInternal.puFileManager.GetResultingFileName(prFileDialogInternal); - } + std::string IGFD::FileDialog::GetCurrentFileName() + { + return prFileDialogInternal.puFileManager.GetResultingFileName(prFileDialogInternal); + } - std::string IGFD::FileDialog::GetCurrentFilter() - { - return prFileDialogInternal.puFilterManager.GetSelectedFilter().filter; - } + std::string IGFD::FileDialog::GetCurrentFilter() + { + return prFileDialogInternal.puFilterManager.GetSelectedFilter().filter; + } - std::map IGFD::FileDialog::GetSelection() - { - return prFileDialogInternal.puFileManager.GetResultingSelection(); - } + std::map IGFD::FileDialog::GetSelection() + { + return prFileDialogInternal.puFileManager.GetResultingSelection(); + } - UserDatas IGFD::FileDialog::GetUserDatas() const - { - return prFileDialogInternal.puDLGuserDatas; - } + UserDatas IGFD::FileDialog::GetUserDatas() const + { + return prFileDialogInternal.puDLGuserDatas; + } - bool IGFD::FileDialog::IsOk() const - { - return prFileDialogInternal.puIsOk; - } + bool IGFD::FileDialog::IsOk() const + { + return prFileDialogInternal.puIsOk; + } - void IGFD::FileDialog::SetFileStyle(const IGFD_FileStyleFlags& vFlags, const char* vCriteria, const FileStyle& vInfos) - { - prFileDialogInternal.puFilterManager.SetFileStyle(vFlags, vCriteria, vInfos); - } + void IGFD::FileDialog::SetFileStyle(const IGFD_FileStyleFlags& vFlags, const char* vCriteria, const FileStyle& vInfos) + { + prFileDialogInternal.puFilterManager.SetFileStyle(vFlags, vCriteria, vInfos); + } - void IGFD::FileDialog::SetFileStyle(const IGFD_FileStyleFlags& vFlags, const char* vCriteria, const ImVec4& vColor, const std::string& vIcon, ImFont* vFont) - { - prFileDialogInternal.puFilterManager.SetFileStyle(vFlags, vCriteria, vColor, vIcon, vFont); - } + void IGFD::FileDialog::SetFileStyle(const IGFD_FileStyleFlags& vFlags, const char* vCriteria, const ImVec4& vColor, const std::string& vIcon, ImFont* vFont) + { + prFileDialogInternal.puFilterManager.SetFileStyle(vFlags, vCriteria, vColor, vIcon, vFont); + } - bool IGFD::FileDialog::GetFileStyle(const IGFD_FileStyleFlags& vFlags, const std::string& vCriteria, ImVec4* vOutColor, std::string* vOutIcon, ImFont **vOutFont) - { - return prFileDialogInternal.puFilterManager.GetFileStyle(vFlags, vCriteria, vOutColor, vOutIcon, vOutFont); - } + bool IGFD::FileDialog::GetFileStyle(const IGFD_FileStyleFlags& vFlags, const std::string& vCriteria, ImVec4* vOutColor, std::string* vOutIcon, ImFont **vOutFont) + { + return prFileDialogInternal.puFilterManager.GetFileStyle(vFlags, vCriteria, vOutColor, vOutIcon, vOutFont); + } - void IGFD::FileDialog::ClearFilesStyle() - { - prFileDialogInternal.puFilterManager.ClearFilesStyle(); - } + void IGFD::FileDialog::ClearFilesStyle() + { + prFileDialogInternal.puFilterManager.ClearFilesStyle(); + } - void IGFD::FileDialog::SetLocales(const int& vLocaleCategory, const std::string& vLocaleBegin, const std::string& vLocaleEnd) - { - prFileDialogInternal.puUseCustomLocale = true; - prFileDialogInternal.puLocaleBegin = vLocaleBegin; - prFileDialogInternal.puLocaleEnd = vLocaleEnd; - } + void IGFD::FileDialog::SetLocales(const int& vLocaleCategory, const std::string& vLocaleBegin, const std::string& vLocaleEnd) + { + prFileDialogInternal.puUseCustomLocale = true; + prFileDialogInternal.puLocaleBegin = vLocaleBegin; + prFileDialogInternal.puLocaleEnd = vLocaleEnd; + } - ////////////////////////////////////////////////////////////////////////////// - //// OVERWRITE DIALOG //////////////////////////////////////////////////////// - ////////////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////////////// + //// OVERWRITE DIALOG //////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////////////// - bool IGFD::FileDialog::prConfirm_Or_OpenOverWriteFileDialog_IfNeeded(bool vLastAction, ImGuiWindowFlags vFlags) - { - // if confirmation => return true for confirm the overwrite et quit the dialog - // if cancel => return false && set IsOk to false for keep inside the dialog + bool IGFD::FileDialog::prConfirm_Or_OpenOverWriteFileDialog_IfNeeded(bool vLastAction, ImGuiWindowFlags vFlags) + { + // if confirmation => return true for confirm the overwrite et quit the dialog + // if cancel => return false && set IsOk to false for keep inside the dialog - // if IsOk == false => return false for quit the dialog - if (!prFileDialogInternal.puIsOk && vLastAction) - { - QuitFrame(); - return true; - } + // if IsOk == false => return false for quit the dialog + if (!prFileDialogInternal.puIsOk && vLastAction) + { + QuitFrame(); + return true; + } - // if IsOk == true && no check of overwrite => return true for confirm the dialog - if (prFileDialogInternal.puIsOk && vLastAction && !(prFileDialogInternal.puDLGflags & ImGuiFileDialogFlags_ConfirmOverwrite)) - { - QuitFrame(); - return true; - } + // if IsOk == true && no check of overwrite => return true for confirm the dialog + if (prFileDialogInternal.puIsOk && vLastAction && !(prFileDialogInternal.puDLGflags & ImGuiFileDialogFlags_ConfirmOverwrite)) + { + QuitFrame(); + return true; + } - // if IsOk == true && check of overwrite => return false and show confirm to overwrite dialog - if ((prFileDialogInternal.puOkResultToConfirm || (prFileDialogInternal.puIsOk && vLastAction)) && - (prFileDialogInternal.puDLGflags & ImGuiFileDialogFlags_ConfirmOverwrite)) - { - if (prFileDialogInternal.puIsOk) // catched only one time - { - if (!prFileDialogInternal.puFileManager.IsFileExist(GetFilePathName())) // not existing => quit dialog - { - QuitFrame(); - return true; - } - else // existing => confirm dialog to open - { - prFileDialogInternal.puIsOk = false; - prFileDialogInternal.puOkResultToConfirm = true; - } - } + // if IsOk == true && check of overwrite => return false and show confirm to overwrite dialog + if ((prFileDialogInternal.puOkResultToConfirm || (prFileDialogInternal.puIsOk && vLastAction)) && + (prFileDialogInternal.puDLGflags & ImGuiFileDialogFlags_ConfirmOverwrite)) + { + if (prFileDialogInternal.puIsOk) // catched only one time + { + if (!prFileDialogInternal.puFileManager.IsFileExist(GetFilePathName())) // not existing => quit dialog + { + QuitFrame(); + return true; + } + else // existing => confirm dialog to open + { + prFileDialogInternal.puIsOk = false; + prFileDialogInternal.puOkResultToConfirm = true; + } + } - std::string name = OverWriteDialogTitleString "##" + prFileDialogInternal.puDLGtitle + prFileDialogInternal.puDLGkey + "OverWriteDialog"; + std::string name = OverWriteDialogTitleString "##" + prFileDialogInternal.puDLGtitle + prFileDialogInternal.puDLGkey + "OverWriteDialog"; - bool res = false; + bool res = false; - ImGui::OpenPopup(name.c_str()); - if (ImGui::BeginPopupModal(name.c_str(), (bool*)0, - vFlags | ImGuiWindowFlags_AlwaysAutoResize | - ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove)) - { - ImGui::SetWindowPos(prFileDialogInternal.puDialogCenterPos - ImGui::GetWindowSize() * 0.5f); // next frame needed for GetWindowSize to work + ImGui::OpenPopup(name.c_str()); + if (ImGui::BeginPopupModal(name.c_str(), (bool*)0, + vFlags | ImGuiWindowFlags_AlwaysAutoResize | + ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove)) + { + ImGui::SetWindowPos(prFileDialogInternal.puDialogCenterPos - ImGui::GetWindowSize() * 0.5f); // next frame needed for GetWindowSize to work - ImGui::Text("%s", OverWriteDialogMessageString); + ImGui::Text("%s", OverWriteDialogMessageString); - if (IMGUI_BUTTON(OverWriteDialogConfirmButtonString)) - { - prFileDialogInternal.puOkResultToConfirm = false; - prFileDialogInternal.puIsOk = true; - res = true; - ImGui::CloseCurrentPopup(); - } + if (IMGUI_BUTTON(OverWriteDialogConfirmButtonString)) + { + prFileDialogInternal.puOkResultToConfirm = false; + prFileDialogInternal.puIsOk = true; + res = true; + ImGui::CloseCurrentPopup(); + } - ImGui::SameLine(); + ImGui::SameLine(); - if (IMGUI_BUTTON(OverWriteDialogCancelButtonString)) - { - prFileDialogInternal.puOkResultToConfirm = false; - prFileDialogInternal.puIsOk = false; - res = false; - ImGui::CloseCurrentPopup(); - } + if (IMGUI_BUTTON(OverWriteDialogCancelButtonString)) + { + prFileDialogInternal.puOkResultToConfirm = false; + prFileDialogInternal.puIsOk = false; + res = false; + ImGui::CloseCurrentPopup(); + } - ImGui::EndPopup(); - } + ImGui::EndPopup(); + } - if (res) - { - QuitFrame(); - } - return res; - } + if (res) + { + QuitFrame(); + } + return res; + } - return false; - } + return false; + } } #endif // __cplusplus @@ -4639,574 +4592,574 @@ namespace IGFD // Return an initialized IGFD_Selection_Pair IMGUIFILEDIALOG_API IGFD_Selection_Pair IGFD_Selection_Pair_Get(void) { - IGFD_Selection_Pair res = {}; - res.fileName = nullptr; - res.filePathName = nullptr; - return res; + IGFD_Selection_Pair res = {}; + res.fileName = nullptr; + res.filePathName = nullptr; + return res; } // destroy only the content of vSelection_Pair IMGUIFILEDIALOG_API void IGFD_Selection_Pair_DestroyContent(IGFD_Selection_Pair* vSelection_Pair) { - if (vSelection_Pair) - { - delete[] vSelection_Pair->fileName; - delete[] vSelection_Pair->filePathName; - } + if (vSelection_Pair) + { + delete[] vSelection_Pair->fileName; + delete[] vSelection_Pair->filePathName; + } } // Return an initialized IGFD_Selection IMGUIFILEDIALOG_API IGFD_Selection IGFD_Selection_Get(void) { - return { nullptr, 0U }; + return { nullptr, 0U }; } // destroy only the content of vSelection IMGUIFILEDIALOG_API void IGFD_Selection_DestroyContent(IGFD_Selection* vSelection) { - if (vSelection) - { - if (vSelection->table) - { - for (size_t i = 0U; i < vSelection->count; i++) - { - IGFD_Selection_Pair_DestroyContent(&vSelection->table[i]); - } - delete[] vSelection->table; - } - vSelection->count = 0U; - } + if (vSelection) + { + if (vSelection->table) + { + for (size_t i = 0U; i < vSelection->count; i++) + { + IGFD_Selection_Pair_DestroyContent(&vSelection->table[i]); + } + delete[] vSelection->table; + } + vSelection->count = 0U; + } } // create an instance of ImGuiFileDialog IMGUIFILEDIALOG_API ImGuiFileDialog* IGFD_Create(void) { - return new ImGuiFileDialog(); + return new ImGuiFileDialog(); } // destroy the instance of ImGuiFileDialog IMGUIFILEDIALOG_API void IGFD_Destroy(ImGuiFileDialog* vContext) { - if (vContext) - { - delete vContext; - vContext = nullptr; - } + if (vContext) + { + delete vContext; + vContext = nullptr; + } } // standard dialog IMGUIFILEDIALOG_API void IGFD_OpenDialog( - ImGuiFileDialog* vContext, - const char* vKey, - const char* vTitle, - const char* vFilters, - const char* vPath, - const char* vFileName, - const int vCountSelectionMax, - void* vUserDatas, - ImGuiFileDialogFlags flags) + ImGuiFileDialog* vContext, + const char* vKey, + const char* vTitle, + const char* vFilters, + const char* vPath, + const char* vFileName, + const int vCountSelectionMax, + void* vUserDatas, + ImGuiFileDialogFlags flags) { - if (vContext) - { - vContext->OpenDialog( - vKey, vTitle, vFilters, vPath, vFileName, - vCountSelectionMax, vUserDatas, flags); - } + if (vContext) + { + vContext->OpenDialog( + vKey, vTitle, vFilters, vPath, vFileName, + vCountSelectionMax, vUserDatas, flags); + } } IMGUIFILEDIALOG_API void IGFD_OpenDialog2( - ImGuiFileDialog* vContext, - const char* vKey, - const char* vTitle, - const char* vFilters, - const char* vFilePathName, - const int vCountSelectionMax, - void* vUserDatas, - ImGuiFileDialogFlags flags) + ImGuiFileDialog* vContext, + const char* vKey, + const char* vTitle, + const char* vFilters, + const char* vFilePathName, + const int vCountSelectionMax, + void* vUserDatas, + ImGuiFileDialogFlags flags) { - if (vContext) - { - vContext->OpenDialog( - vKey, vTitle, vFilters, vFilePathName, - vCountSelectionMax, vUserDatas, flags); - } + if (vContext) + { + vContext->OpenDialog( + vKey, vTitle, vFilters, vFilePathName, + vCountSelectionMax, vUserDatas, flags); + } } IMGUIFILEDIALOG_API void IGFD_OpenPaneDialog( - ImGuiFileDialog* vContext, - const char* vKey, - const char* vTitle, - const char* vFilters, - const char* vPath, - const char* vFileName, - IGFD_PaneFun vSidePane, - const float vSidePaneWidth, - const int vCountSelectionMax, - void* vUserDatas, - ImGuiFileDialogFlags flags) + ImGuiFileDialog* vContext, + const char* vKey, + const char* vTitle, + const char* vFilters, + const char* vPath, + const char* vFileName, + IGFD_PaneFun vSidePane, + const float vSidePaneWidth, + const int vCountSelectionMax, + void* vUserDatas, + ImGuiFileDialogFlags flags) { - if (vContext) - { - vContext->OpenDialog( - vKey, vTitle, vFilters, - vPath, vFileName, - vSidePane, vSidePaneWidth, - vCountSelectionMax, vUserDatas, flags); - } + if (vContext) + { + vContext->OpenDialog( + vKey, vTitle, vFilters, + vPath, vFileName, + vSidePane, vSidePaneWidth, + vCountSelectionMax, vUserDatas, flags); + } } IMGUIFILEDIALOG_API void IGFD_OpenPaneDialog2( - ImGuiFileDialog* vContext, - const char* vKey, - const char* vTitle, - const char* vFilters, - const char* vFilePathName, - IGFD_PaneFun vSidePane, - const float vSidePaneWidth, - const int vCountSelectionMax, - void* vUserDatas, - ImGuiFileDialogFlags flags) + ImGuiFileDialog* vContext, + const char* vKey, + const char* vTitle, + const char* vFilters, + const char* vFilePathName, + IGFD_PaneFun vSidePane, + const float vSidePaneWidth, + const int vCountSelectionMax, + void* vUserDatas, + ImGuiFileDialogFlags flags) { - if (vContext) - { - vContext->OpenDialog( - vKey, vTitle, vFilters, - vFilePathName, - vSidePane, vSidePaneWidth, - vCountSelectionMax, vUserDatas, flags); - } + if (vContext) + { + vContext->OpenDialog( + vKey, vTitle, vFilters, + vFilePathName, + vSidePane, vSidePaneWidth, + vCountSelectionMax, vUserDatas, flags); + } } // modal dialog IMGUIFILEDIALOG_API void IGFD_OpenModal( - ImGuiFileDialog* vContext, - const char* vKey, - const char* vTitle, - const char* vFilters, - const char* vPath, - const char* vFileName, - const int vCountSelectionMax, - void* vUserDatas, - ImGuiFileDialogFlags flags) + ImGuiFileDialog* vContext, + const char* vKey, + const char* vTitle, + const char* vFilters, + const char* vPath, + const char* vFileName, + const int vCountSelectionMax, + void* vUserDatas, + ImGuiFileDialogFlags flags) { - if (vContext) - { - vContext->OpenModal( - vKey, vTitle, vFilters, vPath, vFileName, - vCountSelectionMax, vUserDatas, flags); - } + if (vContext) + { + vContext->OpenModal( + vKey, vTitle, vFilters, vPath, vFileName, + vCountSelectionMax, vUserDatas, flags); + } } IMGUIFILEDIALOG_API void IGFD_OpenModal2( - ImGuiFileDialog* vContext, - const char* vKey, - const char* vTitle, - const char* vFilters, - const char* vFilePathName, - const int vCountSelectionMax, - void* vUserDatas, - ImGuiFileDialogFlags flags) + ImGuiFileDialog* vContext, + const char* vKey, + const char* vTitle, + const char* vFilters, + const char* vFilePathName, + const int vCountSelectionMax, + void* vUserDatas, + ImGuiFileDialogFlags flags) { - if (vContext) - { - vContext->OpenModal( - vKey, vTitle, vFilters, vFilePathName, - vCountSelectionMax, vUserDatas, flags); - } + if (vContext) + { + vContext->OpenModal( + vKey, vTitle, vFilters, vFilePathName, + vCountSelectionMax, vUserDatas, flags); + } } IMGUIFILEDIALOG_API void IGFD_OpenPaneModal( - ImGuiFileDialog* vContext, - const char* vKey, - const char* vTitle, - const char* vFilters, - const char* vPath, - const char* vFileName, - IGFD_PaneFun vSidePane, - const float vSidePaneWidth, - const int vCountSelectionMax, - void* vUserDatas, - ImGuiFileDialogFlags flags) + ImGuiFileDialog* vContext, + const char* vKey, + const char* vTitle, + const char* vFilters, + const char* vPath, + const char* vFileName, + IGFD_PaneFun vSidePane, + const float vSidePaneWidth, + const int vCountSelectionMax, + void* vUserDatas, + ImGuiFileDialogFlags flags) { - if (vContext) - { - vContext->OpenModal( - vKey, vTitle, vFilters, - vPath, vFileName, - vSidePane, vSidePaneWidth, - vCountSelectionMax, vUserDatas, flags); - } + if (vContext) + { + vContext->OpenModal( + vKey, vTitle, vFilters, + vPath, vFileName, + vSidePane, vSidePaneWidth, + vCountSelectionMax, vUserDatas, flags); + } } IMGUIFILEDIALOG_API void IGFD_OpenPaneModal2( - ImGuiFileDialog* vContext, - const char* vKey, - const char* vTitle, - const char* vFilters, - const char* vFilePathName, - IGFD_PaneFun vSidePane, - const float vSidePaneWidth, - const int vCountSelectionMax, - void* vUserDatas, - ImGuiFileDialogFlags flags) + ImGuiFileDialog* vContext, + const char* vKey, + const char* vTitle, + const char* vFilters, + const char* vFilePathName, + IGFD_PaneFun vSidePane, + const float vSidePaneWidth, + const int vCountSelectionMax, + void* vUserDatas, + ImGuiFileDialogFlags flags) { - if (vContext) - { - vContext->OpenModal( - vKey, vTitle, vFilters, - vFilePathName, - vSidePane, vSidePaneWidth, - vCountSelectionMax, vUserDatas, flags); - } + if (vContext) + { + vContext->OpenModal( + vKey, vTitle, vFilters, + vFilePathName, + vSidePane, vSidePaneWidth, + vCountSelectionMax, vUserDatas, flags); + } } IMGUIFILEDIALOG_API bool IGFD_DisplayDialog(ImGuiFileDialog* vContext, - const char* vKey, ImGuiWindowFlags vFlags, ImVec2 vMinSize, ImVec2 vMaxSize) + const char* vKey, ImGuiWindowFlags vFlags, ImVec2 vMinSize, ImVec2 vMaxSize) { - if (vContext) - { - return vContext->Display(vKey, vFlags, vMinSize, vMaxSize); - } + if (vContext) + { + return vContext->Display(vKey, vFlags, vMinSize, vMaxSize); + } - return false; + return false; } IMGUIFILEDIALOG_API void IGFD_CloseDialog(ImGuiFileDialog* vContext) { - if (vContext) - { - vContext->Close(); - } + if (vContext) + { + vContext->Close(); + } } IMGUIFILEDIALOG_API bool IGFD_IsOk(ImGuiFileDialog* vContext) { - if (vContext) - { - return vContext->IsOk(); - } + if (vContext) + { + return vContext->IsOk(); + } - return false; + return false; } IMGUIFILEDIALOG_API bool IGFD_WasKeyOpenedThisFrame(ImGuiFileDialog* vContext, - const char* vKey) + const char* vKey) { - if (vContext) - { - vContext->WasOpenedThisFrame(vKey); - } + if (vContext) + { + vContext->WasOpenedThisFrame(vKey); + } - return false; + return false; } IMGUIFILEDIALOG_API bool IGFD_WasOpenedThisFrame(ImGuiFileDialog* vContext) { - if (vContext) - { - vContext->WasOpenedThisFrame(); - } + if (vContext) + { + vContext->WasOpenedThisFrame(); + } - return false; + return false; } IMGUIFILEDIALOG_API bool IGFD_IsKeyOpened(ImGuiFileDialog* vContext, - const char* vCurrentOpenedKey) + const char* vCurrentOpenedKey) { - if (vContext) - { - vContext->IsOpened(vCurrentOpenedKey); - } + if (vContext) + { + vContext->IsOpened(vCurrentOpenedKey); + } - return false; + return false; } IMGUIFILEDIALOG_API bool IGFD_IsOpened(ImGuiFileDialog* vContext) { - if (vContext) - { - vContext->IsOpened(); - } + if (vContext) + { + vContext->IsOpened(); + } - return false; + return false; } IMGUIFILEDIALOG_API IGFD_Selection IGFD_GetSelection(ImGuiFileDialog* vContext) { - IGFD_Selection res = IGFD_Selection_Get(); + IGFD_Selection res = IGFD_Selection_Get(); - if (vContext) - { - auto sel = vContext->GetSelection(); - if (!sel.empty()) - { - res.count = sel.size(); - res.table = new IGFD_Selection_Pair[res.count]; + if (vContext) + { + auto sel = vContext->GetSelection(); + if (!sel.empty()) + { + res.count = sel.size(); + res.table = new IGFD_Selection_Pair[res.count]; - size_t idx = 0U; - for (const auto& s : sel) - { - IGFD_Selection_Pair* pair = res.table + idx++; + size_t idx = 0U; + for (const auto& s : sel) + { + IGFD_Selection_Pair* pair = res.table + idx++; - // fileNameExt - if (!s.first.empty()) - { - size_t siz = s.first.size() + 1U; - pair->fileName = new char[siz]; + // fileNameExt + if (!s.first.empty()) + { + size_t siz = s.first.size() + 1U; + pair->fileName = new char[siz]; #ifndef MSVC - strncpy(pair->fileName, s.first.c_str(), siz); + strncpy(pair->fileName, s.first.c_str(), siz); #else - strncpy_s(pair->fileName, siz, s.first.c_str(), siz); + strncpy_s(pair->fileName, siz, s.first.c_str(), siz); #endif - pair->fileName[siz - 1U] = '\0'; - } + pair->fileName[siz - 1U] = '\0'; + } - // filePathName - if (!s.second.empty()) - { - size_t siz = s.first.size() + 1U; - pair->filePathName = new char[siz]; + // filePathName + if (!s.second.empty()) + { + size_t siz = s.first.size() + 1U; + pair->filePathName = new char[siz]; #ifndef MSVC - strncpy(pair->filePathName, s.first.c_str(), siz); + strncpy(pair->filePathName, s.first.c_str(), siz); #else - strncpy_s(pair->filePathName, siz, s.first.c_str(), siz); + strncpy_s(pair->filePathName, siz, s.first.c_str(), siz); #endif - pair->filePathName[siz - 1U] = '\0'; - } - } + pair->filePathName[siz - 1U] = '\0'; + } + } - return res; - } - } + return res; + } + } - return res; + return res; } IMGUIFILEDIALOG_API char* IGFD_GetFilePathName(ImGuiFileDialog* vContext) { - char* res = nullptr; + char* res = nullptr; - if (vContext) - { - auto s = vContext->GetFilePathName(); - if (!s.empty()) - { - size_t siz = s.size() + 1U; - res = new char[siz]; + if (vContext) + { + auto s = vContext->GetFilePathName(); + if (!s.empty()) + { + size_t siz = s.size() + 1U; + res = new char[siz]; #ifndef MSVC - strncpy(res, s.c_str(), siz); + strncpy(res, s.c_str(), siz); #else - strncpy_s(res, siz, s.c_str(), siz); + strncpy_s(res, siz, s.c_str(), siz); #endif - res[siz - 1U] = '\0'; - } - } + res[siz - 1U] = '\0'; + } + } - return res; + return res; } IMGUIFILEDIALOG_API char* IGFD_GetCurrentFileName(ImGuiFileDialog* vContext) { - char* res = nullptr; + char* res = nullptr; - if (vContext) - { - auto s = vContext->GetCurrentFileName(); - if (!s.empty()) - { - size_t siz = s.size() + 1U; - res = new char[siz]; + if (vContext) + { + auto s = vContext->GetCurrentFileName(); + if (!s.empty()) + { + size_t siz = s.size() + 1U; + res = new char[siz]; #ifndef MSVC - strncpy(res, s.c_str(), siz); + strncpy(res, s.c_str(), siz); #else - strncpy_s(res, siz, s.c_str(), siz); + strncpy_s(res, siz, s.c_str(), siz); #endif - res[siz - 1U] = '\0'; - } - } + res[siz - 1U] = '\0'; + } + } - return res; + return res; } IMGUIFILEDIALOG_API char* IGFD_GetCurrentPath(ImGuiFileDialog* vContext) { - char* res = nullptr; + char* res = nullptr; - if (vContext) - { - auto s = vContext->GetCurrentPath(); - if (!s.empty()) - { - size_t siz = s.size() + 1U; - res = new char[siz]; + if (vContext) + { + auto s = vContext->GetCurrentPath(); + if (!s.empty()) + { + size_t siz = s.size() + 1U; + res = new char[siz]; #ifndef MSVC - strncpy(res, s.c_str(), siz); + strncpy(res, s.c_str(), siz); #else - strncpy_s(res, siz, s.c_str(), siz); + strncpy_s(res, siz, s.c_str(), siz); #endif - res[siz - 1U] = '\0'; - } - } + res[siz - 1U] = '\0'; + } + } - return res; + return res; } IMGUIFILEDIALOG_API char* IGFD_GetCurrentFilter(ImGuiFileDialog* vContext) { - char* res = nullptr; + char* res = nullptr; - if (vContext) - { - auto s = vContext->GetCurrentFilter(); - if (!s.empty()) - { - size_t siz = s.size() + 1U; - res = new char[siz]; + if (vContext) + { + auto s = vContext->GetCurrentFilter(); + if (!s.empty()) + { + size_t siz = s.size() + 1U; + res = new char[siz]; #ifndef MSVC - strncpy(res, s.c_str(), siz); + strncpy(res, s.c_str(), siz); #else - strncpy_s(res, siz, s.c_str(), siz); + strncpy_s(res, siz, s.c_str(), siz); #endif - res[siz - 1U] = '\0'; - } - } + res[siz - 1U] = '\0'; + } + } - return res; + return res; } IMGUIFILEDIALOG_API void* IGFD_GetUserDatas(ImGuiFileDialog* vContext) { - if (vContext) - { - return vContext->GetUserDatas(); - } + if (vContext) + { + return vContext->GetUserDatas(); + } - return nullptr; + return nullptr; } IMGUIFILEDIALOG_API void IGFD_SetFileStyle(ImGuiFileDialog* vContext, - IGFD_FileStyleFlags vFlags, const char* vCriteria, ImVec4 vColor, const char* vIcon, ImFont* vFont) //-V813 + IGFD_FileStyleFlags vFlags, const char* vCriteria, ImVec4 vColor, const char* vIcon, ImFont* vFont) //-V813 { - if (vContext) - { - vContext->SetFileStyle(vFlags, vCriteria, vColor, vIcon, vFont); - } + if (vContext) + { + vContext->SetFileStyle(vFlags, vCriteria, vColor, vIcon, vFont); + } } IMGUIFILEDIALOG_API void IGFD_SetFileStyle2(ImGuiFileDialog* vContext, - IGFD_FileStyleFlags vFlags, const char* vCriteria, float vR, float vG, float vB, float vA, const char* vIcon, ImFont* vFont) + IGFD_FileStyleFlags vFlags, const char* vCriteria, float vR, float vG, float vB, float vA, const char* vIcon, ImFont* vFont) { - if (vContext) - { - vContext->SetFileStyle(vFlags, vCriteria, ImVec4(vR, vG, vB, vA), vIcon, vFont); - } + if (vContext) + { + vContext->SetFileStyle(vFlags, vCriteria, ImVec4(vR, vG, vB, vA), vIcon, vFont); + } } IMGUIFILEDIALOG_API bool IGFD_GetFileStyle(ImGuiFileDialog* vContext, - IGFD_FileStyleFlags vFlags, const char* vCriteria, ImVec4* vOutColor, char** vOutIcon, ImFont** vOutFont) + IGFD_FileStyleFlags vFlags, const char* vCriteria, ImVec4* vOutColor, char** vOutIcon, ImFont** vOutFont) { - if (vContext) - { - std::string icon; - bool res = vContext->GetFileStyle(vFlags, vCriteria, vOutColor, &icon, vOutFont); - if (!icon.empty() && vOutIcon) - { - size_t siz = icon.size() + 1U; - *vOutIcon = new char[siz]; + if (vContext) + { + std::string icon; + bool res = vContext->GetFileStyle(vFlags, vCriteria, vOutColor, &icon, vOutFont); + if (!icon.empty() && vOutIcon) + { + size_t siz = icon.size() + 1U; + *vOutIcon = new char[siz]; #ifndef MSVC - strncpy(*vOutIcon, icon.c_str(), siz); + strncpy(*vOutIcon, icon.c_str(), siz); #else - strncpy_s(*vOutIcon, siz, icon.c_str(), siz); + strncpy_s(*vOutIcon, siz, icon.c_str(), siz); #endif - (*vOutIcon)[siz - 1U] = '\0'; - } - return res; - } + (*vOutIcon)[siz - 1U] = '\0'; + } + return res; + } - return false; + return false; } IMGUIFILEDIALOG_API void IGFD_ClearFilesStyle(ImGuiFileDialog* vContext) { - if (vContext) - { - vContext->ClearFilesStyle(); - } + if (vContext) + { + vContext->ClearFilesStyle(); + } } IMGUIFILEDIALOG_API void SetLocales(ImGuiFileDialog* vContext, const int vCategory, const char* vBeginLocale, const char* vEndLocale) { - if (vContext) - { - vContext->SetLocales(vCategory, (vBeginLocale ? vBeginLocale : ""), (vEndLocale ? vEndLocale : "")); - } + if (vContext) + { + vContext->SetLocales(vCategory, (vBeginLocale ? vBeginLocale : ""), (vEndLocale ? vEndLocale : "")); + } } #ifdef USE_EXPLORATION_BY_KEYS IMGUIFILEDIALOG_API void IGFD_SetFlashingAttenuationInSeconds(ImGuiFileDialog* vContext, float vAttenValue) { - if (vContext) - { - vContext->SetFlashingAttenuationInSeconds(vAttenValue); - } + if (vContext) + { + vContext->SetFlashingAttenuationInSeconds(vAttenValue); + } } #endif #ifdef USE_BOOKMARK IMGUIFILEDIALOG_API char* IGFD_SerializeBookmarks(ImGuiFileDialog* vContext) { - char* res = nullptr; + char* res = nullptr; - if (vContext) - { - auto s = vContext->SerializeBookmarks(); - if (!s.empty()) - { - size_t siz = s.size() + 1U; - res = new char[siz]; + if (vContext) + { + auto s = vContext->SerializeBookmarks(); + if (!s.empty()) + { + size_t siz = s.size() + 1U; + res = new char[siz]; #ifndef MSVC - strncpy(res, s.c_str(), siz); + strncpy(res, s.c_str(), siz); #else - strncpy_s(res, siz, s.c_str(), siz); + strncpy_s(res, siz, s.c_str(), siz); #endif - res[siz - 1U] = '\0'; - } - } + res[siz - 1U] = '\0'; + } + } - return res; + return res; } IMGUIFILEDIALOG_API void IGFD_DeserializeBookmarks(ImGuiFileDialog* vContext, const char* vBookmarks) { - if (vContext) - { - vContext->DeserializeBookmarks(vBookmarks); - } + if (vContext) + { + vContext->DeserializeBookmarks(vBookmarks); + } } #endif #ifdef USE_THUMBNAILS IMGUIFILEDIALOG_API void SetCreateThumbnailCallback(ImGuiFileDialog* vContext, const IGFD_CreateThumbnailFun vCreateThumbnailFun) { - if (vContext) - { - vContext->SetCreateThumbnailCallback(vCreateThumbnailFun); - } + if (vContext) + { + vContext->SetCreateThumbnailCallback(vCreateThumbnailFun); + } } IMGUIFILEDIALOG_API void SetDestroyThumbnailCallback(ImGuiFileDialog* vContext, const IGFD_DestroyThumbnailFun vDestroyThumbnailFun) { - if (vContext) - { - vContext->SetDestroyThumbnailCallback(vDestroyThumbnailFun); - } + if (vContext) + { + vContext->SetDestroyThumbnailCallback(vDestroyThumbnailFun); + } } IMGUIFILEDIALOG_API void ManageGPUThumbnails(ImGuiFileDialog* vContext) { - if (vContext) - { - vContext->ManageGPUThumbnails(); - } + if (vContext) + { + vContext->ManageGPUThumbnails(); + } } #endif // USE_THUMBNAILS diff --git a/extern/igfd/ImGuiFileDialog.h b/extern/igfd/ImGuiFileDialog.h index 7b252395..93db26e9 100644 --- a/extern/igfd/ImGuiFileDialog.h +++ b/extern/igfd/ImGuiFileDialog.h @@ -85,20 +85,20 @@ void drawGui() { // open Dialog Simple if (ImGui::Button("Open File Dialog")) - ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", "Choose File", ".cpp,.h,.hpp", "."); + ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", "Choose File", ".cpp,.h,.hpp", "."); // display if (ImGuiFileDialog::Instance()->FileDialog("ChooseFileDlgKey")) { - // action if OK - if (ImGuiFileDialog::Instance()->IsOk == true) - { - std::string filePathName = ImGuiFileDialog::Instance()->GetFilePathName(); - std::string filePath = ImGuiFileDialog::Instance()->GetCurrentPath(); - // action - } - // close - ImGuiFileDialog::Instance()->CloseDialog("ChooseFileDlgKey"); + // action if OK + if (ImGuiFileDialog::Instance()->IsOk == true) + { + std::string filePathName = ImGuiFileDialog::Instance()->GetFilePathName(); + std::string filePath = ImGuiFileDialog::Instance()->GetCurrentPath(); + // action + } + // close + ImGuiFileDialog::Instance()->CloseDialog("ChooseFileDlgKey"); } } @@ -121,40 +121,40 @@ Example code : static bool canValidateDialog = false; inline void InfosPane(std::string& vFilter, IGFD::UserDatas vUserDatas, bool *vCantContinue) // if vCantContinue is false, the user cant validate the dialog { - ImGui::TextColored(ImVec4(0, 1, 1, 1), "Infos Pane"); - ImGui::Text("Selected Filter : %s", vFilter.c_str()); - if (vUserDatas) - ImGui::Text("UserDatas : %s", vUserDatas); - ImGui::Checkbox("if not checked you cant validate the dialog", &canValidateDialog); - if (vCantContinue) - *vCantContinue = canValidateDialog; + ImGui::TextColored(ImVec4(0, 1, 1, 1), "Infos Pane"); + ImGui::Text("Selected Filter : %s", vFilter.c_str()); + if (vUserDatas) + ImGui::Text("UserDatas : %s", vUserDatas); + ImGui::Checkbox("if not checked you cant validate the dialog", &canValidateDialog); + if (vCantContinue) + *vCantContinue = canValidateDialog; } void drawGui() { // open Dialog with Pane if (ImGui::Button("Open File Dialog with a custom pane")) - ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", "Choose File", ".cpp,.h,.hpp", - ".", "", std::bind(&InfosPane, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3), 350, 1, IGFD::UserDatas("InfosPane")); + ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", "Choose File", ".cpp,.h,.hpp", + ".", "", std::bind(&InfosPane, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3), 350, 1, IGFD::UserDatas("InfosPane")); // display and action if ok if (ImGuiFileDialog::Instance()->FileDialog("ChooseFileDlgKey")) { - if (ImGuiFileDialog::Instance()->IsOk == true) - { - std::string filePathName = ImGuiFileDialog::Instance()->GetFilePathName(); - std::string filePath = ImGuiFileDialog::Instance()->GetCurrentPath(); - std::string filter = ImGuiFileDialog::Instance()->GetCurrentFilter(); - // here convert from string because a string was passed as a userDatas, but it can be what you want - std::string userDatas; - if (ImGuiFileDialog::Instance()->GetUserDatas()) - userDatas = std::string((const char*)ImGuiFileDialog::Instance()->GetUserDatas()); - auto selection = ImGuiFileDialog::Instance()->GetSelection(); // multiselection + if (ImGuiFileDialog::Instance()->IsOk == true) + { + std::string filePathName = ImGuiFileDialog::Instance()->GetFilePathName(); + std::string filePath = ImGuiFileDialog::Instance()->GetCurrentPath(); + std::string filter = ImGuiFileDialog::Instance()->GetCurrentFilter(); + // here convert from string because a string was passed as a userDatas, but it can be what you want + std::string userDatas; + if (ImGuiFileDialog::Instance()->GetUserDatas()) + userDatas = std::string((const char*)ImGuiFileDialog::Instance()->GetUserDatas()); + auto selection = ImGuiFileDialog::Instance()->GetSelection(); // multiselection - // action - } - // close - ImGuiFileDialog::Instance()->CloseDialog("ChooseFileDlgKey"); + // action + } + // close + ImGuiFileDialog::Instance()->CloseDialog("ChooseFileDlgKey"); } } @@ -170,13 +170,13 @@ the general form is : ImGuiFileDialog::Instance()->SetFileStyle(styleType, criteria, color, icon, font); styleType can be thoses : -IGFD_FileStyle_None // define none style -IGFD_FileStyleByTypeFile // define style for all files -IGFD_FileStyleByTypeDir // define style for all dir -IGFD_FileStyleByTypeLink // define style for all link -IGFD_FileStyleByExtention // define style by extention, for files or links -IGFD_FileStyleByFullName // define style for particular file/dir/link full name (filename + extention) -IGFD_FileStyleByContainedInFullName // define style for file/dir/link when criteria is contained in full name +IGFD_FileStyle_None // define none style +IGFD_FileStyleByTypeFile // define style for all files +IGFD_FileStyleByTypeDir // define style for all dir +IGFD_FileStyleByTypeLink // define style for all link +IGFD_FileStyleByExtention // define style by extention, for files or links +IGFD_FileStyleByFullName // define style for particular file/dir/link full name (filename + extention) +IGFD_FileStyleByContainedInFullName // define style for file/dir/link when criteria is contained in full name samples : @@ -341,14 +341,14 @@ define if a dialog will be for Open or Save behavior. (and its wanted :) ) Example code For Standard Dialog : Example code : ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", - ICON_IGFD_SAVE " Choose a File", filters, - ".", "", 1, nullptr, ImGuiFileDialogFlags_ConfirmOverwrite); + ICON_IGFD_SAVE " Choose a File", filters, + ".", "", 1, nullptr, ImGuiFileDialogFlags_ConfirmOverwrite); Example code For Modal Dialog : Example code : ImGuiFileDialog::Instance()->OpenModal("ChooseFileDlgKey", - ICON_IGFD_SAVE " Choose a File", filters, - ".", "", 1, nullptr, ImGuiFileDialogFlags_ConfirmOverwrite); + ICON_IGFD_SAVE " Choose a File", filters, + ".", "", 1, nullptr, ImGuiFileDialogFlags_ConfirmOverwrite); This dialog will only verify the file in the file field. So Not to be used with GetSelection() @@ -372,8 +372,8 @@ Example code : ----------------------------------------------------------------------------------------------------------------- flag must be specified in OpenDialog or OpenModal -* ImGuiFileDialogFlags_ConfirmOverwrite => show confirm to overwrite dialog -* ImGuiFileDialogFlags_DontShowHiddenFiles => dont show hidden file (file starting with a .) +* ImGuiFileDialogFlags_ConfirmOverwrite => show confirm to overwrite dialog +* ImGuiFileDialogFlags_DontShowHiddenFiles => dont show hidden file (file starting with a .) ----------------------------------------------------------------------------------------------------------------- ## Open / Save dialog Behavior : @@ -419,43 +419,43 @@ Example code : // Create thumbnails texture ImGuiFileDialog::Instance()->SetCreateThumbnailCallback([](IGFD_Thumbnail_Info *vThumbnail_Info) -> void { - if (vThumbnail_Info && - vThumbnail_Info->isReadyToUpload && - vThumbnail_Info->textureFileDatas) - { - GLuint textureId = 0; - glGenTextures(1, &textureId); - vThumbnail_Info->textureID = (void*)textureId; + if (vThumbnail_Info && + vThumbnail_Info->isReadyToUpload && + vThumbnail_Info->textureFileDatas) + { + GLuint textureId = 0; + glGenTextures(1, &textureId); + vThumbnail_Info->textureID = (void*)textureId; - glBindTexture(GL_TEXTURE_2D, textureId); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, - (GLsizei)vThumbnail_Info->textureWidth, (GLsizei)vThumbnail_Info->textureHeight, - 0, GL_RGBA, GL_UNSIGNED_BYTE, vThumbnail_Info->textureFileDatas); - glFinish(); - glBindTexture(GL_TEXTURE_2D, 0); + glBindTexture(GL_TEXTURE_2D, textureId); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, + (GLsizei)vThumbnail_Info->textureWidth, (GLsizei)vThumbnail_Info->textureHeight, + 0, GL_RGBA, GL_UNSIGNED_BYTE, vThumbnail_Info->textureFileDatas); + glFinish(); + glBindTexture(GL_TEXTURE_2D, 0); - delete[] vThumbnail_Info->textureFileDatas; - vThumbnail_Info->textureFileDatas = nullptr; + delete[] vThumbnail_Info->textureFileDatas; + vThumbnail_Info->textureFileDatas = nullptr; - vThumbnail_Info->isReadyToUpload = false; - vThumbnail_Info->isReadyToDisplay = true; - } + vThumbnail_Info->isReadyToUpload = false; + vThumbnail_Info->isReadyToDisplay = true; + } }); Example code : // Destroy thumbnails texture ImGuiFileDialog::Instance()->SetDestroyThumbnailCallback([](IGFD_Thumbnail_Info* vThumbnail_Info) { - if (vThumbnail_Info) - { - GLuint texID = (GLuint)vThumbnail_Info->textureID; - glDeleteTextures(1, &texID); - glFinish(); - } + if (vThumbnail_Info) + { + GLuint texID = (GLuint)vThumbnail_Info->textureID; + glDeleteTextures(1, &texID); + glFinish(); + } }); Example code : @@ -477,17 +477,17 @@ ImGuiFileDialog *cfileDialog = IGFD_Create(); // open dialog if (igButton("Open File", buttonSize)) { - IGFD_OpenDialog(cfiledialog, - "filedlg", // dialog key (make it possible to have different treatment reagrding the dialog key - "Open a File", // dialog title - "c files(*.c *.h){.c,.h}", // dialog filter syntax : simple => .h,.c,.pp, etc and collections : text1{filter0,filter1,filter2}, text2{filter0,filter1,filter2}, etc.. - ".", // base directory for files scan - "", // base filename - 0, // a fucntion for display a right pane if you want - 0.0f, // base width of the pane - 0, // count selection : 0 infinite, 1 one file (default), n (n files) - "User data !", // some user datas - ImGuiFileDialogFlags_ConfirmOverwrite); // ImGuiFileDialogFlags + IGFD_OpenDialog(cfiledialog, + "filedlg", // dialog key (make it possible to have different treatment reagrding the dialog key + "Open a File", // dialog title + "c files(*.c *.h){.c,.h}", // dialog filter syntax : simple => .h,.c,.pp, etc and collections : text1{filter0,filter1,filter2}, text2{filter0,filter1,filter2}, etc.. + ".", // base directory for files scan + "", // base filename + 0, // a fucntion for display a right pane if you want + 0.0f, // base width of the pane + 0, // count selection : 0 infinite, 1 one file (default), n (n files) + "User data !", // some user datas + ImGuiFileDialogFlags_ConfirmOverwrite); // ImGuiFileDialogFlags } ImGuiIO* ioptr = igGetIO(); @@ -501,56 +501,46 @@ minSize.y = maxSize.y * 0.25f; // display dialog if (IGFD_DisplayDialog(cfiledialog, "filedlg", ImGuiWindowFlags_NoCollapse, minSize, maxSize)) { - if (IGFD_IsOk(cfiledialog)) // result ok - { - char* cfilePathName = IGFD_GetFilePathName(cfiledialog); - printf("GetFilePathName : %s\n", cfilePathName); - char* cfilePath = IGFD_GetCurrentPath(cfiledialog); - printf("GetCurrentPath : %s\n", cfilePath); - char* cfilter = IGFD_GetCurrentFilter(cfiledialog); - printf("GetCurrentFilter : %s\n", cfilter); - // here convert from string because a string was passed as a userDatas, but it can be what you want - void* cdatas = IGFD_GetUserDatas(cfiledialog); - if (cdatas) - printf("GetUserDatas : %s\n", (const char*)cdatas); - struct IGFD_Selection csel = IGFD_GetSelection(cfiledialog); // multi selection - printf("Selection :\n"); - for (int i = 0; i < (int)csel.count; i++) - { - printf("(%i) FileName %s => path %s\n", i, csel.table[i].fileName, csel.table[i].filePathName); - } - // action + if (IGFD_IsOk(cfiledialog)) // result ok + { + char* cfilePathName = IGFD_GetFilePathName(cfiledialog); + printf("GetFilePathName : %s\n", cfilePathName); + char* cfilePath = IGFD_GetCurrentPath(cfiledialog); + printf("GetCurrentPath : %s\n", cfilePath); + char* cfilter = IGFD_GetCurrentFilter(cfiledialog); + printf("GetCurrentFilter : %s\n", cfilter); + // here convert from string because a string was passed as a userDatas, but it can be what you want + void* cdatas = IGFD_GetUserDatas(cfiledialog); + if (cdatas) + printf("GetUserDatas : %s\n", (const char*)cdatas); + struct IGFD_Selection csel = IGFD_GetSelection(cfiledialog); // multi selection + printf("Selection :\n"); + for (int i = 0; i < (int)csel.count; i++) + { + printf("(%i) FileName %s => path %s\n", i, csel.table[i].fileName, csel.table[i].filePathName); + } + // action - // destroy - if (cfilePathName) free(cfilePathName); - if (cfilePath) free(cfilePath); - if (cfilter) free(cfilter); + // destroy + if (cfilePathName) free(cfilePathName); + if (cfilePath) free(cfilePath); + if (cfilter) free(cfilter); - IGFD_Selection_DestroyContent(&csel); - } - IGFD_CloseDialog(cfiledialog); + IGFD_Selection_DestroyContent(&csel); + } + IGFD_CloseDialog(cfiledialog); } // destroy ImGuiFileDialog IGFD_Destroy(cfiledialog); ------------------------------------------------------------------------------------------------------------------ -## Std::filesystem (c++17) can be used instead of dirent.h ------------------------------------------------------------------------------------------------------------------ - -you just need to uncomment that in the config file - -#define USE_STD_FILESYSTEM - -in this mode dirent is not more required - ----------------------------------------------------------------------------------------------------------------- ## How to Integrate ImGuiFileDialog in your project ----------------------------------------------------------------------------------------------------------------- ### ImGuiFileDialog require : -* dirent v1.23 (only when USE_STD_FILESYSTEM is not defined) (https://github.com/tronkko/dirent/tree/v1.23) lib, only for windows. Successfully tested with version v1.23 only +* dirent v1.23 (https://github.com/tronkko/dirent/tree/v1.23) lib, only for windows. Successfully tested with version v1.23 only * Dear ImGui (https://github.com/ocornut/imgui/tree/master) (with/without tables widgets) ### Customize ImGuiFileDialog : @@ -582,9 +572,9 @@ ImGuiFontStudio is using also ImGuiFileDialog. #define IMGUIFILEDIALOG_H #if defined(__WIN32__) || defined(_WIN32) - #ifndef WIN32 - #define WIN32 - #endif // WIN32 + #ifndef WIN32 + #define WIN32 + #endif // WIN32 #endif // defined(__WIN32__) || defined(_WIN32) #define IMGUIFILEDIALOG_VERSION "v0.6.4" @@ -599,43 +589,43 @@ ImGuiFontStudio is using also ImGuiFileDialog. typedef int IGFD_FileStyleFlags; // -> enum IGFD_FileStyleFlags_ enum IGFD_FileStyleFlags_ // by evaluation / priority order { - IGFD_FileStyle_None = 0, // define none style - IGFD_FileStyleByTypeFile = (1 << 0), // define style for all files - IGFD_FileStyleByTypeDir = (1 << 1), // define style for all dir - IGFD_FileStyleByTypeLink = (1 << 2), // define style for all link - IGFD_FileStyleByExtention = (1 << 3), // define style by extention, for files or links - IGFD_FileStyleByFullName = (1 << 4), // define style for particular file/dir/link full name (filename + extention) - IGFD_FileStyleByContainedInFullName = (1 << 5), // define style for file/dir/link when criteria is contained in full name + IGFD_FileStyle_None = 0, // define none style + IGFD_FileStyleByTypeFile = (1 << 0), // define style for all files + IGFD_FileStyleByTypeDir = (1 << 1), // define style for all dir + IGFD_FileStyleByTypeLink = (1 << 2), // define style for all link + IGFD_FileStyleByExtention = (1 << 3), // define style by extention, for files or links + IGFD_FileStyleByFullName = (1 << 4), // define style for particular file/dir/link full name (filename + extention) + IGFD_FileStyleByContainedInFullName = (1 << 5), // define style for file/dir/link when criteria is contained in full name }; typedef int ImGuiFileDialogFlags; // -> enum ImGuiFileDialogFlags_ enum ImGuiFileDialogFlags_ { - ImGuiFileDialogFlags_None = 0, - ImGuiFileDialogFlags_ConfirmOverwrite = (1 << 0), // show confirm to overwrite dialog - ImGuiFileDialogFlags_DontShowHiddenFiles = (1 << 1), // dont show hidden file (file starting with a .) - ImGuiFileDialogFlags_DisableCreateDirectoryButton = (1 << 2), // disable the create directory button - ImGuiFileDialogFlags_HideColumnType = (1 << 3), // hide column file type - ImGuiFileDialogFlags_HideColumnSize = (1 << 4), // hide column file size - ImGuiFileDialogFlags_HideColumnDate = (1 << 5), // hide column file date + ImGuiFileDialogFlags_None = 0, + ImGuiFileDialogFlags_ConfirmOverwrite = (1 << 0), // show confirm to overwrite dialog + ImGuiFileDialogFlags_DontShowHiddenFiles = (1 << 1), // dont show hidden file (file starting with a .) + ImGuiFileDialogFlags_DisableCreateDirectoryButton = (1 << 2), // disable the create directory button + ImGuiFileDialogFlags_HideColumnType = (1 << 3), // hide column file type + ImGuiFileDialogFlags_HideColumnSize = (1 << 4), // hide column file size + ImGuiFileDialogFlags_HideColumnDate = (1 << 5), // hide column file date #ifdef USE_THUMBNAILS - ImGuiFileDialogFlags_DisableThumbnailMode = (1 << 6), // disable the thumbnail mode + ImGuiFileDialogFlags_DisableThumbnailMode = (1 << 6), // disable the thumbnail mode #endif - ImGuiFileDialogFlags_Default = ImGuiFileDialogFlags_ConfirmOverwrite + ImGuiFileDialogFlags_Default = ImGuiFileDialogFlags_ConfirmOverwrite }; #ifdef USE_THUMBNAILS struct IGFD_Thumbnail_Info { - int isReadyToDisplay = 0; // ready to be rendered, so texture created - int isReadyToUpload = 0; // ready to upload to gpu - int isLoadingOrLoaded = 0; // was sent to laoding or loaded - void* textureID = 0; // 2d texture id (void* is like ImtextureID type) (GL, DX, VK, Etc..) - unsigned char* textureFileDatas = 0; // file texture datas, will be rested to null after gpu upload - int textureWidth = 0; // width of the texture to upload - int textureHeight = 0; // height of the texture to upload - int textureChannels = 0; // count channels of the texture to upload - void* userDatas = 0; // user datas + int isReadyToDisplay = 0; // ready to be rendered, so texture created + int isReadyToUpload = 0; // ready to upload to gpu + int isLoadingOrLoaded = 0; // was sent to laoding or loaded + void* textureID = 0; // 2d texture id (void* is like ImtextureID type) (GL, DX, VK, Etc..) + unsigned char* textureFileDatas = 0; // file texture datas, will be rested to null after gpu upload + int textureWidth = 0; // width of the texture to upload + int textureHeight = 0; // height of the texture to upload + int textureChannels = 0; // count channels of the texture to upload + void* userDatas = 0; // user datas }; #endif // USE_THUMBNAILS @@ -669,678 +659,680 @@ namespace IGFD #define MAX_PATH_BUFFER_SIZE 1024 #endif // MAX_PATH_BUFFER_SIZE - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - class FileDialogInternal; + class FileDialogInternal; - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - class SearchManager - { - public: - std::string puSearchTag; - char puSearchBuffer[MAX_FILE_DIALOG_NAME_BUFFER] = ""; - bool puSearchInputIsActive = false; + class SearchManager + { + public: + std::string puSearchTag; + char puSearchBuffer[MAX_FILE_DIALOG_NAME_BUFFER] = ""; + bool puSearchInputIsActive = false; - public: - void Clear(); // clear datas - void DrawSearchBar(FileDialogInternal& vFileDialogInternal); // draw the search bar - }; + public: + void Clear(); // clear datas + void DrawSearchBar(FileDialogInternal& vFileDialogInternal); // draw the search bar + }; - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - class Utils - { - public: - struct PathStruct - { - std::string path; - std::string name; - std::string ext; - bool isOk = false; - }; + class Utils + { + public: + struct PathStruct + { + std::string path; + std::string name; + std::string ext; + bool isOk = false; + }; - public: - static bool Splitter(bool split_vertically, float thickness, float* size1, float* size2, float min_size1, float min_size2, float splitter_long_axis_size = -1.0f); - static bool ReplaceString(std::string& str, const std::string& oldStr, const std::string& newStr); - static bool IsDirectoryExist(const std::string& name); - static bool CreateDirectoryIfNotExist(const std::string& name); - static PathStruct ParsePathFileName(const std::string& vPathFileName); - static void AppendToBuffer(char* vBuffer, size_t vBufferLen, const std::string& vStr); - static void ResetBuffer(char* vBuffer); - static void SetBuffer(char* vBuffer, size_t vBufferLen, const std::string& vStr); + public: + static bool Splitter(bool split_vertically, float thickness, float* size1, float* size2, float min_size1, float min_size2, float splitter_long_axis_size = -1.0f); + static bool ReplaceString(std::string& str, const std::string& oldStr, const std::string& newStr); + static bool IsDirectoryExist(const std::string& name); + static bool CreateDirectoryIfNotExist(const std::string& name); + static PathStruct ParsePathFileName(const std::string& vPathFileName); + static void AppendToBuffer(char* vBuffer, size_t vBufferLen, const std::string& vStr); + static void ResetBuffer(char* vBuffer); + static void SetBuffer(char* vBuffer, size_t vBufferLen, const std::string& vStr); #ifdef WIN32 - static bool WReplaceString(std::wstring& str, const std::wstring& oldStr, const std::wstring& newStr); - static std::vector WSplitStringToVector(const std::wstring& text, char delimiter, bool pushEmpty); - static std::string wstring_to_string(const std::wstring& wstr); - static std::wstring string_to_wstring(const std::string& mbstr); + static bool WReplaceString(std::wstring& str, const std::wstring& oldStr, const std::wstring& newStr); + static std::vector WSplitStringToVector(const std::wstring& text, char delimiter, bool pushEmpty); + static std::string wstring_to_string(const std::wstring& wstr); + static std::wstring string_to_wstring(const std::string& mbstr); #endif - static std::vector SplitStringToVector(const std::string& text, char delimiter, bool pushEmpty); - static std::vector GetDrivesList(); - }; + static std::vector SplitStringToVector(const std::string& text, char delimiter, bool pushEmpty); + static std::vector GetDrivesList(); + }; - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - class FileStyle - { - public: - ImVec4 color = ImVec4(0, 0, 0, 0); - std::string icon; - ImFont* font = nullptr; - IGFD_FileStyleFlags flags = 0; + class FileStyle + { + public: + ImVec4 color = ImVec4(0, 0, 0, 0); + std::string icon; + ImFont* font = nullptr; + IGFD_FileStyleFlags flags = 0; - public: - FileStyle(); - FileStyle(const FileStyle& vStyle); - FileStyle(const ImVec4& vColor, const std::string& vIcon = "", ImFont* vFont = nullptr); - }; + public: + FileStyle(); + FileStyle(const FileStyle& vStyle); + FileStyle(const ImVec4& vColor, const std::string& vIcon = "", ImFont* vFont = nullptr); + }; - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - class FileInfos; - class FilterManager - { - public: - class FilterInfos - { - public: - std::string filter; - std::set collectionfilters; + class FileInfos; + class FilterManager + { + public: + class FilterInfos + { + public: + std::string filter; + std::set collectionfilters; - public: - void clear(); // clear the datas - bool empty() const; // is filter empty - bool exist(const std::string& vFilter) const; // is filter exist - }; + public: + void clear(); // clear the datas + bool empty() const; // is filter empty + bool exist(const std::string& vFilter) const; // is filter exist + }; - private: - std::vector prParsedFilters; - std::unordered_map>> prFilesStyle; // file infos for file extention only - FilterInfos prSelectedFilter; + private: + std::vector prParsedFilters; + std::unordered_map>> prFilesStyle; // file infos for file extention only + FilterInfos prSelectedFilter; - public: - std::string puDLGFilters; - std::string puDLGdefaultExt; + public: + std::string puDLGFilters; + std::string puDLGdefaultExt; - public: - void ParseFilters(const char* vFilters); // Parse filter syntax, detect and parse filter collection - void SetSelectedFilterWithExt(const std::string& vFilter); // Select filter - - bool prFillFileStyle(std::shared_ptr vFileInfos) const; // fill with the good style - - void SetFileStyle( - const IGFD_FileStyleFlags& vFlags, - const char* vCriteria, - const FileStyle& vInfos); // Set FileStyle - void SetFileStyle( - const IGFD_FileStyleFlags& vFlags, - const char* vCriteria, - const ImVec4& vColor, - const std::string& vIcon, - ImFont* vFont); // link file style to Color and Icon and Font - bool GetFileStyle( - const IGFD_FileStyleFlags& vFlags, - const std::string& vCriteria, - ImVec4* vOutColor, - std::string* vOutIcon, - ImFont** vOutFont); // Get Color and Icon for Filter - void ClearFilesStyle(); // clear prFileStyle + public: + void ParseFilters(const char* vFilters); // Parse filter syntax, detect and parse filter collection + void SetSelectedFilterWithExt(const std::string& vFilter); // Select filter + + bool prFillFileStyle(std::shared_ptr vFileInfos) const; // fill with the good style + + void SetFileStyle( + const IGFD_FileStyleFlags& vFlags, + const char* vCriteria, + const FileStyle& vInfos); // Set FileStyle + void SetFileStyle( + const IGFD_FileStyleFlags& vFlags, + const char* vCriteria, + const ImVec4& vColor, + const std::string& vIcon, + ImFont* vFont); // link file style to Color and Icon and Font + bool GetFileStyle( + const IGFD_FileStyleFlags& vFlags, + const std::string& vCriteria, + ImVec4* vOutColor, + std::string* vOutIcon, + ImFont** vOutFont); // Get Color and Icon for Filter + void ClearFilesStyle(); // clear prFileStyle - bool IsCoveredByFilters(const std::string& vTag) const; // check if current file extention (vTag) is covered by current filter - bool DrawFilterComboBox(FileDialogInternal& vFileDialogInternal); // draw the filter combobox - FilterInfos GetSelectedFilter(); // get the current selected filter - std::string ReplaceExtentionWithCurrentFilter(const std::string& vFile) const; // replace the extention of the current file by the selected filter - void SetDefaultFilterIfNotDefined(); // define the first filter if no filter is selected - }; + bool IsCoveredByFilters(const std::string& vTag) const; // check if current file extention (vTag) is covered by current filter + bool DrawFilterComboBox(FileDialogInternal& vFileDialogInternal); // draw the filter combobox + FilterInfos GetSelectedFilter(); // get the current selected filter + std::string ReplaceExtentionWithCurrentFilter(const std::string& vFile) const; // replace the extention of the current file by the selected filter + void SetDefaultFilterIfNotDefined(); // define the first filter if no filter is selected + }; - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - class FileInfos - { - public: - char fileType = ' '; // dirent fileType (f:file, d:directory, l:link) - std::string filePath; // path of the file - std::string fileNameExt; // filename of the file (file name + extention) (but no path) - std::string fileNameExt_optimized; // optimized for search => insensitivecase - std::string fileExt; // extention of the file - size_t fileSize = 0; // for sorting operations - std::string formatedFileSize; // file size formated (10 o, 10 ko, 10 mo, 10 go) - std::string fileModifDate; // file user defined format of the date (data + time by default) - std::shared_ptr fileStyle = nullptr; // style of the file + class FileInfos + { + public: + char fileType = ' '; // dirent fileType (f:file, d:directory, l:link) + std::string filePath; // path of the file + std::string fileNameExt; // filename of the file (file name + extention) (but no path) + std::string fileNameExt_optimized; // optimized for search => insensitivecase + std::string fileExt; // extention of the file + size_t fileSize = 0; // for sorting operations + std::string formatedFileSize; // file size formated (10 o, 10 ko, 10 mo, 10 go) + std::string fileModifDate; // file user defined format of the date (data + time by default) + std::shared_ptr fileStyle = nullptr; // style of the file #ifdef USE_THUMBNAILS - IGFD_Thumbnail_Info thumbnailInfo; // structre for the display for image file tetxure + IGFD_Thumbnail_Info thumbnailInfo; // structre for the display for image file tetxure #endif // USE_THUMBNAILS - public: - bool IsTagFound(const std::string& vTag) const; - }; + public: + bool IsTagFound(const std::string& vTag) const; + }; - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - class FileManager - { - public: // types - enum class SortingFieldEnum // sorting for filetering of the file lsit - { - FIELD_NONE = 0, // no sorting preference, result indetermined haha.. - FIELD_FILENAME, // sorted by filename - FIELD_TYPE, // sorted by filetype - FIELD_SIZE, // sorted by filesize (formated file size) - FIELD_DATE, // sorted by filedate + class FileManager + { + public: // types + enum class SortingFieldEnum // sorting for filetering of the file lsit + { + FIELD_NONE = 0, // no sorting preference, result indetermined haha.. + FIELD_FILENAME, // sorted by filename + FIELD_TYPE, // sorted by filetype + FIELD_SIZE, // sorted by filesize (formated file size) + FIELD_DATE, // sorted by filedate #ifdef USE_THUMBNAILS - FIELD_THUMBNAILS, // sorted by thumbnails (comparaison by width then by height) + FIELD_THUMBNAILS, // sorted by thumbnails (comparaison by width then by height) #endif // USE_THUMBNAILS - }; + }; - private: - std::string prCurrentPath; // current path (to be decomposed in prCurrentPathDecomposition - std::vector prCurrentPathDecomposition; // part words - std::vector> prFileList; // base container - std::vector> prFilteredFileList; // filtered container (search, sorting, etc..) - std::string prLastSelectedFileName; // for shift multi selection - std::set prSelectedFileNames; // the user selection of FilePathNames - bool prCreateDirectoryMode = false; // for create directory widget + private: + std::string prCurrentPath; // current path (to be decomposed in prCurrentPathDecomposition + std::vector prCurrentPathDecomposition; // part words + std::vector> prFileList; // base container + std::vector> prFilteredFileList; // filtered container (search, sorting, etc..) + std::string prLastSelectedFileName; // for shift multi selection + std::set prSelectedFileNames; // the user selection of FilePathNames + bool prCreateDirectoryMode = false; // for create directory widget - public: - char puVariadicBuffer[MAX_FILE_DIALOG_NAME_BUFFER] = ""; // called by prSelectableItem - bool puInputPathActivated = false; // show input for path edition - bool puDrivesClicked = false; // event when a drive button is clicked - bool puPathClicked = false; // event when a path button was clicked - char puInputPathBuffer[MAX_PATH_BUFFER_SIZE] = ""; // input path buffer for imgui widget input text (displayed in palce of composer) - char puFileNameBuffer[MAX_FILE_DIALOG_NAME_BUFFER] = ""; // file name buffer in footer for imgui widget input text - char puDirectoryNameBuffer[MAX_FILE_DIALOG_NAME_BUFFER] = ""; // directory name buffer in footer for imgui widget input text (when is directory mode) - std::string puHeaderFileName; // detail view name of column file - std::string puHeaderFileType; // detail view name of column type - std::string puHeaderFileSize; // detail view name of column size - std::string puHeaderFileDate; // detail view name of column date + time + public: + char puVariadicBuffer[MAX_FILE_DIALOG_NAME_BUFFER] = ""; // called by prSelectableItem + bool puInputPathActivated = false; // show input for path edition + bool puDrivesClicked = false; // event when a drive button is clicked + bool puPathClicked = false; // event when a path button was clicked + char puInputPathBuffer[MAX_PATH_BUFFER_SIZE] = ""; // input path buffer for imgui widget input text (displayed in palce of composer) + char puFileNameBuffer[MAX_FILE_DIALOG_NAME_BUFFER] = ""; // file name buffer in footer for imgui widget input text + char puDirectoryNameBuffer[MAX_FILE_DIALOG_NAME_BUFFER] = ""; // directory name buffer in footer for imgui widget input text (when is directory mode) + std::string puHeaderFileName; // detail view name of column file + std::string puHeaderFileType; // detail view name of column type + std::string puHeaderFileSize; // detail view name of column size + std::string puHeaderFileDate; // detail view name of column date + time #ifdef USE_THUMBNAILS - std::string puHeaderFileThumbnails; // detail view name of column thumbnails - bool puSortingDirection[5] = { true, true, true, true, true }; // detail view // true => Descending, false => Ascending + std::string puHeaderFileThumbnails; // detail view name of column thumbnails + bool puSortingDirection[5]; // detail view // true => Descending, false => Ascending #else - bool puSortingDirection[4]; // detail view // true => Descending, false => Ascending + bool puSortingDirection[4]; // detail view // true => Descending, false => Ascending #endif - SortingFieldEnum puSortingField = SortingFieldEnum::FIELD_FILENAME; // detail view sorting column - bool puShowDrives = false; // drives are shown (only on os windows) + SortingFieldEnum puSortingField = SortingFieldEnum::FIELD_FILENAME; // detail view sorting column + bool puShowDrives = false; // drives are shown (only on os windows) bool fileListActuallyEmpty = false; - std::string puDLGpath; // base path set by user when OpenDialog/OpenModal was called - std::string puDLGDefaultFileName; // base default file path name set by user when OpenDialog/OpenModal was called - size_t puDLGcountSelectionMax = 1U; // 0 for infinite // base max selection count set by user when OpenDialog/OpenModal was called - bool puDLGDirectoryMode = false; // is directory mode (defiend like : puDLGDirectoryMode = (filters.empty())) + std::string puDLGpath; // base path set by user when OpenDialog/OpenModal was called + std::string puError; // last error + std::string puDLGDefaultFileName; // base default file path name set by user when OpenDialog/OpenModal was called + size_t puDLGcountSelectionMax = 1U; // 0 for infinite // base max selection count set by user when OpenDialog/OpenModal was called + bool puDLGDirectoryMode = false; // is directory mode (defiend like : puDLGDirectoryMode = (filters.empty())) - std::string puFsRoot; + std::string puFsRoot; - private: - static std::string prRoundNumber(double vvalue, int n); // custom rounding number - static std::string prFormatFileSize(size_t vByteSize); // format file size field - static std::string prOptimizeFilenameForSearchOperations(const std::string& vFileNameExt); // turn all text in lower case for search facilitie - static void prCompleteFileInfos(const std::shared_ptr& FileInfos); // set time and date infos of a file (detail view mode) - void prRemoveFileNameInSelection(const std::string& vFileName); // selection : remove a file name - void prAddFileNameInSelection(const std::string& vFileName, bool vSetLastSelectionFileName); // selection : add a file name - void AddFile(const FileDialogInternal& vFileDialogInternal, - const std::string& vPath, const std::string& vFileName, const char& vFileType); // add file called by scandir + private: + static std::string prRoundNumber(double vvalue, int n); // custom rounding number + static std::string prFormatFileSize(size_t vByteSize); // format file size field + static std::string prOptimizeFilenameForSearchOperations(const std::string& vFileNameExt); // turn all text in lower case for search facilitie + static void prCompleteFileInfos(const std::shared_ptr& FileInfos); // set time and date infos of a file (detail view mode) + void prRemoveFileNameInSelection(const std::string& vFileName); // selection : remove a file name + void prAddFileNameInSelection(const std::string& vFileName, bool vSetLastSelectionFileName); // selection : add a file name + void AddFile(const FileDialogInternal& vFileDialogInternal, + const std::string& vPath, const std::string& vFileName, const char& vFileType, void* ent); // add file called by scandir - public: - FileManager(); - bool IsComposerEmpty(); - size_t GetComposerSize(); - bool IsFileListEmpty(); - bool IsFilteredListEmpty(); - size_t GetFullFileListSize(); - std::shared_ptr GetFullFileAt(size_t vIdx); - size_t GetFilteredListSize(); - std::shared_ptr GetFilteredFileAt(size_t vIdx); - bool IsFileNameSelected(const std::string& vFileName); - std::string GetBack(); - void ClearComposer(); - void ClearFileLists(); // clear file list, will destroy thumbnail textures - void ClearAll(); - void ApplyFilteringOnFileList(const FileDialogInternal& vFileDialogInternal); - void OpenCurrentPath(const FileDialogInternal& vFileDialogInternal); // set the path of the dialog, will launch the directory scan for populate the file listview - void SortFields(const FileDialogInternal& vFileDialogInternal, - const SortingFieldEnum& vSortingField, const bool vCanChangeOrder); // will sort a column - bool GetDrives(); // list drives on windows platform - bool CreateDir(const std::string& vPath); // create a directory on the file system - void ComposeNewPath(std::vector::iterator vIter); // compose a path from the compose path widget - bool SetPathOnParentDirectoryIfAny(); // compose paht on parent directory - std::string GetCurrentPath(); // get the current path - void SetCurrentPath(const std::string& vCurrentPath); // set the current path - static bool IsFileExist(const std::string& vFile); - void SetDefaultFileName(const std::string& vFileName); - bool SelectDirectory(const std::shared_ptr& vInfos); // enter directory - void SelectFileName(const FileDialogInternal& vFileDialogInternal, - const std::shared_ptr& vInfos); // select filename - - //depend of dirent.h - void SetCurrentDir(const std::string& vPath); // define current directory for scan - void ScanDir(const FileDialogInternal& vFileDialogInternal, const std::string& vPath); // scan the directory for retrieve the file list + public: + FileManager(); + bool IsComposerEmpty(); + size_t GetComposerSize(); + bool IsFileListEmpty(); + bool IsFilteredListEmpty(); + size_t GetFullFileListSize(); + std::shared_ptr GetFullFileAt(size_t vIdx); + size_t GetFilteredListSize(); + std::shared_ptr GetFilteredFileAt(size_t vIdx); + bool IsFileNameSelected(const std::string& vFileName); + std::string GetBack(); + void ClearComposer(); + void ClearFileLists(); // clear file list, will destroy thumbnail textures + void ClearAll(); + void ApplyFilteringOnFileList(const FileDialogInternal& vFileDialogInternal); + void OpenCurrentPath(const FileDialogInternal& vFileDialogInternal); // set the path of the dialog, will launch the directory scan for populate the file listview + void SortFields(const FileDialogInternal& vFileDialogInternal, + const SortingFieldEnum& vSortingField, const bool vCanChangeOrder); // will sort a column + bool GetDrives(); // list drives on windows platform + bool CreateDir(const std::string& vPath); // create a directory on the file system + void ComposeNewPath(std::vector::iterator vIter); // compose a path from the compose path widget + bool SetPathOnParentDirectoryIfAny(); // compose paht on parent directory + std::string GetCurrentPath(); // get the current path + void SetCurrentPath(const std::string& vCurrentPath); // set the current path + static bool IsFileExist(const std::string& vFile); + void SetDefaultFileName(const std::string& vFileName); + bool SelectDirectory(const std::shared_ptr& vInfos); // enter directory + void SelectFileName(const FileDialogInternal& vFileDialogInternal, + const std::shared_ptr& vInfos); // select filename + + //depend of dirent.h + void SetCurrentDir(const std::string& vPath); // define current directory for scan + void ScanDir(const FileDialogInternal& vFileDialogInternal, const std::string& vPath); // scan the directory for retrieve the file list - public: - std::string GetResultingPath(); - std::string GetResultingFileName(FileDialogInternal& vFileDialogInternal); - std::string GetResultingFilePathName(FileDialogInternal& vFileDialogInternal); - std::map GetResultingSelection(); + public: + std::string GetResultingPath(); + std::string GetResultingFileName(FileDialogInternal& vFileDialogInternal); + std::string GetResultingFilePathName(FileDialogInternal& vFileDialogInternal); + std::map GetResultingSelection(); - public: - void DrawDirectoryCreation(const FileDialogInternal& vFileDialogInternal); // draw directory creation widget - void DrawPathComposer(const FileDialogInternal& vFileDialogInternal); // draw path composer widget - }; + public: + void DrawDirectoryCreation(const FileDialogInternal& vFileDialogInternal); // draw directory creation widget + void DrawPathComposer(const FileDialogInternal& vFileDialogInternal); // draw path composer widget + }; - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #ifdef USE_THUMBNAILS - typedef std::function CreateThumbnailFun; // texture 2d creation function binding - typedef std::function DestroyThumbnailFun; // texture 2d destroy function binding + typedef std::function CreateThumbnailFun; // texture 2d creation function binding + typedef std::function DestroyThumbnailFun; // texture 2d destroy function binding #endif - class ThumbnailFeature - { - protected: - ThumbnailFeature(); - ~ThumbnailFeature(); + class ThumbnailFeature + { + protected: + ThumbnailFeature(); + ~ThumbnailFeature(); - void NewThumbnailFrame(FileDialogInternal& vFileDialogInternal); - void EndThumbnailFrame(FileDialogInternal& vFileDialogInternal); - void QuitThumbnailFrame(FileDialogInternal& vFileDialogInternal); + void NewThumbnailFrame(FileDialogInternal& vFileDialogInternal); + void EndThumbnailFrame(FileDialogInternal& vFileDialogInternal); + void QuitThumbnailFrame(FileDialogInternal& vFileDialogInternal); #ifdef USE_THUMBNAILS - protected: - enum class DisplayModeEnum - { - FILE_LIST = 0, - THUMBNAILS_LIST, - THUMBNAILS_GRID - }; + protected: + enum class DisplayModeEnum + { + FILE_LIST = 0, + THUMBNAILS_LIST, + THUMBNAILS_GRID + }; - private: - uint32_t prCountFiles = 0U; - bool prIsWorking = false; - std::shared_ptr prThumbnailGenerationThread = nullptr; - std::list> prThumbnailFileDatasToGet; // base container - std::mutex prThumbnailFileDatasToGetMutex; - std::list> prThumbnailToCreate; // base container - std::mutex prThumbnailToCreateMutex; - std::list prThumbnailToDestroy; // base container - std::mutex prThumbnailToDestroyMutex; + private: + uint32_t prCountFiles = 0U; + bool prIsWorking = false; + std::shared_ptr prThumbnailGenerationThread = nullptr; + std::list> prThumbnailFileDatasToGet; // base container + std::mutex prThumbnailFileDatasToGetMutex; + std::list> prThumbnailToCreate; // base container + std::mutex prThumbnailToCreateMutex; + std::list prThumbnailToDestroy; // base container + std::mutex prThumbnailToDestroyMutex; - CreateThumbnailFun prCreateThumbnailFun = nullptr; - DestroyThumbnailFun prDestroyThumbnailFun = nullptr; + CreateThumbnailFun prCreateThumbnailFun = nullptr; + DestroyThumbnailFun prDestroyThumbnailFun = nullptr; - protected: - DisplayModeEnum prDisplayMode = DisplayModeEnum::FILE_LIST; + protected: + DisplayModeEnum prDisplayMode = DisplayModeEnum::FILE_LIST; - protected: - // will be call in cpu zone (imgui computations, will call a texture file retrieval thread) - void prStartThumbnailFileDatasExtraction(); // start the thread who will get byte buffer from image files - bool prStopThumbnailFileDatasExtraction(); // stop the thread who will get byte buffer from image files - void prThreadThumbnailFileDatasExtractionFunc(); // the thread who will get byte buffer from image files - void prDrawThumbnailGenerationProgress(); // a little progressbar who will display the texture gen status - void prAddThumbnailToLoad(const std::shared_ptr& vFileInfos); // add texture to load in the thread - void prAddThumbnailToCreate(const std::shared_ptr& vFileInfos); - void prAddThumbnailToDestroy(const IGFD_Thumbnail_Info& vIGFD_Thumbnail_Info); - void prDrawDisplayModeToolBar(); // draw display mode toolbar (file list, thumbnails list, small thumbnails grid, big thumbnails grid) - void prClearThumbnails(FileDialogInternal& vFileDialogInternal); + protected: + // will be call in cpu zone (imgui computations, will call a texture file retrieval thread) + void prStartThumbnailFileDatasExtraction(); // start the thread who will get byte buffer from image files + bool prStopThumbnailFileDatasExtraction(); // stop the thread who will get byte buffer from image files + void prThreadThumbnailFileDatasExtractionFunc(); // the thread who will get byte buffer from image files + void prDrawThumbnailGenerationProgress(); // a little progressbar who will display the texture gen status + void prAddThumbnailToLoad(const std::shared_ptr& vFileInfos); // add texture to load in the thread + void prAddThumbnailToCreate(const std::shared_ptr& vFileInfos); + void prAddThumbnailToDestroy(const IGFD_Thumbnail_Info& vIGFD_Thumbnail_Info); + void prDrawDisplayModeToolBar(); // draw display mode toolbar (file list, thumbnails list, small thumbnails grid, big thumbnails grid) + void prClearThumbnails(FileDialogInternal& vFileDialogInternal); - public: - void SetCreateThumbnailCallback(const CreateThumbnailFun& vCreateThumbnailFun); - void SetDestroyThumbnailCallback(const DestroyThumbnailFun& vCreateThumbnailFun); - - // must be call in gpu zone (rendering, possibly one rendering thread) - void ManageGPUThumbnails(); // in gpu rendering zone, whill create or destroy texture + public: + void SetCreateThumbnailCallback(const CreateThumbnailFun& vCreateThumbnailFun); + void SetDestroyThumbnailCallback(const DestroyThumbnailFun& vCreateThumbnailFun); + + // must be call in gpu zone (rendering, possibly one rendering thread) + void ManageGPUThumbnails(); // in gpu rendering zone, whill create or destroy texture #endif - }; + }; - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - class BookMarkFeature - { - protected: - BookMarkFeature(); + class BookMarkFeature + { + protected: + BookMarkFeature(); #ifdef USE_BOOKMARK - private: - struct BookmarkStruct - { - std::string name; // name of the bookmark - - // todo: the path could be relative, better if the app is movedn but bookmarked path can be outside of the app - std::string path; // absolute path of the bookmarked directory - }; + private: + struct BookmarkStruct + { + std::string name; // name of the bookmark + + // todo: the path could be relative, better if the app is movedn but bookmarked path can be outside of the app + std::string path; // absolute path of the bookmarked directory + }; - private: - ImGuiListClipper prBookmarkClipper; - std::vector prBookmarks; - char prBookmarkEditBuffer[MAX_FILE_DIALOG_NAME_BUFFER] = ""; + private: + ImGuiListClipper prBookmarkClipper; + std::vector prBookmarks; + char prBookmarkEditBuffer[MAX_FILE_DIALOG_NAME_BUFFER] = ""; - protected: - float prBookmarkWidth = 200.0f; - bool prBookmarkPaneShown = false; - - protected: - void prDrawBookmarkButton(); // draw bookmark button - bool prDrawBookmarkPane(FileDialogInternal& vFileDialogInternal, const ImVec2& vSize); // draw bookmark Pane + protected: + float prBookmarkWidth = 200.0f; + bool prBookmarkPaneShown = false; + + protected: + void prDrawBookmarkButton(); // draw bookmark button + bool prDrawBookmarkPane(FileDialogInternal& vFileDialogInternal, const ImVec2& vSize); // draw bookmark Pane - public: - std::string SerializeBookmarks(); // serialize bookmarks : return bookmark buffer to save in a file - void DeserializeBookmarks( // deserialize bookmarks : load bookmark buffer to load in the dialog (saved from previous use with SerializeBookmarks()) - const std::string& vBookmarks); // bookmark buffer to load + public: + std::string SerializeBookmarks(); // serialize bookmarks : return bookmark buffer to save in a file + void DeserializeBookmarks( // deserialize bookmarks : load bookmark buffer to load in the dialog (saved from previous use with SerializeBookmarks()) + const std::string& vBookmarks); // bookmark buffer to load #endif // USE_BOOKMARK - }; + }; - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // file localization by input chat // widget flashing - class KeyExplorerFeature - { - protected: - KeyExplorerFeature(); + // file localization by input chat // widget flashing + class KeyExplorerFeature + { + protected: + KeyExplorerFeature(); #ifdef USE_EXPLORATION_BY_KEYS - private: - size_t prFlashedItem = 0; // flash when select by char - float prFlashAlpha = 0.0f; // flash when select by char - float prFlashAlphaAttenInSecs = 1.0f; // fps display dependant - size_t prLocateFileByInputChar_lastFileIdx = 0; - ImWchar prLocateFileByInputChar_lastChar = 0; - int prLocateFileByInputChar_InputQueueCharactersSize = 0; - bool prLocateFileByInputChar_lastFound = false; + private: + size_t prFlashedItem = 0; // flash when select by char + float prFlashAlpha = 0.0f; // flash when select by char + float prFlashAlphaAttenInSecs = 1.0f; // fps display dependant + size_t prLocateFileByInputChar_lastFileIdx = 0; + ImWchar prLocateFileByInputChar_lastChar = 0; + int prLocateFileByInputChar_InputQueueCharactersSize = 0; + bool prLocateFileByInputChar_lastFound = false; - protected: - void prLocateByInputKey(FileDialogInternal& vFileDialogInternal); // select a file line in listview according to char key - bool prLocateItem_Loop(FileDialogInternal& vFileDialogInternal, ImWchar vC); // restrat for start of list view if not found a corresponding file - void prExploreWithkeys(FileDialogInternal& vFileDialogInternal, ImGuiID vListViewID); // select file/directory line in listview accroding to up/down enter/backspace keys - static bool prFlashableSelectable( // custom flashing selectable widgets, for flash the selected line in a short time - const char* label, bool selected = false, ImGuiSelectableFlags flags = 0, - bool vFlashing = false, const ImVec2& size = ImVec2(0, 0)); - void prStartFlashItem(size_t vIdx); // define than an item must be flashed - bool prBeginFlashItem(size_t vIdx); // start the flashing of a line in lsit view - static void prEndFlashItem(); // end the fleshing accrdoin to var prFlashAlphaAttenInSecs + protected: + void prLocateByInputKey(FileDialogInternal& vFileDialogInternal); // select a file line in listview according to char key + bool prLocateItem_Loop(FileDialogInternal& vFileDialogInternal, ImWchar vC); // restrat for start of list view if not found a corresponding file + void prExploreWithkeys(FileDialogInternal& vFileDialogInternal, ImGuiID vListViewID); // select file/directory line in listview accroding to up/down enter/backspace keys + static bool prFlashableSelectable( // custom flashing selectable widgets, for flash the selected line in a short time + const char* label, bool selected = false, ImGuiSelectableFlags flags = 0, + bool vFlashing = false, const ImVec2& size = ImVec2(0, 0)); + void prStartFlashItem(size_t vIdx); // define than an item must be flashed + bool prBeginFlashItem(size_t vIdx); // start the flashing of a line in lsit view + static void prEndFlashItem(); // end the fleshing accrdoin to var prFlashAlphaAttenInSecs - public: - void SetFlashingAttenuationInSeconds( // set the flashing time of the line in file list when use exploration keys - float vAttenValue); // set the attenuation (from flashed to not flashed) in seconds + public: + void SetFlashingAttenuationInSeconds( // set the flashing time of the line in file list when use exploration keys + float vAttenValue); // set the attenuation (from flashed to not flashed) in seconds #endif // USE_EXPLORATION_BY_KEYS - }; + }; - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - typedef void* UserDatas; - typedef std::function PaneFun; // side pane function binding + typedef void* UserDatas; + typedef std::function PaneFun; // side pane function binding typedef std::function SelectFun; // click on file function binding - class FileDialogInternal - { - public: - FileManager puFileManager; - FilterManager puFilterManager; - SearchManager puSearchManager; + class FileDialogInternal + { + public: + FileManager puFileManager; + FilterManager puFilterManager; + SearchManager puSearchManager; - public: - std::string puName; - bool puShowDialog = false; - ImVec2 puDialogCenterPos = ImVec2(0, 0); // center pos for display the confirm overwrite dialog - int puLastImGuiFrameCount = 0; // to be sure than only one dialog displayed per frame - float puFooterHeight = 0.0f; - bool puCanWeContinue = true; // events - bool puOkResultToConfirm = false; // to confim if ok for OverWrite - bool puIsOk = false; - bool puFileInputIsActive = false; // when input text for file or directory is active - bool puFileListViewIsActive = false; // when list view is active - std::string puDLGkey; - std::string puDLGtitle; - ImGuiFileDialogFlags puDLGflags = ImGuiFileDialogFlags_None; - UserDatas puDLGuserDatas = nullptr; - PaneFun puDLGoptionsPane = nullptr; + public: + std::string puName; + bool puShowDialog = false; + ImVec2 puDialogCenterPos = ImVec2(0, 0); // center pos for display the confirm overwrite dialog + int puLastImGuiFrameCount = 0; // to be sure than only one dialog displayed per frame + float puFooterHeight = 0.0f; + bool puCanWeContinue = true; // events + bool puOkResultToConfirm = false; // to confim if ok for OverWrite + bool puIsOk = false; + bool puFileInputIsActive = false; // when input text for file or directory is active + bool puFileListViewIsActive = false; // when list view is active + std::string puDLGkey; + std::string puDLGtitle; + ImGuiFileDialogFlags puDLGflags = ImGuiFileDialogFlags_None; + UserDatas puDLGuserDatas = nullptr; + PaneFun puDLGoptionsPane = nullptr; SelectFun puDLGselFun = nullptr; - float puDLGoptionsPaneWidth = 0.0f; - bool puDLGmodal = false; - bool puNeedToExitDialog = false; + float puDLGoptionsPaneWidth = 0.0f; + bool puDLGmodal = false; + bool puNeedToExitDialog = false; - bool puUseCustomLocale = false; - int puLocaleCategory = LC_ALL; // locale category to use - std::string puLocaleBegin; // the locale who will be applied at start of the display dialog - std::string puLocaleEnd; // the locale who will be applaied at end of the display dialog + bool puUseCustomLocale = false; + int puLocaleCategory = LC_ALL; // locale category to use + std::string puLocaleBegin; // the locale who will be applied at start of the display dialog + std::string puLocaleEnd; // the locale who will be applaied at end of the display dialog - public: - void NewFrame(); // new frame, so maybe neded to do somethings, like reset events - void EndFrame(); // end frame, so maybe neded to do somethings fater all - void ResetForNewDialog(); // reset what is needed to reset for the openging of a new dialog - }; + public: + void NewFrame(); // new frame, so maybe neded to do somethings, like reset events + void EndFrame(); // end frame, so maybe neded to do somethings fater all + void ResetForNewDialog(); // reset what is needed to reset for the openging of a new dialog + }; - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - class FileDialog : - public BookMarkFeature, - public KeyExplorerFeature, - public ThumbnailFeature - { - private: - FileDialogInternal prFileDialogInternal; - ImGuiListClipper prFileListClipper; + class FileDialog : + public BookMarkFeature, + public KeyExplorerFeature, + public ThumbnailFeature + { + private: + FileDialogInternal prFileDialogInternal; + ImGuiListClipper prFileListClipper; - public: - bool puAnyWindowsHovered = false; // not remember why haha :) todo : to check if we can remove + public: + bool puAnyWindowsHovered = false; // not remember why haha :) todo : to check if we can remove double DpiScale; bool singleClickSel; bool mobileMode; + std::string homePath; - public: - static FileDialog* Instance() // Singleton for easier accces form anywhere but only one dialog at a time - { - static FileDialog _instance; - return &_instance; - } + public: + static FileDialog* Instance() // Singleton for easier accces form anywhere but only one dialog at a time + { + static FileDialog _instance; + return &_instance; + } - public: - FileDialog(); // ImGuiFileDialog Constructor. can be used for have many dialog at same tiem (not possible with singleton) - virtual ~FileDialog(); // ImGuiFileDialog Destructor + public: + FileDialog(); // ImGuiFileDialog Constructor. can be used for have many dialog at same tiem (not possible with singleton) + virtual ~FileDialog(); // ImGuiFileDialog Destructor - // standard dialog - void OpenDialog( // open simple dialog (path and fileName can be specified) - const std::string& vKey, // key dialog - const std::string& vTitle, // title - const char* vFilters, // filters - const std::string& vPath, // path - const std::string& vFileName, // defaut file name - const int& vCountSelectionMax = 1, // count selection max - UserDatas vUserDatas = nullptr, // user datas (can be retrieved in pane) - ImGuiFileDialogFlags vFlags = 0, // ImGuiFileDialogFlags - SelectFun vSelectFun = nullptr); // function to be called on file click + // standard dialog + void OpenDialog( // open simple dialog (path and fileName can be specified) + const std::string& vKey, // key dialog + const std::string& vTitle, // title + const char* vFilters, // filters + const std::string& vPath, // path + const std::string& vFileName, // defaut file name + const int& vCountSelectionMax = 1, // count selection max + UserDatas vUserDatas = nullptr, // user datas (can be retrieved in pane) + ImGuiFileDialogFlags vFlags = 0, // ImGuiFileDialogFlags + SelectFun vSelectFun = nullptr); // function to be called on file click - void OpenDialog( // open simple dialog (path and filename are obtained from filePathName) - const std::string& vKey, // key dialog - const std::string& vTitle, // title - const char* vFilters, // filters - const std::string& vFilePathName, // file path name (will be decompsoed in path and fileName) - const int& vCountSelectionMax = 1, // count selection max - UserDatas vUserDatas = nullptr, // user datas (can be retrieved in pane) - ImGuiFileDialogFlags vFlags = 0, // ImGuiFileDialogFlags - SelectFun vSelectFun = nullptr); // function to be called on file click + void OpenDialog( // open simple dialog (path and filename are obtained from filePathName) + const std::string& vKey, // key dialog + const std::string& vTitle, // title + const char* vFilters, // filters + const std::string& vFilePathName, // file path name (will be decompsoed in path and fileName) + const int& vCountSelectionMax = 1, // count selection max + UserDatas vUserDatas = nullptr, // user datas (can be retrieved in pane) + ImGuiFileDialogFlags vFlags = 0, // ImGuiFileDialogFlags + SelectFun vSelectFun = nullptr); // function to be called on file click - // with pane - void OpenDialog( // open dialog with custom right pane (path and fileName can be specified) - const std::string& vKey, // key dialog - const std::string& vTitle, // title - const char* vFilters, // filters - const std::string& vPath, // path - const std::string& vFileName, // defaut file name - const PaneFun& vSidePane, // side pane - const float& vSidePaneWidth = 250.0f, // side pane width - const int& vCountSelectionMax = 1, // count selection max - UserDatas vUserDatas = nullptr, // user datas (can be retrieved in pane) - ImGuiFileDialogFlags vFlags = 0, // ImGuiFileDialogFlags - SelectFun vSelectFun = nullptr); // function to be called on file click + // with pane + void OpenDialog( // open dialog with custom right pane (path and fileName can be specified) + const std::string& vKey, // key dialog + const std::string& vTitle, // title + const char* vFilters, // filters + const std::string& vPath, // path + const std::string& vFileName, // defaut file name + const PaneFun& vSidePane, // side pane + const float& vSidePaneWidth = 250.0f, // side pane width + const int& vCountSelectionMax = 1, // count selection max + UserDatas vUserDatas = nullptr, // user datas (can be retrieved in pane) + ImGuiFileDialogFlags vFlags = 0, // ImGuiFileDialogFlags + SelectFun vSelectFun = nullptr); // function to be called on file click - void OpenDialog( // open dialog with custom right pane (path and filename are obtained from filePathName) - const std::string& vKey, // key dialog - const std::string& vTitle, // title - const char* vFilters, // filters - const std::string& vFilePathName, // file path name (will be decompsoed in path and fileName) - const PaneFun& vSidePane, // side pane - const float& vSidePaneWidth = 250.0f, // side pane width - const int& vCountSelectionMax = 1, // count selection max - UserDatas vUserDatas = nullptr, // user datas (can be retrieved in pane) - ImGuiFileDialogFlags vFlags = 0, // ImGuiFileDialogFlags - SelectFun vSelectFun = nullptr); // function to be called on file click + void OpenDialog( // open dialog with custom right pane (path and filename are obtained from filePathName) + const std::string& vKey, // key dialog + const std::string& vTitle, // title + const char* vFilters, // filters + const std::string& vFilePathName, // file path name (will be decompsoed in path and fileName) + const PaneFun& vSidePane, // side pane + const float& vSidePaneWidth = 250.0f, // side pane width + const int& vCountSelectionMax = 1, // count selection max + UserDatas vUserDatas = nullptr, // user datas (can be retrieved in pane) + ImGuiFileDialogFlags vFlags = 0, // ImGuiFileDialogFlags + SelectFun vSelectFun = nullptr); // function to be called on file click - // modal dialog - void OpenModal( // open simple modal (path and fileName can be specified) - const std::string& vKey, // key dialog - const std::string& vTitle, // title - const char* vFilters, // filters - const std::string& vPath, // path - const std::string& vFileName, // defaut file name - const int& vCountSelectionMax = 1, // count selection max - UserDatas vUserDatas = nullptr, // user datas (can be retrieved in pane) - ImGuiFileDialogFlags vFlags = 0, // ImGuiFileDialogFlags - SelectFun vSelectFun = nullptr); // function to be called on file click + // modal dialog + void OpenModal( // open simple modal (path and fileName can be specified) + const std::string& vKey, // key dialog + const std::string& vTitle, // title + const char* vFilters, // filters + const std::string& vPath, // path + const std::string& vFileName, // defaut file name + const int& vCountSelectionMax = 1, // count selection max + UserDatas vUserDatas = nullptr, // user datas (can be retrieved in pane) + ImGuiFileDialogFlags vFlags = 0, // ImGuiFileDialogFlags + SelectFun vSelectFun = nullptr); // function to be called on file click - void OpenModal( // open simple modal (path and fielname are obtained from filePathName) - const std::string& vKey, // key dialog - const std::string& vTitle, // title - const char* vFilters, // filters - const std::string& vFilePathName, // file path name (will be decompsoed in path and fileName) - const int& vCountSelectionMax = 1, // count selection max - UserDatas vUserDatas = nullptr, // user datas (can be retrieved in pane) - ImGuiFileDialogFlags vFlags = 0, // ImGuiFileDialogFlags - SelectFun vSelectFun = nullptr); // function to be called on file click + void OpenModal( // open simple modal (path and fielname are obtained from filePathName) + const std::string& vKey, // key dialog + const std::string& vTitle, // title + const char* vFilters, // filters + const std::string& vFilePathName, // file path name (will be decompsoed in path and fileName) + const int& vCountSelectionMax = 1, // count selection max + UserDatas vUserDatas = nullptr, // user datas (can be retrieved in pane) + ImGuiFileDialogFlags vFlags = 0, // ImGuiFileDialogFlags + SelectFun vSelectFun = nullptr); // function to be called on file click - // with pane - void OpenModal( // open modal with custom right pane (path and filename are obtained from filePathName) - const std::string& vKey, // key dialog - const std::string& vTitle, // title - const char* vFilters, // filters - const std::string& vPath, // path - const std::string& vFileName, // defaut file name - const PaneFun& vSidePane, // side pane - const float& vSidePaneWidth = 250.0f, // side pane width - const int& vCountSelectionMax = 1, // count selection max - UserDatas vUserDatas = nullptr, // user datas (can be retrieved in pane) - ImGuiFileDialogFlags vFlags = 0, // ImGuiFileDialogFlags - SelectFun vSelectFun = nullptr); // function to be called on file click + // with pane + void OpenModal( // open modal with custom right pane (path and filename are obtained from filePathName) + const std::string& vKey, // key dialog + const std::string& vTitle, // title + const char* vFilters, // filters + const std::string& vPath, // path + const std::string& vFileName, // defaut file name + const PaneFun& vSidePane, // side pane + const float& vSidePaneWidth = 250.0f, // side pane width + const int& vCountSelectionMax = 1, // count selection max + UserDatas vUserDatas = nullptr, // user datas (can be retrieved in pane) + ImGuiFileDialogFlags vFlags = 0, // ImGuiFileDialogFlags + SelectFun vSelectFun = nullptr); // function to be called on file click - void OpenModal( // open modal with custom right pane (path and fielname are obtained from filePathName) - const std::string& vKey, // key dialog - const std::string& vTitle, // title - const char* vFilters, // filters - const std::string& vFilePathName, // file path name (will be decompsoed in path and fileName) - const PaneFun& vSidePane, // side pane - const float& vSidePaneWidth = 250.0f, // side pane width - const int& vCountSelectionMax = 1, // count selection max - UserDatas vUserDatas = nullptr, // user datas (can be retrieved in pane) - ImGuiFileDialogFlags vFlags = 0, // ImGuiFileDialogFlags - SelectFun vSelectFun = nullptr); // function to be called on file click + void OpenModal( // open modal with custom right pane (path and fielname are obtained from filePathName) + const std::string& vKey, // key dialog + const std::string& vTitle, // title + const char* vFilters, // filters + const std::string& vFilePathName, // file path name (will be decompsoed in path and fileName) + const PaneFun& vSidePane, // side pane + const float& vSidePaneWidth = 250.0f, // side pane width + const int& vCountSelectionMax = 1, // count selection max + UserDatas vUserDatas = nullptr, // user datas (can be retrieved in pane) + ImGuiFileDialogFlags vFlags = 0, // ImGuiFileDialogFlags + SelectFun vSelectFun = nullptr); // function to be called on file click - // Display / Close dialog form - bool Display( // Display the dialog. return true if a result was obtained (Ok or not) - const std::string& vKey, // key dialog to display (if not the same key as defined by OpenDialog/Modal => no opening) - ImGuiWindowFlags vFlags = ImGuiWindowFlags_NoCollapse, // ImGuiWindowFlags - ImVec2 vMinSize = ImVec2(0, 0), // mininmal size contraint for the ImGuiWindow - ImVec2 vMaxSize = ImVec2(FLT_MAX, FLT_MAX)); // maximal size contraint for the ImGuiWindow - void Close(); // close dialog + // Display / Close dialog form + bool Display( // Display the dialog. return true if a result was obtained (Ok or not) + const std::string& vKey, // key dialog to display (if not the same key as defined by OpenDialog/Modal => no opening) + ImGuiWindowFlags vFlags = ImGuiWindowFlags_NoCollapse, // ImGuiWindowFlags + ImVec2 vMinSize = ImVec2(0, 0), // mininmal size contraint for the ImGuiWindow + ImVec2 vMaxSize = ImVec2(FLT_MAX, FLT_MAX)); // maximal size contraint for the ImGuiWindow + void Close(); // close dialog - // queries - bool WasOpenedThisFrame(const std::string& vKey) const; // say if the dialog key was already opened this frame - bool WasOpenedThisFrame() const; // say if the dialog was already opened this frame - bool IsOpened(const std::string& vKey) const; // say if the key is opened - bool IsOpened() const; // say if the dialog is opened somewhere - std::string GetOpenedKey() const; // return the dialog key who is opened, return nothing if not opened + // queries + bool WasOpenedThisFrame(const std::string& vKey) const; // say if the dialog key was already opened this frame + bool WasOpenedThisFrame() const; // say if the dialog was already opened this frame + bool IsOpened(const std::string& vKey) const; // say if the key is opened + bool IsOpened() const; // say if the dialog is opened somewhere + std::string GetOpenedKey() const; // return the dialog key who is opened, return nothing if not opened - // get result - bool IsOk() const; // true => Dialog Closed with Ok result / false : Dialog closed with cancel result - std::map GetSelection(); // Open File behavior : will return selection via a map - std::string GetFilePathName(); // Save File behavior : will always return the content of the field with current filter extention and current path - std::string GetCurrentFileName(); // Save File behavior : will always return the content of the field with current filter extention - std::string GetCurrentPath(); // will return current path - std::string GetCurrentFilter(); // will return selected filter - UserDatas GetUserDatas() const; // will return user datas send with Open Dialog/Modal + // get result + bool IsOk() const; // true => Dialog Closed with Ok result / false : Dialog closed with cancel result + std::map GetSelection(); // Open File behavior : will return selection via a map + std::string GetFilePathName(); // Save File behavior : will always return the content of the field with current filter extention and current path + std::string GetCurrentFileName(); // Save File behavior : will always return the content of the field with current filter extention + std::string GetCurrentPath(); // will return current path + std::string GetCurrentFilter(); // will return selected filter + UserDatas GetUserDatas() const; // will return user datas send with Open Dialog/Modal - // file style by extentions - void SetFileStyle( // SetExtention datas for have custom display of particular file type - const IGFD_FileStyleFlags& vFlags, // file style - const char* vCriteria, // extention filter to tune - const FileStyle& vInfos); // Filter Extention Struct who contain Color and Icon/Text for the display of the file with extention filter - void SetFileStyle( // SetExtention datas for have custom display of particular file type - const IGFD_FileStyleFlags& vFlags, // file style - const char* vCriteria, // extention filter to tune - const ImVec4& vColor, // wanted color for the display of the file with extention filter - const std::string& vIcon = "", // wanted text or icon of the file with extention filter - ImFont *vFont = nullptr); // wantes font - bool GetFileStyle( // GetExtention datas. return true is extention exist - const IGFD_FileStyleFlags& vFlags, // file style - const std::string& vCriteria, // extention filter (same as used in SetExtentionInfos) - ImVec4* vOutColor, // color to retrieve - std::string* vOutIcon = nullptr, // icon or text to retrieve + // file style by extentions + void SetFileStyle( // SetExtention datas for have custom display of particular file type + const IGFD_FileStyleFlags& vFlags, // file style + const char* vCriteria, // extention filter to tune + const FileStyle& vInfos); // Filter Extention Struct who contain Color and Icon/Text for the display of the file with extention filter + void SetFileStyle( // SetExtention datas for have custom display of particular file type + const IGFD_FileStyleFlags& vFlags, // file style + const char* vCriteria, // extention filter to tune + const ImVec4& vColor, // wanted color for the display of the file with extention filter + const std::string& vIcon = "", // wanted text or icon of the file with extention filter + ImFont *vFont = nullptr); // wantes font + bool GetFileStyle( // GetExtention datas. return true is extention exist + const IGFD_FileStyleFlags& vFlags, // file style + const std::string& vCriteria, // extention filter (same as used in SetExtentionInfos) + ImVec4* vOutColor, // color to retrieve + std::string* vOutIcon = nullptr, // icon or text to retrieve ImFont** vOutFont = nullptr); // font to retreive - void ClearFilesStyle(); // clear extentions setttings + void ClearFilesStyle(); // clear extentions setttings - void SetLocales( // set locales to use before and after the dialog display - const int& vLocaleCategory, // set local category - const std::string& vLocaleBegin, // locale to use at begining of the dialog display - const std::string& vLocaleEnd); // locale to use at the end of the dialog display + void SetLocales( // set locales to use before and after the dialog display + const int& vLocaleCategory, // set local category + const std::string& vLocaleBegin, // locale to use at begining of the dialog display + const std::string& vLocaleEnd); // locale to use at the end of the dialog display - protected: - void NewFrame(); // new frame just at begining of display - void EndFrame(); // end frame just at end of display - void QuitFrame(); // quit frame when qui quit the dialog + protected: + void NewFrame(); // new frame just at begining of display + void EndFrame(); // end frame just at end of display + void QuitFrame(); // quit frame when qui quit the dialog - // others - bool prConfirm_Or_OpenOverWriteFileDialog_IfNeeded( - bool vLastAction, ImGuiWindowFlags vFlags); // treatment of the result, start the confirm to overwrite dialog if needed (if defined with flag) - - public: - // dialog parts - virtual void prDrawHeader(); // draw header part of the dialog (bookmark btn, dir creation, path composer, search bar) - virtual bool prDrawContent(); // draw content part of the dialog (bookmark pane, file list, side pane) - virtual bool prDrawFooter(); // draw footer part of the dialog (file field, fitler combobox, ok/cancel btn's) + // others + bool prConfirm_Or_OpenOverWriteFileDialog_IfNeeded( + bool vLastAction, ImGuiWindowFlags vFlags); // treatment of the result, start the confirm to overwrite dialog if needed (if defined with flag) + + public: + // dialog parts + virtual void prDrawHeader(); // draw header part of the dialog (bookmark btn, dir creation, path composer, search bar) + virtual bool prDrawContent(); // draw content part of the dialog (bookmark pane, file list, side pane) + virtual bool prDrawFooter(); // draw footer part of the dialog (file field, fitler combobox, ok/cancel btn's) - // widgets components - virtual void prDrawSidePane(float vHeight); // draw side pane - virtual int prSelectableItem(int vidx, - std::shared_ptr vInfos, - bool vSelected, const char* vFmt, ...); // draw a custom selectable behavior item - virtual bool prDrawFileListView(ImVec2 vSize); // draw file list view (default mode) + // widgets components + virtual void prDrawSidePane(float vHeight); // draw side pane + virtual int prSelectableItem(int vidx, + std::shared_ptr vInfos, + bool vSelected, const char* vFmt, ...); // draw a custom selectable behavior item + virtual bool prDrawFileListView(ImVec2 vSize); // draw file list view (default mode) #ifdef USE_THUMBNAILS - virtual void prDrawThumbnailsListView(ImVec2 vSize); // draw file list view with small thumbnails on the same line - virtual void prDrawThumbnailsGridView(ImVec2 vSize); // draw a grid of small thumbnails + virtual void prDrawThumbnailsListView(ImVec2 vSize); // draw file list view with small thumbnails on the same line + virtual void prDrawThumbnailsGridView(ImVec2 vSize); // draw a grid of small thumbnails #endif - // to be called only by these function and theirs overrides - // - prDrawFileListView - // - prDrawThumbnailsListView - // - prDrawThumbnailsGridView - void prBeginFileColorIconStyle( - std::shared_ptr vFileInfos, - bool& vOutShowColor, - std::string& vOutStr, - ImFont** vOutFont); // begin style apply of filter with color an icon if any - void prEndFileColorIconStyle( - const bool& vShowColor, - ImFont* vFont); // end style apply of filter - }; + // to be called only by these function and theirs overrides + // - prDrawFileListView + // - prDrawThumbnailsListView + // - prDrawThumbnailsGridView + void prBeginFileColorIconStyle( + std::shared_ptr vFileInfos, + bool& vOutShowColor, + std::string& vOutStr, + ImFont** vOutFont); // begin style apply of filter with color an icon if any + void prEndFileColorIconStyle( + const bool& vShowColor, + ImFont* vFont); // end style apply of filter + }; } typedef IGFD::UserDatas IGFDUserDatas; @@ -1382,229 +1374,229 @@ typedef struct IGFD_Selection IGFD_Selection; struct IGFD_Selection_Pair { - char* fileName; - char* filePathName; + char* fileName; + char* filePathName; }; -IMGUIFILEDIALOG_API IGFD_Selection_Pair IGFD_Selection_Pair_Get(); // return an initialized IGFD_Selection_Pair -IMGUIFILEDIALOG_API void IGFD_Selection_Pair_DestroyContent(IGFD_Selection_Pair* vSelection_Pair); // destroy the content of a IGFD_Selection_Pair +IMGUIFILEDIALOG_API IGFD_Selection_Pair IGFD_Selection_Pair_Get(); // return an initialized IGFD_Selection_Pair +IMGUIFILEDIALOG_API void IGFD_Selection_Pair_DestroyContent(IGFD_Selection_Pair* vSelection_Pair); // destroy the content of a IGFD_Selection_Pair struct IGFD_Selection { - IGFD_Selection_Pair* table; // 0 - size_t count; // 0U + IGFD_Selection_Pair* table; // 0 + size_t count; // 0U }; -IMGUIFILEDIALOG_API IGFD_Selection IGFD_Selection_Get(); // return an initialized IGFD_Selection -IMGUIFILEDIALOG_API void IGFD_Selection_DestroyContent(IGFD_Selection* vSelection); // destroy the content of a IGFD_Selection +IMGUIFILEDIALOG_API IGFD_Selection IGFD_Selection_Get(); // return an initialized IGFD_Selection +IMGUIFILEDIALOG_API void IGFD_Selection_DestroyContent(IGFD_Selection* vSelection); // destroy the content of a IGFD_Selection // constructor / destructor -IMGUIFILEDIALOG_API ImGuiFileDialog* IGFD_Create(void); // create the filedialog context -IMGUIFILEDIALOG_API void IGFD_Destroy(ImGuiFileDialog* vContext); // destroy the filedialog context +IMGUIFILEDIALOG_API ImGuiFileDialog* IGFD_Create(void); // create the filedialog context +IMGUIFILEDIALOG_API void IGFD_Destroy(ImGuiFileDialog* vContext); // destroy the filedialog context -typedef void (*IGFD_PaneFun)(const char*, void*, bool*); // callback fucntion for display the pane +typedef void (*IGFD_PaneFun)(const char*, void*, bool*); // callback fucntion for display the pane #ifdef USE_THUMBNAILS -typedef void (*IGFD_CreateThumbnailFun)(IGFD_Thumbnail_Info*); // callback function for create thumbnail texture -typedef void (*IGFD_DestroyThumbnailFun)(IGFD_Thumbnail_Info*); // callback fucntion for destroy thumbnail texture +typedef void (*IGFD_CreateThumbnailFun)(IGFD_Thumbnail_Info*); // callback function for create thumbnail texture +typedef void (*IGFD_DestroyThumbnailFun)(IGFD_Thumbnail_Info*); // callback fucntion for destroy thumbnail texture #endif // USE_THUMBNAILS -IMGUIFILEDIALOG_API void IGFD_OpenDialog( // open a standard dialog - ImGuiFileDialog* vContext, // ImGuiFileDialog context - const char* vKey, // key dialog - const char* vTitle, // title - const char* vFilters, // filters/filter collections. set it to null for directory mode - const char* vPath, // path - const char* vFileName, // defaut file name - const int vCountSelectionMax, // count selection max - void* vUserDatas, // user datas (can be retrieved in pane) - ImGuiFileDialogFlags vFlags); // ImGuiFileDialogFlags +IMGUIFILEDIALOG_API void IGFD_OpenDialog( // open a standard dialog + ImGuiFileDialog* vContext, // ImGuiFileDialog context + const char* vKey, // key dialog + const char* vTitle, // title + const char* vFilters, // filters/filter collections. set it to null for directory mode + const char* vPath, // path + const char* vFileName, // defaut file name + const int vCountSelectionMax, // count selection max + void* vUserDatas, // user datas (can be retrieved in pane) + ImGuiFileDialogFlags vFlags); // ImGuiFileDialogFlags -IMGUIFILEDIALOG_API void IGFD_OpenDialog2( // open a standard dialog - ImGuiFileDialog* vContext, // ImGuiFileDialog context - const char* vKey, // key dialog - const char* vTitle, // title - const char* vFilters, // filters/filter collections. set it to null for directory mode - const char* vFilePathName, // defaut file path name (path and filename witl be extracted from it) - const int vCountSelectionMax, // count selection max - void* vUserDatas, // user datas (can be retrieved in pane) - ImGuiFileDialogFlags vFlags); // ImGuiFileDialogFlags +IMGUIFILEDIALOG_API void IGFD_OpenDialog2( // open a standard dialog + ImGuiFileDialog* vContext, // ImGuiFileDialog context + const char* vKey, // key dialog + const char* vTitle, // title + const char* vFilters, // filters/filter collections. set it to null for directory mode + const char* vFilePathName, // defaut file path name (path and filename witl be extracted from it) + const int vCountSelectionMax, // count selection max + void* vUserDatas, // user datas (can be retrieved in pane) + ImGuiFileDialogFlags vFlags); // ImGuiFileDialogFlags -IMGUIFILEDIALOG_API void IGFD_OpenPaneDialog( // open a standard dialog with pane - ImGuiFileDialog* vContext, // ImGuiFileDialog context - const char* vKey, // key dialog - const char* vTitle, // title - const char* vFilters, // filters/filter collections. set it to null for directory mode - const char* vPath, // path - const char* vFileName, // defaut file name - const IGFD_PaneFun vSidePane, // side pane - const float vSidePaneWidth, // side pane base width - const int vCountSelectionMax, // count selection max - void* vUserDatas, // user datas (can be retrieved in pane) - ImGuiFileDialogFlags vFlags); // ImGuiFileDialogFlags +IMGUIFILEDIALOG_API void IGFD_OpenPaneDialog( // open a standard dialog with pane + ImGuiFileDialog* vContext, // ImGuiFileDialog context + const char* vKey, // key dialog + const char* vTitle, // title + const char* vFilters, // filters/filter collections. set it to null for directory mode + const char* vPath, // path + const char* vFileName, // defaut file name + const IGFD_PaneFun vSidePane, // side pane + const float vSidePaneWidth, // side pane base width + const int vCountSelectionMax, // count selection max + void* vUserDatas, // user datas (can be retrieved in pane) + ImGuiFileDialogFlags vFlags); // ImGuiFileDialogFlags -IMGUIFILEDIALOG_API void IGFD_OpenPaneDialog2( // open a standard dialog with pane - ImGuiFileDialog* vContext, // ImGuiFileDialog context - const char* vKey, // key dialog - const char* vTitle, // title - const char* vFilters, // filters/filter collections. set it to null for directory mode - const char* vFilePathName, // defaut file name (path and filename witl be extracted from it) - const IGFD_PaneFun vSidePane, // side pane - const float vSidePaneWidth, // side pane base width - const int vCountSelectionMax, // count selection max - void* vUserDatas, // user datas (can be retrieved in pane) - ImGuiFileDialogFlags vFlags); // ImGuiFileDialogFlags +IMGUIFILEDIALOG_API void IGFD_OpenPaneDialog2( // open a standard dialog with pane + ImGuiFileDialog* vContext, // ImGuiFileDialog context + const char* vKey, // key dialog + const char* vTitle, // title + const char* vFilters, // filters/filter collections. set it to null for directory mode + const char* vFilePathName, // defaut file name (path and filename witl be extracted from it) + const IGFD_PaneFun vSidePane, // side pane + const float vSidePaneWidth, // side pane base width + const int vCountSelectionMax, // count selection max + void* vUserDatas, // user datas (can be retrieved in pane) + ImGuiFileDialogFlags vFlags); // ImGuiFileDialogFlags -IMGUIFILEDIALOG_API void IGFD_OpenModal( // open a modal dialog - ImGuiFileDialog* vContext, // ImGuiFileDialog context - const char* vKey, // key dialog - const char* vTitle, // title - const char* vFilters, // filters/filter collections. set it to null for directory mode - const char* vPath, // path - const char* vFileName, // defaut file name - const int vCountSelectionMax, // count selection max - void* vUserDatas, // user datas (can be retrieved in pane) - ImGuiFileDialogFlags vFlags); // ImGuiFileDialogFlags +IMGUIFILEDIALOG_API void IGFD_OpenModal( // open a modal dialog + ImGuiFileDialog* vContext, // ImGuiFileDialog context + const char* vKey, // key dialog + const char* vTitle, // title + const char* vFilters, // filters/filter collections. set it to null for directory mode + const char* vPath, // path + const char* vFileName, // defaut file name + const int vCountSelectionMax, // count selection max + void* vUserDatas, // user datas (can be retrieved in pane) + ImGuiFileDialogFlags vFlags); // ImGuiFileDialogFlags -IMGUIFILEDIALOG_API void IGFD_OpenModal2( // open a modal dialog - ImGuiFileDialog* vContext, // ImGuiFileDialog context - const char* vKey, // key dialog - const char* vTitle, // title - const char* vFilters, // filters/filter collections. set it to null for directory mode - const char* vFilePathName, // defaut file name (path and filename witl be extracted from it) - const int vCountSelectionMax, // count selection max - void* vUserDatas, // user datas (can be retrieved in pane) - ImGuiFileDialogFlags vFlags); // ImGuiFileDialogFlags +IMGUIFILEDIALOG_API void IGFD_OpenModal2( // open a modal dialog + ImGuiFileDialog* vContext, // ImGuiFileDialog context + const char* vKey, // key dialog + const char* vTitle, // title + const char* vFilters, // filters/filter collections. set it to null for directory mode + const char* vFilePathName, // defaut file name (path and filename witl be extracted from it) + const int vCountSelectionMax, // count selection max + void* vUserDatas, // user datas (can be retrieved in pane) + ImGuiFileDialogFlags vFlags); // ImGuiFileDialogFlags -IMGUIFILEDIALOG_API void IGFD_OpenPaneModal( // open a modal dialog with pane - ImGuiFileDialog* vContext, // ImGuiFileDialog context - const char* vKey, // key dialog - const char* vTitle, // title - const char* vFilters, // filters/filter collections. set it to null for directory mode - const char* vPath, // path - const char* vFileName, // defaut file name - const IGFD_PaneFun vSidePane, // side pane - const float vSidePaneWidth, // side pane base width - const int vCountSelectionMax, // count selection max - void* vUserDatas, // user datas (can be retrieved in pane) - ImGuiFileDialogFlags vFlags); // ImGuiFileDialogFlags +IMGUIFILEDIALOG_API void IGFD_OpenPaneModal( // open a modal dialog with pane + ImGuiFileDialog* vContext, // ImGuiFileDialog context + const char* vKey, // key dialog + const char* vTitle, // title + const char* vFilters, // filters/filter collections. set it to null for directory mode + const char* vPath, // path + const char* vFileName, // defaut file name + const IGFD_PaneFun vSidePane, // side pane + const float vSidePaneWidth, // side pane base width + const int vCountSelectionMax, // count selection max + void* vUserDatas, // user datas (can be retrieved in pane) + ImGuiFileDialogFlags vFlags); // ImGuiFileDialogFlags -IMGUIFILEDIALOG_API void IGFD_OpenPaneModal2( // open a modal dialog with pane - ImGuiFileDialog* vContext, // ImGuiFileDialog context - const char* vKey, // key dialog - const char* vTitle, // title - const char* vFilters, // filters/filter collections. set it to null for directory mode - const char* vFilePathName, // defaut file name (path and filename witl be extracted from it) - const IGFD_PaneFun vSidePane, // side pane - const float vSidePaneWidth, // side pane base width - const int vCountSelectionMax, // count selection max - void* vUserDatas, // user datas (can be retrieved in pane) - ImGuiFileDialogFlags vFlags); // ImGuiFileDialogFlags +IMGUIFILEDIALOG_API void IGFD_OpenPaneModal2( // open a modal dialog with pane + ImGuiFileDialog* vContext, // ImGuiFileDialog context + const char* vKey, // key dialog + const char* vTitle, // title + const char* vFilters, // filters/filter collections. set it to null for directory mode + const char* vFilePathName, // defaut file name (path and filename witl be extracted from it) + const IGFD_PaneFun vSidePane, // side pane + const float vSidePaneWidth, // side pane base width + const int vCountSelectionMax, // count selection max + void* vUserDatas, // user datas (can be retrieved in pane) + ImGuiFileDialogFlags vFlags); // ImGuiFileDialogFlags -IMGUIFILEDIALOG_API bool IGFD_DisplayDialog( // Display the dialog - ImGuiFileDialog* vContext, // ImGuiFileDialog context - const char* vKey, // key dialog to display (if not the same key as defined by OpenDialog/Modal => no opening) - ImGuiWindowFlags vFlags, // ImGuiWindowFlags - ImVec2 vMinSize, // mininmal size contraint for the ImGuiWindow - ImVec2 vMaxSize); // maximal size contraint for the ImGuiWindow +IMGUIFILEDIALOG_API bool IGFD_DisplayDialog( // Display the dialog + ImGuiFileDialog* vContext, // ImGuiFileDialog context + const char* vKey, // key dialog to display (if not the same key as defined by OpenDialog/Modal => no opening) + ImGuiWindowFlags vFlags, // ImGuiWindowFlags + ImVec2 vMinSize, // mininmal size contraint for the ImGuiWindow + ImVec2 vMaxSize); // maximal size contraint for the ImGuiWindow -IMGUIFILEDIALOG_API void IGFD_CloseDialog( // Close the dialog - ImGuiFileDialog* vContext); // ImGuiFileDialog context +IMGUIFILEDIALOG_API void IGFD_CloseDialog( // Close the dialog + ImGuiFileDialog* vContext); // ImGuiFileDialog context -IMGUIFILEDIALOG_API bool IGFD_IsOk( // true => Dialog Closed with Ok result / false : Dialog closed with cancel result - ImGuiFileDialog* vContext); // ImGuiFileDialog context +IMGUIFILEDIALOG_API bool IGFD_IsOk( // true => Dialog Closed with Ok result / false : Dialog closed with cancel result + ImGuiFileDialog* vContext); // ImGuiFileDialog context -IMGUIFILEDIALOG_API bool IGFD_WasKeyOpenedThisFrame( // say if the dialog key was already opened this frame - ImGuiFileDialog* vContext, // ImGuiFileDialog context - const char* vKey); +IMGUIFILEDIALOG_API bool IGFD_WasKeyOpenedThisFrame( // say if the dialog key was already opened this frame + ImGuiFileDialog* vContext, // ImGuiFileDialog context + const char* vKey); -IMGUIFILEDIALOG_API bool IGFD_WasOpenedThisFrame( // say if the dialog was already opened this frame - ImGuiFileDialog* vContext); // ImGuiFileDialog context +IMGUIFILEDIALOG_API bool IGFD_WasOpenedThisFrame( // say if the dialog was already opened this frame + ImGuiFileDialog* vContext); // ImGuiFileDialog context -IMGUIFILEDIALOG_API bool IGFD_IsKeyOpened( // say if the dialog key is opened - ImGuiFileDialog* vContext, // ImGuiFileDialog context - const char* vCurrentOpenedKey); // the dialog key +IMGUIFILEDIALOG_API bool IGFD_IsKeyOpened( // say if the dialog key is opened + ImGuiFileDialog* vContext, // ImGuiFileDialog context + const char* vCurrentOpenedKey); // the dialog key -IMGUIFILEDIALOG_API bool IGFD_IsOpened( // say if the dialog is opened somewhere - ImGuiFileDialog* vContext); // ImGuiFileDialog context +IMGUIFILEDIALOG_API bool IGFD_IsOpened( // say if the dialog is opened somewhere + ImGuiFileDialog* vContext); // ImGuiFileDialog context -IMGUIFILEDIALOG_API IGFD_Selection IGFD_GetSelection( // Open File behavior : will return selection via a map - ImGuiFileDialog* vContext); // ImGuiFileDialog context +IMGUIFILEDIALOG_API IGFD_Selection IGFD_GetSelection( // Open File behavior : will return selection via a map + ImGuiFileDialog* vContext); // ImGuiFileDialog context -IMGUIFILEDIALOG_API char* IGFD_GetFilePathName( // Save File behavior : will always return the content of the field with current filter extention and current path - ImGuiFileDialog* vContext); // ImGuiFileDialog context +IMGUIFILEDIALOG_API char* IGFD_GetFilePathName( // Save File behavior : will always return the content of the field with current filter extention and current path + ImGuiFileDialog* vContext); // ImGuiFileDialog context -IMGUIFILEDIALOG_API char* IGFD_GetCurrentFileName( // Save File behavior : will always return the content of the field with current filter extention - ImGuiFileDialog* vContext); // ImGuiFileDialog context +IMGUIFILEDIALOG_API char* IGFD_GetCurrentFileName( // Save File behavior : will always return the content of the field with current filter extention + ImGuiFileDialog* vContext); // ImGuiFileDialog context -IMGUIFILEDIALOG_API char* IGFD_GetCurrentPath( // will return current path - ImGuiFileDialog* vContext); // ImGuiFileDialog context +IMGUIFILEDIALOG_API char* IGFD_GetCurrentPath( // will return current path + ImGuiFileDialog* vContext); // ImGuiFileDialog context -IMGUIFILEDIALOG_API char* IGFD_GetCurrentFilter( // will return selected filter - ImGuiFileDialog* vContext); // ImGuiFileDialog context +IMGUIFILEDIALOG_API char* IGFD_GetCurrentFilter( // will return selected filter + ImGuiFileDialog* vContext); // ImGuiFileDialog context -IMGUIFILEDIALOG_API void* IGFD_GetUserDatas( // will return user datas send with Open Dialog/Modal - ImGuiFileDialog* vContext); // ImGuiFileDialog context +IMGUIFILEDIALOG_API void* IGFD_GetUserDatas( // will return user datas send with Open Dialog/Modal + ImGuiFileDialog* vContext); // ImGuiFileDialog context -IMGUIFILEDIALOG_API void IGFD_SetFileStyle( // SetExtention datas for have custom display of particular file type - ImGuiFileDialog* vContext, // ImGuiFileDialog context - IGFD_FileStyleFlags vFileStyleFlags, // file style type - const char* vFilter, // extention filter to tune - ImVec4 vColor, // wanted color for the display of the file with extention filter - const char* vIconText, // wanted text or icon of the file with extention filter (can be sued with font icon) - ImFont* vFont); // wanted font pointer +IMGUIFILEDIALOG_API void IGFD_SetFileStyle( // SetExtention datas for have custom display of particular file type + ImGuiFileDialog* vContext, // ImGuiFileDialog context + IGFD_FileStyleFlags vFileStyleFlags, // file style type + const char* vFilter, // extention filter to tune + ImVec4 vColor, // wanted color for the display of the file with extention filter + const char* vIconText, // wanted text or icon of the file with extention filter (can be sued with font icon) + ImFont* vFont); // wanted font pointer -IMGUIFILEDIALOG_API void IGFD_SetFileStyle2( // SetExtention datas for have custom display of particular file type - ImGuiFileDialog* vContext, // ImGuiFileDialog context - IGFD_FileStyleFlags vFileStyleFlags, // file style type - const char* vFilter, // extention filter to tune - float vR, float vG, float vB, float vA, // wanted color channels RGBA for the display of the file with extention filter - const char* vIconText, // wanted text or icon of the file with extention filter (can be sued with font icon) - ImFont* vFont); // wanted font pointer +IMGUIFILEDIALOG_API void IGFD_SetFileStyle2( // SetExtention datas for have custom display of particular file type + ImGuiFileDialog* vContext, // ImGuiFileDialog context + IGFD_FileStyleFlags vFileStyleFlags, // file style type + const char* vFilter, // extention filter to tune + float vR, float vG, float vB, float vA, // wanted color channels RGBA for the display of the file with extention filter + const char* vIconText, // wanted text or icon of the file with extention filter (can be sued with font icon) + ImFont* vFont); // wanted font pointer IMGUIFILEDIALOG_API bool IGFD_GetFileStyle( - ImGuiFileDialog* vContext, // ImGuiFileDialog context - IGFD_FileStyleFlags vFileStyleFlags, // file style type - const char* vFilter, // extention filter (same as used in SetExtentionInfos) - ImVec4* vOutColor, // color to retrieve - char** vOutIconText, // icon or text to retrieve - ImFont** vOutFont); // font pointer to retrived + ImGuiFileDialog* vContext, // ImGuiFileDialog context + IGFD_FileStyleFlags vFileStyleFlags, // file style type + const char* vFilter, // extention filter (same as used in SetExtentionInfos) + ImVec4* vOutColor, // color to retrieve + char** vOutIconText, // icon or text to retrieve + ImFont** vOutFont); // font pointer to retrived -IMGUIFILEDIALOG_API void IGFD_ClearFilesStyle( // clear extentions setttings - ImGuiFileDialog* vContext); // ImGuiFileDialog context +IMGUIFILEDIALOG_API void IGFD_ClearFilesStyle( // clear extentions setttings + ImGuiFileDialog* vContext); // ImGuiFileDialog context -IMGUIFILEDIALOG_API void SetLocales( // set locales to use before and after display - ImGuiFileDialog* vContext, // ImGuiFileDialog context - const int vCategory, // set local category - const char* vBeginLocale, // locale to use at begining of the dialog display - const char* vEndLocale); // locale to set at end of the dialog display +IMGUIFILEDIALOG_API void SetLocales( // set locales to use before and after display + ImGuiFileDialog* vContext, // ImGuiFileDialog context + const int vCategory, // set local category + const char* vBeginLocale, // locale to use at begining of the dialog display + const char* vEndLocale); // locale to set at end of the dialog display #ifdef USE_EXPLORATION_BY_KEYS -IMGUIFILEDIALOG_API void IGFD_SetFlashingAttenuationInSeconds( // set the flashing time of the line in file list when use exploration keys - ImGuiFileDialog* vContext, // ImGuiFileDialog context - float vAttenValue); // set the attenuation (from flashed to not flashed) in seconds +IMGUIFILEDIALOG_API void IGFD_SetFlashingAttenuationInSeconds( // set the flashing time of the line in file list when use exploration keys + ImGuiFileDialog* vContext, // ImGuiFileDialog context + float vAttenValue); // set the attenuation (from flashed to not flashed) in seconds #endif #ifdef USE_BOOKMARK -IMGUIFILEDIALOG_API char* IGFD_SerializeBookmarks( // serialize bookmarks : return bookmark buffer to save in a file - ImGuiFileDialog* vContext); // ImGuiFileDialog context +IMGUIFILEDIALOG_API char* IGFD_SerializeBookmarks( // serialize bookmarks : return bookmark buffer to save in a file + ImGuiFileDialog* vContext); // ImGuiFileDialog context -IMGUIFILEDIALOG_API void IGFD_DeserializeBookmarks( // deserialize bookmarks : load bookmar buffer to load in the dialog (saved from previous use with SerializeBookmarks()) - ImGuiFileDialog* vContext, // ImGuiFileDialog context - const char* vBookmarks); // bookmark buffer to load +IMGUIFILEDIALOG_API void IGFD_DeserializeBookmarks( // deserialize bookmarks : load bookmar buffer to load in the dialog (saved from previous use with SerializeBookmarks()) + ImGuiFileDialog* vContext, // ImGuiFileDialog context + const char* vBookmarks); // bookmark buffer to load #endif #ifdef USE_THUMBNAILS -IMGUIFILEDIALOG_API void SetCreateThumbnailCallback( // define the callback for create the thumbnails texture - ImGuiFileDialog* vContext, // ImGuiFileDialog context - IGFD_CreateThumbnailFun vCreateThumbnailFun); // the callback for create the thumbnails texture +IMGUIFILEDIALOG_API void SetCreateThumbnailCallback( // define the callback for create the thumbnails texture + ImGuiFileDialog* vContext, // ImGuiFileDialog context + IGFD_CreateThumbnailFun vCreateThumbnailFun); // the callback for create the thumbnails texture -IMGUIFILEDIALOG_API void SetDestroyThumbnailCallback( // define the callback for destroy the thumbnails texture - ImGuiFileDialog* vContext, // ImGuiFileDialog context - IGFD_DestroyThumbnailFun vDestroyThumbnailFun); // the callback for destroy the thumbnails texture +IMGUIFILEDIALOG_API void SetDestroyThumbnailCallback( // define the callback for destroy the thumbnails texture + ImGuiFileDialog* vContext, // ImGuiFileDialog context + IGFD_DestroyThumbnailFun vDestroyThumbnailFun); // the callback for destroy the thumbnails texture -IMGUIFILEDIALOG_API void ManageGPUThumbnails( // must be call in gpu zone, possibly a thread, will call the callback for create / destroy the textures - ImGuiFileDialog* vContext); // ImGuiFileDialog context +IMGUIFILEDIALOG_API void ManageGPUThumbnails( // must be call in gpu zone, possibly a thread, will call the callback for create / destroy the textures + ImGuiFileDialog* vContext); // ImGuiFileDialog context #endif // USE_THUMBNAILS //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/extern/igfd/ImGuiFileDialogConfig.h b/extern/igfd/ImGuiFileDialogConfig.h index 3416b029..4a212b60 100644 --- a/extern/igfd/ImGuiFileDialogConfig.h +++ b/extern/igfd/ImGuiFileDialogConfig.h @@ -2,9 +2,6 @@ // uncomment and modify defines under for customize ImGuiFileDialog -//this options need c++17 -//#define USE_STD_FILESYSTEM - //#define MAX_FILE_DIALOG_NAME_BUFFER 1024 //#define MAX_PATH_BUFFER_SIZE 1024 @@ -80,9 +77,9 @@ //#define DateTimeFormat "%Y/%m/%d %i:%M%p" // theses icons will appear in table headers -//#define USE_CUSTOM_SORTING_ICON -//#define tableHeaderAscendingIcon "A|" -//#define tableHeaderDescendingIcon "D|" +#define USE_CUSTOM_SORTING_ICON +#define tableHeaderAscendingIcon ICON_FA_CHEVRON_UP " " +#define tableHeaderDescendingIcon ICON_FA_CHEVRON_DOWN " " //#define tableHeaderFileNameString " File name" //#define tableHeaderFileTypeString " Type" //#define tableHeaderFileSizeString " Size" diff --git a/extern/igfd/dirent/dirent.h b/extern/igfd/dirent/dirent.h index 0549aa27..35d948a6 100644 --- a/extern/igfd/dirent/dirent.h +++ b/extern/igfd/dirent/dirent.h @@ -237,6 +237,10 @@ struct _wdirent { /* File name */ wchar_t d_name[PATH_MAX+1]; + + /* Windows extensions */ + size_t dwin_size; + FILETIME dwin_mtime; }; typedef struct _wdirent _wdirent; @@ -277,6 +281,10 @@ struct dirent { /* File name */ char d_name[PATH_MAX+1]; + + /* Windows extensions */ + size_t dwin_size; + FILETIME dwin_mtime; }; typedef struct dirent dirent; @@ -516,6 +524,9 @@ _wreaddir_r( entry->d_off = 0; entry->d_reclen = sizeof (struct _wdirent); + entry->dwin_size = ((size_t)datap->nFileSizeHigh<<32) | datap->nFileSizeLow; + entry->dwin_mtime = datap->ftLastWriteTime; + /* Set result address */ *result = entry; @@ -806,6 +817,9 @@ readdir_r( entry->d_off = 0; entry->d_reclen = sizeof (struct dirent); + entry->dwin_size = ((size_t)datap->nFileSizeHigh<<32) | datap->nFileSizeLow; + entry->dwin_mtime = datap->ftLastWriteTime; + } else { /* @@ -821,6 +835,9 @@ readdir_r( entry->d_ino = 0; entry->d_off = -1; entry->d_reclen = 0; + entry->dwin_size = 0; + entry->dwin_mtime.dwHighDateTime = 0; + entry->dwin_mtime.dwLowDateTime = 0; } diff --git a/extern/imgui_patched/.editorconfig b/extern/imgui_patched/.editorconfig index c6dc600a..5adfefa2 100644 --- a/extern/imgui_patched/.editorconfig +++ b/extern/imgui_patched/.editorconfig @@ -1,7 +1,11 @@ # See http://editorconfig.org to read about the EditorConfig format. # - In theory automatically supported by VS2017+ and most common IDE or text editors. -# - In practice VS2019 stills gets trailing whitespaces wrong :( -# - Suggest install to trim whitespaces: https://marketplace.visualstudio.com/items?itemName=MadsKristensen.TrailingWhitespaceVisualizer +# - In practice VS2019-VS2022 stills don't trim trailing whitespaces correctly :( +# - Suggest installing this to trim whitespaces: +# GitHub https://github.com/madskristensen/TrailingWhitespace +# VS2019 https://marketplace.visualstudio.com/items?itemName=MadsKristensen.TrailingWhitespaceVisualizer +# VS2022 https://marketplace.visualstudio.com/items?itemName=MadsKristensen.TrailingWhitespace64 +# (in spite of its name doesn't only visualize but also trims) # - Alternative for older VS2010 to VS2015: https://marketplace.visualstudio.com/items?itemName=EditorConfigTeam.EditorConfig # top-most EditorConfig file diff --git a/extern/imgui_patched/.gitignore b/extern/imgui_patched/.gitignore index 86bed609..dc716466 100644 --- a/extern/imgui_patched/.gitignore +++ b/extern/imgui_patched/.gitignore @@ -26,6 +26,9 @@ ipch *.VC.db *.VC.VC.opendb +## Getting files created in JSON/Schemas/Catalog/ from a VS2022 update +JSON/ + ## Commonly used CMake directories /build*/ @@ -37,7 +40,8 @@ xcuserdata examples/*.o.tmp examples/*.out.js examples/*.out.wasm -examples/example_emscripten_opengl3/web/* +examples/example_glfw_opengl3/web/* +examples/example_sdl2_opengl3/web/* examples/example_emscripten_wgpu/web/* ## JetBrains IDE artifacts @@ -45,9 +49,12 @@ examples/example_emscripten_wgpu/web/* cmake-build-* ## Unix executables from our example Makefiles +examples/example_glfw_metal/example_glfw_metal examples/example_glfw_opengl2/example_glfw_opengl2 examples/example_glfw_opengl3/example_glfw_opengl3 examples/example_glut_opengl2/example_glut_opengl2 examples/example_null/example_null -examples/example_sdl_opengl2/example_sdl_opengl2 -examples/example_sdl_opengl3/example_sdl_opengl3 +examples/example_sdl2_metal/example_sdl2_metal +examples/example_sdl2_opengl2/example_sdl2_opengl2 +examples/example_sdl2_opengl3/example_sdl2_opengl3 +examples/example_sdl2_sdlrenderer/example_sdl2_sdlrenderer diff --git a/extern/imgui_patched/LICENSE.txt b/extern/imgui_patched/LICENSE.txt index 4023e0ca..fb715bdc 100644 --- a/extern/imgui_patched/LICENSE.txt +++ b/extern/imgui_patched/LICENSE.txt @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2014-2022 Omar Cornut +Copyright (c) 2014-2023 Omar Cornut Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/extern/imgui_patched/backends/imgui_impl_allegro5.cpp b/extern/imgui_patched/backends/imgui_impl_allegro5.cpp index 83203382..ae91443c 100644 --- a/extern/imgui_patched/backends/imgui_impl_allegro5.cpp +++ b/extern/imgui_patched/backends/imgui_impl_allegro5.cpp @@ -7,7 +7,7 @@ // [X] Platform: Clipboard support (from Allegro 5.1.12) // [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'. // Issues: -// [ ] Renderer: The renderer is suboptimal as we need to unindex our buffers and convert vertices manually. +// [ ] Renderer: The renderer is suboptimal as we need to convert vertices manually. // [ ] Platform: Missing gamepad support. // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. @@ -17,7 +17,10 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) -// 2022-01-26: Inputs: replaced short-lived io.AddKeyModsEvent() (added two weeks ago)with io.AddKeyEvent() using ImGuiKey_ModXXX flags. Sorry for the confusion. +// 2022-11-30: Renderer: Restoring using al_draw_indexed_prim() when Allegro version is >= 5.2.5. +// 2022-10-11: Using 'nullptr' instead of 'NULL' as per our switch to C++11. +// 2022-09-26: Inputs: Renamed ImGuiKey_ModXXX introduced in 1.87 to ImGuiMod_XXX (old names still supported). +// 2022-01-26: Inputs: replaced short-lived io.AddKeyModsEvent() (added two weeks ago) with io.AddKeyEvent() using ImGuiKey_ModXXX flags. Sorry for the confusion. // 2022-01-17: Inputs: calling new io.AddMousePosEvent(), io.AddMouseButtonEvent(), io.AddMouseWheelEvent() API (1.87+). // 2022-01-17: Inputs: always calling io.AddKeyModsEvent() next and before key event (not in NewFrame) to fix input queue with very low framerates. // 2022-01-10: Inputs: calling new io.AddKeyEvent(), io.AddKeyModsEvent() + io.SetKeyEventNativeData() API (1.87+). Support for full ImGuiKey range. @@ -35,6 +38,7 @@ // 2018-11-30: Misc: Setting up io.BackendPlatformName/io.BackendRendererName so they can be displayed in the About Window. // 2018-06-13: Platform: Added clipboard support (from Allegro 5.1.12). // 2018-06-13: Renderer: Use draw_data->DisplayPos and draw_data->DisplaySize to setup projection matrix and clipping rectangle. +// 2018-06-13: Renderer: Stopped using al_draw_indexed_prim() as it is buggy in Allegro's DX9 backend. // 2018-06-13: Renderer: Backup/restore transform and clipping rectangle. // 2018-06-11: Misc: Setup io.BackendFlags ImGuiBackendFlags_HasMouseCursors flag + honor ImGuiConfigFlags_NoMouseCursorChange flag. // 2018-04-18: Misc: Renamed file from imgui_impl_a5.cpp to imgui_impl_allegro5.cpp. @@ -54,13 +58,27 @@ #ifdef _WIN32 #include #endif -#define ALLEGRO_HAS_CLIPBOARD (ALLEGRO_VERSION_INT >= ((5 << 24) | (1 << 16) | (12 << 8))) // Clipboard only supported from Allegro 5.1.12 +#define ALLEGRO_HAS_CLIPBOARD (ALLEGRO_VERSION_INT >= ((5 << 24) | (1 << 16) | (12 << 8))) // Clipboard only supported from Allegro 5.1.12 +#define ALLEGRO_HAS_DRAW_INDEXED_PRIM (ALLEGRO_VERSION_INT >= ((5 << 24) | (2 << 16) | ( 5 << 8))) // DX9 implementation of al_draw_indexed_prim() got fixed in Allegro 5.2.5 // Visual Studio warnings #ifdef _MSC_VER #pragma warning (disable: 4127) // condition expression is constant #endif +struct ImDrawVertAllegro +{ + ImVec2 pos; + ImVec2 uv; + ALLEGRO_COLOR col; +}; + +// FIXME-OPT: Unfortunately Allegro doesn't support 32-bit packed colors so we have to convert them to 4 float as well.. +// FIXME-OPT: Consider inlining al_map_rgba()? +// see https://github.com/liballeg/allegro5/blob/master/src/pixels.c#L554 +// and https://github.com/liballeg/allegro5/blob/master/include/allegro5/internal/aintern_pixels.h +#define DRAW_VERT_IMGUI_TO_ALLEGRO(DST, SRC) { (DST)->pos = (SRC)->pos; (DST)->uv = (SRC)->uv; unsigned char* c = (unsigned char*)&(SRC)->col; (DST)->col = al_map_rgba(c[0], c[1], c[2], c[3]); } + // Allegro Data struct ImGui_ImplAllegro5_Data { @@ -71,20 +89,16 @@ struct ImGui_ImplAllegro5_Data ALLEGRO_VERTEX_DECL* VertexDecl; char* ClipboardTextData; + ImVector BufVertices; + ImVector BufIndices; + ImGui_ImplAllegro5_Data() { memset((void*)this, 0, sizeof(*this)); } }; // Backend data stored in io.BackendPlatformUserData to allow support for multiple Dear ImGui contexts // It is STRONGLY preferred that you use docking branch with multi-viewports (== single Dear ImGui context + multiple windows) instead of multiple Dear ImGui contexts. // FIXME: multi-context support is not well tested and probably dysfunctional in this backend. -static ImGui_ImplAllegro5_Data* ImGui_ImplAllegro5_GetBackendData() { return ImGui::GetCurrentContext() ? (ImGui_ImplAllegro5_Data*)ImGui::GetIO().BackendPlatformUserData : NULL; } - -struct ImDrawVertAllegro -{ - ImVec2 pos; - ImVec2 uv; - ALLEGRO_COLOR col; -}; +static ImGui_ImplAllegro5_Data* ImGui_ImplAllegro5_GetBackendData() { return ImGui::GetCurrentContext() ? (ImGui_ImplAllegro5_Data*)ImGui::GetIO().BackendPlatformUserData : nullptr; } static void ImGui_ImplAllegro5_SetupRenderState(ImDrawData* draw_data) { @@ -130,35 +144,40 @@ void ImGui_ImplAllegro5_RenderDrawData(ImDrawData* draw_data) { const ImDrawList* cmd_list = draw_data->CmdLists[n]; - // Allegro's implementation of al_draw_indexed_prim() for DX9 is completely broken. Unindex our buffers ourselves. - // FIXME-OPT: Unfortunately Allegro doesn't support 32-bit packed colors so we have to convert them to 4 float as well.. - static ImVector vertices; - vertices.resize(cmd_list->IdxBuffer.Size); - for (int i = 0; i < cmd_list->IdxBuffer.Size; i++) + ImVector& vertices = bd->BufVertices; +#if ALLEGRO_HAS_DRAW_INDEXED_PRIM + vertices.resize(cmd_list->VtxBuffer.Size); + for (int i = 0; i < cmd_list->VtxBuffer.Size; i++) { - const ImDrawVert* src_v = &cmd_list->VtxBuffer[cmd_list->IdxBuffer[i]]; + const ImDrawVert* src_v = &cmd_list->VtxBuffer[i]; ImDrawVertAllegro* dst_v = &vertices[i]; - dst_v->pos = src_v->pos; - dst_v->uv = src_v->uv; - unsigned char* c = (unsigned char*)&src_v->col; - dst_v->col = al_map_rgba(c[0], c[1], c[2], c[3]); + DRAW_VERT_IMGUI_TO_ALLEGRO(dst_v, src_v); } - - const int* indices = NULL; + const int* indices = nullptr; if (sizeof(ImDrawIdx) == 2) { - // FIXME-OPT: Unfortunately Allegro doesn't support 16-bit indices.. You can '#define ImDrawIdx int' in imconfig.h to request Dear ImGui to output 32-bit indices. + // FIXME-OPT: Allegro doesn't support 16-bit indices. + // You can '#define ImDrawIdx int' in imconfig.h to request Dear ImGui to output 32-bit indices. // Otherwise, we convert them from 16-bit to 32-bit at runtime here, which works perfectly but is a little wasteful. - static ImVector indices_converted; - indices_converted.resize(cmd_list->IdxBuffer.Size); + bd->BufIndices.resize(cmd_list->IdxBuffer.Size); for (int i = 0; i < cmd_list->IdxBuffer.Size; ++i) - indices_converted[i] = (int)cmd_list->IdxBuffer.Data[i]; - indices = indices_converted.Data; + bd->BufIndices[i] = (int)cmd_list->IdxBuffer.Data[i]; + indices = bd->BufIndices.Data; } else if (sizeof(ImDrawIdx) == 4) { indices = (const int*)cmd_list->IdxBuffer.Data; } +#else + // Allegro's implementation of al_draw_indexed_prim() for DX9 was broken until 5.2.5. Unindex buffers ourselves while converting vertex format. + vertices.resize(cmd_list->IdxBuffer.Size); + for (int i = 0; i < cmd_list->IdxBuffer.Size; i++) + { + const ImDrawVert* src_v = &cmd_list->VtxBuffer[cmd_list->IdxBuffer[i]]; + ImDrawVertAllegro* dst_v = &vertices[i]; + DRAW_VERT_IMGUI_TO_ALLEGRO(dst_v, src_v); + } +#endif // Render command lists ImVec2 clip_off = draw_data->DisplayPos; @@ -185,7 +204,11 @@ void ImGui_ImplAllegro5_RenderDrawData(ImDrawData* draw_data) // Apply scissor/clipping rectangle, Draw ALLEGRO_BITMAP* texture = (ALLEGRO_BITMAP*)pcmd->GetTexID(); al_set_clipping_rectangle(clip_min.x, clip_min.y, clip_max.x - clip_min.x, clip_max.y - clip_min.y); +#if ALLEGRO_HAS_DRAW_INDEXED_PRIM + al_draw_indexed_prim(&vertices[0], bd->VertexDecl, texture, &indices[pcmd->IdxOffset], pcmd->ElemCount, ALLEGRO_PRIM_TRIANGLE_LIST); +#else al_draw_prim(&vertices[0], bd->VertexDecl, texture, pcmd->IdxOffset, pcmd->IdxOffset + pcmd->ElemCount, ALLEGRO_PRIM_TRIANGLE_LIST); +#endif } } } @@ -252,14 +275,14 @@ void ImGui_ImplAllegro5_InvalidateDeviceObjects() ImGui_ImplAllegro5_Data* bd = ImGui_ImplAllegro5_GetBackendData(); if (bd->Texture) { - io.Fonts->SetTexID(NULL); + io.Fonts->SetTexID(0); al_destroy_bitmap(bd->Texture); - bd->Texture = NULL; + bd->Texture = nullptr; } if (bd->MouseCursorInvisible) { al_destroy_mouse_cursor(bd->MouseCursorInvisible); - bd->MouseCursorInvisible = NULL; + bd->MouseCursorInvisible = nullptr; } } @@ -396,7 +419,7 @@ static ImGuiKey ImGui_ImplAllegro5_KeyCodeToImGuiKey(int key_code) bool ImGui_ImplAllegro5_Init(ALLEGRO_DISPLAY* display) { ImGuiIO& io = ImGui::GetIO(); - IM_ASSERT(io.BackendPlatformUserData == NULL && "Already initialized a platform backend!"); + IM_ASSERT(io.BackendPlatformUserData == nullptr && "Already initialized a platform backend!"); // Setup backend capabilities flags ImGui_ImplAllegro5_Data* bd = IM_NEW(ImGui_ImplAllegro5_Data)(); @@ -421,7 +444,7 @@ bool ImGui_ImplAllegro5_Init(ALLEGRO_DISPLAY* display) #if ALLEGRO_HAS_CLIPBOARD io.SetClipboardTextFn = ImGui_ImplAllegro5_SetClipboardText; io.GetClipboardTextFn = ImGui_ImplAllegro5_GetClipboardText; - io.ClipboardUserData = NULL; + io.ClipboardUserData = nullptr; #endif return true; @@ -430,7 +453,7 @@ bool ImGui_ImplAllegro5_Init(ALLEGRO_DISPLAY* display) void ImGui_ImplAllegro5_Shutdown() { ImGui_ImplAllegro5_Data* bd = ImGui_ImplAllegro5_GetBackendData(); - IM_ASSERT(bd != NULL && "No platform backend to shutdown, or already shutdown?"); + IM_ASSERT(bd != nullptr && "No platform backend to shutdown, or already shutdown?"); ImGuiIO& io = ImGui::GetIO(); ImGui_ImplAllegro5_InvalidateDeviceObjects(); @@ -439,8 +462,9 @@ void ImGui_ImplAllegro5_Shutdown() if (bd->ClipboardTextData) al_free(bd->ClipboardTextData); - io.BackendPlatformUserData = NULL; - io.BackendPlatformName = io.BackendRendererName = NULL; + io.BackendPlatformName = io.BackendRendererName = nullptr; + io.BackendPlatformUserData = nullptr; + io.BackendFlags &= ~ImGuiBackendFlags_HasMouseCursors; IM_DELETE(bd); } @@ -450,10 +474,10 @@ static void ImGui_ImplAllegro5_UpdateKeyModifiers() ImGuiIO& io = ImGui::GetIO(); ALLEGRO_KEYBOARD_STATE keys; al_get_keyboard_state(&keys); - io.AddKeyEvent(ImGuiKey_ModCtrl, al_key_down(&keys, ALLEGRO_KEY_LCTRL) || al_key_down(&keys, ALLEGRO_KEY_RCTRL)); - io.AddKeyEvent(ImGuiKey_ModShift, al_key_down(&keys, ALLEGRO_KEY_LSHIFT) || al_key_down(&keys, ALLEGRO_KEY_RSHIFT)); - io.AddKeyEvent(ImGuiKey_ModAlt, al_key_down(&keys, ALLEGRO_KEY_ALT) || al_key_down(&keys, ALLEGRO_KEY_ALTGR)); - io.AddKeyEvent(ImGuiKey_ModSuper, al_key_down(&keys, ALLEGRO_KEY_LWIN) || al_key_down(&keys, ALLEGRO_KEY_RWIN)); + io.AddKeyEvent(ImGuiMod_Ctrl, al_key_down(&keys, ALLEGRO_KEY_LCTRL) || al_key_down(&keys, ALLEGRO_KEY_RCTRL)); + io.AddKeyEvent(ImGuiMod_Shift, al_key_down(&keys, ALLEGRO_KEY_LSHIFT) || al_key_down(&keys, ALLEGRO_KEY_RSHIFT)); + io.AddKeyEvent(ImGuiMod_Alt, al_key_down(&keys, ALLEGRO_KEY_ALT) || al_key_down(&keys, ALLEGRO_KEY_ALTGR)); + io.AddKeyEvent(ImGuiMod_Super, al_key_down(&keys, ALLEGRO_KEY_LWIN) || al_key_down(&keys, ALLEGRO_KEY_RWIN)); } // You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs. @@ -558,7 +582,7 @@ static void ImGui_ImplAllegro5_UpdateMouseCursor() void ImGui_ImplAllegro5_NewFrame() { ImGui_ImplAllegro5_Data* bd = ImGui_ImplAllegro5_GetBackendData(); - IM_ASSERT(bd != NULL && "Did you call ImGui_ImplAllegro5_Init()?"); + IM_ASSERT(bd != nullptr && "Did you call ImGui_ImplAllegro5_Init()?"); if (!bd->Texture) ImGui_ImplAllegro5_CreateDeviceObjects(); diff --git a/extern/imgui_patched/backends/imgui_impl_android.cpp b/extern/imgui_patched/backends/imgui_impl_android.cpp index bb8de811..48828ec2 100644 --- a/extern/imgui_patched/backends/imgui_impl_android.cpp +++ b/extern/imgui_patched/backends/imgui_impl_android.cpp @@ -3,6 +3,7 @@ // Implemented features: // [X] Platform: Keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(ImGuiKey_Space). [Legacy AKEYCODE_* values will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set] +// [X] Platform: Mouse support. Can discriminate Mouse/TouchScreen/Pen. // Missing features: // [ ] Platform: Clipboard support. // [ ] Platform: Gamepad support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'. @@ -19,7 +20,8 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) -// 2022-01-26: Inputs: replaced short-lived io.AddKeyModsEvent() (added two weeks ago)with io.AddKeyEvent() using ImGuiKey_ModXXX flags. Sorry for the confusion. +// 2022-09-26: Inputs: Renamed ImGuiKey_ModXXX introduced in 1.87 to ImGuiMod_XXX (old names still supported). +// 2022-01-26: Inputs: replaced short-lived io.AddKeyModsEvent() (added two weeks ago) with io.AddKeyEvent() using ImGuiKey_ModXXX flags. Sorry for the confusion. // 2022-01-17: Inputs: calling new io.AddMousePosEvent(), io.AddMouseButtonEvent(), io.AddMouseWheelEvent() API (1.87+). // 2022-01-10: Inputs: calling new io.AddKeyEvent(), io.AddKeyModsEvent() + io.SetKeyEventNativeData() API (1.87+). Support for full ImGuiKey range. // 2021-03-04: Initial version. @@ -163,10 +165,10 @@ int32_t ImGui_ImplAndroid_HandleInputEvent(AInputEvent* input_event) int32_t event_action = AKeyEvent_getAction(input_event); int32_t event_meta_state = AKeyEvent_getMetaState(input_event); - io.AddKeyEvent(ImGuiKey_ModCtrl, (event_meta_state & AMETA_CTRL_ON) != 0); - io.AddKeyEvent(ImGuiKey_ModShift, (event_meta_state & AMETA_SHIFT_ON) != 0); - io.AddKeyEvent(ImGuiKey_ModAlt, (event_meta_state & AMETA_ALT_ON) != 0); - io.AddKeyEvent(ImGuiKey_ModSuper, (event_meta_state & AMETA_META_ON) != 0); + io.AddKeyEvent(ImGuiMod_Ctrl, (event_meta_state & AMETA_CTRL_ON) != 0); + io.AddKeyEvent(ImGuiMod_Shift, (event_meta_state & AMETA_SHIFT_ON) != 0); + io.AddKeyEvent(ImGuiMod_Alt, (event_meta_state & AMETA_ALT_ON) != 0); + io.AddKeyEvent(ImGuiMod_Super, (event_meta_state & AMETA_META_ON) != 0); switch (event_action) { @@ -195,6 +197,22 @@ int32_t ImGui_ImplAndroid_HandleInputEvent(AInputEvent* input_event) int32_t event_action = AMotionEvent_getAction(input_event); int32_t event_pointer_index = (event_action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT; event_action &= AMOTION_EVENT_ACTION_MASK; + + switch (AMotionEvent_getToolType(input_event, event_pointer_index)) + { + case AMOTION_EVENT_TOOL_TYPE_MOUSE: + io.AddMouseSourceEvent(ImGuiMouseSource_Mouse); + break; + case AMOTION_EVENT_TOOL_TYPE_STYLUS: + case AMOTION_EVENT_TOOL_TYPE_ERASER: + io.AddMouseSourceEvent(ImGuiMouseSource_Pen); + break; + case AMOTION_EVENT_TOOL_TYPE_FINGER: + default: + io.AddMouseSourceEvent(ImGuiMouseSource_TouchScreen); + break; + } + switch (event_action) { case AMOTION_EVENT_ACTION_DOWN: @@ -251,6 +269,8 @@ bool ImGui_ImplAndroid_Init(ANativeWindow* window) void ImGui_ImplAndroid_Shutdown() { + ImGuiIO& io = ImGui::GetIO(); + io.BackendPlatformName = nullptr; } void ImGui_ImplAndroid_NewFrame() diff --git a/extern/imgui_patched/backends/imgui_impl_android.h b/extern/imgui_patched/backends/imgui_impl_android.h index 8bfa1860..eb97c4c8 100644 --- a/extern/imgui_patched/backends/imgui_impl_android.h +++ b/extern/imgui_patched/backends/imgui_impl_android.h @@ -3,6 +3,7 @@ // Implemented features: // [X] Platform: Keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(ImGuiKey_Space). [Legacy AKEYCODE_* values will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set] +// [X] Platform: Mouse support. Can discriminate Mouse/TouchScreen/Pen. // Missing features: // [ ] Platform: Clipboard support. // [ ] Platform: Gamepad support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'. diff --git a/extern/imgui_patched/backends/imgui_impl_dx10.cpp b/extern/imgui_patched/backends/imgui_impl_dx10.cpp index bd8e32a6..05b106cf 100644 --- a/extern/imgui_patched/backends/imgui_impl_dx10.cpp +++ b/extern/imgui_patched/backends/imgui_impl_dx10.cpp @@ -3,8 +3,8 @@ // Implemented features: // [X] Renderer: User texture binding. Use 'ID3D10ShaderResourceView*' as ImTextureID. Read the FAQ about ImTextureID! -// [X] Renderer: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'. // [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices. +// [X] Renderer: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'. // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. @@ -13,7 +13,8 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) -// 2022-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface. +// 2023-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface. +// 2022-10-11: Using 'nullptr' instead of 'NULL' as per our switch to C++11. // 2021-06-29: Reorganized backend to pull data from a single structure to facilitate usage with multiple-contexts (all g_XXXX access changed to bd->XXXX). // 2021-05-19: DirectX10: Replaced direct access to ImDrawCmd::TextureId with a call to ImDrawCmd::GetTexID(). (will become a requirement) // 2021-02-18: DirectX10: Change blending equation to preserve alpha in output buffer. @@ -64,7 +65,7 @@ struct ImGui_ImplDX10_Data ImGui_ImplDX10_Data() { memset((void*)this, 0, sizeof(*this)); VertexBufferSize = 5000; IndexBufferSize = 10000; } }; -struct VERTEX_CONSTANT_BUFFER +struct VERTEX_CONSTANT_BUFFER_DX10 { float mvp[4][4]; }; @@ -73,7 +74,7 @@ struct VERTEX_CONSTANT_BUFFER // It is STRONGLY preferred that you use docking branch with multi-viewports (== single Dear ImGui context + multiple windows) instead of multiple Dear ImGui contexts. static ImGui_ImplDX10_Data* ImGui_ImplDX10_GetBackendData() { - return ImGui::GetCurrentContext() ? (ImGui_ImplDX10_Data*)ImGui::GetIO().BackendRendererUserData : NULL; + return ImGui::GetCurrentContext() ? (ImGui_ImplDX10_Data*)ImGui::GetIO().BackendRendererUserData : nullptr; } // Forward Declarations @@ -106,7 +107,7 @@ static void ImGui_ImplDX10_SetupRenderState(ImDrawData* draw_data, ID3D10Device* ctx->VSSetConstantBuffers(0, 1, &bd->pVertexConstantBuffer); ctx->PSSetShader(bd->pPixelShader); ctx->PSSetSamplers(0, 1, &bd->pFontSampler); - ctx->GSSetShader(NULL); + ctx->GSSetShader(nullptr); // Setup render state const float blend_factor[4] = { 0.f, 0.f, 0.f, 0.f }; @@ -128,7 +129,7 @@ void ImGui_ImplDX10_RenderDrawData(ImDrawData* draw_data) // Create and grow vertex/index buffers if needed if (!bd->pVB || bd->VertexBufferSize < draw_data->TotalVtxCount) { - if (bd->pVB) { bd->pVB->Release(); bd->pVB = NULL; } + if (bd->pVB) { bd->pVB->Release(); bd->pVB = nullptr; } bd->VertexBufferSize = draw_data->TotalVtxCount + 5000; D3D10_BUFFER_DESC desc; memset(&desc, 0, sizeof(D3D10_BUFFER_DESC)); @@ -137,13 +138,13 @@ void ImGui_ImplDX10_RenderDrawData(ImDrawData* draw_data) desc.BindFlags = D3D10_BIND_VERTEX_BUFFER; desc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE; desc.MiscFlags = 0; - if (ctx->CreateBuffer(&desc, NULL, &bd->pVB) < 0) + if (ctx->CreateBuffer(&desc, nullptr, &bd->pVB) < 0) return; } if (!bd->pIB || bd->IndexBufferSize < draw_data->TotalIdxCount) { - if (bd->pIB) { bd->pIB->Release(); bd->pIB = NULL; } + if (bd->pIB) { bd->pIB->Release(); bd->pIB = nullptr; } bd->IndexBufferSize = draw_data->TotalIdxCount + 10000; D3D10_BUFFER_DESC desc; memset(&desc, 0, sizeof(D3D10_BUFFER_DESC)); @@ -151,13 +152,13 @@ void ImGui_ImplDX10_RenderDrawData(ImDrawData* draw_data) desc.ByteWidth = bd->IndexBufferSize * sizeof(ImDrawIdx); desc.BindFlags = D3D10_BIND_INDEX_BUFFER; desc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE; - if (ctx->CreateBuffer(&desc, NULL, &bd->pIB) < 0) + if (ctx->CreateBuffer(&desc, nullptr, &bd->pIB) < 0) return; } // Copy and convert all vertices into a single contiguous buffer - ImDrawVert* vtx_dst = NULL; - ImDrawIdx* idx_dst = NULL; + ImDrawVert* vtx_dst = nullptr; + ImDrawIdx* idx_dst = nullptr; bd->pVB->Map(D3D10_MAP_WRITE_DISCARD, 0, (void**)&vtx_dst); bd->pIB->Map(D3D10_MAP_WRITE_DISCARD, 0, (void**)&idx_dst); for (int n = 0; n < draw_data->CmdListsCount; n++) @@ -177,7 +178,7 @@ void ImGui_ImplDX10_RenderDrawData(ImDrawData* draw_data) void* mapped_resource; if (bd->pVertexConstantBuffer->Map(D3D10_MAP_WRITE_DISCARD, 0, &mapped_resource) != S_OK) return; - VERTEX_CONSTANT_BUFFER* constant_buffer = (VERTEX_CONSTANT_BUFFER*)mapped_resource; + VERTEX_CONSTANT_BUFFER_DX10* constant_buffer = (VERTEX_CONSTANT_BUFFER_DX10*)mapped_resource; float L = draw_data->DisplayPos.x; float R = draw_data->DisplayPos.x + draw_data->DisplaySize.x; float T = draw_data->DisplayPos.y; @@ -320,13 +321,13 @@ static void ImGui_ImplDX10_CreateFontsTexture() desc.BindFlags = D3D10_BIND_SHADER_RESOURCE; desc.CPUAccessFlags = 0; - ID3D10Texture2D* pTexture = NULL; + ID3D10Texture2D* pTexture = nullptr; D3D10_SUBRESOURCE_DATA subResource; subResource.pSysMem = pixels; subResource.SysMemPitch = desc.Width * 4; subResource.SysMemSlicePitch = 0; bd->pd3dDevice->CreateTexture2D(&desc, &subResource, &pTexture); - IM_ASSERT(pTexture != NULL); + IM_ASSERT(pTexture != nullptr); // Create texture view D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc; @@ -404,7 +405,7 @@ bool ImGui_ImplDX10_CreateDeviceObjects() }"; ID3DBlob* vertexShaderBlob; - if (FAILED(D3DCompile(vertexShader, strlen(vertexShader), NULL, NULL, NULL, "main", "vs_4_0", 0, 0, &vertexShaderBlob, NULL))) + if (FAILED(D3DCompile(vertexShader, strlen(vertexShader), nullptr, nullptr, nullptr, "main", "vs_4_0", 0, 0, &vertexShaderBlob, nullptr))) return false; // NB: Pass ID3DBlob* pErrorBlob to D3DCompile() to get error showing in (const char*)pErrorBlob->GetBufferPointer(). Make sure to Release() the blob! if (bd->pd3dDevice->CreateVertexShader(vertexShaderBlob->GetBufferPointer(), vertexShaderBlob->GetBufferSize(), &bd->pVertexShader) != S_OK) { @@ -429,12 +430,12 @@ bool ImGui_ImplDX10_CreateDeviceObjects() // Create the constant buffer { D3D10_BUFFER_DESC desc; - desc.ByteWidth = sizeof(VERTEX_CONSTANT_BUFFER); + desc.ByteWidth = sizeof(VERTEX_CONSTANT_BUFFER_DX10); desc.Usage = D3D10_USAGE_DYNAMIC; desc.BindFlags = D3D10_BIND_CONSTANT_BUFFER; desc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE; desc.MiscFlags = 0; - bd->pd3dDevice->CreateBuffer(&desc, NULL, &bd->pVertexConstantBuffer); + bd->pd3dDevice->CreateBuffer(&desc, nullptr, &bd->pVertexConstantBuffer); } } @@ -457,7 +458,7 @@ bool ImGui_ImplDX10_CreateDeviceObjects() }"; ID3DBlob* pixelShaderBlob; - if (FAILED(D3DCompile(pixelShader, strlen(pixelShader), NULL, NULL, NULL, "main", "ps_4_0", 0, 0, &pixelShaderBlob, NULL))) + if (FAILED(D3DCompile(pixelShader, strlen(pixelShader), nullptr, nullptr, nullptr, "main", "ps_4_0", 0, 0, &pixelShaderBlob, nullptr))) return false; // NB: Pass ID3DBlob* pErrorBlob to D3DCompile() to get error showing in (const char*)pErrorBlob->GetBufferPointer(). Make sure to Release() the blob! if (bd->pd3dDevice->CreatePixelShader(pixelShaderBlob->GetBufferPointer(), pixelShaderBlob->GetBufferSize(), &bd->pPixelShader) != S_OK) { @@ -519,23 +520,23 @@ void ImGui_ImplDX10_InvalidateDeviceObjects() if (!bd->pd3dDevice) return; - if (bd->pFontSampler) { bd->pFontSampler->Release(); bd->pFontSampler = NULL; } - if (bd->pFontTextureView) { bd->pFontTextureView->Release(); bd->pFontTextureView = NULL; ImGui::GetIO().Fonts->SetTexID(NULL); } // We copied bd->pFontTextureView to io.Fonts->TexID so let's clear that as well. - if (bd->pIB) { bd->pIB->Release(); bd->pIB = NULL; } - if (bd->pVB) { bd->pVB->Release(); bd->pVB = NULL; } - if (bd->pBlendState) { bd->pBlendState->Release(); bd->pBlendState = NULL; } - if (bd->pDepthStencilState) { bd->pDepthStencilState->Release(); bd->pDepthStencilState = NULL; } - if (bd->pRasterizerState) { bd->pRasterizerState->Release(); bd->pRasterizerState = NULL; } - if (bd->pPixelShader) { bd->pPixelShader->Release(); bd->pPixelShader = NULL; } - if (bd->pVertexConstantBuffer) { bd->pVertexConstantBuffer->Release(); bd->pVertexConstantBuffer = NULL; } - if (bd->pInputLayout) { bd->pInputLayout->Release(); bd->pInputLayout = NULL; } - if (bd->pVertexShader) { bd->pVertexShader->Release(); bd->pVertexShader = NULL; } + if (bd->pFontSampler) { bd->pFontSampler->Release(); bd->pFontSampler = nullptr; } + if (bd->pFontTextureView) { bd->pFontTextureView->Release(); bd->pFontTextureView = nullptr; ImGui::GetIO().Fonts->SetTexID(0); } // We copied bd->pFontTextureView to io.Fonts->TexID so let's clear that as well. + if (bd->pIB) { bd->pIB->Release(); bd->pIB = nullptr; } + if (bd->pVB) { bd->pVB->Release(); bd->pVB = nullptr; } + if (bd->pBlendState) { bd->pBlendState->Release(); bd->pBlendState = nullptr; } + if (bd->pDepthStencilState) { bd->pDepthStencilState->Release(); bd->pDepthStencilState = nullptr; } + if (bd->pRasterizerState) { bd->pRasterizerState->Release(); bd->pRasterizerState = nullptr; } + if (bd->pPixelShader) { bd->pPixelShader->Release(); bd->pPixelShader = nullptr; } + if (bd->pVertexConstantBuffer) { bd->pVertexConstantBuffer->Release(); bd->pVertexConstantBuffer = nullptr; } + if (bd->pInputLayout) { bd->pInputLayout->Release(); bd->pInputLayout = nullptr; } + if (bd->pVertexShader) { bd->pVertexShader->Release(); bd->pVertexShader = nullptr; } } bool ImGui_ImplDX10_Init(ID3D10Device* device) { ImGuiIO& io = ImGui::GetIO(); - IM_ASSERT(io.BackendRendererUserData == NULL && "Already initialized a renderer backend!"); + IM_ASSERT(io.BackendRendererUserData == nullptr && "Already initialized a renderer backend!"); // Setup backend capabilities flags ImGui_ImplDX10_Data* bd = IM_NEW(ImGui_ImplDX10_Data)(); @@ -545,9 +546,9 @@ bool ImGui_ImplDX10_Init(ID3D10Device* device) io.BackendFlags |= ImGuiBackendFlags_RendererHasViewports; // We can create multi-viewports on the Renderer side (optional) // Get factory from device - IDXGIDevice* pDXGIDevice = NULL; - IDXGIAdapter* pDXGIAdapter = NULL; - IDXGIFactory* pFactory = NULL; + IDXGIDevice* pDXGIDevice = nullptr; + IDXGIAdapter* pDXGIAdapter = nullptr; + IDXGIFactory* pFactory = nullptr; if (device->QueryInterface(IID_PPV_ARGS(&pDXGIDevice)) == S_OK) if (pDXGIDevice->GetParent(IID_PPV_ARGS(&pDXGIAdapter)) == S_OK) if (pDXGIAdapter->GetParent(IID_PPV_ARGS(&pFactory)) == S_OK) @@ -567,22 +568,23 @@ bool ImGui_ImplDX10_Init(ID3D10Device* device) void ImGui_ImplDX10_Shutdown() { ImGui_ImplDX10_Data* bd = ImGui_ImplDX10_GetBackendData(); - IM_ASSERT(bd != NULL && "No renderer backend to shutdown, or already shutdown?"); + IM_ASSERT(bd != nullptr && "No renderer backend to shutdown, or already shutdown?"); ImGuiIO& io = ImGui::GetIO(); ImGui_ImplDX10_ShutdownPlatformInterface(); ImGui_ImplDX10_InvalidateDeviceObjects(); if (bd->pFactory) { bd->pFactory->Release(); } if (bd->pd3dDevice) { bd->pd3dDevice->Release(); } - io.BackendRendererName = NULL; - io.BackendRendererUserData = NULL; + io.BackendRendererName = nullptr; + io.BackendRendererUserData = nullptr; + io.BackendFlags &= ~(ImGuiBackendFlags_RendererHasVtxOffset | ImGuiBackendFlags_RendererHasViewports); IM_DELETE(bd); } void ImGui_ImplDX10_NewFrame() { ImGui_ImplDX10_Data* bd = ImGui_ImplDX10_GetBackendData(); - IM_ASSERT(bd != NULL && "Did you call ImGui_ImplDX10_Init()?"); + IM_ASSERT(bd != nullptr && "Did you call ImGui_ImplDX10_Init()?"); if (!bd->pFontSampler) ImGui_ImplDX10_CreateDeviceObjects(); @@ -594,14 +596,14 @@ void ImGui_ImplDX10_NewFrame() // If you are new to dear imgui or creating a new binding for dear imgui, it is recommended that you completely ignore this section first.. //-------------------------------------------------------------------------------------------------------- -// Helper structure we store in the void* RenderUserData field of each ImGuiViewport to easily retrieve our backend data. +// Helper structure we store in the void* RendererUserData field of each ImGuiViewport to easily retrieve our backend data. struct ImGui_ImplDX10_ViewportData { IDXGISwapChain* SwapChain; ID3D10RenderTargetView* RTView; - ImGui_ImplDX10_ViewportData() { SwapChain = NULL; RTView = NULL; } - ~ImGui_ImplDX10_ViewportData() { IM_ASSERT(SwapChain == NULL && RTView == NULL); } + ImGui_ImplDX10_ViewportData() { SwapChain = nullptr; RTView = nullptr; } + ~ImGui_ImplDX10_ViewportData() { IM_ASSERT(SwapChain == nullptr && RTView == nullptr); } }; static void ImGui_ImplDX10_CreateWindow(ImGuiViewport* viewport) @@ -611,7 +613,7 @@ static void ImGui_ImplDX10_CreateWindow(ImGuiViewport* viewport) viewport->RendererUserData = vd; // PlatformHandleRaw should always be a HWND, whereas PlatformHandle might be a higher-level handle (e.g. GLFWWindow*, SDL_Window*). - // Some backends will leave PlatformHandleRaw NULL, in which case we assume PlatformHandle will contain the HWND. + // Some backends will leave PlatformHandleRaw == 0, in which case we assume PlatformHandle will contain the HWND. HWND hwnd = viewport->PlatformHandleRaw ? (HWND)viewport->PlatformHandleRaw : (HWND)viewport->PlatformHandle; IM_ASSERT(hwnd != 0); @@ -630,7 +632,7 @@ static void ImGui_ImplDX10_CreateWindow(ImGuiViewport* viewport) sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; sd.Flags = 0; - IM_ASSERT(vd->SwapChain == NULL && vd->RTView == NULL); + IM_ASSERT(vd->SwapChain == nullptr && vd->RTView == nullptr); bd->pFactory->CreateSwapChain(bd->pd3dDevice, &sd, &vd->SwapChain); // Create the render target @@ -638,25 +640,25 @@ static void ImGui_ImplDX10_CreateWindow(ImGuiViewport* viewport) { ID3D10Texture2D* pBackBuffer; vd->SwapChain->GetBuffer(0, IID_PPV_ARGS(&pBackBuffer)); - bd->pd3dDevice->CreateRenderTargetView(pBackBuffer, NULL, &vd->RTView); + bd->pd3dDevice->CreateRenderTargetView(pBackBuffer, nullptr, &vd->RTView); pBackBuffer->Release(); } } static void ImGui_ImplDX10_DestroyWindow(ImGuiViewport* viewport) { - // The main viewport (owned by the application) will always have RendererUserData == NULL here since we didn't create the data for it. + // The main viewport (owned by the application) will always have RendererUserData == 0 here since we didn't create the data for it. if (ImGui_ImplDX10_ViewportData* vd = (ImGui_ImplDX10_ViewportData*)viewport->RendererUserData) { if (vd->SwapChain) vd->SwapChain->Release(); - vd->SwapChain = NULL; + vd->SwapChain = nullptr; if (vd->RTView) vd->RTView->Release(); - vd->RTView = NULL; + vd->RTView = nullptr; IM_DELETE(vd); } - viewport->RendererUserData = NULL; + viewport->RendererUserData = nullptr; } static void ImGui_ImplDX10_SetWindowSize(ImGuiViewport* viewport, ImVec2 size) @@ -666,15 +668,15 @@ static void ImGui_ImplDX10_SetWindowSize(ImGuiViewport* viewport, ImVec2 size) if (vd->RTView) { vd->RTView->Release(); - vd->RTView = NULL; + vd->RTView = nullptr; } if (vd->SwapChain) { - ID3D10Texture2D* pBackBuffer = NULL; + ID3D10Texture2D* pBackBuffer = nullptr; vd->SwapChain->ResizeBuffers(0, (UINT)size.x, (UINT)size.y, DXGI_FORMAT_UNKNOWN, 0); vd->SwapChain->GetBuffer(0, IID_PPV_ARGS(&pBackBuffer)); - if (pBackBuffer == NULL) { fprintf(stderr, "ImGui_ImplDX10_SetWindowSize() failed creating buffers.\n"); return; } - bd->pd3dDevice->CreateRenderTargetView(pBackBuffer, NULL, &vd->RTView); + if (pBackBuffer == nullptr) { fprintf(stderr, "ImGui_ImplDX10_SetWindowSize() failed creating buffers.\n"); return; } + bd->pd3dDevice->CreateRenderTargetView(pBackBuffer, nullptr, &vd->RTView); pBackBuffer->Release(); } } @@ -684,7 +686,7 @@ static void ImGui_ImplDX10_RenderViewport(ImGuiViewport* viewport, void*) ImGui_ImplDX10_Data* bd = ImGui_ImplDX10_GetBackendData(); ImGui_ImplDX10_ViewportData* vd = (ImGui_ImplDX10_ViewportData*)viewport->RendererUserData; ImVec4 clear_color = ImVec4(0.0f, 0.0f, 0.0f, 1.0f); - bd->pd3dDevice->OMSetRenderTargets(1, &vd->RTView, NULL); + bd->pd3dDevice->OMSetRenderTargets(1, &vd->RTView, nullptr); if (!(viewport->Flags & ImGuiViewportFlags_NoRendererClear)) bd->pd3dDevice->ClearRenderTargetView(vd->RTView, (float*)&clear_color); ImGui_ImplDX10_RenderDrawData(viewport->DrawData); diff --git a/extern/imgui_patched/backends/imgui_impl_dx10.h b/extern/imgui_patched/backends/imgui_impl_dx10.h index 94957d43..c2c0f936 100644 --- a/extern/imgui_patched/backends/imgui_impl_dx10.h +++ b/extern/imgui_patched/backends/imgui_impl_dx10.h @@ -3,10 +3,10 @@ // Implemented features: // [X] Renderer: User texture binding. Use 'ID3D10ShaderResourceView*' as ImTextureID. Read the FAQ about ImTextureID! -// [X] Renderer: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'. // [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices. +// [X] Renderer: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'. -// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. +// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. // If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp. // Read online: https://github.com/ocornut/imgui/tree/master/docs diff --git a/extern/imgui_patched/backends/imgui_impl_dx11.cpp b/extern/imgui_patched/backends/imgui_impl_dx11.cpp index 78b8147e..86276968 100644 --- a/extern/imgui_patched/backends/imgui_impl_dx11.cpp +++ b/extern/imgui_patched/backends/imgui_impl_dx11.cpp @@ -3,8 +3,8 @@ // Implemented features: // [X] Renderer: User texture binding. Use 'ID3D11ShaderResourceView*' as ImTextureID. Read the FAQ about ImTextureID! -// [X] Renderer: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'. // [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices. +// [X] Renderer: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'. // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. @@ -13,7 +13,8 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) -// 2022-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface. +// 2023-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface. +// 2022-10-11: Using 'nullptr' instead of 'NULL' as per our switch to C++11. // 2021-06-29: Reorganized backend to pull data from a single structure to facilitate usage with multiple-contexts (all g_XXXX access changed to bd->XXXX). // 2021-05-19: DirectX11: Replaced direct access to ImDrawCmd::TextureId with a call to ImDrawCmd::GetTexID(). (will become a requirement) // 2021-02-18: DirectX11: Change blending equation to preserve alpha in output buffer. @@ -31,16 +32,16 @@ // 2018-02-06: Misc: Removed call to ImGui::Shutdown() which is not available from 1.60 WIP, user needs to call CreateContext/DestroyContext themselves. // 2016-05-07: DirectX11: Disabling depth-write. +// DISCLAIMER: modified with d3dcompiler patch (see https://github.com/ocornut/imgui/pull/638). + #include "imgui.h" #include "imgui_impl_dx11.h" // DirectX #include #include -#include -#ifdef _MSC_VER -#pragma comment(lib, "d3dcompiler") // Automatically link with d3dcompiler.lib as we are using D3DCompile() below. -#endif + +typedef HRESULT (__stdcall *D3DCompile_t)(LPCVOID, SIZE_T, LPCSTR, D3D_SHADER_MACRO*, ID3DInclude*, LPCSTR, LPCSTR, UINT, UINT, ID3DBlob**, ID3DBlob*); // DirectX11 data struct ImGui_ImplDX11_Data @@ -65,7 +66,7 @@ struct ImGui_ImplDX11_Data ImGui_ImplDX11_Data() { memset((void*)this, 0, sizeof(*this)); VertexBufferSize = 5000; IndexBufferSize = 10000; } }; -struct VERTEX_CONSTANT_BUFFER +struct VERTEX_CONSTANT_BUFFER_DX11 { float mvp[4][4]; }; @@ -74,7 +75,7 @@ struct VERTEX_CONSTANT_BUFFER // It is STRONGLY preferred that you use docking branch with multi-viewports (== single Dear ImGui context + multiple windows) instead of multiple Dear ImGui contexts. static ImGui_ImplDX11_Data* ImGui_ImplDX11_GetBackendData() { - return ImGui::GetCurrentContext() ? (ImGui_ImplDX11_Data*)ImGui::GetIO().BackendRendererUserData : NULL; + return ImGui::GetCurrentContext() ? (ImGui_ImplDX11_Data*)ImGui::GetIO().BackendRendererUserData : nullptr; } // Forward Declarations @@ -103,14 +104,14 @@ static void ImGui_ImplDX11_SetupRenderState(ImDrawData* draw_data, ID3D11DeviceC ctx->IASetVertexBuffers(0, 1, &bd->pVB, &stride, &offset); ctx->IASetIndexBuffer(bd->pIB, sizeof(ImDrawIdx) == 2 ? DXGI_FORMAT_R16_UINT : DXGI_FORMAT_R32_UINT, 0); ctx->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); - ctx->VSSetShader(bd->pVertexShader, NULL, 0); + ctx->VSSetShader(bd->pVertexShader, nullptr, 0); ctx->VSSetConstantBuffers(0, 1, &bd->pVertexConstantBuffer); - ctx->PSSetShader(bd->pPixelShader, NULL, 0); + ctx->PSSetShader(bd->pPixelShader, nullptr, 0); ctx->PSSetSamplers(0, 1, &bd->pFontSampler); - ctx->GSSetShader(NULL, NULL, 0); - ctx->HSSetShader(NULL, NULL, 0); // In theory we should backup and restore this as well.. very infrequently used.. - ctx->DSSetShader(NULL, NULL, 0); // In theory we should backup and restore this as well.. very infrequently used.. - ctx->CSSetShader(NULL, NULL, 0); // In theory we should backup and restore this as well.. very infrequently used.. + ctx->GSSetShader(nullptr, nullptr, 0); + ctx->HSSetShader(nullptr, nullptr, 0); // In theory we should backup and restore this as well.. very infrequently used.. + ctx->DSSetShader(nullptr, nullptr, 0); // In theory we should backup and restore this as well.. very infrequently used.. + ctx->CSSetShader(nullptr, nullptr, 0); // In theory we should backup and restore this as well.. very infrequently used.. // Setup blend state const float blend_factor[4] = { 0.f, 0.f, 0.f, 0.f }; @@ -132,7 +133,7 @@ void ImGui_ImplDX11_RenderDrawData(ImDrawData* draw_data) // Create and grow vertex/index buffers if needed if (!bd->pVB || bd->VertexBufferSize < draw_data->TotalVtxCount) { - if (bd->pVB) { bd->pVB->Release(); bd->pVB = NULL; } + if (bd->pVB) { bd->pVB->Release(); bd->pVB = nullptr; } bd->VertexBufferSize = draw_data->TotalVtxCount + 5000; D3D11_BUFFER_DESC desc; memset(&desc, 0, sizeof(D3D11_BUFFER_DESC)); @@ -141,12 +142,12 @@ void ImGui_ImplDX11_RenderDrawData(ImDrawData* draw_data) desc.BindFlags = D3D11_BIND_VERTEX_BUFFER; desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; desc.MiscFlags = 0; - if (bd->pd3dDevice->CreateBuffer(&desc, NULL, &bd->pVB) < 0) + if (bd->pd3dDevice->CreateBuffer(&desc, nullptr, &bd->pVB) < 0) return; } if (!bd->pIB || bd->IndexBufferSize < draw_data->TotalIdxCount) { - if (bd->pIB) { bd->pIB->Release(); bd->pIB = NULL; } + if (bd->pIB) { bd->pIB->Release(); bd->pIB = nullptr; } bd->IndexBufferSize = draw_data->TotalIdxCount + 10000; D3D11_BUFFER_DESC desc; memset(&desc, 0, sizeof(D3D11_BUFFER_DESC)); @@ -154,7 +155,7 @@ void ImGui_ImplDX11_RenderDrawData(ImDrawData* draw_data) desc.ByteWidth = bd->IndexBufferSize * sizeof(ImDrawIdx); desc.BindFlags = D3D11_BIND_INDEX_BUFFER; desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; - if (bd->pd3dDevice->CreateBuffer(&desc, NULL, &bd->pIB) < 0) + if (bd->pd3dDevice->CreateBuffer(&desc, nullptr, &bd->pIB) < 0) return; } @@ -183,7 +184,7 @@ void ImGui_ImplDX11_RenderDrawData(ImDrawData* draw_data) D3D11_MAPPED_SUBRESOURCE mapped_resource; if (ctx->Map(bd->pVertexConstantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_resource) != S_OK) return; - VERTEX_CONSTANT_BUFFER* constant_buffer = (VERTEX_CONSTANT_BUFFER*)mapped_resource.pData; + VERTEX_CONSTANT_BUFFER_DX11* constant_buffer = (VERTEX_CONSTANT_BUFFER_DX11*)mapped_resource.pData; float L = draw_data->DisplayPos.x; float R = draw_data->DisplayPos.x + draw_data->DisplaySize.x; float T = draw_data->DisplayPos.y; @@ -258,7 +259,7 @@ void ImGui_ImplDX11_RenderDrawData(ImDrawData* draw_data) for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++) { const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i]; - if (pcmd->UserCallback != NULL) + if (pcmd->UserCallback != nullptr) { // User callback, registered via ImDrawList::AddCallback() // (ImDrawCallback_ResetRenderState is a special callback value used by the user to request the renderer to reset render state.) @@ -332,13 +333,13 @@ static void ImGui_ImplDX11_CreateFontsTexture() desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; desc.CPUAccessFlags = 0; - ID3D11Texture2D* pTexture = NULL; + ID3D11Texture2D* pTexture = nullptr; D3D11_SUBRESOURCE_DATA subResource; subResource.pSysMem = pixels; subResource.SysMemPitch = desc.Width * 4; subResource.SysMemSlicePitch = 0; bd->pd3dDevice->CreateTexture2D(&desc, &subResource, &pTexture); - IM_ASSERT(pTexture != NULL); + IM_ASSERT(pTexture != nullptr); // Create texture view D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc; @@ -379,11 +380,22 @@ bool ImGui_ImplDX11_CreateDeviceObjects() if (bd->pFontSampler) ImGui_ImplDX11_InvalidateDeviceObjects(); - // By using D3DCompile() from / d3dcompiler.lib, we introduce a dependency to a given version of d3dcompiler_XX.dll (see D3DCOMPILER_DLL_A) - // If you would like to use this DX11 sample code but remove this dependency you can: - // 1) compile once, save the compiled shader blobs into a file or source code and pass them to CreateVertexShader()/CreatePixelShader() [preferred solution] - // 2) use code to detect any version of the DLL and grab a pointer to D3DCompile from the DLL. // See https://github.com/ocornut/imgui/pull/638 for sources and details. + // Detect which d3dcompiler_XX.dll is present in the system and grab a pointer to D3DCompile. + // Without this, you must link d3dcompiler.lib with the project. + D3DCompile_t D3DCompile = NULL; + { + char dllBuffer[20]; + for (int i = 47; i > 30 && !D3DCompile; i--) + { + sprintf(dllBuffer, "d3dcompiler_%d.dll", i); + HMODULE hDll = LoadLibraryA(dllBuffer); + if (hDll) + D3DCompile = (D3DCompile_t)GetProcAddress(hDll, "D3DCompile"); + } + if (!D3DCompile) + return false; + } // Create the vertex shader { @@ -416,9 +428,9 @@ bool ImGui_ImplDX11_CreateDeviceObjects() }"; ID3DBlob* vertexShaderBlob; - if (FAILED(D3DCompile(vertexShader, strlen(vertexShader), NULL, NULL, NULL, "main", "vs_4_0", 0, 0, &vertexShaderBlob, NULL))) + if (FAILED(D3DCompile(vertexShader, strlen(vertexShader), nullptr, nullptr, nullptr, "main", "vs_4_0", 0, 0, &vertexShaderBlob, nullptr))) return false; // NB: Pass ID3DBlob* pErrorBlob to D3DCompile() to get error showing in (const char*)pErrorBlob->GetBufferPointer(). Make sure to Release() the blob! - if (bd->pd3dDevice->CreateVertexShader(vertexShaderBlob->GetBufferPointer(), vertexShaderBlob->GetBufferSize(), NULL, &bd->pVertexShader) != S_OK) + if (bd->pd3dDevice->CreateVertexShader(vertexShaderBlob->GetBufferPointer(), vertexShaderBlob->GetBufferSize(), nullptr, &bd->pVertexShader) != S_OK) { vertexShaderBlob->Release(); return false; @@ -441,12 +453,12 @@ bool ImGui_ImplDX11_CreateDeviceObjects() // Create the constant buffer { D3D11_BUFFER_DESC desc; - desc.ByteWidth = sizeof(VERTEX_CONSTANT_BUFFER); + desc.ByteWidth = sizeof(VERTEX_CONSTANT_BUFFER_DX11); desc.Usage = D3D11_USAGE_DYNAMIC; desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; desc.MiscFlags = 0; - bd->pd3dDevice->CreateBuffer(&desc, NULL, &bd->pVertexConstantBuffer); + bd->pd3dDevice->CreateBuffer(&desc, nullptr, &bd->pVertexConstantBuffer); } } @@ -469,9 +481,9 @@ bool ImGui_ImplDX11_CreateDeviceObjects() }"; ID3DBlob* pixelShaderBlob; - if (FAILED(D3DCompile(pixelShader, strlen(pixelShader), NULL, NULL, NULL, "main", "ps_4_0", 0, 0, &pixelShaderBlob, NULL))) + if (FAILED(D3DCompile(pixelShader, strlen(pixelShader), nullptr, nullptr, nullptr, "main", "ps_4_0", 0, 0, &pixelShaderBlob, nullptr))) return false; // NB: Pass ID3DBlob* pErrorBlob to D3DCompile() to get error showing in (const char*)pErrorBlob->GetBufferPointer(). Make sure to Release() the blob! - if (bd->pd3dDevice->CreatePixelShader(pixelShaderBlob->GetBufferPointer(), pixelShaderBlob->GetBufferSize(), NULL, &bd->pPixelShader) != S_OK) + if (bd->pd3dDevice->CreatePixelShader(pixelShaderBlob->GetBufferPointer(), pixelShaderBlob->GetBufferSize(), nullptr, &bd->pPixelShader) != S_OK) { pixelShaderBlob->Release(); return false; @@ -531,23 +543,23 @@ void ImGui_ImplDX11_InvalidateDeviceObjects() if (!bd->pd3dDevice) return; - if (bd->pFontSampler) { bd->pFontSampler->Release(); bd->pFontSampler = NULL; } - if (bd->pFontTextureView) { bd->pFontTextureView->Release(); bd->pFontTextureView = NULL; ImGui::GetIO().Fonts->SetTexID(NULL); } // We copied data->pFontTextureView to io.Fonts->TexID so let's clear that as well. - if (bd->pIB) { bd->pIB->Release(); bd->pIB = NULL; } - if (bd->pVB) { bd->pVB->Release(); bd->pVB = NULL; } - if (bd->pBlendState) { bd->pBlendState->Release(); bd->pBlendState = NULL; } - if (bd->pDepthStencilState) { bd->pDepthStencilState->Release(); bd->pDepthStencilState = NULL; } - if (bd->pRasterizerState) { bd->pRasterizerState->Release(); bd->pRasterizerState = NULL; } - if (bd->pPixelShader) { bd->pPixelShader->Release(); bd->pPixelShader = NULL; } - if (bd->pVertexConstantBuffer) { bd->pVertexConstantBuffer->Release(); bd->pVertexConstantBuffer = NULL; } - if (bd->pInputLayout) { bd->pInputLayout->Release(); bd->pInputLayout = NULL; } - if (bd->pVertexShader) { bd->pVertexShader->Release(); bd->pVertexShader = NULL; } + if (bd->pFontSampler) { bd->pFontSampler->Release(); bd->pFontSampler = nullptr; } + if (bd->pFontTextureView) { bd->pFontTextureView->Release(); bd->pFontTextureView = nullptr; ImGui::GetIO().Fonts->SetTexID(0); } // We copied data->pFontTextureView to io.Fonts->TexID so let's clear that as well. + if (bd->pIB) { bd->pIB->Release(); bd->pIB = nullptr; } + if (bd->pVB) { bd->pVB->Release(); bd->pVB = nullptr; } + if (bd->pBlendState) { bd->pBlendState->Release(); bd->pBlendState = nullptr; } + if (bd->pDepthStencilState) { bd->pDepthStencilState->Release(); bd->pDepthStencilState = nullptr; } + if (bd->pRasterizerState) { bd->pRasterizerState->Release(); bd->pRasterizerState = nullptr; } + if (bd->pPixelShader) { bd->pPixelShader->Release(); bd->pPixelShader = nullptr; } + if (bd->pVertexConstantBuffer) { bd->pVertexConstantBuffer->Release(); bd->pVertexConstantBuffer = nullptr; } + if (bd->pInputLayout) { bd->pInputLayout->Release(); bd->pInputLayout = nullptr; } + if (bd->pVertexShader) { bd->pVertexShader->Release(); bd->pVertexShader = nullptr; } } bool ImGui_ImplDX11_Init(ID3D11Device* device, ID3D11DeviceContext* device_context) { ImGuiIO& io = ImGui::GetIO(); - IM_ASSERT(io.BackendRendererUserData == NULL && "Already initialized a renderer backend!"); + IM_ASSERT(io.BackendRendererUserData == nullptr && "Already initialized a renderer backend!"); // Setup backend capabilities flags ImGui_ImplDX11_Data* bd = IM_NEW(ImGui_ImplDX11_Data)(); @@ -557,9 +569,9 @@ bool ImGui_ImplDX11_Init(ID3D11Device* device, ID3D11DeviceContext* device_co io.BackendFlags |= ImGuiBackendFlags_RendererHasViewports; // We can create multi-viewports on the Renderer side (optional) // Get factory from device - IDXGIDevice* pDXGIDevice = NULL; - IDXGIAdapter* pDXGIAdapter = NULL; - IDXGIFactory* pFactory = NULL; + IDXGIDevice* pDXGIDevice = nullptr; + IDXGIAdapter* pDXGIAdapter = nullptr; + IDXGIFactory* pFactory = nullptr; if (device->QueryInterface(IID_PPV_ARGS(&pDXGIDevice)) == S_OK) if (pDXGIDevice->GetParent(IID_PPV_ARGS(&pDXGIAdapter)) == S_OK) @@ -583,7 +595,7 @@ bool ImGui_ImplDX11_Init(ID3D11Device* device, ID3D11DeviceContext* device_co void ImGui_ImplDX11_Shutdown() { ImGui_ImplDX11_Data* bd = ImGui_ImplDX11_GetBackendData(); - IM_ASSERT(bd != NULL && "No renderer backend to shutdown, or already shutdown?"); + IM_ASSERT(bd != nullptr && "No renderer backend to shutdown, or already shutdown?"); ImGuiIO& io = ImGui::GetIO(); ImGui_ImplDX11_ShutdownPlatformInterface(); @@ -591,15 +603,16 @@ void ImGui_ImplDX11_Shutdown() if (bd->pFactory) { bd->pFactory->Release(); } if (bd->pd3dDevice) { bd->pd3dDevice->Release(); } if (bd->pd3dDeviceContext) { bd->pd3dDeviceContext->Release(); } - io.BackendRendererName = NULL; - io.BackendRendererUserData = NULL; + io.BackendRendererName = nullptr; + io.BackendRendererUserData = nullptr; + io.BackendFlags &= ~(ImGuiBackendFlags_RendererHasVtxOffset | ImGuiBackendFlags_RendererHasViewports); IM_DELETE(bd); } void ImGui_ImplDX11_NewFrame() { ImGui_ImplDX11_Data* bd = ImGui_ImplDX11_GetBackendData(); - IM_ASSERT(bd != NULL && "Did you call ImGui_ImplDX11_Init()?"); + IM_ASSERT(bd != nullptr && "Did you call ImGui_ImplDX11_Init()?"); if (!bd->pFontSampler) ImGui_ImplDX11_CreateDeviceObjects(); @@ -611,14 +624,14 @@ void ImGui_ImplDX11_NewFrame() // If you are new to dear imgui or creating a new binding for dear imgui, it is recommended that you completely ignore this section first.. //-------------------------------------------------------------------------------------------------------- -// Helper structure we store in the void* RenderUserData field of each ImGuiViewport to easily retrieve our backend data. +// Helper structure we store in the void* RendererUserData field of each ImGuiViewport to easily retrieve our backend data. struct ImGui_ImplDX11_ViewportData { IDXGISwapChain* SwapChain; ID3D11RenderTargetView* RTView; - ImGui_ImplDX11_ViewportData() { SwapChain = NULL; RTView = NULL; } - ~ImGui_ImplDX11_ViewportData() { IM_ASSERT(SwapChain == NULL && RTView == NULL); } + ImGui_ImplDX11_ViewportData() { SwapChain = nullptr; RTView = nullptr; } + ~ImGui_ImplDX11_ViewportData() { IM_ASSERT(SwapChain == nullptr && RTView == nullptr); } }; static void ImGui_ImplDX11_CreateWindow(ImGuiViewport* viewport) @@ -628,7 +641,7 @@ static void ImGui_ImplDX11_CreateWindow(ImGuiViewport* viewport) viewport->RendererUserData = vd; // PlatformHandleRaw should always be a HWND, whereas PlatformHandle might be a higher-level handle (e.g. GLFWWindow*, SDL_Window*). - // Some backend will leave PlatformHandleRaw NULL, in which case we assume PlatformHandle will contain the HWND. + // Some backends will leave PlatformHandleRaw == 0, in which case we assume PlatformHandle will contain the HWND. HWND hwnd = viewport->PlatformHandleRaw ? (HWND)viewport->PlatformHandleRaw : (HWND)viewport->PlatformHandle; IM_ASSERT(hwnd != 0); @@ -647,7 +660,7 @@ static void ImGui_ImplDX11_CreateWindow(ImGuiViewport* viewport) sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; sd.Flags = 0; - IM_ASSERT(vd->SwapChain == NULL && vd->RTView == NULL); + IM_ASSERT(vd->SwapChain == nullptr && vd->RTView == nullptr); bd->pFactory->CreateSwapChain(bd->pd3dDevice, &sd, &vd->SwapChain); // Create the render target @@ -655,25 +668,25 @@ static void ImGui_ImplDX11_CreateWindow(ImGuiViewport* viewport) { ID3D11Texture2D* pBackBuffer; vd->SwapChain->GetBuffer(0, IID_PPV_ARGS(&pBackBuffer)); - bd->pd3dDevice->CreateRenderTargetView(pBackBuffer, NULL, &vd->RTView); + bd->pd3dDevice->CreateRenderTargetView(pBackBuffer, nullptr, &vd->RTView); pBackBuffer->Release(); } } static void ImGui_ImplDX11_DestroyWindow(ImGuiViewport* viewport) { - // The main viewport (owned by the application) will always have RendererUserData == NULL since we didn't create the data for it. + // The main viewport (owned by the application) will always have RendererUserData == nullptr since we didn't create the data for it. if (ImGui_ImplDX11_ViewportData* vd = (ImGui_ImplDX11_ViewportData*)viewport->RendererUserData) { if (vd->SwapChain) vd->SwapChain->Release(); - vd->SwapChain = NULL; + vd->SwapChain = nullptr; if (vd->RTView) vd->RTView->Release(); - vd->RTView = NULL; + vd->RTView = nullptr; IM_DELETE(vd); } - viewport->RendererUserData = NULL; + viewport->RendererUserData = nullptr; } static void ImGui_ImplDX11_SetWindowSize(ImGuiViewport* viewport, ImVec2 size) @@ -683,15 +696,15 @@ static void ImGui_ImplDX11_SetWindowSize(ImGuiViewport* viewport, ImVec2 size) if (vd->RTView) { vd->RTView->Release(); - vd->RTView = NULL; + vd->RTView = nullptr; } if (vd->SwapChain) { - ID3D11Texture2D* pBackBuffer = NULL; + ID3D11Texture2D* pBackBuffer = nullptr; vd->SwapChain->ResizeBuffers(0, (UINT)size.x, (UINT)size.y, DXGI_FORMAT_UNKNOWN, 0); vd->SwapChain->GetBuffer(0, IID_PPV_ARGS(&pBackBuffer)); - if (pBackBuffer == NULL) { fprintf(stderr, "ImGui_ImplDX11_SetWindowSize() failed creating buffers.\n"); return; } - bd->pd3dDevice->CreateRenderTargetView(pBackBuffer, NULL, &vd->RTView); + if (pBackBuffer == nullptr) { fprintf(stderr, "ImGui_ImplDX11_SetWindowSize() failed creating buffers.\n"); return; } + bd->pd3dDevice->CreateRenderTargetView(pBackBuffer, nullptr, &vd->RTView); pBackBuffer->Release(); } } @@ -701,7 +714,7 @@ static void ImGui_ImplDX11_RenderWindow(ImGuiViewport* viewport, void*) ImGui_ImplDX11_Data* bd = ImGui_ImplDX11_GetBackendData(); ImGui_ImplDX11_ViewportData* vd = (ImGui_ImplDX11_ViewportData*)viewport->RendererUserData; ImVec4 clear_color = ImVec4(0.0f, 0.0f, 0.0f, 1.0f); - bd->pd3dDeviceContext->OMSetRenderTargets(1, &vd->RTView, NULL); + bd->pd3dDeviceContext->OMSetRenderTargets(1, &vd->RTView, nullptr); if (!(viewport->Flags & ImGuiViewportFlags_NoRendererClear)) bd->pd3dDeviceContext->ClearRenderTargetView(vd->RTView, (float*)&clear_color); ImGui_ImplDX11_RenderDrawData(viewport->DrawData); diff --git a/extern/imgui_patched/backends/imgui_impl_dx11.h b/extern/imgui_patched/backends/imgui_impl_dx11.h index 8e2aa685..cee486f5 100644 --- a/extern/imgui_patched/backends/imgui_impl_dx11.h +++ b/extern/imgui_patched/backends/imgui_impl_dx11.h @@ -3,10 +3,10 @@ // Implemented features: // [X] Renderer: User texture binding. Use 'ID3D11ShaderResourceView*' as ImTextureID. Read the FAQ about ImTextureID! -// [X] Renderer: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'. // [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices. +// [X] Renderer: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'. -// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. +// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. // If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp. // Read online: https://github.com/ocornut/imgui/tree/master/docs diff --git a/extern/imgui_patched/backends/imgui_impl_dx12.cpp b/extern/imgui_patched/backends/imgui_impl_dx12.cpp index c7445522..36b12ec7 100644 --- a/extern/imgui_patched/backends/imgui_impl_dx12.cpp +++ b/extern/imgui_patched/backends/imgui_impl_dx12.cpp @@ -3,9 +3,9 @@ // Implemented features: // [X] Renderer: User texture binding. Use 'D3D12_GPU_DESCRIPTOR_HANDLE' as ImTextureID. Read the FAQ about ImTextureID! +// [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices. // [X] Renderer: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'. // FIXME: The transition from removing a viewport and moving the window in an existing hosted viewport tends to flicker. -// [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices. // Important: to compile on 32-bit systems, this backend requires code to be compiled with '#define ImTextureID ImU64'. // This is because we need ImTextureID to carry a 64-bit value and by default ImTextureID is defined as void*. @@ -22,7 +22,8 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) -// 2022-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface. +// 2023-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface. +// 2022-10-11: Using 'nullptr' instead of 'NULL' as per our switch to C++11. // 2021-06-29: Reorganized backend to pull data from a single structure to facilitate usage with multiple-contexts (all g_XXXX access changed to bd->XXXX). // 2021-05-19: DirectX12: Replaced direct access to ImDrawCmd::TextureId with a call to ImDrawCmd::GetTexID(). (will become a requirement) // 2021-02-18: DirectX12: Change blending equation to preserve alpha in output buffer. @@ -71,7 +72,7 @@ struct ImGui_ImplDX12_Data // It is STRONGLY preferred that you use docking branch with multi-viewports (== single Dear ImGui context + multiple windows) instead of multiple Dear ImGui contexts. static ImGui_ImplDX12_Data* ImGui_ImplDX12_GetBackendData() { - return ImGui::GetCurrentContext() ? (ImGui_ImplDX12_Data*)ImGui::GetIO().BackendRendererUserData : NULL; + return ImGui::GetCurrentContext() ? (ImGui_ImplDX12_Data*)ImGui::GetIO().BackendRendererUserData : nullptr; } // Buffers used during the rendering of a frame @@ -113,13 +114,13 @@ struct ImGui_ImplDX12_ViewportData ImGui_ImplDX12_ViewportData(UINT num_frames_in_flight) { - CommandQueue = NULL; - CommandList = NULL; - RtvDescHeap = NULL; - SwapChain = NULL; - Fence = NULL; + CommandQueue = nullptr; + CommandList = nullptr; + RtvDescHeap = nullptr; + SwapChain = nullptr; + Fence = nullptr; FenceSignaledValue = 0; - FenceEvent = NULL; + FenceEvent = nullptr; NumFramesInFlight = num_frames_in_flight; FrameCtx = new ImGui_ImplDX12_FrameContext[NumFramesInFlight]; FrameIndex = UINT_MAX; @@ -127,36 +128,36 @@ struct ImGui_ImplDX12_ViewportData for (UINT i = 0; i < NumFramesInFlight; ++i) { - FrameCtx[i].CommandAllocator = NULL; - FrameCtx[i].RenderTarget = NULL; + FrameCtx[i].CommandAllocator = nullptr; + FrameCtx[i].RenderTarget = nullptr; // Create buffers with a default size (they will later be grown as needed) - FrameRenderBuffers[i].IndexBuffer = NULL; - FrameRenderBuffers[i].VertexBuffer = NULL; + FrameRenderBuffers[i].IndexBuffer = nullptr; + FrameRenderBuffers[i].VertexBuffer = nullptr; FrameRenderBuffers[i].VertexBufferSize = 5000; FrameRenderBuffers[i].IndexBufferSize = 10000; } } ~ImGui_ImplDX12_ViewportData() { - IM_ASSERT(CommandQueue == NULL && CommandList == NULL); - IM_ASSERT(RtvDescHeap == NULL); - IM_ASSERT(SwapChain == NULL); - IM_ASSERT(Fence == NULL); - IM_ASSERT(FenceEvent == NULL); + IM_ASSERT(CommandQueue == nullptr && CommandList == nullptr); + IM_ASSERT(RtvDescHeap == nullptr); + IM_ASSERT(SwapChain == nullptr); + IM_ASSERT(Fence == nullptr); + IM_ASSERT(FenceEvent == nullptr); for (UINT i = 0; i < NumFramesInFlight; ++i) { - IM_ASSERT(FrameCtx[i].CommandAllocator == NULL && FrameCtx[i].RenderTarget == NULL); - IM_ASSERT(FrameRenderBuffers[i].IndexBuffer == NULL && FrameRenderBuffers[i].VertexBuffer == NULL); + IM_ASSERT(FrameCtx[i].CommandAllocator == nullptr && FrameCtx[i].RenderTarget == nullptr); + IM_ASSERT(FrameRenderBuffers[i].IndexBuffer == nullptr && FrameRenderBuffers[i].VertexBuffer == nullptr); } - delete[] FrameCtx; FrameCtx = NULL; - delete[] FrameRenderBuffers; FrameRenderBuffers = NULL; + delete[] FrameCtx; FrameCtx = nullptr; + delete[] FrameRenderBuffers; FrameRenderBuffers = nullptr; } }; -struct VERTEX_CONSTANT_BUFFER +struct VERTEX_CONSTANT_BUFFER_DX12 { float mvp[4][4]; }; @@ -172,7 +173,7 @@ static void ImGui_ImplDX12_SetupRenderState(ImDrawData* draw_data, ID3D12Graphic // Setup orthographic projection matrix into our constant buffer // Our visible imgui space lies from draw_data->DisplayPos (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right). - VERTEX_CONSTANT_BUFFER vertex_constant_buffer; + VERTEX_CONSTANT_BUFFER_DX12 vertex_constant_buffer; { float L = draw_data->DisplayPos.x; float R = draw_data->DisplayPos.x + draw_data->DisplaySize.x; @@ -228,7 +229,7 @@ static inline void SafeRelease(T*& res) { if (res) res->Release(); - res = NULL; + res = nullptr; } // Render function @@ -244,7 +245,7 @@ void ImGui_ImplDX12_RenderDrawData(ImDrawData* draw_data, ID3D12GraphicsCommandL ImGui_ImplDX12_RenderBuffers* fr = &vd->FrameRenderBuffers[vd->FrameIndex % bd->numFramesInFlight]; // Create and grow vertex/index buffers if needed - if (fr->VertexBuffer == NULL || fr->VertexBufferSize < draw_data->TotalVtxCount) + if (fr->VertexBuffer == nullptr || fr->VertexBufferSize < draw_data->TotalVtxCount) { SafeRelease(fr->VertexBuffer); fr->VertexBufferSize = draw_data->TotalVtxCount + 5000; @@ -264,10 +265,10 @@ void ImGui_ImplDX12_RenderDrawData(ImDrawData* draw_data, ID3D12GraphicsCommandL desc.SampleDesc.Count = 1; desc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR; desc.Flags = D3D12_RESOURCE_FLAG_NONE; - if (bd->pd3dDevice->CreateCommittedResource(&props, D3D12_HEAP_FLAG_NONE, &desc, D3D12_RESOURCE_STATE_GENERIC_READ, NULL, IID_PPV_ARGS(&fr->VertexBuffer)) < 0) + if (bd->pd3dDevice->CreateCommittedResource(&props, D3D12_HEAP_FLAG_NONE, &desc, D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, IID_PPV_ARGS(&fr->VertexBuffer)) < 0) return; } - if (fr->IndexBuffer == NULL || fr->IndexBufferSize < draw_data->TotalIdxCount) + if (fr->IndexBuffer == nullptr || fr->IndexBufferSize < draw_data->TotalIdxCount) { SafeRelease(fr->IndexBuffer); fr->IndexBufferSize = draw_data->TotalIdxCount + 10000; @@ -287,7 +288,7 @@ void ImGui_ImplDX12_RenderDrawData(ImDrawData* draw_data, ID3D12GraphicsCommandL desc.SampleDesc.Count = 1; desc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR; desc.Flags = D3D12_RESOURCE_FLAG_NONE; - if (bd->pd3dDevice->CreateCommittedResource(&props, D3D12_HEAP_FLAG_NONE, &desc, D3D12_RESOURCE_STATE_GENERIC_READ, NULL, IID_PPV_ARGS(&fr->IndexBuffer)) < 0) + if (bd->pd3dDevice->CreateCommittedResource(&props, D3D12_HEAP_FLAG_NONE, &desc, D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, IID_PPV_ARGS(&fr->IndexBuffer)) < 0) return; } @@ -326,7 +327,7 @@ void ImGui_ImplDX12_RenderDrawData(ImDrawData* draw_data, ID3D12GraphicsCommandL for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++) { const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i]; - if (pcmd->UserCallback != NULL) + if (pcmd->UserCallback != nullptr) { // User callback, registered via ImDrawList::AddCallback() // (ImDrawCallback_ResetRenderState is a special callback value used by the user to request the renderer to reset render state.) @@ -388,9 +389,9 @@ static void ImGui_ImplDX12_CreateFontsTexture() desc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN; desc.Flags = D3D12_RESOURCE_FLAG_NONE; - ID3D12Resource* pTexture = NULL; + ID3D12Resource* pTexture = nullptr; bd->pd3dDevice->CreateCommittedResource(&props, D3D12_HEAP_FLAG_NONE, &desc, - D3D12_RESOURCE_STATE_COPY_DEST, NULL, IID_PPV_ARGS(&pTexture)); + D3D12_RESOURCE_STATE_COPY_DEST, nullptr, IID_PPV_ARGS(&pTexture)); UINT uploadPitch = (width * 4 + D3D12_TEXTURE_DATA_PITCH_ALIGNMENT - 1u) & ~(D3D12_TEXTURE_DATA_PITCH_ALIGNMENT - 1u); UINT uploadSize = height * uploadPitch; @@ -410,12 +411,12 @@ static void ImGui_ImplDX12_CreateFontsTexture() props.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN; props.MemoryPoolPreference = D3D12_MEMORY_POOL_UNKNOWN; - ID3D12Resource* uploadBuffer = NULL; + ID3D12Resource* uploadBuffer = nullptr; HRESULT hr = bd->pd3dDevice->CreateCommittedResource(&props, D3D12_HEAP_FLAG_NONE, &desc, - D3D12_RESOURCE_STATE_GENERIC_READ, NULL, IID_PPV_ARGS(&uploadBuffer)); + D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, IID_PPV_ARGS(&uploadBuffer)); IM_ASSERT(SUCCEEDED(hr)); - void* mapped = NULL; + void* mapped = nullptr; D3D12_RANGE range = { 0, uploadSize }; hr = uploadBuffer->Map(0, &range, &mapped); IM_ASSERT(SUCCEEDED(hr)); @@ -445,31 +446,31 @@ static void ImGui_ImplDX12_CreateFontsTexture() barrier.Transition.StateBefore = D3D12_RESOURCE_STATE_COPY_DEST; barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE; - ID3D12Fence* fence = NULL; + ID3D12Fence* fence = nullptr; hr = bd->pd3dDevice->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&fence)); IM_ASSERT(SUCCEEDED(hr)); HANDLE event = CreateEvent(0, 0, 0, 0); - IM_ASSERT(event != NULL); + IM_ASSERT(event != nullptr); D3D12_COMMAND_QUEUE_DESC queueDesc = {}; queueDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT; queueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE; queueDesc.NodeMask = 1; - ID3D12CommandQueue* cmdQueue = NULL; + ID3D12CommandQueue* cmdQueue = nullptr; hr = bd->pd3dDevice->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(&cmdQueue)); IM_ASSERT(SUCCEEDED(hr)); - ID3D12CommandAllocator* cmdAlloc = NULL; + ID3D12CommandAllocator* cmdAlloc = nullptr; hr = bd->pd3dDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&cmdAlloc)); IM_ASSERT(SUCCEEDED(hr)); - ID3D12GraphicsCommandList* cmdList = NULL; - hr = bd->pd3dDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, cmdAlloc, NULL, IID_PPV_ARGS(&cmdList)); + ID3D12GraphicsCommandList* cmdList = nullptr; + hr = bd->pd3dDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, cmdAlloc, nullptr, IID_PPV_ARGS(&cmdList)); IM_ASSERT(SUCCEEDED(hr)); - cmdList->CopyTextureRegion(&dstLocation, 0, 0, 0, &srcLocation, NULL); + cmdList->CopyTextureRegion(&dstLocation, 0, 0, 0, &srcLocation, nullptr); cmdList->ResourceBarrier(1, &barrier); hr = cmdList->Close(); @@ -574,7 +575,7 @@ bool ImGui_ImplDX12_CreateDeviceObjects() // Load d3d12.dll and D3D12SerializeRootSignature() function address dynamically to facilitate using with D3D12On7. // See if any version of d3d12.dll is already loaded in the process. If so, give preference to that. static HINSTANCE d3d12_dll = ::GetModuleHandleA("d3d12.dll"); - if (d3d12_dll == NULL) + if (d3d12_dll == nullptr) { // Attempt to load d3d12.dll from local directories. This will only succeed if // (1) the current OS is Windows 7, and @@ -582,23 +583,23 @@ bool ImGui_ImplDX12_CreateDeviceObjects() // See https://github.com/ocornut/imgui/pull/3696 for details. const char* localD3d12Paths[] = { ".\\d3d12.dll", ".\\d3d12on7\\d3d12.dll", ".\\12on7\\d3d12.dll" }; // A. current directory, B. used by some games, C. used in Microsoft D3D12On7 sample for (int i = 0; i < IM_ARRAYSIZE(localD3d12Paths); i++) - if ((d3d12_dll = ::LoadLibraryA(localD3d12Paths[i])) != NULL) + if ((d3d12_dll = ::LoadLibraryA(localD3d12Paths[i])) != nullptr) break; // If failed, we are on Windows >= 10. - if (d3d12_dll == NULL) + if (d3d12_dll == nullptr) d3d12_dll = ::LoadLibraryA("d3d12.dll"); - if (d3d12_dll == NULL) + if (d3d12_dll == nullptr) return false; } PFN_D3D12_SERIALIZE_ROOT_SIGNATURE D3D12SerializeRootSignatureFn = (PFN_D3D12_SERIALIZE_ROOT_SIGNATURE)::GetProcAddress(d3d12_dll, "D3D12SerializeRootSignature"); - if (D3D12SerializeRootSignatureFn == NULL) + if (D3D12SerializeRootSignatureFn == nullptr) return false; - ID3DBlob* blob = NULL; - if (D3D12SerializeRootSignatureFn(&desc, D3D_ROOT_SIGNATURE_VERSION_1, &blob, NULL) != S_OK) + ID3DBlob* blob = nullptr; + if (D3D12SerializeRootSignatureFn(&desc, D3D_ROOT_SIGNATURE_VERSION_1, &blob, nullptr) != S_OK) return false; bd->pd3dDevice->CreateRootSignature(0, blob->GetBufferPointer(), blob->GetBufferSize(), IID_PPV_ARGS(&bd->pRootSignature)); @@ -607,7 +608,7 @@ bool ImGui_ImplDX12_CreateDeviceObjects() // By using D3DCompile() from / d3dcompiler.lib, we introduce a dependency to a given version of d3dcompiler_XX.dll (see D3DCOMPILER_DLL_A) // If you would like to use this DX12 sample code but remove this dependency you can: - // 1) compile once, save the compiled shader blobs into a file or source code and pass them to CreateVertexShader()/CreatePixelShader() [preferred solution] + // 1) compile once, save the compiled shader blobs into a file or source code and assign them to psoDesc.VS/PS [preferred solution] // 2) use code to detect any version of the DLL and grab a pointer to D3DCompile from the DLL. // See https://github.com/ocornut/imgui/pull/638 for sources and details. @@ -655,8 +656,8 @@ bool ImGui_ImplDX12_CreateDeviceObjects() return output;\ }"; - if (FAILED(D3DCompile(vertexShader, strlen(vertexShader), NULL, NULL, NULL, "main", "vs_5_0", 0, 0, &vertexShaderBlob, NULL))) - return false; // NB: Pass ID3D10Blob* pErrorBlob to D3DCompile() to get error showing in (const char*)pErrorBlob->GetBufferPointer(). Make sure to Release() the blob! + if (FAILED(D3DCompile(vertexShader, strlen(vertexShader), nullptr, nullptr, nullptr, "main", "vs_5_0", 0, 0, &vertexShaderBlob, nullptr))) + return false; // NB: Pass ID3DBlob* pErrorBlob to D3DCompile() to get error showing in (const char*)pErrorBlob->GetBufferPointer(). Make sure to Release() the blob! psoDesc.VS = { vertexShaderBlob->GetBufferPointer(), vertexShaderBlob->GetBufferSize() }; // Create the input layout @@ -687,10 +688,10 @@ bool ImGui_ImplDX12_CreateDeviceObjects() return out_col; \ }"; - if (FAILED(D3DCompile(pixelShader, strlen(pixelShader), NULL, NULL, NULL, "main", "ps_5_0", 0, 0, &pixelShaderBlob, NULL))) + if (FAILED(D3DCompile(pixelShader, strlen(pixelShader), nullptr, nullptr, nullptr, "main", "ps_5_0", 0, 0, &pixelShaderBlob, nullptr))) { vertexShaderBlob->Release(); - return false; // NB: Pass ID3D10Blob* pErrorBlob to D3DCompile() to get error showing in (const char*)pErrorBlob->GetBufferPointer(). Make sure to Release() the blob! + return false; // NB: Pass ID3DBlob* pErrorBlob to D3DCompile() to get error showing in (const char*)pErrorBlob->GetBufferPointer(). Make sure to Release() the blob! } psoDesc.PS = { pixelShaderBlob->GetBufferPointer(), pixelShaderBlob->GetBufferSize() }; } @@ -765,14 +766,14 @@ void ImGui_ImplDX12_InvalidateDeviceObjects() SafeRelease(bd->pRootSignature); SafeRelease(bd->pPipelineState); SafeRelease(bd->pFontTextureResource); - io.Fonts->SetTexID(NULL); // We copied bd->pFontTextureView to io.Fonts->TexID so let's clear that as well. + io.Fonts->SetTexID(0); // We copied bd->pFontTextureView to io.Fonts->TexID so let's clear that as well. } bool ImGui_ImplDX12_Init(ID3D12Device* device, int num_frames_in_flight, DXGI_FORMAT rtv_format, ID3D12DescriptorHeap* cbv_srv_heap, D3D12_CPU_DESCRIPTOR_HANDLE font_srv_cpu_desc_handle, D3D12_GPU_DESCRIPTOR_HANDLE font_srv_gpu_desc_handle) { ImGuiIO& io = ImGui::GetIO(); - IM_ASSERT(io.BackendRendererUserData == NULL && "Already initialized a renderer backend!"); + IM_ASSERT(io.BackendRendererUserData == nullptr && "Already initialized a renderer backend!"); // Setup backend capabilities flags ImGui_ImplDX12_Data* bd = IM_NEW(ImGui_ImplDX12_Data)(); @@ -801,7 +802,7 @@ bool ImGui_ImplDX12_Init(ID3D12Device* device, int num_frames_in_flight, DXGI_FO void ImGui_ImplDX12_Shutdown() { ImGui_ImplDX12_Data* bd = ImGui_ImplDX12_GetBackendData(); - IM_ASSERT(bd != NULL && "No renderer backend to shutdown, or already shutdown?"); + IM_ASSERT(bd != nullptr && "No renderer backend to shutdown, or already shutdown?"); ImGuiIO& io = ImGui::GetIO(); // Manually delete main viewport render resources in-case we haven't initialized for viewports @@ -812,22 +813,23 @@ void ImGui_ImplDX12_Shutdown() for (UINT i = 0; i < bd->numFramesInFlight; i++) ImGui_ImplDX12_DestroyRenderBuffers(&vd->FrameRenderBuffers[i]); IM_DELETE(vd); - main_viewport->RendererUserData = NULL; + main_viewport->RendererUserData = nullptr; } // Clean up windows and device objects ImGui_ImplDX12_ShutdownPlatformInterface(); ImGui_ImplDX12_InvalidateDeviceObjects(); - io.BackendRendererName = NULL; - io.BackendRendererUserData = NULL; + io.BackendRendererName = nullptr; + io.BackendRendererUserData = nullptr; + io.BackendFlags &= ~(ImGuiBackendFlags_RendererHasVtxOffset | ImGuiBackendFlags_RendererHasViewports); IM_DELETE(bd); } void ImGui_ImplDX12_NewFrame() { ImGui_ImplDX12_Data* bd = ImGui_ImplDX12_GetBackendData(); - IM_ASSERT(bd != NULL && "Did you call ImGui_ImplDX12_Init()?"); + IM_ASSERT(bd != nullptr && "Did you call ImGui_ImplDX12_Init()?"); if (!bd->pPipelineState) ImGui_ImplDX12_CreateDeviceObjects(); @@ -846,7 +848,7 @@ static void ImGui_ImplDX12_CreateWindow(ImGuiViewport* viewport) viewport->RendererUserData = vd; // PlatformHandleRaw should always be a HWND, whereas PlatformHandle might be a higher-level handle (e.g. GLFWWindow*, SDL_Window*). - // Some backends will leave PlatformHandleRaw NULL, in which case we assume PlatformHandle will contain the HWND. + // Some backends will leave PlatformHandleRaw == 0, in which case we assume PlatformHandle will contain the HWND. HWND hwnd = viewport->PlatformHandleRaw ? (HWND)viewport->PlatformHandleRaw : (HWND)viewport->PlatformHandle; IM_ASSERT(hwnd != 0); @@ -869,7 +871,7 @@ static void ImGui_ImplDX12_CreateWindow(ImGuiViewport* viewport) } // Create command list. - res = bd->pd3dDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, vd->FrameCtx[0].CommandAllocator, NULL, IID_PPV_ARGS(&vd->CommandList)); + res = bd->pd3dDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, vd->FrameCtx[0].CommandAllocator, nullptr, IID_PPV_ARGS(&vd->CommandList)); IM_ASSERT(res == S_OK); vd->CommandList->Close(); @@ -877,8 +879,8 @@ static void ImGui_ImplDX12_CreateWindow(ImGuiViewport* viewport) res = bd->pd3dDevice->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&vd->Fence)); IM_ASSERT(res == S_OK); - vd->FenceEvent = CreateEvent(NULL, FALSE, FALSE, NULL); - IM_ASSERT(vd->FenceEvent != NULL); + vd->FenceEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr); + IM_ASSERT(vd->FenceEvent != nullptr); // Create swap chain // FIXME-VIEWPORT: May want to copy/inherit swap chain settings from the user/application. @@ -896,18 +898,18 @@ static void ImGui_ImplDX12_CreateWindow(ImGuiViewport* viewport) sd1.Scaling = DXGI_SCALING_STRETCH; sd1.Stereo = FALSE; - IDXGIFactory4* dxgi_factory = NULL; + IDXGIFactory4* dxgi_factory = nullptr; res = ::CreateDXGIFactory1(IID_PPV_ARGS(&dxgi_factory)); IM_ASSERT(res == S_OK); - IDXGISwapChain1* swap_chain = NULL; - res = dxgi_factory->CreateSwapChainForHwnd(vd->CommandQueue, hwnd, &sd1, NULL, NULL, &swap_chain); + IDXGISwapChain1* swap_chain = nullptr; + res = dxgi_factory->CreateSwapChainForHwnd(vd->CommandQueue, hwnd, &sd1, nullptr, nullptr, &swap_chain); IM_ASSERT(res == S_OK); dxgi_factory->Release(); // Or swapChain.As(&mSwapChain) - IM_ASSERT(vd->SwapChain == NULL); + IM_ASSERT(vd->SwapChain == nullptr); swap_chain->QueryInterface(IID_PPV_ARGS(&vd->SwapChain)); swap_chain->Release(); @@ -934,9 +936,9 @@ static void ImGui_ImplDX12_CreateWindow(ImGuiViewport* viewport) ID3D12Resource* back_buffer; for (UINT i = 0; i < bd->numFramesInFlight; i++) { - IM_ASSERT(vd->FrameCtx[i].RenderTarget == NULL); + IM_ASSERT(vd->FrameCtx[i].RenderTarget == nullptr); vd->SwapChain->GetBuffer(i, IID_PPV_ARGS(&back_buffer)); - bd->pd3dDevice->CreateRenderTargetView(back_buffer, NULL, vd->FrameCtx[i].RenderTargetCpuDescriptors); + bd->pd3dDevice->CreateRenderTargetView(back_buffer, nullptr, vd->FrameCtx[i].RenderTargetCpuDescriptors); vd->FrameCtx[i].RenderTarget = back_buffer; } } @@ -961,7 +963,7 @@ static void ImGui_WaitForPendingOperations(ImGui_ImplDX12_ViewportData* vd) static void ImGui_ImplDX12_DestroyWindow(ImGuiViewport* viewport) { - // The main viewport (owned by the application) will always have RendererUserData == NULL since we didn't create the data for it. + // The main viewport (owned by the application) will always have RendererUserData == 0 since we didn't create the data for it. ImGui_ImplDX12_Data* bd = ImGui_ImplDX12_GetBackendData(); if (ImGui_ImplDX12_ViewportData* vd = (ImGui_ImplDX12_ViewportData*)viewport->RendererUserData) { @@ -973,7 +975,7 @@ static void ImGui_ImplDX12_DestroyWindow(ImGuiViewport* viewport) SafeRelease(vd->RtvDescHeap); SafeRelease(vd->Fence); ::CloseHandle(vd->FenceEvent); - vd->FenceEvent = NULL; + vd->FenceEvent = nullptr; for (UINT i = 0; i < bd->numFramesInFlight; i++) { @@ -983,7 +985,7 @@ static void ImGui_ImplDX12_DestroyWindow(ImGuiViewport* viewport) } IM_DELETE(vd); } - viewport->RendererUserData = NULL; + viewport->RendererUserData = nullptr; } static void ImGui_ImplDX12_SetWindowSize(ImGuiViewport* viewport, ImVec2 size) @@ -998,12 +1000,12 @@ static void ImGui_ImplDX12_SetWindowSize(ImGuiViewport* viewport, ImVec2 size) if (vd->SwapChain) { - ID3D12Resource* back_buffer = NULL; + ID3D12Resource* back_buffer = nullptr; vd->SwapChain->ResizeBuffers(0, (UINT)size.x, (UINT)size.y, DXGI_FORMAT_UNKNOWN, 0); for (UINT i = 0; i < bd->numFramesInFlight; i++) { vd->SwapChain->GetBuffer(i, IID_PPV_ARGS(&back_buffer)); - bd->pd3dDevice->CreateRenderTargetView(back_buffer, NULL, vd->FrameCtx[i].RenderTargetCpuDescriptors); + bd->pd3dDevice->CreateRenderTargetView(back_buffer, nullptr, vd->FrameCtx[i].RenderTargetCpuDescriptors); vd->FrameCtx[i].RenderTarget = back_buffer; } } @@ -1030,11 +1032,11 @@ static void ImGui_ImplDX12_RenderWindow(ImGuiViewport* viewport, void*) ID3D12GraphicsCommandList* cmd_list = vd->CommandList; frame_context->CommandAllocator->Reset(); - cmd_list->Reset(frame_context->CommandAllocator, NULL); + cmd_list->Reset(frame_context->CommandAllocator, nullptr); cmd_list->ResourceBarrier(1, &barrier); - cmd_list->OMSetRenderTargets(1, &vd->FrameCtx[back_buffer_idx].RenderTargetCpuDescriptors, FALSE, NULL); + cmd_list->OMSetRenderTargets(1, &vd->FrameCtx[back_buffer_idx].RenderTargetCpuDescriptors, FALSE, nullptr); if (!(viewport->Flags & ImGuiViewportFlags_NoRendererClear)) - cmd_list->ClearRenderTargetView(vd->FrameCtx[back_buffer_idx].RenderTargetCpuDescriptors, (float*)&clear_color, 0, NULL); + cmd_list->ClearRenderTargetView(vd->FrameCtx[back_buffer_idx].RenderTargetCpuDescriptors, (float*)&clear_color, 0, nullptr); cmd_list->SetDescriptorHeaps(1, &bd->pd3dSrvDescHeap); ImGui_ImplDX12_RenderDrawData(viewport->DrawData, cmd_list); diff --git a/extern/imgui_patched/backends/imgui_impl_dx12.h b/extern/imgui_patched/backends/imgui_impl_dx12.h index 63a3c1a8..a4d02aa8 100644 --- a/extern/imgui_patched/backends/imgui_impl_dx12.h +++ b/extern/imgui_patched/backends/imgui_impl_dx12.h @@ -3,8 +3,8 @@ // Implemented features: // [X] Renderer: User texture binding. Use 'D3D12_GPU_DESCRIPTOR_HANDLE' as ImTextureID. Read the FAQ about ImTextureID! -// [X] Renderer: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'. // [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices. +// [X] Renderer: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'. // Important: to compile on 32-bit systems, this backend requires code to be compiled with '#define ImTextureID ImU64'. // See imgui_impl_dx12.cpp file for details. diff --git a/extern/imgui_patched/backends/imgui_impl_dx9.cpp b/extern/imgui_patched/backends/imgui_impl_dx9.cpp index e4006260..7274f299 100644 --- a/extern/imgui_patched/backends/imgui_impl_dx9.cpp +++ b/extern/imgui_patched/backends/imgui_impl_dx9.cpp @@ -3,8 +3,8 @@ // Implemented features: // [X] Renderer: User texture binding. Use 'LPDIRECT3DTEXTURE9' as ImTextureID. Read the FAQ about ImTextureID! -// [X] Renderer: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'. // [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices. +// [X] Renderer: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'. // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. @@ -13,7 +13,8 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) -// 2022-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface. +// 2023-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface. +// 2022-10-11: Using 'nullptr' instead of 'NULL' as per our switch to C++11. // 2021-06-29: Reorganized backend to pull data from a single structure to facilitate usage with multiple-contexts (all g_XXXX access changed to bd->XXXX). // 2021-06-25: DirectX9: Explicitly disable texture state stages after >= 1. // 2021-05-19: DirectX9: Replaced direct access to ImDrawCmd::TextureId with a call to ImDrawCmd::GetTexID(). (will become a requirement) @@ -69,7 +70,7 @@ struct CUSTOMVERTEX // It is STRONGLY preferred that you use docking branch with multi-viewports (== single Dear ImGui context + multiple windows) instead of multiple Dear ImGui contexts. static ImGui_ImplDX9_Data* ImGui_ImplDX9_GetBackendData() { - return ImGui::GetCurrentContext() ? (ImGui_ImplDX9_Data*)ImGui::GetIO().BackendRendererUserData : NULL; + return ImGui::GetCurrentContext() ? (ImGui_ImplDX9_Data*)ImGui::GetIO().BackendRendererUserData : nullptr; } // Forward Declarations @@ -93,8 +94,8 @@ static void ImGui_ImplDX9_SetupRenderState(ImDrawData* draw_data) bd->pd3dDevice->SetViewport(&vp); // Setup render state: fixed-pipeline, alpha-blending, no face culling, no depth testing, shade mode (for gradient), bilinear sampling. - bd->pd3dDevice->SetPixelShader(NULL); - bd->pd3dDevice->SetVertexShader(NULL); + bd->pd3dDevice->SetPixelShader(nullptr); + bd->pd3dDevice->SetVertexShader(nullptr); bd->pd3dDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID); bd->pd3dDevice->SetRenderState(D3DRS_SHADEMODE, D3DSHADE_GOURAUD); bd->pd3dDevice->SetRenderState(D3DRS_ZWRITEENABLE, FALSE); @@ -159,21 +160,21 @@ void ImGui_ImplDX9_RenderDrawData(ImDrawData* draw_data) ImGui_ImplDX9_Data* bd = ImGui_ImplDX9_GetBackendData(); if (!bd->pVB || bd->VertexBufferSize < draw_data->TotalVtxCount) { - if (bd->pVB) { bd->pVB->Release(); bd->pVB = NULL; } + if (bd->pVB) { bd->pVB->Release(); bd->pVB = nullptr; } bd->VertexBufferSize = draw_data->TotalVtxCount + 5000; - if (bd->pd3dDevice->CreateVertexBuffer(bd->VertexBufferSize * sizeof(CUSTOMVERTEX), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &bd->pVB, NULL) < 0) + if (bd->pd3dDevice->CreateVertexBuffer(bd->VertexBufferSize * sizeof(CUSTOMVERTEX), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &bd->pVB, nullptr) < 0) return; } if (!bd->pIB || bd->IndexBufferSize < draw_data->TotalIdxCount) { - if (bd->pIB) { bd->pIB->Release(); bd->pIB = NULL; } + if (bd->pIB) { bd->pIB->Release(); bd->pIB = nullptr; } bd->IndexBufferSize = draw_data->TotalIdxCount + 10000; - if (bd->pd3dDevice->CreateIndexBuffer(bd->IndexBufferSize * sizeof(ImDrawIdx), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, sizeof(ImDrawIdx) == 2 ? D3DFMT_INDEX16 : D3DFMT_INDEX32, D3DPOOL_DEFAULT, &bd->pIB, NULL) < 0) + if (bd->pd3dDevice->CreateIndexBuffer(bd->IndexBufferSize * sizeof(ImDrawIdx), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, sizeof(ImDrawIdx) == 2 ? D3DFMT_INDEX16 : D3DFMT_INDEX32, D3DPOOL_DEFAULT, &bd->pIB, nullptr) < 0) return; } // Backup the DX9 state - IDirect3DStateBlock9* d3d9_state_block = NULL; + IDirect3DStateBlock9* d3d9_state_block = nullptr; if (bd->pd3dDevice->CreateStateBlock(D3DSBT_ALL, &d3d9_state_block) < 0) return; if (d3d9_state_block->Capture() < 0) @@ -245,7 +246,7 @@ void ImGui_ImplDX9_RenderDrawData(ImDrawData* draw_data) for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++) { const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i]; - if (pcmd->UserCallback != NULL) + if (pcmd->UserCallback != nullptr) { // User callback, registered via ImDrawList::AddCallback() // (ImDrawCallback_ResetRenderState is a special callback value used by the user to request the renderer to reset render state.) @@ -292,7 +293,7 @@ void ImGui_ImplDX9_RenderDrawData(ImDrawData* draw_data) bool ImGui_ImplDX9_Init(IDirect3DDevice9* device) { ImGuiIO& io = ImGui::GetIO(); - IM_ASSERT(io.BackendRendererUserData == NULL && "Already initialized a renderer backend!"); + IM_ASSERT(io.BackendRendererUserData == nullptr && "Already initialized a renderer backend!"); // Setup backend capabilities flags ImGui_ImplDX9_Data* bd = IM_NEW(ImGui_ImplDX9_Data)(); @@ -313,14 +314,15 @@ bool ImGui_ImplDX9_Init(IDirect3DDevice9* device) void ImGui_ImplDX9_Shutdown() { ImGui_ImplDX9_Data* bd = ImGui_ImplDX9_GetBackendData(); - IM_ASSERT(bd != NULL && "No renderer backend to shutdown, or already shutdown?"); + IM_ASSERT(bd != nullptr && "No renderer backend to shutdown, or already shutdown?"); ImGuiIO& io = ImGui::GetIO(); ImGui_ImplDX9_ShutdownPlatformInterface(); ImGui_ImplDX9_InvalidateDeviceObjects(); if (bd->pd3dDevice) { bd->pd3dDevice->Release(); } - io.BackendRendererName = NULL; - io.BackendRendererUserData = NULL; + io.BackendRendererName = nullptr; + io.BackendRendererUserData = nullptr; + io.BackendFlags &= ~(ImGuiBackendFlags_RendererHasVtxOffset | ImGuiBackendFlags_RendererHasViewports); IM_DELETE(bd); } @@ -345,11 +347,11 @@ static bool ImGui_ImplDX9_CreateFontsTexture() #endif // Upload texture to graphics system - bd->FontTexture = NULL; - if (bd->pd3dDevice->CreateTexture(width, height, 1, D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &bd->FontTexture, NULL) < 0) + bd->FontTexture = nullptr; + if (bd->pd3dDevice->CreateTexture(width, height, 1, D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &bd->FontTexture, nullptr) < 0) return false; D3DLOCKED_RECT tex_locked_rect; - if (bd->FontTexture->LockRect(0, &tex_locked_rect, NULL, 0) != D3D_OK) + if (bd->FontTexture->LockRect(0, &tex_locked_rect, nullptr, 0) != D3D_OK) return false; for (int y = 0; y < height; y++) memcpy((unsigned char*)tex_locked_rect.pBits + (size_t)tex_locked_rect.Pitch * y, pixels + (size_t)width * bytes_per_pixel * y, (size_t)width * bytes_per_pixel); @@ -382,16 +384,16 @@ void ImGui_ImplDX9_InvalidateDeviceObjects() ImGui_ImplDX9_Data* bd = ImGui_ImplDX9_GetBackendData(); if (!bd || !bd->pd3dDevice) return; - if (bd->pVB) { bd->pVB->Release(); bd->pVB = NULL; } - if (bd->pIB) { bd->pIB->Release(); bd->pIB = NULL; } - if (bd->FontTexture) { bd->FontTexture->Release(); bd->FontTexture = NULL; ImGui::GetIO().Fonts->SetTexID(NULL); } // We copied bd->pFontTextureView to io.Fonts->TexID so let's clear that as well. + if (bd->pVB) { bd->pVB->Release(); bd->pVB = nullptr; } + if (bd->pIB) { bd->pIB->Release(); bd->pIB = nullptr; } + if (bd->FontTexture) { bd->FontTexture->Release(); bd->FontTexture = nullptr; ImGui::GetIO().Fonts->SetTexID(0); } // We copied bd->pFontTextureView to io.Fonts->TexID so let's clear that as well. ImGui_ImplDX9_InvalidateDeviceObjectsForPlatformWindows(); } void ImGui_ImplDX9_NewFrame() { ImGui_ImplDX9_Data* bd = ImGui_ImplDX9_GetBackendData(); - IM_ASSERT(bd != NULL && "Did you call ImGui_ImplDX9_Init()?"); + IM_ASSERT(bd != nullptr && "Did you call ImGui_ImplDX9_Init()?"); if (!bd->FontTexture) ImGui_ImplDX9_CreateDeviceObjects(); @@ -403,14 +405,14 @@ void ImGui_ImplDX9_NewFrame() // If you are new to dear imgui or creating a new binding for dear imgui, it is recommended that you completely ignore this section first.. //-------------------------------------------------------------------------------------------------------- -// Helper structure we store in the void* RenderUserData field of each ImGuiViewport to easily retrieve our backend data. +// Helper structure we store in the void* RendererUserData field of each ImGuiViewport to easily retrieve our backend data. struct ImGui_ImplDX9_ViewportData { IDirect3DSwapChain9* SwapChain; D3DPRESENT_PARAMETERS d3dpp; - ImGui_ImplDX9_ViewportData() { SwapChain = NULL; ZeroMemory(&d3dpp, sizeof(D3DPRESENT_PARAMETERS)); } - ~ImGui_ImplDX9_ViewportData() { IM_ASSERT(SwapChain == NULL); } + ImGui_ImplDX9_ViewportData() { SwapChain = nullptr; ZeroMemory(&d3dpp, sizeof(D3DPRESENT_PARAMETERS)); } + ~ImGui_ImplDX9_ViewportData() { IM_ASSERT(SwapChain == nullptr); } }; static void ImGui_ImplDX9_CreateWindow(ImGuiViewport* viewport) @@ -420,7 +422,7 @@ static void ImGui_ImplDX9_CreateWindow(ImGuiViewport* viewport) viewport->RendererUserData = vd; // PlatformHandleRaw should always be a HWND, whereas PlatformHandle might be a higher-level handle (e.g. GLFWWindow*, SDL_Window*). - // Some backends will leave PlatformHandleRaw NULL, in which case we assume PlatformHandle will contain the HWND. + // Some backends will leave PlatformHandleRaw == 0, in which case we assume PlatformHandle will contain the HWND. HWND hwnd = viewport->PlatformHandleRaw ? (HWND)viewport->PlatformHandleRaw : (HWND)viewport->PlatformHandle; IM_ASSERT(hwnd != 0); @@ -437,21 +439,21 @@ static void ImGui_ImplDX9_CreateWindow(ImGuiViewport* viewport) HRESULT hr = bd->pd3dDevice->CreateAdditionalSwapChain(&vd->d3dpp, &vd->SwapChain); IM_UNUSED(hr); IM_ASSERT(hr == D3D_OK); - IM_ASSERT(vd->SwapChain != NULL); + IM_ASSERT(vd->SwapChain != nullptr); } static void ImGui_ImplDX9_DestroyWindow(ImGuiViewport* viewport) { - // The main viewport (owned by the application) will always have RendererUserData == NULL since we didn't create the data for it. + // The main viewport (owned by the application) will always have RendererUserData == 0 since we didn't create the data for it. if (ImGui_ImplDX9_ViewportData* vd = (ImGui_ImplDX9_ViewportData*)viewport->RendererUserData) { if (vd->SwapChain) vd->SwapChain->Release(); - vd->SwapChain = NULL; + vd->SwapChain = nullptr; ZeroMemory(&vd->d3dpp, sizeof(D3DPRESENT_PARAMETERS)); IM_DELETE(vd); } - viewport->RendererUserData = NULL; + viewport->RendererUserData = nullptr; } static void ImGui_ImplDX9_SetWindowSize(ImGuiViewport* viewport, ImVec2 size) @@ -461,7 +463,7 @@ static void ImGui_ImplDX9_SetWindowSize(ImGuiViewport* viewport, ImVec2 size) if (vd->SwapChain) { vd->SwapChain->Release(); - vd->SwapChain = NULL; + vd->SwapChain = nullptr; vd->d3dpp.BackBufferWidth = (UINT)size.x; vd->d3dpp.BackBufferHeight = (UINT)size.y; HRESULT hr = bd->pd3dDevice->CreateAdditionalSwapChain(&vd->d3dpp, &vd->SwapChain); IM_UNUSED(hr); @@ -475,19 +477,19 @@ static void ImGui_ImplDX9_RenderWindow(ImGuiViewport* viewport, void*) ImGui_ImplDX9_ViewportData* vd = (ImGui_ImplDX9_ViewportData*)viewport->RendererUserData; ImVec4 clear_color = ImVec4(0.0f, 0.0f, 0.0f, 1.0f); - LPDIRECT3DSURFACE9 render_target = NULL; - LPDIRECT3DSURFACE9 last_render_target = NULL; - LPDIRECT3DSURFACE9 last_depth_stencil = NULL; + LPDIRECT3DSURFACE9 render_target = nullptr; + LPDIRECT3DSURFACE9 last_render_target = nullptr; + LPDIRECT3DSURFACE9 last_depth_stencil = nullptr; vd->SwapChain->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &render_target); bd->pd3dDevice->GetRenderTarget(0, &last_render_target); bd->pd3dDevice->GetDepthStencilSurface(&last_depth_stencil); bd->pd3dDevice->SetRenderTarget(0, render_target); - bd->pd3dDevice->SetDepthStencilSurface(NULL); + bd->pd3dDevice->SetDepthStencilSurface(nullptr); if (!(viewport->Flags & ImGuiViewportFlags_NoRendererClear)) { D3DCOLOR clear_col_dx = D3DCOLOR_RGBA((int)(clear_color.x*255.0f), (int)(clear_color.y*255.0f), (int)(clear_color.z*255.0f), (int)(clear_color.w*255.0f)); - bd->pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET, clear_col_dx, 1.0f, 0); + bd->pd3dDevice->Clear(0, nullptr, D3DCLEAR_TARGET, clear_col_dx, 1.0f, 0); } ImGui_ImplDX9_RenderDrawData(viewport->DrawData); @@ -503,7 +505,7 @@ static void ImGui_ImplDX9_RenderWindow(ImGuiViewport* viewport, void*) static void ImGui_ImplDX9_SwapBuffers(ImGuiViewport* viewport, void*) { ImGui_ImplDX9_ViewportData* vd = (ImGui_ImplDX9_ViewportData*)viewport->RendererUserData; - HRESULT hr = vd->SwapChain->Present(NULL, NULL, vd->d3dpp.hDeviceWindow, NULL, 0); + HRESULT hr = vd->SwapChain->Present(nullptr, nullptr, vd->d3dpp.hDeviceWindow, nullptr, 0); // Let main application handle D3DERR_DEVICELOST by resetting the device. IM_ASSERT(hr == D3D_OK || hr == D3DERR_DEVICELOST); } diff --git a/extern/imgui_patched/backends/imgui_impl_dx9.h b/extern/imgui_patched/backends/imgui_impl_dx9.h index 2d75662d..3e7c1736 100644 --- a/extern/imgui_patched/backends/imgui_impl_dx9.h +++ b/extern/imgui_patched/backends/imgui_impl_dx9.h @@ -3,10 +3,10 @@ // Implemented features: // [X] Renderer: User texture binding. Use 'LPDIRECT3DTEXTURE9' as ImTextureID. Read the FAQ about ImTextureID! -// [X] Renderer: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'. // [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices. +// [X] Renderer: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'. -// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. +// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. // If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp. // Read online: https://github.com/ocornut/imgui/tree/master/docs diff --git a/extern/imgui_patched/backends/imgui_impl_glfw.cpp b/extern/imgui_patched/backends/imgui_impl_glfw.cpp index 92f6c552..87ea528b 100644 --- a/extern/imgui_patched/backends/imgui_impl_glfw.cpp +++ b/extern/imgui_patched/backends/imgui_impl_glfw.cpp @@ -1,10 +1,11 @@ // dear imgui: Platform Backend for GLFW // This needs to be used along with a Renderer (e.g. OpenGL3, Vulkan, WebGPU..) // (Info: GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.) -// (Requires: GLFW 3.1+. Prefer GLFW 3.3+ for full feature support.) +// (Requires: GLFW 3.1+. Prefer GLFW 3.3+ or GLFW 3.4+ for full feature support.) // Implemented features: // [X] Platform: Clipboard support. +// [X] Platform: Mouse support. Can discriminate Mouse/TouchScreen/Pen (Windows only). // [X] Platform: Keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(ImGuiKey_Space). [Legacy GLFW_KEY_* values will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set] // [X] Platform: Gamepad support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'. // [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange' (note: the resizing cursors requires GLFW 3.4+). @@ -20,11 +21,22 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) -// 2022-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface. +// 2023-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface. +// 2023-04-04: Inputs: Added support for io.AddMouseSourceEvent() to discriminate ImGuiMouseSource_Mouse/ImGuiMouseSource_TouchScreen/ImGuiMouseSource_Pen on Windows ONLY, using a custom WndProc hook. (#2702) +// 2023-03-16: Inputs: Fixed key modifiers handling on secondary viewports (docking branch). Broken on 2023/01/04. (#6248, #6034) +// 2023-03-14: Emscripten: Avoid using glfwGetError() and glfwGetGamepadState() which are not correctly implemented in Emscripten emulation. (#6240) +// 2023-02-03: Emscripten: Registering custom low-level mouse wheel handler to get more accurate scrolling impulses on Emscripten. (#4019, #6096) +// 2023-01-18: Handle unsupported glfwGetVideoMode() call on e.g. Emscripten. +// 2023-01-04: Inputs: Fixed mods state on Linux when using Alt-GR text input (e.g. German keyboard layout), could lead to broken text input. Revert a 2022/01/17 change were we resumed using mods provided by GLFW, turns out they were faulty. +// 2022-11-22: Perform a dummy glfwGetError() read to cancel missing names with glfwGetKeyName(). (#5908) +// 2022-10-18: Perform a dummy glfwGetError() read to cancel missing mouse cursors errors. Using GLFW_VERSION_COMBINED directly. (#5785) +// 2022-10-11: Using 'nullptr' instead of 'NULL' as per our switch to C++11. +// 2022-09-26: Inputs: Renamed ImGuiKey_ModXXX introduced in 1.87 to ImGuiMod_XXX (old names still supported). +// 2022-09-01: Inputs: Honor GLFW_CURSOR_DISABLED by not setting mouse position. // 2022-04-30: Inputs: Fixed ImGui_ImplGlfw_TranslateUntranslatedKey() for lower case letters on OSX. // 2022-03-23: Inputs: Fixed a regression in 1.87 which resulted in keyboard modifiers events being reported incorrectly on Linux/X11. // 2022-02-07: Added ImGui_ImplGlfw_InstallCallbacks()/ImGui_ImplGlfw_RestoreCallbacks() helpers to facilitate user installing callbacks after initializing backend. -// 2022-01-26: Inputs: replaced short-lived io.AddKeyModsEvent() (added two weeks ago)with io.AddKeyEvent() using ImGuiKey_ModXXX flags. Sorry for the confusion. +// 2022-01-26: Inputs: replaced short-lived io.AddKeyModsEvent() (added two weeks ago) with io.AddKeyEvent() using ImGuiKey_ModXXX flags. Sorry for the confusion. // 2021-01-20: Inputs: calling new io.AddKeyAnalogEvent() for gamepad support, instead of writing directly to io.NavInputs[]. // 2022-01-17: Inputs: calling new io.AddMousePosEvent(), io.AddMouseButtonEvent(), io.AddMouseWheelEvent() API (1.87+). // 2022-01-17: Inputs: always update key mods next and before key event (not in NewFrame) to fix input queue with very low framerates. @@ -64,39 +76,54 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wold-style-cast" // warning: use of old-style cast #pragma clang diagnostic ignored "-Wsign-conversion" // warning: implicit conversion changes signedness -#if __has_warning("-Wzero-as-null-pointer-constant") -#pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant" -#endif #endif // GLFW #include + #ifdef _WIN32 #undef APIENTRY #define GLFW_EXPOSE_NATIVE_WIN32 -#include // for glfwGetWin32Window +#include // for glfwGetWin32Window() #endif -#define GLFW_HAS_WINDOW_TOPMOST (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 >= 3200) // 3.2+ GLFW_FLOATING -#define GLFW_HAS_WINDOW_HOVERED (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 >= 3300) // 3.3+ GLFW_HOVERED -#define GLFW_HAS_WINDOW_ALPHA (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 >= 3300) // 3.3+ glfwSetWindowOpacity -#define GLFW_HAS_PER_MONITOR_DPI (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 >= 3300) // 3.3+ glfwGetMonitorContentScale -#define GLFW_HAS_VULKAN (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 >= 3200) // 3.2+ glfwCreateWindowSurface -#define GLFW_HAS_FOCUS_WINDOW (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 >= 3200) // 3.2+ glfwFocusWindow -#define GLFW_HAS_FOCUS_ON_SHOW (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 >= 3300) // 3.3+ GLFW_FOCUS_ON_SHOW -#define GLFW_HAS_MONITOR_WORK_AREA (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 >= 3300) // 3.3+ glfwGetMonitorWorkarea -#define GLFW_HAS_OSX_WINDOW_POS_FIX (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 + GLFW_VERSION_REVISION * 10 >= 3310) // 3.3.1+ Fixed: Resizing window repositions it on MacOS #1553 -#ifdef GLFW_RESIZE_NESW_CURSOR // Let's be nice to people who pulled GLFW between 2019-04-16 (3.4 define) and 2019-11-29 (cursors defines) // FIXME: Remove when GLFW 3.4 is released? -#define GLFW_HAS_NEW_CURSORS (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 >= 3400) // 3.4+ GLFW_RESIZE_ALL_CURSOR, GLFW_RESIZE_NESW_CURSOR, GLFW_RESIZE_NWSE_CURSOR, GLFW_NOT_ALLOWED_CURSOR +#ifdef __APPLE__ +#define GLFW_EXPOSE_NATIVE_COCOA +#include // for glfwGetCocoaWindow() +#endif + +#ifdef __EMSCRIPTEN__ +#include +#include +#endif + +// We gather version tests as define in order to easily see which features are version-dependent. +#define GLFW_VERSION_COMBINED (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 + GLFW_VERSION_REVISION) +#define GLFW_HAS_WINDOW_TOPMOST (GLFW_VERSION_COMBINED >= 3200) // 3.2+ GLFW_FLOATING +#define GLFW_HAS_WINDOW_HOVERED (GLFW_VERSION_COMBINED >= 3300) // 3.3+ GLFW_HOVERED +#define GLFW_HAS_WINDOW_ALPHA (GLFW_VERSION_COMBINED >= 3300) // 3.3+ glfwSetWindowOpacity +#define GLFW_HAS_PER_MONITOR_DPI (GLFW_VERSION_COMBINED >= 3300) // 3.3+ glfwGetMonitorContentScale +#if defined(__EMSCRIPTEN__) || defined(__SWITCH__) // no Vulkan support in GLFW for Emscripten or homebrew Nintendo Switch +#define GLFW_HAS_VULKAN (0) #else -#define GLFW_HAS_NEW_CURSORS (0) +#define GLFW_HAS_VULKAN (GLFW_VERSION_COMBINED >= 3200) // 3.2+ glfwCreateWindowSurface #endif -#ifdef GLFW_MOUSE_PASSTHROUGH // Let's be nice to people who pulled GLFW between 2019-04-16 (3.4 define) and 2020-07-17 (passthrough) -#define GLFW_HAS_MOUSE_PASSTHROUGH (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 >= 3400) // 3.4+ GLFW_MOUSE_PASSTHROUGH +#define GLFW_HAS_FOCUS_WINDOW (GLFW_VERSION_COMBINED >= 3200) // 3.2+ glfwFocusWindow +#define GLFW_HAS_FOCUS_ON_SHOW (GLFW_VERSION_COMBINED >= 3300) // 3.3+ GLFW_FOCUS_ON_SHOW +#define GLFW_HAS_MONITOR_WORK_AREA (GLFW_VERSION_COMBINED >= 3300) // 3.3+ glfwGetMonitorWorkarea +#define GLFW_HAS_OSX_WINDOW_POS_FIX (GLFW_VERSION_COMBINED >= 3301) // 3.3.1+ Fixed: Resizing window repositions it on MacOS #1553 +#ifdef GLFW_RESIZE_NESW_CURSOR // Let's be nice to people who pulled GLFW between 2019-04-16 (3.4 define) and 2019-11-29 (cursors defines) // FIXME: Remove when GLFW 3.4 is released? +#define GLFW_HAS_NEW_CURSORS (GLFW_VERSION_COMBINED >= 3400) // 3.4+ GLFW_RESIZE_ALL_CURSOR, GLFW_RESIZE_NESW_CURSOR, GLFW_RESIZE_NWSE_CURSOR, GLFW_NOT_ALLOWED_CURSOR #else -#define GLFW_HAS_MOUSE_PASSTHROUGH (0) +#define GLFW_HAS_NEW_CURSORS (0) #endif -#define GLFW_HAS_GAMEPAD_API (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 >= 3300) // 3.3+ glfwGetGamepadState() new api -#define GLFW_HAS_GET_KEY_NAME (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 >= 3200) // 3.2+ glfwGetKeyName() +#ifdef GLFW_MOUSE_PASSTHROUGH // Let's be nice to people who pulled GLFW between 2019-04-16 (3.4 define) and 2020-07-17 (passthrough) +#define GLFW_HAS_MOUSE_PASSTHROUGH (GLFW_VERSION_COMBINED >= 3400) // 3.4+ GLFW_MOUSE_PASSTHROUGH +#else +#define GLFW_HAS_MOUSE_PASSTHROUGH (0) +#endif +#define GLFW_HAS_GAMEPAD_API (GLFW_VERSION_COMBINED >= 3300) // 3.3+ glfwGetGamepadState() new api +#define GLFW_HAS_GETKEYNAME (GLFW_VERSION_COMBINED >= 3200) // 3.2+ glfwGetKeyName() +#define GLFW_HAS_GETERROR (GLFW_VERSION_COMBINED >= 3300) // 3.3+ glfwGetError() // GLFW data enum GlfwClientApi @@ -116,6 +143,7 @@ struct ImGui_ImplGlfw_Data ImVec2 LastValidMousePos; GLFWwindow* KeyOwnerWindows[GLFW_KEY_LAST]; bool InstalledCallbacks; + bool CallbacksChainForAllWindows; bool WantUpdateMonitors; // Chain GLFW callbacks: our callbacks will call the user's previously installed callbacks, if any. @@ -127,6 +155,9 @@ struct ImGui_ImplGlfw_Data GLFWkeyfun PrevUserCallbackKey; GLFWcharfun PrevUserCallbackChar; GLFWmonitorfun PrevUserCallbackMonitor; +#ifdef _WIN32 + WNDPROC GlfwWndProc; +#endif ImGui_ImplGlfw_Data() { memset((void*)this, 0, sizeof(*this)); } }; @@ -140,7 +171,7 @@ struct ImGui_ImplGlfw_Data // FIXME: some shared resources (mouse cursor shape, gamepad) are mishandled when using multi-context. static ImGui_ImplGlfw_Data* ImGui_ImplGlfw_GetBackendData() { - return ImGui::GetCurrentContext() ? (ImGui_ImplGlfw_Data*)ImGui::GetIO().BackendPlatformUserData : NULL; + return ImGui::GetCurrentContext() ? (ImGui_ImplGlfw_Data*)ImGui::GetIO().BackendPlatformUserData : nullptr; } // Forward Declarations @@ -272,35 +303,30 @@ static ImGuiKey ImGui_ImplGlfw_KeyToImGuiKey(int key) } } -static int ImGui_ImplGlfw_KeyToModifier(int key) -{ - if (key == GLFW_KEY_LEFT_CONTROL || key == GLFW_KEY_RIGHT_CONTROL) - return GLFW_MOD_CONTROL; - if (key == GLFW_KEY_LEFT_SHIFT || key == GLFW_KEY_RIGHT_SHIFT) - return GLFW_MOD_SHIFT; - if (key == GLFW_KEY_LEFT_ALT || key == GLFW_KEY_RIGHT_ALT) - return GLFW_MOD_ALT; - if (key == GLFW_KEY_LEFT_SUPER || key == GLFW_KEY_RIGHT_SUPER) - return GLFW_MOD_SUPER; - return 0; -} - -static void ImGui_ImplGlfw_UpdateKeyModifiers(int mods) +// X11 does not include current pressed/released modifier key in 'mods' flags submitted by GLFW +// See https://github.com/ocornut/imgui/issues/6034 and https://github.com/glfw/glfw/issues/1630 +static void ImGui_ImplGlfw_UpdateKeyModifiers(GLFWwindow* window) { ImGuiIO& io = ImGui::GetIO(); - io.AddKeyEvent(ImGuiKey_ModCtrl, (mods & GLFW_MOD_CONTROL) != 0); - io.AddKeyEvent(ImGuiKey_ModShift, (mods & GLFW_MOD_SHIFT) != 0); - io.AddKeyEvent(ImGuiKey_ModAlt, (mods & GLFW_MOD_ALT) != 0); - io.AddKeyEvent(ImGuiKey_ModSuper, (mods & GLFW_MOD_SUPER) != 0); + io.AddKeyEvent(ImGuiMod_Ctrl, (glfwGetKey(window, GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS) || (glfwGetKey(window, GLFW_KEY_RIGHT_CONTROL) == GLFW_PRESS)); + io.AddKeyEvent(ImGuiMod_Shift, (glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS) || (glfwGetKey(window, GLFW_KEY_RIGHT_SHIFT) == GLFW_PRESS)); + io.AddKeyEvent(ImGuiMod_Alt, (glfwGetKey(window, GLFW_KEY_LEFT_ALT) == GLFW_PRESS) || (glfwGetKey(window, GLFW_KEY_RIGHT_ALT) == GLFW_PRESS)); + io.AddKeyEvent(ImGuiMod_Super, (glfwGetKey(window, GLFW_KEY_LEFT_SUPER) == GLFW_PRESS) || (glfwGetKey(window, GLFW_KEY_RIGHT_SUPER) == GLFW_PRESS)); +} + +static bool ImGui_ImplGlfw_ShouldChainCallback(GLFWwindow* window) +{ + ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData(); + return bd->CallbacksChainForAllWindows ? true : (window == bd->Window); } void ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow* window, int button, int action, int mods) { ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData(); - if (bd->PrevUserCallbackMousebutton != NULL && window == bd->Window) + if (bd->PrevUserCallbackMousebutton != nullptr && ImGui_ImplGlfw_ShouldChainCallback(window)) bd->PrevUserCallbackMousebutton(window, button, action, mods); - ImGui_ImplGlfw_UpdateKeyModifiers(mods); + ImGui_ImplGlfw_UpdateKeyModifiers(window); ImGuiIO& io = ImGui::GetIO(); if (button >= 0 && button < ImGuiMouseButton_COUNT) @@ -310,16 +336,21 @@ void ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow* window, int button, int acti void ImGui_ImplGlfw_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset) { ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData(); - if (bd->PrevUserCallbackScroll != NULL && window == bd->Window) + if (bd->PrevUserCallbackScroll != nullptr && ImGui_ImplGlfw_ShouldChainCallback(window)) bd->PrevUserCallbackScroll(window, xoffset, yoffset); +#ifdef __EMSCRIPTEN__ + // Ignore GLFW events: will be processed in ImGui_ImplEmscripten_WheelCallback(). + return; +#endif + ImGuiIO& io = ImGui::GetIO(); io.AddMouseWheelEvent((float)xoffset, (float)yoffset); } static int ImGui_ImplGlfw_TranslateUntranslatedKey(int key, int scancode) { -#if GLFW_HAS_GET_KEY_NAME && !defined(__EMSCRIPTEN__) +#if GLFW_HAS_GETKEYNAME && !defined(__EMSCRIPTEN__) // GLFW 3.1+ attempts to "untranslate" keys, which goes the opposite of what every other framework does, making using lettered shortcuts difficult. // (It had reasons to do so: namely GLFW is/was more likely to be used for WASD-type game controls rather than lettered shortcuts, but IHMO the 3.1 change could have been done differently) // See https://github.com/glfw/glfw/issues/1502 for details. @@ -327,7 +358,12 @@ static int ImGui_ImplGlfw_TranslateUntranslatedKey(int key, int scancode) // This won't cover edge cases but this is at least going to cover common cases. if (key >= GLFW_KEY_KP_0 && key <= GLFW_KEY_KP_EQUAL) return key; + GLFWerrorfun prev_error_callback = glfwSetErrorCallback(nullptr); const char* key_name = glfwGetKeyName(key, scancode); + glfwSetErrorCallback(prev_error_callback); +#if GLFW_HAS_GETERROR && !defined(__EMSCRIPTEN__) // Eat errors (see #5908) + (void)glfwGetError(nullptr); +#endif if (key_name && key_name[0] != 0 && key_name[1] == 0) { const char char_names[] = "`-=[]\\,;\'./"; @@ -348,19 +384,16 @@ static int ImGui_ImplGlfw_TranslateUntranslatedKey(int key, int scancode) void ImGui_ImplGlfw_KeyCallback(GLFWwindow* window, int keycode, int scancode, int action, int mods) { ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData(); - if (bd->PrevUserCallbackKey != NULL && window == bd->Window) + if (bd->PrevUserCallbackKey != nullptr && ImGui_ImplGlfw_ShouldChainCallback(window)) bd->PrevUserCallbackKey(window, keycode, scancode, action, mods); if (action != GLFW_PRESS && action != GLFW_RELEASE) return; - // Workaround: X11 does not include current pressed/released modifier key in 'mods' flags. https://github.com/glfw/glfw/issues/1630 - if (int keycode_to_mod = ImGui_ImplGlfw_KeyToModifier(keycode)) - mods = (action == GLFW_PRESS) ? (mods | keycode_to_mod) : (mods & ~keycode_to_mod); - ImGui_ImplGlfw_UpdateKeyModifiers(mods); + ImGui_ImplGlfw_UpdateKeyModifiers(window); if (keycode >= 0 && keycode < IM_ARRAYSIZE(bd->KeyOwnerWindows)) - bd->KeyOwnerWindows[keycode] = (action == GLFW_PRESS) ? window : NULL; + bd->KeyOwnerWindows[keycode] = (action == GLFW_PRESS) ? window : nullptr; keycode = ImGui_ImplGlfw_TranslateUntranslatedKey(keycode, scancode); @@ -373,7 +406,7 @@ void ImGui_ImplGlfw_KeyCallback(GLFWwindow* window, int keycode, int scancode, i void ImGui_ImplGlfw_WindowFocusCallback(GLFWwindow* window, int focused) { ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData(); - if (bd->PrevUserCallbackWindowFocus != NULL && window == bd->Window) + if (bd->PrevUserCallbackWindowFocus != nullptr && ImGui_ImplGlfw_ShouldChainCallback(window)) bd->PrevUserCallbackWindowFocus(window, focused); ImGuiIO& io = ImGui::GetIO(); @@ -383,8 +416,10 @@ void ImGui_ImplGlfw_WindowFocusCallback(GLFWwindow* window, int focused) void ImGui_ImplGlfw_CursorPosCallback(GLFWwindow* window, double x, double y) { ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData(); - if (bd->PrevUserCallbackCursorPos != NULL && window == bd->Window) + if (bd->PrevUserCallbackCursorPos != nullptr && ImGui_ImplGlfw_ShouldChainCallback(window)) bd->PrevUserCallbackCursorPos(window, x, y); + if (glfwGetInputMode(window, GLFW_CURSOR) == GLFW_CURSOR_DISABLED) + return; ImGuiIO& io = ImGui::GetIO(); if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) @@ -403,8 +438,10 @@ void ImGui_ImplGlfw_CursorPosCallback(GLFWwindow* window, double x, double y) void ImGui_ImplGlfw_CursorEnterCallback(GLFWwindow* window, int entered) { ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData(); - if (bd->PrevUserCallbackCursorEnter != NULL && window == bd->Window) + if (bd->PrevUserCallbackCursorEnter != nullptr && ImGui_ImplGlfw_ShouldChainCallback(window)) bd->PrevUserCallbackCursorEnter(window, entered); + if (glfwGetInputMode(window, GLFW_CURSOR) == GLFW_CURSOR_DISABLED) + return; ImGuiIO& io = ImGui::GetIO(); if (entered) @@ -415,7 +452,7 @@ void ImGui_ImplGlfw_CursorEnterCallback(GLFWwindow* window, int entered) else if (!entered && bd->MouseWindow == window) { bd->LastValidMousePos = io.MousePos; - bd->MouseWindow = NULL; + bd->MouseWindow = nullptr; io.AddMousePosEvent(-FLT_MAX, -FLT_MAX); } } @@ -423,7 +460,7 @@ void ImGui_ImplGlfw_CursorEnterCallback(GLFWwindow* window, int entered) void ImGui_ImplGlfw_CharCallback(GLFWwindow* window, unsigned int c) { ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData(); - if (bd->PrevUserCallbackChar != NULL && window == bd->Window) + if (bd->PrevUserCallbackChar != nullptr && ImGui_ImplGlfw_ShouldChainCallback(window)) bd->PrevUserCallbackChar(window, c); ImGuiIO& io = ImGui::GetIO(); @@ -436,6 +473,69 @@ void ImGui_ImplGlfw_MonitorCallback(GLFWmonitor*, int) bd->WantUpdateMonitors = true; } +#ifdef __EMSCRIPTEN__ +static EM_BOOL ImGui_ImplEmscripten_WheelCallback(int, const EmscriptenWheelEvent* ev, void*) +{ + // Mimic Emscripten_HandleWheel() in SDL. + // Corresponding equivalent in GLFW JS emulation layer has incorrect quantizing preventing small values. See #6096 + float multiplier = 0.0f; + if (ev->deltaMode == DOM_DELTA_PIXEL) { multiplier = 1.0f / 100.0f; } // 100 pixels make up a step. + else if (ev->deltaMode == DOM_DELTA_LINE) { multiplier = 1.0f / 3.0f; } // 3 lines make up a step. + else if (ev->deltaMode == DOM_DELTA_PAGE) { multiplier = 80.0f; } // A page makes up 80 steps. + float wheel_x = ev->deltaX * -multiplier; + float wheel_y = ev->deltaY * -multiplier; + ImGuiIO& io = ImGui::GetIO(); + io.AddMouseWheelEvent(wheel_x, wheel_y); + //IMGUI_DEBUG_LOG("[Emsc] mode %d dx: %.2f, dy: %.2f, dz: %.2f --> feed %.2f %.2f\n", (int)ev->deltaMode, ev->deltaX, ev->deltaY, ev->deltaZ, wheel_x, wheel_y); + return EM_TRUE; +} +#endif + +#ifdef _WIN32 +// GLFW doesn't allow to distinguish Mouse vs TouchScreen vs Pen. +// Add support for Win32 (based on imgui_impl_win32), because we rely on _TouchScreen info to trickle inputs differently. +static ImGuiMouseSource GetMouseSourceFromMessageExtraInfo() +{ + LPARAM extra_info = ::GetMessageExtraInfo(); + if ((extra_info & 0xFFFFFF80) == 0xFF515700) + return ImGuiMouseSource_Pen; + if ((extra_info & 0xFFFFFF80) == 0xFF515780) + return ImGuiMouseSource_TouchScreen; + return ImGuiMouseSource_Mouse; +} +static LRESULT CALLBACK ImGui_ImplGlfw_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData(); + switch (msg) + { + case WM_MOUSEMOVE: case WM_NCMOUSEMOVE: + case WM_LBUTTONDOWN: case WM_LBUTTONDBLCLK: case WM_LBUTTONUP: + case WM_RBUTTONDOWN: case WM_RBUTTONDBLCLK: case WM_RBUTTONUP: + case WM_MBUTTONDOWN: case WM_MBUTTONDBLCLK: case WM_MBUTTONUP: + case WM_XBUTTONDOWN: case WM_XBUTTONDBLCLK: case WM_XBUTTONUP: + ImGui::GetIO().AddMouseSourceEvent(GetMouseSourceFromMessageExtraInfo()); + break; + + // We have submitted https://github.com/glfw/glfw/pull/1568 to allow GLFW to support "transparent inputs". + // In the meanwhile we implement custom per-platform workarounds here (FIXME-VIEWPORT: Implement same work-around for Linux/OSX!) +#if !GLFW_HAS_MOUSE_PASSTHROUGH && GLFW_HAS_WINDOW_HOVERED + case WM_NCHITTEST: + { + // Let mouse pass-through the window. This will allow the backend to call io.AddMouseViewportEvent() properly (which is OPTIONAL). + // The ImGuiViewportFlags_NoInputs flag is set while dragging a viewport, as want to detect the window behind the one we are dragging. + // If you cannot easily access those viewport flags from your windowing/event code: you may manually synchronize its state e.g. in + // your main loop after calling UpdatePlatformWindows(). Iterate all viewports/platform windows and pass the flag to your windowing system. + ImGuiViewport* viewport = (ImGuiViewport*)::GetPropA(hWnd, "IMGUI_VIEWPORT"); + if (viewport && (viewport->Flags & ImGuiViewportFlags_NoInputs)) + return HTTRANSPARENT; + break; + } +#endif + } + return ::CallWindowProc(bd->GlfwWndProc, hWnd, msg, wParam, lParam); +} +#endif + void ImGui_ImplGlfw_InstallCallbacks(GLFWwindow* window) { ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData(); @@ -468,20 +568,31 @@ void ImGui_ImplGlfw_RestoreCallbacks(GLFWwindow* window) glfwSetCharCallback(window, bd->PrevUserCallbackChar); glfwSetMonitorCallback(bd->PrevUserCallbackMonitor); bd->InstalledCallbacks = false; - bd->PrevUserCallbackWindowFocus = NULL; - bd->PrevUserCallbackCursorEnter = NULL; - bd->PrevUserCallbackCursorPos = NULL; - bd->PrevUserCallbackMousebutton = NULL; - bd->PrevUserCallbackScroll = NULL; - bd->PrevUserCallbackKey = NULL; - bd->PrevUserCallbackChar = NULL; - bd->PrevUserCallbackMonitor = NULL; + bd->PrevUserCallbackWindowFocus = nullptr; + bd->PrevUserCallbackCursorEnter = nullptr; + bd->PrevUserCallbackCursorPos = nullptr; + bd->PrevUserCallbackMousebutton = nullptr; + bd->PrevUserCallbackScroll = nullptr; + bd->PrevUserCallbackKey = nullptr; + bd->PrevUserCallbackChar = nullptr; + bd->PrevUserCallbackMonitor = nullptr; +} + +// Set to 'true' to enable chaining installed callbacks for all windows (including secondary viewports created by backends or by user. +// This is 'false' by default meaning we only chain callbacks for the main viewport. +// We cannot set this to 'true' by default because user callbacks code may be not testing the 'window' parameter of their callback. +// If you set this to 'true' your user callback code will need to make sure you are testing the 'window' parameter. +void ImGui_ImplGlfw_SetCallbacksChainForAllWindows(bool chain_for_all_windows) +{ + ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData(); + bd->CallbacksChainForAllWindows = chain_for_all_windows; } static bool ImGui_ImplGlfw_Init(GLFWwindow* window, bool install_callbacks, GlfwClientApi client_api) { ImGuiIO& io = ImGui::GetIO(); - IM_ASSERT(io.BackendPlatformUserData == NULL && "Already initialized a platform backend!"); + IM_ASSERT(io.BackendPlatformUserData == nullptr && "Already initialized a platform backend!"); + //printf("GLFW_VERSION: %d.%d.%d (%d)", GLFW_VERSION_MAJOR, GLFW_VERSION_MINOR, GLFW_VERSION_REVISION, GLFW_VERSION_COMBINED); // Setup backend capabilities flags ImGui_ImplGlfw_Data* bd = IM_NEW(ImGui_ImplGlfw_Data)(); @@ -489,7 +600,9 @@ static bool ImGui_ImplGlfw_Init(GLFWwindow* window, bool install_callbacks, Glfw io.BackendPlatformName = "imgui_impl_glfw"; io.BackendFlags |= ImGuiBackendFlags_HasMouseCursors; // We can honor GetMouseCursor() values (optional) io.BackendFlags |= ImGuiBackendFlags_HasSetMousePos; // We can honor io.WantSetMousePos requests (optional, rarely used) +#ifndef __EMSCRIPTEN__ io.BackendFlags |= ImGuiBackendFlags_PlatformHasViewports; // We can create multi-viewports on the Platform side (optional) +#endif #if GLFW_HAS_MOUSE_PASSTHROUGH || (GLFW_HAS_WINDOW_HOVERED && defined(_WIN32)) io.BackendFlags |= ImGuiBackendFlags_HasMouseHoveredViewport; // We can call io.AddMouseViewportEvent() with correct data (optional) #endif @@ -505,8 +618,8 @@ static bool ImGui_ImplGlfw_Init(GLFWwindow* window, bool install_callbacks, Glfw // Create mouse cursors // (By design, on X11 cursors are user configurable and some cursors may be missing. When a cursor doesn't exist, // GLFW will emit an error which will often be printed by the app, so we temporarily disable error reporting. - // Missing cursors will return NULL and our _UpdateMouseCursor() function will use the Arrow cursor instead.) - GLFWerrorfun prev_error_callback = glfwSetErrorCallback(NULL); + // Missing cursors will return nullptr and our _UpdateMouseCursor() function will use the Arrow cursor instead.) + GLFWerrorfun prev_error_callback = glfwSetErrorCallback(nullptr); bd->MouseCursors[ImGuiMouseCursor_Arrow] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR); bd->MouseCursors[ImGuiMouseCursor_TextInput] = glfwCreateStandardCursor(GLFW_IBEAM_CURSOR); bd->MouseCursors[ImGuiMouseCursor_ResizeNS] = glfwCreateStandardCursor(GLFW_VRESIZE_CURSOR); @@ -524,24 +637,44 @@ static bool ImGui_ImplGlfw_Init(GLFWwindow* window, bool install_callbacks, Glfw bd->MouseCursors[ImGuiMouseCursor_NotAllowed] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR); #endif glfwSetErrorCallback(prev_error_callback); +#if GLFW_HAS_GETERROR && !defined(__EMSCRIPTEN__) // Eat errors (see #5908) + (void)glfwGetError(nullptr); +#endif // Chain GLFW callbacks: our callbacks will call the user's previously installed callbacks, if any. if (install_callbacks) ImGui_ImplGlfw_InstallCallbacks(window); + // Register Emscripten Wheel callback to workaround issue in Emscripten GLFW Emulation (#6096) + // We intentionally do not check 'if (install_callbacks)' here, as some users may set it to false and call GLFW callback themselves. + // FIXME: May break chaining in case user registered their own Emscripten callback? +#ifdef __EMSCRIPTEN__ + emscripten_set_wheel_callback(EMSCRIPTEN_EVENT_TARGET_DOCUMENT, nullptr, false, ImGui_ImplEmscripten_WheelCallback); +#endif // Update monitors the first time (note: monitor callback are broken in GLFW 3.2 and earlier, see github.com/glfw/glfw/issues/784) ImGui_ImplGlfw_UpdateMonitors(); glfwSetMonitorCallback(ImGui_ImplGlfw_MonitorCallback); - // Our mouse update function expect PlatformHandle to be filled for the main viewport + // Set platform dependent data in viewport ImGuiViewport* main_viewport = ImGui::GetMainViewport(); main_viewport->PlatformHandle = (void*)bd->Window; #ifdef _WIN32 main_viewport->PlatformHandleRaw = glfwGetWin32Window(bd->Window); +#elif defined(__APPLE__) + main_viewport->PlatformHandleRaw = (void*)glfwGetCocoaWindow(bd->Window); +#else + IM_UNUSED(main_viewport); #endif if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) ImGui_ImplGlfw_InitPlatformInterface(); + // Windows: register a WndProc hook so we can intercept some messages. +#ifdef _WIN32 + bd->GlfwWndProc = (WNDPROC)::GetWindowLongPtr((HWND)main_viewport->PlatformHandleRaw, GWLP_WNDPROC); + IM_ASSERT(bd->GlfwWndProc != nullptr); + ::SetWindowLongPtr((HWND)main_viewport->PlatformHandleRaw, GWLP_WNDPROC, (LONG_PTR)ImGui_ImplGlfw_WndProc); +#endif + bd->ClientApi = client_api; return true; } @@ -564,7 +697,7 @@ bool ImGui_ImplGlfw_InitForOther(GLFWwindow* window, bool install_callbacks) void ImGui_ImplGlfw_Shutdown() { ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData(); - IM_ASSERT(bd != NULL && "No platform backend to shutdown, or already shutdown?"); + IM_ASSERT(bd != nullptr && "No platform backend to shutdown, or already shutdown?"); ImGuiIO& io = ImGui::GetIO(); ImGui_ImplGlfw_ShutdownPlatformInterface(); @@ -575,8 +708,16 @@ void ImGui_ImplGlfw_Shutdown() for (ImGuiMouseCursor cursor_n = 0; cursor_n < ImGuiMouseCursor_COUNT; cursor_n++) glfwDestroyCursor(bd->MouseCursors[cursor_n]); - io.BackendPlatformName = NULL; - io.BackendPlatformUserData = NULL; + // Windows: register a WndProc hook so we can intercept some messages. +#ifdef _WIN32 + ImGuiViewport* main_viewport = ImGui::GetMainViewport(); + ::SetWindowLongPtr((HWND)main_viewport->PlatformHandleRaw, GWLP_WNDPROC, (LONG_PTR)bd->GlfwWndProc); + bd->GlfwWndProc = nullptr; +#endif + + io.BackendPlatformName = nullptr; + io.BackendPlatformUserData = nullptr; + io.BackendFlags &= ~(ImGuiBackendFlags_HasMouseCursors | ImGuiBackendFlags_HasSetMousePos | ImGuiBackendFlags_HasGamepad | ImGuiBackendFlags_PlatformHasViewports | ImGuiBackendFlags_HasMouseHoveredViewport); IM_DELETE(bd); } @@ -586,6 +727,12 @@ static void ImGui_ImplGlfw_UpdateMouseData() ImGuiIO& io = ImGui::GetIO(); ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO(); + if (glfwGetInputMode(bd->Window, GLFW_CURSOR) == GLFW_CURSOR_DISABLED) + { + io.AddMousePosEvent(-FLT_MAX, -FLT_MAX); + return; + } + ImGuiID mouse_viewport_id = 0; const ImVec2 mouse_pos_prev = io.MousePos; for (int n = 0; n < platform_io.Viewports.Size; n++) @@ -606,7 +753,7 @@ static void ImGui_ImplGlfw_UpdateMouseData() glfwSetCursorPos(window, (double)(mouse_pos_prev.x - viewport->Pos.x), (double)(mouse_pos_prev.y - viewport->Pos.y)); // (Optional) Fallback to provide mouse position when focused (ImGui_ImplGlfw_CursorPosCallback already provides this when hovered or captured) - if (bd->MouseWindow == NULL) + if (bd->MouseWindow == nullptr) { double mouse_x, mouse_y; glfwGetCursorPos(window, &mouse_x, &mouse_y); @@ -682,11 +829,11 @@ static inline float Saturate(float v) { return v < 0.0f ? 0.0f : v > 1.0f ? 1.0 static void ImGui_ImplGlfw_UpdateGamepads() { ImGuiIO& io = ImGui::GetIO(); - if ((io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) == 0) + if ((io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) == 0) // FIXME: Technically feeding gamepad shouldn't depend on this now that they are regular inputs. return; io.BackendFlags &= ~ImGuiBackendFlags_HasGamepad; -#if GLFW_HAS_GAMEPAD_API +#if GLFW_HAS_GAMEPAD_API && !defined(__EMSCRIPTEN__) GLFWgamepadstate gamepad; if (!glfwGetGamepadState(GLFW_JOYSTICK_1, &gamepad)) return; @@ -704,10 +851,10 @@ static void ImGui_ImplGlfw_UpdateGamepads() io.BackendFlags |= ImGuiBackendFlags_HasGamepad; MAP_BUTTON(ImGuiKey_GamepadStart, GLFW_GAMEPAD_BUTTON_START, 7); MAP_BUTTON(ImGuiKey_GamepadBack, GLFW_GAMEPAD_BUTTON_BACK, 6); - MAP_BUTTON(ImGuiKey_GamepadFaceDown, GLFW_GAMEPAD_BUTTON_A, 0); // Xbox A, PS Cross - MAP_BUTTON(ImGuiKey_GamepadFaceRight, GLFW_GAMEPAD_BUTTON_B, 1); // Xbox B, PS Circle MAP_BUTTON(ImGuiKey_GamepadFaceLeft, GLFW_GAMEPAD_BUTTON_X, 2); // Xbox X, PS Square + MAP_BUTTON(ImGuiKey_GamepadFaceRight, GLFW_GAMEPAD_BUTTON_B, 1); // Xbox B, PS Circle MAP_BUTTON(ImGuiKey_GamepadFaceUp, GLFW_GAMEPAD_BUTTON_Y, 3); // Xbox Y, PS Triangle + MAP_BUTTON(ImGuiKey_GamepadFaceDown, GLFW_GAMEPAD_BUTTON_A, 0); // Xbox A, PS Cross MAP_BUTTON(ImGuiKey_GamepadDpadLeft, GLFW_GAMEPAD_BUTTON_DPAD_LEFT, 13); MAP_BUTTON(ImGuiKey_GamepadDpadRight, GLFW_GAMEPAD_BUTTON_DPAD_RIGHT, 11); MAP_BUTTON(ImGuiKey_GamepadDpadUp, GLFW_GAMEPAD_BUTTON_DPAD_UP, 10); @@ -734,8 +881,13 @@ static void ImGui_ImplGlfw_UpdateMonitors() { ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData(); ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO(); + bd->WantUpdateMonitors = false; + int monitors_count = 0; GLFWmonitor** glfw_monitors = glfwGetMonitors(&monitors_count); + if (monitors_count == 0) // Preserve existing monitor list if there are none. Happens on macOS sleeping (#5683) + return; + platform_io.Monitors.resize(0); for (int n = 0; n < monitors_count; n++) { @@ -743,6 +895,8 @@ static void ImGui_ImplGlfw_UpdateMonitors() int x, y; glfwGetMonitorPos(glfw_monitors[n], &x, &y); const GLFWvidmode* vid_mode = glfwGetVideoMode(glfw_monitors[n]); + if (vid_mode == nullptr) + continue; // Failed to get Video mode (e.g. Emscripten does not support this function) monitor.MainPos = monitor.WorkPos = ImVec2((float)x, (float)y); monitor.MainSize = monitor.WorkSize = ImVec2((float)vid_mode->width, (float)vid_mode->height); #if GLFW_HAS_MONITOR_WORK_AREA @@ -760,16 +914,16 @@ static void ImGui_ImplGlfw_UpdateMonitors() glfwGetMonitorContentScale(glfw_monitors[n], &x_scale, &y_scale); monitor.DpiScale = x_scale; #endif + monitor.PlatformHandle = (void*)glfw_monitors[n]; // [...] GLFW doc states: "guaranteed to be valid only until the monitor configuration changes" platform_io.Monitors.push_back(monitor); } - bd->WantUpdateMonitors = false; } void ImGui_ImplGlfw_NewFrame() { ImGuiIO& io = ImGui::GetIO(); ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData(); - IM_ASSERT(bd != NULL && "Did you call ImGui_ImplGlfw_InitForXXX()?"); + IM_ASSERT(bd != nullptr && "Did you call ImGui_ImplGlfw_InitForXXX()?"); // Setup display size (every frame to accommodate for window resizing) int w, h; @@ -800,7 +954,7 @@ void ImGui_ImplGlfw_NewFrame() // If you are new to dear imgui or creating a new binding for dear imgui, it is recommended that you completely ignore this section first.. //-------------------------------------------------------------------------------------------------------- -// Helper structure we store in the void* RenderUserData field of each ImGuiViewport to easily retrieve our backend data. +// Helper structure we store in the void* RendererUserData field of each ImGuiViewport to easily retrieve our backend data. struct ImGui_ImplGlfw_ViewportData { GLFWwindow* Window; @@ -808,8 +962,8 @@ struct ImGui_ImplGlfw_ViewportData int IgnoreWindowPosEventFrame; int IgnoreWindowSizeEventFrame; - ImGui_ImplGlfw_ViewportData() { Window = NULL; WindowOwned = false; IgnoreWindowSizeEventFrame = IgnoreWindowPosEventFrame = -1; } - ~ImGui_ImplGlfw_ViewportData() { IM_ASSERT(Window == NULL); } + ImGui_ImplGlfw_ViewportData() { Window = nullptr; WindowOwned = false; IgnoreWindowSizeEventFrame = IgnoreWindowPosEventFrame = -1; } + ~ImGui_ImplGlfw_ViewportData() { IM_ASSERT(Window == nullptr); } }; static void ImGui_ImplGlfw_WindowCloseCallback(GLFWwindow* window) @@ -871,12 +1025,14 @@ static void ImGui_ImplGlfw_CreateWindow(ImGuiViewport* viewport) #if GLFW_HAS_WINDOW_TOPMOST glfwWindowHint(GLFW_FLOATING, (viewport->Flags & ImGuiViewportFlags_TopMost) ? true : false); #endif - GLFWwindow* share_window = (bd->ClientApi == GlfwClientApi_OpenGL) ? bd->Window : NULL; - vd->Window = glfwCreateWindow((int)viewport->Size.x, (int)viewport->Size.y, "No Title Yet", NULL, share_window); + GLFWwindow* share_window = (bd->ClientApi == GlfwClientApi_OpenGL) ? bd->Window : nullptr; + vd->Window = glfwCreateWindow((int)viewport->Size.x, (int)viewport->Size.y, "No Title Yet", nullptr, share_window); vd->WindowOwned = true; viewport->PlatformHandle = (void*)vd->Window; #ifdef _WIN32 viewport->PlatformHandleRaw = glfwGetWin32Window(vd->Window); +#elif defined(__APPLE__) + viewport->PlatformHandleRaw = (void*)glfwGetCocoaWindow(vd->Window); #endif glfwSetWindowPos(vd->Window, (int)viewport->Pos.x, (int)viewport->Pos.y); @@ -918,32 +1074,12 @@ static void ImGui_ImplGlfw_DestroyWindow(ImGuiViewport* viewport) glfwDestroyWindow(vd->Window); } - vd->Window = NULL; + vd->Window = nullptr; IM_DELETE(vd); } - viewport->PlatformUserData = viewport->PlatformHandle = NULL; + viewport->PlatformUserData = viewport->PlatformHandle = nullptr; } -// We have submitted https://github.com/glfw/glfw/pull/1568 to allow GLFW to support "transparent inputs". -// In the meanwhile we implement custom per-platform workarounds here (FIXME-VIEWPORT: Implement same work-around for Linux/OSX!) -#if !GLFW_HAS_MOUSE_PASSTHROUGH && GLFW_HAS_WINDOW_HOVERED && defined(_WIN32) -static WNDPROC g_GlfwWndProc = NULL; -static LRESULT CALLBACK WndProcNoInputs(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) -{ - if (msg == WM_NCHITTEST) - { - // Let mouse pass-through the window. This will allow the backend to call io.AddMouseViewportEvent() properly (which is OPTIONAL). - // The ImGuiViewportFlags_NoInputs flag is set while dragging a viewport, as want to detect the window behind the one we are dragging. - // If you cannot easily access those viewport flags from your windowing/event code: you may manually synchronize its state e.g. in - // your main loop after calling UpdatePlatformWindows(). Iterate all viewports/platform windows and pass the flag to your windowing system. - ImGuiViewport* viewport = (ImGuiViewport*)::GetPropA(hWnd, "IMGUI_VIEWPORT"); - if (viewport->Flags & ImGuiViewportFlags_NoInputs) - return HTTRANSPARENT; - } - return ::CallWindowProc(g_GlfwWndProc, hWnd, msg, wParam, lParam); -} -#endif - static void ImGui_ImplGlfw_ShowWindow(ImGuiViewport* viewport) { ImGui_ImplGlfw_ViewportData* vd = (ImGui_ImplGlfw_ViewportData*)viewport->PlatformUserData; @@ -961,10 +1097,10 @@ static void ImGui_ImplGlfw_ShowWindow(ImGuiViewport* viewport) // GLFW hack: install hook for WM_NCHITTEST message handler #if !GLFW_HAS_MOUSE_PASSTHROUGH && GLFW_HAS_WINDOW_HOVERED && defined(_WIN32) + ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData(); ::SetPropA(hwnd, "IMGUI_VIEWPORT", viewport); - if (g_GlfwWndProc == NULL) - g_GlfwWndProc = (WNDPROC)::GetWindowLongPtr(hwnd, GWLP_WNDPROC); - ::SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)WndProcNoInputs); + IM_ASSERT(bd->GlfwWndProc == (WNDPROC)::GetWindowLongPtr(hwnd, GWLP_WNDPROC)); + ::SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)ImGui_ImplGlfw_WndProc); #endif #if !GLFW_HAS_FOCUS_ON_SHOW diff --git a/extern/imgui_patched/backends/imgui_impl_glfw.h b/extern/imgui_patched/backends/imgui_impl_glfw.h index b96f3ee2..2e3b8bf2 100644 --- a/extern/imgui_patched/backends/imgui_impl_glfw.h +++ b/extern/imgui_patched/backends/imgui_impl_glfw.h @@ -5,6 +5,7 @@ // Implemented features: // [X] Platform: Clipboard support. +// [X] Platform: Mouse support. Can discriminate Mouse/TouchScreen/Pen (Windows only). // [X] Platform: Keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(ImGuiKey_Space). [Legacy GLFW_KEY_* values will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set] // [X] Platform: Gamepad support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'. // [x] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange' (note: the resizing cursors requires GLFW 3.4+). @@ -18,10 +19,6 @@ // If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp. // Read online: https://github.com/ocornut/imgui/tree/master/docs -// About GLSL version: -// The 'glsl_version' initialization parameter defaults to "#version 150" if NULL. -// Only override if your GL version doesn't handle this GLSL version. Keep NULL if unsure! - #pragma once #include "imgui.h" // IMGUI_IMPL_API @@ -34,13 +31,17 @@ IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForOther(GLFWwindow* window, bool ins IMGUI_IMPL_API void ImGui_ImplGlfw_Shutdown(); IMGUI_IMPL_API void ImGui_ImplGlfw_NewFrame(); -// GLFW callbacks (installer) +// GLFW callbacks install // - When calling Init with 'install_callbacks=true': ImGui_ImplGlfw_InstallCallbacks() is called. GLFW callbacks will be installed for you. They will chain-call user's previously installed callbacks, if any. // - When calling Init with 'install_callbacks=false': GLFW callbacks won't be installed. You will need to call individual function yourself from your own GLFW callbacks. IMGUI_IMPL_API void ImGui_ImplGlfw_InstallCallbacks(GLFWwindow* window); IMGUI_IMPL_API void ImGui_ImplGlfw_RestoreCallbacks(GLFWwindow* window); -// GLFW callbacks (individual callbacks to call if you didn't install callbacks) +// GFLW callbacks options: +// - Set 'chain_for_all_windows=true' to enable chaining callbacks for all windows (including secondary viewports created by backends or by user) +IMGUI_IMPL_API void ImGui_ImplGlfw_SetCallbacksChainForAllWindows(bool chain_for_all_windows); + +// GLFW callbacks (individual callbacks to call yourself if you didn't install callbacks) IMGUI_IMPL_API void ImGui_ImplGlfw_WindowFocusCallback(GLFWwindow* window, int focused); // Since 1.84 IMGUI_IMPL_API void ImGui_ImplGlfw_CursorEnterCallback(GLFWwindow* window, int entered); // Since 1.84 IMGUI_IMPL_API void ImGui_ImplGlfw_CursorPosCallback(GLFWwindow* window, double x, double y); // Since 1.87 diff --git a/extern/imgui_patched/backends/imgui_impl_glut.cpp b/extern/imgui_patched/backends/imgui_impl_glut.cpp index 1bf036b5..3f911a13 100644 --- a/extern/imgui_patched/backends/imgui_impl_glut.cpp +++ b/extern/imgui_patched/backends/imgui_impl_glut.cpp @@ -9,6 +9,7 @@ // [X] Platform: Partial keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(ImGuiKey_Space). [Legacy GLUT values will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set] // Issues: // [ ] Platform: GLUT is unable to distinguish e.g. Backspace from CTRL+H or TAB from CTRL+I +// [ ] Platform: Missing horizontal mouse wheel support. // [ ] Platform: Missing mouse cursor shape/visibility support. // [ ] Platform: Missing clipboard support (not supported by Glut). // [ ] Platform: Missing gamepad support. @@ -20,6 +21,8 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) +// 2023-04-17: BREAKING: Removed call to ImGui::NewFrame() from ImGui_ImplGLUT_NewFrame(). Needs to be called from the main application loop, like with every other backends. +// 2022-09-26: Inputs: Renamed ImGuiKey_ModXXX introduced in 1.87 to ImGuiMod_XXX (old names still supported). // 2022-01-26: Inputs: replaced short-lived io.AddKeyModsEvent() (added two weeks ago) with io.AddKeyEvent() using ImGuiKey_ModXXX flags. Sorry for the confusion. // 2022-01-17: Inputs: calling new io.AddMousePosEvent(), io.AddMouseButtonEvent(), io.AddMouseWheelEvent() API (1.87+). // 2022-01-10: Inputs: calling new io.AddKeyEvent(), io.AddKeyModsEvent() + io.SetKeyEventNativeData() API (1.87+). Support for full ImGuiKey range. @@ -30,6 +33,7 @@ #include "imgui.h" #include "imgui_impl_glut.h" +#define GL_SILENCE_DEPRECATION #ifdef __APPLE__ #include #else @@ -187,6 +191,8 @@ void ImGui_ImplGLUT_InstallFuncs() void ImGui_ImplGLUT_Shutdown() { + ImGuiIO& io = ImGui::GetIO(); + io.BackendPlatformName = nullptr; } void ImGui_ImplGLUT_NewFrame() @@ -199,18 +205,15 @@ void ImGui_ImplGLUT_NewFrame() delta_time_ms = 1; io.DeltaTime = delta_time_ms / 1000.0f; g_Time = current_time; - - // Start the frame - ImGui::NewFrame(); } static void ImGui_ImplGLUT_UpdateKeyModifiers() { ImGuiIO& io = ImGui::GetIO(); int glut_key_mods = glutGetModifiers(); - io.AddKeyEvent(ImGuiKey_ModCtrl, (glut_key_mods & GLUT_ACTIVE_CTRL) != 0); - io.AddKeyEvent(ImGuiKey_ModShift, (glut_key_mods & GLUT_ACTIVE_SHIFT) != 0); - io.AddKeyEvent(ImGuiKey_ModAlt, (glut_key_mods & GLUT_ACTIVE_ALT) != 0); + io.AddKeyEvent(ImGuiMod_Ctrl, (glut_key_mods & GLUT_ACTIVE_CTRL) != 0); + io.AddKeyEvent(ImGuiMod_Shift, (glut_key_mods & GLUT_ACTIVE_SHIFT) != 0); + io.AddKeyEvent(ImGuiMod_Alt, (glut_key_mods & GLUT_ACTIVE_ALT) != 0); } static void ImGui_ImplGLUT_AddKeyEvent(ImGuiKey key, bool down, int native_keycode) diff --git a/extern/imgui_patched/backends/imgui_impl_glut.h b/extern/imgui_patched/backends/imgui_impl_glut.h index 98d4e598..545cd8dd 100644 --- a/extern/imgui_patched/backends/imgui_impl_glut.h +++ b/extern/imgui_patched/backends/imgui_impl_glut.h @@ -9,6 +9,7 @@ // [X] Platform: Partial keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(ImGuiKey_Space). [Legacy GLUT values will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set] // Issues: // [ ] Platform: GLUT is unable to distinguish e.g. Backspace from CTRL+H or TAB from CTRL+I +// [ ] Platform: Missing horizontal mouse wheel support. // [ ] Platform: Missing mouse cursor shape/visibility support. // [ ] Platform: Missing clipboard support (not supported by Glut). // [ ] Platform: Missing gamepad support. diff --git a/extern/imgui_patched/backends/imgui_impl_metal.h b/extern/imgui_patched/backends/imgui_impl_metal.h index 8407290f..a281f6a2 100644 --- a/extern/imgui_patched/backends/imgui_impl_metal.h +++ b/extern/imgui_patched/backends/imgui_impl_metal.h @@ -6,7 +6,7 @@ // [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices. // [X] Renderer: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'. -// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. +// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. // If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp. // Read online: https://github.com/ocornut/imgui/tree/master/docs @@ -45,9 +45,7 @@ IMGUI_IMPL_API void ImGui_ImplMetal_DestroyDeviceObjects(); // More info about using Metal from C++: https://developer.apple.com/metal/cpp/ #ifdef IMGUI_IMPL_METAL_CPP - #include - #ifndef __OBJC__ IMGUI_IMPL_API bool ImGui_ImplMetal_Init(MTL::Device* device); @@ -64,5 +62,4 @@ IMGUI_IMPL_API bool ImGui_ImplMetal_CreateDeviceObjects(MTL::Device* device); IMGUI_IMPL_API void ImGui_ImplMetal_DestroyDeviceObjects(); #endif - #endif diff --git a/extern/imgui_patched/backends/imgui_impl_metal.mm b/extern/imgui_patched/backends/imgui_impl_metal.mm index fbe04a15..521a01ac 100644 --- a/extern/imgui_patched/backends/imgui_impl_metal.mm +++ b/extern/imgui_patched/backends/imgui_impl_metal.mm @@ -13,7 +13,11 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) -// 2022-XX-XX: Metal: Added support for multiple windows via the ImGuiPlatformIO interface. +// 2023-XX-XX: Metal: Added support for multiple windows via the ImGuiPlatformIO interface. +// 2022-08-23: Metal: Update deprecated property 'sampleCount'->'rasterSampleCount'. +// 2022-07-05: Metal: Add dispatch synchronization. +// 2022-06-30: Metal: Use __bridge for ARC based systems. +// 2022-06-01: Metal: Fixed null dereference on exit inside command buffer completion handler. // 2022-04-27: Misc: Store backend data in a per-context struct, allowing to use this backend with multiple contexts. // 2022-01-03: Metal: Ignore ImDrawCmd where ElemCount == 0 (very rare but can technically be manufactured by user code). // 2021-12-30: Metal: Added Metal C++ support. Enable with '#define IMGUI_IMPL_METAL_CPP' in your imconfig.h file. @@ -74,16 +78,16 @@ static void ImGui_ImplMetal_InvalidateDeviceObjectsForPlatformWindows(); struct ImGui_ImplMetal_Data { - MetalContext* SharedMetalContext; + MetalContext* SharedMetalContext; - ImGui_ImplMetal_Data() { memset(this, 0, sizeof(*this)); } + ImGui_ImplMetal_Data() { memset(this, 0, sizeof(*this)); } }; -static ImGui_ImplMetal_Data* ImGui_ImplMetal_CreateBackendData() { return IM_NEW(ImGui_ImplMetal_Data)(); } -static ImGui_ImplMetal_Data* ImGui_ImplMetal_GetBackendData() { return ImGui::GetCurrentContext() ? (ImGui_ImplMetal_Data*)ImGui::GetIO().BackendRendererUserData : NULL; } -static void ImGui_ImplMetal_DestroyBackendData() { IM_DELETE(ImGui_ImplMetal_GetBackendData()); } +static ImGui_ImplMetal_Data* ImGui_ImplMetal_CreateBackendData() { return IM_NEW(ImGui_ImplMetal_Data)(); } +static ImGui_ImplMetal_Data* ImGui_ImplMetal_GetBackendData() { return ImGui::GetCurrentContext() ? (ImGui_ImplMetal_Data*)ImGui::GetIO().BackendRendererUserData : nullptr; } +static void ImGui_ImplMetal_DestroyBackendData(){ IM_DELETE(ImGui_ImplMetal_GetBackendData()); } -static inline CFTimeInterval GetMachAbsoluteTimeInSeconds() { return static_cast(static_cast(clock_gettime_nsec_np(CLOCK_UPTIME_RAW)) / 1e9); } +static inline CFTimeInterval GetMachAbsoluteTimeInSeconds() { return (CFTimeInterval)(double)(clock_gettime_nsec_np(CLOCK_UPTIME_RAW) / 1e9); } #ifdef IMGUI_IMPL_METAL_CPP @@ -91,12 +95,12 @@ static inline CFTimeInterval GetMachAbsoluteTimeInSeconds() { return s bool ImGui_ImplMetal_Init(MTL::Device* device) { - return ImGui_ImplMetal_Init((id)(device)); + return ImGui_ImplMetal_Init((__bridge id)(device)); } void ImGui_ImplMetal_NewFrame(MTL::RenderPassDescriptor* renderPassDescriptor) { - ImGui_ImplMetal_NewFrame((MTLRenderPassDescriptor*)(renderPassDescriptor)); + ImGui_ImplMetal_NewFrame((__bridge MTLRenderPassDescriptor*)(renderPassDescriptor)); } void ImGui_ImplMetal_RenderDrawData(ImDrawData* draw_data, @@ -104,19 +108,19 @@ void ImGui_ImplMetal_RenderDrawData(ImDrawData* draw_data, MTL::RenderCommandEncoder* commandEncoder) { ImGui_ImplMetal_RenderDrawData(draw_data, - (id)(commandBuffer), - (id)(commandEncoder)); + (__bridge id)(commandBuffer), + (__bridge id)(commandEncoder)); } bool ImGui_ImplMetal_CreateFontsTexture(MTL::Device* device) { - return ImGui_ImplMetal_CreateFontsTexture((id)(device)); + return ImGui_ImplMetal_CreateFontsTexture((__bridge id)(device)); } bool ImGui_ImplMetal_CreateDeviceObjects(MTL::Device* device) { - return ImGui_ImplMetal_CreateDeviceObjects((id)(device)); + return ImGui_ImplMetal_CreateDeviceObjects((__bridge id)(device)); } #endif // #ifdef IMGUI_IMPL_METAL_CPP @@ -143,9 +147,16 @@ bool ImGui_ImplMetal_Init(id device) void ImGui_ImplMetal_Shutdown() { + ImGui_ImplMetal_Data* bd = ImGui_ImplMetal_GetBackendData(); + IM_ASSERT(bd != nullptr && "No renderer backend to shutdown, or already shutdown?"); ImGui_ImplMetal_ShutdownPlatformInterface(); ImGui_ImplMetal_DestroyDeviceObjects(); ImGui_ImplMetal_DestroyBackendData(); + + ImGuiIO& io = ImGui::GetIO(); + io.BackendRendererName = nullptr; + io.BackendRendererUserData = nullptr; + io.BackendFlags &= ~(ImGuiBackendFlags_RendererHasVtxOffset | ImGuiBackendFlags_RendererHasViewports); } void ImGui_ImplMetal_NewFrame(MTLRenderPassDescriptor* renderPassDescriptor) @@ -306,8 +317,14 @@ void ImGui_ImplMetal_RenderDrawData(ImDrawData* drawData, id c { dispatch_async(dispatch_get_main_queue(), ^{ ImGui_ImplMetal_Data* bd = ImGui_ImplMetal_GetBackendData(); - [bd->SharedMetalContext.bufferCache addObject:vertexBuffer]; - [bd->SharedMetalContext.bufferCache addObject:indexBuffer]; + if (bd != nullptr) + { + @synchronized(bd->SharedMetalContext.bufferCache) + { + [bd->SharedMetalContext.bufferCache addObject:vertexBuffer]; + [bd->SharedMetalContext.bufferCache addObject:indexBuffer]; + } + } }); }]; } @@ -347,7 +364,7 @@ void ImGui_ImplMetal_DestroyFontsTexture() ImGui_ImplMetal_Data* bd = ImGui_ImplMetal_GetBackendData(); ImGuiIO& io = ImGui::GetIO(); bd->SharedMetalContext.fontTexture = nil; - io.Fonts->SetTexID(nullptr); + io.Fonts->SetTexID(0); } bool ImGui_ImplMetal_CreateDeviceObjects(id device) @@ -390,7 +407,7 @@ struct ImGuiViewportDataMetal CAMetalLayer* MetalLayer; id CommandQueue; MTLRenderPassDescriptor* RenderPassDescriptor; - void* Handle = NULL; + void* Handle = nullptr; bool FirstFrame = true; }; @@ -401,15 +418,15 @@ static void ImGui_ImplMetal_CreateWindow(ImGuiViewport* viewport) viewport->RendererUserData = data; // PlatformHandleRaw should always be a NSWindow*, whereas PlatformHandle might be a higher-level handle (e.g. GLFWWindow*, SDL_Window*). - // Some back-ends will leave PlatformHandleRaw NULL, in which case we assume PlatformHandle will contain the NSWindow*. + // Some back-ends will leave PlatformHandleRaw == 0, in which case we assume PlatformHandle will contain the NSWindow*. void* handle = viewport->PlatformHandleRaw ? viewport->PlatformHandleRaw : viewport->PlatformHandle; - IM_ASSERT(handle != NULL); + IM_ASSERT(handle != nullptr); - id device = [bd->SharedMetalContext.depthStencilState device]; + id device = bd->SharedMetalContext.device; CAMetalLayer* layer = [CAMetalLayer layer]; layer.device = device; layer.framebufferOnly = YES; - layer.pixelFormat = MTLPixelFormatBGRA8Unorm; + layer.pixelFormat = bd->SharedMetalContext.framebufferDescriptor.colorPixelFormat; #if TARGET_OS_OSX NSWindow* window = (__bridge NSWindow*)handle; NSView* view = window.contentView; @@ -424,10 +441,10 @@ static void ImGui_ImplMetal_CreateWindow(ImGuiViewport* viewport) static void ImGui_ImplMetal_DestroyWindow(ImGuiViewport* viewport) { - // The main viewport (owned by the application) will always have RendererUserData == NULL since we didn't create the data for it. + // The main viewport (owned by the application) will always have RendererUserData == 0 since we didn't create the data for it. if (ImGuiViewportDataMetal* data = (ImGuiViewportDataMetal*)viewport->RendererUserData) IM_DELETE(data); - viewport->RendererUserData = NULL; + viewport->RendererUserData = nullptr; } inline static CGSize MakeScaledSize(CGSize size, CGFloat scale) @@ -458,7 +475,7 @@ static void ImGui_ImplMetal_RenderWindow(ImGuiViewport* viewport, void*) } data->FirstFrame = false; - viewport->DpiScale = static_cast(window.backingScaleFactor); + viewport->DpiScale = (float)window.backingScaleFactor; if (data->MetalLayer.contentsScale != viewport->DpiScale) { data->MetalLayer.contentsScale = viewport->DpiScale; @@ -585,8 +602,8 @@ static void ImGui_ImplMetal_InvalidateDeviceObjectsForPlatformWindows() { if ((self = [super init])) { - _renderPipelineStateCache = [NSMutableDictionary dictionary]; - _bufferCache = [NSMutableArray array]; + self.renderPipelineStateCache = [NSMutableDictionary dictionary]; + self.bufferCache = [NSMutableArray array]; _lastBufferCachePurge = GetMachAbsoluteTimeInSeconds(); } return self; @@ -596,28 +613,31 @@ static void ImGui_ImplMetal_InvalidateDeviceObjectsForPlatformWindows() { uint64_t now = GetMachAbsoluteTimeInSeconds(); - // Purge old buffers that haven't been useful for a while - if (now - self.lastBufferCachePurge > 1.0) + @synchronized(self.bufferCache) { - NSMutableArray* survivors = [NSMutableArray array]; + // Purge old buffers that haven't been useful for a while + if (now - self.lastBufferCachePurge > 1.0) + { + NSMutableArray* survivors = [NSMutableArray array]; + for (MetalBuffer* candidate in self.bufferCache) + if (candidate.lastReuseTime > self.lastBufferCachePurge) + [survivors addObject:candidate]; + self.bufferCache = [survivors mutableCopy]; + self.lastBufferCachePurge = now; + } + + // See if we have a buffer we can reuse + MetalBuffer* bestCandidate = nil; for (MetalBuffer* candidate in self.bufferCache) - if (candidate.lastReuseTime > self.lastBufferCachePurge) - [survivors addObject:candidate]; - self.bufferCache = [survivors mutableCopy]; - self.lastBufferCachePurge = now; - } + if (candidate.buffer.length >= length && (bestCandidate == nil || bestCandidate.lastReuseTime > candidate.lastReuseTime)) + bestCandidate = candidate; - // See if we have a buffer we can reuse - MetalBuffer* bestCandidate = nil; - for (MetalBuffer* candidate in self.bufferCache) - if (candidate.buffer.length >= length && (bestCandidate == nil || bestCandidate.lastReuseTime > candidate.lastReuseTime)) - bestCandidate = candidate; - - if (bestCandidate != nil) - { - [self.bufferCache removeObject:bestCandidate]; - bestCandidate.lastReuseTime = now; - return bestCandidate; + if (bestCandidate != nil) + { + [self.bufferCache removeObject:bestCandidate]; + bestCandidate.lastReuseTime = now; + return bestCandidate; + } } // No luck; make a new buffer @@ -700,7 +720,7 @@ static void ImGui_ImplMetal_InvalidateDeviceObjectsForPlatformWindows() pipelineDescriptor.vertexFunction = vertexFunction; pipelineDescriptor.fragmentFunction = fragmentFunction; pipelineDescriptor.vertexDescriptor = vertexDescriptor; - pipelineDescriptor.sampleCount = self.framebufferDescriptor.sampleCount; + pipelineDescriptor.rasterSampleCount = self.framebufferDescriptor.sampleCount; pipelineDescriptor.colorAttachments[0].pixelFormat = self.framebufferDescriptor.colorPixelFormat; pipelineDescriptor.colorAttachments[0].blendingEnabled = YES; pipelineDescriptor.colorAttachments[0].rgbBlendOperation = MTLBlendOperationAdd; diff --git a/extern/imgui_patched/backends/imgui_impl_opengl2.cpp b/extern/imgui_patched/backends/imgui_impl_opengl2.cpp index ccd00554..47e7aef9 100644 --- a/extern/imgui_patched/backends/imgui_impl_opengl2.cpp +++ b/extern/imgui_patched/backends/imgui_impl_opengl2.cpp @@ -20,7 +20,8 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) -// 2022-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface. +// 2023-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface. +// 2022-10-11: Using 'nullptr' instead of 'NULL' as per our switch to C++11. // 2021-12-08: OpenGL: Fixed mishandling of the the ImDrawCmd::IdxOffset field! This is an old bug but it never had an effect until some internal rendering changes in 1.86. // 2021-06-29: Reorganized backend to pull data from a single structure to facilitate usage with multiple-contexts (all g_XXXX access changed to bd->XXXX). // 2021-05-19: OpenGL: Replaced direct access to ImDrawCmd::TextureId with a call to ImDrawCmd::GetTexID(). (will become a requirement) @@ -45,6 +46,13 @@ #include // intptr_t #endif +// Clang/GCC warnings with -Weverything +#if defined(__clang__) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunused-macros" // warning: macro is not used +#pragma clang diagnostic ignored "-Wnonportable-system-include-path" +#endif + // Include OpenGL header (without an OpenGL loader) requires a bit of fiddling #if defined(_WIN32) && !defined(APIENTRY) #define APIENTRY __stdcall // It is customary to use APIENTRY for OpenGL function pointer declarations on all platforms. Additionally, the Windows OpenGL header needs APIENTRY. @@ -70,7 +78,7 @@ struct ImGui_ImplOpenGL2_Data // It is STRONGLY preferred that you use docking branch with multi-viewports (== single Dear ImGui context + multiple windows) instead of multiple Dear ImGui contexts. static ImGui_ImplOpenGL2_Data* ImGui_ImplOpenGL2_GetBackendData() { - return ImGui::GetCurrentContext() ? (ImGui_ImplOpenGL2_Data*)ImGui::GetIO().BackendRendererUserData : NULL; + return ImGui::GetCurrentContext() ? (ImGui_ImplOpenGL2_Data*)ImGui::GetIO().BackendRendererUserData : nullptr; } // Forward Declarations @@ -81,7 +89,7 @@ static void ImGui_ImplOpenGL2_ShutdownPlatformInterface(); bool ImGui_ImplOpenGL2_Init() { ImGuiIO& io = ImGui::GetIO(); - IM_ASSERT(io.BackendRendererUserData == NULL && "Already initialized a renderer backend!"); + IM_ASSERT(io.BackendRendererUserData == nullptr && "Already initialized a renderer backend!"); // Setup backend capabilities flags ImGui_ImplOpenGL2_Data* bd = IM_NEW(ImGui_ImplOpenGL2_Data)(); @@ -98,20 +106,21 @@ bool ImGui_ImplOpenGL2_Init() void ImGui_ImplOpenGL2_Shutdown() { ImGui_ImplOpenGL2_Data* bd = ImGui_ImplOpenGL2_GetBackendData(); - IM_ASSERT(bd != NULL && "No renderer backend to shutdown, or already shutdown?"); + IM_ASSERT(bd != nullptr && "No renderer backend to shutdown, or already shutdown?"); ImGuiIO& io = ImGui::GetIO(); ImGui_ImplOpenGL2_ShutdownPlatformInterface(); ImGui_ImplOpenGL2_DestroyDeviceObjects(); - io.BackendRendererName = NULL; - io.BackendRendererUserData = NULL; + io.BackendRendererName = nullptr; + io.BackendRendererUserData = nullptr; + io.BackendFlags &= ~ImGuiBackendFlags_RendererHasViewports; IM_DELETE(bd); } void ImGui_ImplOpenGL2_NewFrame() { ImGui_ImplOpenGL2_Data* bd = ImGui_ImplOpenGL2_GetBackendData(); - IM_ASSERT(bd != NULL && "Did you call ImGui_ImplOpenGL2_Init()?"); + IM_ASSERT(bd != nullptr && "Did you call ImGui_ImplOpenGL2_Init()?"); if (!bd->FontTexture) ImGui_ImplOpenGL2_CreateDeviceObjects(); @@ -219,7 +228,7 @@ void ImGui_ImplOpenGL2_RenderDrawData(ImDrawData* draw_data) continue; // Apply scissor/clipping rectangle (Y is inverted in OpenGL) - glScissor((int)clip_min.x, (int)(fb_height - clip_max.y), (int)(clip_max.x - clip_min.x), (int)(clip_max.y - clip_min.y)); + glScissor((int)clip_min.x, (int)((float)fb_height - clip_max.y), (int)(clip_max.x - clip_min.x), (int)(clip_max.y - clip_min.y)); // Bind texture, Draw glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->GetTexID()); @@ -323,3 +332,7 @@ static void ImGui_ImplOpenGL2_ShutdownPlatformInterface() { ImGui::DestroyPlatformWindows(); } + +#if defined(__clang__) +#pragma clang diagnostic pop +#endif diff --git a/extern/imgui_patched/backends/imgui_impl_opengl3.cpp b/extern/imgui_patched/backends/imgui_impl_opengl3.cpp index 0e8d53d5..2ff3e262 100644 --- a/extern/imgui_patched/backends/imgui_impl_opengl3.cpp +++ b/extern/imgui_patched/backends/imgui_impl_opengl3.cpp @@ -5,8 +5,13 @@ // Implemented features: // [X] Renderer: User texture binding. Use 'GLuint' OpenGL texture identifier as void*/ImTextureID. Read the FAQ about ImTextureID! +// [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices (Desktop OpenGL only). // [X] Renderer: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'. -// [x] Renderer: Large meshes support (64k+ vertices) with 16-bit indices (Desktop OpenGL only). + +// About WebGL/ES: +// - You need to '#define IMGUI_IMPL_OPENGL_ES2' or '#define IMGUI_IMPL_OPENGL_ES3' to use WebGL or OpenGL ES. +// - This is done automatically on iOS, Android and Emscripten targets. +// - For other targets, the define needs to be visible from the imgui_impl_opengl3.cpp compilation unit. If unsure, define globally or in imconfig.h. // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. @@ -15,8 +20,17 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) -// 2022-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface. -// 2022-05-13: OpenGL: Fix state corruption on OpenGL ES 2.0 due to not preserving GL_ELEMENT_ARRAY_BUFFER_BINDING and vertex attribute states. +// 2023-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface. +// 2023-05-09: OpenGL: Support for glBindSampler() backup/restore on ES3. (#6375) +// 2023-04-18: OpenGL: Restore front and back polygon mode separately when supported by context. (#6333) +// 2023-03-23: OpenGL: Properly restoring "no shader program bound" if it was the case prior to running the rendering function. (#6267, #6220, #6224) +// 2023-03-15: OpenGL: Fixed GL loader crash when GL_VERSION returns NULL. (#6154, #4445, #3530) +// 2023-03-06: OpenGL: Fixed restoration of a potentially deleted OpenGL program, by calling glIsProgram(). (#6220, #6224) +// 2022-11-09: OpenGL: Reverted use of glBufferSubData(), too many corruptions issues + old issues seemingly can't be reproed with Intel drivers nowadays (revert 2021-12-15 and 2022-05-23 changes). +// 2022-10-11: Using 'nullptr' instead of 'NULL' as per our switch to C++11. +// 2022-09-27: OpenGL: Added ability to '#define IMGUI_IMPL_OPENGL_DEBUG'. +// 2022-05-23: OpenGL: Reworking 2021-12-15 "Using buffer orphaning" so it only happens on Intel GPU, seems to cause problems otherwise. (#4468, #4825, #4832, #5127). +// 2022-05-13: OpenGL: Fixed state corruption on OpenGL ES 2.0 due to not preserving GL_ELEMENT_ARRAY_BUFFER_BINDING and vertex attribute states. // 2021-12-15: OpenGL: Using buffer orphaning + glBufferSubData(), seems to fix leaks with multi-viewports with some Intel HD drivers. // 2021-08-23: OpenGL: Fixed ES 3.0 shader ("#version 300 es") use normal precision floats to avoid wobbly rendering at HD resolutions. // 2021-08-19: OpenGL: Embed and use our own minimal GL loader (imgui_impl_opengl3_loader.h), removing requirement and support for third-party loader. @@ -57,7 +71,7 @@ // 2018-06-08: Misc: Extracted imgui_impl_opengl3.cpp/.h away from the old combined GLFW/SDL+OpenGL3 examples. // 2018-06-08: OpenGL: Use draw_data->DisplayPos and draw_data->DisplaySize to setup projection matrix and clipping rectangle. // 2018-05-25: OpenGL: Removed unnecessary backup/restore of GL_ELEMENT_ARRAY_BUFFER_BINDING since this is part of the VAO state. -// 2018-05-14: OpenGL: Making the call to glBindSampler() optional so 3.2 context won't fail if the function is a NULL pointer. +// 2018-05-14: OpenGL: Making the call to glBindSampler() optional so 3.2 context won't fail if the function is a nullptr pointer. // 2018-03-06: OpenGL: Added const char* glsl_version parameter to ImGui_ImplOpenGL3_Init() so user can override the GLSL version e.g. "#version 150". // 2018-02-23: OpenGL: Create the VAO in the render function so the setup can more easily be used with multiple shared GL context. // 2018-02-16: Misc: Obsoleted the io.RenderDrawListsFn callback and exposed ImGui_ImplSdlGL3_RenderDrawData() in the .h file so you can call it yourself. @@ -98,15 +112,24 @@ #else #include // intptr_t #endif +#if defined(__APPLE__) +#include +#endif -// Clang warnings with -Weverything +// Clang/GCC warnings with -Weverything #if defined(__clang__) #pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wold-style-cast" // warning: use of old-style cast -#pragma clang diagnostic ignored "-Wsign-conversion" // warning: implicit conversion changes signedness -#if __has_warning("-Wzero-as-null-pointer-constant") -#pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant" +#pragma clang diagnostic ignored "-Wold-style-cast" // warning: use of old-style cast +#pragma clang diagnostic ignored "-Wsign-conversion" // warning: implicit conversion changes signedness +#pragma clang diagnostic ignored "-Wunused-macros" // warning: macro is not used +#pragma clang diagnostic ignored "-Wnonportable-system-include-path" +//#pragma clang diagnostic ignored "-Wcast-function-type" // warning: cast between incompatible function types (for loader) #endif +#if defined(__GNUC__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wpragmas" // warning: unknown option after '#pragma GCC diagnostic' kind +#pragma GCC diagnostic ignored "-Wunknown-warning-option" // warning: unknown warning group 'xxx' +#pragma GCC diagnostic ignored "-Wcast-function-type" // warning: cast between incompatible function types (for loader) #endif // GL includes @@ -123,9 +146,6 @@ #include #endif #elif defined(IMGUI_IMPL_OPENGL_ES3) -#if defined(__APPLE__) -#include -#endif #if (defined(__APPLE__) && (TARGET_OS_IOS || TARGET_OS_TV)) #include // Use GL ES 3 #else @@ -164,8 +184,8 @@ #define IMGUI_IMPL_OPENGL_MAY_HAVE_VTX_OFFSET #endif -// Desktop GL 3.3+ has glBindSampler() -#if !defined(IMGUI_IMPL_OPENGL_ES2) && !defined(IMGUI_IMPL_OPENGL_ES3) && defined(GL_VERSION_3_3) +// Desktop GL 3.3+ and GL ES 3.0+ have glBindSampler() +#if !defined(IMGUI_IMPL_OPENGL_ES2) && (defined(IMGUI_IMPL_OPENGL_ES3) || defined(GL_VERSION_3_3)) #define IMGUI_IMPL_OPENGL_MAY_HAVE_BIND_SAMPLER #endif @@ -179,11 +199,24 @@ #define IMGUI_IMPL_OPENGL_MAY_HAVE_EXTENSIONS #endif +// [Debugging] +//#define IMGUI_IMPL_OPENGL_DEBUG +#ifdef IMGUI_IMPL_OPENGL_DEBUG +#include +#define GL_CALL(_CALL) do { _CALL; GLenum gl_err = glGetError(); if (gl_err != 0) fprintf(stderr, "GL error 0x%x returned from '%s'.\n", gl_err, #_CALL); } while (0) // Call with error check +#else +#define GL_CALL(_CALL) _CALL // Call without error check +#endif + // OpenGL Data struct ImGui_ImplOpenGL3_Data { GLuint GlVersion; // Extracted at runtime using GL_MAJOR_VERSION, GL_MINOR_VERSION queries (e.g. 320 for GL 3.2) char GlslVersionString[32]; // Specified by user or detected based on compile time GL settings. + bool GlProfileIsES2; + bool GlProfileIsES3; + bool GlProfileIsCompat; + GLint GlProfileMask; GLuint FontTexture; GLuint ShaderHandle; GLint AttribLocationTex; // Uniforms location @@ -195,6 +228,7 @@ struct ImGui_ImplOpenGL3_Data GLsizeiptr VertexBufferSize; GLsizeiptr IndexBufferSize; bool HasClipOrigin; + bool UseBufferSubData; ImGui_ImplOpenGL3_Data() { memset((void*)this, 0, sizeof(*this)); } }; @@ -203,7 +237,7 @@ struct ImGui_ImplOpenGL3_Data // It is STRONGLY preferred that you use docking branch with multi-viewports (== single Dear ImGui context + multiple windows) instead of multiple Dear ImGui contexts. static ImGui_ImplOpenGL3_Data* ImGui_ImplOpenGL3_GetBackendData() { - return ImGui::GetCurrentContext() ? (ImGui_ImplOpenGL3_Data*)ImGui::GetIO().BackendRendererUserData : NULL; + return ImGui::GetCurrentContext() ? (ImGui_ImplOpenGL3_Data*)ImGui::GetIO().BackendRendererUserData : nullptr; } // Forward Declarations @@ -238,7 +272,7 @@ struct ImGui_ImplOpenGL3_VtxAttribState bool ImGui_ImplOpenGL3_Init(const char* glsl_version) { ImGuiIO& io = ImGui::GetIO(); - IM_ASSERT(io.BackendRendererUserData == NULL && "Already initialized a renderer backend!"); + IM_ASSERT(io.BackendRendererUserData == nullptr && "Already initialized a renderer backend!"); // Initialize our loader #if !defined(IMGUI_IMPL_OPENGL_ES2) && !defined(IMGUI_IMPL_OPENGL_ES3) && !defined(IMGUI_IMPL_OPENGL_LOADER_CUSTOM) @@ -267,8 +301,30 @@ bool ImGui_ImplOpenGL3_Init(const char* glsl_version) sscanf(gl_version, "%d.%d", &major, &minor); } bd->GlVersion = (GLuint)(major * 100 + minor * 10); -#else +#if defined(GL_CONTEXT_PROFILE_MASK) + glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &bd->GlProfileMask); + bd->GlProfileIsCompat = (bd->GlProfileMask & GL_CONTEXT_COMPATIBILITY_PROFILE_BIT) != 0; +#endif + + bd->UseBufferSubData = false; + /* + // Query vendor to enable glBufferSubData kludge +#ifdef _WIN32 + if (const char* vendor = (const char*)glGetString(GL_VENDOR)) + if (strncmp(vendor, "Intel", 5) == 0) + bd->UseBufferSubData = true; +#endif + */ +#elif defined(IMGUI_IMPL_OPENGL_ES2) bd->GlVersion = 200; // GLES 2 + bd->GlProfileIsES2 = true; +#elif defined(IMGUI_IMPL_OPENGL_ES3) + bd->GlVersion = 200; // Don't raise version as it is intended as a desktop version check for now. + bd->GlProfileIsES3 = true; +#endif + +#ifdef IMGUI_IMPL_OPENGL_DEBUG + printf("GL_MAJOR_VERSION = %d\nGL_MINOR_VERSION = %d\nGL_VENDOR = '%s'\nGL_RENDERER = '%s'\n", major, minor, (const char*)glGetString(GL_VENDOR), (const char*)glGetString(GL_RENDERER)); // [DEBUG] #endif #ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_VTX_OFFSET @@ -278,8 +334,8 @@ bool ImGui_ImplOpenGL3_Init(const char* glsl_version) io.BackendFlags |= ImGuiBackendFlags_RendererHasViewports; // We can create multi-viewports on the Renderer side (optional) // Store GLSL version string so we can refer to it later in case we recreate shaders. - // Note: GLSL version is NOT the same as GL version. Leave this to NULL if unsure. - if (glsl_version == NULL) + // Note: GLSL version is NOT the same as GL version. Leave this to nullptr if unsure. + if (glsl_version == nullptr) { #if defined(IMGUI_IMPL_OPENGL_ES2) glsl_version = "#version 100"; @@ -308,7 +364,7 @@ bool ImGui_ImplOpenGL3_Init(const char* glsl_version) for (GLint i = 0; i < num_extensions; i++) { const char* extension = (const char*)glGetStringi(GL_EXTENSIONS, i); - if (extension != NULL && strcmp(extension, "GL_ARB_clip_control") == 0) + if (extension != nullptr && strcmp(extension, "GL_ARB_clip_control") == 0) bd->HasClipOrigin = true; } #endif @@ -322,20 +378,21 @@ bool ImGui_ImplOpenGL3_Init(const char* glsl_version) void ImGui_ImplOpenGL3_Shutdown() { ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData(); - IM_ASSERT(bd != NULL && "No renderer backend to shutdown, or already shutdown?"); + IM_ASSERT(bd != nullptr && "No renderer backend to shutdown, or already shutdown?"); ImGuiIO& io = ImGui::GetIO(); ImGui_ImplOpenGL3_ShutdownPlatformInterface(); ImGui_ImplOpenGL3_DestroyDeviceObjects(); - io.BackendRendererName = NULL; - io.BackendRendererUserData = NULL; + io.BackendRendererName = nullptr; + io.BackendRendererUserData = nullptr; + io.BackendFlags &= ~(ImGuiBackendFlags_RendererHasVtxOffset | ImGuiBackendFlags_RendererHasViewports); IM_DELETE(bd); } void ImGui_ImplOpenGL3_NewFrame() { ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData(); - IM_ASSERT(bd != NULL && "Did you call ImGui_ImplOpenGL3_Init()?"); + IM_ASSERT(bd != nullptr && "Did you call ImGui_ImplOpenGL3_Init()?"); if (!bd->ShaderHandle) ImGui_ImplOpenGL3_CreateDeviceObjects(); @@ -374,7 +431,7 @@ static void ImGui_ImplOpenGL3_SetupRenderState(ImDrawData* draw_data, int fb_wid // Setup viewport, orthographic projection matrix // Our visible imgui space lies from draw_data->DisplayPos (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right). DisplayPos is (0,0) for single viewport apps. - glViewport(0, 0, (GLsizei)fb_width, (GLsizei)fb_height); + GL_CALL(glViewport(0, 0, (GLsizei)fb_width, (GLsizei)fb_height)); float L = draw_data->DisplayPos.x; float R = draw_data->DisplayPos.x + draw_data->DisplaySize.x; float T = draw_data->DisplayPos.y; @@ -394,8 +451,8 @@ static void ImGui_ImplOpenGL3_SetupRenderState(ImDrawData* draw_data, int fb_wid glUniformMatrix4fv(bd->AttribLocationProjMtx, 1, GL_FALSE, &ortho_projection[0][0]); #ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_BIND_SAMPLER - if (bd->GlVersion >= 330) - glBindSampler(0, 0); // We use combined texture/sampler state. Applications using GL 3.3 may set that otherwise. + if (bd->GlVersion >= 330 || bd->GlProfileIsES3) + glBindSampler(0, 0); // We use combined texture/sampler state. Applications using GL 3.3 and GL ES 3.0 may set that otherwise. #endif (void)vertex_array_object; @@ -404,14 +461,14 @@ static void ImGui_ImplOpenGL3_SetupRenderState(ImDrawData* draw_data, int fb_wid #endif // Bind vertex/index buffers and setup attributes for ImDrawVert - glBindBuffer(GL_ARRAY_BUFFER, bd->VboHandle); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bd->ElementsHandle); - glEnableVertexAttribArray(bd->AttribLocationVtxPos); - glEnableVertexAttribArray(bd->AttribLocationVtxUV); - glEnableVertexAttribArray(bd->AttribLocationVtxColor); - glVertexAttribPointer(bd->AttribLocationVtxPos, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*)IM_OFFSETOF(ImDrawVert, pos)); - glVertexAttribPointer(bd->AttribLocationVtxUV, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*)IM_OFFSETOF(ImDrawVert, uv)); - glVertexAttribPointer(bd->AttribLocationVtxColor, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(ImDrawVert), (GLvoid*)IM_OFFSETOF(ImDrawVert, col)); + GL_CALL(glBindBuffer(GL_ARRAY_BUFFER, bd->VboHandle)); + GL_CALL(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bd->ElementsHandle)); + GL_CALL(glEnableVertexAttribArray(bd->AttribLocationVtxPos)); + GL_CALL(glEnableVertexAttribArray(bd->AttribLocationVtxUV)); + GL_CALL(glEnableVertexAttribArray(bd->AttribLocationVtxColor)); + GL_CALL(glVertexAttribPointer(bd->AttribLocationVtxPos, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*)IM_OFFSETOF(ImDrawVert, pos))); + GL_CALL(glVertexAttribPointer(bd->AttribLocationVtxUV, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*)IM_OFFSETOF(ImDrawVert, uv))); + GL_CALL(glVertexAttribPointer(bd->AttribLocationVtxColor, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(ImDrawVert), (GLvoid*)IM_OFFSETOF(ImDrawVert, col))); } // OpenGL3 Render function. @@ -433,7 +490,7 @@ void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data) GLuint last_program; glGetIntegerv(GL_CURRENT_PROGRAM, (GLint*)&last_program); GLuint last_texture; glGetIntegerv(GL_TEXTURE_BINDING_2D, (GLint*)&last_texture); #ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_BIND_SAMPLER - GLuint last_sampler; if (bd->GlVersion >= 330) { glGetIntegerv(GL_SAMPLER_BINDING, (GLint*)&last_sampler); } else { last_sampler = 0; } + GLuint last_sampler; if (bd->GlVersion >= 330 || bd->GlProfileIsES3) { glGetIntegerv(GL_SAMPLER_BINDING, (GLint*)&last_sampler); } else { last_sampler = 0; } #endif GLuint last_array_buffer; glGetIntegerv(GL_ARRAY_BUFFER_BINDING, (GLint*)&last_array_buffer); #ifndef IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY @@ -471,7 +528,7 @@ void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data) // The renderer would actually work without any VAO bound, but then our VertexAttrib calls would overwrite the default one currently bound. GLuint vertex_array_object = 0; #ifdef IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY - glGenVertexArrays(1, &vertex_array_object); + GL_CALL(glGenVertexArrays(1, &vertex_array_object)); #endif ImGui_ImplOpenGL3_SetupRenderState(draw_data, fb_width, fb_height, vertex_array_object); @@ -485,25 +542,40 @@ void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data) const ImDrawList* cmd_list = draw_data->CmdLists[n]; // Upload vertex/index buffers - GLsizeiptr vtx_buffer_size = (GLsizeiptr)cmd_list->VtxBuffer.Size * (int)sizeof(ImDrawVert); - GLsizeiptr idx_buffer_size = (GLsizeiptr)cmd_list->IdxBuffer.Size * (int)sizeof(ImDrawIdx); - if (bd->VertexBufferSize < vtx_buffer_size) + // - OpenGL drivers are in a very sorry state nowadays.... + // During 2021 we attempted to switch from glBufferData() to orphaning+glBufferSubData() following reports + // of leaks on Intel GPU when using multi-viewports on Windows. + // - After this we kept hearing of various display corruptions issues. We started disabling on non-Intel GPU, but issues still got reported on Intel. + // - We are now back to using exclusively glBufferData(). So bd->UseBufferSubData IS ALWAYS FALSE in this code. + // We are keeping the old code path for a while in case people finding new issues may want to test the bd->UseBufferSubData path. + // - See https://github.com/ocornut/imgui/issues/4468 and please report any corruption issues. + const GLsizeiptr vtx_buffer_size = (GLsizeiptr)cmd_list->VtxBuffer.Size * (int)sizeof(ImDrawVert); + const GLsizeiptr idx_buffer_size = (GLsizeiptr)cmd_list->IdxBuffer.Size * (int)sizeof(ImDrawIdx); + if (bd->UseBufferSubData) { - bd->VertexBufferSize = vtx_buffer_size; - glBufferData(GL_ARRAY_BUFFER, bd->VertexBufferSize, NULL, GL_STREAM_DRAW); + if (bd->VertexBufferSize < vtx_buffer_size) + { + bd->VertexBufferSize = vtx_buffer_size; + GL_CALL(glBufferData(GL_ARRAY_BUFFER, bd->VertexBufferSize, nullptr, GL_STREAM_DRAW)); + } + if (bd->IndexBufferSize < idx_buffer_size) + { + bd->IndexBufferSize = idx_buffer_size; + GL_CALL(glBufferData(GL_ELEMENT_ARRAY_BUFFER, bd->IndexBufferSize, nullptr, GL_STREAM_DRAW)); + } + GL_CALL(glBufferSubData(GL_ARRAY_BUFFER, 0, vtx_buffer_size, (const GLvoid*)cmd_list->VtxBuffer.Data)); + GL_CALL(glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, idx_buffer_size, (const GLvoid*)cmd_list->IdxBuffer.Data)); } - if (bd->IndexBufferSize < idx_buffer_size) + else { - bd->IndexBufferSize = idx_buffer_size; - glBufferData(GL_ELEMENT_ARRAY_BUFFER, bd->IndexBufferSize, NULL, GL_STREAM_DRAW); + GL_CALL(glBufferData(GL_ARRAY_BUFFER, vtx_buffer_size, (const GLvoid*)cmd_list->VtxBuffer.Data, GL_STREAM_DRAW)); + GL_CALL(glBufferData(GL_ELEMENT_ARRAY_BUFFER, idx_buffer_size, (const GLvoid*)cmd_list->IdxBuffer.Data, GL_STREAM_DRAW)); } - glBufferSubData(GL_ARRAY_BUFFER, 0, vtx_buffer_size, (const GLvoid*)cmd_list->VtxBuffer.Data); - glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, idx_buffer_size, (const GLvoid*)cmd_list->IdxBuffer.Data); for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++) { const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i]; - if (pcmd->UserCallback != NULL) + if (pcmd->UserCallback != nullptr) { // User callback, registered via ImDrawList::AddCallback() // (ImDrawCallback_ResetRenderState is a special callback value used by the user to request the renderer to reset render state.) @@ -521,30 +593,31 @@ void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data) continue; // Apply scissor/clipping rectangle (Y is inverted in OpenGL) - glScissor((int)clip_min.x, (int)((float)fb_height - clip_max.y), (int)(clip_max.x - clip_min.x), (int)(clip_max.y - clip_min.y)); + GL_CALL(glScissor((int)clip_min.x, (int)((float)fb_height - clip_max.y), (int)(clip_max.x - clip_min.x), (int)(clip_max.y - clip_min.y))); // Bind texture, Draw - glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->GetTexID()); + GL_CALL(glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->GetTexID())); #ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_VTX_OFFSET if (bd->GlVersion >= 320) - glDrawElementsBaseVertex(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, (void*)(intptr_t)(pcmd->IdxOffset * sizeof(ImDrawIdx)), (GLint)pcmd->VtxOffset); + GL_CALL(glDrawElementsBaseVertex(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, (void*)(intptr_t)(pcmd->IdxOffset * sizeof(ImDrawIdx)), (GLint)pcmd->VtxOffset)); else #endif - glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, (void*)(intptr_t)(pcmd->IdxOffset * sizeof(ImDrawIdx))); + GL_CALL(glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, (void*)(intptr_t)(pcmd->IdxOffset * sizeof(ImDrawIdx)))); } } } // Destroy the temporary VAO #ifdef IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY - glDeleteVertexArrays(1, &vertex_array_object); + GL_CALL(glDeleteVertexArrays(1, &vertex_array_object)); #endif // Restore modified GL state - glUseProgram(last_program); + // This "glIsProgram()" check is required because if the program is "pending deletion" at the time of binding backup, it will have been deleted by now and will cause an OpenGL error. See #6220. + if (last_program == 0 || glIsProgram(last_program)) glUseProgram(last_program); glBindTexture(GL_TEXTURE_2D, last_texture); #ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_BIND_SAMPLER - if (bd->GlVersion >= 330) + if (bd->GlVersion >= 330 || bd->GlProfileIsES3) glBindSampler(0, last_sampler); #endif glActiveTexture(last_active_texture); @@ -570,8 +643,18 @@ void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data) #endif #ifdef IMGUI_IMPL_HAS_POLYGON_MODE - glPolygonMode(GL_FRONT_AND_BACK, (GLenum)last_polygon_mode[0]); -#endif + // Desktop OpenGL 3.0 and OpenGL 3.1 had separate polygon draw modes for front-facing and back-facing faces of polygons + if (bd->GlVersion <= 310 || bd->GlProfileIsCompat) + { + glPolygonMode(GL_FRONT, (GLenum)last_polygon_mode[0]); + glPolygonMode(GL_BACK, (GLenum)last_polygon_mode[1]); + } + else + { + glPolygonMode(GL_FRONT_AND_BACK, (GLenum)last_polygon_mode[0]); + } +#endif // IMGUI_IMPL_HAS_POLYGON_MODE + glViewport(last_viewport[0], last_viewport[1], (GLsizei)last_viewport[2], (GLsizei)last_viewport[3]); glScissor(last_scissor_box[0], last_scissor_box[1], (GLsizei)last_scissor_box[2], (GLsizei)last_scissor_box[3]); (void)bd; // Not all compilation paths use this @@ -590,21 +673,21 @@ bool ImGui_ImplOpenGL3_CreateFontsTexture() // Upload texture to graphics system // (Bilinear sampling is required by default. Set 'io.Fonts->Flags |= ImFontAtlasFlags_NoBakedLines' or 'style.AntiAliasedLinesUseTex = false' to allow point/nearest sampling) GLint last_texture; - glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture); - glGenTextures(1, &bd->FontTexture); - glBindTexture(GL_TEXTURE_2D, bd->FontTexture); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + GL_CALL(glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture)); + GL_CALL(glGenTextures(1, &bd->FontTexture)); + GL_CALL(glBindTexture(GL_TEXTURE_2D, bd->FontTexture)); + GL_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); + GL_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); #ifdef GL_UNPACK_ROW_LENGTH // Not on WebGL/ES - glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); + GL_CALL(glPixelStorei(GL_UNPACK_ROW_LENGTH, 0)); #endif - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); + GL_CALL(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels)); // Store our identifier io.Fonts->SetTexID((ImTextureID)(intptr_t)bd->FontTexture); // Restore state - glBindTexture(GL_TEXTURE_2D, last_texture); + GL_CALL(glBindTexture(GL_TEXTURE_2D, last_texture)); return true; } @@ -634,7 +717,7 @@ static bool CheckShader(GLuint handle, const char* desc) { ImVector buf; buf.resize((int)(log_length + 1)); - glGetShaderInfoLog(handle, log_length, NULL, (GLchar*)buf.begin()); + glGetShaderInfoLog(handle, log_length, nullptr, (GLchar*)buf.begin()); fprintf(stderr, "%s\n", buf.begin()); } return (GLboolean)status == GL_TRUE; @@ -653,7 +736,7 @@ static bool CheckProgram(GLuint handle, const char* desc) { ImVector buf; buf.resize((int)(log_length + 1)); - glGetProgramInfoLog(handle, log_length, NULL, (GLchar*)buf.begin()); + glGetProgramInfoLog(handle, log_length, nullptr, (GLchar*)buf.begin()); fprintf(stderr, "%s\n", buf.begin()); } return (GLboolean)status == GL_TRUE; @@ -777,8 +860,8 @@ bool ImGui_ImplOpenGL3_CreateDeviceObjects() "}\n"; // Select shaders matching our GLSL versions - const GLchar* vertex_shader = NULL; - const GLchar* fragment_shader = NULL; + const GLchar* vertex_shader = nullptr; + const GLchar* fragment_shader = nullptr; if (glsl_version < 130) { vertex_shader = vertex_shader_glsl_120; @@ -803,13 +886,13 @@ bool ImGui_ImplOpenGL3_CreateDeviceObjects() // Create shaders const GLchar* vertex_shader_with_version[2] = { bd->GlslVersionString, vertex_shader }; GLuint vert_handle = glCreateShader(GL_VERTEX_SHADER); - glShaderSource(vert_handle, 2, vertex_shader_with_version, NULL); + glShaderSource(vert_handle, 2, vertex_shader_with_version, nullptr); glCompileShader(vert_handle); CheckShader(vert_handle, "vertex shader"); const GLchar* fragment_shader_with_version[2] = { bd->GlslVersionString, fragment_shader }; GLuint frag_handle = glCreateShader(GL_FRAGMENT_SHADER); - glShaderSource(frag_handle, 2, fragment_shader_with_version, NULL); + glShaderSource(frag_handle, 2, fragment_shader_with_version, nullptr); glCompileShader(frag_handle); CheckShader(frag_handle, "fragment shader"); @@ -884,6 +967,9 @@ static void ImGui_ImplOpenGL3_ShutdownPlatformInterface() ImGui::DestroyPlatformWindows(); } +#if defined(__GNUC__) +#pragma GCC diagnostic pop +#endif #if defined(__clang__) #pragma clang diagnostic pop #endif diff --git a/extern/imgui_patched/backends/imgui_impl_opengl3.h b/extern/imgui_patched/backends/imgui_impl_opengl3.h index 81722bdf..1c7666c8 100644 --- a/extern/imgui_patched/backends/imgui_impl_opengl3.h +++ b/extern/imgui_patched/backends/imgui_impl_opengl3.h @@ -5,8 +5,13 @@ // Implemented features: // [X] Renderer: User texture binding. Use 'GLuint' OpenGL texture identifier as void*/ImTextureID. Read the FAQ about ImTextureID! +// [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices (Desktop OpenGL only). // [X] Renderer: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'. -// [x] Renderer: Large meshes support (64k+ vertices) with 16-bit indices (Desktop OpenGL only). + +// About WebGL/ES: +// - You need to '#define IMGUI_IMPL_OPENGL_ES2' or '#define IMGUI_IMPL_OPENGL_ES3' to use WebGL or OpenGL ES. +// - This is done automatically on iOS, Android and Emscripten targets. +// - For other targets, the define needs to be visible from the imgui_impl_opengl3.cpp compilation unit. If unsure, define globally or in imconfig.h. // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. @@ -14,7 +19,7 @@ // Read online: https://github.com/ocornut/imgui/tree/master/docs // About GLSL version: -// The 'glsl_version' initialization parameter should be NULL (default) or a "#version XXX" string. +// The 'glsl_version' initialization parameter should be nullptr (default) or a "#version XXX" string. // On computer platform the GLSL version default to "#version 130". On OpenGL ES 3 platform it defaults to "#version 300 es" // Only override if your GL version doesn't handle this GLSL version. See GLSL version table at the top of imgui_impl_opengl3.cpp. @@ -22,7 +27,7 @@ #include "imgui.h" // IMGUI_IMPL_API // Backend API -IMGUI_IMPL_API bool ImGui_ImplOpenGL3_Init(const char* glsl_version = NULL); +IMGUI_IMPL_API bool ImGui_ImplOpenGL3_Init(const char* glsl_version = nullptr); IMGUI_IMPL_API void ImGui_ImplOpenGL3_Shutdown(); IMGUI_IMPL_API void ImGui_ImplOpenGL3_NewFrame(); IMGUI_IMPL_API void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data); diff --git a/extern/imgui_patched/backends/imgui_impl_opengl3_loader.h b/extern/imgui_patched/backends/imgui_impl_opengl3_loader.h index 67ac389d..7ca72e37 100644 --- a/extern/imgui_patched/backends/imgui_impl_opengl3_loader.h +++ b/extern/imgui_patched/backends/imgui_impl_opengl3_loader.h @@ -9,6 +9,14 @@ // YOU SHOULD NOT NEED TO INCLUDE/USE THIS DIRECTLY. THIS IS USED BY imgui_impl_opengl3.cpp ONLY. // THE REST OF YOUR APP SHOULD USE A DIFFERENT GL LOADER: ANY GL LOADER OF YOUR CHOICE. // +// IF YOU GET BUILD ERRORS IN THIS FILE (commonly macro redefinitions or function redefinitions): +// IT LIKELY MEANS THAT YOU ARE BUILDING 'imgui_impl_opengl3.cpp' OR INCUDING 'imgui_impl_opengl3_loader.h' +// IN THE SAME COMPILATION UNIT AS ONE OF YOUR FILE WHICH IS USING A THIRD-PARTY OPENGL LOADER. +// (e.g. COULD HAPPEN IF YOU ARE DOING A UNITY/JUMBO BUILD, OR INCLUDING .CPP FILES FROM OTHERS) +// YOU SHOULD NOT BUILD BOTH IN THE SAME COMPILATION UNIT. +// BUT IF YOU REALLY WANT TO, you can '#define IMGUI_IMPL_OPENGL_LOADER_CUSTOM' and imgui_impl_opengl3.cpp +// WILL NOT BE USING OUR LOADER, AND INSTEAD EXPECT ANOTHER/YOUR LOADER TO BE AVAILABLE IN THE COMPILATION UNIT. +// // Regenerate with: // python gl3w_gen.py --output ../imgui/backends/imgui_impl_opengl3_loader.h --ref ../imgui/backends/imgui_impl_opengl3.cpp ./extra_symbols.txt // @@ -146,6 +154,8 @@ typedef khronos_uint8_t GLubyte; #define GL_ONE 1 #define GL_SRC_ALPHA 0x0302 #define GL_ONE_MINUS_SRC_ALPHA 0x0303 +#define GL_FRONT 0x0404 +#define GL_BACK 0x0405 #define GL_FRONT_AND_BACK 0x0408 #define GL_POLYGON_MODE 0x0B40 #define GL_CULL_FACE 0x0B44 @@ -164,6 +174,8 @@ typedef khronos_uint8_t GLubyte; #define GL_FLOAT 0x1406 #define GL_RGBA 0x1908 #define GL_FILL 0x1B02 +#define GL_VENDOR 0x1F00 +#define GL_RENDERER 0x1F01 #define GL_VERSION 0x1F02 #define GL_EXTENSIONS 0x1F03 #define GL_LINEAR 0x2601 @@ -299,6 +311,7 @@ typedef void (APIENTRYP PFNGLGETSHADERINFOLOGPROC) (GLuint shader, GLsizei bufSi typedef GLint (APIENTRYP PFNGLGETUNIFORMLOCATIONPROC) (GLuint program, const GLchar *name); typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIVPROC) (GLuint index, GLenum pname, GLint *params); typedef void (APIENTRYP PFNGLGETVERTEXATTRIBPOINTERVPROC) (GLuint index, GLenum pname, void **pointer); +typedef GLboolean (APIENTRYP PFNGLISPROGRAMPROC) (GLuint program); typedef void (APIENTRYP PFNGLLINKPROGRAMPROC) (GLuint program); typedef void (APIENTRYP PFNGLSHADERSOURCEPROC) (GLuint shader, GLsizei count, const GLchar *const*string, const GLint *length); typedef void (APIENTRYP PFNGLUSEPROGRAMPROC) (GLuint program); @@ -324,6 +337,7 @@ GLAPI void APIENTRY glGetShaderInfoLog (GLuint shader, GLsizei bufSize, GLsizei GLAPI GLint APIENTRY glGetUniformLocation (GLuint program, const GLchar *name); GLAPI void APIENTRY glGetVertexAttribiv (GLuint index, GLenum pname, GLint *params); GLAPI void APIENTRY glGetVertexAttribPointerv (GLuint index, GLenum pname, void **pointer); +GLAPI GLboolean APIENTRY glIsProgram (GLuint program); GLAPI void APIENTRY glLinkProgram (GLuint program); GLAPI void APIENTRY glShaderSource (GLuint shader, GLsizei count, const GLchar *const*string, const GLint *length); GLAPI void APIENTRY glUseProgram (GLuint program); @@ -361,6 +375,8 @@ GLAPI void APIENTRY glGenVertexArrays (GLsizei n, GLuint *arrays); typedef struct __GLsync *GLsync; typedef khronos_uint64_t GLuint64; typedef khronos_int64_t GLint64; +#define GL_CONTEXT_COMPATIBILITY_PROFILE_BIT 0x00000002 +#define GL_CONTEXT_PROFILE_MASK 0x9126 typedef void (APIENTRYP PFNGLDRAWELEMENTSBASEVERTEXPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLint basevertex); typedef void (APIENTRYP PFNGLGETINTEGER64I_VPROC) (GLenum target, GLuint index, GLint64 *data); #ifdef GL_GLEXT_PROTOTYPES @@ -452,7 +468,7 @@ GL3W_API GL3WglProc imgl3wGetProcAddress(const char *proc); /* gl3w internal state */ union GL3WProcs { - GL3WglProc ptr[58]; + GL3WglProc ptr[59]; struct { PFNGLACTIVETEXTUREPROC ActiveTexture; PFNGLATTACHSHADERPROC AttachShader; @@ -499,6 +515,7 @@ union GL3WProcs { PFNGLGETVERTEXATTRIBPOINTERVPROC GetVertexAttribPointerv; PFNGLGETVERTEXATTRIBIVPROC GetVertexAttribiv; PFNGLISENABLEDPROC IsEnabled; + PFNGLISPROGRAMPROC IsProgram; PFNGLLINKPROGRAMPROC LinkProgram; PFNGLPIXELSTOREIPROC PixelStorei; PFNGLPOLYGONMODEPROC PolygonMode; @@ -563,6 +580,7 @@ GL3W_API extern union GL3WProcs imgl3wProcs; #define glGetVertexAttribPointerv imgl3wProcs.gl.GetVertexAttribPointerv #define glGetVertexAttribiv imgl3wProcs.gl.GetVertexAttribiv #define glIsEnabled imgl3wProcs.gl.IsEnabled +#define glIsProgram imgl3wProcs.gl.IsProgram #define glLinkProgram imgl3wProcs.gl.LinkProgram #define glPixelStorei imgl3wProcs.gl.PixelStorei #define glPolygonMode imgl3wProcs.gl.PolygonMode @@ -675,7 +693,13 @@ static int parse_version(void) return GL3W_ERROR_INIT; glGetIntegerv(GL_MAJOR_VERSION, &version.major); glGetIntegerv(GL_MINOR_VERSION, &version.minor); - if (version.major < 3) + if (version.major == 0 && version.minor == 0) + { + // Query GL_VERSION in desktop GL 2.x, the string will start with "." + if (const char* gl_version = (const char*)glGetString(GL_VERSION)) + sscanf(gl_version, "%d.%d", &version.major, &version.minor); + } + if (version.major < 2) return GL3W_ERROR_OPENGL_VERSION; return GL3W_OK; } @@ -699,7 +723,7 @@ int imgl3wInit2(GL3WGetProcAddressProc proc) int imgl3wIsSupported(int major, int minor) { - if (major < 3) + if (major < 2) return 0; if (version.major == major) return version.minor >= minor; @@ -754,6 +778,7 @@ static const char *proc_names[] = { "glGetVertexAttribPointerv", "glGetVertexAttribiv", "glIsEnabled", + "glIsProgram", "glLinkProgram", "glPixelStorei", "glPolygonMode", diff --git a/extern/imgui_patched/backends/imgui_impl_osx.h b/extern/imgui_patched/backends/imgui_impl_osx.h index 18a7554f..08b6ab74 100644 --- a/extern/imgui_patched/backends/imgui_impl_osx.h +++ b/extern/imgui_patched/backends/imgui_impl_osx.h @@ -1,9 +1,11 @@ // dear imgui: Platform Backend for OSX / Cocoa // This needs to be used along with a Renderer (e.g. OpenGL2, OpenGL3, Vulkan, Metal..) -// [ALPHA] Early backend, not well tested. If you want a portable application, prefer using the GLFW or SDL platform Backends on Mac. +// - Not well tested. If you want a portable application, prefer using the GLFW or SDL platform Backends on Mac. +// - Requires linking with the GameController framework ("-framework GameController"). // Implemented features: // [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'. +// [X] Platform: Mouse support. Can discriminate Mouse/Pen. // [X] Platform: Keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(ImGuiKey_Space). [Legacy kVK_* values will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set] // [X] Platform: OSX clipboard is supported within core Dear ImGui (no specific code in this backend). // [X] Platform: Gamepad support. Enabled with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'. @@ -17,9 +19,28 @@ #include "imgui.h" // IMGUI_IMPL_API +#ifdef __OBJC__ + @class NSEvent; @class NSView; IMGUI_IMPL_API bool ImGui_ImplOSX_Init(NSView* _Nonnull view); IMGUI_IMPL_API void ImGui_ImplOSX_Shutdown(); IMGUI_IMPL_API void ImGui_ImplOSX_NewFrame(NSView* _Nullable view); + +#endif + +//----------------------------------------------------------------------------- +// C++ API +//----------------------------------------------------------------------------- + +#ifdef IMGUI_IMPL_METAL_CPP_EXTENSIONS +// #include +#ifndef __OBJC__ + +IMGUI_IMPL_API bool ImGui_ImplOSX_Init(void* _Nonnull view); +IMGUI_IMPL_API void ImGui_ImplOSX_Shutdown(); +IMGUI_IMPL_API void ImGui_ImplOSX_NewFrame(void* _Nullable view); + +#endif +#endif diff --git a/extern/imgui_patched/backends/imgui_impl_osx.mm b/extern/imgui_patched/backends/imgui_impl_osx.mm index 49526d9f..bfd0dba9 100644 --- a/extern/imgui_patched/backends/imgui_impl_osx.mm +++ b/extern/imgui_patched/backends/imgui_impl_osx.mm @@ -1,9 +1,11 @@ // dear imgui: Platform Backend for OSX / Cocoa // This needs to be used along with a Renderer (e.g. OpenGL2, OpenGL3, Vulkan, Metal..) -// [ALPHA] Early backend, not well tested. If you want a portable application, prefer using the GLFW or SDL platform Backends on Mac. +// - Not well tested. If you want a portable application, prefer using the GLFW or SDL platform Backends on Mac. +// - Requires linking with the GameController framework ("-framework GameController"). // Implemented features: // [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'. +// [X] Platform: Mouse support. Can discriminate Mouse/Pen. // [X] Platform: Keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(ImGuiKey_Space). [Legacy kVK_* values will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set] // [X] Platform: OSX clipboard is supported within core Dear ImGui (no specific code in this backend). // [X] Platform: Gamepad support. Enabled with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'. @@ -24,13 +26,18 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) -// 2022-XX-XX: Added support for multiple windows via the ImGuiPlatformIO interface. +// 2023-XX-XX: Added support for multiple windows via the ImGuiPlatformIO interface. +// 2023-04-09: Inputs: Added support for io.AddMouseSourceEvent() to discriminate ImGuiMouseSource_Mouse/ImGuiMouseSource_Pen. +// 2023-02-01: Fixed scroll wheel scaling for devices emitting events with hasPreciseScrollingDeltas==false (e.g. non-Apple mices). +// 2022-11-02: Fixed mouse coordinates before clicking the host window. +// 2022-10-06: Fixed mouse inputs on flipped views. +// 2022-09-26: Inputs: Renamed ImGuiKey_ModXXX introduced in 1.87 to ImGuiMod_XXX (old names still supported). // 2022-05-03: Inputs: Removed ImGui_ImplOSX_HandleEvent() from backend API in favor of backend automatically handling event capture. // 2022-04-27: Misc: Store backend data in a per-context struct, allowing to use this backend with multiple contexts. // 2022-03-22: Inputs: Monitor NSKeyUp events to catch missing keyUp for key when user press Cmd + key // 2022-02-07: Inputs: Forward keyDown/keyUp events to OS when unused by dear imgui. -// 2022-01-31: Fix building with old Xcode versions that are missing gamepad features. -// 2022-01-26: Inputs: replaced short-lived io.AddKeyModsEvent() (added two weeks ago)with io.AddKeyEvent() using ImGuiKey_ModXXX flags. Sorry for the confusion. +// 2022-01-31: Fixed building with old Xcode versions that are missing gamepad features. +// 2022-01-26: Inputs: replaced short-lived io.AddKeyModsEvent() (added two weeks ago) with io.AddKeyEvent() using ImGuiKey_ModXXX flags. Sorry for the confusion. // 2021-01-20: Inputs: calling new io.AddKeyAnalogEvent() for gamepad support, instead of writing directly to io.NavInputs[]. // 2022-01-17: Inputs: calling new io.AddMousePosEvent(), io.AddMouseButtonEvent(), io.AddMouseWheelEvent() API (1.87+). // 2022-01-12: Inputs: Added basic Platform IME support, hooking the io.SetPlatformImeDataFn() function. @@ -63,23 +70,23 @@ // Data struct ImGui_ImplOSX_Data { - CFTimeInterval Time; - NSCursor* MouseCursors[ImGuiMouseCursor_COUNT]; - bool MouseCursorHidden; - ImGuiObserver* Observer; - KeyEventResponder* KeyEventResponder; - NSTextInputContext* InputContext; - id Monitor; - NSWindow* Window; + CFTimeInterval Time; + NSCursor* MouseCursors[ImGuiMouseCursor_COUNT]; + bool MouseCursorHidden; + ImGuiObserver* Observer; + KeyEventResponder* KeyEventResponder; + NSTextInputContext* InputContext; + id Monitor; + NSWindow* Window; - ImGui_ImplOSX_Data() { memset(this, 0, sizeof(*this)); } + ImGui_ImplOSX_Data() { memset(this, 0, sizeof(*this)); } }; -static ImGui_ImplOSX_Data* ImGui_ImplOSX_CreateBackendData() { return IM_NEW(ImGui_ImplOSX_Data)(); } -static ImGui_ImplOSX_Data* ImGui_ImplOSX_GetBackendData() { return (ImGui_ImplOSX_Data*)ImGui::GetIO().BackendPlatformUserData; } -static void ImGui_ImplOSX_DestroyBackendData() { IM_DELETE(ImGui_ImplOSX_GetBackendData()); } +static ImGui_ImplOSX_Data* ImGui_ImplOSX_CreateBackendData() { return IM_NEW(ImGui_ImplOSX_Data)(); } +static ImGui_ImplOSX_Data* ImGui_ImplOSX_GetBackendData() { return (ImGui_ImplOSX_Data*)ImGui::GetIO().BackendPlatformUserData; } +static void ImGui_ImplOSX_DestroyBackendData() { IM_DELETE(ImGui_ImplOSX_GetBackendData()); } -static inline CFTimeInterval GetMachAbsoluteTimeInSeconds() { return static_cast(static_cast(clock_gettime_nsec_np(CLOCK_UPTIME_RAW)) / 1e9); } +static inline CFTimeInterval GetMachAbsoluteTimeInSeconds() { return (CFTimeInterval)(double)(clock_gettime_nsec_np(CLOCK_UPTIME_RAW) / 1e9); } // Forward Declarations static void ImGui_ImplOSX_InitPlatformInterface(); @@ -376,6 +383,18 @@ static ImGuiKey ImGui_ImplOSX_KeyCodeToImGuiKey(int key_code) } } +#ifdef IMGUI_IMPL_METAL_CPP_EXTENSIONS + +IMGUI_IMPL_API bool ImGui_ImplOSX_Init(void* _Nonnull view) { + return ImGui_ImplOSX_Init((__bridge NSView*)(view)); +} + +IMGUI_IMPL_API void ImGui_ImplOSX_NewFrame(void* _Nullable view) { + return ImGui_ImplOSX_NewFrame((__bridge NSView*)(view)); +} + +#endif + bool ImGui_ImplOSX_Init(NSView* view) { @@ -424,11 +443,11 @@ bool ImGui_ImplOSX_Init(NSView* view) NSPasteboard* pasteboard = [NSPasteboard generalPasteboard]; NSString* available = [pasteboard availableTypeFromArray: [NSArray arrayWithObject:NSPasteboardTypeString]]; if (![available isEqualToString:NSPasteboardTypeString]) - return NULL; + return nullptr; NSString* string = [pasteboard stringForType:NSPasteboardTypeString]; if (string == nil) - return NULL; + return nullptr; const char* string_c = (const char*)[string UTF8String]; size_t string_len = strlen(string_c); @@ -475,8 +494,22 @@ bool ImGui_ImplOSX_Init(NSView* view) void ImGui_ImplOSX_Shutdown() { + ImGui_ImplOSX_Data* bd = ImGui_ImplOSX_GetBackendData(); + IM_ASSERT(bd != nullptr && "No platform backend to shutdown, or already shutdown?"); + + bd->Observer = nullptr; + if (bd->Monitor != nullptr) + { + [NSEvent removeMonitor:bd->Monitor]; + bd->Monitor = nullptr; + } + ImGui_ImplOSX_ShutdownPlatformInterface(); ImGui_ImplOSX_DestroyBackendData(); + ImGuiIO& io = ImGui::GetIO(); + io.BackendPlatformName = nullptr; + io.BackendPlatformUserData = nullptr; + io.BackendFlags &= ~(ImGuiBackendFlags_HasMouseCursors | ImGuiBackendFlags_HasGamepad | ImGuiBackendFlags_PlatformHasViewports); } static void ImGui_ImplOSX_UpdateMouseCursor() @@ -516,7 +549,7 @@ static void ImGui_ImplOSX_UpdateGamepads() { ImGuiIO& io = ImGui::GetIO(); memset(io.NavInputs, 0, sizeof(io.NavInputs)); - if ((io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) == 0) + if ((io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) == 0) // FIXME: Technically feeding gamepad shouldn't depend on this now that they are regular inputs. return; #if APPLE_HAS_CONTROLLER @@ -541,10 +574,10 @@ static void ImGui_ImplOSX_UpdateGamepads() #if APPLE_HAS_BUTTON_OPTIONS MAP_BUTTON(ImGuiKey_GamepadBack, buttonOptions); #endif - MAP_BUTTON(ImGuiKey_GamepadFaceDown, buttonA); // Xbox A, PS Cross - MAP_BUTTON(ImGuiKey_GamepadFaceRight, buttonB); // Xbox B, PS Circle MAP_BUTTON(ImGuiKey_GamepadFaceLeft, buttonX); // Xbox X, PS Square + MAP_BUTTON(ImGuiKey_GamepadFaceRight, buttonB); // Xbox B, PS Circle MAP_BUTTON(ImGuiKey_GamepadFaceUp, buttonY); // Xbox Y, PS Triangle + MAP_BUTTON(ImGuiKey_GamepadFaceDown, buttonA); // Xbox A, PS Cross MAP_BUTTON(ImGuiKey_GamepadDpadLeft, dpad.left); MAP_BUTTON(ImGuiKey_GamepadDpadRight, dpad.right); MAP_BUTTON(ImGuiKey_GamepadDpadUp, dpad.up); @@ -605,6 +638,26 @@ void ImGui_ImplOSX_NewFrame(NSView* view) ImGui_ImplOSX_UpdateImePosWithView(view); } +// Must only be called for a mouse event, otherwise an exception occurs +// (Note that NSEventTypeScrollWheel is considered "other input". Oddly enough an exception does not occur with it, but the value will sometimes be wrong!) +static ImGuiMouseSource GetMouseSource(NSEvent* event) +{ + switch (event.subtype) + { + case NSEventSubtypeTabletPoint: + return ImGuiMouseSource_Pen; + // macOS considers input from relative touch devices (like the trackpad or Apple Magic Mouse) to be touch input. + // This doesn't really make sense for Dear ImGui, which expects absolute touch devices only. + // There does not seem to be a simple way to disambiguate things here so we consider NSEventSubtypeTouch events to always come from mice. + // See https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/EventOverview/HandlingTouchEvents/HandlingTouchEvents.html#//apple_ref/doc/uid/10000060i-CH13-SW24 + //case NSEventSubtypeTouch: + // return ImGuiMouseSource_TouchScreen; + case NSEventSubtypeMouseEvent: + default: + return ImGuiMouseSource_Mouse; + } +} + static bool ImGui_ImplOSX_HandleEvent(NSEvent* event, NSView* view) { ImGuiIO& io = ImGui::GetIO(); @@ -613,7 +666,10 @@ static bool ImGui_ImplOSX_HandleEvent(NSEvent* event, NSView* view) { int button = (int)[event buttonNumber]; if (button >= 0 && button < ImGuiMouseButton_COUNT) + { + io.AddMouseSourceEvent(GetMouseSource(event)); io.AddMouseButtonEvent(button, true); + } return io.WantCaptureMouse; } @@ -621,7 +677,10 @@ static bool ImGui_ImplOSX_HandleEvent(NSEvent* event, NSView* view) { int button = (int)[event buttonNumber]; if (button >= 0 && button < ImGuiMouseButton_COUNT) + { + io.AddMouseSourceEvent(GetMouseSource(event)); io.AddMouseButtonEvent(button, false); + } return io.WantCaptureMouse; } @@ -636,11 +695,15 @@ static bool ImGui_ImplOSX_HandleEvent(NSEvent* event, NSView* view) else { mousePoint = event.locationInWindow; + if (event.window == nil) + mousePoint = [[view window] convertPointFromScreen:mousePoint]; mousePoint = [view convertPoint:mousePoint fromView:nil]; // Convert to local coordinates of view - CGSize size = view.bounds.size; - mousePoint.y = size.height - mousePoint.y; + if ([view isFlipped]) + mousePoint = NSMakePoint(mousePoint.x, mousePoint.y); + else + mousePoint = NSMakePoint(mousePoint.x, view.bounds.size.height - mousePoint.y); } - + io.AddMouseSourceEvent(GetMouseSource(event)); io.AddMousePosEvent((float)mousePoint.x, (float)mousePoint.y); return io.WantCaptureMouse; } @@ -672,18 +735,18 @@ static bool ImGui_ImplOSX_HandleEvent(NSEvent* event, NSView* view) wheel_dy = [event scrollingDeltaY]; if ([event hasPreciseScrollingDeltas]) { - wheel_dx *= 0.1; - wheel_dy *= 0.1; + wheel_dx *= 0.01; + wheel_dy *= 0.01; } } else #endif // MAC_OS_X_VERSION_MAX_ALLOWED { - wheel_dx = [event deltaX]; - wheel_dy = [event deltaY]; + wheel_dx = [event deltaX] * 0.1; + wheel_dy = [event deltaY] * 0.1; } if (wheel_dx != 0.0 || wheel_dy != 0.0) - io.AddMouseWheelEvent((float)wheel_dx * 0.1f, (float)wheel_dy * 0.1f); + io.AddMouseWheelEvent((float)wheel_dx, (float)wheel_dy); return io.WantCaptureMouse; } @@ -706,10 +769,10 @@ static bool ImGui_ImplOSX_HandleEvent(NSEvent* event, NSView* view) unsigned short key_code = [event keyCode]; NSEventModifierFlags modifier_flags = [event modifierFlags]; - io.AddKeyEvent(ImGuiKey_ModShift, (modifier_flags & NSEventModifierFlagShift) != 0); - io.AddKeyEvent(ImGuiKey_ModCtrl, (modifier_flags & NSEventModifierFlagControl) != 0); - io.AddKeyEvent(ImGuiKey_ModAlt, (modifier_flags & NSEventModifierFlagOption) != 0); - io.AddKeyEvent(ImGuiKey_ModSuper, (modifier_flags & NSEventModifierFlagCommand) != 0); + io.AddKeyEvent(ImGuiMod_Shift, (modifier_flags & NSEventModifierFlagShift) != 0); + io.AddKeyEvent(ImGuiMod_Ctrl, (modifier_flags & NSEventModifierFlagControl) != 0); + io.AddKeyEvent(ImGuiMod_Alt, (modifier_flags & NSEventModifierFlagOption) != 0); + io.AddKeyEvent(ImGuiMod_Super, (modifier_flags & NSEventModifierFlagCommand) != 0); ImGuiKey key = ImGui_ImplOSX_KeyCodeToImGuiKey(key_code); if (key != ImGuiKey_None) @@ -796,7 +859,7 @@ struct ImGuiViewportDataOSX static void ConvertNSRect(NSScreen* screen, NSRect* r) { - r->origin.y = CGDisplayPixelsHigh(kCGDirectMainDisplay) - r->origin.y - r->size.height; + r->origin.y = screen.frame.size.height - r->origin.y - r->size.height; } static void ImGui_ImplOSX_CreateWindow(ImGuiViewport* viewport) @@ -855,7 +918,7 @@ static void ImGui_ImplOSX_DestroyWindow(ImGuiViewport* viewport) data->Window = nil; IM_DELETE(data); } - viewport->PlatformUserData = viewport->PlatformHandle = viewport->PlatformHandleRaw = NULL; + viewport->PlatformUserData = viewport->PlatformHandle = viewport->PlatformHandleRaw = nullptr; } static void ImGui_ImplOSX_ShowWindow(ImGuiViewport* viewport) @@ -904,7 +967,7 @@ static ImVec2 ImGui_ImplOSX_GetWindowSize(ImGuiViewport* viewport) NSWindow* window = data->Window; NSSize size = window.contentLayoutRect.size; - return ImVec2(size.width, size.width); + return ImVec2(size.width, size.height); } static void ImGui_ImplOSX_SetWindowSize(ImGuiViewport* viewport, ImVec2 size) @@ -985,6 +1048,7 @@ static void ImGui_ImplOSX_UpdateMonitors() imgui_monitor.WorkPos = ImVec2(visibleFrame.origin.x, visibleFrame.origin.y); imgui_monitor.WorkSize = ImVec2(visibleFrame.size.width, visibleFrame.size.height); imgui_monitor.DpiScale = screen.backingScaleFactor; + imgui_monitor.PlatformHandle = (__bridge_retained void*)screen; platform_io.Monitors.push_back(imgui_monitor); } @@ -1031,17 +1095,17 @@ static void ImGui_ImplOSX_ShutdownPlatformInterface() [NSNotificationCenter.defaultCenter removeObserver:bd->Observer name:NSApplicationDidChangeScreenParametersNotification object:nil]; - bd->Observer = NULL; - bd->Window = NULL; - if (bd->Monitor != NULL) + bd->Observer = nullptr; + bd->Window = nullptr; + if (bd->Monitor != nullptr) { [NSEvent removeMonitor:bd->Monitor]; - bd->Monitor = NULL; + bd->Monitor = nullptr; } ImGuiViewport* main_viewport = ImGui::GetMainViewport(); ImGuiViewportDataOSX* data = (ImGuiViewportDataOSX*)main_viewport->PlatformUserData; IM_DELETE(data); - main_viewport->PlatformUserData = NULL; + main_viewport->PlatformUserData = nullptr; ImGui::DestroyPlatformWindows(); } diff --git a/extern/imgui_patched/backends/imgui_impl_sdl.cpp b/extern/imgui_patched/backends/imgui_impl_sdl2.cpp similarity index 83% rename from extern/imgui_patched/backends/imgui_impl_sdl.cpp rename to extern/imgui_patched/backends/imgui_impl_sdl2.cpp index 499676fc..5dc65568 100644 --- a/extern/imgui_patched/backends/imgui_impl_sdl.cpp +++ b/extern/imgui_patched/backends/imgui_impl_sdl2.cpp @@ -5,13 +5,14 @@ // Implemented features: // [X] Platform: Clipboard support. +// [X] Platform: Mouse support. Can discriminate Mouse/TouchScreen. // [X] Platform: Keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(ImGuiKey_Space). [Legacy SDL_SCANCODE_* values will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set] // [X] Platform: Gamepad support. Enabled with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'. // [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'. // [X] Platform: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'. // Missing features: -// [ ] Platform: SDL2 handling of IME under Windows appears to be broken and it explicitly disable the regular Windows IME. You can restore Windows IME by compiling SDL with SDL_DISABLE_WINDOWS_IME. // [ ] Platform: Multi-viewport + Minimized windows seems to break mouse wheel events (at least under Windows). +// [x] Platform: Basic IME support. App needs to call 'SDL_SetHint(SDL_HINT_IME_SHOW_UI, "1");' before SDL_CreateWindow()!. // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. @@ -20,7 +21,19 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) -// 2022-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface. +// 2023-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface. +// 2023-04-06: Inputs: Avoid calling SDL_StartTextInput()/SDL_StopTextInput() as they don't only pertain to IME. It's unclear exactly what their relation is to IME. (#6306) +// 2023-04-04: Inputs: Added support for io.AddMouseSourceEvent() to discriminate ImGuiMouseSource_Mouse/ImGuiMouseSource_TouchScreen. (#2702) +// 2023-02-23: Accept SDL_GetPerformanceCounter() not returning a monotonically increasing value. (#6189, #6114, #3644) +// 2023-02-07: Implement IME handler (io.SetPlatformImeDataFn will call SDL_SetTextInputRect()/SDL_StartTextInput()). +// 2023-02-07: *BREAKING CHANGE* Renamed this backend file from imgui_impl_sdl.cpp/.h to imgui_impl_sdl2.cpp/.h in prevision for the future release of SDL3. +// 2023-02-02: Avoid calling SDL_SetCursor() when cursor has not changed, as the function is surprisingly costly on Mac with latest SDL (may be fixed in next SDL version). +// 2023-02-02: Added support for SDL 2.0.18+ preciseX/preciseY mouse wheel data for smooth scrolling + Scaling X value on Emscripten (bug?). (#4019, #6096) +// 2023-02-02: Removed SDL_MOUSEWHEEL value clamping, as values seem correct in latest Emscripten. (#4019) +// 2023-02-01: Flipping SDL_MOUSEWHEEL 'wheel.x' value to match other backends and offer consistent horizontal scrolling direction. (#4019, #6096, #1463) +// 2022-10-11: Using 'nullptr' instead of 'NULL' as per our switch to C++11. +// 2022-09-26: Inputs: Disable SDL 2.0.22 new "auto capture" (SDL_HINT_MOUSE_AUTO_CAPTURE) which prevents drag and drop across windows for multi-viewport support + don't capture when drag and dropping. (#5710) +// 2022-09-26: Inputs: Renamed ImGuiKey_ModXXX introduced in 1.87 to ImGuiMod_XXX (old names still supported). // 2022-03-22: Inputs: Fix mouse position issues when dragging outside of boundaries. SDL_CaptureMouse() erroneously still gives out LEAVE events when hovering OS decorations. // 2022-03-22: Inputs: Added support for extra mouse buttons (SDL_BUTTON_X1/SDL_BUTTON_X2). // 2022-02-04: Added SDL_Renderer* parameter to ImGui_ImplSDL2_InitForSDLRenderer(), so we can use SDL_GetRendererOutputSize() instead of SDL_GL_GetDrawableSize() when bound to a SDL_Renderer. @@ -64,10 +77,16 @@ // 2016-10-15: Misc: Added a void* user_data parameter to Clipboard function handlers. #include "imgui.h" -#include "imgui_impl_sdl.h" +#include "imgui_impl_sdl2.h" #include #include +// Clang warnings with -Weverything +#if defined(__clang__) +#pragma clang diagnostic push +//#pragma clang diagnostic ignored "-Wimplicit-int-float-conversion" // warning: implicit conversion from 'xxx' to 'float' may lose precision +#endif + // SDL // (the multi-viewports feature requires SDL features supported from SDL 2.0.4+. SDL 2.0.5+ is highly recommended) #include @@ -84,12 +103,12 @@ extern "C" { #else #define SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE 0 #endif -#define SDL_HAS_MOUSE_FOCUS_CLICKTHROUGH SDL_VERSION_ATLEAST(2,0,5) #define SDL_HAS_WINDOW_ALPHA SDL_VERSION_ATLEAST(2,0,5) #define SDL_HAS_ALWAYS_ON_TOP SDL_VERSION_ATLEAST(2,0,5) #define SDL_HAS_USABLE_DISPLAY_BOUNDS SDL_VERSION_ATLEAST(2,0,5) #define SDL_HAS_PER_MONITOR_DPI SDL_VERSION_ATLEAST(2,0,4) #define SDL_HAS_VULKAN SDL_VERSION_ATLEAST(2,0,6) +#define SDL_HAS_DISPLAY_EVENT SDL_VERSION_ATLEAST(2,0,9) #if !SDL_HAS_VULKAN static const Uint32 SDL_WINDOW_VULKAN = 0x10000000; #endif @@ -103,10 +122,13 @@ struct ImGui_ImplSDL2_Data Uint32 MouseWindowID; int MouseButtonsDown; SDL_Cursor* MouseCursors[ImGuiMouseCursor_COUNT]; + SDL_Cursor* LastMouseCursor; int PendingMouseLeaveFrame; char* ClipboardTextData; bool MouseCanUseGlobalState; + bool MouseCanReportHoveredViewport; // This is hard to use/unreliable on SDL so we'll set ImGuiBackendFlags_HasMouseHoveredViewport dynamically based on state. bool UseVulkan; + bool WantUpdateMonitors; ImGui_ImplSDL2_Data() { memset((void*)this, 0, sizeof(*this)); } }; @@ -117,7 +139,7 @@ struct ImGui_ImplSDL2_Data // FIXME: some shared resources (mouse cursor shape, gamepad) are mishandled when using multi-context. static ImGui_ImplSDL2_Data* ImGui_ImplSDL2_GetBackendData() { - return ImGui::GetCurrentContext() ? (ImGui_ImplSDL2_Data*)ImGui::GetIO().BackendPlatformUserData : NULL; + return ImGui::GetCurrentContext() ? (ImGui_ImplSDL2_Data*)ImGui::GetIO().BackendPlatformUserData : nullptr; } // Forward Declarations @@ -140,6 +162,20 @@ static void ImGui_ImplSDL2_SetClipboardText(void*, const char* text) SDL_SetClipboardText(text); } +// Note: native IME will only display if user calls SDL_SetHint(SDL_HINT_IME_SHOW_UI, "1") _before_ SDL_CreateWindow(). +static void ImGui_ImplSDL2_SetPlatformImeData(ImGuiViewport* viewport, ImGuiPlatformImeData* data) +{ + if (data->WantVisible) + { + SDL_Rect r; + r.x = (int)(data->InputPos.x - viewport->Pos.x); + r.y = (int)(data->InputPos.y - viewport->Pos.y + data->InputLineHeight); + r.w = 1; + r.h = (int)data->InputLineHeight; + SDL_SetTextInputRect(&r); + } +} + static ImGuiKey ImGui_ImplSDL2_KeycodeToImGuiKey(int keycode) { switch (keycode) @@ -256,10 +292,10 @@ static ImGuiKey ImGui_ImplSDL2_KeycodeToImGuiKey(int keycode) static void ImGui_ImplSDL2_UpdateKeyModifiers(SDL_Keymod sdl_key_mods) { ImGuiIO& io = ImGui::GetIO(); - io.AddKeyEvent(ImGuiKey_ModCtrl, (sdl_key_mods & KMOD_CTRL) != 0); - io.AddKeyEvent(ImGuiKey_ModShift, (sdl_key_mods & KMOD_SHIFT) != 0); - io.AddKeyEvent(ImGuiKey_ModAlt, (sdl_key_mods & KMOD_ALT) != 0); - io.AddKeyEvent(ImGuiKey_ModSuper, (sdl_key_mods & KMOD_GUI) != 0); + io.AddKeyEvent(ImGuiMod_Ctrl, (sdl_key_mods & KMOD_CTRL) != 0); + io.AddKeyEvent(ImGuiMod_Shift, (sdl_key_mods & KMOD_SHIFT) != 0); + io.AddKeyEvent(ImGuiMod_Alt, (sdl_key_mods & KMOD_ALT) != 0); + io.AddKeyEvent(ImGuiMod_Super, (sdl_key_mods & KMOD_GUI) != 0); } // You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs. @@ -293,16 +329,27 @@ bool ImGui_ImplSDL2_ProcessEvent(const SDL_Event* event) mouse_pos.x *= std::ceil(platform_io.Monitors[0].DpiScale); mouse_pos.y *= std::ceil(platform_io.Monitors[0].DpiScale); } + io.AddMouseSourceEvent(event->motion.which == SDL_TOUCH_MOUSEID ? ImGuiMouseSource_TouchScreen : ImGuiMouseSource_Mouse); io.AddMousePosEvent(mouse_pos.x, mouse_pos.y); return true; } case SDL_MOUSEWHEEL: { - float wheel_x = (event->wheel.x > 0) ? 1.0f : (event->wheel.x < 0) ? -1.0f : 0.0f; - float wheel_y = (event->wheel.y > 0) ? 1.0f : (event->wheel.y < 0) ? -1.0f : 0.0f; + //IMGUI_DEBUG_LOG("wheel %.2f %.2f, precise %.2f %.2f\n", (float)event->wheel.x, (float)event->wheel.y, event->wheel.preciseX, event->wheel.preciseY); +#if SDL_VERSION_ATLEAST(2,0,18) // If this fails to compile on Emscripten: update to latest Emscripten! + float wheel_x = -event->wheel.preciseX; + float wheel_y = event->wheel.preciseY; +#else + float wheel_x = -(float)event->wheel.x; + float wheel_y = (float)event->wheel.y; +#endif +#ifdef __EMSCRIPTEN__ + wheel_x /= 100.0f; +#endif #ifdef __APPLE__ wheel_x = -wheel_x; #endif + io.AddMouseSourceEvent(event->wheel.which == SDL_TOUCH_MOUSEID ? ImGuiMouseSource_TouchScreen : ImGuiMouseSource_Mouse); io.AddMouseWheelEvent(wheel_x, wheel_y); return true; } @@ -317,6 +364,7 @@ bool ImGui_ImplSDL2_ProcessEvent(const SDL_Event* event) if (event->button.button == SDL_BUTTON_X2) { mouse_button = 4; } if (mouse_button == -1) break; + io.AddMouseSourceEvent(event->button.which == SDL_TOUCH_MOUSEID ? ImGuiMouseSource_TouchScreen : ImGuiMouseSource_Mouse); io.AddMouseButtonEvent(mouse_button, (event->type == SDL_MOUSEBUTTONDOWN)); bd->MouseButtonsDown = (event->type == SDL_MOUSEBUTTONDOWN) ? (bd->MouseButtonsDown | (1 << mouse_button)) : (bd->MouseButtonsDown & ~(1 << mouse_button)); return true; @@ -335,6 +383,15 @@ bool ImGui_ImplSDL2_ProcessEvent(const SDL_Event* event) io.SetKeyEventNativeData(key, event->key.keysym.sym, event->key.keysym.scancode, event->key.keysym.scancode); // To support legacy indexing (<1.87 user code). Legacy backend uses SDLK_*** as indices to IsKeyXXX() functions. return true; } +#if SDL_HAS_DISPLAY_EVENT + case SDL_DISPLAYEVENT: + { + // 2.0.26 has SDL_DISPLAYEVENT_CONNECTED/SDL_DISPLAYEVENT_DISCONNECTED/SDL_DISPLAYEVENT_ORIENTATION, + // so change of DPI/Scaling are not reflected in this event. (SDL3 has it) + bd->WantUpdateMonitors = true; + return true; + } +#endif case SDL_WINDOWEVENT: { // - When capturing mouse, SDL will send a bunch of conflicting LEAVE/ENTER event on every mouse move, but the final ENTER tends to be right. @@ -374,7 +431,7 @@ bool ImGui_ImplSDL2_ProcessEvent(const SDL_Event* event) static bool ImGui_ImplSDL2_Init(SDL_Window* window, SDL_Renderer* renderer, void* sdl_gl_context) { ImGuiIO& io = ImGui::GetIO(); - IM_ASSERT(io.BackendPlatformUserData == NULL && "Already initialized a platform backend!"); + IM_ASSERT(io.BackendPlatformUserData == nullptr && "Already initialized a platform backend!"); // Check and store if we are on a SDL backend that supports global mouse position // ("wayland" and "rpi" don't support it, but we chose to use a white-list instead of a black-list) @@ -390,25 +447,29 @@ static bool ImGui_ImplSDL2_Init(SDL_Window* window, SDL_Renderer* renderer, void // Setup backend capabilities flags ImGui_ImplSDL2_Data* bd = IM_NEW(ImGui_ImplSDL2_Data)(); io.BackendPlatformUserData = (void*)bd; - io.BackendPlatformName = "imgui_impl_sdl"; + io.BackendPlatformName = "imgui_impl_sdl2"; io.BackendFlags |= ImGuiBackendFlags_HasMouseCursors; // We can honor GetMouseCursor() values (optional) io.BackendFlags |= ImGuiBackendFlags_HasSetMousePos; // We can honor io.WantSetMousePos requests (optional, rarely used) if (mouse_can_use_global_state) io.BackendFlags |= ImGuiBackendFlags_PlatformHasViewports; // We can create multi-viewports on the Platform side (optional) - // SDL on Linux/OSX doesn't report events for unfocused windows (see https://github.com/ocornut/imgui/issues/4960) -#ifndef __APPLE__ - if (mouse_can_use_global_state) - io.BackendFlags |= ImGuiBackendFlags_HasMouseHoveredViewport;// We can call io.AddMouseViewportEvent() with correct data (optional) -#endif - bd->Window = window; bd->Renderer = renderer; + + // SDL on Linux/OSX doesn't report events for unfocused windows (see https://github.com/ocornut/imgui/issues/4960) + // We will use 'MouseCanReportHoveredViewport' to set 'ImGuiBackendFlags_HasMouseHoveredViewport' dynamically each frame. bd->MouseCanUseGlobalState = mouse_can_use_global_state; +#ifndef __APPLE__ + bd->MouseCanReportHoveredViewport = bd->MouseCanUseGlobalState; +#else + bd->MouseCanReportHoveredViewport = false; +#endif + bd->WantUpdateMonitors = true; io.SetClipboardTextFn = ImGui_ImplSDL2_SetClipboardText; io.GetClipboardTextFn = ImGui_ImplSDL2_GetClipboardText; - io.ClipboardUserData = NULL; + io.ClipboardUserData = nullptr; + io.SetPlatformImeDataFn = ImGui_ImplSDL2_SetPlatformImeData; // Load mouse cursors bd->MouseCursors[ImGuiMouseCursor_Arrow] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW); @@ -425,24 +486,38 @@ static bool ImGui_ImplSDL2_Init(SDL_Window* window, SDL_Renderer* renderer, void // Our mouse update function expect PlatformHandle to be filled for the main viewport ImGuiViewport* main_viewport = ImGui::GetMainViewport(); main_viewport->PlatformHandle = (void*)window; -#ifdef _WIN32 + main_viewport->PlatformHandleRaw = nullptr; SDL_SysWMinfo info; SDL_VERSION(&info.version); if (SDL_GetWindowWMInfo(window, &info)) + { +#if defined(SDL_VIDEO_DRIVER_WINDOWS) main_viewport->PlatformHandleRaw = (void*)info.info.win.window; +#elif defined(__APPLE__) && defined(SDL_VIDEO_DRIVER_COCOA) + main_viewport->PlatformHandleRaw = (void*)info.info.cocoa.window; #endif + } - // Set SDL hint to receive mouse click events on window focus, otherwise SDL doesn't emit the event. + // From 2.0.5: Set SDL hint to receive mouse click events on window focus, otherwise SDL doesn't emit the event. // Without this, when clicking to gain focus, our widgets wouldn't activate even though they showed as hovered. // (This is unfortunately a global SDL setting, so enabling it might have a side-effect on your application. // It is unlikely to make a difference, but if your app absolutely needs to ignore the initial on-focus click: // you can ignore SDL_MOUSEBUTTONDOWN events coming right after a SDL_WINDOWEVENT_FOCUS_GAINED) -#if SDL_HAS_MOUSE_FOCUS_CLICKTHROUGH +#ifdef SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH SDL_SetHint(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "1"); #endif - // Update monitors - ImGui_ImplSDL2_UpdateMonitors(); + // From 2.0.18: Enable native IME. + // IMPORTANT: This is used at the time of SDL_CreateWindow() so this will only affects secondary windows, if any. + // For the main window to be affected, your application needs to call this manually before calling SDL_CreateWindow(). +#ifdef SDL_HINT_IME_SHOW_UI + SDL_SetHint(SDL_HINT_IME_SHOW_UI, "1"); +#endif + + // From 2.0.22: Disable auto-capture, this is preventing drag and drop across multiple windows (see #5710) +#ifdef SDL_HINT_MOUSE_AUTO_CAPTURE + SDL_SetHint(SDL_HINT_MOUSE_AUTO_CAPTURE, "0"); +#endif // We need SDL_CaptureMouse(), SDL_GetGlobalMouseState() from SDL 2.0.4+ to support multiple viewports. // We left the call to ImGui_ImplSDL2_InitPlatformInterface() outside of #ifdef to avoid unused-function warnings. @@ -454,7 +529,7 @@ static bool ImGui_ImplSDL2_Init(SDL_Window* window, SDL_Renderer* renderer, void bool ImGui_ImplSDL2_InitForOpenGL(SDL_Window* window, void* sdl_gl_context) { - return ImGui_ImplSDL2_Init(window, NULL, sdl_gl_context); + return ImGui_ImplSDL2_Init(window, nullptr, sdl_gl_context); } bool ImGui_ImplSDL2_InitForVulkan(SDL_Window* window) @@ -462,7 +537,7 @@ bool ImGui_ImplSDL2_InitForVulkan(SDL_Window* window) #if !SDL_HAS_VULKAN IM_ASSERT(0 && "Unsupported"); #endif - if (!ImGui_ImplSDL2_Init(window, NULL, NULL)) + if (!ImGui_ImplSDL2_Init(window, nullptr, nullptr)) return false; ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_GetBackendData(); bd->UseVulkan = true; @@ -474,23 +549,23 @@ bool ImGui_ImplSDL2_InitForD3D(SDL_Window* window) #if !defined(_WIN32) IM_ASSERT(0 && "Unsupported"); #endif - return ImGui_ImplSDL2_Init(window, NULL, NULL); + return ImGui_ImplSDL2_Init(window, nullptr, nullptr); } bool ImGui_ImplSDL2_InitForMetal(SDL_Window* window) { - return ImGui_ImplSDL2_Init(window, NULL, NULL); + return ImGui_ImplSDL2_Init(window, nullptr, nullptr); } bool ImGui_ImplSDL2_InitForSDLRenderer(SDL_Window* window, SDL_Renderer* renderer) { - return ImGui_ImplSDL2_Init(window, renderer, NULL); + return ImGui_ImplSDL2_Init(window, renderer, nullptr); } void ImGui_ImplSDL2_Shutdown() { ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_GetBackendData(); - IM_ASSERT(bd != NULL && "No platform backend to shutdown, or already shutdown?"); + IM_ASSERT(bd != nullptr && "No platform backend to shutdown, or already shutdown?"); ImGuiIO& io = ImGui::GetIO(); ImGui_ImplSDL2_ShutdownPlatformInterface(); @@ -499,9 +574,11 @@ void ImGui_ImplSDL2_Shutdown() SDL_free(bd->ClipboardTextData); for (ImGuiMouseCursor cursor_n = 0; cursor_n < ImGuiMouseCursor_COUNT; cursor_n++) SDL_FreeCursor(bd->MouseCursors[cursor_n]); + bd->LastMouseCursor = nullptr; - io.BackendPlatformName = NULL; - io.BackendPlatformUserData = NULL; + io.BackendPlatformName = nullptr; + io.BackendPlatformUserData = nullptr; + io.BackendFlags &= ~(ImGuiBackendFlags_HasMouseCursors | ImGuiBackendFlags_HasSetMousePos | ImGuiBackendFlags_HasGamepad | ImGuiBackendFlags_PlatformHasViewports | ImGuiBackendFlags_HasMouseHoveredViewport); IM_DELETE(bd); } @@ -514,7 +591,7 @@ static void ImGui_ImplSDL2_UpdateMouseData() // We forward mouse input when hovered or captured (via SDL_MOUSEMOTION) or when focused (below) #if SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE // SDL_CaptureMouse() let the OS know e.g. that our imgui drag outside the SDL window boundaries shouldn't e.g. trigger other operations outside - SDL_CaptureMouse(bd->MouseButtonsDown != 0 ? SDL_TRUE : SDL_FALSE); + SDL_CaptureMouse((bd->MouseButtonsDown != 0) ? SDL_TRUE : SDL_FALSE); SDL_Window* focused_window = SDL_GetKeyboardFocus(); const bool is_app_focused = (focused_window && (bd->Window == focused_window || ImGui::FindViewportByPlatformHandle((void*)focused_window))); #else @@ -593,7 +670,12 @@ static void ImGui_ImplSDL2_UpdateMouseCursor() else { // Show OS mouse cursor - SDL_SetCursor(bd->MouseCursors[imgui_cursor] ? bd->MouseCursors[imgui_cursor] : bd->MouseCursors[ImGuiMouseCursor_Arrow]); + SDL_Cursor* expected_cursor = bd->MouseCursors[imgui_cursor] ? bd->MouseCursors[imgui_cursor] : bd->MouseCursors[ImGuiMouseCursor_Arrow]; + if (bd->LastMouseCursor != expected_cursor) + { + SDL_SetCursor(expected_cursor); // SDL function doesn't have an early out (see #6113) + bd->LastMouseCursor = expected_cursor; + } SDL_ShowCursor(SDL_TRUE); } } @@ -601,7 +683,7 @@ static void ImGui_ImplSDL2_UpdateMouseCursor() static void ImGui_ImplSDL2_UpdateGamepads() { ImGuiIO& io = ImGui::GetIO(); - if ((io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) == 0) + if ((io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) == 0) // FIXME: Technically feeding gamepad shouldn't depend on this now that they are regular inputs. return; // Get gamepad @@ -618,10 +700,10 @@ static void ImGui_ImplSDL2_UpdateGamepads() const int thumb_dead_zone = 8000; // SDL_gamecontroller.h suggests using this value. MAP_BUTTON(ImGuiKey_GamepadStart, SDL_CONTROLLER_BUTTON_START); MAP_BUTTON(ImGuiKey_GamepadBack, SDL_CONTROLLER_BUTTON_BACK); - MAP_BUTTON(ImGuiKey_GamepadFaceDown, SDL_CONTROLLER_BUTTON_A); // Xbox A, PS Cross - MAP_BUTTON(ImGuiKey_GamepadFaceRight, SDL_CONTROLLER_BUTTON_B); // Xbox B, PS Circle MAP_BUTTON(ImGuiKey_GamepadFaceLeft, SDL_CONTROLLER_BUTTON_X); // Xbox X, PS Square + MAP_BUTTON(ImGuiKey_GamepadFaceRight, SDL_CONTROLLER_BUTTON_B); // Xbox B, PS Circle MAP_BUTTON(ImGuiKey_GamepadFaceUp, SDL_CONTROLLER_BUTTON_Y); // Xbox Y, PS Triangle + MAP_BUTTON(ImGuiKey_GamepadFaceDown, SDL_CONTROLLER_BUTTON_A); // Xbox A, PS Cross MAP_BUTTON(ImGuiKey_GamepadDpadLeft, SDL_CONTROLLER_BUTTON_DPAD_LEFT); MAP_BUTTON(ImGuiKey_GamepadDpadRight, SDL_CONTROLLER_BUTTON_DPAD_RIGHT); MAP_BUTTON(ImGuiKey_GamepadDpadUp, SDL_CONTROLLER_BUTTON_DPAD_UP); @@ -644,11 +726,13 @@ static void ImGui_ImplSDL2_UpdateGamepads() #undef MAP_ANALOG } -// FIXME-PLATFORM: SDL doesn't have an event to notify the application of display/monitor changes +// FIXME: Note that doesn't update with DPI/Scaling change only as SDL2 doesn't have an event for it (SDL3 has). static void ImGui_ImplSDL2_UpdateMonitors() { + ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_GetBackendData(); ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO(); platform_io.Monitors.resize(0); + bd->WantUpdateMonitors = false; int display_count = SDL_GetNumVideoDisplays(); for (int n = 0; n < display_count; n++) { @@ -666,6 +750,7 @@ static void ImGui_ImplSDL2_UpdateMonitors() #if SDL_HAS_PER_MONITOR_DPI monitor.DpiScale = 1.0f; #endif + monitor.PlatformHandle = (void*)(intptr_t)n; platform_io.Monitors.push_back(monitor); } } @@ -673,7 +758,7 @@ static void ImGui_ImplSDL2_UpdateMonitors() void ImGui_ImplSDL2_NewFrame() { ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_GetBackendData(); - IM_ASSERT(bd != NULL && "Did you call ImGui_ImplSDL2_Init()?"); + IM_ASSERT(bd != nullptr && "Did you call ImGui_ImplSDL2_Init()?"); ImGuiIO& io = ImGui::GetIO(); // Setup display size (every frame to accommodate for window resizing) @@ -695,6 +780,11 @@ void ImGui_ImplSDL2_NewFrame() io.DisplayFramebufferScale = ImVec2((float)display_w / w, (float)display_h / h); } + // TODO: is this before, or after? + // Update monitors + if (bd->WantUpdateMonitors) + ImGui_ImplSDL2_UpdateMonitors(); + // On Apple and Wayland, The window size is reported in Low DPI, even when running in high DPI mode ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO(); if (!platform_io.Monitors.empty() /*&& platform_io.Monitors[0].DpiScale > 1.0f*/ && display_h != h && w != 0 && display_w != 0) @@ -706,8 +796,11 @@ void ImGui_ImplSDL2_NewFrame() } // Setup time step (we don't use SDL_GetTicks() because it is using millisecond resolution) + // (Accept SDL_GetPerformanceCounter() not returning a monotonically increasing value. Happens in VMs and Emscripten, see #6189, #6114, #3644) static Uint64 frequency = SDL_GetPerformanceFrequency(); Uint64 current_time = SDL_GetPerformanceCounter(); + if (current_time <= bd->Time) + current_time = bd->Time + 1; io.DeltaTime = bd->Time > 0 ? (float)((double)(current_time - bd->Time) / frequency) : (float)(1.0f / 60.0f); bd->Time = current_time; @@ -718,6 +811,13 @@ void ImGui_ImplSDL2_NewFrame() io.AddMousePosEvent(-FLT_MAX, -FLT_MAX); } + // Our io.AddMouseViewportEvent() calls will only be valid when not capturing. + // Technically speaking testing for 'bd->MouseButtonsDown == 0' would be more rygorous, but testing for payload reduces noise and potential side-effects. + if (bd->MouseCanReportHoveredViewport && ImGui::GetDragDropPayload() == nullptr) + io.BackendFlags |= ImGuiBackendFlags_HasMouseHoveredViewport; + else + io.BackendFlags &= ~ImGuiBackendFlags_HasMouseHoveredViewport; + ImGui_ImplSDL2_UpdateMouseData(); ImGui_ImplSDL2_UpdateMouseCursor(); @@ -731,7 +831,7 @@ void ImGui_ImplSDL2_NewFrame() // If you are new to dear imgui or creating a new binding for dear imgui, it is recommended that you completely ignore this section first.. //-------------------------------------------------------------------------------------------------------- -// Helper structure we store in the void* RenderUserData field of each ImGuiViewport to easily retrieve our backend data. +// Helper structure we store in the void* RendererUserData field of each ImGuiViewport to easily retrieve our backend data. struct ImGui_ImplSDL2_ViewportData { SDL_Window* Window; @@ -739,8 +839,8 @@ struct ImGui_ImplSDL2_ViewportData bool WindowOwned; SDL_GLContext GLContext; - ImGui_ImplSDL2_ViewportData() { Window = NULL; WindowID = 0; WindowOwned = false; GLContext = NULL; } - ~ImGui_ImplSDL2_ViewportData() { IM_ASSERT(Window == NULL && GLContext == NULL); } + ImGui_ImplSDL2_ViewportData() { Window = nullptr; WindowID = 0; WindowOwned = false; GLContext = nullptr; } + ~ImGui_ImplSDL2_ViewportData() { IM_ASSERT(Window == nullptr && GLContext == nullptr); } }; static void ImGui_ImplSDL2_CreateWindow(ImGuiViewport* viewport) @@ -753,8 +853,8 @@ static void ImGui_ImplSDL2_CreateWindow(ImGuiViewport* viewport) ImGui_ImplSDL2_ViewportData* main_viewport_data = (ImGui_ImplSDL2_ViewportData*)main_viewport->PlatformUserData; // Share GL resources with main context - bool use_opengl = (main_viewport_data->GLContext != NULL); - SDL_GLContext backup_context = NULL; + bool use_opengl = (main_viewport_data->GLContext != nullptr); + SDL_GLContext backup_context = nullptr; if (use_opengl) { backup_context = SDL_GL_GetCurrentContext(); @@ -786,12 +886,17 @@ static void ImGui_ImplSDL2_CreateWindow(ImGuiViewport* viewport) SDL_GL_MakeCurrent(vd->Window, backup_context); viewport->PlatformHandle = (void*)vd->Window; -#if defined(_WIN32) + viewport->PlatformHandleRaw = nullptr; SDL_SysWMinfo info; SDL_VERSION(&info.version); if (SDL_GetWindowWMInfo(vd->Window, &info)) + { +#if defined(SDL_VIDEO_DRIVER_WINDOWS) viewport->PlatformHandleRaw = info.info.win.window; +#elif defined(__APPLE__) && defined(SDL_VIDEO_DRIVER_COCOA) + viewport->PlatformHandleRaw = (void*)info.info.cocoa.window; #endif + } } static void ImGui_ImplSDL2_DestroyWindow(ImGuiViewport* viewport) @@ -802,11 +907,11 @@ static void ImGui_ImplSDL2_DestroyWindow(ImGuiViewport* viewport) SDL_GL_DeleteContext(vd->GLContext); if (vd->Window && vd->WindowOwned) SDL_DestroyWindow(vd->Window); - vd->GLContext = NULL; - vd->Window = NULL; + vd->GLContext = nullptr; + vd->Window = nullptr; IM_DELETE(vd); } - viewport->PlatformUserData = viewport->PlatformHandle = NULL; + viewport->PlatformUserData = viewport->PlatformHandle = nullptr; } static void ImGui_ImplSDL2_ShowWindow(ImGuiViewport* viewport) @@ -966,3 +1071,7 @@ static void ImGui_ImplSDL2_ShutdownPlatformInterface() { ImGui::DestroyPlatformWindows(); } + +#if defined(__clang__) +#pragma clang diagnostic pop +#endif diff --git a/extern/imgui_patched/backends/imgui_impl_sdl.h b/extern/imgui_patched/backends/imgui_impl_sdl2.h similarity index 92% rename from extern/imgui_patched/backends/imgui_impl_sdl.h rename to extern/imgui_patched/backends/imgui_impl_sdl2.h index 92755414..1ca91b3a 100644 --- a/extern/imgui_patched/backends/imgui_impl_sdl.h +++ b/extern/imgui_patched/backends/imgui_impl_sdl2.h @@ -4,13 +4,14 @@ // Implemented features: // [X] Platform: Clipboard support. +// [X] Platform: Mouse support. Can discriminate Mouse/TouchScreen. // [X] Platform: Keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(ImGuiKey_Space). [Legacy SDL_SCANCODE_* values will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set] // [X] Platform: Gamepad support. Enabled with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'. // [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'. // [X] Platform: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'. // Missing features: -// [ ] Platform: SDL2 handling of IME under Windows appears to be broken and it explicitly disable the regular Windows IME. You can restore Windows IME by compiling SDL with SDL_DISABLE_WINDOWS_IME. // [ ] Platform: Multi-viewport + Minimized windows seems to break mouse wheel events (at least under Windows). +// [x] Platform: Basic IME support. App needs to call 'SDL_SetHint(SDL_HINT_IME_SHOW_UI, "1");' before SDL_CreateWindow()!. // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. diff --git a/extern/imgui_patched/backends/imgui_impl_sdl3.cpp b/extern/imgui_patched/backends/imgui_impl_sdl3.cpp new file mode 100644 index 00000000..47fe49f2 --- /dev/null +++ b/extern/imgui_patched/backends/imgui_impl_sdl3.cpp @@ -0,0 +1,949 @@ +// dear imgui: Platform Backend for SDL3 (*EXPERIMENTAL*) +// This needs to be used along with a Renderer (e.g. DirectX11, OpenGL3, Vulkan..) +// (Info: SDL3 is a cross-platform general purpose library for handling windows, inputs, graphics context creation, etc.) +// (IMPORTANT: SDL 3.0.0 is NOT YET RELEASED. IT IS POSSIBLE THAT ITS SPECS/API WILL CHANGE BEFORE RELEASE) + +// Implemented features: +// [X] Platform: Clipboard support. +// [X] Platform: Mouse support. Can discriminate Mouse/TouchScreen. +// [X] Platform: Keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(ImGuiKey_Space). [Legacy SDL_SCANCODE_* values will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set] +// [X] Platform: Gamepad support. Enabled with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'. +// [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'. +// [x] Platform: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable' -> the OS animation effect when window gets created/destroyed is problematic. SDL2 backend doesn't have issue. +// Missing features: +// [ ] Platform: Multi-viewport + Minimized windows seems to break mouse wheel events (at least under Windows). +// [x] Platform: Basic IME support. Position somehow broken in SDL3 + app needs to call 'SDL_SetHint(SDL_HINT_IME_SHOW_UI, "1");' before SDL_CreateWindow()!. + +// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. +// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. +// If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp. +// Read online: https://github.com/ocornut/imgui/tree/master/docs + +// CHANGELOG +// (minor and older changes stripped away, please see git history for details) +// 2023-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface. +// 2023-05-04: Fixed build on Emscripten/iOS/Android. (#6391) +// 2023-04-06: Inputs: Avoid calling SDL_StartTextInput()/SDL_StopTextInput() as they don't only pertain to IME. It's unclear exactly what their relation is to IME. (#6306) +// 2023-04-04: Inputs: Added support for io.AddMouseSourceEvent() to discriminate ImGuiMouseSource_Mouse/ImGuiMouseSource_TouchScreen. (#2702) +// 2023-02-23: Accept SDL_GetPerformanceCounter() not returning a monotonically increasing value. (#6189, #6114, #3644) +// 2023-02-07: Forked "imgui_impl_sdl2" into "imgui_impl_sdl3". Removed version checks for old feature. Refer to imgui_impl_sdl2.cpp for older changelog. + +#include "imgui.h" +#include "imgui_impl_sdl3.h" + +// Clang warnings with -Weverything +#if defined(__clang__) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wimplicit-int-float-conversion" // warning: implicit conversion from 'xxx' to 'float' may lose precision +#endif + +// SDL +#include +#include +#if defined(__APPLE__) +#include +#endif + +#if !defined(__EMSCRIPTEN__) && !defined(__ANDROID__) && !(defined(__APPLE__) && TARGET_OS_IOS) && !defined(__amigaos4__) +#define SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE 1 +#else +#define SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE 0 +#endif + +// SDL Data +struct ImGui_ImplSDL3_Data +{ + SDL_Window* Window; + SDL_Renderer* Renderer; + Uint64 Time; + Uint32 MouseWindowID; + int MouseButtonsDown; + SDL_Cursor* MouseCursors[ImGuiMouseCursor_COUNT]; + SDL_Cursor* LastMouseCursor; + int PendingMouseLeaveFrame; + char* ClipboardTextData; + bool MouseCanUseGlobalState; + bool MouseCanReportHoveredViewport; // This is hard to use/unreliable on SDL so we'll set ImGuiBackendFlags_HasMouseHoveredViewport dynamically based on state. + bool UseVulkan; + bool WantUpdateMonitors; + + ImGui_ImplSDL3_Data() { memset((void*)this, 0, sizeof(*this)); } +}; + +// Backend data stored in io.BackendPlatformUserData to allow support for multiple Dear ImGui contexts +// It is STRONGLY preferred that you use docking branch with multi-viewports (== single Dear ImGui context + multiple windows) instead of multiple Dear ImGui contexts. +// FIXME: multi-context support is not well tested and probably dysfunctional in this backend. +// FIXME: some shared resources (mouse cursor shape, gamepad) are mishandled when using multi-context. +static ImGui_ImplSDL3_Data* ImGui_ImplSDL3_GetBackendData() +{ + return ImGui::GetCurrentContext() ? (ImGui_ImplSDL3_Data*)ImGui::GetIO().BackendPlatformUserData : nullptr; +} + +// Forward Declarations +static void ImGui_ImplSDL3_UpdateMonitors(); +static void ImGui_ImplSDL3_InitPlatformInterface(SDL_Window* window, void* sdl_gl_context); +static void ImGui_ImplSDL3_ShutdownPlatformInterface(); + +// Functions +static const char* ImGui_ImplSDL3_GetClipboardText(void*) +{ + ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData(); + if (bd->ClipboardTextData) + SDL_free(bd->ClipboardTextData); + bd->ClipboardTextData = SDL_GetClipboardText(); + return bd->ClipboardTextData; +} + +static void ImGui_ImplSDL3_SetClipboardText(void*, const char* text) +{ + SDL_SetClipboardText(text); +} + +static void ImGui_ImplSDL3_SetPlatformImeData(ImGuiViewport* viewport, ImGuiPlatformImeData* data) +{ + if (data->WantVisible) + { + SDL_Rect r; + r.x = (int)(data->InputPos.x - viewport->Pos.x); + r.y = (int)(data->InputPos.y - viewport->Pos.y + data->InputLineHeight); + r.w = 1; + r.h = (int)data->InputLineHeight; + SDL_SetTextInputRect(&r); + } +} + +static ImGuiKey ImGui_ImplSDL3_KeycodeToImGuiKey(int keycode) +{ + switch (keycode) + { + case SDLK_TAB: return ImGuiKey_Tab; + case SDLK_LEFT: return ImGuiKey_LeftArrow; + case SDLK_RIGHT: return ImGuiKey_RightArrow; + case SDLK_UP: return ImGuiKey_UpArrow; + case SDLK_DOWN: return ImGuiKey_DownArrow; + case SDLK_PAGEUP: return ImGuiKey_PageUp; + case SDLK_PAGEDOWN: return ImGuiKey_PageDown; + case SDLK_HOME: return ImGuiKey_Home; + case SDLK_END: return ImGuiKey_End; + case SDLK_INSERT: return ImGuiKey_Insert; + case SDLK_DELETE: return ImGuiKey_Delete; + case SDLK_BACKSPACE: return ImGuiKey_Backspace; + case SDLK_SPACE: return ImGuiKey_Space; + case SDLK_RETURN: return ImGuiKey_Enter; + case SDLK_ESCAPE: return ImGuiKey_Escape; + case SDLK_QUOTE: return ImGuiKey_Apostrophe; + case SDLK_COMMA: return ImGuiKey_Comma; + case SDLK_MINUS: return ImGuiKey_Minus; + case SDLK_PERIOD: return ImGuiKey_Period; + case SDLK_SLASH: return ImGuiKey_Slash; + case SDLK_SEMICOLON: return ImGuiKey_Semicolon; + case SDLK_EQUALS: return ImGuiKey_Equal; + case SDLK_LEFTBRACKET: return ImGuiKey_LeftBracket; + case SDLK_BACKSLASH: return ImGuiKey_Backslash; + case SDLK_RIGHTBRACKET: return ImGuiKey_RightBracket; + case SDLK_BACKQUOTE: return ImGuiKey_GraveAccent; + case SDLK_CAPSLOCK: return ImGuiKey_CapsLock; + case SDLK_SCROLLLOCK: return ImGuiKey_ScrollLock; + case SDLK_NUMLOCKCLEAR: return ImGuiKey_NumLock; + case SDLK_PRINTSCREEN: return ImGuiKey_PrintScreen; + case SDLK_PAUSE: return ImGuiKey_Pause; + case SDLK_KP_0: return ImGuiKey_Keypad0; + case SDLK_KP_1: return ImGuiKey_Keypad1; + case SDLK_KP_2: return ImGuiKey_Keypad2; + case SDLK_KP_3: return ImGuiKey_Keypad3; + case SDLK_KP_4: return ImGuiKey_Keypad4; + case SDLK_KP_5: return ImGuiKey_Keypad5; + case SDLK_KP_6: return ImGuiKey_Keypad6; + case SDLK_KP_7: return ImGuiKey_Keypad7; + case SDLK_KP_8: return ImGuiKey_Keypad8; + case SDLK_KP_9: return ImGuiKey_Keypad9; + case SDLK_KP_PERIOD: return ImGuiKey_KeypadDecimal; + case SDLK_KP_DIVIDE: return ImGuiKey_KeypadDivide; + case SDLK_KP_MULTIPLY: return ImGuiKey_KeypadMultiply; + case SDLK_KP_MINUS: return ImGuiKey_KeypadSubtract; + case SDLK_KP_PLUS: return ImGuiKey_KeypadAdd; + case SDLK_KP_ENTER: return ImGuiKey_KeypadEnter; + case SDLK_KP_EQUALS: return ImGuiKey_KeypadEqual; + case SDLK_LCTRL: return ImGuiKey_LeftCtrl; + case SDLK_LSHIFT: return ImGuiKey_LeftShift; + case SDLK_LALT: return ImGuiKey_LeftAlt; + case SDLK_LGUI: return ImGuiKey_LeftSuper; + case SDLK_RCTRL: return ImGuiKey_RightCtrl; + case SDLK_RSHIFT: return ImGuiKey_RightShift; + case SDLK_RALT: return ImGuiKey_RightAlt; + case SDLK_RGUI: return ImGuiKey_RightSuper; + case SDLK_APPLICATION: return ImGuiKey_Menu; + case SDLK_0: return ImGuiKey_0; + case SDLK_1: return ImGuiKey_1; + case SDLK_2: return ImGuiKey_2; + case SDLK_3: return ImGuiKey_3; + case SDLK_4: return ImGuiKey_4; + case SDLK_5: return ImGuiKey_5; + case SDLK_6: return ImGuiKey_6; + case SDLK_7: return ImGuiKey_7; + case SDLK_8: return ImGuiKey_8; + case SDLK_9: return ImGuiKey_9; + case SDLK_a: return ImGuiKey_A; + case SDLK_b: return ImGuiKey_B; + case SDLK_c: return ImGuiKey_C; + case SDLK_d: return ImGuiKey_D; + case SDLK_e: return ImGuiKey_E; + case SDLK_f: return ImGuiKey_F; + case SDLK_g: return ImGuiKey_G; + case SDLK_h: return ImGuiKey_H; + case SDLK_i: return ImGuiKey_I; + case SDLK_j: return ImGuiKey_J; + case SDLK_k: return ImGuiKey_K; + case SDLK_l: return ImGuiKey_L; + case SDLK_m: return ImGuiKey_M; + case SDLK_n: return ImGuiKey_N; + case SDLK_o: return ImGuiKey_O; + case SDLK_p: return ImGuiKey_P; + case SDLK_q: return ImGuiKey_Q; + case SDLK_r: return ImGuiKey_R; + case SDLK_s: return ImGuiKey_S; + case SDLK_t: return ImGuiKey_T; + case SDLK_u: return ImGuiKey_U; + case SDLK_v: return ImGuiKey_V; + case SDLK_w: return ImGuiKey_W; + case SDLK_x: return ImGuiKey_X; + case SDLK_y: return ImGuiKey_Y; + case SDLK_z: return ImGuiKey_Z; + case SDLK_F1: return ImGuiKey_F1; + case SDLK_F2: return ImGuiKey_F2; + case SDLK_F3: return ImGuiKey_F3; + case SDLK_F4: return ImGuiKey_F4; + case SDLK_F5: return ImGuiKey_F5; + case SDLK_F6: return ImGuiKey_F6; + case SDLK_F7: return ImGuiKey_F7; + case SDLK_F8: return ImGuiKey_F8; + case SDLK_F9: return ImGuiKey_F9; + case SDLK_F10: return ImGuiKey_F10; + case SDLK_F11: return ImGuiKey_F11; + case SDLK_F12: return ImGuiKey_F12; + } + return ImGuiKey_None; +} + +static void ImGui_ImplSDL3_UpdateKeyModifiers(SDL_Keymod sdl_key_mods) +{ + ImGuiIO& io = ImGui::GetIO(); + io.AddKeyEvent(ImGuiMod_Ctrl, (sdl_key_mods & SDL_KMOD_CTRL) != 0); + io.AddKeyEvent(ImGuiMod_Shift, (sdl_key_mods & SDL_KMOD_SHIFT) != 0); + io.AddKeyEvent(ImGuiMod_Alt, (sdl_key_mods & SDL_KMOD_ALT) != 0); + io.AddKeyEvent(ImGuiMod_Super, (sdl_key_mods & SDL_KMOD_GUI) != 0); +} + +// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs. +// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application, or clear/overwrite your copy of the mouse data. +// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application, or clear/overwrite your copy of the keyboard data. +// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags. +// If you have multiple SDL events and some of them are not meant to be used by dear imgui, you may need to filter events based on their windowID field. +bool ImGui_ImplSDL3_ProcessEvent(const SDL_Event* event) +{ + ImGuiIO& io = ImGui::GetIO(); + ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData(); + + switch (event->type) + { + case SDL_EVENT_MOUSE_MOTION: + { + ImVec2 mouse_pos((float)event->motion.x, (float)event->motion.y); + if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) + { + int window_x, window_y; + SDL_GetWindowPosition(SDL_GetWindowFromID(event->motion.windowID), &window_x, &window_y); + mouse_pos.x += window_x; + mouse_pos.y += window_y; + } + io.AddMouseSourceEvent(event->motion.which == SDL_TOUCH_MOUSEID ? ImGuiMouseSource_TouchScreen : ImGuiMouseSource_Mouse); + io.AddMousePosEvent(mouse_pos.x, mouse_pos.y); + return true; + } + case SDL_EVENT_MOUSE_WHEEL: + { + //IMGUI_DEBUG_LOG("wheel %.2f %.2f, precise %.2f %.2f\n", (float)event->wheel.x, (float)event->wheel.y, event->wheel.preciseX, event->wheel.preciseY); + float wheel_x = -event->wheel.x; + float wheel_y = event->wheel.y; + #ifdef __EMSCRIPTEN__ + wheel_x /= 100.0f; + #endif + io.AddMouseSourceEvent(event->wheel.which == SDL_TOUCH_MOUSEID ? ImGuiMouseSource_TouchScreen : ImGuiMouseSource_Mouse); + io.AddMouseWheelEvent(wheel_x, wheel_y); + return true; + } + case SDL_EVENT_MOUSE_BUTTON_DOWN: + case SDL_EVENT_MOUSE_BUTTON_UP: + { + int mouse_button = -1; + if (event->button.button == SDL_BUTTON_LEFT) { mouse_button = 0; } + if (event->button.button == SDL_BUTTON_RIGHT) { mouse_button = 1; } + if (event->button.button == SDL_BUTTON_MIDDLE) { mouse_button = 2; } + if (event->button.button == SDL_BUTTON_X1) { mouse_button = 3; } + if (event->button.button == SDL_BUTTON_X2) { mouse_button = 4; } + if (mouse_button == -1) + break; + io.AddMouseSourceEvent(event->button.which == SDL_TOUCH_MOUSEID ? ImGuiMouseSource_TouchScreen : ImGuiMouseSource_Mouse); + io.AddMouseButtonEvent(mouse_button, (event->type == SDL_EVENT_MOUSE_BUTTON_DOWN)); + bd->MouseButtonsDown = (event->type == SDL_EVENT_MOUSE_BUTTON_DOWN) ? (bd->MouseButtonsDown | (1 << mouse_button)) : (bd->MouseButtonsDown & ~(1 << mouse_button)); + return true; + } + case SDL_EVENT_TEXT_INPUT: + { + io.AddInputCharactersUTF8(event->text.text); + return true; + } + case SDL_EVENT_KEY_DOWN: + case SDL_EVENT_KEY_UP: + { + ImGui_ImplSDL3_UpdateKeyModifiers((SDL_Keymod)event->key.keysym.mod); + ImGuiKey key = ImGui_ImplSDL3_KeycodeToImGuiKey(event->key.keysym.sym); + io.AddKeyEvent(key, (event->type == SDL_EVENT_KEY_DOWN)); + io.SetKeyEventNativeData(key, event->key.keysym.sym, event->key.keysym.scancode, event->key.keysym.scancode); // To support legacy indexing (<1.87 user code). Legacy backend uses SDLK_*** as indices to IsKeyXXX() functions. + return true; + } + case SDL_EVENT_DISPLAY_ORIENTATION: + case SDL_EVENT_DISPLAY_CONNECTED: + case SDL_EVENT_DISPLAY_DISCONNECTED: + case SDL_EVENT_DISPLAY_MOVED: + case SDL_EVENT_DISPLAY_CONTENT_SCALE_CHANGED: + { + bd->WantUpdateMonitors = true; + return true; + } + case SDL_EVENT_WINDOW_MOUSE_ENTER: + { + bd->MouseWindowID = event->window.windowID; + bd->PendingMouseLeaveFrame = 0; + return true; + } + // - In some cases, when detaching a window from main viewport SDL may send SDL_WINDOWEVENT_ENTER one frame too late, + // causing SDL_WINDOWEVENT_LEAVE on previous frame to interrupt drag operation by clear mouse position. This is why + // we delay process the SDL_WINDOWEVENT_LEAVE events by one frame. See issue #5012 for details. + // FIXME: Unconfirmed whether this is still needed with SDL3. + case SDL_EVENT_WINDOW_MOUSE_LEAVE: + { + bd->PendingMouseLeaveFrame = ImGui::GetFrameCount() + 1; + return true; + } + case SDL_EVENT_WINDOW_FOCUS_GAINED: + io.AddFocusEvent(true); + return true; + case SDL_EVENT_WINDOW_FOCUS_LOST: + io.AddFocusEvent(false); + return true; + case SDL_EVENT_WINDOW_CLOSE_REQUESTED: + case SDL_EVENT_WINDOW_MOVED: + case SDL_EVENT_WINDOW_RESIZED: + if (ImGuiViewport* viewport = ImGui::FindViewportByPlatformHandle((void*)SDL_GetWindowFromID(event->window.windowID))) + { + if (event->type == SDL_EVENT_WINDOW_CLOSE_REQUESTED) + viewport->PlatformRequestClose = true; + if (event->type == SDL_EVENT_WINDOW_MOVED) + viewport->PlatformRequestMove = true; + if (event->type == SDL_EVENT_WINDOW_RESIZED) + viewport->PlatformRequestResize = true; + return true; + } + return true; + } + return false; +} + +static bool ImGui_ImplSDL3_Init(SDL_Window* window, SDL_Renderer* renderer, void* sdl_gl_context) +{ + ImGuiIO& io = ImGui::GetIO(); + IM_ASSERT(io.BackendPlatformUserData == nullptr && "Already initialized a platform backend!"); + + // Check and store if we are on a SDL backend that supports global mouse position + // ("wayland" and "rpi" don't support it, but we chose to use a white-list instead of a black-list) + bool mouse_can_use_global_state = false; +#if SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE + const char* sdl_backend = SDL_GetCurrentVideoDriver(); + const char* global_mouse_whitelist[] = { "windows", "cocoa", "x11", "DIVE", "VMAN" }; + for (int n = 0; n < IM_ARRAYSIZE(global_mouse_whitelist); n++) + if (strncmp(sdl_backend, global_mouse_whitelist[n], strlen(global_mouse_whitelist[n])) == 0) + mouse_can_use_global_state = true; +#endif + + // Setup backend capabilities flags + ImGui_ImplSDL3_Data* bd = IM_NEW(ImGui_ImplSDL3_Data)(); + io.BackendPlatformUserData = (void*)bd; + io.BackendPlatformName = "imgui_impl_sdl3"; + io.BackendFlags |= ImGuiBackendFlags_HasMouseCursors; // We can honor GetMouseCursor() values (optional) + io.BackendFlags |= ImGuiBackendFlags_HasSetMousePos; // We can honor io.WantSetMousePos requests (optional, rarely used) + if (mouse_can_use_global_state) + io.BackendFlags |= ImGuiBackendFlags_PlatformHasViewports; // We can create multi-viewports on the Platform side (optional) + + bd->Window = window; + bd->Renderer = renderer; + + // SDL on Linux/OSX doesn't report events for unfocused windows (see https://github.com/ocornut/imgui/issues/4960) + // We will use 'MouseCanReportHoveredViewport' to set 'ImGuiBackendFlags_HasMouseHoveredViewport' dynamically each frame. + bd->MouseCanUseGlobalState = mouse_can_use_global_state; +#ifndef __APPLE__ + bd->MouseCanReportHoveredViewport = bd->MouseCanUseGlobalState; +#else + bd->MouseCanReportHoveredViewport = false; +#endif + bd->WantUpdateMonitors = true; + + io.SetClipboardTextFn = ImGui_ImplSDL3_SetClipboardText; + io.GetClipboardTextFn = ImGui_ImplSDL3_GetClipboardText; + io.ClipboardUserData = nullptr; + io.SetPlatformImeDataFn = ImGui_ImplSDL3_SetPlatformImeData; + + // Load mouse cursors + bd->MouseCursors[ImGuiMouseCursor_Arrow] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW); + bd->MouseCursors[ImGuiMouseCursor_TextInput] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_IBEAM); + bd->MouseCursors[ImGuiMouseCursor_ResizeAll] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZEALL); + bd->MouseCursors[ImGuiMouseCursor_ResizeNS] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENS); + bd->MouseCursors[ImGuiMouseCursor_ResizeEW] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZEWE); + bd->MouseCursors[ImGuiMouseCursor_ResizeNESW] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENESW); + bd->MouseCursors[ImGuiMouseCursor_ResizeNWSE] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENWSE); + bd->MouseCursors[ImGuiMouseCursor_Hand] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_HAND); + bd->MouseCursors[ImGuiMouseCursor_NotAllowed] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_NO); + + // Set platform dependent data in viewport + // Our mouse update function expect PlatformHandle to be filled for the main viewport + ImGuiViewport* main_viewport = ImGui::GetMainViewport(); + main_viewport->PlatformHandle = (void*)window; + main_viewport->PlatformHandleRaw = nullptr; + SDL_SysWMinfo info; + if (SDL_GetWindowWMInfo(window, &info, SDL_SYSWM_CURRENT_VERSION) == 0) + { +#if defined(SDL_ENABLE_SYSWM_WINDOWS) + main_viewport->PlatformHandleRaw = (void*)info.info.win.window; +#elif defined(__APPLE__) && defined(SDL_ENABLE_SYSWM_COCOA) + main_viewport->PlatformHandleRaw = (void*)info.info.cocoa.window; +#endif + } + + // From 2.0.5: Set SDL hint to receive mouse click events on window focus, otherwise SDL doesn't emit the event. + // Without this, when clicking to gain focus, our widgets wouldn't activate even though they showed as hovered. + // (This is unfortunately a global SDL setting, so enabling it might have a side-effect on your application. + // It is unlikely to make a difference, but if your app absolutely needs to ignore the initial on-focus click: + // you can ignore SDL_EVENT_MOUSE_BUTTON_DOWN events coming right after a SDL_WINDOWEVENT_FOCUS_GAINED) + SDL_SetHint(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "1"); + + // From 2.0.22: Disable auto-capture, this is preventing drag and drop across multiple windows (see #5710) + SDL_SetHint(SDL_HINT_MOUSE_AUTO_CAPTURE, "0"); + + // SDL 3.x : see https://github.com/libsdl-org/SDL/issues/6659 + SDL_SetHint("SDL_BORDERLESS_WINDOWED_STYLE", "0"); + + // We need SDL_CaptureMouse(), SDL_GetGlobalMouseState() from SDL 2.0.4+ to support multiple viewports. + // We left the call to ImGui_ImplSDL3_InitPlatformInterface() outside of #ifdef to avoid unused-function warnings. + if ((io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) && (io.BackendFlags & ImGuiBackendFlags_PlatformHasViewports)) + ImGui_ImplSDL3_InitPlatformInterface(window, sdl_gl_context); + + return true; +} + +bool ImGui_ImplSDL3_InitForOpenGL(SDL_Window* window, void* sdl_gl_context) +{ + return ImGui_ImplSDL3_Init(window, nullptr, sdl_gl_context); +} + +bool ImGui_ImplSDL3_InitForVulkan(SDL_Window* window) +{ + if (!ImGui_ImplSDL3_Init(window, nullptr, nullptr)) + return false; + ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData(); + bd->UseVulkan = true; + return true; +} + +bool ImGui_ImplSDL3_InitForD3D(SDL_Window* window) +{ +#if !defined(_WIN32) + IM_ASSERT(0 && "Unsupported"); +#endif + return ImGui_ImplSDL3_Init(window, nullptr, nullptr); +} + +bool ImGui_ImplSDL3_InitForMetal(SDL_Window* window) +{ + return ImGui_ImplSDL3_Init(window, nullptr, nullptr); +} + +bool ImGui_ImplSDL3_InitForSDLRenderer(SDL_Window* window, SDL_Renderer* renderer) +{ + return ImGui_ImplSDL3_Init(window, renderer, nullptr); +} + +void ImGui_ImplSDL3_Shutdown() +{ + ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData(); + IM_ASSERT(bd != nullptr && "No platform backend to shutdown, or already shutdown?"); + ImGuiIO& io = ImGui::GetIO(); + + ImGui_ImplSDL3_ShutdownPlatformInterface(); + + if (bd->ClipboardTextData) + SDL_free(bd->ClipboardTextData); + for (ImGuiMouseCursor cursor_n = 0; cursor_n < ImGuiMouseCursor_COUNT; cursor_n++) + SDL_DestroyCursor(bd->MouseCursors[cursor_n]); + bd->LastMouseCursor = nullptr; + + io.BackendPlatformName = nullptr; + io.BackendPlatformUserData = nullptr; + io.BackendFlags &= ~(ImGuiBackendFlags_HasMouseCursors | ImGuiBackendFlags_HasSetMousePos | ImGuiBackendFlags_HasGamepad | ImGuiBackendFlags_PlatformHasViewports | ImGuiBackendFlags_HasMouseHoveredViewport); + IM_DELETE(bd); +} + +// This code is incredibly messy because some of the functions we need for full viewport support are not available in SDL < 2.0.4. +static void ImGui_ImplSDL3_UpdateMouseData() +{ + ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData(); + ImGuiIO& io = ImGui::GetIO(); + + // We forward mouse input when hovered or captured (via SDL_EVENT_MOUSE_MOTION) or when focused (below) +#if SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE + // SDL_CaptureMouse() let the OS know e.g. that our imgui drag outside the SDL window boundaries shouldn't e.g. trigger other operations outside + SDL_CaptureMouse((bd->MouseButtonsDown != 0) ? SDL_TRUE : SDL_FALSE); + SDL_Window* focused_window = SDL_GetKeyboardFocus(); + const bool is_app_focused = (focused_window && (bd->Window == focused_window || ImGui::FindViewportByPlatformHandle((void*)focused_window))); +#else + SDL_Window* focused_window = bd->Window; + const bool is_app_focused = (SDL_GetWindowFlags(bd->Window) & SDL_WINDOW_INPUT_FOCUS) != 0; // SDL 2.0.3 and non-windowed systems: single-viewport only +#endif + if (is_app_focused) + { + // (Optional) Set OS mouse position from Dear ImGui if requested (rarely used, only when ImGuiConfigFlags_NavEnableSetMousePos is enabled by user) + if (io.WantSetMousePos) + { +#if SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE + if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) + SDL_WarpMouseGlobal(io.MousePos.x, io.MousePos.y); + else +#endif + SDL_WarpMouseInWindow(bd->Window, io.MousePos.x, io.MousePos.y); + } + + // (Optional) Fallback to provide mouse position when focused (SDL_EVENT_MOUSE_MOTION already provides this when hovered or captured) + if (bd->MouseCanUseGlobalState && bd->MouseButtonsDown == 0) + { + // Single-viewport mode: mouse position in client window coordinates (io.MousePos is (0,0) when the mouse is on the upper-left corner of the app window) + // Multi-viewport mode: mouse position in OS absolute coordinates (io.MousePos is (0,0) when the mouse is on the upper-left of the primary monitor) + float mouse_x, mouse_y; + int window_x, window_y; + SDL_GetGlobalMouseState(&mouse_x, &mouse_y); + if (!(io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)) + { + SDL_GetWindowPosition(focused_window, &window_x, &window_y); + mouse_x -= window_x; + mouse_y -= window_y; + } + io.AddMousePosEvent((float)mouse_x, (float)mouse_y); + } + } + + // (Optional) When using multiple viewports: call io.AddMouseViewportEvent() with the viewport the OS mouse cursor is hovering. + // If ImGuiBackendFlags_HasMouseHoveredViewport is not set by the backend, Dear imGui will ignore this field and infer the information using its flawed heuristic. + // - [!] SDL backend does NOT correctly ignore viewports with the _NoInputs flag. + // Some backend are not able to handle that correctly. If a backend report an hovered viewport that has the _NoInputs flag (e.g. when dragging a window + // for docking, the viewport has the _NoInputs flag in order to allow us to find the viewport under), then Dear ImGui is forced to ignore the value reported + // by the backend, and use its flawed heuristic to guess the viewport behind. + // - [X] SDL backend correctly reports this regardless of another viewport behind focused and dragged from (we need this to find a useful drag and drop target). + if (io.BackendFlags & ImGuiBackendFlags_HasMouseHoveredViewport) + { + ImGuiID mouse_viewport_id = 0; + if (SDL_Window* sdl_mouse_window = SDL_GetWindowFromID(bd->MouseWindowID)) + if (ImGuiViewport* mouse_viewport = ImGui::FindViewportByPlatformHandle((void*)sdl_mouse_window)) + mouse_viewport_id = mouse_viewport->ID; + io.AddMouseViewportEvent(mouse_viewport_id); + } +} + +static void ImGui_ImplSDL3_UpdateMouseCursor() +{ + ImGuiIO& io = ImGui::GetIO(); + if (io.ConfigFlags & ImGuiConfigFlags_NoMouseCursorChange) + return; + ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData(); + + ImGuiMouseCursor imgui_cursor = ImGui::GetMouseCursor(); + if (io.MouseDrawCursor || imgui_cursor == ImGuiMouseCursor_None) + { + // Hide OS mouse cursor if imgui is drawing it or if it wants no cursor + SDL_HideCursor(); + } + else + { + // Show OS mouse cursor + SDL_Cursor* expected_cursor = bd->MouseCursors[imgui_cursor] ? bd->MouseCursors[imgui_cursor] : bd->MouseCursors[ImGuiMouseCursor_Arrow]; + if (bd->LastMouseCursor != expected_cursor) + { + SDL_SetCursor(expected_cursor); // SDL function doesn't have an early out (see #6113) + bd->LastMouseCursor = expected_cursor; + } + SDL_ShowCursor(); + } +} + +static void ImGui_ImplSDL3_UpdateGamepads() +{ + ImGuiIO& io = ImGui::GetIO(); + if ((io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) == 0) // FIXME: Technically feeding gamepad shouldn't depend on this now that they are regular inputs. + return; + + // Get gamepad + io.BackendFlags &= ~ImGuiBackendFlags_HasGamepad; + SDL_Gamepad* gamepad = SDL_OpenGamepad(0); + if (!gamepad) + return; + io.BackendFlags |= ImGuiBackendFlags_HasGamepad; + + // Update gamepad inputs + #define IM_SATURATE(V) (V < 0.0f ? 0.0f : V > 1.0f ? 1.0f : V) + #define MAP_BUTTON(KEY_NO, BUTTON_NO) { io.AddKeyEvent(KEY_NO, SDL_GetGamepadButton(gamepad, BUTTON_NO) != 0); } + #define MAP_ANALOG(KEY_NO, AXIS_NO, V0, V1) { float vn = (float)(SDL_GetGamepadAxis(gamepad, AXIS_NO) - V0) / (float)(V1 - V0); vn = IM_SATURATE(vn); io.AddKeyAnalogEvent(KEY_NO, vn > 0.1f, vn); } + const int thumb_dead_zone = 8000; // SDL_gamecontroller.h suggests using this value. + MAP_BUTTON(ImGuiKey_GamepadStart, SDL_GAMEPAD_BUTTON_START); + MAP_BUTTON(ImGuiKey_GamepadBack, SDL_GAMEPAD_BUTTON_BACK); + MAP_BUTTON(ImGuiKey_GamepadFaceLeft, SDL_GAMEPAD_BUTTON_X); // Xbox X, PS Square + MAP_BUTTON(ImGuiKey_GamepadFaceRight, SDL_GAMEPAD_BUTTON_B); // Xbox B, PS Circle + MAP_BUTTON(ImGuiKey_GamepadFaceUp, SDL_GAMEPAD_BUTTON_Y); // Xbox Y, PS Triangle + MAP_BUTTON(ImGuiKey_GamepadFaceDown, SDL_GAMEPAD_BUTTON_A); // Xbox A, PS Cross + MAP_BUTTON(ImGuiKey_GamepadDpadLeft, SDL_GAMEPAD_BUTTON_DPAD_LEFT); + MAP_BUTTON(ImGuiKey_GamepadDpadRight, SDL_GAMEPAD_BUTTON_DPAD_RIGHT); + MAP_BUTTON(ImGuiKey_GamepadDpadUp, SDL_GAMEPAD_BUTTON_DPAD_UP); + MAP_BUTTON(ImGuiKey_GamepadDpadDown, SDL_GAMEPAD_BUTTON_DPAD_DOWN); + MAP_BUTTON(ImGuiKey_GamepadL1, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER); + MAP_BUTTON(ImGuiKey_GamepadR1, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER); + MAP_ANALOG(ImGuiKey_GamepadL2, SDL_GAMEPAD_AXIS_LEFT_TRIGGER, 0.0f, 32767); + MAP_ANALOG(ImGuiKey_GamepadR2, SDL_GAMEPAD_AXIS_RIGHT_TRIGGER, 0.0f, 32767); + MAP_BUTTON(ImGuiKey_GamepadL3, SDL_GAMEPAD_BUTTON_LEFT_STICK); + MAP_BUTTON(ImGuiKey_GamepadR3, SDL_GAMEPAD_BUTTON_RIGHT_STICK); + MAP_ANALOG(ImGuiKey_GamepadLStickLeft, SDL_GAMEPAD_AXIS_LEFTX, -thumb_dead_zone, -32768); + MAP_ANALOG(ImGuiKey_GamepadLStickRight, SDL_GAMEPAD_AXIS_LEFTX, +thumb_dead_zone, +32767); + MAP_ANALOG(ImGuiKey_GamepadLStickUp, SDL_GAMEPAD_AXIS_LEFTY, -thumb_dead_zone, -32768); + MAP_ANALOG(ImGuiKey_GamepadLStickDown, SDL_GAMEPAD_AXIS_LEFTY, +thumb_dead_zone, +32767); + MAP_ANALOG(ImGuiKey_GamepadRStickLeft, SDL_GAMEPAD_AXIS_RIGHTX, -thumb_dead_zone, -32768); + MAP_ANALOG(ImGuiKey_GamepadRStickRight, SDL_GAMEPAD_AXIS_RIGHTX, +thumb_dead_zone, +32767); + MAP_ANALOG(ImGuiKey_GamepadRStickUp, SDL_GAMEPAD_AXIS_RIGHTY, -thumb_dead_zone, -32768); + MAP_ANALOG(ImGuiKey_GamepadRStickDown, SDL_GAMEPAD_AXIS_RIGHTY, +thumb_dead_zone, +32767); + #undef MAP_BUTTON + #undef MAP_ANALOG +} + +static void ImGui_ImplSDL3_UpdateMonitors() +{ + ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData(); + ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO(); + platform_io.Monitors.resize(0); + bd->WantUpdateMonitors = false; + + int display_count; + SDL_DisplayID* displays = SDL_GetDisplays(&display_count); + for (int n = 0; n < display_count; n++) + { + // Warning: the validity of monitor DPI information on Windows depends on the application DPI awareness settings, which generally needs to be set in the manifest or at runtime. + SDL_DisplayID display_id = displays[n]; + ImGuiPlatformMonitor monitor; + SDL_Rect r; + SDL_GetDisplayBounds(display_id, &r); + monitor.MainPos = monitor.WorkPos = ImVec2((float)r.x, (float)r.y); + monitor.MainSize = monitor.WorkSize = ImVec2((float)r.w, (float)r.h); + SDL_GetDisplayUsableBounds(display_id, &r); + monitor.WorkPos = ImVec2((float)r.x, (float)r.y); + monitor.WorkSize = ImVec2((float)r.w, (float)r.h); + // FIXME-VIEWPORT: On MacOS SDL reports actual monitor DPI scale, ignoring OS configuration. We may want to set + // DpiScale to cocoa_window.backingScaleFactor here. + monitor.DpiScale = SDL_GetDisplayContentScale(display_id); + monitor.PlatformHandle = (void*)(intptr_t)n; + platform_io.Monitors.push_back(monitor); + } +} + +void ImGui_ImplSDL3_NewFrame() +{ + ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData(); + IM_ASSERT(bd != nullptr && "Did you call ImGui_ImplSDL3_Init()?"); + ImGuiIO& io = ImGui::GetIO(); + + // Setup display size (every frame to accommodate for window resizing) + int w, h; + int display_w, display_h; + SDL_GetWindowSize(bd->Window, &w, &h); + if (SDL_GetWindowFlags(bd->Window) & SDL_WINDOW_MINIMIZED) + w = h = 0; + SDL_GetWindowSizeInPixels(bd->Window, &display_w, &display_h); + io.DisplaySize = ImVec2((float)w, (float)h); + if (w > 0 && h > 0) + io.DisplayFramebufferScale = ImVec2((float)display_w / w, (float)display_h / h); + + // Update monitors + if (bd->WantUpdateMonitors) + ImGui_ImplSDL3_UpdateMonitors(); + + // Setup time step (we don't use SDL_GetTicks() because it is using millisecond resolution) + // (Accept SDL_GetPerformanceCounter() not returning a monotonically increasing value. Happens in VMs and Emscripten, see #6189, #6114, #3644) + static Uint64 frequency = SDL_GetPerformanceFrequency(); + Uint64 current_time = SDL_GetPerformanceCounter(); + if (current_time <= bd->Time) + current_time = bd->Time + 1; + io.DeltaTime = bd->Time > 0 ? (float)((double)(current_time - bd->Time) / frequency) : (float)(1.0f / 60.0f); + bd->Time = current_time; + + if (bd->PendingMouseLeaveFrame && bd->PendingMouseLeaveFrame >= ImGui::GetFrameCount() && bd->MouseButtonsDown == 0) + { + bd->MouseWindowID = 0; + bd->PendingMouseLeaveFrame = 0; + io.AddMousePosEvent(-FLT_MAX, -FLT_MAX); + } + + // Our io.AddMouseViewportEvent() calls will only be valid when not capturing. + // Technically speaking testing for 'bd->MouseButtonsDown == 0' would be more rygorous, but testing for payload reduces noise and potential side-effects. + if (bd->MouseCanReportHoveredViewport && ImGui::GetDragDropPayload() == nullptr) + io.BackendFlags |= ImGuiBackendFlags_HasMouseHoveredViewport; + else + io.BackendFlags &= ~ImGuiBackendFlags_HasMouseHoveredViewport; + + ImGui_ImplSDL3_UpdateMouseData(); + ImGui_ImplSDL3_UpdateMouseCursor(); + + // Update game controllers (if enabled and available) + ImGui_ImplSDL3_UpdateGamepads(); +} + +//-------------------------------------------------------------------------------------------------------- +// MULTI-VIEWPORT / PLATFORM INTERFACE SUPPORT +// This is an _advanced_ and _optional_ feature, allowing the backend to create and handle multiple viewports simultaneously. +// If you are new to dear imgui or creating a new binding for dear imgui, it is recommended that you completely ignore this section first.. +//-------------------------------------------------------------------------------------------------------- + +// Helper structure we store in the void* RendererUserData field of each ImGuiViewport to easily retrieve our backend data. +struct ImGui_ImplSDL3_ViewportData +{ + SDL_Window* Window; + Uint32 WindowID; + bool WindowOwned; + SDL_GLContext GLContext; + + ImGui_ImplSDL3_ViewportData() { Window = nullptr; WindowID = 0; WindowOwned = false; GLContext = nullptr; } + ~ImGui_ImplSDL3_ViewportData() { IM_ASSERT(Window == nullptr && GLContext == nullptr); } +}; + +static void ImGui_ImplSDL3_CreateWindow(ImGuiViewport* viewport) +{ + ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData(); + ImGui_ImplSDL3_ViewportData* vd = IM_NEW(ImGui_ImplSDL3_ViewportData)(); + viewport->PlatformUserData = vd; + + ImGuiViewport* main_viewport = ImGui::GetMainViewport(); + ImGui_ImplSDL3_ViewportData* main_viewport_data = (ImGui_ImplSDL3_ViewportData*)main_viewport->PlatformUserData; + + // Share GL resources with main context + bool use_opengl = (main_viewport_data->GLContext != nullptr); + SDL_GLContext backup_context = nullptr; + if (use_opengl) + { + backup_context = SDL_GL_GetCurrentContext(); + SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1); + SDL_GL_MakeCurrent(main_viewport_data->Window, main_viewport_data->GLContext); + } + + Uint32 sdl_flags = 0; + sdl_flags |= use_opengl ? SDL_WINDOW_OPENGL : (bd->UseVulkan ? SDL_WINDOW_VULKAN : 0); + sdl_flags |= SDL_GetWindowFlags(bd->Window); + sdl_flags |= (viewport->Flags & ImGuiViewportFlags_NoDecoration) ? SDL_WINDOW_BORDERLESS : 0; + sdl_flags |= (viewport->Flags & ImGuiViewportFlags_NoDecoration) ? 0 : SDL_WINDOW_RESIZABLE; +#if !defined(_WIN32) + // See SDL hack in ImGui_ImplSDL3_ShowWindow(). + sdl_flags |= (viewport->Flags & ImGuiViewportFlags_NoTaskBarIcon) ? SDL_WINDOW_SKIP_TASKBAR : 0; +#endif + sdl_flags |= (viewport->Flags & ImGuiViewportFlags_TopMost) ? SDL_WINDOW_ALWAYS_ON_TOP : 0; + vd->Window = SDL_CreateWindow("No Title Yet", (int)viewport->Size.x, (int)viewport->Size.y, sdl_flags); + SDL_SetWindowPosition(vd->Window, (int)viewport->Pos.x, (int)viewport->Pos.y); + vd->WindowOwned = true; + if (use_opengl) + { + vd->GLContext = SDL_GL_CreateContext(vd->Window); + SDL_GL_SetSwapInterval(0); + } + if (use_opengl && backup_context) + SDL_GL_MakeCurrent(vd->Window, backup_context); + + viewport->PlatformHandle = (void*)vd->Window; + viewport->PlatformHandleRaw = nullptr; + SDL_SysWMinfo info; + if (SDL_GetWindowWMInfo(vd->Window, &info, SDL_SYSWM_CURRENT_VERSION)) + { +#if defined(SDL_VIDEO_DRIVER_WINDOWS) + viewport->PlatformHandleRaw = info.info.win.window; +#elif defined(__APPLE__) && defined(SDL_VIDEO_DRIVER_COCOA) + viewport->PlatformHandleRaw = (void*)info.info.cocoa.window; +#endif + } +} + +static void ImGui_ImplSDL3_DestroyWindow(ImGuiViewport* viewport) +{ + if (ImGui_ImplSDL3_ViewportData* vd = (ImGui_ImplSDL3_ViewportData*)viewport->PlatformUserData) + { + if (vd->GLContext && vd->WindowOwned) + SDL_GL_DeleteContext(vd->GLContext); + if (vd->Window && vd->WindowOwned) + SDL_DestroyWindow(vd->Window); + vd->GLContext = nullptr; + vd->Window = nullptr; + IM_DELETE(vd); + } + viewport->PlatformUserData = viewport->PlatformHandle = nullptr; +} + +static void ImGui_ImplSDL3_ShowWindow(ImGuiViewport* viewport) +{ + ImGui_ImplSDL3_ViewportData* vd = (ImGui_ImplSDL3_ViewportData*)viewport->PlatformUserData; +#if defined(_WIN32) + HWND hwnd = (HWND)viewport->PlatformHandleRaw; + + // SDL hack: Hide icon from task bar + // Note: SDL 2.0.6+ has a SDL_WINDOW_SKIP_TASKBAR flag which is supported under Windows but the way it create the window breaks our seamless transition. + if (viewport->Flags & ImGuiViewportFlags_NoTaskBarIcon) + { + LONG ex_style = ::GetWindowLong(hwnd, GWL_EXSTYLE); + ex_style &= ~WS_EX_APPWINDOW; + ex_style |= WS_EX_TOOLWINDOW; + ::SetWindowLong(hwnd, GWL_EXSTYLE, ex_style); + } + + // SDL hack: SDL always activate/focus windows :/ + if (viewport->Flags & ImGuiViewportFlags_NoFocusOnAppearing) + { + ::ShowWindow(hwnd, SW_SHOWNA); + return; + } +#endif + + SDL_ShowWindow(vd->Window); +} + +static ImVec2 ImGui_ImplSDL3_GetWindowPos(ImGuiViewport* viewport) +{ + ImGui_ImplSDL3_ViewportData* vd = (ImGui_ImplSDL3_ViewportData*)viewport->PlatformUserData; + int x = 0, y = 0; + SDL_GetWindowPosition(vd->Window, &x, &y); + return ImVec2((float)x, (float)y); +} + +static void ImGui_ImplSDL3_SetWindowPos(ImGuiViewport* viewport, ImVec2 pos) +{ + ImGui_ImplSDL3_ViewportData* vd = (ImGui_ImplSDL3_ViewportData*)viewport->PlatformUserData; + SDL_SetWindowPosition(vd->Window, (int)pos.x, (int)pos.y); +} + +static ImVec2 ImGui_ImplSDL3_GetWindowSize(ImGuiViewport* viewport) +{ + ImGui_ImplSDL3_ViewportData* vd = (ImGui_ImplSDL3_ViewportData*)viewport->PlatformUserData; + int w = 0, h = 0; + SDL_GetWindowSize(vd->Window, &w, &h); + return ImVec2((float)w, (float)h); +} + +static void ImGui_ImplSDL3_SetWindowSize(ImGuiViewport* viewport, ImVec2 size) +{ + ImGui_ImplSDL3_ViewportData* vd = (ImGui_ImplSDL3_ViewportData*)viewport->PlatformUserData; + SDL_SetWindowSize(vd->Window, (int)size.x, (int)size.y); +} + +static void ImGui_ImplSDL3_SetWindowTitle(ImGuiViewport* viewport, const char* title) +{ + ImGui_ImplSDL3_ViewportData* vd = (ImGui_ImplSDL3_ViewportData*)viewport->PlatformUserData; + SDL_SetWindowTitle(vd->Window, title); +} + +static void ImGui_ImplSDL3_SetWindowAlpha(ImGuiViewport* viewport, float alpha) +{ + ImGui_ImplSDL3_ViewportData* vd = (ImGui_ImplSDL3_ViewportData*)viewport->PlatformUserData; + SDL_SetWindowOpacity(vd->Window, alpha); +} + +static void ImGui_ImplSDL3_SetWindowFocus(ImGuiViewport* viewport) +{ + ImGui_ImplSDL3_ViewportData* vd = (ImGui_ImplSDL3_ViewportData*)viewport->PlatformUserData; + SDL_RaiseWindow(vd->Window); +} + +static bool ImGui_ImplSDL3_GetWindowFocus(ImGuiViewport* viewport) +{ + ImGui_ImplSDL3_ViewportData* vd = (ImGui_ImplSDL3_ViewportData*)viewport->PlatformUserData; + return (SDL_GetWindowFlags(vd->Window) & SDL_WINDOW_INPUT_FOCUS) != 0; +} + +static bool ImGui_ImplSDL3_GetWindowMinimized(ImGuiViewport* viewport) +{ + ImGui_ImplSDL3_ViewportData* vd = (ImGui_ImplSDL3_ViewportData*)viewport->PlatformUserData; + return (SDL_GetWindowFlags(vd->Window) & SDL_WINDOW_MINIMIZED) != 0; +} + +static void ImGui_ImplSDL3_RenderWindow(ImGuiViewport* viewport, void*) +{ + ImGui_ImplSDL3_ViewportData* vd = (ImGui_ImplSDL3_ViewportData*)viewport->PlatformUserData; + if (vd->GLContext) + SDL_GL_MakeCurrent(vd->Window, vd->GLContext); +} + +static void ImGui_ImplSDL3_SwapBuffers(ImGuiViewport* viewport, void*) +{ + ImGui_ImplSDL3_ViewportData* vd = (ImGui_ImplSDL3_ViewportData*)viewport->PlatformUserData; + if (vd->GLContext) + { + SDL_GL_MakeCurrent(vd->Window, vd->GLContext); + SDL_GL_SwapWindow(vd->Window); + } +} + +// Vulkan support (the Vulkan renderer needs to call a platform-side support function to create the surface) +// SDL is graceful enough to _not_ need so we can safely include this. +#include +static int ImGui_ImplSDL3_CreateVkSurface(ImGuiViewport* viewport, ImU64 vk_instance, const void* vk_allocator, ImU64* out_vk_surface) +{ + ImGui_ImplSDL3_ViewportData* vd = (ImGui_ImplSDL3_ViewportData*)viewport->PlatformUserData; + (void)vk_allocator; + SDL_bool ret = SDL_Vulkan_CreateSurface(vd->Window, (VkInstance)vk_instance, (VkSurfaceKHR*)out_vk_surface); + return ret ? 0 : 1; // ret ? VK_SUCCESS : VK_NOT_READY +} + +static void ImGui_ImplSDL3_InitPlatformInterface(SDL_Window* window, void* sdl_gl_context) +{ + // Register platform interface (will be coupled with a renderer interface) + ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO(); + platform_io.Platform_CreateWindow = ImGui_ImplSDL3_CreateWindow; + platform_io.Platform_DestroyWindow = ImGui_ImplSDL3_DestroyWindow; + platform_io.Platform_ShowWindow = ImGui_ImplSDL3_ShowWindow; + platform_io.Platform_SetWindowPos = ImGui_ImplSDL3_SetWindowPos; + platform_io.Platform_GetWindowPos = ImGui_ImplSDL3_GetWindowPos; + platform_io.Platform_SetWindowSize = ImGui_ImplSDL3_SetWindowSize; + platform_io.Platform_GetWindowSize = ImGui_ImplSDL3_GetWindowSize; + platform_io.Platform_SetWindowFocus = ImGui_ImplSDL3_SetWindowFocus; + platform_io.Platform_GetWindowFocus = ImGui_ImplSDL3_GetWindowFocus; + platform_io.Platform_GetWindowMinimized = ImGui_ImplSDL3_GetWindowMinimized; + platform_io.Platform_SetWindowTitle = ImGui_ImplSDL3_SetWindowTitle; + platform_io.Platform_RenderWindow = ImGui_ImplSDL3_RenderWindow; + platform_io.Platform_SwapBuffers = ImGui_ImplSDL3_SwapBuffers; + platform_io.Platform_SetWindowAlpha = ImGui_ImplSDL3_SetWindowAlpha; + platform_io.Platform_CreateVkSurface = ImGui_ImplSDL3_CreateVkSurface; + + // Register main window handle (which is owned by the main application, not by us) + // This is mostly for simplicity and consistency, so that our code (e.g. mouse handling etc.) can use same logic for main and secondary viewports. + ImGuiViewport* main_viewport = ImGui::GetMainViewport(); + ImGui_ImplSDL3_ViewportData* vd = IM_NEW(ImGui_ImplSDL3_ViewportData)(); + vd->Window = window; + vd->WindowID = SDL_GetWindowID(window); + vd->WindowOwned = false; + vd->GLContext = sdl_gl_context; + main_viewport->PlatformUserData = vd; + main_viewport->PlatformHandle = vd->Window; +} + +static void ImGui_ImplSDL3_ShutdownPlatformInterface() +{ + ImGui::DestroyPlatformWindows(); +} + +#if defined(__clang__) +#pragma clang diagnostic pop +#endif diff --git a/extern/imgui_patched/backends/imgui_impl_sdl3.h b/extern/imgui_patched/backends/imgui_impl_sdl3.h new file mode 100644 index 00000000..e2d9f90f --- /dev/null +++ b/extern/imgui_patched/backends/imgui_impl_sdl3.h @@ -0,0 +1,36 @@ +// dear imgui: Platform Backend for SDL3 (*EXPERIMENTAL*) +// This needs to be used along with a Renderer (e.g. DirectX11, OpenGL3, Vulkan..) +// (Info: SDL3 is a cross-platform general purpose library for handling windows, inputs, graphics context creation, etc.) +// (IMPORTANT: SDL 3.0.0 is NOT YET RELEASED. IT IS POSSIBLE THAT ITS SPECS/API WILL CHANGE BEFORE RELEASE) + +// Implemented features: +// [X] Platform: Clipboard support. +// [X] Platform: Mouse support. Can discriminate Mouse/TouchScreen. +// [X] Platform: Keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(ImGuiKey_Space). [Legacy SDL_SCANCODE_* values will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set] +// [X] Platform: Gamepad support. Enabled with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'. +// [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'. +// [x] Platform: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable' -> the OS animation effect when window gets created/destroyed is problematic. SDL2 backend doesn't have issue. +// Missing features: +// [ ] Platform: Multi-viewport + Minimized windows seems to break mouse wheel events (at least under Windows). +// [x] Platform: Basic IME support. Position somehow broken in SDL3 + app needs to call 'SDL_SetHint(SDL_HINT_IME_SHOW_UI, "1");' before SDL_CreateWindow()!. + +// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. +// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. +// If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp. +// Read online: https://github.com/ocornut/imgui/tree/master/docs + +#pragma once +#include "imgui.h" // IMGUI_IMPL_API + +struct SDL_Window; +struct SDL_Renderer; +typedef union SDL_Event SDL_Event; + +IMGUI_IMPL_API bool ImGui_ImplSDL3_InitForOpenGL(SDL_Window* window, void* sdl_gl_context); +IMGUI_IMPL_API bool ImGui_ImplSDL3_InitForVulkan(SDL_Window* window); +IMGUI_IMPL_API bool ImGui_ImplSDL3_InitForD3D(SDL_Window* window); +IMGUI_IMPL_API bool ImGui_ImplSDL3_InitForMetal(SDL_Window* window); +IMGUI_IMPL_API bool ImGui_ImplSDL3_InitForSDLRenderer(SDL_Window* window, SDL_Renderer* renderer); +IMGUI_IMPL_API void ImGui_ImplSDL3_Shutdown(); +IMGUI_IMPL_API void ImGui_ImplSDL3_NewFrame(); +IMGUI_IMPL_API bool ImGui_ImplSDL3_ProcessEvent(const SDL_Event* event); diff --git a/extern/imgui_patched/backends/imgui_impl_sdlrenderer.h b/extern/imgui_patched/backends/imgui_impl_sdlrenderer.h deleted file mode 100644 index 3281a758..00000000 --- a/extern/imgui_patched/backends/imgui_impl_sdlrenderer.h +++ /dev/null @@ -1,31 +0,0 @@ -// dear imgui: Renderer Backend for SDL_Renderer -// (Requires: SDL 2.0.17+) - -// Important to understand: SDL_Renderer is an _optional_ component of SDL. -// For a multi-platform app consider using e.g. SDL+DirectX on Windows and SDL+OpenGL on Linux/OSX. -// If your application will want to render any non trivial amount of graphics other than UI, -// please be aware that SDL_Renderer offers a limited graphic API to the end-user and it might -// be difficult to step out of those boundaries. -// However, we understand it is a convenient choice to get an app started easily. - -// Implemented features: -// [X] Renderer: User texture binding. Use 'SDL_Texture*' as ImTextureID. Read the FAQ about ImTextureID! -// [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices. -// Missing features: -// [ ] Renderer: Multi-viewport support (multiple windows). - -#pragma once -#include "imgui.h" // IMGUI_IMPL_API - -struct SDL_Renderer; - -IMGUI_IMPL_API bool ImGui_ImplSDLRenderer_Init(SDL_Renderer* renderer); -IMGUI_IMPL_API void ImGui_ImplSDLRenderer_Shutdown(); -IMGUI_IMPL_API bool ImGui_ImplSDLRenderer_NewFrame(); -IMGUI_IMPL_API void ImGui_ImplSDLRenderer_RenderDrawData(ImDrawData* draw_data); - -// Called by Init/NewFrame/Shutdown -IMGUI_IMPL_API bool ImGui_ImplSDLRenderer_CreateFontsTexture(); -IMGUI_IMPL_API void ImGui_ImplSDLRenderer_DestroyFontsTexture(); -IMGUI_IMPL_API bool ImGui_ImplSDLRenderer_CreateDeviceObjects(); -IMGUI_IMPL_API void ImGui_ImplSDLRenderer_DestroyDeviceObjects(); diff --git a/extern/imgui_patched/backends/imgui_impl_sdlrenderer.cpp b/extern/imgui_patched/backends/imgui_impl_sdlrenderer2.cpp similarity index 65% rename from extern/imgui_patched/backends/imgui_impl_sdlrenderer.cpp rename to extern/imgui_patched/backends/imgui_impl_sdlrenderer2.cpp index 8cc79f7e..fd5a0747 100644 --- a/extern/imgui_patched/backends/imgui_impl_sdlrenderer.cpp +++ b/extern/imgui_patched/backends/imgui_impl_sdlrenderer2.cpp @@ -1,12 +1,11 @@ -// dear imgui: Renderer Backend for SDL_Renderer +// dear imgui: Renderer Backend for SDL_Renderer for SDL2 // (Requires: SDL 2.0.17+) -// Important to understand: SDL_Renderer is an _optional_ component of SDL. +// Note how SDL_Renderer is an _optional_ component of SDL2. // For a multi-platform app consider using e.g. SDL+DirectX on Windows and SDL+OpenGL on Linux/OSX. // If your application will want to render any non trivial amount of graphics other than UI, -// please be aware that SDL_Renderer offers a limited graphic API to the end-user and it might -// be difficult to step out of those boundaries. -// However, we understand it is a convenient choice to get an app started easily. +// please be aware that SDL_Renderer currently offers a limited graphic API to the end-user and +// it might be difficult to step out of those boundaries. // Implemented features: // [X] Renderer: User texture binding. Use 'SDL_Texture*' as ImTextureID. Read the FAQ about ImTextureID! @@ -19,19 +18,27 @@ // Read online: https://github.com/ocornut/imgui/tree/master/docs // CHANGELOG +// 2023-05-30: Renamed imgui_impl_sdlrenderer.h/.cpp to imgui_impl_sdlrenderer2.h/.cpp to accommodate for upcoming SDL3. +// 2022-10-11: Using 'nullptr' instead of 'NULL' as per our switch to C++11. // 2021-12-21: Update SDL_RenderGeometryRaw() format to work with SDL 2.0.19. // 2021-12-03: Added support for large mesh (64K+ vertices), enable ImGuiBackendFlags_RendererHasVtxOffset flag. // 2021-10-06: Backup and restore modified ClipRect/Viewport. // 2021-09-21: Initial version. #include "imgui.h" -#include "imgui_impl_sdlrenderer.h" +#include "imgui_impl_sdlrenderer2.h" #if defined(_MSC_VER) && _MSC_VER <= 1500 // MSVC 2008 or earlier #include // intptr_t #else #include // intptr_t #endif +// Clang warnings with -Weverything +#if defined(__clang__) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wsign-conversion" // warning: implicit conversion changes signedness +#endif + // SDL #include #if !SDL_VERSION_ATLEAST(2,0,17) @@ -39,31 +46,31 @@ #endif // SDL_Renderer data -struct ImGui_ImplSDLRenderer_Data +struct ImGui_ImplSDLRenderer2_Data { SDL_Renderer* SDLRenderer; SDL_Texture* FontTexture; - ImGui_ImplSDLRenderer_Data() { memset((void*)this, 0, sizeof(*this)); } + ImGui_ImplSDLRenderer2_Data() { memset((void*)this, 0, sizeof(*this)); } }; // Backend data stored in io.BackendRendererUserData to allow support for multiple Dear ImGui contexts // It is STRONGLY preferred that you use docking branch with multi-viewports (== single Dear ImGui context + multiple windows) instead of multiple Dear ImGui contexts. -static ImGui_ImplSDLRenderer_Data* ImGui_ImplSDLRenderer_GetBackendData() +static ImGui_ImplSDLRenderer2_Data* ImGui_ImplSDLRenderer2_GetBackendData() { - return ImGui::GetCurrentContext() ? (ImGui_ImplSDLRenderer_Data*)ImGui::GetIO().BackendRendererUserData : NULL; + return ImGui::GetCurrentContext() ? (ImGui_ImplSDLRenderer2_Data*)ImGui::GetIO().BackendRendererUserData : nullptr; } // Functions -bool ImGui_ImplSDLRenderer_Init(SDL_Renderer* renderer) +bool ImGui_ImplSDLRenderer2_Init(SDL_Renderer* renderer) { ImGuiIO& io = ImGui::GetIO(); - IM_ASSERT(io.BackendRendererUserData == NULL && "Already initialized a renderer backend!"); - IM_ASSERT(renderer != NULL && "SDL_Renderer not initialized!"); + IM_ASSERT(io.BackendRendererUserData == nullptr && "Already initialized a renderer backend!"); + IM_ASSERT(renderer != nullptr && "SDL_Renderer not initialized!"); // Setup backend capabilities flags - ImGui_ImplSDLRenderer_Data* bd = IM_NEW(ImGui_ImplSDLRenderer_Data)(); + ImGui_ImplSDLRenderer2_Data* bd = IM_NEW(ImGui_ImplSDLRenderer2_Data)(); io.BackendRendererUserData = (void*)bd; - io.BackendRendererName = "imgui_impl_sdlrenderer"; + io.BackendRendererName = "imgui_impl_sdlrenderer2"; io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes. bd->SDLRenderer = renderer; @@ -71,42 +78,43 @@ bool ImGui_ImplSDLRenderer_Init(SDL_Renderer* renderer) return true; } -void ImGui_ImplSDLRenderer_Shutdown() +void ImGui_ImplSDLRenderer2_Shutdown() { - ImGui_ImplSDLRenderer_Data* bd = ImGui_ImplSDLRenderer_GetBackendData(); - IM_ASSERT(bd != NULL && "No renderer backend to shutdown, or already shutdown?"); + ImGui_ImplSDLRenderer2_Data* bd = ImGui_ImplSDLRenderer2_GetBackendData(); + IM_ASSERT(bd != nullptr && "No renderer backend to shutdown, or already shutdown?"); ImGuiIO& io = ImGui::GetIO(); - ImGui_ImplSDLRenderer_DestroyDeviceObjects(); + ImGui_ImplSDLRenderer2_DestroyDeviceObjects(); - io.BackendRendererName = NULL; - io.BackendRendererUserData = NULL; + io.BackendRendererName = nullptr; + io.BackendRendererUserData = nullptr; + io.BackendFlags &= ~ImGuiBackendFlags_RendererHasVtxOffset; IM_DELETE(bd); } -static void ImGui_ImplSDLRenderer_SetupRenderState() +static void ImGui_ImplSDLRenderer2_SetupRenderState() { - ImGui_ImplSDLRenderer_Data* bd = ImGui_ImplSDLRenderer_GetBackendData(); + ImGui_ImplSDLRenderer2_Data* bd = ImGui_ImplSDLRenderer2_GetBackendData(); // Clear out any viewports and cliprect set by the user // FIXME: Technically speaking there are lots of other things we could backup/setup/restore during our render process. - SDL_RenderSetViewport(bd->SDLRenderer, NULL); - SDL_RenderSetClipRect(bd->SDLRenderer, NULL); + SDL_RenderSetViewport(bd->SDLRenderer, nullptr); + SDL_RenderSetClipRect(bd->SDLRenderer, nullptr); } -bool ImGui_ImplSDLRenderer_NewFrame() +bool ImGui_ImplSDLRenderer2_NewFrame() { - ImGui_ImplSDLRenderer_Data* bd = ImGui_ImplSDLRenderer_GetBackendData(); - IM_ASSERT(bd != NULL && "Did you call ImGui_ImplSDLRenderer_Init()?"); + ImGui_ImplSDLRenderer2_Data* bd = ImGui_ImplSDLRenderer2_GetBackendData(); + IM_ASSERT(bd != nullptr && "Did you call ImGui_ImplSDLRenderer2_Init()?"); if (!bd->FontTexture) - return ImGui_ImplSDLRenderer_CreateDeviceObjects(); + return ImGui_ImplSDLRenderer2_CreateDeviceObjects(); return true; } -void ImGui_ImplSDLRenderer_RenderDrawData(ImDrawData* draw_data) +void ImGui_ImplSDLRenderer2_RenderDrawData(ImDrawData* draw_data) { - ImGui_ImplSDLRenderer_Data* bd = ImGui_ImplSDLRenderer_GetBackendData(); + ImGui_ImplSDLRenderer2_Data* bd = ImGui_ImplSDLRenderer2_GetBackendData(); // If there's a scale factor set by the user, use that instead // If the user has specified a scale factor to SDL_Renderer already via SDL_RenderSetScale(), SDL will scale whatever we pass @@ -141,7 +149,7 @@ void ImGui_ImplSDLRenderer_RenderDrawData(ImDrawData* draw_data) ImVec2 clip_scale = render_scale; // Render command lists - ImGui_ImplSDLRenderer_SetupRenderState(); + ImGui_ImplSDLRenderer2_SetupRenderState(); for (int n = 0; n < draw_data->CmdListsCount; n++) { const ImDrawList* cmd_list = draw_data->CmdLists[n]; @@ -156,7 +164,7 @@ void ImGui_ImplSDLRenderer_RenderDrawData(ImDrawData* draw_data) // User callback, registered via ImDrawList::AddCallback() // (ImDrawCallback_ResetRenderState is a special callback value used by the user to request the renderer to reset render state.) if (pcmd->UserCallback == ImDrawCallback_ResetRenderState) - ImGui_ImplSDLRenderer_SetupRenderState(); + ImGui_ImplSDLRenderer2_SetupRenderState(); else pcmd->UserCallback(cmd_list, pcmd); } @@ -167,20 +175,20 @@ void ImGui_ImplSDLRenderer_RenderDrawData(ImDrawData* draw_data) ImVec2 clip_max((pcmd->ClipRect.z - clip_off.x) * clip_scale.x, (pcmd->ClipRect.w - clip_off.y) * clip_scale.y); if (clip_min.x < 0.0f) { clip_min.x = 0.0f; } if (clip_min.y < 0.0f) { clip_min.y = 0.0f; } - if (clip_max.x > fb_width) { clip_max.x = (float)fb_width; } - if (clip_max.y > fb_height) { clip_max.y = (float)fb_height; } + if (clip_max.x > (float)fb_width) { clip_max.x = (float)fb_width; } + if (clip_max.y > (float)fb_height) { clip_max.y = (float)fb_height; } if (clip_max.x <= clip_min.x || clip_max.y <= clip_min.y) continue; SDL_Rect r = { (int)(clip_min.x), (int)(clip_min.y), (int)(clip_max.x - clip_min.x), (int)(clip_max.y - clip_min.y) }; SDL_RenderSetClipRect(bd->SDLRenderer, &r); - const float* xy = (const float*)((const char*)(vtx_buffer + pcmd->VtxOffset) + IM_OFFSETOF(ImDrawVert, pos)); - const float* uv = (const float*)((const char*)(vtx_buffer + pcmd->VtxOffset) + IM_OFFSETOF(ImDrawVert, uv)); + const float* xy = (const float*)(const void*)((const char*)(vtx_buffer + pcmd->VtxOffset) + IM_OFFSETOF(ImDrawVert, pos)); + const float* uv = (const float*)(const void*)((const char*)(vtx_buffer + pcmd->VtxOffset) + IM_OFFSETOF(ImDrawVert, uv)); #if SDL_VERSION_ATLEAST(2,0,19) - const SDL_Color* color = (const SDL_Color*)((const char*)(vtx_buffer + pcmd->VtxOffset) + IM_OFFSETOF(ImDrawVert, col)); // SDL 2.0.19+ + const SDL_Color* color = (const SDL_Color*)(const void*)((const char*)(vtx_buffer + pcmd->VtxOffset) + IM_OFFSETOF(ImDrawVert, col)); // SDL 2.0.19+ #else - const int* color = (const int*)((const char*)(vtx_buffer + pcmd->VtxOffset) + IM_OFFSETOF(ImDrawVert, col)); // SDL 2.0.17 and 2.0.18 + const int* color = (const int*)(const void*)((const char*)(vtx_buffer + pcmd->VtxOffset) + IM_OFFSETOF(ImDrawVert, col)); // SDL 2.0.17 and 2.0.18 #endif // Bind texture, Draw @@ -198,14 +206,14 @@ void ImGui_ImplSDLRenderer_RenderDrawData(ImDrawData* draw_data) // Restore modified SDL_Renderer state SDL_RenderSetViewport(bd->SDLRenderer, &old.Viewport); - SDL_RenderSetClipRect(bd->SDLRenderer, old.ClipEnabled ? &old.ClipRect : NULL); + SDL_RenderSetClipRect(bd->SDLRenderer, old.ClipEnabled ? &old.ClipRect : nullptr); } // Called by Init/NewFrame/Shutdown -bool ImGui_ImplSDLRenderer_CreateFontsTexture() +bool ImGui_ImplSDLRenderer2_CreateFontsTexture() { ImGuiIO& io = ImGui::GetIO(); - ImGui_ImplSDLRenderer_Data* bd = ImGui_ImplSDLRenderer_GetBackendData(); + ImGui_ImplSDLRenderer2_Data* bd = ImGui_ImplSDLRenderer2_GetBackendData(); // Build texture atlas unsigned char* pixels; @@ -215,12 +223,12 @@ bool ImGui_ImplSDLRenderer_CreateFontsTexture() // Upload texture to graphics system // (Bilinear sampling is required by default. Set 'io.Fonts->Flags |= ImFontAtlasFlags_NoBakedLines' or 'style.AntiAliasedLinesUseTex = false' to allow point/nearest sampling) bd->FontTexture = SDL_CreateTexture(bd->SDLRenderer, SDL_PIXELFORMAT_ABGR8888, SDL_TEXTUREACCESS_STATIC, width, height); - if (bd->FontTexture == NULL) + if (bd->FontTexture == nullptr) { SDL_Log("error creating texture"); return false; } - SDL_UpdateTexture(bd->FontTexture, NULL, pixels, 4 * width); + SDL_UpdateTexture(bd->FontTexture, nullptr, pixels, 4 * width); SDL_SetTextureBlendMode(bd->FontTexture, SDL_BLENDMODE_BLEND); SDL_SetTextureScaleMode(bd->FontTexture, SDL_ScaleModeLinear); @@ -230,24 +238,28 @@ bool ImGui_ImplSDLRenderer_CreateFontsTexture() return true; } -void ImGui_ImplSDLRenderer_DestroyFontsTexture() +void ImGui_ImplSDLRenderer2_DestroyFontsTexture() { ImGuiIO& io = ImGui::GetIO(); - ImGui_ImplSDLRenderer_Data* bd = ImGui_ImplSDLRenderer_GetBackendData(); + ImGui_ImplSDLRenderer2_Data* bd = ImGui_ImplSDLRenderer2_GetBackendData(); if (bd->FontTexture) { io.Fonts->SetTexID(0); SDL_DestroyTexture(bd->FontTexture); - bd->FontTexture = NULL; + bd->FontTexture = nullptr; } } -bool ImGui_ImplSDLRenderer_CreateDeviceObjects() +bool ImGui_ImplSDLRenderer2_CreateDeviceObjects() { - return ImGui_ImplSDLRenderer_CreateFontsTexture(); + return ImGui_ImplSDLRenderer2_CreateFontsTexture(); } -void ImGui_ImplSDLRenderer_DestroyDeviceObjects() +void ImGui_ImplSDLRenderer2_DestroyDeviceObjects() { - ImGui_ImplSDLRenderer_DestroyFontsTexture(); + ImGui_ImplSDLRenderer2_DestroyFontsTexture(); } + +#if defined(__clang__) +#pragma clang diagnostic pop +#endif diff --git a/extern/imgui_patched/backends/imgui_impl_sdlrenderer2.h b/extern/imgui_patched/backends/imgui_impl_sdlrenderer2.h new file mode 100644 index 00000000..0f1b2b6c --- /dev/null +++ b/extern/imgui_patched/backends/imgui_impl_sdlrenderer2.h @@ -0,0 +1,30 @@ +// dear imgui: Renderer Backend for SDL_Renderer for SDL2 +// (Requires: SDL 2.0.17+) + +// Note how SDL_Renderer is an _optional_ component of SDL2. +// For a multi-platform app consider using e.g. SDL+DirectX on Windows and SDL+OpenGL on Linux/OSX. +// If your application will want to render any non trivial amount of graphics other than UI, +// please be aware that SDL_Renderer currently offers a limited graphic API to the end-user and +// it might be difficult to step out of those boundaries. + +// Implemented features: +// [X] Renderer: User texture binding. Use 'SDL_Texture*' as ImTextureID. Read the FAQ about ImTextureID! +// [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices. +// Missing features: +// [ ] Renderer: Multi-viewport support (multiple windows). + +#pragma once +#include "imgui.h" // IMGUI_IMPL_API + +struct SDL_Renderer; + +IMGUI_IMPL_API bool ImGui_ImplSDLRenderer2_Init(SDL_Renderer* renderer); +IMGUI_IMPL_API void ImGui_ImplSDLRenderer2_Shutdown(); +IMGUI_IMPL_API bool ImGui_ImplSDLRenderer2_NewFrame(); +IMGUI_IMPL_API void ImGui_ImplSDLRenderer2_RenderDrawData(ImDrawData* draw_data); + +// Called by Init/NewFrame/Shutdown +IMGUI_IMPL_API bool ImGui_ImplSDLRenderer2_CreateFontsTexture(); +IMGUI_IMPL_API void ImGui_ImplSDLRenderer2_DestroyFontsTexture(); +IMGUI_IMPL_API bool ImGui_ImplSDLRenderer2_CreateDeviceObjects(); +IMGUI_IMPL_API void ImGui_ImplSDLRenderer2_DestroyDeviceObjects(); diff --git a/extern/imgui_patched/imgui_impl_sdlrenderer.cpp b/extern/imgui_patched/backends/imgui_impl_sdlrenderer3.cpp similarity index 57% rename from extern/imgui_patched/imgui_impl_sdlrenderer.cpp rename to extern/imgui_patched/backends/imgui_impl_sdlrenderer3.cpp index 9da0d488..7c1b3bf1 100644 --- a/extern/imgui_patched/imgui_impl_sdlrenderer.cpp +++ b/extern/imgui_patched/backends/imgui_impl_sdlrenderer3.cpp @@ -1,16 +1,15 @@ -// dear imgui: Renderer Backend for SDL_Renderer -// (Requires: SDL 2.0.17+) +// dear imgui: Renderer Backend for SDL_Renderer for SDL3 +// (Requires: SDL 3.0.0+) -// Important to understand: SDL_Renderer is an _optional_ component of SDL. +// Note how SDL_Renderer is an _optional_ component of SDL3. // For a multi-platform app consider using e.g. SDL+DirectX on Windows and SDL+OpenGL on Linux/OSX. // If your application will want to render any non trivial amount of graphics other than UI, -// please be aware that SDL_Renderer offers a limited graphic API to the end-user and it might -// be difficult to step out of those boundaries. -// However, we understand it is a convenient choice to get an app started easily. +// please be aware that SDL_Renderer currently offers a limited graphic API to the end-user and +// it might be difficult to step out of those boundaries. // Implemented features: // [X] Renderer: User texture binding. Use 'SDL_Texture*' as ImTextureID. Read the FAQ about ImTextureID! -// [X] Renderer: Support for large meshes (64k+ vertices) with 16-bit indices. +// [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices. // Missing features: // [ ] Renderer: Multi-viewport support (multiple windows). @@ -19,52 +18,54 @@ // Read online: https://github.com/ocornut/imgui/tree/master/docs // CHANGELOG -// 2021-12-21: Update SDL_RenderGeometryRaw() format to work with SDL 2.0.19. -// 2021-12-03: Added support for large mesh (64K+ vertices), enable ImGuiBackendFlags_RendererHasVtxOffset flag. -// 2021-10-06: Backup and restore modified ClipRect/Viewport. -// 2021-09-21: Initial version. +// 2023-05-30: Initial version. #include "imgui.h" -#include "imgui_impl_sdlrenderer.h" -#include +#include "imgui_impl_sdlrenderer3.h" #if defined(_MSC_VER) && _MSC_VER <= 1500 // MSVC 2008 or earlier #include // intptr_t #else #include // intptr_t #endif +// Clang warnings with -Weverything +#if defined(__clang__) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wsign-conversion" // warning: implicit conversion changes signedness +#endif + // SDL -#include -#if !SDL_VERSION_ATLEAST(2,0,17) -#error This backend requires SDL 2.0.17+ because of SDL_RenderGeometry() function +#include +#if !SDL_VERSION_ATLEAST(3,0,0) +#error This backend requires SDL 3.0.0+ #endif // SDL_Renderer data -struct ImGui_ImplSDLRenderer_Data +struct ImGui_ImplSDLRenderer3_Data { SDL_Renderer* SDLRenderer; SDL_Texture* FontTexture; - ImGui_ImplSDLRenderer_Data() { memset(this, 0, sizeof(*this)); } + ImGui_ImplSDLRenderer3_Data() { memset((void*)this, 0, sizeof(*this)); } }; // Backend data stored in io.BackendRendererUserData to allow support for multiple Dear ImGui contexts // It is STRONGLY preferred that you use docking branch with multi-viewports (== single Dear ImGui context + multiple windows) instead of multiple Dear ImGui contexts. -static ImGui_ImplSDLRenderer_Data* ImGui_ImplSDLRenderer_GetBackendData() +static ImGui_ImplSDLRenderer3_Data* ImGui_ImplSDLRenderer3_GetBackendData() { - return ImGui::GetCurrentContext() ? (ImGui_ImplSDLRenderer_Data*)ImGui::GetIO().BackendRendererUserData : NULL; + return ImGui::GetCurrentContext() ? (ImGui_ImplSDLRenderer3_Data*)ImGui::GetIO().BackendRendererUserData : nullptr; } // Functions -bool ImGui_ImplSDLRenderer_Init(SDL_Renderer* renderer) +bool ImGui_ImplSDLRenderer3_Init(SDL_Renderer* renderer) { ImGuiIO& io = ImGui::GetIO(); - IM_ASSERT(io.BackendRendererUserData == NULL && "Already initialized a renderer backend!"); - IM_ASSERT(renderer != NULL && "SDL_Renderer not initialized!"); + IM_ASSERT(io.BackendRendererUserData == nullptr && "Already initialized a renderer backend!"); + IM_ASSERT(renderer != nullptr && "SDL_Renderer not initialized!"); // Setup backend capabilities flags - ImGui_ImplSDLRenderer_Data* bd = IM_NEW(ImGui_ImplSDLRenderer_Data)(); + ImGui_ImplSDLRenderer3_Data* bd = IM_NEW(ImGui_ImplSDLRenderer3_Data)(); io.BackendRendererUserData = (void*)bd; - io.BackendRendererName = "imgui_impl_sdlrenderer"; + io.BackendRendererName = "imgui_impl_sdlrenderer3"; io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes. bd->SDLRenderer = renderer; @@ -72,50 +73,49 @@ bool ImGui_ImplSDLRenderer_Init(SDL_Renderer* renderer) return true; } -void ImGui_ImplSDLRenderer_Shutdown() +void ImGui_ImplSDLRenderer3_Shutdown() { - ImGui_ImplSDLRenderer_Data* bd = ImGui_ImplSDLRenderer_GetBackendData(); - IM_ASSERT(bd != NULL && "No renderer backend to shutdown, or already shutdown?"); + ImGui_ImplSDLRenderer3_Data* bd = ImGui_ImplSDLRenderer3_GetBackendData(); + IM_ASSERT(bd != nullptr && "No renderer backend to shutdown, or already shutdown?"); ImGuiIO& io = ImGui::GetIO(); - ImGui_ImplSDLRenderer_DestroyDeviceObjects(); + ImGui_ImplSDLRenderer3_DestroyDeviceObjects(); - io.BackendRendererName = NULL; - io.BackendRendererUserData = NULL; + io.BackendRendererName = nullptr; + io.BackendRendererUserData = nullptr; + io.BackendFlags &= ~ImGuiBackendFlags_RendererHasVtxOffset; IM_DELETE(bd); } -static void ImGui_ImplSDLRenderer_SetupRenderState() +static void ImGui_ImplSDLRenderer3_SetupRenderState() { - ImGui_ImplSDLRenderer_Data* bd = ImGui_ImplSDLRenderer_GetBackendData(); + ImGui_ImplSDLRenderer3_Data* bd = ImGui_ImplSDLRenderer3_GetBackendData(); // Clear out any viewports and cliprect set by the user // FIXME: Technically speaking there are lots of other things we could backup/setup/restore during our render process. - SDL_RenderSetViewport(bd->SDLRenderer, NULL); - SDL_RenderSetClipRect(bd->SDLRenderer, NULL); + SDL_SetRenderViewport(bd->SDLRenderer, nullptr); + SDL_SetRenderClipRect(bd->SDLRenderer, nullptr); } -bool ImGui_ImplSDLRenderer_NewFrame() +void ImGui_ImplSDLRenderer3_NewFrame() { - ImGui_ImplSDLRenderer_Data* bd = ImGui_ImplSDLRenderer_GetBackendData(); - IM_ASSERT(bd != NULL && "Did you call ImGui_ImplSDLRenderer_Init()?"); + ImGui_ImplSDLRenderer3_Data* bd = ImGui_ImplSDLRenderer3_GetBackendData(); + IM_ASSERT(bd != nullptr && "Did you call ImGui_ImplSDLRenderer3_Init()?"); if (!bd->FontTexture) - return ImGui_ImplSDLRenderer_CreateDeviceObjects(); - - return true; + ImGui_ImplSDLRenderer3_CreateDeviceObjects(); } -void ImGui_ImplSDLRenderer_RenderDrawData(ImDrawData* draw_data) +void ImGui_ImplSDLRenderer3_RenderDrawData(ImDrawData* draw_data) { - ImGui_ImplSDLRenderer_Data* bd = ImGui_ImplSDLRenderer_GetBackendData(); + ImGui_ImplSDLRenderer3_Data* bd = ImGui_ImplSDLRenderer3_GetBackendData(); // If there's a scale factor set by the user, use that instead // If the user has specified a scale factor to SDL_Renderer already via SDL_RenderSetScale(), SDL will scale whatever we pass // to SDL_RenderGeometryRaw() by that scale factor. In that case we don't want to be also scaling it ourselves here. float rsx = 1.0f; float rsy = 1.0f; - SDL_RenderGetScale(bd->SDLRenderer, &rsx, &rsy); + SDL_GetRenderScale(bd->SDLRenderer, &rsx, &rsy); ImVec2 render_scale; render_scale.x = (rsx == 1.0f) ? draw_data->FramebufferScale.x : 1.0f; render_scale.y = (rsy == 1.0f) ? draw_data->FramebufferScale.y : 1.0f; @@ -134,16 +134,16 @@ void ImGui_ImplSDLRenderer_RenderDrawData(ImDrawData* draw_data) SDL_Rect ClipRect; }; BackupSDLRendererState old = {}; - old.ClipEnabled = SDL_RenderIsClipEnabled(bd->SDLRenderer) == SDL_TRUE; - SDL_RenderGetViewport(bd->SDLRenderer, &old.Viewport); - SDL_RenderGetClipRect(bd->SDLRenderer, &old.ClipRect); + old.ClipEnabled = SDL_RenderClipEnabled(bd->SDLRenderer) == SDL_TRUE; + SDL_GetRenderViewport(bd->SDLRenderer, &old.Viewport); + SDL_GetRenderClipRect(bd->SDLRenderer, &old.ClipRect); // Will project scissor/clipping rectangles into framebuffer space ImVec2 clip_off = draw_data->DisplayPos; // (0,0) unless using multi-viewports ImVec2 clip_scale = render_scale; // Render command lists - ImGui_ImplSDLRenderer_SetupRenderState(); + ImGui_ImplSDLRenderer3_SetupRenderState(); for (int n = 0; n < draw_data->CmdListsCount; n++) { const ImDrawList* cmd_list = draw_data->CmdLists[n]; @@ -158,7 +158,7 @@ void ImGui_ImplSDLRenderer_RenderDrawData(ImDrawData* draw_data) // User callback, registered via ImDrawList::AddCallback() // (ImDrawCallback_ResetRenderState is a special callback value used by the user to request the renderer to reset render state.) if (pcmd->UserCallback == ImDrawCallback_ResetRenderState) - ImGui_ImplSDLRenderer_SetupRenderState(); + ImGui_ImplSDLRenderer3_SetupRenderState(); else pcmd->UserCallback(cmd_list, pcmd); } @@ -169,25 +169,24 @@ void ImGui_ImplSDLRenderer_RenderDrawData(ImDrawData* draw_data) ImVec2 clip_max((pcmd->ClipRect.z - clip_off.x) * clip_scale.x, (pcmd->ClipRect.w - clip_off.y) * clip_scale.y); if (clip_min.x < 0.0f) { clip_min.x = 0.0f; } if (clip_min.y < 0.0f) { clip_min.y = 0.0f; } - if (clip_max.x > fb_width) { clip_max.x = (float)fb_width; } - if (clip_max.y > fb_height) { clip_max.y = (float)fb_height; } + if (clip_max.x > (float)fb_width) { clip_max.x = (float)fb_width; } + if (clip_max.y > (float)fb_height) { clip_max.y = (float)fb_height; } if (clip_max.x <= clip_min.x || clip_max.y <= clip_min.y) continue; SDL_Rect r = { (int)(clip_min.x), (int)(clip_min.y), (int)(clip_max.x - clip_min.x), (int)(clip_max.y - clip_min.y) }; - SDL_RenderSetClipRect(bd->SDLRenderer, &r); + SDL_SetRenderClipRect(bd->SDLRenderer, &r); - const float* xy = (const float*)((const char*)(vtx_buffer + pcmd->VtxOffset) + IM_OFFSETOF(ImDrawVert, pos)); - const float* uv = (const float*)((const char*)(vtx_buffer + pcmd->VtxOffset) + IM_OFFSETOF(ImDrawVert, uv)); + const float* xy = (const float*)(const void*)((const char*)(vtx_buffer + pcmd->VtxOffset) + IM_OFFSETOF(ImDrawVert, pos)); + const float* uv = (const float*)(const void*)((const char*)(vtx_buffer + pcmd->VtxOffset) + IM_OFFSETOF(ImDrawVert, uv)); #if SDL_VERSION_ATLEAST(2,0,19) - const SDL_Color* color = (const SDL_Color*)((const char*)(vtx_buffer + pcmd->VtxOffset) + IM_OFFSETOF(ImDrawVert, col)); // SDL 2.0.19+ + const SDL_Color* color = (const SDL_Color*)(const void*)((const char*)(vtx_buffer + pcmd->VtxOffset) + IM_OFFSETOF(ImDrawVert, col)); // SDL 2.0.19+ #else - const int* color = (const int*)((const char*)(vtx_buffer + pcmd->VtxOffset) + IM_OFFSETOF(ImDrawVert, col)); // SDL 2.0.17 and 2.0.18 + const int* color = (const int*)(const void*)((const char*)(vtx_buffer + pcmd->VtxOffset) + IM_OFFSETOF(ImDrawVert, col)); // SDL 2.0.17 and 2.0.18 #endif // Bind texture, Draw SDL_Texture* tex = (SDL_Texture*)pcmd->GetTexID(); - SDL_SetTextureScaleMode(tex, SDL_ScaleModeBest); // ??? SDL_RenderGeometryRaw(bd->SDLRenderer, tex, xy, (int)sizeof(ImDrawVert), color, (int)sizeof(ImDrawVert), @@ -199,15 +198,15 @@ void ImGui_ImplSDLRenderer_RenderDrawData(ImDrawData* draw_data) } // Restore modified SDL_Renderer state - SDL_RenderSetViewport(bd->SDLRenderer, &old.Viewport); - SDL_RenderSetClipRect(bd->SDLRenderer, old.ClipEnabled ? &old.ClipRect : NULL); + SDL_SetRenderViewport(bd->SDLRenderer, &old.Viewport); + SDL_SetRenderClipRect(bd->SDLRenderer, old.ClipEnabled ? &old.ClipRect : nullptr); } // Called by Init/NewFrame/Shutdown -bool ImGui_ImplSDLRenderer_CreateFontsTexture() +bool ImGui_ImplSDLRenderer3_CreateFontsTexture() { ImGuiIO& io = ImGui::GetIO(); - ImGui_ImplSDLRenderer_Data* bd = ImGui_ImplSDLRenderer_GetBackendData(); + ImGui_ImplSDLRenderer3_Data* bd = ImGui_ImplSDLRenderer3_GetBackendData(); // Build texture atlas unsigned char* pixels; @@ -215,14 +214,16 @@ bool ImGui_ImplSDLRenderer_CreateFontsTexture() io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height); // Load as RGBA 32-bit (75% of the memory is wasted, but default font is so small) because it is more likely to be compatible with user's existing shaders. If your ImTextureId represent a higher-level concept than just a GL texture id, consider calling GetTexDataAsAlpha8() instead to save on GPU memory. // Upload texture to graphics system + // (Bilinear sampling is required by default. Set 'io.Fonts->Flags |= ImFontAtlasFlags_NoBakedLines' or 'style.AntiAliasedLinesUseTex = false' to allow point/nearest sampling) bd->FontTexture = SDL_CreateTexture(bd->SDLRenderer, SDL_PIXELFORMAT_ABGR8888, SDL_TEXTUREACCESS_STATIC, width, height); - if (bd->FontTexture == NULL) + if (bd->FontTexture == nullptr) { SDL_Log("error creating texture"); return false; } - SDL_UpdateTexture(bd->FontTexture, NULL, pixels, 4 * width); + SDL_UpdateTexture(bd->FontTexture, nullptr, pixels, 4 * width); SDL_SetTextureBlendMode(bd->FontTexture, SDL_BLENDMODE_BLEND); + SDL_SetTextureScaleMode(bd->FontTexture, SDL_SCALEMODE_LINEAR); // Store our identifier io.Fonts->SetTexID((ImTextureID)(intptr_t)bd->FontTexture); @@ -230,24 +231,28 @@ bool ImGui_ImplSDLRenderer_CreateFontsTexture() return true; } -void ImGui_ImplSDLRenderer_DestroyFontsTexture() +void ImGui_ImplSDLRenderer3_DestroyFontsTexture() { ImGuiIO& io = ImGui::GetIO(); - ImGui_ImplSDLRenderer_Data* bd = ImGui_ImplSDLRenderer_GetBackendData(); + ImGui_ImplSDLRenderer3_Data* bd = ImGui_ImplSDLRenderer3_GetBackendData(); if (bd->FontTexture) { io.Fonts->SetTexID(0); SDL_DestroyTexture(bd->FontTexture); - bd->FontTexture = NULL; + bd->FontTexture = nullptr; } } -bool ImGui_ImplSDLRenderer_CreateDeviceObjects() +bool ImGui_ImplSDLRenderer3_CreateDeviceObjects() { - return ImGui_ImplSDLRenderer_CreateFontsTexture(); + return ImGui_ImplSDLRenderer3_CreateFontsTexture(); } -void ImGui_ImplSDLRenderer_DestroyDeviceObjects() +void ImGui_ImplSDLRenderer3_DestroyDeviceObjects() { - ImGui_ImplSDLRenderer_DestroyFontsTexture(); + ImGui_ImplSDLRenderer3_DestroyFontsTexture(); } + +#if defined(__clang__) +#pragma clang diagnostic pop +#endif diff --git a/extern/imgui_patched/backends/imgui_impl_sdlrenderer3.h b/extern/imgui_patched/backends/imgui_impl_sdlrenderer3.h new file mode 100644 index 00000000..71eec439 --- /dev/null +++ b/extern/imgui_patched/backends/imgui_impl_sdlrenderer3.h @@ -0,0 +1,30 @@ +// dear imgui: Renderer Backend for SDL_Renderer for SDL3 +// (Requires: SDL 3.0.0+) + +// Note how SDL_Renderer is an _optional_ component of SDL3. +// For a multi-platform app consider using e.g. SDL+DirectX on Windows and SDL+OpenGL on Linux/OSX. +// If your application will want to render any non trivial amount of graphics other than UI, +// please be aware that SDL_Renderer currently offers a limited graphic API to the end-user and +// it might be difficult to step out of those boundaries. + +// Implemented features: +// [X] Renderer: User texture binding. Use 'SDL_Texture*' as ImTextureID. Read the FAQ about ImTextureID! +// [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices. +// Missing features: +// [ ] Renderer: Multi-viewport support (multiple windows). + +#pragma once +#include "imgui.h" // IMGUI_IMPL_API + +struct SDL_Renderer; + +IMGUI_IMPL_API bool ImGui_ImplSDLRenderer3_Init(SDL_Renderer* renderer); +IMGUI_IMPL_API void ImGui_ImplSDLRenderer3_Shutdown(); +IMGUI_IMPL_API void ImGui_ImplSDLRenderer3_NewFrame(); +IMGUI_IMPL_API void ImGui_ImplSDLRenderer3_RenderDrawData(ImDrawData* draw_data); + +// Called by Init/NewFrame/Shutdown +IMGUI_IMPL_API bool ImGui_ImplSDLRenderer3_CreateFontsTexture(); +IMGUI_IMPL_API void ImGui_ImplSDLRenderer3_DestroyFontsTexture(); +IMGUI_IMPL_API bool ImGui_ImplSDLRenderer3_CreateDeviceObjects(); +IMGUI_IMPL_API void ImGui_ImplSDLRenderer3_DestroyDeviceObjects(); diff --git a/extern/imgui_patched/backends/imgui_impl_vulkan.cpp b/extern/imgui_patched/backends/imgui_impl_vulkan.cpp index 1fc210e1..59bb6d65 100644 --- a/extern/imgui_patched/backends/imgui_impl_vulkan.cpp +++ b/extern/imgui_patched/backends/imgui_impl_vulkan.cpp @@ -2,9 +2,9 @@ // This needs to be used along with a Platform Backend (e.g. GLFW, SDL, Win32, custom..) // Implemented features: +// [x] Renderer: User texture binding. Use 'VkDescriptorSet' as ImTextureID. Read the FAQ about ImTextureID! See https://github.com/ocornut/imgui/pull/914 for discussions. // [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices. // [x] Renderer: Multi-viewport / platform windows. With issues (flickering when creating a new viewport). -// [!] Renderer: User texture binding. Use 'VkDescriptorSet' as ImTextureID. Read the FAQ about ImTextureID! See https://github.com/ocornut/imgui/pull/914 for discussions. // Important: on 32-bit systems, user texture binding is only supported if your imconfig file has '#define ImTextureID ImU64'. // This is because we need ImTextureID to carry a 64-bit value and by default ImTextureID is defined as void*. @@ -31,7 +31,11 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) -// 2022-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface. +// 2023-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface. +// 2023-01-02: Vulkan: Fixed sampler passed to ImGui_ImplVulkan_AddTexture() not being honored + removed a bunch of duplicate code. +// 2022-10-11: Using 'nullptr' instead of 'NULL' as per our switch to C++11. +// 2022-10-04: Vulkan: Added experimental ImGui_ImplVulkan_RemoveTexture() for api symetry. (#914, #5738). +// 2022-01-20: Vulkan: Added support for ImTextureID as VkDescriptorSet. User need to call ImGui_ImplVulkan_AddTexture(). Building for 32-bit targets requires '#define ImTextureID ImU64'. (#914). // 2021-10-15: Vulkan: Call vkCmdSetScissor() at the end of render a full-viewport to reduce likehood of issues with people using VK_DYNAMIC_STATE_SCISSOR in their app without calling vkCmdSetScissor() explicitly every frame. // 2021-06-29: Reorganized backend to pull data from a single structure to facilitate usage with multiple-contexts (all g_XXXX access changed to bd->XXXX). // 2021-03-22: Vulkan: Fix mapped memory validation error when buffer sizes are not multiple of VkPhysicalDeviceLimits::nonCoherentAtomSize. @@ -93,7 +97,7 @@ struct ImGui_ImplVulkanH_WindowRenderBuffers }; // For multi-viewport support: -// Helper structure we store in the void* RenderUserData field of each ImGuiViewport to easily retrieve our backend data. +// Helper structure we store in the void* RendererUserData field of each ImGuiViewport to easily retrieve our backend data. struct ImGui_ImplVulkan_ViewportData { bool WindowOwned; @@ -204,6 +208,7 @@ static bool g_FunctionsLoaded = true; IMGUI_VULKAN_FUNC_MAP_MACRO(vkDeviceWaitIdle) \ IMGUI_VULKAN_FUNC_MAP_MACRO(vkFlushMappedMemoryRanges) \ IMGUI_VULKAN_FUNC_MAP_MACRO(vkFreeCommandBuffers) \ + IMGUI_VULKAN_FUNC_MAP_MACRO(vkFreeDescriptorSets) \ IMGUI_VULKAN_FUNC_MAP_MACRO(vkFreeMemory) \ IMGUI_VULKAN_FUNC_MAP_MACRO(vkGetBufferMemoryRequirements) \ IMGUI_VULKAN_FUNC_MAP_MACRO(vkGetImageMemoryRequirements) \ @@ -355,7 +360,7 @@ static uint32_t __glsl_shader_frag_spv[] = // FIXME: multi-context support is not tested and probably dysfunctional in this backend. static ImGui_ImplVulkan_Data* ImGui_ImplVulkan_GetBackendData() { - return ImGui::GetCurrentContext() ? (ImGui_ImplVulkan_Data*)ImGui::GetIO().BackendRendererUserData : NULL; + return ImGui::GetCurrentContext() ? (ImGui_ImplVulkan_Data*)ImGui::GetIO().BackendRendererUserData : nullptr; } static uint32_t ImGui_ImplVulkan_MemoryType(VkMemoryPropertyFlags properties, uint32_t type_bits) @@ -474,9 +479,9 @@ void ImGui_ImplVulkan_RenderDrawData(ImDrawData* draw_data, VkCommandBuffer comm // Allocate array to store enough vertex/index buffers. Each unique viewport gets its own storage. ImGui_ImplVulkan_ViewportData* viewport_renderer_data = (ImGui_ImplVulkan_ViewportData*)draw_data->OwnerViewport->RendererUserData; - IM_ASSERT(viewport_renderer_data != NULL); + IM_ASSERT(viewport_renderer_data != nullptr); ImGui_ImplVulkanH_WindowRenderBuffers* wrb = &viewport_renderer_data->RenderBuffers; - if (wrb->FrameRenderBuffers == NULL) + if (wrb->FrameRenderBuffers == nullptr) { wrb->Index = 0; wrb->Count = v->ImageCount; @@ -498,8 +503,8 @@ void ImGui_ImplVulkan_RenderDrawData(ImDrawData* draw_data, VkCommandBuffer comm CreateOrResizeBuffer(rb->IndexBuffer, rb->IndexBufferMemory, rb->IndexBufferSize, index_size, VK_BUFFER_USAGE_INDEX_BUFFER_BIT); // Upload vertex/index data into a single contiguous GPU buffer - ImDrawVert* vtx_dst = NULL; - ImDrawIdx* idx_dst = NULL; + ImDrawVert* vtx_dst = nullptr; + ImDrawIdx* idx_dst = nullptr; VkResult err = vkMapMemory(v->Device, rb->VertexBufferMemory, 0, rb->VertexBufferSize, 0, (void**)(&vtx_dst)); check_vk_result(err); err = vkMapMemory(v->Device, rb->IndexBufferMemory, 0, rb->IndexBufferSize, 0, (void**)(&idx_dst)); @@ -542,7 +547,7 @@ void ImGui_ImplVulkan_RenderDrawData(ImDrawData* draw_data, VkCommandBuffer comm for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++) { const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i]; - if (pcmd->UserCallback != NULL) + if (pcmd->UserCallback != nullptr) { // User callback, registered via ImDrawList::AddCallback() // (ImDrawCallback_ResetRenderState is a special callback value used by the user to request the renderer to reset render state.) @@ -581,7 +586,7 @@ void ImGui_ImplVulkan_RenderDrawData(ImDrawData* draw_data, VkCommandBuffer comm IM_ASSERT(pcmd->TextureId == (ImTextureID)bd->FontDescriptorSet); desc_set[0] = bd->FontDescriptorSet; } - vkCmdBindDescriptorSets(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, bd->PipelineLayout, 0, 1, desc_set, 0, NULL); + vkCmdBindDescriptorSets(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, bd->PipelineLayout, 0, 1, desc_set, 0, nullptr); // Draw vkCmdDrawIndexed(command_buffer, pcmd->ElemCount, 1, pcmd->IdxOffset + global_idx_offset, pcmd->VtxOffset + global_vtx_offset, 0); @@ -594,7 +599,7 @@ void ImGui_ImplVulkan_RenderDrawData(ImDrawData* draw_data, VkCommandBuffer comm // Note: at this point both vkCmdSetViewport() and vkCmdSetScissor() have been called. // Our last values will leak into user/application rendering IF: // - Your app uses a pipeline with VK_DYNAMIC_STATE_VIEWPORT or VK_DYNAMIC_STATE_SCISSOR dynamic state - // - And you forgot to call vkCmdSetViewport() and vkCmdSetScissor() yourself to explicitely set that state. + // - And you forgot to call vkCmdSetViewport() and vkCmdSetScissor() yourself to explicitly set that state. // If you use VK_DYNAMIC_STATE_VIEWPORT or VK_DYNAMIC_STATE_SCISSOR you are responsible for setting the values before rendering. // In theory we should aim to backup/restore those values but I am not sure this is possible. // We perform a call to vkCmdSetScissor() to set back a full viewport which is likely to fix things for 99% users but technically this is not perfect. (See github #4644) @@ -686,7 +691,7 @@ bool ImGui_ImplVulkan_CreateFontsTexture(VkCommandBuffer command_buffer) // Upload to Buffer: { - char* map = NULL; + char* map = nullptr; err = vkMapMemory(v->Device, bd->UploadBufferMemory, 0, upload_size, 0, (void**)(&map)); check_vk_result(err); memcpy(map, pixels, upload_size); @@ -712,7 +717,7 @@ bool ImGui_ImplVulkan_CreateFontsTexture(VkCommandBuffer command_buffer) copy_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; copy_barrier[0].subresourceRange.levelCount = 1; copy_barrier[0].subresourceRange.layerCount = 1; - vkCmdPipelineBarrier(command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, NULL, 0, NULL, 1, copy_barrier); + vkCmdPipelineBarrier(command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, nullptr, 0, nullptr, 1, copy_barrier); VkBufferImageCopy region = {}; region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; @@ -734,7 +739,7 @@ bool ImGui_ImplVulkan_CreateFontsTexture(VkCommandBuffer command_buffer) use_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; use_barrier[0].subresourceRange.levelCount = 1; use_barrier[0].subresourceRange.layerCount = 1; - vkCmdPipelineBarrier(command_buffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, 0, 0, NULL, 0, NULL, 1, use_barrier); + vkCmdPipelineBarrier(command_buffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, use_barrier); } // Store our identifier @@ -767,72 +772,6 @@ static void ImGui_ImplVulkan_CreateShaderModules(VkDevice device, const VkAlloca } } -static void ImGui_ImplVulkan_CreateFontSampler(VkDevice device, const VkAllocationCallbacks* allocator) -{ - ImGui_ImplVulkan_Data* bd = ImGui_ImplVulkan_GetBackendData(); - if (bd->FontSampler) - return; - - // Bilinear sampling is required by default. Set 'io.Fonts->Flags |= ImFontAtlasFlags_NoBakedLines' or 'style.AntiAliasedLinesUseTex = false' to allow point/nearest sampling. - VkSamplerCreateInfo info = {}; - info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; - info.magFilter = VK_FILTER_LINEAR; - info.minFilter = VK_FILTER_LINEAR; - info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR; - info.addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT; - info.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT; - info.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT; - info.minLod = -1000; - info.maxLod = 1000; - info.maxAnisotropy = 1.0f; - VkResult err = vkCreateSampler(device, &info, allocator, &bd->FontSampler); - check_vk_result(err); -} - -static void ImGui_ImplVulkan_CreateDescriptorSetLayout(VkDevice device, const VkAllocationCallbacks* allocator) -{ - ImGui_ImplVulkan_Data* bd = ImGui_ImplVulkan_GetBackendData(); - if (bd->DescriptorSetLayout) - return; - - ImGui_ImplVulkan_CreateFontSampler(device, allocator); - VkSampler sampler[1] = { bd->FontSampler }; - VkDescriptorSetLayoutBinding binding[1] = {}; - binding[0].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; - binding[0].descriptorCount = 1; - binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; - binding[0].pImmutableSamplers = sampler; - VkDescriptorSetLayoutCreateInfo info = {}; - info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; - info.bindingCount = 1; - info.pBindings = binding; - VkResult err = vkCreateDescriptorSetLayout(device, &info, allocator, &bd->DescriptorSetLayout); - check_vk_result(err); -} - -static void ImGui_ImplVulkan_CreatePipelineLayout(VkDevice device, const VkAllocationCallbacks* allocator) -{ - ImGui_ImplVulkan_Data* bd = ImGui_ImplVulkan_GetBackendData(); - if (bd->PipelineLayout) - return; - - // Constants: we are using 'vec2 offset' and 'vec2 scale' instead of a full 3d projection matrix - ImGui_ImplVulkan_CreateDescriptorSetLayout(device, allocator); - VkPushConstantRange push_constants[1] = {}; - push_constants[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT; - push_constants[0].offset = sizeof(float) * 0; - push_constants[0].size = sizeof(float) * 4; - VkDescriptorSetLayout set_layout[1] = { bd->DescriptorSetLayout }; - VkPipelineLayoutCreateInfo layout_info = {}; - layout_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; - layout_info.setLayoutCount = 1; - layout_info.pSetLayouts = set_layout; - layout_info.pushConstantRangeCount = 1; - layout_info.pPushConstantRanges = push_constants; - VkResult err = vkCreatePipelineLayout(device, &layout_info, allocator, &bd->PipelineLayout); - check_vk_result(err); -} - static void ImGui_ImplVulkan_CreatePipeline(VkDevice device, const VkAllocationCallbacks* allocator, VkPipelineCache pipelineCache, VkRenderPass renderPass, VkSampleCountFlagBits MSAASamples, VkPipeline* pipeline, uint32_t subpass) { ImGui_ImplVulkan_Data* bd = ImGui_ImplVulkan_GetBackendData(); @@ -917,8 +856,6 @@ static void ImGui_ImplVulkan_CreatePipeline(VkDevice device, const VkAllocationC dynamic_state.dynamicStateCount = (uint32_t)IM_ARRAYSIZE(dynamic_states); dynamic_state.pDynamicStates = dynamic_states; - ImGui_ImplVulkan_CreatePipelineLayout(device, allocator); - VkGraphicsPipelineCreateInfo info = {}; info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; info.flags = bd->PipelineCreateFlags; @@ -947,6 +884,7 @@ bool ImGui_ImplVulkan_CreateDeviceObjects() if (!bd->FontSampler) { + // Bilinear sampling is required by default. Set 'io.Fonts->Flags |= ImFontAtlasFlags_NoBakedLines' or 'style.AntiAliasedLinesUseTex = false' to allow point/nearest sampling. VkSamplerCreateInfo info = {}; info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; info.magFilter = VK_FILTER_LINEAR; @@ -964,12 +902,10 @@ bool ImGui_ImplVulkan_CreateDeviceObjects() if (!bd->DescriptorSetLayout) { - VkSampler sampler[1] = {bd->FontSampler}; VkDescriptorSetLayoutBinding binding[1] = {}; binding[0].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; binding[0].descriptorCount = 1; binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; - binding[0].pImmutableSamplers = sampler; VkDescriptorSetLayoutCreateInfo info = {}; info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; info.bindingCount = 1; @@ -1044,7 +980,7 @@ bool ImGui_ImplVulkan_LoadFunctions(PFN_vkVoidFunction(*loader_func)(const ch #ifdef VK_NO_PROTOTYPES #define IMGUI_VULKAN_FUNC_LOAD(func) \ func = reinterpret_cast(loader_func(#func, user_data)); \ - if (func == NULL) \ + if (func == nullptr) \ return false; IMGUI_VULKAN_FUNC_MAP(IMGUI_VULKAN_FUNC_LOAD) #undef IMGUI_VULKAN_FUNC_LOAD @@ -1061,7 +997,7 @@ bool ImGui_ImplVulkan_Init(ImGui_ImplVulkan_InitInfo* info, VkRenderPass rend IM_ASSERT(g_FunctionsLoaded && "Need to call ImGui_ImplVulkan_LoadFunctions() if IMGUI_IMPL_VULKAN_NO_PROTOTYPES or VK_NO_PROTOTYPES are set!"); ImGuiIO& io = ImGui::GetIO(); - IM_ASSERT(io.BackendRendererUserData == NULL && "Already initialized a renderer backend!"); + IM_ASSERT(io.BackendRendererUserData == nullptr && "Already initialized a renderer backend!"); // Setup backend capabilities flags ImGui_ImplVulkan_Data* bd = IM_NEW(ImGui_ImplVulkan_Data)(); @@ -1098,7 +1034,7 @@ bool ImGui_ImplVulkan_Init(ImGui_ImplVulkan_InitInfo* info, VkRenderPass rend void ImGui_ImplVulkan_Shutdown() { ImGui_ImplVulkan_Data* bd = ImGui_ImplVulkan_GetBackendData(); - IM_ASSERT(bd != NULL && "No renderer backend to shutdown, or already shutdown?"); + IM_ASSERT(bd != nullptr && "No renderer backend to shutdown, or already shutdown?"); ImGuiIO& io = ImGui::GetIO(); // First destroy objects in all viewports @@ -1108,20 +1044,21 @@ void ImGui_ImplVulkan_Shutdown() ImGuiViewport* main_viewport = ImGui::GetMainViewport(); if (ImGui_ImplVulkan_ViewportData* vd = (ImGui_ImplVulkan_ViewportData*)main_viewport->RendererUserData) IM_DELETE(vd); - main_viewport->RendererUserData = NULL; + main_viewport->RendererUserData = nullptr; // Clean up windows ImGui_ImplVulkan_ShutdownPlatformInterface(); - io.BackendRendererName = NULL; - io.BackendRendererUserData = NULL; + io.BackendRendererName = nullptr; + io.BackendRendererUserData = nullptr; + io.BackendFlags &= ~(ImGuiBackendFlags_RendererHasVtxOffset | ImGuiBackendFlags_RendererHasViewports); IM_DELETE(bd); } void ImGui_ImplVulkan_NewFrame() { ImGui_ImplVulkan_Data* bd = ImGui_ImplVulkan_GetBackendData(); - IM_ASSERT(bd != NULL && "Did you call ImGui_ImplVulkan_Init()?"); + IM_ASSERT(bd != nullptr && "Did you call ImGui_ImplVulkan_Init()?"); IM_UNUSED(bd); } @@ -1172,11 +1109,18 @@ VkDescriptorSet ImGui_ImplVulkan_AddTexture(VkSampler sampler, VkImageView image write_desc[0].descriptorCount = 1; write_desc[0].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; write_desc[0].pImageInfo = desc_image; - vkUpdateDescriptorSets(v->Device, 1, write_desc, 0, NULL); + vkUpdateDescriptorSets(v->Device, 1, write_desc, 0, nullptr); } return descriptor_set; } +void ImGui_ImplVulkan_RemoveTexture(VkDescriptorSet descriptor_set) +{ + ImGui_ImplVulkan_Data* bd = ImGui_ImplVulkan_GetBackendData(); + ImGui_ImplVulkan_InitInfo* v = &bd->VulkanInitInfo; + vkFreeDescriptorSets(v->Device, v->DescriptorPool, 1, &descriptor_set); +} + //------------------------------------------------------------------------- // Internal / Miscellaneous Vulkan Helpers // (Used by example's main.cpp. Used by multi-viewport features. PROBABLY NOT used by your own app.) @@ -1196,7 +1140,7 @@ VkDescriptorSet ImGui_ImplVulkan_AddTexture(VkSampler sampler, VkImageView image VkSurfaceFormatKHR ImGui_ImplVulkanH_SelectSurfaceFormat(VkPhysicalDevice physical_device, VkSurfaceKHR surface, const VkFormat* request_formats, int request_formats_count, VkColorSpaceKHR request_color_space) { IM_ASSERT(g_FunctionsLoaded && "Need to call ImGui_ImplVulkan_LoadFunctions() if IMGUI_IMPL_VULKAN_NO_PROTOTYPES or VK_NO_PROTOTYPES are set!"); - IM_ASSERT(request_formats != NULL); + IM_ASSERT(request_formats != nullptr); IM_ASSERT(request_formats_count > 0); // Per Spec Format and View Format are expected to be the same unless VK_IMAGE_CREATE_MUTABLE_BIT was set at image creation @@ -1204,7 +1148,7 @@ VkSurfaceFormatKHR ImGui_ImplVulkanH_SelectSurfaceFormat(VkPhysicalDevice physic // Additionally several new color spaces were introduced with Vulkan Spec v1.0.40, // hence we must make sure that a format with the mostly available color space, VK_COLOR_SPACE_SRGB_NONLINEAR_KHR, is found and used. uint32_t avail_count; - vkGetPhysicalDeviceSurfaceFormatsKHR(physical_device, surface, &avail_count, NULL); + vkGetPhysicalDeviceSurfaceFormatsKHR(physical_device, surface, &avail_count, nullptr); ImVector avail_format; avail_format.resize((int)avail_count); vkGetPhysicalDeviceSurfaceFormatsKHR(physical_device, surface, &avail_count, avail_format.Data); @@ -1241,12 +1185,12 @@ VkSurfaceFormatKHR ImGui_ImplVulkanH_SelectSurfaceFormat(VkPhysicalDevice physic VkPresentModeKHR ImGui_ImplVulkanH_SelectPresentMode(VkPhysicalDevice physical_device, VkSurfaceKHR surface, const VkPresentModeKHR* request_modes, int request_modes_count) { IM_ASSERT(g_FunctionsLoaded && "Need to call ImGui_ImplVulkan_LoadFunctions() if IMGUI_IMPL_VULKAN_NO_PROTOTYPES or VK_NO_PROTOTYPES are set!"); - IM_ASSERT(request_modes != NULL); + IM_ASSERT(request_modes != nullptr); IM_ASSERT(request_modes_count > 0); // Request a certain mode and confirm that it is available. If not use VK_PRESENT_MODE_FIFO_KHR which is mandatory uint32_t avail_count = 0; - vkGetPhysicalDeviceSurfacePresentModesKHR(physical_device, surface, &avail_count, NULL); + vkGetPhysicalDeviceSurfacePresentModesKHR(physical_device, surface, &avail_count, nullptr); ImVector avail_modes; avail_modes.resize((int)avail_count); vkGetPhysicalDeviceSurfacePresentModesKHR(physical_device, surface, &avail_count, avail_modes.Data); @@ -1338,8 +1282,8 @@ void ImGui_ImplVulkanH_CreateWindowSwapChain(VkPhysicalDevice physical_device, V } IM_FREE(wd->Frames); IM_FREE(wd->FrameSemaphores); - wd->Frames = NULL; - wd->FrameSemaphores = NULL; + wd->Frames = nullptr; + wd->FrameSemaphores = nullptr; wd->ImageCount = 0; if (wd->RenderPass) vkDestroyRenderPass(device, wd->RenderPass, allocator); @@ -1386,7 +1330,7 @@ void ImGui_ImplVulkanH_CreateWindowSwapChain(VkPhysicalDevice physical_device, V } err = vkCreateSwapchainKHR(device, &info, allocator, &wd->Swapchain); check_vk_result(err); - err = vkGetSwapchainImagesKHR(device, wd->Swapchain, &wd->ImageCount, NULL); + err = vkGetSwapchainImagesKHR(device, wd->Swapchain, &wd->ImageCount, nullptr); check_vk_result(err); VkImage backbuffers[16] = {}; IM_ASSERT(wd->ImageCount >= min_image_count); @@ -1394,7 +1338,7 @@ void ImGui_ImplVulkanH_CreateWindowSwapChain(VkPhysicalDevice physical_device, V err = vkGetSwapchainImagesKHR(device, wd->Swapchain, &wd->ImageCount, backbuffers); check_vk_result(err); - IM_ASSERT(wd->Frames == NULL); + IM_ASSERT(wd->Frames == nullptr); wd->Frames = (ImGui_ImplVulkanH_Frame*)IM_ALLOC(sizeof(ImGui_ImplVulkanH_Frame) * wd->ImageCount); wd->FrameSemaphores = (ImGui_ImplVulkanH_FrameSemaphores*)IM_ALLOC(sizeof(ImGui_ImplVulkanH_FrameSemaphores) * wd->ImageCount); memset(wd->Frames, 0, sizeof(wd->Frames[0]) * wd->ImageCount); @@ -1510,8 +1454,8 @@ void ImGui_ImplVulkanH_DestroyWindow(VkInstance instance, VkDevice device, ImGui } IM_FREE(wd->Frames); IM_FREE(wd->FrameSemaphores); - wd->Frames = NULL; - wd->FrameSemaphores = NULL; + wd->Frames = nullptr; + wd->FrameSemaphores = nullptr; vkDestroyPipeline(device, wd->Pipeline, allocator); vkDestroyRenderPass(device, wd->RenderPass, allocator); vkDestroySwapchainKHR(device, wd->Swapchain, allocator); @@ -1555,7 +1499,7 @@ void ImGui_ImplVulkanH_DestroyWindowRenderBuffers(VkDevice device, ImGui_ImplVul for (uint32_t n = 0; n < buffers->Count; n++) ImGui_ImplVulkanH_DestroyFrameRenderBuffers(device, &buffers->FrameRenderBuffers[n], allocator); IM_FREE(buffers->FrameRenderBuffers); - buffers->FrameRenderBuffers = NULL; + buffers->FrameRenderBuffers = nullptr; buffers->Index = 0; buffers->Count = 0; } @@ -1615,7 +1559,7 @@ static void ImGui_ImplVulkan_CreateWindow(ImGuiViewport* viewport) static void ImGui_ImplVulkan_DestroyWindow(ImGuiViewport* viewport) { - // The main viewport (owned by the application) will always have RendererUserData == NULL since we didn't create the data for it. + // The main viewport (owned by the application) will always have RendererUserData == 0 since we didn't create the data for it. ImGui_ImplVulkan_Data* bd = ImGui_ImplVulkan_GetBackendData(); if (ImGui_ImplVulkan_ViewportData* vd = (ImGui_ImplVulkan_ViewportData*)viewport->RendererUserData) { @@ -1625,14 +1569,14 @@ static void ImGui_ImplVulkan_DestroyWindow(ImGuiViewport* viewport) ImGui_ImplVulkanH_DestroyWindowRenderBuffers(v->Device, &vd->RenderBuffers, v->Allocator); IM_DELETE(vd); } - viewport->RendererUserData = NULL; + viewport->RendererUserData = nullptr; } static void ImGui_ImplVulkan_SetWindowSize(ImGuiViewport* viewport, ImVec2 size) { ImGui_ImplVulkan_Data* bd = ImGui_ImplVulkan_GetBackendData(); ImGui_ImplVulkan_ViewportData* vd = (ImGui_ImplVulkan_ViewportData*)viewport->RendererUserData; - if (vd == NULL) // This is NULL for the main viewport (which is left to the user/app to handle) + if (vd == nullptr) // This is nullptr for the main viewport (which is left to the user/app to handle) return; ImGui_ImplVulkan_InitInfo* v = &bd->VulkanInitInfo; vd->Window.ClearEnable = (viewport->Flags & ImGuiViewportFlags_NoRendererClear) ? false : true; @@ -1682,7 +1626,7 @@ static void ImGui_ImplVulkan_RenderWindow(ImGuiViewport* viewport, void*) info.renderArea.extent.width = wd->Width; info.renderArea.extent.height = wd->Height; info.clearValueCount = (viewport->Flags & ImGuiViewportFlags_NoRendererClear) ? 0 : 1; - info.pClearValues = (viewport->Flags & ImGuiViewportFlags_NoRendererClear) ? NULL : &wd->ClearValue; + info.pClearValues = (viewport->Flags & ImGuiViewportFlags_NoRendererClear) ? nullptr : &wd->ClearValue; vkCmdBeginRenderPass(fd->CommandBuffer, &info, VK_SUBPASS_CONTENTS_INLINE); } } @@ -1745,7 +1689,7 @@ void ImGui_ImplVulkan_InitPlatformInterface() { ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO(); if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable) - IM_ASSERT(platform_io.Platform_CreateVkSurface != NULL && "Platform needs to setup the CreateVkSurface handler."); + IM_ASSERT(platform_io.Platform_CreateVkSurface != nullptr && "Platform needs to setup the CreateVkSurface handler."); platform_io.Renderer_CreateWindow = ImGui_ImplVulkan_CreateWindow; platform_io.Renderer_DestroyWindow = ImGui_ImplVulkan_DestroyWindow; platform_io.Renderer_SetWindowSize = ImGui_ImplVulkan_SetWindowSize; diff --git a/extern/imgui_patched/backends/imgui_impl_vulkan.h b/extern/imgui_patched/backends/imgui_impl_vulkan.h index d2cb0ab4..044437ad 100644 --- a/extern/imgui_patched/backends/imgui_impl_vulkan.h +++ b/extern/imgui_patched/backends/imgui_impl_vulkan.h @@ -2,9 +2,9 @@ // This needs to be used along with a Platform Backend (e.g. GLFW, SDL, Win32, custom..) // Implemented features: +// [x] Renderer: User texture binding. Use 'VkDescriptorSet' as ImTextureID. Read the FAQ about ImTextureID! See https://github.com/ocornut/imgui/pull/914 for discussions. // [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices. // [x] Renderer: Multi-viewport / platform windows. With issues (flickering when creating a new viewport). -// [!] Renderer: User texture binding. Use 'VkDescriptorSet' as ImTextureID. Read the FAQ about ImTextureID! See https://github.com/ocornut/imgui/pull/914 for discussions. // Important: on 32-bit systems, user texture binding is only supported if your imconfig file has '#define ImTextureID ImU64'. // See imgui_impl_vulkan.cpp file for details. @@ -74,12 +74,14 @@ IMGUI_IMPL_API void ImGui_ImplVulkan_DestroyFontUploadObjects(); IMGUI_IMPL_API void ImGui_ImplVulkan_SetMinImageCount(uint32_t min_image_count); // To override MinImageCount after initialization (e.g. if swap chain is recreated) // Register a texture (VkDescriptorSet == ImTextureID) -// FIXME: This is experimental in the sense that we are unsure how to best design/tackle this problem, please post to https://github.com/ocornut/imgui/pull/914 if you have suggestions. +// FIXME: This is experimental in the sense that we are unsure how to best design/tackle this problem +// Please post to https://github.com/ocornut/imgui/pull/914 if you have suggestions. IMGUI_IMPL_API VkDescriptorSet ImGui_ImplVulkan_AddTexture(VkSampler sampler, VkImageView image_view, VkImageLayout image_layout); +IMGUI_IMPL_API void ImGui_ImplVulkan_RemoveTexture(VkDescriptorSet descriptor_set); // Optional: load Vulkan functions with a custom function loader // This is only useful with IMGUI_IMPL_VULKAN_NO_PROTOTYPES / VK_NO_PROTOTYPES -IMGUI_IMPL_API bool ImGui_ImplVulkan_LoadFunctions(PFN_vkVoidFunction(*loader_func)(const char* function_name, void* user_data), void* user_data = NULL); +IMGUI_IMPL_API bool ImGui_ImplVulkan_LoadFunctions(PFN_vkVoidFunction(*loader_func)(const char* function_name, void* user_data), void* user_data = nullptr); //------------------------------------------------------------------------- // Internal / Miscellaneous Vulkan Helpers diff --git a/extern/imgui_patched/backends/imgui_impl_wgpu.cpp b/extern/imgui_patched/backends/imgui_impl_wgpu.cpp index b9f363b9..8da8e457 100644 --- a/extern/imgui_patched/backends/imgui_impl_wgpu.cpp +++ b/extern/imgui_patched/backends/imgui_impl_wgpu.cpp @@ -13,8 +13,14 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) +// 2023-04-11: Align buffer sizes. Use WGSL shaders instead of precompiled SPIR-V. +// 2023-04-11: Reorganized backend to pull data from a single structure to facilitate usage with multiple-contexts (all g_XXXX access changed to bd->XXXX). +// 2023-01-25: Revert automatic pipeline layout generation (see https://github.com/gpuweb/gpuweb/issues/2470) +// 2022-11-24: Fixed validation error with default depth buffer settings. +// 2022-11-10: Fixed rendering when a depth buffer is enabled. Added 'WGPUTextureFormat depth_format' parameter to ImGui_ImplWGPU_Init(). +// 2022-10-11: Using 'nullptr' instead of 'NULL' as per our switch to C++11. // 2021-11-29: Passing explicit buffer sizes to wgpuRenderPassEncoderSetVertexBuffer()/wgpuRenderPassEncoderSetIndexBuffer(). -// 2021-08-24: Fix for latest specs. +// 2021-08-24: Fixed for latest specs. // 2021-05-24: Add support for draw_data->FramebufferScale. // 2021-05-19: Replaced direct access to ImDrawCmd::TextureId with a call to ImDrawCmd::GetTexID(). (will become a requirement) // 2021-05-16: Update to latest WebGPU specs (compatible with Emscripten 2.0.20 and Chrome Canary 92). @@ -26,33 +32,22 @@ #include #include -#define HAS_EMSCRIPTEN_VERSION(major, minor, tiny) (__EMSCRIPTEN_major__ > (major) || (__EMSCRIPTEN_major__ == (major) && __EMSCRIPTEN_minor__ > (minor)) || (__EMSCRIPTEN_major__ == (major) && __EMSCRIPTEN_minor__ == (minor) && __EMSCRIPTEN_tiny__ >= (tiny))) - -#if defined(__EMSCRIPTEN__) && !HAS_EMSCRIPTEN_VERSION(2, 0, 20) -#error "Requires at least emscripten 2.0.20" -#endif - // Dear ImGui prototypes from imgui_internal.h extern ImGuiID ImHashData(const void* data_p, size_t data_size, ImU32 seed = 0); +#define MEMALIGN(_SIZE,_ALIGN) (((_SIZE) + ((_ALIGN) - 1)) & ~((_ALIGN) - 1)) // Memory align (copied from IM_ALIGN() macro). // WebGPU data -static WGPUDevice g_wgpuDevice = NULL; -static WGPUQueue g_defaultQueue = NULL; -static WGPUTextureFormat g_renderTargetFormat = WGPUTextureFormat_Undefined; -static WGPURenderPipeline g_pipelineState = NULL; - struct RenderResources { - WGPUTexture FontTexture; // Font texture - WGPUTextureView FontTextureView; // Texture view for font texture - WGPUSampler Sampler; // Sampler for the font texture - WGPUBuffer Uniforms; // Shader uniforms - WGPUBindGroup CommonBindGroup; // Resources bind-group to bind the common resources to pipeline - ImGuiStorage ImageBindGroups; // Resources bind-group to bind the font/image resources to pipeline (this is a key->value map) - WGPUBindGroup ImageBindGroup; // Default font-resource of Dear ImGui - WGPUBindGroupLayout ImageBindGroupLayout; // Cache layout used for the image bind group. Avoids allocating unnecessary JS objects when working with WebASM + WGPUTexture FontTexture = nullptr; // Font texture + WGPUTextureView FontTextureView = nullptr; // Texture view for font texture + WGPUSampler Sampler = nullptr; // Sampler for the font texture + WGPUBuffer Uniforms = nullptr; // Shader uniforms + WGPUBindGroup CommonBindGroup = nullptr; // Resources bind-group to bind the common resources to pipeline + ImGuiStorage ImageBindGroups; // Resources bind-group to bind the font/image resources to pipeline (this is a key->value map) + WGPUBindGroup ImageBindGroup = nullptr; // Default font-resource of Dear ImGui + WGPUBindGroupLayout ImageBindGroupLayout = nullptr; // Cache layout used for the image bind group. Avoids allocating unnecessary JS objects when working with WebASM }; -static RenderResources g_resources; struct FrameResources { @@ -63,186 +58,151 @@ struct FrameResources int IndexBufferSize; int VertexBufferSize; }; -static FrameResources* g_pFrameResources = NULL; -static unsigned int g_numFramesInFlight = 0; -static unsigned int g_frameIndex = UINT_MAX; struct Uniforms { float MVP[4][4]; + float Gamma; }; +struct ImGui_ImplWGPU_Data +{ + WGPUDevice wgpuDevice = nullptr; + WGPUQueue defaultQueue = nullptr; + WGPUTextureFormat renderTargetFormat = WGPUTextureFormat_Undefined; + WGPUTextureFormat depthStencilFormat = WGPUTextureFormat_Undefined; + WGPURenderPipeline pipelineState = nullptr; + + RenderResources renderResources; + FrameResources* pFrameResources = nullptr; + unsigned int numFramesInFlight = 0; + unsigned int frameIndex = UINT_MAX; +}; + +// Backend data stored in io.BackendRendererUserData to allow support for multiple Dear ImGui contexts +// It is STRONGLY preferred that you use docking branch with multi-viewports (== single Dear ImGui context + multiple windows) instead of multiple Dear ImGui contexts. +static ImGui_ImplWGPU_Data* ImGui_ImplWGPU_GetBackendData() +{ + return ImGui::GetCurrentContext() ? (ImGui_ImplWGPU_Data*)ImGui::GetIO().BackendRendererUserData : nullptr; +} + //----------------------------------------------------------------------------- // SHADERS //----------------------------------------------------------------------------- -// glsl_shader.vert, compiled with: -// # glslangValidator -V -x -o glsl_shader.vert.u32 glsl_shader.vert -/* -#version 450 core -layout(location = 0) in vec2 aPos; -layout(location = 1) in vec2 aUV; -layout(location = 2) in vec4 aColor; -layout(set=0, binding = 0) uniform transform { mat4 mvp; }; - -out gl_PerVertex { vec4 gl_Position; }; -layout(location = 0) out struct { vec4 Color; vec2 UV; } Out; - -void main() -{ - Out.Color = aColor; - Out.UV = aUV; - gl_Position = mvp * vec4(aPos, 0, 1); -} -*/ -static uint32_t __glsl_shader_vert_spv[] = -{ - 0x07230203,0x00010000,0x00080007,0x0000002c,0x00000000,0x00020011,0x00000001,0x0006000b, - 0x00000001,0x4c534c47,0x6474732e,0x3035342e,0x00000000,0x0003000e,0x00000000,0x00000001, - 0x000a000f,0x00000000,0x00000004,0x6e69616d,0x00000000,0x0000000b,0x0000000f,0x00000015, - 0x0000001b,0x00000023,0x00030003,0x00000002,0x000001c2,0x00040005,0x00000004,0x6e69616d, - 0x00000000,0x00030005,0x00000009,0x00000000,0x00050006,0x00000009,0x00000000,0x6f6c6f43, - 0x00000072,0x00040006,0x00000009,0x00000001,0x00005655,0x00030005,0x0000000b,0x0074754f, - 0x00040005,0x0000000f,0x6c6f4361,0x0000726f,0x00030005,0x00000015,0x00565561,0x00060005, - 0x00000019,0x505f6c67,0x65567265,0x78657472,0x00000000,0x00060006,0x00000019,0x00000000, - 0x505f6c67,0x7469736f,0x006e6f69,0x00030005,0x0000001b,0x00000000,0x00050005,0x0000001d, - 0x6e617274,0x726f6673,0x0000006d,0x00040006,0x0000001d,0x00000000,0x0070766d,0x00030005, - 0x0000001f,0x00000000,0x00040005,0x00000023,0x736f5061,0x00000000,0x00040047,0x0000000b, - 0x0000001e,0x00000000,0x00040047,0x0000000f,0x0000001e,0x00000002,0x00040047,0x00000015, - 0x0000001e,0x00000001,0x00050048,0x00000019,0x00000000,0x0000000b,0x00000000,0x00030047, - 0x00000019,0x00000002,0x00040048,0x0000001d,0x00000000,0x00000005,0x00050048,0x0000001d, - 0x00000000,0x00000023,0x00000000,0x00050048,0x0000001d,0x00000000,0x00000007,0x00000010, - 0x00030047,0x0000001d,0x00000002,0x00040047,0x0000001f,0x00000022,0x00000000,0x00040047, - 0x0000001f,0x00000021,0x00000000,0x00040047,0x00000023,0x0000001e,0x00000000,0x00020013, - 0x00000002,0x00030021,0x00000003,0x00000002,0x00030016,0x00000006,0x00000020,0x00040017, - 0x00000007,0x00000006,0x00000004,0x00040017,0x00000008,0x00000006,0x00000002,0x0004001e, - 0x00000009,0x00000007,0x00000008,0x00040020,0x0000000a,0x00000003,0x00000009,0x0004003b, - 0x0000000a,0x0000000b,0x00000003,0x00040015,0x0000000c,0x00000020,0x00000001,0x0004002b, - 0x0000000c,0x0000000d,0x00000000,0x00040020,0x0000000e,0x00000001,0x00000007,0x0004003b, - 0x0000000e,0x0000000f,0x00000001,0x00040020,0x00000011,0x00000003,0x00000007,0x0004002b, - 0x0000000c,0x00000013,0x00000001,0x00040020,0x00000014,0x00000001,0x00000008,0x0004003b, - 0x00000014,0x00000015,0x00000001,0x00040020,0x00000017,0x00000003,0x00000008,0x0003001e, - 0x00000019,0x00000007,0x00040020,0x0000001a,0x00000003,0x00000019,0x0004003b,0x0000001a, - 0x0000001b,0x00000003,0x00040018,0x0000001c,0x00000007,0x00000004,0x0003001e,0x0000001d, - 0x0000001c,0x00040020,0x0000001e,0x00000002,0x0000001d,0x0004003b,0x0000001e,0x0000001f, - 0x00000002,0x00040020,0x00000020,0x00000002,0x0000001c,0x0004003b,0x00000014,0x00000023, - 0x00000001,0x0004002b,0x00000006,0x00000025,0x00000000,0x0004002b,0x00000006,0x00000026, - 0x3f800000,0x00050036,0x00000002,0x00000004,0x00000000,0x00000003,0x000200f8,0x00000005, - 0x0004003d,0x00000007,0x00000010,0x0000000f,0x00050041,0x00000011,0x00000012,0x0000000b, - 0x0000000d,0x0003003e,0x00000012,0x00000010,0x0004003d,0x00000008,0x00000016,0x00000015, - 0x00050041,0x00000017,0x00000018,0x0000000b,0x00000013,0x0003003e,0x00000018,0x00000016, - 0x00050041,0x00000020,0x00000021,0x0000001f,0x0000000d,0x0004003d,0x0000001c,0x00000022, - 0x00000021,0x0004003d,0x00000008,0x00000024,0x00000023,0x00050051,0x00000006,0x00000027, - 0x00000024,0x00000000,0x00050051,0x00000006,0x00000028,0x00000024,0x00000001,0x00070050, - 0x00000007,0x00000029,0x00000027,0x00000028,0x00000025,0x00000026,0x00050091,0x00000007, - 0x0000002a,0x00000022,0x00000029,0x00050041,0x00000011,0x0000002b,0x0000001b,0x0000000d, - 0x0003003e,0x0000002b,0x0000002a,0x000100fd,0x00010038 +static const char __shader_vert_wgsl[] = R"( +struct VertexInput { + @location(0) position: vec2, + @location(1) uv: vec2, + @location(2) color: vec4, }; -// glsl_shader.frag, compiled with: -// # glslangValidator -V -x -o glsl_shader.frag.u32 glsl_shader.frag -/* -#version 450 core -layout(location = 0) out vec4 fColor; -layout(set=0, binding=1) uniform sampler s; -layout(set=1, binding=0) uniform texture2D t; -layout(location = 0) in struct { vec4 Color; vec2 UV; } In; -void main() -{ - fColor = In.Color * texture(sampler2D(t, s), In.UV.st); -} -*/ -static uint32_t __glsl_shader_frag_spv[] = -{ - 0x07230203,0x00010000,0x00080007,0x00000023,0x00000000,0x00020011,0x00000001,0x0006000b, - 0x00000001,0x4c534c47,0x6474732e,0x3035342e,0x00000000,0x0003000e,0x00000000,0x00000001, - 0x0007000f,0x00000004,0x00000004,0x6e69616d,0x00000000,0x00000009,0x0000000d,0x00030010, - 0x00000004,0x00000007,0x00030003,0x00000002,0x000001c2,0x00040005,0x00000004,0x6e69616d, - 0x00000000,0x00040005,0x00000009,0x6c6f4366,0x0000726f,0x00030005,0x0000000b,0x00000000, - 0x00050006,0x0000000b,0x00000000,0x6f6c6f43,0x00000072,0x00040006,0x0000000b,0x00000001, - 0x00005655,0x00030005,0x0000000d,0x00006e49,0x00030005,0x00000015,0x00000074,0x00030005, - 0x00000019,0x00000073,0x00040047,0x00000009,0x0000001e,0x00000000,0x00040047,0x0000000d, - 0x0000001e,0x00000000,0x00040047,0x00000015,0x00000022,0x00000001,0x00040047,0x00000015, - 0x00000021,0x00000000,0x00040047,0x00000019,0x00000022,0x00000000,0x00040047,0x00000019, - 0x00000021,0x00000001,0x00020013,0x00000002,0x00030021,0x00000003,0x00000002,0x00030016, - 0x00000006,0x00000020,0x00040017,0x00000007,0x00000006,0x00000004,0x00040020,0x00000008, - 0x00000003,0x00000007,0x0004003b,0x00000008,0x00000009,0x00000003,0x00040017,0x0000000a, - 0x00000006,0x00000002,0x0004001e,0x0000000b,0x00000007,0x0000000a,0x00040020,0x0000000c, - 0x00000001,0x0000000b,0x0004003b,0x0000000c,0x0000000d,0x00000001,0x00040015,0x0000000e, - 0x00000020,0x00000001,0x0004002b,0x0000000e,0x0000000f,0x00000000,0x00040020,0x00000010, - 0x00000001,0x00000007,0x00090019,0x00000013,0x00000006,0x00000001,0x00000000,0x00000000, - 0x00000000,0x00000001,0x00000000,0x00040020,0x00000014,0x00000000,0x00000013,0x0004003b, - 0x00000014,0x00000015,0x00000000,0x0002001a,0x00000017,0x00040020,0x00000018,0x00000000, - 0x00000017,0x0004003b,0x00000018,0x00000019,0x00000000,0x0003001b,0x0000001b,0x00000013, - 0x0004002b,0x0000000e,0x0000001d,0x00000001,0x00040020,0x0000001e,0x00000001,0x0000000a, - 0x00050036,0x00000002,0x00000004,0x00000000,0x00000003,0x000200f8,0x00000005,0x00050041, - 0x00000010,0x00000011,0x0000000d,0x0000000f,0x0004003d,0x00000007,0x00000012,0x00000011, - 0x0004003d,0x00000013,0x00000016,0x00000015,0x0004003d,0x00000017,0x0000001a,0x00000019, - 0x00050056,0x0000001b,0x0000001c,0x00000016,0x0000001a,0x00050041,0x0000001e,0x0000001f, - 0x0000000d,0x0000001d,0x0004003d,0x0000000a,0x00000020,0x0000001f,0x00050057,0x00000007, - 0x00000021,0x0000001c,0x00000020,0x00050085,0x00000007,0x00000022,0x00000012,0x00000021, - 0x0003003e,0x00000009,0x00000022,0x000100fd,0x00010038 +struct VertexOutput { + @builtin(position) position: vec4, + @location(0) color: vec4, + @location(1) uv: vec2, }; +struct Uniforms { + mvp: mat4x4, + gamma: f32, +}; + +@group(0) @binding(0) var uniforms: Uniforms; + +@vertex +fn main(in: VertexInput) -> VertexOutput { + var out: VertexOutput; + out.position = uniforms.mvp * vec4(in.position, 0.0, 1.0); + out.color = in.color; + out.uv = in.uv; + return out; +} +)"; + +static const char __shader_frag_wgsl[] = R"( +struct VertexOutput { + @builtin(position) position: vec4, + @location(0) color: vec4, + @location(1) uv: vec2, +}; + +struct Uniforms { + mvp: mat4x4, + gamma: f32, +}; + +@group(0) @binding(0) var uniforms: Uniforms; +@group(0) @binding(1) var s: sampler; +@group(1) @binding(0) var t: texture_2d; + +@fragment +fn main(in: VertexOutput) -> @location(0) vec4 { + let color = in.color * textureSample(t, s, in.uv); + let corrected_color = pow(color.rgb, vec3(uniforms.gamma)); + return vec4(corrected_color, color.a); +} +)"; + static void SafeRelease(ImDrawIdx*& res) { if (res) delete[] res; - res = NULL; + res = nullptr; } static void SafeRelease(ImDrawVert*& res) { if (res) delete[] res; - res = NULL; + res = nullptr; } static void SafeRelease(WGPUBindGroupLayout& res) { if (res) wgpuBindGroupLayoutRelease(res); - res = NULL; + res = nullptr; } static void SafeRelease(WGPUBindGroup& res) { if (res) wgpuBindGroupRelease(res); - res = NULL; + res = nullptr; } static void SafeRelease(WGPUBuffer& res) { if (res) wgpuBufferRelease(res); - res = NULL; + res = nullptr; } static void SafeRelease(WGPURenderPipeline& res) { if (res) wgpuRenderPipelineRelease(res); - res = NULL; + res = nullptr; } static void SafeRelease(WGPUSampler& res) { if (res) wgpuSamplerRelease(res); - res = NULL; + res = nullptr; } static void SafeRelease(WGPUShaderModule& res) { if (res) wgpuShaderModuleRelease(res); - res = NULL; + res = nullptr; } static void SafeRelease(WGPUTextureView& res) { if (res) wgpuTextureViewRelease(res); - res = NULL; + res = nullptr; } static void SafeRelease(WGPUTexture& res) { if (res) wgpuTextureRelease(res); - res = NULL; + res = nullptr; } static void SafeRelease(RenderResources& res) @@ -264,35 +224,39 @@ static void SafeRelease(FrameResources& res) SafeRelease(res.VertexBufferHost); } -static WGPUProgrammableStageDescriptor ImGui_ImplWGPU_CreateShaderModule(uint32_t* binary_data, uint32_t binary_data_size) +static WGPUProgrammableStageDescriptor ImGui_ImplWGPU_CreateShaderModule(const char* wgsl_source) { - WGPUShaderModuleSPIRVDescriptor spirv_desc = {}; - spirv_desc.chain.sType = WGPUSType_ShaderModuleSPIRVDescriptor; - spirv_desc.codeSize = binary_data_size; - spirv_desc.code = binary_data; + ImGui_ImplWGPU_Data* bd = ImGui_ImplWGPU_GetBackendData(); + + WGPUShaderModuleWGSLDescriptor wgsl_desc = {}; + wgsl_desc.chain.sType = WGPUSType_ShaderModuleWGSLDescriptor; + wgsl_desc.source = wgsl_source; WGPUShaderModuleDescriptor desc = {}; - desc.nextInChain = reinterpret_cast(&spirv_desc); + desc.nextInChain = reinterpret_cast(&wgsl_desc); WGPUProgrammableStageDescriptor stage_desc = {}; - stage_desc.module = wgpuDeviceCreateShaderModule(g_wgpuDevice, &desc); + stage_desc.module = wgpuDeviceCreateShaderModule(bd->wgpuDevice, &desc); stage_desc.entryPoint = "main"; return stage_desc; } static WGPUBindGroup ImGui_ImplWGPU_CreateImageBindGroup(WGPUBindGroupLayout layout, WGPUTextureView texture) { + ImGui_ImplWGPU_Data* bd = ImGui_ImplWGPU_GetBackendData(); WGPUBindGroupEntry image_bg_entries[] = { { nullptr, 0, 0, 0, 0, 0, texture } }; WGPUBindGroupDescriptor image_bg_descriptor = {}; image_bg_descriptor.layout = layout; image_bg_descriptor.entryCount = sizeof(image_bg_entries) / sizeof(WGPUBindGroupEntry); image_bg_descriptor.entries = image_bg_entries; - return wgpuDeviceCreateBindGroup(g_wgpuDevice, &image_bg_descriptor); + return wgpuDeviceCreateBindGroup(bd->wgpuDevice, &image_bg_descriptor); } static void ImGui_ImplWGPU_SetupRenderState(ImDrawData* draw_data, WGPURenderPassEncoder ctx, FrameResources* fr) { + ImGui_ImplWGPU_Data* bd = ImGui_ImplWGPU_GetBackendData(); + // Setup orthographic projection matrix into our constant buffer // Our visible imgui space lies from draw_data->DisplayPos (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right). { @@ -307,7 +271,38 @@ static void ImGui_ImplWGPU_SetupRenderState(ImDrawData* draw_data, WGPURenderPas { 0.0f, 0.0f, 0.5f, 0.0f }, { (R+L)/(L-R), (T+B)/(B-T), 0.5f, 1.0f }, }; - wgpuQueueWriteBuffer(g_defaultQueue, g_resources.Uniforms, 0, mvp, sizeof(mvp)); + wgpuQueueWriteBuffer(bd->defaultQueue, bd->renderResources.Uniforms, offsetof(Uniforms, MVP), mvp, sizeof(Uniforms::MVP)); + float gamma; + switch (bd->renderTargetFormat) + { + case WGPUTextureFormat_ASTC10x10UnormSrgb: + case WGPUTextureFormat_ASTC10x5UnormSrgb: + case WGPUTextureFormat_ASTC10x6UnormSrgb: + case WGPUTextureFormat_ASTC10x8UnormSrgb: + case WGPUTextureFormat_ASTC12x10UnormSrgb: + case WGPUTextureFormat_ASTC12x12UnormSrgb: + case WGPUTextureFormat_ASTC4x4UnormSrgb: + case WGPUTextureFormat_ASTC5x5UnormSrgb: + case WGPUTextureFormat_ASTC6x5UnormSrgb: + case WGPUTextureFormat_ASTC6x6UnormSrgb: + case WGPUTextureFormat_ASTC8x5UnormSrgb: + case WGPUTextureFormat_ASTC8x6UnormSrgb: + case WGPUTextureFormat_ASTC8x8UnormSrgb: + case WGPUTextureFormat_BC1RGBAUnormSrgb: + case WGPUTextureFormat_BC2RGBAUnormSrgb: + case WGPUTextureFormat_BC3RGBAUnormSrgb: + case WGPUTextureFormat_BC7RGBAUnormSrgb: + case WGPUTextureFormat_BGRA8UnormSrgb: + case WGPUTextureFormat_ETC2RGB8A1UnormSrgb: + case WGPUTextureFormat_ETC2RGB8UnormSrgb: + case WGPUTextureFormat_ETC2RGBA8UnormSrgb: + case WGPUTextureFormat_RGBA8UnormSrgb: + gamma = 2.2f; + break; + default: + gamma = 1.0f; + } + wgpuQueueWriteBuffer(bd->defaultQueue, bd->renderResources.Uniforms, offsetof(Uniforms, Gamma), &gamma, sizeof(Uniforms::Gamma)); } // Setup viewport @@ -316,8 +311,8 @@ static void ImGui_ImplWGPU_SetupRenderState(ImDrawData* draw_data, WGPURenderPas // Bind shader and vertex buffers wgpuRenderPassEncoderSetVertexBuffer(ctx, 0, fr->VertexBuffer, 0, fr->VertexBufferSize * sizeof(ImDrawVert)); wgpuRenderPassEncoderSetIndexBuffer(ctx, fr->IndexBuffer, sizeof(ImDrawIdx) == 2 ? WGPUIndexFormat_Uint16 : WGPUIndexFormat_Uint32, 0, fr->IndexBufferSize * sizeof(ImDrawIdx)); - wgpuRenderPassEncoderSetPipeline(ctx, g_pipelineState); - wgpuRenderPassEncoderSetBindGroup(ctx, 0, g_resources.CommonBindGroup, 0, NULL); + wgpuRenderPassEncoderSetPipeline(ctx, bd->pipelineState); + wgpuRenderPassEncoderSetBindGroup(ctx, 0, bd->renderResources.CommonBindGroup, 0, nullptr); // Setup blend factor WGPUColor blend_color = { 0.f, 0.f, 0.f, 0.f }; @@ -334,11 +329,12 @@ void ImGui_ImplWGPU_RenderDrawData(ImDrawData* draw_data, WGPURenderPassEncoder // FIXME: Assuming that this only gets called once per frame! // If not, we can't just re-allocate the IB or VB, we'll have to do a proper allocator. - g_frameIndex = g_frameIndex + 1; - FrameResources* fr = &g_pFrameResources[g_frameIndex % g_numFramesInFlight]; + ImGui_ImplWGPU_Data* bd = ImGui_ImplWGPU_GetBackendData(); + bd->frameIndex = bd->frameIndex + 1; + FrameResources* fr = &bd->pFrameResources[bd->frameIndex % bd->numFramesInFlight]; // Create and grow vertex/index buffers if needed - if (fr->VertexBuffer == NULL || fr->VertexBufferSize < draw_data->TotalVtxCount) + if (fr->VertexBuffer == nullptr || fr->VertexBufferSize < draw_data->TotalVtxCount) { if (fr->VertexBuffer) { @@ -350,19 +346,19 @@ void ImGui_ImplWGPU_RenderDrawData(ImDrawData* draw_data, WGPURenderPassEncoder WGPUBufferDescriptor vb_desc = { - NULL, + nullptr, "Dear ImGui Vertex buffer", WGPUBufferUsage_CopyDst | WGPUBufferUsage_Vertex, - fr->VertexBufferSize * sizeof(ImDrawVert), + MEMALIGN(fr->VertexBufferSize * sizeof(ImDrawVert), 4), false }; - fr->VertexBuffer = wgpuDeviceCreateBuffer(g_wgpuDevice, &vb_desc); + fr->VertexBuffer = wgpuDeviceCreateBuffer(bd->wgpuDevice, &vb_desc); if (!fr->VertexBuffer) return; fr->VertexBufferHost = new ImDrawVert[fr->VertexBufferSize]; } - if (fr->IndexBuffer == NULL || fr->IndexBufferSize < draw_data->TotalIdxCount) + if (fr->IndexBuffer == nullptr || fr->IndexBufferSize < draw_data->TotalIdxCount) { if (fr->IndexBuffer) { @@ -374,13 +370,13 @@ void ImGui_ImplWGPU_RenderDrawData(ImDrawData* draw_data, WGPURenderPassEncoder WGPUBufferDescriptor ib_desc = { - NULL, + nullptr, "Dear ImGui Index buffer", WGPUBufferUsage_CopyDst | WGPUBufferUsage_Index, - fr->IndexBufferSize * sizeof(ImDrawIdx), + MEMALIGN(fr->IndexBufferSize * sizeof(ImDrawIdx), 4), false }; - fr->IndexBuffer = wgpuDeviceCreateBuffer(g_wgpuDevice, &ib_desc); + fr->IndexBuffer = wgpuDeviceCreateBuffer(bd->wgpuDevice, &ib_desc); if (!fr->IndexBuffer) return; @@ -398,10 +394,10 @@ void ImGui_ImplWGPU_RenderDrawData(ImDrawData* draw_data, WGPURenderPassEncoder vtx_dst += cmd_list->VtxBuffer.Size; idx_dst += cmd_list->IdxBuffer.Size; } - int64_t vb_write_size = ((char*)vtx_dst - (char*)fr->VertexBufferHost + 3) & ~3; - int64_t ib_write_size = ((char*)idx_dst - (char*)fr->IndexBufferHost + 3) & ~3; - wgpuQueueWriteBuffer(g_defaultQueue, fr->VertexBuffer, 0, fr->VertexBufferHost, vb_write_size); - wgpuQueueWriteBuffer(g_defaultQueue, fr->IndexBuffer, 0, fr->IndexBufferHost, ib_write_size); + int64_t vb_write_size = MEMALIGN((char*)vtx_dst - (char*)fr->VertexBufferHost, 4); + int64_t ib_write_size = MEMALIGN((char*)idx_dst - (char*)fr->IndexBufferHost, 4); + wgpuQueueWriteBuffer(bd->defaultQueue, fr->VertexBuffer, 0, fr->VertexBufferHost, vb_write_size); + wgpuQueueWriteBuffer(bd->defaultQueue, fr->IndexBuffer, 0, fr->IndexBufferHost, ib_write_size); // Setup desired render state ImGui_ImplWGPU_SetupRenderState(draw_data, pass_encoder, fr); @@ -418,7 +414,7 @@ void ImGui_ImplWGPU_RenderDrawData(ImDrawData* draw_data, WGPURenderPassEncoder for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++) { const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i]; - if (pcmd->UserCallback != NULL) + if (pcmd->UserCallback != nullptr) { // User callback, registered via ImDrawList::AddCallback() // (ImDrawCallback_ResetRenderState is a special callback value used by the user to request the renderer to reset render state.) @@ -432,16 +428,16 @@ void ImGui_ImplWGPU_RenderDrawData(ImDrawData* draw_data, WGPURenderPassEncoder // Bind custom texture ImTextureID tex_id = pcmd->GetTexID(); ImGuiID tex_id_hash = ImHashData(&tex_id, sizeof(tex_id)); - auto bind_group = g_resources.ImageBindGroups.GetVoidPtr(tex_id_hash); + auto bind_group = bd->renderResources.ImageBindGroups.GetVoidPtr(tex_id_hash); if (bind_group) { - wgpuRenderPassEncoderSetBindGroup(pass_encoder, 1, (WGPUBindGroup)bind_group, 0, NULL); + wgpuRenderPassEncoderSetBindGroup(pass_encoder, 1, (WGPUBindGroup)bind_group, 0, nullptr); } else { - WGPUBindGroup image_bind_group = ImGui_ImplWGPU_CreateImageBindGroup(g_resources.ImageBindGroupLayout, (WGPUTextureView)tex_id); - g_resources.ImageBindGroups.SetVoidPtr(tex_id_hash, image_bind_group); - wgpuRenderPassEncoderSetBindGroup(pass_encoder, 1, image_bind_group, 0, NULL); + WGPUBindGroup image_bind_group = ImGui_ImplWGPU_CreateImageBindGroup(bd->renderResources.ImageBindGroupLayout, (WGPUTextureView)tex_id); + bd->renderResources.ImageBindGroups.SetVoidPtr(tex_id_hash, image_bind_group); + wgpuRenderPassEncoderSetBindGroup(pass_encoder, 1, image_bind_group, 0, nullptr); } // Project scissor/clipping rectangles into framebuffer space @@ -463,6 +459,7 @@ void ImGui_ImplWGPU_RenderDrawData(ImDrawData* draw_data, WGPURenderPassEncoder static void ImGui_ImplWGPU_CreateFontsTexture() { // Build texture atlas + ImGui_ImplWGPU_Data* bd = ImGui_ImplWGPU_GetBackendData(); ImGuiIO& io = ImGui::GetIO(); unsigned char* pixels; int width, height, size_pp; @@ -480,7 +477,7 @@ static void ImGui_ImplWGPU_CreateFontsTexture() tex_desc.format = WGPUTextureFormat_RGBA8Unorm; tex_desc.mipLevelCount = 1; tex_desc.usage = WGPUTextureUsage_CopyDst | WGPUTextureUsage_TextureBinding; - g_resources.FontTexture = wgpuDeviceCreateTexture(g_wgpuDevice, &tex_desc); + bd->renderResources.FontTexture = wgpuDeviceCreateTexture(bd->wgpuDevice, &tex_desc); WGPUTextureViewDescriptor tex_view_desc = {}; tex_view_desc.format = WGPUTextureFormat_RGBA8Unorm; @@ -490,13 +487,13 @@ static void ImGui_ImplWGPU_CreateFontsTexture() tex_view_desc.baseArrayLayer = 0; tex_view_desc.arrayLayerCount = 1; tex_view_desc.aspect = WGPUTextureAspect_All; - g_resources.FontTextureView = wgpuTextureCreateView(g_resources.FontTexture, &tex_view_desc); + bd->renderResources.FontTextureView = wgpuTextureCreateView(bd->renderResources.FontTexture, &tex_view_desc); } // Upload texture data { WGPUImageCopyTexture dst_view = {}; - dst_view.texture = g_resources.FontTexture; + dst_view.texture = bd->renderResources.FontTexture; dst_view.mipLevel = 0; dst_view.origin = { 0, 0, 0 }; dst_view.aspect = WGPUTextureAspect_All; @@ -505,7 +502,7 @@ static void ImGui_ImplWGPU_CreateFontsTexture() layout.bytesPerRow = width * size_pp; layout.rowsPerImage = height; WGPUExtent3D size = { (uint32_t)width, (uint32_t)height, 1 }; - wgpuQueueWriteTexture(g_defaultQueue, &dst_view, pixels, (uint32_t)(width * size_pp * height), &layout, &size); + wgpuQueueWriteTexture(bd->defaultQueue, &dst_view, pixels, (uint32_t)(width * size_pp * height), &layout, &size); } // Create the associated sampler @@ -519,32 +516,34 @@ static void ImGui_ImplWGPU_CreateFontsTexture() sampler_desc.addressModeV = WGPUAddressMode_Repeat; sampler_desc.addressModeW = WGPUAddressMode_Repeat; sampler_desc.maxAnisotropy = 1; - g_resources.Sampler = wgpuDeviceCreateSampler(g_wgpuDevice, &sampler_desc); + bd->renderResources.Sampler = wgpuDeviceCreateSampler(bd->wgpuDevice, &sampler_desc); } // Store our identifier - static_assert(sizeof(ImTextureID) >= sizeof(g_resources.FontTexture), "Can't pack descriptor handle into TexID, 32-bit not supported yet."); - io.Fonts->SetTexID((ImTextureID)g_resources.FontTextureView); + static_assert(sizeof(ImTextureID) >= sizeof(bd->renderResources.FontTexture), "Can't pack descriptor handle into TexID, 32-bit not supported yet."); + io.Fonts->SetTexID((ImTextureID)bd->renderResources.FontTextureView); } static void ImGui_ImplWGPU_CreateUniformBuffer() { + ImGui_ImplWGPU_Data* bd = ImGui_ImplWGPU_GetBackendData(); WGPUBufferDescriptor ub_desc = { - NULL, + nullptr, "Dear ImGui Uniform buffer", WGPUBufferUsage_CopyDst | WGPUBufferUsage_Uniform, - sizeof(Uniforms), + MEMALIGN(sizeof(Uniforms), 16), false }; - g_resources.Uniforms = wgpuDeviceCreateBuffer(g_wgpuDevice, &ub_desc); + bd->renderResources.Uniforms = wgpuDeviceCreateBuffer(bd->wgpuDevice, &ub_desc); } bool ImGui_ImplWGPU_CreateDeviceObjects() { - if (!g_wgpuDevice) + ImGui_ImplWGPU_Data* bd = ImGui_ImplWGPU_GetBackendData(); + if (!bd->wgpuDevice) return false; - if (g_pipelineState) + if (bd->pipelineState) ImGui_ImplWGPU_InvalidateDeviceObjects(); // Create render pipeline @@ -556,10 +555,41 @@ bool ImGui_ImplWGPU_CreateDeviceObjects() graphics_pipeline_desc.multisample.count = 1; graphics_pipeline_desc.multisample.mask = UINT_MAX; graphics_pipeline_desc.multisample.alphaToCoverageEnabled = false; - graphics_pipeline_desc.layout = nullptr; // Use automatic layout generation + + // Bind group layouts + WGPUBindGroupLayoutEntry common_bg_layout_entries[2] = {}; + common_bg_layout_entries[0].binding = 0; + common_bg_layout_entries[0].visibility = WGPUShaderStage_Vertex | WGPUShaderStage_Fragment; + common_bg_layout_entries[0].buffer.type = WGPUBufferBindingType_Uniform; + common_bg_layout_entries[1].binding = 1; + common_bg_layout_entries[1].visibility = WGPUShaderStage_Fragment; + common_bg_layout_entries[1].sampler.type = WGPUSamplerBindingType_Filtering; + + WGPUBindGroupLayoutEntry image_bg_layout_entries[1] = {}; + image_bg_layout_entries[0].binding = 0; + image_bg_layout_entries[0].visibility = WGPUShaderStage_Fragment; + image_bg_layout_entries[0].texture.sampleType = WGPUTextureSampleType_Float; + image_bg_layout_entries[0].texture.viewDimension = WGPUTextureViewDimension_2D; + + WGPUBindGroupLayoutDescriptor common_bg_layout_desc = {}; + common_bg_layout_desc.entryCount = 2; + common_bg_layout_desc.entries = common_bg_layout_entries; + + WGPUBindGroupLayoutDescriptor image_bg_layout_desc = {}; + image_bg_layout_desc.entryCount = 1; + image_bg_layout_desc.entries = image_bg_layout_entries; + + WGPUBindGroupLayout bg_layouts[2]; + bg_layouts[0] = wgpuDeviceCreateBindGroupLayout(bd->wgpuDevice, &common_bg_layout_desc); + bg_layouts[1] = wgpuDeviceCreateBindGroupLayout(bd->wgpuDevice, &image_bg_layout_desc); + + WGPUPipelineLayoutDescriptor layout_desc = {}; + layout_desc.bindGroupLayoutCount = 2; + layout_desc.bindGroupLayouts = bg_layouts; + graphics_pipeline_desc.layout = wgpuDeviceCreatePipelineLayout(bd->wgpuDevice, &layout_desc); // Create the vertex shader - WGPUProgrammableStageDescriptor vertex_shader_desc = ImGui_ImplWGPU_CreateShaderModule(__glsl_shader_vert_spv, sizeof(__glsl_shader_vert_spv) / sizeof(uint32_t)); + WGPUProgrammableStageDescriptor vertex_shader_desc = ImGui_ImplWGPU_CreateShaderModule(__shader_vert_wgsl); graphics_pipeline_desc.vertex.module = vertex_shader_desc.module; graphics_pipeline_desc.vertex.entryPoint = vertex_shader_desc.entryPoint; @@ -581,7 +611,7 @@ bool ImGui_ImplWGPU_CreateDeviceObjects() graphics_pipeline_desc.vertex.buffers = buffer_layouts; // Create the pixel shader - WGPUProgrammableStageDescriptor pixel_shader_desc = ImGui_ImplWGPU_CreateShaderModule(__glsl_shader_frag_spv, sizeof(__glsl_shader_frag_spv) / sizeof(uint32_t)); + WGPUProgrammableStageDescriptor pixel_shader_desc = ImGui_ImplWGPU_CreateShaderModule(__shader_frag_wgsl); // Create the blending setup WGPUBlendState blend_state = {}; @@ -593,7 +623,7 @@ bool ImGui_ImplWGPU_CreateDeviceObjects() blend_state.color.dstFactor = WGPUBlendFactor_OneMinusSrcAlpha; WGPUColorTargetState color_state = {}; - color_state.format = g_renderTargetFormat; + color_state.format = bd->renderTargetFormat; color_state.blend = &blend_state; color_state.writeMask = WGPUColorWriteMask_All; @@ -607,39 +637,37 @@ bool ImGui_ImplWGPU_CreateDeviceObjects() // Create depth-stencil State WGPUDepthStencilState depth_stencil_state = {}; - depth_stencil_state.depthBias = 0; - depth_stencil_state.depthBiasClamp = 0; - depth_stencil_state.depthBiasSlopeScale = 0; + depth_stencil_state.format = bd->depthStencilFormat; + depth_stencil_state.depthWriteEnabled = false; + depth_stencil_state.depthCompare = WGPUCompareFunction_Always; + depth_stencil_state.stencilFront.compare = WGPUCompareFunction_Always; + depth_stencil_state.stencilBack.compare = WGPUCompareFunction_Always; // Configure disabled depth-stencil state - graphics_pipeline_desc.depthStencil = nullptr; + graphics_pipeline_desc.depthStencil = (bd->depthStencilFormat == WGPUTextureFormat_Undefined) ? nullptr : &depth_stencil_state; - g_pipelineState = wgpuDeviceCreateRenderPipeline(g_wgpuDevice, &graphics_pipeline_desc); + bd->pipelineState = wgpuDeviceCreateRenderPipeline(bd->wgpuDevice, &graphics_pipeline_desc); ImGui_ImplWGPU_CreateFontsTexture(); ImGui_ImplWGPU_CreateUniformBuffer(); // Create resource bind group - WGPUBindGroupLayout bg_layouts[2]; - bg_layouts[0] = wgpuRenderPipelineGetBindGroupLayout(g_pipelineState, 0); - bg_layouts[1] = wgpuRenderPipelineGetBindGroupLayout(g_pipelineState, 1); - WGPUBindGroupEntry common_bg_entries[] = { - { nullptr, 0, g_resources.Uniforms, 0, sizeof(Uniforms), 0, 0 }, - { nullptr, 1, 0, 0, 0, g_resources.Sampler, 0 }, + { nullptr, 0, bd->renderResources.Uniforms, 0, MEMALIGN(sizeof(Uniforms), 16), 0, 0 }, + { nullptr, 1, 0, 0, 0, bd->renderResources.Sampler, 0 }, }; WGPUBindGroupDescriptor common_bg_descriptor = {}; common_bg_descriptor.layout = bg_layouts[0]; common_bg_descriptor.entryCount = sizeof(common_bg_entries) / sizeof(WGPUBindGroupEntry); common_bg_descriptor.entries = common_bg_entries; - g_resources.CommonBindGroup = wgpuDeviceCreateBindGroup(g_wgpuDevice, &common_bg_descriptor); + bd->renderResources.CommonBindGroup = wgpuDeviceCreateBindGroup(bd->wgpuDevice, &common_bg_descriptor); - WGPUBindGroup image_bind_group = ImGui_ImplWGPU_CreateImageBindGroup(bg_layouts[1], g_resources.FontTextureView); - g_resources.ImageBindGroup = image_bind_group; - g_resources.ImageBindGroupLayout = bg_layouts[1]; - g_resources.ImageBindGroups.SetVoidPtr(ImHashData(&g_resources.FontTextureView, sizeof(ImTextureID)), image_bind_group); + WGPUBindGroup image_bind_group = ImGui_ImplWGPU_CreateImageBindGroup(bg_layouts[1], bd->renderResources.FontTextureView); + bd->renderResources.ImageBindGroup = image_bind_group; + bd->renderResources.ImageBindGroupLayout = bg_layouts[1]; + bd->renderResources.ImageBindGroups.SetVoidPtr(ImHashData(&bd->renderResources.FontTextureView, sizeof(ImTextureID)), image_bind_group); SafeRelease(vertex_shader_desc.module); SafeRelease(pixel_shader_desc.module); @@ -650,50 +678,56 @@ bool ImGui_ImplWGPU_CreateDeviceObjects() void ImGui_ImplWGPU_InvalidateDeviceObjects() { - if (!g_wgpuDevice) + ImGui_ImplWGPU_Data* bd = ImGui_ImplWGPU_GetBackendData(); + if (!bd->wgpuDevice) return; - SafeRelease(g_pipelineState); - SafeRelease(g_resources); + SafeRelease(bd->pipelineState); + SafeRelease(bd->renderResources); ImGuiIO& io = ImGui::GetIO(); - io.Fonts->SetTexID(NULL); // We copied g_pFontTextureView to io.Fonts->TexID so let's clear that as well. + io.Fonts->SetTexID(0); // We copied g_pFontTextureView to io.Fonts->TexID so let's clear that as well. - for (unsigned int i = 0; i < g_numFramesInFlight; i++) - SafeRelease(g_pFrameResources[i]); + for (unsigned int i = 0; i < bd->numFramesInFlight; i++) + SafeRelease(bd->pFrameResources[i]); } -bool ImGui_ImplWGPU_Init(WGPUDevice device, int num_frames_in_flight, WGPUTextureFormat rt_format) +bool ImGui_ImplWGPU_Init(WGPUDevice device, int num_frames_in_flight, WGPUTextureFormat rt_format, WGPUTextureFormat depth_format) { - // Setup backend capabilities flags ImGuiIO& io = ImGui::GetIO(); + IM_ASSERT(io.BackendRendererUserData == nullptr && "Already initialized a renderer backend!"); + + // Setup backend capabilities flags + ImGui_ImplWGPU_Data* bd = IM_NEW(ImGui_ImplWGPU_Data)(); + io.BackendRendererUserData = (void*)bd; io.BackendRendererName = "imgui_impl_webgpu"; io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes. - g_wgpuDevice = device; - g_defaultQueue = wgpuDeviceGetQueue(g_wgpuDevice); - g_renderTargetFormat = rt_format; - g_pFrameResources = new FrameResources[num_frames_in_flight]; - g_numFramesInFlight = num_frames_in_flight; - g_frameIndex = UINT_MAX; + bd->wgpuDevice = device; + bd->defaultQueue = wgpuDeviceGetQueue(bd->wgpuDevice); + bd->renderTargetFormat = rt_format; + bd->depthStencilFormat = depth_format; + bd->numFramesInFlight = num_frames_in_flight; + bd->frameIndex = UINT_MAX; - g_resources.FontTexture = NULL; - g_resources.FontTextureView = NULL; - g_resources.Sampler = NULL; - g_resources.Uniforms = NULL; - g_resources.CommonBindGroup = NULL; - g_resources.ImageBindGroups.Data.reserve(100); - g_resources.ImageBindGroup = NULL; - g_resources.ImageBindGroupLayout = NULL; + bd->renderResources.FontTexture = nullptr; + bd->renderResources.FontTextureView = nullptr; + bd->renderResources.Sampler = nullptr; + bd->renderResources.Uniforms = nullptr; + bd->renderResources.CommonBindGroup = nullptr; + bd->renderResources.ImageBindGroups.Data.reserve(100); + bd->renderResources.ImageBindGroup = nullptr; + bd->renderResources.ImageBindGroupLayout = nullptr; // Create buffers with a default size (they will later be grown as needed) + bd->pFrameResources = new FrameResources[num_frames_in_flight]; for (int i = 0; i < num_frames_in_flight; i++) { - FrameResources* fr = &g_pFrameResources[i]; - fr->IndexBuffer = NULL; - fr->VertexBuffer = NULL; - fr->IndexBufferHost = NULL; - fr->VertexBufferHost = NULL; + FrameResources* fr = &bd->pFrameResources[i]; + fr->IndexBuffer = nullptr; + fr->VertexBuffer = nullptr; + fr->IndexBufferHost = nullptr; + fr->VertexBufferHost = nullptr; fr->IndexBufferSize = 10000; fr->VertexBufferSize = 5000; } @@ -703,17 +737,27 @@ bool ImGui_ImplWGPU_Init(WGPUDevice device, int num_frames_in_flight, WGPUTextur void ImGui_ImplWGPU_Shutdown() { + ImGui_ImplWGPU_Data* bd = ImGui_ImplWGPU_GetBackendData(); + IM_ASSERT(bd != nullptr && "No renderer backend to shutdown, or already shutdown?"); + ImGuiIO& io = ImGui::GetIO(); + ImGui_ImplWGPU_InvalidateDeviceObjects(); - delete[] g_pFrameResources; - g_pFrameResources = NULL; - wgpuQueueRelease(g_defaultQueue); - g_wgpuDevice = NULL; - g_numFramesInFlight = 0; - g_frameIndex = UINT_MAX; + delete[] bd->pFrameResources; + bd->pFrameResources = nullptr; + wgpuQueueRelease(bd->defaultQueue); + bd->wgpuDevice = nullptr; + bd->numFramesInFlight = 0; + bd->frameIndex = UINT_MAX; + + io.BackendRendererName = nullptr; + io.BackendRendererUserData = nullptr; + io.BackendFlags &= ~ImGuiBackendFlags_RendererHasVtxOffset; + IM_DELETE(bd); } void ImGui_ImplWGPU_NewFrame() { - if (!g_pipelineState) + ImGui_ImplWGPU_Data* bd = ImGui_ImplWGPU_GetBackendData(); + if (!bd->pipelineState) ImGui_ImplWGPU_CreateDeviceObjects(); } diff --git a/extern/imgui_patched/backends/imgui_impl_wgpu.h b/extern/imgui_patched/backends/imgui_impl_wgpu.h index 8f80acaf..09142078 100644 --- a/extern/imgui_patched/backends/imgui_impl_wgpu.h +++ b/extern/imgui_patched/backends/imgui_impl_wgpu.h @@ -6,7 +6,7 @@ // [X] Renderer: User texture binding. Use 'WGPUTextureView' as ImTextureID. Read the FAQ about ImTextureID! // [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices. -// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. +// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. // If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp. // Read online: https://github.com/ocornut/imgui/tree/master/docs @@ -15,7 +15,7 @@ #include "imgui.h" // IMGUI_IMPL_API #include -IMGUI_IMPL_API bool ImGui_ImplWGPU_Init(WGPUDevice device, int num_frames_in_flight, WGPUTextureFormat rt_format); +IMGUI_IMPL_API bool ImGui_ImplWGPU_Init(WGPUDevice device, int num_frames_in_flight, WGPUTextureFormat rt_format, WGPUTextureFormat depth_format = WGPUTextureFormat_Undefined); IMGUI_IMPL_API void ImGui_ImplWGPU_Shutdown(); IMGUI_IMPL_API void ImGui_ImplWGPU_NewFrame(); IMGUI_IMPL_API void ImGui_ImplWGPU_RenderDrawData(ImDrawData* draw_data, WGPURenderPassEncoder pass_encoder); diff --git a/extern/imgui_patched/backends/imgui_impl_win32.cpp b/extern/imgui_patched/backends/imgui_impl_win32.cpp index 89ef37a2..d24c655d 100644 --- a/extern/imgui_patched/backends/imgui_impl_win32.cpp +++ b/extern/imgui_patched/backends/imgui_impl_win32.cpp @@ -1,8 +1,9 @@ -// dear imgui: Platform Backend for Windows (standard windows API for 32 and 64 bits applications) +// dear imgui: Platform Backend for Windows (standard windows API for 32-bits AND 64-bits applications) // This needs to be used along with a Renderer (e.g. DirectX11, OpenGL3, Vulkan..) // Implemented features: // [X] Platform: Clipboard support (for Win32 this is actually part of core dear imgui) +// [X] Platform: Mouse support. Can discriminate Mouse/TouchScreen/Pen. // [X] Platform: Keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(ImGuiKey_Space). [Legacy VK_* values will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set] // [X] Platform: Gamepad support. Enabled with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'. // [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'. @@ -35,8 +36,15 @@ typedef DWORD (WINAPI *PFN_XInputGetState)(DWORD, XINPUT_STATE*); // CHANGELOG // (minor and older changes stripped away, please see git history for details) -// 2022-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface. -// 2022-01-26: Inputs: replaced short-lived io.AddKeyModsEvent() (added two weeks ago)with io.AddKeyEvent() using ImGuiKey_ModXXX flags. Sorry for the confusion. +// 2023-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface. +// 2023-04-19: Added ImGui_ImplWin32_InitForOpenGL() to facilitate combining raw Win32/Winapi with OpenGL. (#3218) +// 2023-04-04: Inputs: Added support for io.AddMouseSourceEvent() to discriminate ImGuiMouseSource_Mouse/ImGuiMouseSource_TouchScreen/ImGuiMouseSource_Pen. (#2702) +// 2023-02-15: Inputs: Use WM_NCMOUSEMOVE / WM_NCMOUSELEAVE to track mouse position over non-client area (e.g. OS decorations) when app is not focused. (#6045, #6162) +// 2023-02-02: Inputs: Flipping WM_MOUSEHWHEEL (horizontal mouse-wheel) value to match other backends and offer consistent horizontal scrolling direction. (#4019, #6096, #1463) +// 2022-10-11: Using 'nullptr' instead of 'NULL' as per our switch to C++11. +// 2022-09-28: Inputs: Convert WM_CHAR values with MultiByteToWideChar() when window class was registered as MBCS (not Unicode). +// 2022-09-26: Inputs: Renamed ImGuiKey_ModXXX introduced in 1.87 to ImGuiMod_XXX (old names still supported). +// 2022-01-26: Inputs: replaced short-lived io.AddKeyModsEvent() (added two weeks ago) with io.AddKeyEvent() using ImGuiKey_ModXXX flags. Sorry for the confusion. // 2021-01-20: Inputs: calling new io.AddKeyAnalogEvent() for gamepad support, instead of writing directly to io.NavInputs[]. // 2022-01-17: Inputs: calling new io.AddMousePosEvent(), io.AddMouseButtonEvent(), io.AddMouseWheelEvent() API (1.87+). // 2022-01-17: Inputs: always update key mods next and before a key event (not in NewFrame) to fix input queue with very low framerates. @@ -76,10 +84,10 @@ typedef DWORD (WINAPI *PFN_XInputGetState)(DWORD, XINPUT_STATE*); // 2018-01-05: Inputs: Added WM_LBUTTONDBLCLK double-click handlers for window classes with the CS_DBLCLKS flag. // 2017-10-23: Inputs: Added WM_SYSKEYDOWN / WM_SYSKEYUP handlers so e.g. the VK_MENU key can be read. // 2017-10-23: Inputs: Using Win32 ::SetCapture/::GetCapture() to retrieve mouse positions outside the client area when dragging. -// 2016-11-12: Inputs: Only call Win32 ::SetCursor(NULL) when io.MouseDrawCursor is set. +// 2016-11-12: Inputs: Only call Win32 ::SetCursor(nullptr) when io.MouseDrawCursor is set. // Forward Declarations -static void ImGui_ImplWin32_InitPlatformInterface(); +static void ImGui_ImplWin32_InitPlatformInterface(bool platformHasOwnDC); static void ImGui_ImplWin32_ShutdownPlatformInterface(); static void ImGui_ImplWin32_UpdateMonitors(); @@ -87,16 +95,16 @@ struct ImGui_ImplWin32_Data { HWND hWnd; HWND MouseHwnd; - bool MouseTracked; + int MouseTrackedArea; // 0: not tracked, 1: client are, 2: non-client area int MouseButtonsDown; INT64 Time; INT64 TicksPerSecond; ImGuiMouseCursor LastMouseCursor; - bool HasGamepad; - bool WantUpdateHasGamepad; bool WantUpdateMonitors; #ifndef IMGUI_IMPL_WIN32_DISABLE_GAMEPAD + bool HasGamepad; + bool WantUpdateHasGamepad; HMODULE XInputDLL; PFN_XInputGetCapabilities XInputGetCapabilities; PFN_XInputGetState XInputGetState; @@ -111,14 +119,14 @@ struct ImGui_ImplWin32_Data // FIXME: some shared resources (mouse cursor shape, gamepad) are mishandled when using multi-context. static ImGui_ImplWin32_Data* ImGui_ImplWin32_GetBackendData() { - return ImGui::GetCurrentContext() ? (ImGui_ImplWin32_Data*)ImGui::GetIO().BackendPlatformUserData : NULL; + return ImGui::GetCurrentContext() ? (ImGui_ImplWin32_Data*)ImGui::GetIO().BackendPlatformUserData : nullptr; } // Functions -bool ImGui_ImplWin32_Init(void* hwnd) +static bool ImGui_ImplWin32_InitEx(void* hwnd, bool platform_has_own_dc) { ImGuiIO& io = ImGui::GetIO(); - IM_ASSERT(io.BackendPlatformUserData == NULL && "Already initialized a platform backend!"); + IM_ASSERT(io.BackendPlatformUserData == nullptr && "Already initialized a platform backend!"); INT64 perf_frequency, perf_counter; if (!::QueryPerformanceFrequency((LARGE_INTEGER*)&perf_frequency)) @@ -136,7 +144,6 @@ bool ImGui_ImplWin32_Init(void* hwnd) io.BackendFlags |= ImGuiBackendFlags_HasMouseHoveredViewport; // We can call io.AddMouseViewportEvent() with correct data (optional) bd->hWnd = (HWND)hwnd; - bd->WantUpdateHasGamepad = true; bd->WantUpdateMonitors = true; bd->TicksPerSecond = perf_frequency; bd->Time = perf_counter; @@ -146,10 +153,11 @@ bool ImGui_ImplWin32_Init(void* hwnd) ImGuiViewport* main_viewport = ImGui::GetMainViewport(); main_viewport->PlatformHandle = main_viewport->PlatformHandleRaw = (void*)bd->hWnd; if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) - ImGui_ImplWin32_InitPlatformInterface(); + ImGui_ImplWin32_InitPlatformInterface(platform_has_own_dc); // Dynamically load XInput library #ifndef IMGUI_IMPL_WIN32_DISABLE_GAMEPAD + bd->WantUpdateHasGamepad = true; const char* xinput_dll_names[] = { "xinput1_4.dll", // Windows 8+ @@ -171,10 +179,21 @@ bool ImGui_ImplWin32_Init(void* hwnd) return true; } +IMGUI_IMPL_API bool ImGui_ImplWin32_Init(void* hwnd) +{ + return ImGui_ImplWin32_InitEx(hwnd, false); +} + +IMGUI_IMPL_API bool ImGui_ImplWin32_InitForOpenGL(void* hwnd) +{ + // OpenGL needs CS_OWNDC + return ImGui_ImplWin32_InitEx(hwnd, true); +} + void ImGui_ImplWin32_Shutdown() { ImGui_ImplWin32_Data* bd = ImGui_ImplWin32_GetBackendData(); - IM_ASSERT(bd != NULL && "No platform backend to shutdown, or already shutdown?"); + IM_ASSERT(bd != nullptr && "No platform backend to shutdown, or already shutdown?"); ImGuiIO& io = ImGui::GetIO(); ImGui_ImplWin32_ShutdownPlatformInterface(); @@ -185,8 +204,9 @@ void ImGui_ImplWin32_Shutdown() ::FreeLibrary(bd->XInputDLL); #endif // IMGUI_IMPL_WIN32_DISABLE_GAMEPAD - io.BackendPlatformName = NULL; - io.BackendPlatformUserData = NULL; + io.BackendPlatformName = nullptr; + io.BackendPlatformUserData = nullptr; + io.BackendFlags &= ~(ImGuiBackendFlags_HasMouseCursors | ImGuiBackendFlags_HasSetMousePos | ImGuiBackendFlags_HasGamepad | ImGuiBackendFlags_PlatformHasViewports | ImGuiBackendFlags_HasMouseHoveredViewport); IM_DELETE(bd); } @@ -200,7 +220,7 @@ static bool ImGui_ImplWin32_UpdateMouseCursor() if (imgui_cursor == ImGuiMouseCursor_None || io.MouseDrawCursor) { // Hide OS mouse cursor if imgui is drawing it or if it wants no cursor - ::SetCursor(NULL); + ::SetCursor(nullptr); } else { @@ -218,7 +238,7 @@ static bool ImGui_ImplWin32_UpdateMouseCursor() case ImGuiMouseCursor_Hand: win32_cursor = IDC_HAND; break; case ImGuiMouseCursor_NotAllowed: win32_cursor = IDC_NO; break; } - ::SetCursor(::LoadCursor(NULL, win32_cursor)); + ::SetCursor(::LoadCursor(nullptr, win32_cursor)); } return true; } @@ -254,10 +274,10 @@ static void ImGui_ImplWin32_ProcessKeyEventsWorkarounds() static void ImGui_ImplWin32_UpdateKeyModifiers() { ImGuiIO& io = ImGui::GetIO(); - io.AddKeyEvent(ImGuiKey_ModCtrl, IsVkDown(VK_CONTROL)); - io.AddKeyEvent(ImGuiKey_ModShift, IsVkDown(VK_SHIFT)); - io.AddKeyEvent(ImGuiKey_ModAlt, IsVkDown(VK_MENU)); - io.AddKeyEvent(ImGuiKey_ModSuper, IsVkDown(VK_APPS)); + io.AddKeyEvent(ImGuiMod_Ctrl, IsVkDown(VK_CONTROL)); + io.AddKeyEvent(ImGuiMod_Shift, IsVkDown(VK_SHIFT)); + io.AddKeyEvent(ImGuiMod_Alt, IsVkDown(VK_MENU)); + io.AddKeyEvent(ImGuiMod_Super, IsVkDown(VK_APPS)); } // This code supports multi-viewports (multiple OS Windows mapped into different Dear ImGui viewports) @@ -286,7 +306,8 @@ static void ImGui_ImplWin32_UpdateMouseData() } // (Optional) Fallback to provide mouse position when focused (WM_MOUSEMOVE already provides this when hovered or captured) - if (!io.WantSetMousePos && !bd->MouseTracked && has_mouse_screen_pos) + // This also fills a short gap when clicking non-client area: WM_NCMOUSELEAVE -> modal OS move -> gap -> WM_NCMOUSEMOVE + if (!io.WantSetMousePos && bd->MouseTrackedArea == 0 && has_mouse_screen_pos) { // Single viewport mode: mouse position in client window coordinates (io.MousePos is (0,0) when the mouse is on the upper-left corner of the app window) // (This is the position you can get with ::GetCursorPos() + ::ScreenToClient() or WM_MOUSEMOVE.) @@ -320,8 +341,8 @@ static void ImGui_ImplWin32_UpdateGamepads() #ifndef IMGUI_IMPL_WIN32_DISABLE_GAMEPAD ImGuiIO& io = ImGui::GetIO(); ImGui_ImplWin32_Data* bd = ImGui_ImplWin32_GetBackendData(); - if ((io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) == 0) - return; + //if ((io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) == 0) // FIXME: Technically feeding gamepad shouldn't depend on this now that they are regular inputs. + // return; // Calling XInputGetState() every frame on disconnected gamepads is unfortunately too slow. // Instead we refresh gamepad availability by calling XInputGetCapabilities() _only_ after receiving WM_DEVICECHANGE. @@ -335,7 +356,7 @@ static void ImGui_ImplWin32_UpdateGamepads() io.BackendFlags &= ~ImGuiBackendFlags_HasGamepad; XINPUT_STATE xinput_state; XINPUT_GAMEPAD& gamepad = xinput_state.Gamepad; - if (!bd->HasGamepad || bd->XInputGetState == NULL || bd->XInputGetState(0, &xinput_state) != ERROR_SUCCESS) + if (!bd->HasGamepad || bd->XInputGetState == nullptr || bd->XInputGetState(0, &xinput_state) != ERROR_SUCCESS) return; io.BackendFlags |= ImGuiBackendFlags_HasGamepad; @@ -344,10 +365,10 @@ static void ImGui_ImplWin32_UpdateGamepads() #define MAP_ANALOG(KEY_NO, VALUE, V0, V1) { float vn = (float)(VALUE - V0) / (float)(V1 - V0); io.AddKeyAnalogEvent(KEY_NO, vn > 0.10f, IM_SATURATE(vn)); } MAP_BUTTON(ImGuiKey_GamepadStart, XINPUT_GAMEPAD_START); MAP_BUTTON(ImGuiKey_GamepadBack, XINPUT_GAMEPAD_BACK); - MAP_BUTTON(ImGuiKey_GamepadFaceDown, XINPUT_GAMEPAD_A); - MAP_BUTTON(ImGuiKey_GamepadFaceRight, XINPUT_GAMEPAD_B); MAP_BUTTON(ImGuiKey_GamepadFaceLeft, XINPUT_GAMEPAD_X); + MAP_BUTTON(ImGuiKey_GamepadFaceRight, XINPUT_GAMEPAD_B); MAP_BUTTON(ImGuiKey_GamepadFaceUp, XINPUT_GAMEPAD_Y); + MAP_BUTTON(ImGuiKey_GamepadFaceDown, XINPUT_GAMEPAD_A); MAP_BUTTON(ImGuiKey_GamepadDpadLeft, XINPUT_GAMEPAD_DPAD_LEFT); MAP_BUTTON(ImGuiKey_GamepadDpadRight, XINPUT_GAMEPAD_DPAD_RIGHT); MAP_BUTTON(ImGuiKey_GamepadDpadUp, XINPUT_GAMEPAD_DPAD_UP); @@ -383,6 +404,7 @@ static BOOL CALLBACK ImGui_ImplWin32_UpdateMonitors_EnumFunc(HMONITOR monitor, H imgui_monitor.WorkPos = ImVec2((float)info.rcWork.left, (float)info.rcWork.top); imgui_monitor.WorkSize = ImVec2((float)(info.rcWork.right - info.rcWork.left), (float)(info.rcWork.bottom - info.rcWork.top)); imgui_monitor.DpiScale = ImGui_ImplWin32_GetDpiScaleForMonitor(monitor); + imgui_monitor.PlatformHandle = (void*)monitor; ImGuiPlatformIO& io = ImGui::GetPlatformIO(); if (info.dwFlags & MONITORINFOF_PRIMARY) io.Monitors.push_front(imgui_monitor); @@ -395,7 +417,7 @@ static void ImGui_ImplWin32_UpdateMonitors() { ImGui_ImplWin32_Data* bd = ImGui_ImplWin32_GetBackendData(); ImGui::GetPlatformIO().Monitors.resize(0); - ::EnumDisplayMonitors(NULL, NULL, ImGui_ImplWin32_UpdateMonitors_EnumFunc, 0); + ::EnumDisplayMonitors(nullptr, nullptr, ImGui_ImplWin32_UpdateMonitors_EnumFunc, 0); bd->WantUpdateMonitors = false; } @@ -403,7 +425,7 @@ void ImGui_ImplWin32_NewFrame() { ImGuiIO& io = ImGui::GetIO(); ImGui_ImplWin32_Data* bd = ImGui_ImplWin32_GetBackendData(); - IM_ASSERT(bd != NULL && "Did you call ImGui_ImplWin32_Init()?"); + IM_ASSERT(bd != nullptr && "Did you call ImGui_ImplWin32_Init()?"); // Setup display size (every frame to accommodate for window resizing) RECT rect = { 0, 0, 0, 0 }; @@ -572,9 +594,22 @@ static ImGuiKey ImGui_ImplWin32_VirtualKeyToImGuiKey(WPARAM wParam) // Copy this line into your .cpp file to forward declare the function. extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); #endif + +// See https://learn.microsoft.com/en-us/windows/win32/tablet/system-events-and-mouse-messages +// Prefer to call this at the top of the message handler to avoid the possibility of other Win32 calls interfering with this. +static ImGuiMouseSource GetMouseSourceFromMessageExtraInfo() +{ + LPARAM extra_info = ::GetMessageExtraInfo(); + if ((extra_info & 0xFFFFFF80) == 0xFF515700) + return ImGuiMouseSource_Pen; + if ((extra_info & 0xFFFFFF80) == 0xFF515780) + return ImGuiMouseSource_TouchScreen; + return ImGuiMouseSource_Mouse; +} + IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { - if (ImGui::GetCurrentContext() == NULL) + if (ImGui::GetCurrentContext() == nullptr) return 0; ImGuiIO& io = ImGui::GetIO(); @@ -583,40 +618,59 @@ IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hwnd, UINT msg, WPARA switch (msg) { case WM_MOUSEMOVE: + case WM_NCMOUSEMOVE: { // We need to call TrackMouseEvent in order to receive WM_MOUSELEAVE events + ImGuiMouseSource mouse_source = GetMouseSourceFromMessageExtraInfo(); + const int area = (msg == WM_MOUSEMOVE) ? 1 : 2; bd->MouseHwnd = hwnd; - if (!bd->MouseTracked) + if (bd->MouseTrackedArea != area) { - TRACKMOUSEEVENT tme = { sizeof(tme), TME_LEAVE, hwnd, 0 }; - ::TrackMouseEvent(&tme); - bd->MouseTracked = true; + TRACKMOUSEEVENT tme_cancel = { sizeof(tme_cancel), TME_CANCEL, hwnd, 0 }; + TRACKMOUSEEVENT tme_track = { sizeof(tme_track), (DWORD)((area == 2) ? (TME_LEAVE | TME_NONCLIENT) : TME_LEAVE), hwnd, 0 }; + if (bd->MouseTrackedArea != 0) + ::TrackMouseEvent(&tme_cancel); + ::TrackMouseEvent(&tme_track); + bd->MouseTrackedArea = area; } POINT mouse_pos = { (LONG)GET_X_LPARAM(lParam), (LONG)GET_Y_LPARAM(lParam) }; - if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) + bool want_absolute_pos = (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) != 0; + if (msg == WM_MOUSEMOVE && want_absolute_pos) // WM_MOUSEMOVE are client-relative coordinates. ::ClientToScreen(hwnd, &mouse_pos); + if (msg == WM_NCMOUSEMOVE && !want_absolute_pos) // WM_NCMOUSEMOVE are absolute coordinates. + ::ScreenToClient(hwnd, &mouse_pos); + io.AddMouseSourceEvent(mouse_source); io.AddMousePosEvent((float)mouse_pos.x, (float)mouse_pos.y); break; } case WM_MOUSELEAVE: - if (bd->MouseHwnd == hwnd) - bd->MouseHwnd = NULL; - bd->MouseTracked = false; - io.AddMousePosEvent(-FLT_MAX, -FLT_MAX); + case WM_NCMOUSELEAVE: + { + const int area = (msg == WM_MOUSELEAVE) ? 1 : 2; + if (bd->MouseTrackedArea == area) + { + if (bd->MouseHwnd == hwnd) + bd->MouseHwnd = nullptr; + bd->MouseTrackedArea = 0; + io.AddMousePosEvent(-FLT_MAX, -FLT_MAX); + } break; + } case WM_LBUTTONDOWN: case WM_LBUTTONDBLCLK: case WM_RBUTTONDOWN: case WM_RBUTTONDBLCLK: case WM_MBUTTONDOWN: case WM_MBUTTONDBLCLK: case WM_XBUTTONDOWN: case WM_XBUTTONDBLCLK: { + ImGuiMouseSource mouse_source = GetMouseSourceFromMessageExtraInfo(); int button = 0; if (msg == WM_LBUTTONDOWN || msg == WM_LBUTTONDBLCLK) { button = 0; } if (msg == WM_RBUTTONDOWN || msg == WM_RBUTTONDBLCLK) { button = 1; } if (msg == WM_MBUTTONDOWN || msg == WM_MBUTTONDBLCLK) { button = 2; } if (msg == WM_XBUTTONDOWN || msg == WM_XBUTTONDBLCLK) { button = (GET_XBUTTON_WPARAM(wParam) == XBUTTON1) ? 3 : 4; } - if (bd->MouseButtonsDown == 0 && ::GetCapture() == NULL) + if (bd->MouseButtonsDown == 0 && ::GetCapture() == nullptr) ::SetCapture(hwnd); bd->MouseButtonsDown |= 1 << button; + io.AddMouseSourceEvent(mouse_source); io.AddMouseButtonEvent(button, true); return 0; } @@ -625,6 +679,7 @@ IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hwnd, UINT msg, WPARA case WM_MBUTTONUP: case WM_XBUTTONUP: { + ImGuiMouseSource mouse_source = GetMouseSourceFromMessageExtraInfo(); int button = 0; if (msg == WM_LBUTTONUP) { button = 0; } if (msg == WM_RBUTTONUP) { button = 1; } @@ -633,6 +688,7 @@ IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hwnd, UINT msg, WPARA bd->MouseButtonsDown &= ~(1 << button); if (bd->MouseButtonsDown == 0 && ::GetCapture() == hwnd) ::ReleaseCapture(); + io.AddMouseSourceEvent(mouse_source); io.AddMouseButtonEvent(button, false); return 0; } @@ -640,7 +696,7 @@ IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hwnd, UINT msg, WPARA io.AddMouseWheelEvent(0.0f, (float)GET_WHEEL_DELTA_WPARAM(wParam) / (float)WHEEL_DELTA); return 0; case WM_MOUSEHWHEEL: - io.AddMouseWheelEvent((float)GET_WHEEL_DELTA_WPARAM(wParam) / (float)WHEEL_DELTA, 0.0f); + io.AddMouseWheelEvent(-(float)GET_WHEEL_DELTA_WPARAM(wParam) / (float)WHEEL_DELTA, 0.0f); return 0; case WM_KEYDOWN: case WM_KEYUP: @@ -690,17 +746,29 @@ IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hwnd, UINT msg, WPARA io.AddFocusEvent(msg == WM_SETFOCUS); return 0; case WM_CHAR: - // You can also use ToAscii()+GetKeyboardState() to retrieve characters. - if (wParam > 0 && wParam < 0x10000) - io.AddInputCharacterUTF16((unsigned short)wParam); + if (::IsWindowUnicode(hwnd)) + { + // You can also use ToAscii()+GetKeyboardState() to retrieve characters. + if (wParam > 0 && wParam < 0x10000) + io.AddInputCharacterUTF16((unsigned short)wParam); + } + else + { + wchar_t wch = 0; + ::MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, (char*)&wParam, 1, &wch, 1); + io.AddInputCharacter(wch); + } return 0; case WM_SETCURSOR: + // This is required to restore cursor when transitioning from e.g resize borders to client area. if (LOWORD(lParam) == HTCLIENT && ImGui_ImplWin32_UpdateMouseCursor()) return 1; return 0; case WM_DEVICECHANGE: +#ifndef IMGUI_IMPL_WIN32_DISABLE_GAMEPAD if ((UINT)wParam == DBT_DEVNODES_CHANGED) bd->WantUpdateHasGamepad = true; +#endif return 0; case WM_DISPLAYCHANGE: bd->WantUpdateMonitors = true; @@ -729,11 +797,11 @@ IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hwnd, UINT msg, WPARA static BOOL _IsWindowsVersionOrGreater(WORD major, WORD minor, WORD) { typedef LONG(WINAPI* PFN_RtlVerifyVersionInfo)(OSVERSIONINFOEXW*, ULONG, ULONGLONG); - static PFN_RtlVerifyVersionInfo RtlVerifyVersionInfoFn = NULL; - if (RtlVerifyVersionInfoFn == NULL) + static PFN_RtlVerifyVersionInfo RtlVerifyVersionInfoFn = nullptr; + if (RtlVerifyVersionInfoFn == nullptr) if (HMODULE ntdllModule = ::GetModuleHandleA("ntdll.dll")) RtlVerifyVersionInfoFn = (PFN_RtlVerifyVersionInfo)GetProcAddress(ntdllModule, "RtlVerifyVersionInfo"); - if (RtlVerifyVersionInfoFn == NULL) + if (RtlVerifyVersionInfoFn == nullptr) return FALSE; RTL_OSVERSIONINFOEXW versionInfo = { }; @@ -806,10 +874,10 @@ float ImGui_ImplWin32_GetDpiScaleForMonitor(void* monitor) if (_IsWindows8Point1OrGreater()) { static HINSTANCE shcore_dll = ::LoadLibraryA("shcore.dll"); // Reference counted per-process - static PFN_GetDpiForMonitor GetDpiForMonitorFn = NULL; - if (GetDpiForMonitorFn == NULL && shcore_dll != NULL) + static PFN_GetDpiForMonitor GetDpiForMonitorFn = nullptr; + if (GetDpiForMonitorFn == nullptr && shcore_dll != nullptr) GetDpiForMonitorFn = (PFN_GetDpiForMonitor)::GetProcAddress(shcore_dll, "GetDpiForMonitor"); - if (GetDpiForMonitorFn != NULL) + if (GetDpiForMonitorFn != nullptr) { GetDpiForMonitorFn((HMONITOR)monitor, MDT_EFFECTIVE_DPI, &xdpi, &ydpi); IM_ASSERT(xdpi == ydpi); // Please contact me if you hit this assert! @@ -817,11 +885,11 @@ float ImGui_ImplWin32_GetDpiScaleForMonitor(void* monitor) } } #ifndef NOGDI - const HDC dc = ::GetDC(NULL); + const HDC dc = ::GetDC(nullptr); xdpi = ::GetDeviceCaps(dc, LOGPIXELSX); ydpi = ::GetDeviceCaps(dc, LOGPIXELSY); IM_ASSERT(xdpi == ydpi); // Please contact me if you hit this assert! - ::ReleaseDC(NULL, dc); + ::ReleaseDC(nullptr, dc); #endif return xdpi / 96.0f; } @@ -832,13 +900,53 @@ float ImGui_ImplWin32_GetDpiScaleForHwnd(void* hwnd) return ImGui_ImplWin32_GetDpiScaleForMonitor(monitor); } +//--------------------------------------------------------------------------------------------------------- +// Transparency related helpers (optional) //-------------------------------------------------------------------------------------------------------- + +#if defined(_MSC_VER) +#pragma comment(lib, "dwmapi") // Link with dwmapi.lib. MinGW will require linking with '-ldwmapi' +#endif + +// [experimental] +// Borrowed from GLFW's function updateFramebufferTransparency() in src/win32_window.c +// (the Dwm* functions are Vista era functions but we are borrowing logic from GLFW) +void ImGui_ImplWin32_EnableAlphaCompositing(void* hwnd) +{ + if (!_IsWindowsVistaOrGreater()) + return; + + BOOL composition; + if (FAILED(::DwmIsCompositionEnabled(&composition)) || !composition) + return; + + BOOL opaque; + DWORD color; + if (_IsWindows8OrGreater() || (SUCCEEDED(::DwmGetColorizationColor(&color, &opaque)) && !opaque)) + { + HRGN region = ::CreateRectRgn(0, 0, -1, -1); + DWM_BLURBEHIND bb = {}; + bb.dwFlags = DWM_BB_ENABLE | DWM_BB_BLURREGION; + bb.hRgnBlur = region; + bb.fEnable = TRUE; + ::DwmEnableBlurBehindWindow((HWND)hwnd, &bb); + ::DeleteObject(region); + } + else + { + DWM_BLURBEHIND bb = {}; + bb.dwFlags = DWM_BB_ENABLE; + ::DwmEnableBlurBehindWindow((HWND)hwnd, &bb); + } +} + +//--------------------------------------------------------------------------------------------------------- // MULTI-VIEWPORT / PLATFORM INTERFACE SUPPORT // This is an _advanced_ and _optional_ feature, allowing the backend to create and handle multiple viewports simultaneously. // If you are new to dear imgui or creating a new binding for dear imgui, it is recommended that you completely ignore this section first.. //-------------------------------------------------------------------------------------------------------- -// Helper structure we store in the void* RenderUserData field of each ImGuiViewport to easily retrieve our backend data. +// Helper structure we store in the void* RendererUserData field of each ImGuiViewport to easily retrieve our backend data. struct ImGui_ImplWin32_ViewportData { HWND Hwnd; @@ -846,8 +954,8 @@ struct ImGui_ImplWin32_ViewportData DWORD DwStyle; DWORD DwExStyle; - ImGui_ImplWin32_ViewportData() { Hwnd = NULL; HwndOwned = false; DwStyle = DwExStyle = 0; } - ~ImGui_ImplWin32_ViewportData() { IM_ASSERT(Hwnd == NULL); } + ImGui_ImplWin32_ViewportData() { Hwnd = nullptr; HwndOwned = false; DwStyle = DwExStyle = 0; } + ~ImGui_ImplWin32_ViewportData() { IM_ASSERT(Hwnd == nullptr); } }; static void ImGui_ImplWin32_GetWin32StyleFromViewportFlags(ImGuiViewportFlags flags, DWORD* out_style, DWORD* out_ex_style) @@ -873,7 +981,7 @@ static void ImGui_ImplWin32_CreateWindow(ImGuiViewport* viewport) // Select style and parent window ImGui_ImplWin32_GetWin32StyleFromViewportFlags(viewport->Flags, &vd->DwStyle, &vd->DwExStyle); - HWND parent_window = NULL; + HWND parent_window = nullptr; if (viewport->ParentViewportId != 0) if (ImGuiViewport* parent_viewport = ImGui::FindViewportByID(viewport->ParentViewportId)) parent_window = (HWND)parent_viewport->PlatformHandle; @@ -882,9 +990,9 @@ static void ImGui_ImplWin32_CreateWindow(ImGuiViewport* viewport) RECT rect = { (LONG)viewport->Pos.x, (LONG)viewport->Pos.y, (LONG)(viewport->Pos.x + viewport->Size.x), (LONG)(viewport->Pos.y + viewport->Size.y) }; ::AdjustWindowRectEx(&rect, vd->DwStyle, FALSE, vd->DwExStyle); vd->Hwnd = ::CreateWindowEx( - vd->DwExStyle, _T("ImGui Platform"), _T("Untitled"), vd->DwStyle, // Style, class name, window name + vd->DwExStyle, _T("ImGui Platform"), _T("Untitled"), vd->DwStyle, // Style, class name, window name rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, // Window area - parent_window, NULL, ::GetModuleHandle(NULL), NULL); // Parent window, Menu, Instance, Param + parent_window, nullptr, ::GetModuleHandle(nullptr), nullptr); // Parent window, Menu, Instance, Param vd->HwndOwned = true; viewport->PlatformRequestResize = false; viewport->PlatformHandle = viewport->PlatformHandleRaw = vd->Hwnd; @@ -903,10 +1011,10 @@ static void ImGui_ImplWin32_DestroyWindow(ImGuiViewport* viewport) } if (vd->Hwnd && vd->HwndOwned) ::DestroyWindow(vd->Hwnd); - vd->Hwnd = NULL; + vd->Hwnd = nullptr; IM_DELETE(vd); } - viewport->PlatformUserData = viewport->PlatformHandle = NULL; + viewport->PlatformUserData = viewport->PlatformHandle = nullptr; } static void ImGui_ImplWin32_ShowWindow(ImGuiViewport* viewport) @@ -965,7 +1073,7 @@ static void ImGui_ImplWin32_SetWindowPos(ImGuiViewport* viewport, ImVec2 pos) IM_ASSERT(vd->Hwnd != 0); RECT rect = { (LONG)pos.x, (LONG)pos.y, (LONG)pos.x, (LONG)pos.y }; ::AdjustWindowRectEx(&rect, vd->DwStyle, FALSE, vd->DwExStyle); - ::SetWindowPos(vd->Hwnd, NULL, rect.left, rect.top, 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE); + ::SetWindowPos(vd->Hwnd, nullptr, rect.left, rect.top, 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE); } static ImVec2 ImGui_ImplWin32_GetWindowSize(ImGuiViewport* viewport) @@ -983,7 +1091,7 @@ static void ImGui_ImplWin32_SetWindowSize(ImGuiViewport* viewport, ImVec2 size) IM_ASSERT(vd->Hwnd != 0); RECT rect = { 0, 0, (LONG)size.x, (LONG)size.y }; ::AdjustWindowRectEx(&rect, vd->DwStyle, FALSE, vd->DwExStyle); // Client to Screen - ::SetWindowPos(vd->Hwnd, NULL, 0, 0, rect.right - rect.left, rect.bottom - rect.top, SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE); + ::SetWindowPos(vd->Hwnd, nullptr, 0, 0, rect.right - rect.left, rect.bottom - rect.top, SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE); } static void ImGui_ImplWin32_SetWindowFocus(ImGuiViewport* viewport) @@ -1014,7 +1122,7 @@ static void ImGui_ImplWin32_SetWindowTitle(ImGuiViewport* viewport, const char* // ::SetWindowTextA() doesn't properly handle UTF-8 so we explicitely convert our string. ImGui_ImplWin32_ViewportData* vd = (ImGui_ImplWin32_ViewportData*)viewport->PlatformUserData; IM_ASSERT(vd->Hwnd != 0); - int n = ::MultiByteToWideChar(CP_UTF8, 0, title, -1, NULL, 0); + int n = ::MultiByteToWideChar(CP_UTF8, 0, title, -1, nullptr, 0); ImVector title_w; title_w.resize(n); ::MultiByteToWideChar(CP_UTF8, 0, title, -1, title_w.Data, n); @@ -1098,21 +1206,21 @@ static LRESULT CALLBACK ImGui_ImplWin32_WndProcHandler_PlatformWindow(HWND hWnd, return DefWindowProc(hWnd, msg, wParam, lParam); } -static void ImGui_ImplWin32_InitPlatformInterface() +static void ImGui_ImplWin32_InitPlatformInterface(bool platform_has_own_dc) { WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX); - wcex.style = CS_HREDRAW | CS_VREDRAW; + wcex.style = CS_HREDRAW | CS_VREDRAW | (platform_has_own_dc ? CS_OWNDC : 0); wcex.lpfnWndProc = ImGui_ImplWin32_WndProcHandler_PlatformWindow; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; - wcex.hInstance = ::GetModuleHandle(NULL); - wcex.hIcon = NULL; - wcex.hCursor = NULL; + wcex.hInstance = ::GetModuleHandle(nullptr); + wcex.hIcon = nullptr; + wcex.hCursor = nullptr; wcex.hbrBackground = (HBRUSH)(COLOR_BACKGROUND + 1); - wcex.lpszMenuName = NULL; + wcex.lpszMenuName = nullptr; wcex.lpszClassName = _T("ImGui Platform"); - wcex.hIconSm = NULL; + wcex.hIconSm = nullptr; ::RegisterClassEx(&wcex); ImGui_ImplWin32_UpdateMonitors(); @@ -1148,48 +1256,8 @@ static void ImGui_ImplWin32_InitPlatformInterface() static void ImGui_ImplWin32_ShutdownPlatformInterface() { - ::UnregisterClass(_T("ImGui Platform"), ::GetModuleHandle(NULL)); + ::UnregisterClass(_T("ImGui Platform"), ::GetModuleHandle(nullptr)); ImGui::DestroyPlatformWindows(); } //--------------------------------------------------------------------------------------------------------- -// Transparency related helpers (optional) -//-------------------------------------------------------------------------------------------------------- - -#if defined(_MSC_VER) -#pragma comment(lib, "dwmapi") // Link with dwmapi.lib. MinGW will require linking with '-ldwmapi' -#endif - -// [experimental] -// Borrowed from GLFW's function updateFramebufferTransparency() in src/win32_window.c -// (the Dwm* functions are Vista era functions but we are borrowing logic from GLFW) -void ImGui_ImplWin32_EnableAlphaCompositing(void* hwnd) -{ - if (!_IsWindowsVistaOrGreater()) - return; - - BOOL composition; - if (FAILED(::DwmIsCompositionEnabled(&composition)) || !composition) - return; - - BOOL opaque; - DWORD color; - if (_IsWindows8OrGreater() || (SUCCEEDED(::DwmGetColorizationColor(&color, &opaque)) && !opaque)) - { - HRGN region = ::CreateRectRgn(0, 0, -1, -1); - DWM_BLURBEHIND bb = {}; - bb.dwFlags = DWM_BB_ENABLE | DWM_BB_BLURREGION; - bb.hRgnBlur = region; - bb.fEnable = TRUE; - ::DwmEnableBlurBehindWindow((HWND)hwnd, &bb); - ::DeleteObject(region); - } - else - { - DWM_BLURBEHIND bb = {}; - bb.dwFlags = DWM_BB_ENABLE; - ::DwmEnableBlurBehindWindow((HWND)hwnd, &bb); - } -} - -//--------------------------------------------------------------------------------------------------------- diff --git a/extern/imgui_patched/backends/imgui_impl_win32.h b/extern/imgui_patched/backends/imgui_impl_win32.h index 3778c322..5f720cda 100644 --- a/extern/imgui_patched/backends/imgui_impl_win32.h +++ b/extern/imgui_patched/backends/imgui_impl_win32.h @@ -1,8 +1,9 @@ -// dear imgui: Platform Backend for Windows (standard windows API for 32 and 64 bits applications) +// dear imgui: Platform Backend for Windows (standard windows API for 32-bits AND 64-bits applications) // This needs to be used along with a Renderer (e.g. DirectX11, OpenGL3, Vulkan..) // Implemented features: // [X] Platform: Clipboard support (for Win32 this is actually part of core dear imgui) +// [X] Platform: Mouse support. Can discriminate Mouse/TouchScreen/Pen. // [X] Platform: Keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(ImGuiKey_Space). [Legacy VK_* values will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set] // [X] Platform: Gamepad support. Enabled with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'. // [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'. @@ -17,6 +18,7 @@ #include "imgui.h" // IMGUI_IMPL_API IMGUI_IMPL_API bool ImGui_ImplWin32_Init(void* hwnd); +IMGUI_IMPL_API bool ImGui_ImplWin32_InitForOpenGL(void* hwnd); IMGUI_IMPL_API void ImGui_ImplWin32_Shutdown(); IMGUI_IMPL_API void ImGui_ImplWin32_NewFrame(); diff --git a/extern/imgui_patched/docs/BACKENDS.md b/extern/imgui_patched/docs/BACKENDS.md index cac11b6c..2b4a4fbe 100644 --- a/extern/imgui_patched/docs/BACKENDS.md +++ b/extern/imgui_patched/docs/BACKENDS.md @@ -5,22 +5,22 @@ _(You may browse this at https://github.com/ocornut/imgui/blob/master/docs/BACKE **The backends/ folder contains backends for popular platforms/graphics API, which you can use in your application or engine to easily integrate Dear ImGui.** Each backend is typically self-contained in a pair of files: imgui_impl_XXXX.cpp + imgui_impl_XXXX.h. -- The 'Platform' backends are in charge of: mouse/keyboard/gamepad inputs, cursor shape, timing, windowing.
- e.g. Windows ([imgui_impl_win32.cpp](https://github.com/ocornut/imgui/blob/master/backends/imgui_impl_win32.cpp)), GLFW ([imgui_impl_glfw.cpp](https://github.com/ocornut/imgui/blob/master/backends/imgui_impl_glfw.cpp)), SDL2 ([imgui_impl_sdl.cpp](https://github.com/ocornut/imgui/blob/master/backends/imgui_impl_sdl.cpp)), etc. +- The 'Platform' backends are in charge of: mouse/keyboard/gamepad inputs, cursor shape, timing, and windowing.
+ e.g. Windows ([imgui_impl_win32.cpp](https://github.com/ocornut/imgui/blob/master/backends/imgui_impl_win32.cpp)), GLFW ([imgui_impl_glfw.cpp](https://github.com/ocornut/imgui/blob/master/backends/imgui_impl_glfw.cpp)), SDL2 ([imgui_impl_sdl2.cpp](https://github.com/ocornut/imgui/blob/master/backends/imgui_impl_sdl2.cpp)), etc. -- The 'Renderer' backends are in charge of: creating atlas texture, rendering imgui draw data.
+- The 'Renderer' backends are in charge of: creating atlas texture, and rendering imgui draw data.
e.g. DirectX11 ([imgui_impl_dx11.cpp](https://github.com/ocornut/imgui/blob/master/backends/imgui_impl_dx11.cpp)), OpenGL/WebGL ([imgui_impl_opengl3.cpp](https://github.com/ocornut/imgui/blob/master/backends/imgui_impl_opengl3.cpp)), Vulkan ([imgui_impl_vulkan.cpp](https://github.com/ocornut/imgui/blob/master/backends/imgui_impl_vulkan.cpp)), etc. -- For some high-level frameworks, a single backend usually handle both 'Platform' and 'Renderer' parts.
+- For some high-level frameworks, a single backend usually handles both 'Platform' and 'Renderer' parts.
e.g. Allegro 5 ([imgui_impl_allegro5.cpp](https://github.com/ocornut/imgui/blob/master/backends/imgui_impl_allegro5.cpp)). If you end up creating a custom backend for your engine, you may want to do the same. -An application usually combines 1 Platform backend + 1 Renderer backend + main Dear ImGui sources. +An application usually combines one Platform backend + one Renderer backend + main Dear ImGui sources. For example, the [example_win32_directx11](https://github.com/ocornut/imgui/tree/master/examples/example_win32_directx11) application combines imgui_impl_win32.cpp + imgui_impl_dx11.cpp. There are 20+ examples in the [examples/](https://github.com/ocornut/imgui/blob/master/examples/) folder. See [EXAMPLES.MD](https://github.com/ocornut/imgui/blob/master/docs/EXAMPLES.md) for details. **Once Dear ImGui is setup and running, run and refer to `ImGui::ShowDemoWindow()` in imgui_demo.cpp for usage of the end-user API.** -### What are backends +### What are backends? Dear ImGui is highly portable and only requires a few things to run and render, typically: @@ -41,7 +41,7 @@ Dear ImGui is highly portable and only requires a few things to run and render, This is essentially what each backend is doing + obligatory portability cruft. Using default backends ensure you can get all those features including the ones that would be harder to implement on your side (e.g. multi-viewports support). It is important to understand the difference between the core Dear ImGui library (files in the root folder) -and backends which we are describing here (backends/ folder). +and the backends which we are describing here (backends/ folder). - Some issues may only be backend or platform specific. - You should be able to write backends for pretty much any platform and any 3D graphics API. @@ -62,7 +62,8 @@ List of Platforms Backends: imgui_impl_android.cpp ; Android native app API imgui_impl_glfw.cpp ; GLFW (Windows, macOS, Linux, etc.) http://www.glfw.org/ imgui_impl_osx.mm ; macOS native API (not as feature complete as glfw/sdl backends) - imgui_impl_sdl.cpp ; SDL2 (Windows, macOS, Linux, iOS, Android) https://www.libsdl.org + imgui_impl_sdl2.cpp ; SDL2 (Windows, macOS, Linux, iOS, Android) https://www.libsdl.org + imgui_impl_sdl3.cpp ; SDL2 (Windows, macOS, Linux, iOS, Android) https://www.libsdl.org (*EXPERIMENTAL*) imgui_impl_win32.cpp ; Win32 native API (Windows) imgui_impl_glut.cpp ; GLUT/FreeGLUT (this is prehistoric software and absolutely not recommended today!) @@ -75,7 +76,8 @@ List of Renderer Backends: imgui_impl_metal.mm ; Metal (with ObjC) imgui_impl_opengl2.cpp ; OpenGL 2 (legacy, fixed pipeline <- don't use with modern OpenGL context) imgui_impl_opengl3.cpp ; OpenGL 3/4, OpenGL ES 2, OpenGL ES 3 (modern programmable pipeline) - imgui_impl_sdlrenderer.cpp; SDL_Renderer (optional component of SDL2 available from SDL 2.0.18+) + imgui_impl_sdlrenderer2.cpp ; SDL_Renderer (optional component of SDL2 available from SDL 2.0.18+) + imgui_impl_sdlrenderer3.cpp ; SDL_Renderer (optional component of SDL3 available from SDL 3.0.0+) imgui_impl_vulkan.cpp ; Vulkan imgui_impl_wgpu.cpp ; WebGPU @@ -83,8 +85,8 @@ List of high-level Frameworks Backends (combining Platform + Renderer): imgui_impl_allegro5.cpp -Emscripten is also supported. -The [example_emscripten_opengl3](https://github.com/ocornut/imgui/tree/master/examples/example_emscripten_opengl3) app uses imgui_impl_sdl.cpp + imgui_impl_opengl3.cpp, but other combos are possible. +Emscripten is also supported! +The SDL+GL, GLFW+GL and SDL+WebGPU examples are all ready to build and run with Emscripten. ### Backends for third-party frameworks, graphics API or other languages @@ -97,7 +99,7 @@ If you are not sure which backend to use, the recommended platform/frameworks fo |Library |Website |Backend |Note | |--------|--------|--------|-----| | GLFW | https://github.com/glfw/glfw | imgui_impl_glfw.cpp | | -| SDL2 | https://www.libsdl.org | imgui_impl_sdl.cpp | | +| SDL2 | https://www.libsdl.org | imgui_impl_sdl2.cpp | | | Sokol | https://github.com/floooh/sokol | [util/sokol_imgui.h](https://github.com/floooh/sokol/blob/master/util/sokol_imgui.h) | Lower-level than GLFW/SDL | @@ -109,19 +111,19 @@ Think twice! If you are new to Dear ImGui, first try using the existing backends as-is. You will save lots of time integrating the library. You can LATER decide to rewrite yourself a custom backend if you really need to. -In most situations, custom backends have less features and more bugs than the standard backends we provide. +In most situations, custom backends have fewer features and more bugs than the standard backends we provide. If you want portability, you can use multiple backends and choose between them either at compile time or at runtime. **Example A**: your engine is built over Windows + DirectX11 but you have your own high-level rendering system layered over DirectX11.
Suggestion: try using imgui_impl_win32.cpp + imgui_impl_dx11.cpp first. -Once it works, if you really need it you can replace the imgui_impl_dx11.cpp code with a +Once it works, if you really need it, you can replace the imgui_impl_dx11.cpp code with a custom renderer using your own rendering functions, and keep using the standard Win32 code etc. -**Example B**: your engine runs on Windows, Mac, Linux and uses DirectX11, Metal, Vulkan respectively.
+**Example B**: your engine runs on Windows, Mac, Linux and uses DirectX11, Metal, and Vulkan respectively.
Suggestion: use multiple generic backends! -Once it works, if you really need it you can replace parts of backends with your own abstractions. +Once it works, if you really need it, you can replace parts of backends with your own abstractions. **Example C**: your engine runs on platforms we can't provide public backends for (e.g. PS4/PS5, Switch), and you have high-level systems everywhere.
diff --git a/extern/imgui_patched/docs/CHANGELOG.txt b/extern/imgui_patched/docs/CHANGELOG.txt index dac5e8cc..03d290e4 100644 --- a/extern/imgui_patched/docs/CHANGELOG.txt +++ b/extern/imgui_patched/docs/CHANGELOG.txt @@ -8,8 +8,8 @@ Changes to backends are also included within the individual .cpp files of each b RELEASE NOTES: https://github.com/ocornut/imgui/releases REPORT ISSUES: https://github.com/ocornut/imgui/issues DISCUSS, ASK QUESTIONS: https://github.com/ocornut/imgui/discussions -FAQ https://www.dearimgui.org/faq/ WIKI https://github.com/ocornut/imgui/wiki +FAQ https://www.dearimgui.com/faq/ WHEN TO UPDATE? @@ -99,17 +99,674 @@ Other changes: ----------------------------------------------------------------------- - VERSION 1.88 WIP (In Progress) + VERSION 1.89.6 (Released 2023-05-31) ----------------------------------------------------------------------- +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.89.6 + Breaking changes: +- Clipper: Commented out obsolete redirection constructor which was marked obsolete in 1.79: + 'ImGuiListClipper(int items_count, float items_height)' --> Use 'ImGuiListClipper() + clipper.Begin()'. +- Clipper: Renamed ForceDisplayRangeByIndices() to IncludeRangeByIndices(), kept + inline redirection function (introduced in 1.86 and rarely used). (#6424, #3841) +- Commented out obsolete/redirecting functions that were marked obsolete more than two years ago: + - ListBoxHeader() -> use BeginListBox() + - ListBoxFooter() -> use EndListBox() + - Note how two variants of ListBoxHeader() existed. Check commented versions in imgui.h for refeence. +- Backends: SDL_Renderer: Renamed 'imgui_impl_sdlrenderer.h/cpp' to 'imgui_impl_sdlrenderer2.h/cpp', + in order to accomodate for upcoming SDL3 and change in its SDL_Renderer API. (#6286) +- Backends: GLUT: Removed call to ImGui::NewFrame() from ImGui_ImplGLUT_NewFrame(). + It needs to be called from the main app loop, like with every other backends. (#6337) [@GereonV] + +Other changes: + +- Window: Fixed resizing from upper border when io.ConfigWindowsMoveFromTitleBarOnly is set. (#6390) +- Tables: Fixed a small miscalculation in TableHeader() leading to an empty tooltip + showing when a sorting column has no visible name. (#6342) [@lukaasm] +- Tables: Fixed command merging when compiling with VS2013 (one array on stack was not + initialized on VS2013. Unsure if due to a bug or UB/standard conformance). (#6377) +- InputText: Avoid setting io.WantTextInputNextFrame during the deactivation frame. + (#6341) [@lukaasm] +- Drag, Sliders: if the format string doesn't contain any %, CTRL+Click to input text will + use the default format specifier for the type. Allow display/input of raw value when using + "enums" patterns (display label instead of value) + allow using when value is hidden. (#6405) +- Nav: Record/restore preferred position on each given axis after a movement on that axis, + then score movement on the other axis using this as a bias. This allows going up and down + between e.g. a large header spanning horizontal space and three-ways-columns, landing + on the same column as before. +- Nav: Fixed navigation within tables/columns where item boundaries goes beyond columns limits, + unclipped bounding boxes would interfere with other columns. (#2221) [@zzzyap, @ocornut] +- Nav: Fixed CTRL+Tab into a root window with only childs with _NavFlattened flags + erroneously initializing default nav layer to menu layer. +- Menus: Fixed an issue when opening a menu hierarchy in a given menu-bar would allow + opening another via simple hovering. (#3496, #4797) +- Fonts: Fixed crash when merging fonts and the first font has no valid glyph. (#6446) [@JaedanC] +- Fonts: Fixed crash when manually specifying an EllipsisChar that doesn't exist. (#6480) +- Misc: Added ImVec2 unary minus operator. (#6368) [@Koostosh] +- Debug Tools: Debug Log: Fixed not parsing 0xXXXXXXXX values for geo-locating on mouse + hover hover when the identifier is at the end of the line. (#5855) +- Debug Tools: Added 'io.ConfigDebugIgnoreFocusLoss' option to disable 'io.AddFocusEvent(false)' + handling. May facilitate interactions with a debugger when focus loss leads to clearing + inputs data. (#4388, #4921) +- Backends: Clear bits sets io.BackendFlags on backend Shutdown(). (#6334, #6335] [@GereonV] + Potentially this would facilitate switching runtime backend mid-session. +- Backends: Win32: Added ImGui_ImplWin32_InitForOpenGL() to facilitate combining raw + Win32/Winapi with OpenGL. (#3218) +- Backends: OpenGL3: Restore front and back polygon mode separately when supported + by context (Desktop 3.0, 3.1, or 3.2+ with compat bit). (#6333) [@GereonV] +- Backends: OpenGL3: Support for glBindSampler() backup/restore on ES3. (#6375) [@jsm174] +- Backends: SDL3: Fixed build on Emscripten/iOS/Android. (#6391) [@jo-codegirl] +- Backends: SDLRenderer3: Added SDL_Renderer for SDL3 backend. (#6286) [@Carcons, @ocornut] +- Examples: Added native Win32+OpenGL3 example. We don't recommend using this setup but we + provide it for completeness. (#3218, #5170, #6086, #2772, #2600, #2359, #2022, #1553) [@learn-more] +- Examples: Vulkan: Use integrated GPU if nothing else is available. (#6359) [@kimidaisuki22] +- Examples: DX9, DX10, DX11: Queue framebuffer resize instead of processing in WM_SIZE, + as some drivers tends to only cleanup after existing the native resize modal loop. (#6374) +- Examples: Added SDL3+SDL_Renderer example. (#6286) +- Examples: Updated all Visual Studio projects and batches to use /utf-8 argument. + +Docking+Viewports Branch: + +- Viewports: Fixed platform-side focus (e.g. Alt+Tab) from leading to accidental + closure of Modal windows. Regression from 1.89.5. (#6357, #6299) +- Viewports: Fixed loss of imgui-side focus when dragging a secondary viewport back in + main viewport, due to platform-side handling changes. Regression from 1.89.5 (#6299) +- Viewports: Avoid applying imgui-side focus when focus change is due to a viewport + destruction. Fixes erroneous popup closure on closing a previous popup. (#6462, #6299) +- Viewports: Added void* ImGuiPlatformMonitor::PlatformHandle field (backend-dependant), + for usage by user code. +- Backends: GLFW: Preserve monitor list when there are no monitor, may briefly + happen when recovering from macOS sleeping mode. (#5683) [@Guistac] +- Backends: SDL2: Update monitor list when receiving a display event. (#6348) + Note however that SDL2 currently doesn't have an event for a DPI/Scaling change, + so monitor data won't be updated in this situation. +- Backends: SDL3: Update monitor list when receiving a display event. (#6348) + + +----------------------------------------------------------------------- + VERSION 1.89.5 (Released 2023-04-13) +----------------------------------------------------------------------- + +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.89.5 + +Other changes: + +- InputText: Reworked prev/next-word behavior to more closely match Visual Studio + text editor. Include '.' as a delimiter and alter varying subtle behavior with how + blanks and separators are treated when skipping words. (#6067) [@ajweeks] +- InputText: Fixed a tricky edge case, ensuring value is always written back on the + frame where IsItemDeactivated() returns true, in order to allow usage without user + retaining underlying data. While we don't really want to encourage user not retaining + underlying data, in the absence of a "late commit" behavior/flag we understand it may + be desirable to take advantage of this trick. (#4714) +- Drag, Sliders: Fixed parsing of text input when '+' or '#' format flags are used + in the format string. (#6259) [@idbrii] +- Nav: Made Ctrl+Tab/Ctrl+Shift+Tab windowing register ownership to held modifier so + it doesn't interfere with other code when remapping those actions. (#4828, #3255, #5641) +- Nav: Made PageUp/PageDown/Home/End navigation also scroll parent windows when + necessary to make the target location fully visible (same as e.g. arrow keys). +- ColorEdit: Fixed shading of S/V triangle in Hue Wheel mode. (#5200, #6254) [@jamesthomasgriffin] +- TabBar: Tab-bars with ImGuiTabBarFlags_FittingPolicyScroll can be scrolled with + horizontal mouse-wheel (or Shift + WheelY). (#2702) +- Rendering: Using adaptive tessellation for RadioButton, ColorEdit preview circles, + Windows Close and Collapse Buttons. +- ButtonBehavior: Fixed an edge case where changing widget type/behavior while active + and using same id could lead to an assert. (#6304) +- Misc: Fixed ImVec2 operator[] violating aliasing rules causing issue with Intel C++ + compiler. (#6272) [@BayesBug] +- IO: Input queue trickling adjustment for touch screens. (#2702, #4921) + This fixes single-tapping to move simulated mouse and immediately click on a widget + that is using the ImGuiButtonFlags_AllowItemOverlap policy. + - This only works if the backend can distinguish TouchScreen vs Mouse. + See 'Demo->Tools->Metrics->Inputs->Mouse Source' to verify. + - Fixed tapping on BeginTabItem() on a touch-screen. (#2702) + - Fixed tapping on CollapsingHeader() with a close button on a touch-screen. + - Fixed tapping on TreeNode() using ImGuiTreeNodeFlags_AllowItemOverlap on a touch-screen. + - Fixed tapping on Selectable() using ImGuiSelectableFlags_AllowItemOverlap on a touch-screen. + - Fixed tapping on TableHeader() on a touch-screen. +- IO: Added io.AddMouseSourceEvent() and ImGuiMouseSource enum. This is to allow backend to + specify actual event source between Mouse/TouchScreen/Pen. (#2702, #2334, #2372, #3453, #5693) +- IO: Fixed support for calling io.AddXXXX functions from inactive context (wrongly + advertised as supported in 1.89.4). (#6199, #6256, #5856) [@cfillion] +- Backends: OpenGL3: Fixed GL loader crash when GL_VERSION returns NULL. (#6154, #4445, #3530) +- Backends: OpenGL3: Properly restoring "no shader program bound" if it was the case prior to + running the rendering function. (#6267, #6220, #6224) [@BrunoLevy] +- Backends: Win32: Added support for io.AddMouseSourceEvent() to discriminate Mouse/TouchScreen/Pen. (#2334, #2702) +- Backends: SDL2/SDL3: Added support for io.AddMouseSourceEvent() to discriminate Mouse/TouchScreen. + This is relying on SDL passing SDL_TOUCH_MOUSEID in the event's 'which' field. (#2334, #2702) +- Backends: SDL2/SDL3: Avoid calling SDL_StartTextInput()/SDL_StopTextInput() as they actually + block text input input and don't only pertain to IME. It's unclear exactly what their relation + is to other IME function such as SDL_SetTextInputRect(). (#6306, #6071, #1953) +- Backends: GLFW: Added support on Win32 only for io.AddMouseSourceEvent() to discriminate + Mouse/TouchScreen/Pen. (#2334, #2702) +- Backends: Android: Added support for io.AddMouseSourceEvent() to discriminate Mouse/TouchScreen/Pen. + (#6315) [@PathogenDavid] +- Backends: OSX: Added support for io.AddMouseSourceEvent() to discriminate Mouse/Pen. + (#6314) [@PathogenDavid] +- Backends: WebGPU: Align buffers. Use WGSL shaders instead of SPIR-V. Add gamma uniform. (#6188) [@eliemichel] +- Backends: WebGPU: Reorganized to store data in io.BackendRendererUserData like other backends. +- Examples: Vulkan: Fixed validation errors with newer VulkanSDK by explicitly querying and enabling + "VK_KHR_get_physical_device_properties2", "VK_KHR_portability_enumeration", and + VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR. (#6109, #6172, #6101) +- Examples: Windows: Added 'misc/debuggers/imgui.natstepfilter' file to all Visual Studio projects, + now that VS 2022 17.6 Preview 2 support adding Debug Step Filter spec files into projects. +- Examples: SDL3: Updated for latest WIP SDL3 branch. (#6243) +- TestSuite: Added variety of new regression tests and improved/amended existing ones + in imgui_test_engine/ repo. [@PathogenDavid, @ocornut] + +Docking+Viewports Branch: + +- Viewports: Setting focus from Platform/OS (e.g. via decoration, or Alt-Tab) sets corresponding + focus at Dear ImGui level (generally last focused window in the viewport). (#6299) +- Docking: Fixed using GetItemXXX() or IsItemXXX() functions after a DockSpace(). (#6217) +- Backends: GLFW: Fixed key modifiers handling on secondary viewports. (#6248, #6034) [@aiekick] +- Backends: GLFW: Fixed Emscripten erroneously enabling multi-viewport support, leading to assert. (#5683) +- Backends: SDL2/SDL3: Fixed IME text input rectangle position with viewports. (#6071, #1953) +- Backends: SDL3: Fixed for compilation with multi-viewports. (#6255) [@P3RK4N] + + +----------------------------------------------------------------------- + VERSION 1.89.4 (Released 2023-03-14) +----------------------------------------------------------------------- + +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.89.4 + +Breaking Changes: + +- Renamed PushAllowKeyboardFocus()/PopAllowKeyboardFocus() to PushTabStop()/PopTabStop(). + Kept inline redirection functions (will obsolete). +- Moved the optional "courtesy maths operators" implementation from imgui_internal.h in imgui.h. + Even though we encourage using your own maths types and operators by setting up IM_VEC2_CLASS_EXTRA, + it has been frequently requested by people to use our own. We had an opt-in define which was + previously fulfilled by imgui_internal.h. It is now fulfilled by imgui.h. (#6164, #6137, #5966, #2832) + OK: #define IMGUI_DEFINE_MATH_OPERATORS / #include "imgui.h" / #include "imgui_internal.h" + Error: #include "imgui.h" / #define IMGUI_DEFINE_MATH_OPERATORS / #include "imgui_internal.h" + Added a dedicated compile-time check message to help diagnose this. +- Tooltips: Added 'bool' return value to BeginTooltip() for API consistency. + Please only submit contents and call EndTooltip() if BeginTooltip() returns true. + In reality the function will _currently_ always return true, but further changes down the + line may change this, best to clarify API sooner. Updated demo code accordingly. +- Commented out redirecting enums/functions names that were marked obsolete two years ago: + - ImGuiSliderFlags_ClampOnInput -> use ImGuiSliderFlags_AlwaysClamp + - ImGuiInputTextFlags_AlwaysInsertMode -> use ImGuiInputTextFlags_AlwaysOverwrite + - ImDrawList::AddBezierCurve() -> use ImDrawList::AddBezierCubic() + - ImDrawList::PathBezierCurveTo() -> use ImDrawList::PathBezierCubicCurveTo() + +Other changes: + +- Nav: Tabbing now cycles through all items when ImGuiConfigFlags_NavEnableKeyboard is set. + (#3092, #5759, #787) + While this was generally desired and requested by many, note that its addition means + that some types of UI may become more fastidious to use TAB key with, if the navigation + cursor cycles through too many items. You can mark items items as not tab-spottable: + - Public API: PushTabStop(false) / PopTabStop() + - Internal: PushItemFlag(ImGuiItemFlags_NoTabStop, true); + - Internal: Directly pass ImGuiItemFlags_NoTabStop to ItemAdd() for custom widgets. +- Nav: Tabbing/Shift-Tabbing can more reliably be used to step out of an item that is not + tab-stoppable. (#3092, #5759, #787) +- Nav: Made Enter key submit the same type of Activation event as Space key, + allowing to press buttons with Enter. (#5606) + (Enter emulates a "prefer text input" activation vs. + Space emulates a "prefer tweak" activation which is to closer to gamepad controls). +- Nav: Fixed an issue with Gamepad navigation when the movement lead to a scroll and + frame time > repeat rate. Triggering a new move request on the same frame as a move + result lead to an incorrect calculation and loss of navigation id. (#6171) +- Nav: Fixed SetItemDefaultFocus() from not scrolling when item is partially visible. + (#2814, #2812) [@DomGries] +- Tables: Fixed an issue where user's Y cursor movement within a hidden column would + have side-effects. +- IO: Lifted constraint to call io.AddEventXXX functions from current context. (#4921, #5856, #6199) +- InputText: Fixed not being able to use CTRL+Tab while an InputText() using Tab + for completion or text data is active (regression from 1.89). +- Drag and Drop: Fixed handling of overlapping targets when smaller one is submitted + before and can accept the same data type. (#6183). +- Drag and Drop: Clear drag and drop state as soon as delivery is accepted in order to + avoid interferences. (#5817, #6183) [@DimaKoltun] +- Debug Tools: Added io.ConfigDebugBeginReturnValueOnce / io.ConfigDebugBeginReturnValueLoop + options to simulate Begin/BeginChild returning false to facilitate debugging user behavior. +- Demo: Updated to test return value of BeginTooltip(). +- Backends: OpenGL3: Fixed restoration of a potentially deleted OpenGL program. If an active + program was pending deletion, attempting to restore it would error. (#6220, #6224) [@Cyphall] +- Backends: Win32: Use WM_NCMOUSEMOVE / WM_NCMOUSELEAVE to track mouse positions over + non-client area (e.g. OS decorations) when app is not focused. (#6045, #6162) +- Backends: SDL2, SDL3: Accept SDL_GetPerformanceCounter() not returning a monotonically + increasing value. (#6189, #6114, #3644) [@adamkewley] +- Backends: GLFW: Avoid using glfwGetError() and glfwGetGamepadState() on Emscripten, which + recently updated its GLFW emulation layer to GLFW 3.3 without supporting those. (#6240) +- Examples: Android: Fixed example build for Gradle 8. (#6229, #6227) [@duddel] +- Examples: Updated all examples application to enable ImGuiConfigFlags_NavEnableKeyboard + and ImGuiConfigFlags_NavEnableGamepad by default. (#787) +- Internals: Misc tweaks to facilitate applying an explicit-context patch. (#5856) [@Dragnalith] + +----------------------------------------------------------------------- + VERSION 1.89.3 (Released 2023-02-14) +----------------------------------------------------------------------- + +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.89.3 + +Breaking Changes: + +- Backends+Examples: SDL2: renamed all unnumbered references to "sdl" to "sdl2". + This is in prevision for the future release of SDL3 and its associated backend. (#6146) + - imgui_impl_sdl.cpp -> imgui_impl_sdl2.cpp + - imgui_impl_sdl.h -> imgui_impl_sdl2.h + - example_sdl_xxxx/ -> example_sdl2_xxxx/ (folders and projects) + +Other changes: + +- SeparatorText(): Added SeparatorText() widget. (#1643) [@phed, @ocornut] + - Added to style: float SeparatorTextBorderSize. + - Added to style: ImVec2 SeparatorTextAlign, SeparatorTextPadding. +- Tables: Raised max Columns count from 64 to 512. (#6094, #5305, #4876, #3572) + The previous limit was due to using 64-bit integers but we moved to bits-array + and tweaked the system enough to ensure no performance loss. +- Tables: Solved an ID conflict issue with multiple-instances of a same table, + due to how unique table instance id was generated. (#6140) [@ocornut, @rodrigorc] +- Inputs, Scrolling: Made horizontal scroll wheel and horizontal scroll direction consistent + across backends/os. (#4019, #6096, #1463) [@PathogenDavid, @ocornut, @rokups] + - Clarified that 'wheel_y > 0.0f' scrolls Up, 'wheel_y > 0.0f' scrolls Down. + Clarified that 'wheel_x > 0.0f' scrolls Left, 'wheel_x > 0.0f' scrolls Right. + - Backends: Fixed horizontal scroll direction for Win32 and SDL backends. (#4019) + - Shift+WheelY support on non-OSX machines was already correct. (#2424, #1463) + (whereas on OSX machines Shift+WheelY turns into WheelX at the OS level). + - If you use a custom backend, you should verify horizontal wheel direction. + - Axises are flipped by OSX for mouse & touch-pad when 'Natural Scrolling' is on. + - Axises are flipped by Windows for touch-pad when 'Settings->Touchpad->Down motion scrolls up' is on. + - You can use 'Demo->Tools->Debug Log->IO" to visualize values submitted to Dear ImGui. + - Known issues remaining with Emscripten: + - The magnitude of wheeling values on Emscripten was improved but isn't perfect. (#6096) + - When running the Emscripten app on a Mac with a mouse, SHIFT+WheelY doesn't turn into WheelX. + This is because we don't know that we are running on Mac and apply our own Shift+swapping + on top of OSX' own swapping, so wheel axises are swapped twice. Emscripten apps may need + to find a way to detect this and set io.ConfigMacOSXBehaviors manually (if you know a way + let us know!), or offer the "OSX-style behavior" option to their user. +- Window: Avoid rendering shapes for hidden resize grips. +- Text: Fixed layouting of wrapped-text block skipping successive empty lines, + regression from the fix in 1.89.2. (#5720, #5919) +- Text: Fixed clipping of single-character "..." ellipsis (U+2026 or U+0085) when font + is scaled. Scaling wasn't taken into account, leading to ellipsis character straying + slightly out of its expected boundaries. (#2775) +- Text: Tweaked rendering of three-dots "..." ellipsis variant. (#2775, #4269) +- InputText: Added support for Ctrl+Delete to delete up to end-of-word. (#6067) [@ajweeks] + (Not adding Super+Delete to delete to up to end-of-line on OSX, as OSX doesn't have it) +- InputText: On OSX, inhibit usage of Alt key to toggle menu when active (used for work skip). +- Menus: Fixed layout of MenuItem()/BeginMenu() when label contains a '\n'. (#6116) [@imkcy9] +- ColorEdit, ColorPicker: Fixed hue/saturation preservation logic from interfering with + the displayed value (but not stored value) of others widgets instances. (#6155) +- PlotHistogram, PlotLines: Passing negative sizes honor alignment like other widgets. +- Combo: Allow SetNextWindowSize() to alter combo popup size. (#6130) +- Fonts: Assert that in each GlyphRanges[] pairs first is <= second. +- ImDrawList: Added missing early-out in AddPolyline() and AddConvexPolyFilled() when + color alpha is zero. +- Misc: Most text functions treat "%s" as a shortcut to no-formatting. (#3466) +- Misc: Tolerate zero delta-time under Emscripten as backends are imprecise in their + values for io.DeltaTime, and browser features such as "privacy.resistFingerprinting=true" + can exacerbate that. (#6114, #3644) +- Backends: OSX: Fixed scroll/wheel scaling for devices emitting events with + hasPreciseScrollingDeltas==false (e.g. non-Apple mices). +- Backends: Win32: flipping WM_MOUSEHWHEEL horizontal value to match other backends and + offer consistent horizontal scrolling direction. (#4019) +- Backends: SDL2: flipping SDL_MOUSEWHEEL horizontal value to match other backends and + offer consistent horizontal scrolling direction. (#4019) +- Backends: SDL2: Removed SDL_MOUSEWHEEL value clamping. (#4019, #6096, #6081) +- Backends: SDL2: Added support for SDL 2.0.18+ preciseX/preciseY mouse wheel data + for smooth scrolling as reported by SDL. (#4019, #6096) +- Backends: SDL2: Avoid calling SDL_SetCursor() when cursor has not changed, as the function + is surprisingly costly on Mac with latest SDL (already fixed in SDL latest trunk). (#6113) +- Backends: SDL2: Implement IME handler to call SDL_SetTextInputRect()/SDL_StartTextInput(). + It will only works with SDL 2.0.18+ if your code calls 'SDL_SetHint(SDL_HINT_IME_SHOW_UI, "1")' + prior to calling SDL_CreateWindow(). Updated all examples accordingly. (#6071, #1953) +- Backends: SDL3: Added experimental imgui_impl_sdl3.cpp backend. (#6146) [@dovker, @ocornut] + SDL 3.0.0 has not yet been released, so it is possible that its specs/api will change before + release. This backend is provided as a convenience for early adopters etc. We don't recommend + switching to SDL3 before it is released. +- Backends: GLFW: Registering custom low-level mouse wheel handler to get more accurate + scrolling impulses on Emscripten. (#4019, #6096) [@ocornut, @wolfpld, @tolopolarity] +- Backends: GLFW: Added ImGui_ImplGlfw_SetCallbacksChainForAllWindows() to instruct backend + to chain callbacks even for secondary viewports/windows. User callbacks may need to test + the 'window' parameter. (#6142) +- Backends: OpenGL3: Fixed GL loader compatibility with 2.x profiles. (#6154, #4445, #3530) [@grauw] +- Backends: WebGPU: Fixed building for latest WebGPU specs (remove implicit layout generation). + (#6117, #4116, #3632) [@tonygrue, @bfierz] +- Examples: refactored SDL2+GL and GLFW+GL examples to compile with Emscripten. + (#2492, #2494, #3699, #3705) [@ocornut, @nicolasnoble] + The dedicated example_emscripten_opengl3/ has been removed. +- Examples: Added SDL3+GL experimental example. (#6146) +- Examples: Win32: Fixed examples using RegisterClassW() since 1.89 to also call + DefWindowProcW() instead of DefWindowProc() so that title text are correctly converted + when application is compiled without /DUNICODE. (#5725, #5961, #5975) [@markreidvfx] +- Examples: SDL2+SDL_Renderer: Added call to SDL_RenderSetScale() to fix display on a + Retina display (albeit lower-res as our other unmodified examples). (#6121, #6065, #5931). + +Docking+Viewports Branch: + +- Backends: GLFW: Handle unsupported glfwGetVideoMode() for Emscripten. (#6096) + + +----------------------------------------------------------------------- + VERSION 1.89.2 (Released 2023-01-05) +----------------------------------------------------------------------- + +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.89.2 + +All changes: + +- Tables, Nav, Scrolling: fixed scrolling functions and focus tracking with frozen rows and + frozen columns. Windows now have a better understanding of outer/inner decoration sizes, + which should later lead us toward more flexible uses of menu/status bars. (#5143, #3692) +- Tables, Nav: frozen columns are not part of menu layer and can be crossed over. (#5143, #3692) +- Tables, Columns: fixed cases where empty columns may lead to empty ImDrawCmd. (#4857, #5937) +- Tables: fixed matching width of synchronized tables (multiple tables with same id) when only + some instances have a vertical scrollbar and not all. (#5920) +- Fixed cases where CTRL+Tab or Modal can occasionally lead to the creation of ImDrawCmd with + zero triangles, which would makes the render loop of some backends assert (e.g. Metal with + debugging, Allegro). (#4857, #5937) +- Inputs, IO: reworked ImGuiMod_Shortcut to redirect to Ctrl/Super at runtime instead of + compile-time, being consistent with our support for io.ConfigMacOSXBehaviors and making it + easier for bindings generators to process that value. (#5923, #456) +- Inputs, Scrolling: better selection of scrolling window when hovering nested windows + and when backend/OS is emitting dual-axis wheeling inputs (typically touch pads on macOS). + We now select a primary axis based on recent events, and select a target window based on it. + We expect this behavior to be further improved/tweaked. (#3795, #4559) [@ocornut, @folays] +- InputText: fixed cursor navigation when pressing Up Arrow on the last character of a + multiline buffer which doesn't end with a carriage return. (#6000) +- Text: fixed layouting of wrapped-text block when the last source line is above the + clipping region. Regression added in 1.89. (#5720, #5919) +- Misc: added GetItemID() in public API. It is not often expected that you would use this, + but it is useful for Shortcut() and upcoming owner-aware input functions which wants to + be implemented with public API. +- Fonts: imgui_freetype: fixed a packing issue which in some occurrences would prevent large + amount of glyphs from being packed correctly. (#5788, #5829) +- Fonts: added a 'void* UserData' field in ImFontAtlas, as a convenience for use by + applications using multiple font atlases. +- Demo: simplified "Inputs" section, moved contents to Metrics->Inputs. +- Debug Tools: Metrics: added "Inputs" section, moved from Demo for consistency. +- Misc: fixed parameters to IMGUI_DEBUG_LOG() not being dead-stripped when building + with IMGUI_DISABLE_DEBUG_TOOLS is used. (#5901) [@Teselka] +- Misc: fixed compile-time detection of SSE features on MSVC 32-bits builds. (#5943) [@TheMostDiligent] +- Examples: DirectX10, DirectX11: try WARP software driver if hardware driver is not available. (#5924, #5562) +- Backends: GLFW: Fixed mods state on Linux when using Alt-GR text input (e.g. German keyboard layout), which + could lead to broken text input. Revert a 2022/01/17 change were we resumed using mods provided by GLFW, + turns out they are faulty in this specific situation. (#6034) +- Backends: Allegro5: restoring using al_draw_indexed_prim() when Allegro version is >= 5.2.5. (#5937) [@Espyo] +- Backends: Vulkan: Fixed sampler passed to ImGui_ImplVulkan_AddTexture() not being honored as we were using + an immutable sampler. (#5502, #6001, #914) [@martin-ejdestig, @rytisss] + +Docking+Viewports Branch: + +- Docking: Internals: fixed DockBuilderCopyDockSpace() crashing when windows not in the + remapping list are docked on the left or top side of a split. (#6035) +- Docking: fixed DockSpace() with ImGuiDockNodeFlags_KeepAliveOnly marking current window + as written to, even if it doesn't technically submit an item. This allow using KeepAliveOnly + from any window location. (#6037) +- Backends: OSX: fixed typo in ImGui_ImplOSX_GetWindowSize that would cause issues when resiing + from OS decorations, if they are enabled on secondary viewports. (#6009) [@sivu] +- Backends: Metal: fixed secondary viewport rendering. (#6015) [@dmirty-kuzmenko] + + +----------------------------------------------------------------------- + VERSION 1.89.1 (Released 2022-11-24) +----------------------------------------------------------------------- + +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.89.1 + +Other changes: + +- Scrolling, Focus: fixed SetKeyboardFocusHere()/SetItemDefaultFocus() during a window-appearing + frame (and associated lower-level functions e.g. ScrollToRectEx()) from not centering item. (#5902) +- Inputs: fixed moving a window or drag and dropping from preventing input-owner-unaware code + from accessing keys. (#5888, #4921, #456) +- Inputs: fixed moving a window or drag and dropping from capturing mods. (#5888, #4921, #456) +- Layout: fixed End()/EndChild() incorrectly asserting if users manipulates cursor position + inside a collapsed/culled window and IMGUI_DISABLE_OBSOLETE_FUNCTIONS is enabled. (#5548, #5911) +- Combo: fixed selected item (marked with SetItemDefaultFocus()) from not being centered when + the combo window initially appears. (#5902). +- ColorEdit: fixed label overlapping when using style.ColorButtonPosition == ImGuiDir_Left to + move the color button on the left side (regression introduced in 1.88 WIP 2022/02/28). (#5912) +- Drag and Drop: fixed GetDragDropPayload() returning a non-NULL value if a drag source is + active but a payload hasn't been submitted yet. This is convenient to detect new payload + from within a drag source handler. (#5910, #143) +- Backends: GLFW: cancel out errors emitted by glfwGetKeyName() when a name is missing. (#5908) +- Backends: WebGPU: fixed validation error with default depth buffer settings. (#5869, #5914) [@kdchambers] + +Docking+Viewports Branch: + +- Viewports: Fixed collapsed windows setting ImGuiViewportFlags_NoRendererClear without + making title bar color opaque, leading to potential texture/fb garbage being visible. + Right now as we don't fully support transparent viewports (#2766), so we turn that + 'TitleBgCollapsed' color opaque just lke we do for 'WindowBG' on uncollapsed windows. + + +----------------------------------------------------------------------- + VERSION 1.89 (Released 2022-11-15) +----------------------------------------------------------------------- + +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.89 + +Breaking changes: + +- Layout: Obsoleted using SetCursorPos()/SetCursorScreenPos() to extend parent window/cell boundaries. (#5548) + This relates to when moving the cursor position beyond current boundaries WITHOUT submitting an item. + - Previously this would make the window content size ~200x200: + Begin(...) + SetCursorScreenPos(GetCursorScreenPos() + ImVec2(200,200)) + End(); + - Instead, please submit an item: + Begin(...) + SetCursorScreenPos(GetCursorScreenPos() + ImVec2(200,200)) + Dummy(ImVec2(0,0)) + End(); + - Alternative: + Begin(...) + Dummy(ImVec2(200,200)) + End(); + Content size is now only extended when submitting an item. + With '#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS' this will now be detected and assert. + Without '#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS' this will silently be fixed until we obsolete it. + (This incorrect pattern has been mentioned or suggested in: #4510, #3355, #1760, #1490, #4152, #150, + threads have been amended to refer to this issue). +- Inputs: ImGuiKey is now a typed enum, allowing ImGuiKey_XXX symbols to be named in debuggers. (#4921) + This will require uses of legacy backend-dependent indices to be casted, e.g. + - with imgui_impl_glfw: IsKeyPressed(GLFW_KEY_A) -> IsKeyPressed((ImGuiKey)GLFW_KEY_A); + - with imgui_impl_win32: IsKeyPressed('A') -> IsKeyPressed((ImGuiKey)'A') + - etc. however if you are upgrading code you might as well use the backend-agnostic IsKeyPressed(ImGuiKey_A) now. +- Renamed and merged keyboard modifiers key enums and flags into a same set: (#4921, #456) + - ImGuiKey_ModCtrl and ImGuiModFlags_Ctrl -> ImGuiMod_Ctrl + - ImGuiKey_ModShift and ImGuiModFlags_Shift -> ImGuiMod_Shift + - ImGuiKey_ModAlt and ImGuiModFlags_Alt -> ImGuiMod_Alt + - ImGuiKey_ModSuper and ImGuiModFlags_Super -> ImGuiMod_Super + Kept inline redirection enums (will obsolete). + This change simplifies a few things, reduces confusion, and will facilitate upcoming + shortcut/input ownership apis. + - The ImGuiKey_ModXXX were introduced in 1.87 and mostly used by backends. + - The ImGuiModFlags_XXX have been exposed in imgui.h but not really used by any public api, + only by third-party extensions. They were however subject to a recent rename + (ImGuiKeyModFlags_XXX -> ImGuiModFlags_XXX) and we are exceptionally commenting out + the older ImGuiKeyModFlags_XXX names ahead of obsolescence schedule to reduce confusion + and because they were not meant to be used anyway. +- Removed io.NavInputs[] and ImGuiNavInput enum that were used to feed gamepad inputs. + Basically 1.87 already obsoleted them from the backend's point of view, but internally + our navigation code still used this array and enum, so they were still present. + Not anymore! (#4921, #4858, #787, #1599, #323) + Transition guide: + - Official backends from 1.87+ -> no issue. + - Official backends from 1.60 to 1.86 -> will build and convert gamepad inputs, unless IMGUI_DISABLE_OBSOLETE_KEYIO is defined. Need updating! + - Custom backends not writing to io.NavInputs[] -> no issue. + - Custom backends writing to io.NavInputs[] -> will build and convert gamepad inputs, unless IMGUI_DISABLE_OBSOLETE_KEYIO is defined. Need fixing! + - TL;DR: Backends should call io.AddKeyEvent()/io.AddKeyAnalogEvent() with ImGuiKey_GamepadXXX values instead of filling io.NavInput[]. + The ImGuiNavInput enum was essentially 1.60's attempt to combine keyboard and gamepad inputs with named + semantic, but the additional indirection and copy added complexity and got in the way of other + incoming work. User's code (other than backends) should not be affected, unless you have custom + widgets intercepting navigation events via the named enums (in which case you can upgrade your code). +- DragInt()/SliderInt(): Removed runtime patching of invalid "%f"/"%.0f" types of format strings. + This was obsoleted in 1.61 (May 2018). See 1.61 changelog for details. +- Changed signature of ImageButton() function: (#5533, #4471, #2464, #1390) + - Added 'const char* str_id' parameter + removed 'int frame_padding = -1' parameter. + - Old signature: bool ImageButton(ImTextureID tex_id, ImVec2 size, ImVec2 uv0 = ImVec2(0,0), ImVec2 uv1 = ImVec2(1,1), int frame_padding = -1, ImVec4 bg_col = ImVec4(0,0,0,0), ImVec4 tint_col = ImVec4(1,1,1,1)); + - used the ImTextureID value to create an ID. This was inconsistent with other functions, led to ID conflicts, and caused problems with engines using transient ImTextureID values. + - had a FramePadding override which was inconsistent with other functions and made the already-long signature even longer. + - New signature: bool ImageButton(const char* str_id, ImTextureID tex_id, ImVec2 size, ImVec2 uv0 = ImVec2(0,0), ImVec2 uv1 = ImVec2(1,1), ImVec4 bg_col = ImVec4(0,0,0,0), ImVec4 tint_col = ImVec4(1,1,1,1)); + - requires an explicit identifier. You may still use e.g. PushID() calls and then pass an empty identifier. + - always uses style.FramePadding for padding, to be consistent with other buttons. You may use PushStyleVar() to alter this. + - As always we are keeping a redirection function available (will obsolete later). +- Removed the bizarre legacy default argument for 'TreePush(const void* ptr = NULL)'. (#1057) + Must always pass a pointer value explicitly, NULL/nullptr is ok but require cast, e.g. TreePush((void*)nullptr); + If you used TreePush() replace with TreePush((void*)NULL); +- Removed support for 1.42-era IMGUI_DISABLE_INCLUDE_IMCONFIG_H / IMGUI_INCLUDE_IMCONFIG_H. (#255) + They only made sense before we could use IMGUI_USER_CONFIG. + +Other Changes: + +- Popups & Modals: fixed nested Begin() inside a popup being erroneously input-inhibited. + While it is unusual, you can nest a Begin() inside a popup or modal, it is occasionally + useful to achieve certain things (e.g. to implement suggestion popups #718, #4461). +- Inputs: Standard widgets now claim for key/button ownership and test for them. + - Fixes scenario where e.g. a Popup with a Selectable() reacting on mouse down + (e.g. double click) closes, and behind it is another window with an item reacting + on mouse up. Previously this would lead to both items reacting, now the item in the + window behind won't react on the mouse up since the mouse button ownership has already + been claimed earlier. + - Internals: There are MANY more aspects to this changes. Added experimental/internal APIs + to allow handling input/shorting routing and key ownership. Things will be moved into + public APIs over time. For now this release is a way to test the solidity of underlying + systems while letting early adopters adopters toy with internals. + (#456, #2637, #2620, #2891, #3370, #3724, #4828, #5108, #5242, #5641) +- Scrolling: Tweak mouse-wheel locked window timer so it is shorter but also gets reset + whenever scrolling again. Modulate for small (sub-pixel) amounts. (#2604) +- Scrolling: Mitigated issue where multi-axis mouse-wheel inputs (usually from touch pad + events) are incorrectly locking scrolling in a parent window. (#4559, #3795, #2604) +- Scrolling: Exposed SetNextWindowScroll() in public API. Useful to remove a scrolling + delay in some situations where e.g. windows need to be synched. (#1526) +- InputText: added experimental io.ConfigInputTextEnterKeepActive feature to make pressing + Enter keep the input active and select all text. +- InputText: numerical fields automatically accept full-width characters (U+FF01..U+FF5E) + by converting them to half-width (U+0021..U+007E). +- InputText: added ImGuiInputTextFlags_EscapeClearsAll flag: first press on Escape clears + text if any, second press deactivate the InputText(). (#5688, #2620) +- InputText: added support for shift+click style selection. (#5619) [@procedural] +- InputText: clarified that callbacks cannot modify buffer when using the ReadOnly flag. +- InputText: fixed minor one-frame selection glitch when reverting with Escape. +- ColorEdit3: fixed id collision leading to an assertion. (#5707) +- IsItemHovered: Added ImGuiHoveredFlags_DelayNormal and ImGuiHoveredFlags_DelayShort flags, + allowing to introduce a shared delay for tooltip idioms. The delays are respectively + io.HoverDelayNormal (default to 0.30f) and io.HoverDelayFast (default to 0.10f). (#1485) +- IsItemHovered: Added ImGuiHoveredFlags_NoSharedDelay to disable sharing delays between items, + so moving from one item to a nearby one will requires delay to elapse again. (#1485) +- Tables: activating an ID (e.g. clicking button inside) column doesn't prevent columns + output flags from having ImGuiTableColumnFlags_IsHovered set. (#2957) +- Tables,Columns: fixed a layout issue where SameLine() prior to a row change would set the + next row in such state where subsequent SameLine() would move back to previous row. +- Tabs: Fixed a crash when closing multiple windows (possible with docking only) with an + appended TabItemButton(). (#5515, #3291) [@rokups] +- Tabs: Fixed shrinking policy leading to infinite loops when fed unrounded tab widths. (#5652) +- Tabs: Fixed shrinking policy sometimes erroneously making right-most tabs stray a little out + bar boundaries (bug in 1.88). (#5652). +- Tabs: Enforcing minimum size of 1.0f, fixed asserting on zero-tab widths. (#5572) +- Window: Fixed a potential crash when appending to a child window. (#5515, #3496, #4797) [@rokups] +- Window: Fixed an issue where uncollapsed a window would show a scrollbar for a frame. +- Window: Auto-fit size takes account of work rectangle (menu bars eating from viewport). (#5843) +- Window: Fixed position not being clamped while auto-resizing (fixes appearing windows without + .ini data from moving for a frame when using io.ConfigWindowsMoveFromTitleBarOnly). (#5843) +- IO: Added ImGuiMod_Shortcut which is ImGuiMod_Super on Mac and ImGuiMod_Ctrl otherwise. (#456) +- IO: Added ImGuiKey_MouseXXX aliases for mouse buttons/wheel so all operations done on ImGuiKey + can apply to mouse data as well. (#4921) +- IO: Filter duplicate input events during the AddXXX() calls. (#5599, #4921) +- IO: Fixed AddFocusEvent(false) to also clear MouseDown[] state. (#4921) +- Menus: Fixed incorrect sub-menu parent association when opening a menu by closing another. + Among other things, it would accidentally break part of the closing heuristic logic when moving + towards a sub-menu. (#2517, #5614). [@rokups] +- Menus: Fixed gaps in closing logic which would make child-menu erroneously close when crossing + the gap between a menu item inside a window and a child-menu in a secondary viewport. (#5614) +- Menus: Fixed using IsItemHovered()/IsItemClicked() on BeginMenu(). (#5775) +- Menus, Popups: Experimental fix for issue where clicking on an open BeginMenu() item called from + a window which is neither a popup neither a menu used to incorrectly close and reopen the menu + (the fix may have side-effect and is labelld as experimental as we may need to revert). (#5775) +- Menus, Nav: Fixed keyboard/gamepad navigation occasionally erroneously landing on menu-item + in parent window when the parent is not a popup. (#5730) +- Menus, Nav: Fixed not being able to close a menu with Left arrow when parent is not a popup. (#5730) +- Menus, Nav: Fixed using left/right navigation when appending to an existing menu (multiple + BeginMenu() call with same names). (#1207) +- Menus: Fixed a one-frame issue where SetNextWindowXXX data are not consumed by a BeginMenu() + returning false. +- Nav: Fixed moving/resizing window with gamepad or keyboard when running at very high framerate. +- Nav: Pressing Space/GamepadFaceDown on a repeating button uses the same repeating rate as a mouse hold. +- Nav: Fixed an issue opening a menu with Right key from a non-menu window. +- Text: Fixed wrapped-text not doing a fast-forward on lines above the clipping region, + which would result in an abnormal number of vertices created (was slower and more likely to + asserts with 16-bits ImDrawVtx). (#5720) +- Fonts: Added GetGlyphRangesGreek() helper for Greek & Coptic glyph range. (#5676, #5727) [@azonenberg] +- ImDrawList: Not using alloca() anymore, lift single polygon size limits. (#5704, #1811) + - Note: now using a temporary buffer stored in ImDrawListSharedData. + This change made it more visible than you cannot append to multiple ImDrawList from multiple + threads if they share the same ImDrawListSharedData. Previously it was a little more likely + for this to "accidentally" work, but was already incorrect. (#6167) +- Platform IME: [Windows] Removed call to ImmAssociateContextEx() leading to freeze on some setups. + (#2589, #5535, #5264, #4972) +- Misc: better error reporting for PopStyleColor()/PopStyleVar() + easier to recover. (#1651) +- Misc: io.Framerate moving average now converge in 60 frames instead of 120. (#5236, #4138) +- Debug Tools: Debug Log: Visually locate items when hovering a 0xXXXXXXXX value. (#5855) +- Debug Tools: Debug Log: Added 'IO' and 'Clipper' events logging. (#5855) +- Debug Tools: Metrics: Visually locate items when hovering a 0xXXXXXXXX value (in most places). +- Debug Tools: Item Picker: Mouse button can be changed by holding Ctrl+Shift, making it easier + to use the Item Picker in e.g. menus. (#2673) +- Docs: Fixed various typos in comments and documentations. (#5649, #5675, #5679) [@tocic, @lessigsx] +- Demo: Improved "Constrained-resizing window" example, more clearly showcase aspect-ratio. (#5627) +- Demo: Added more explicit "Center window" mode to "Overlay example". (#5618) +- Demo: Fixed Log & Console from losing scrolling position with Auto-Scroll when child is clipped. (#5721) +- Examples: Added all SDL examples to default VS solution. +- Examples: Win32: Always use RegisterClassW() to ensure windows are Unicode. (#5725) +- Examples: Android: Enable .ini file loading/saving into application internal data folder. (#5836) [@rewtio] +- Backends: GLFW: Honor GLFW_CURSOR_DISABLED by not setting mouse position. (#5625) [@scorpion-26] +- Backends: GLFW: Add glfwGetError() call on GLFW 3.3 to inhibit missing mouse cursor errors. (#5785) [@mitchellh] +- Backends: SDL: Disable SDL 2.0.22 new "auto capture" which prevents drag and drop across windows + (e.g. for multi-viewport support) and don't capture mouse when drag and dropping. (#5710) +- Backends: Win32: Convert WM_CHAR values with MultiByteToWideChar() when window class was + registered as MBCS (not Unicode). (#5725, #1807, #471, #2815, #1060) [@or75, @ocornut] +- Backends: OSX: Fixed mouse inputs on flipped views. (#5756) [@Nemirtingas] +- Backends: OSX: Fixed mouse coordinate before clicking on the host window. (#5842) [@maezawa-akira] +- Backends: OSX: Fixes to support full app creation in C++. (#5403) [@stack] +- Backends: OpenGL3: Reverted use of glBufferSubData(), too many corruptions issues were reported, + and old leaks issues seemingly can't be reproed with Intel drivers nowadays (revert earlier changes). + (#4468, #4504, #3381, #2981, #4825, #4832, #5127). +- Backends: Metal: Use __bridge for ARC based systems. (#5403) [@stack] +- Backends: Metal: Add dispatch synchronization. (#5447) [@luigifcruz] +- Backends: Metal: Update deprecated property 'sampleCount'->'rasterSampleCount'. (#5603) [@dcvz] +- Backends: Vulkan: Added experimental ImGui_ImplVulkan_RemoveTexture() for api symetry. (#914, #5738). +- Backends: WebGPU: fixed rendering when a depth buffer is enabled. (#5869) [@brainlag] + +Docking+Viewports Branch: + +- Docking: Fixed incorrect focus highlight on docking node when focusing a menu. (#5702) +- Docking, Nav: Fixed using gamepad/keyboard navigation not being able enter menu layer when + it only contained the standard Collapse/Close buttons and no actual menu. (#5463, #4792) +- Docking: Fixed regression introduced in v1.87 when docked window content not rendered + while switching between with CTRL+Tab. [@rokups] +- Docking: Fixed amending into an existing tab bar from rendering invisible items. (#5515) +- Docking: Made spacing between dock nodes not a dropping gap. When hovering it only + outer-docking drop markers are visible. +- Docking+Viewports: Fixed undocking window node causing parent viewports to become unresponsive + in certain situation (e.g. hidden tab bar). (#5503) [@rokups] +- Backends: SDL: Fixed building backend under non-OSX Apple targets (e.g. iPhone). (#5665) +- Backends: SDL: Fixed drag'n drop crossing a viewport border losing mouse coordinates. (#5710, #5012) +- Backends: GLFW: Fixed leftover static variable preventing from changing or + reinitializing backend while application is running. (#4616, #5434) [@rtoumazet] + + +----------------------------------------------------------------------- + VERSION 1.88 (Released 2022-06-21) +----------------------------------------------------------------------- + +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.88 + +Breaking changes: + +- Renamed IMGUI_DISABLE_METRICS_WINDOW to IMGUI_DISABLE_DEBUG_TOOLS for correctness. + Kept support for old define (will obsolete). +- Renamed CaptureMouseFromApp() and CaptureKeyboardFromApp() to SetNextFrameWantCaptureMouse() + and SetNextFrameWantCaptureKeyboard() to clarify purpose, old name was too misleading. + Kept inline redirection functions (will obsolete). - Renamed ImGuiKeyModFlags to ImGuiModFlags. Kept inline redirection enums (will obsolete). (This was never used in public API functions but technically present in imgui.h and ImGuiIO). - Backends: OSX: Removed ImGui_ImplOSX_HandleEvent() from backend API in favor of backend automatically handling event capture. Examples that are using the OSX backend have removed all the now-unnecessary calls to ImGui_ImplOSX_HandleEvent(), applications can do as well. [@stuartcarnie] (#4821) +- Internals: calling ButtonBehavior() without calling ItemAdd() now requires a KeepAliveID() + call. This is because the KeepAliveID() call was moved from GetID() to ItemAdd(). (#5181) Other Changes: @@ -122,9 +779,14 @@ Other Changes: In particular, using the input system for fast game-like actions (e.g. WASD camera move) would typically have been impacted, as well as holding a key while dragging mouse. Constraints have been lifted and are now only happening when e.g. an InputText() widget is active. (#4921, #4858) - Not that even thought you shouldn't need to disable io.ConfigInputTrickleEventQueue, you can + Note that even thought you shouldn't need to disable io.ConfigInputTrickleEventQueue, you can technically dynamically change its setting based on the context (e.g. disable only when hovering or interacting with a game/3D view). +- IO: Fixed input queue trickling of mouse wheel events: multiple wheel events are merged, while + a mouse pos followed by a mouse wheel are now trickled. (#4921, #4821) +- IO: Added io.SetAppAcceptingEvents() to set a master flag for accepting key/mouse/characters + events (default to true). Useful if you have native dialog boxes that are interrupting your + application loop/refresh, and you want to disable events being queued while your app is frozen. - Windows: Fixed first-time windows appearing in negative coordinates from being initialized with a wrong size. This would most often be noticeable in multi-viewport mode (docking branch) when spawning a window in a monitor with negative coordinates. (#5215, #3414) [@DimaKoltun] @@ -133,32 +795,56 @@ Other Changes: - Layout: Fixed mixing up SameLine() and SetCursorPos() together from creating situations where line height would be emitted from the wrong location (e.g. 'ItemA+SameLine()+SetCursorPos()+ItemB' would emit ItemA worth of height from the position of ItemB, which is not necessarily aligned with ItemA). +- Sliders: An initial click within the knob/grab doesn't shift its position. (#1946, #5328) - Sliders, Drags: Fixed dragging when using hexadecimal display format string. (#5165, #3133) - Sliders, Drags: Fixed manual input when using hexadecimal display format string. (#5165, #3133) - InputScalar: Fixed manual input when using %03d style width in display format string. (#5165, #3133) - InputScalar: Automatically allow hexadecimal input when format is %X (without extra flag). - InputScalar: Automatically allow scientific input when format is float/double (without extra flag). - Nav: Fixed nav movement in a scope with only one disabled item from focusing the disabled item. (#5189) +- Nav: Fixed issues with nav request being transferred to another window when calling SetKeyboardFocusHere() + and simultaneous changing window focus. (#4449) +- Nav: Changed SetKeyboardFocusHere() to not behave if a drag or window moving is in progress. +- Nav: Fixed inability to cancel nav in modal popups. (#5400) [@rokups] - IsItemHovered(): added ImGuiHoveredFlags_NoNavOverride to disable the behavior where the - return value is overriden by focus when gamepad/keyboard navigation is active. + return value is overridden by focus when gamepad/keyboard navigation is active. - InputText: Fixed pressing Tab emitting two tabs characters because of dual Keys/Chars events being trickled with the new input queue (happened on some backends only). (#2467, #1336) +- InputText: Fixed a one-frame display glitch where pressing Escape to revert after a deletion + would lead to small garbage being displayed for one frame. Curiously a rather old bug! (#3008) +- InputText: Fixed an undo-state corruption issue when editing main buffer before reactivating item. (#4947) +- InputText: Fixed an undo-state corruption issue when editing in-flight buffer in user callback. + (#4947, #4949] [@JoshuaWebb] - Tables: Fixed incorrect border height used for logic when resizing one of several synchronized instance of a same table ID, when instances have a different height. (#3955). - Tables: Fixed incorrect auto-fit of parent windows when using non-resizable weighted columns. (#5276) +- Tables: Fixed draw-call merging of last column. Depending on some unrelated settings (e.g. BorderH) + merging draw-call of the last column didn't always work (regression since 1.87). (#4843, #4844) [@rokups] - Inputs: Fixed IsMouseClicked() repeat mode rate being half of keyboard repeat rate. - ColorEdit: Fixed text baseline alignment after a SameLine() after a ColorEdit() with visible label. +- Tabs: BeginTabItem() now reacts to SetNextItemWidth(). (#5262) +- Tabs: Tweak shrinking policy so that while resizing tabs that don't need shrinking keep their + initial width more precisely (without the occasional +1 worth of width). - Menus: Adjusted BeginMenu() closing logic so hovering void or non-MenuItem() in parent window always lead to menu closure. Fixes using items that are not MenuItem() or BeginItem() at the root level of a popup with a child menu opened. +- Menus: Menus emitted from the main/scrolling layer are not part of the same menu-set as menus emitted + from the menu-bar, avoiding accidental hovering from one to the other. (#3496, #4797) [@rokups] +- Style: Adjust default value of GrabMinSize from 10.0f to 12.0f. - Stack Tool: Added option to copy item path to clipboard. (#4631) +- Settings: Fixed out-of-bounds read when .ini file on disk is empty. (#5351) [@quantum5] +- Settings: Fixed some SetNextWindowPos/SetNextWindowSize API calls not marking settings as dirty. - DrawList: Fixed PathArcTo() emitting terminating vertices too close to arc vertices. (#4993) [@thedmd] - DrawList: Fixed texture-based anti-aliasing path with RGBA textures (#5132, #3245) [@cfillion] - DrawList: Fixed divide-by-zero or glitches with Radius/Rounding values close to zero. (#5249, #5293, #3491) - DrawList: Circle with a radius smaller than 0.5f won't appear, to be consistent with other primitives. [@thedmd] -- Debug: Added DebugTextEncoding() function to facilitate diagnosing issues when not sure about whether - you have a UTF-8 text encoding issue or a font loading issue. [@LaMarche05, @ocornut] +- Debug Tools: Debug Log: Added ShowDebugLogWindow() showing an opt-in synthetic log of principal events + (focus, popup, active id changes) helping to diagnose issues. +- Debug Tools: Added DebugTextEncoding() function to facilitate diagnosing issues when not sure about + whether you have a UTF-8 text encoding issue or a font loading issue. [@LaMarche05, @ocornut] +- Demo: Add better demo of how to use SetNextFrameWantCaptureMouse()/SetNextFrameWantCaptureKeyboard(). - Metrics: Added a "UTF-8 Encoding Viewer" section using the aforementioned DebugTextEncoding() function. +- Metrics: Added "InputText" section to visualize internal state (#4947, #4949). - Misc: Fixed calling GetID("label") _before_ a widget emitting this item inside a group (such as InputInt()) from causing an assertion when closing the group. (#5181). - Misc: Fixed IsAnyItemHovered() returning false when using navigation. @@ -180,6 +866,14 @@ Other Changes: - Backends: OSX: Monitor NSKeyUp events to catch missing keyUp for key when user press Cmd + key (#5128) [@thedmd] - Backends: OSX, Metal: Store backend data in a per-context struct, allowing to use these backends with multiple contexts. (#5203, #5221, #4141) [@noisewuwei] +- Backends: Metal: Fixed null dereference on exit inside command buffer completion handler. (#5363, #5365) [@warrenm] +- Backends: OpenGL3: Partially revert 1.86 change of using glBufferSubData(): now only done on Windows and + Intel GPU, based on querying glGetString(GL_VENDOR). Essentially we got report of accumulating leaks on Intel + with multi-viewports when using simple glBufferData() without orphaning, and report of corruptions on other + GPUs with multi-viewports when using orphaning and glBufferSubData(), so currently switching technique based + on GPU vendor, which unfortunately reinforce the cargo-cult nature of dealing with OpenGL drivers. + Navigating the space of mysterious OpenGL drivers is particularly difficult as they are known to rely on + application specific whitelisting. (#4468, #3381, #2981, #4825, #4832, #5127). - Backends: OpenGL3: Fix state corruption on OpenGL ES 2.0 due to not preserving GL_ELEMENT_ARRAY_BUFFER_BINDING and vertex attribute states. [@rokups] - Examples: Emscripten+WebGPU: Fix building for latest WebGPU specs. (#3632) @@ -188,20 +882,29 @@ Other Changes: Docking+Viewports Branch: - Docking: Fixed floating docked nodes not being clamped into viewport workrect to stay reachable - when g.ConfigWindowsMoveFromTitleBarOnly is set and multi-viewports are disabled. (#5044) + when io.ConfigWindowsMoveFromTitleBarOnly is true and multi-viewports are disabled. (#5044) +- Docking: Fixed a regression where moving window would be interrupted after undocking a tab + when io.ConfigDockingAlwaysTabBar is true. (#5324) [@rokups] +- Docking: Fixed incorrect focus highlight on docking node when focusing empty central node + or a child window which was manually injected into a dockspace window. +- Docking, Modal: Fixed a crash when opening popup from a parent which is being docked on the same frame. (#5401) +- Viewports: Fixed an issue where MouseViewport was lagging by a frame when using 1.87 Input Queue. + A common side-effect would be that when releasing a window drag the underlying window would highlight + for a frame. (#5837, #4921) [@cfillion] - Viewports: Fixed translating a host viewport from briefly altering the size of AlwaysAutoResize windows. (#5057) - Viewports: Fixed main viewport size not matching ImDrawData::DisplaySize for one frame during resize when multi-viewports are disabled. (#4900) - Backends: SDL: Fixed dragging out main viewport broken on some SDL setups. (#5012) [@rokups] -- Backends: OSX: Added suppot for multi-viewports. [@stuartcarnie, @metarutaiga] (#4821, #2778) -- Backends: Metal: Added suppot for multi-viewports. [@stuartcarnie, @metarutaiga] (#4821, #2778) +- Backends: OSX: Added support for multi-viewports. [@stuartcarnie, @metarutaiga] (#4821, #2778) +- Backends: Metal: Added support for multi-viewports. [@stuartcarnie, @metarutaiga] (#4821, #2778) +- Examples: OSX+Metal, SDL+Metal, GLFW+Metal: Added support for multi-viewports. [@rokups] ----------------------------------------------------------------------- VERSION 1.87 (Released 2022-02-07) ----------------------------------------------------------------------- -Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.87 +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.87 Breaking Changes: @@ -366,7 +1069,7 @@ Docking+Viewports Branch: VERSION 1.86 (Released 2021-12-22) ----------------------------------------------------------------------- -Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.86 +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.86 Breaking Changes: @@ -381,7 +1084,7 @@ Other Changes: - Added an assertion for the common user mistake of using "" as an identifier at the root level of a window instead of using "##something". Empty identifiers are valid and useful in a very small amount of cases, but 99.9% of the time if you need an empty label you should use "##something". (#1414, #2562, #2807, #4008, - #4158, #4375, #4548, #4657, #4796). READ THE FAQ ABOUT HOW THE ID STACK WORKS -> https://dearimgui.org/faq + #4158, #4375, #4548, #4657, #4796). READ THE FAQ ABOUT HOW THE ID STACK WORKS -> https://dearimgui.com/faq - Added GetMouseClickedCount() function, returning the number of successive clicks. (#3229) [@kudaba] (so IsMouseDoubleClicked(ImGuiMouseButton_Left) is same as GetMouseClickedCount(ImGuiMouseButton_Left) == 2, but it allows testing for triple clicks and more). @@ -420,7 +1123,7 @@ Other Changes: Fixes issue where e.g. drag and dropping an item and scrolling ensure the item source location is still submitted. (#3841, #1725) [@GamingMinds-DanielC, @ocornut] - Clipper: added ForceDisplayRangeByIndices() to force a given item (or several) to be stepped out - during a clipping operation. (#3841) [@@GamingMinds-DanielC] + during a clipping operation. (#3841) [@GamingMinds-DanielC] - Clipper: rework so gamepad/keyboard navigation doesn't create spikes in number of items requested by the clipper to display. (#3841) - Clipper: fixed content height declaration slightly mismatching the value of when not using a clipper. @@ -482,7 +1185,7 @@ Docking+Viewports Branch: VERSION 1.85 (Released 2021-10-12) ----------------------------------------------------------------------- -Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.85 +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.85 This is the last release officially supporting C++03 and Visual Studio 2008/2010. (#4537) We expect that the next release will require a subset of the C++11 language (VS 2012~, GCC 4.8.1, Clang 3.3). @@ -491,7 +1194,7 @@ If you are stuck on ancient compiler you may need to stay at this version onward Breaking Changes: -- Removed GetWindowContentRegionWidth() function. Keep inline redirection helper. +- Removed GetWindowContentRegionWidth() function. Kept inline redirection helper. Can use 'GetWindowContentRegionMax().x - GetWindowContentRegionMin().x' instead but it's not very useful in practice, and the only use of it in the demo was illfit. Using 'GetContentRegionAvail().x' is generally a better choice. @@ -600,7 +1303,7 @@ Docking+Viewports Branch: VERSION 1.84.2 (Released 2021-08-23) ----------------------------------------------------------------------- -Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.84.2 +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.84.2 - Disabled: Fixed nested BeginDisabled()/EndDisabled() calls. (#211, #4452, #4453, #4462) [@Legulysse] - Backends: OpenGL3: OpenGL: Fixed ES 3.0 shader ("#version 300 es") to use normal precision @@ -611,7 +1314,7 @@ Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.84.2 VERSION 1.84.1 (Released 2021-08-20) ----------------------------------------------------------------------- -Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.84.1 +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.84.1 - Disabled: Fixed BeginDisabled(false) - BeginDisabled(true) was working. (#211, #4452, #4453) @@ -620,7 +1323,7 @@ Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.84.1 VERSION 1.84 (Released 2021-08-20) ----------------------------------------------------------------------- -Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.84 +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.84 Breaking Changes: @@ -670,7 +1373,7 @@ Other Changes: Convenient for some small columns. Name will still appear in context menu. (#4206). - Tables: Fixed columns order on TableSetupScrollFreeze() if previous data got frozen columns out of their section. - Tables: Fixed invalid data in TableGetSortSpecs() when SpecsDirty flag is unset. (#4233) -- TabBar: Fixed using more than 32 KB-worth of tab names. (#4176) +- Tabs: Fixed using more than 32 KB-worth of tab names. (#4176) - InputInt/InputFloat: When used with Steps values and _ReadOnly flag, the step button look disabled. (#211) - InputText: Fixed named filtering flags disabling newline or tabs in multiline inputs (#4409, #4410) [@kfsone] - Drag and Drop: drop target highlight doesn't try to bypass host clipping rectangle. (#4281, #3272) @@ -744,6 +1447,8 @@ Docking+Viewports Branch: (#4292, #3834, #3633, #3521, #3492, #3335, #2999, #2648) - Docking: (Internal/Experimental) Removed DockNodeFlagsOverrideClear flags from ImGuiWindowClass as it is ambiguous how to apply them and we haven't got a use out of them yet. +- Docking: Fixed ImGuiWindowFlags_UnsavedDocument clipping label in docked windows when there are + no close button. (#5745) - Viewports: Fix popup/tooltip created without a parent window from being given a ParentViewportId value from the implicit/fallback window. (#4236, #2409) - Backends: Vulkan: Fix the use of the incorrect fence for secondary viewports. (#4208) [@FunMiles] @@ -753,7 +1458,7 @@ Docking+Viewports Branch: VERSION 1.83 (Released 2021-05-24) ----------------------------------------------------------------------- -Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.83 +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.83 Breaking Changes: @@ -780,7 +1485,7 @@ Other Changes: - Tables: Expose TableSetColumnEnabled() in public api. (#3935) - Tables: Better preserve widths when columns count changes. (#4046) - Tables: Sharing more memory buffers between tables, reducing general memory footprints. (#3740) -- TabBar: Fixed mouse reordering with very fast movements (e.g. crossing multiple tabs in a single +- Tabs: Fixed mouse reordering with very fast movements (e.g. crossing multiple tabs in a single frame and then immediately standing still (would only affect automation/bots). [@rokups] - Menus: made MenuItem() in a menu bar reflect the 'selected' argument with a highlight. (#4128) [@mattelegende] - Drags, Sliders, Inputs: Specifying a NULL format to Float functions default them to "%.3f" to be @@ -853,7 +1558,7 @@ Docking+Viewports Branch: VERSION 1.82 (Released 2021-02-15) ----------------------------------------------------------------------- -Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.82 +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.82 Breaking Changes: @@ -955,7 +1660,7 @@ Docking+Viewports Branch: VERSION 1.81 (Released 2021-02-10) ----------------------------------------------------------------------- -Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.81 +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.81 Breaking Changes: @@ -1047,7 +1752,7 @@ Docking+Viewports Branch: VERSION 1.80 (Released 2021-01-21) ----------------------------------------------------------------------- -Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.80 +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.80 Breaking Changes: @@ -1097,11 +1802,11 @@ Other Changes: - Added 2 enums: ImGuiSortDirection, ImGuiTableBgTarget - Added 1 style variable: ImGuiStyleVar_CellPadding - Added 5 style colors: ImGuiCol_TableHeaderBg, ImGuiCol_TableBorderStrong, ImGuiCol_TableBorderLight, ImGuiCol_TableRowBg, ImGuiCol_TableRowBgAlt. -- Tab Bar: Made it possible to append to an existing tab bar by calling BeginTabBar()/EndTabBar() again. -- Tab Bar: Fixed using more than 128 tabs in a tab bar (scrolling policy recommended). -- Tab Bar: Do not display a tooltip if the name already fits over a given tab. (#3521) -- Tab Bar: Fixed minor/unlikely bug skipping over a button when scrolling left with arrows. -- Tab Bar: Requested ideal content size (for auto-fit) doesn't affect horizontal scrolling. (#3414) +- Tabs: Made it possible to append to an existing tab bar by calling BeginTabBar()/EndTabBar() again. +- Tabs: Fixed using more than 128 tabs in a tab bar (scrolling policy recommended). +- Tabs: Do not display a tooltip if the name already fits over a given tab. (#3521) +- Tabs: Fixed minor/unlikely bug skipping over a button when scrolling left with arrows. +- Tabs: Requested ideal content size (for auto-fit) doesn't affect horizontal scrolling. (#3414) - Drag and Drop: Fix losing drop source ActiveID (and often source tooltip) when opening a TreeNode() or CollapsingHeader() while dragging. (#1738) - Drag and Drop: Fix drag and drop to tie same-size drop targets by chosen the later one. Fixes dragging @@ -1174,7 +1879,7 @@ Docking+Viewports Branch: VERSION 1.79 (Released 2020-10-08) ----------------------------------------------------------------------- -Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.79 +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.79 Breaking Changes: @@ -1230,16 +1935,16 @@ Other Changes: rather than the Mouse Down+Up sequence, even if the _OpenOnArrow flag isn't set. This is standard behavior and amends the change done in 1.76 which only affected cases were _OpenOnArrow flag was set. (This is also necessary to support full multi/range-select/drag and drop operations.) -- Tab Bar: Added TabItemButton() to submit tab that behave like a button. (#3291) [@Xipiryon] -- Tab Bar: Added ImGuiTabItemFlags_Leading and ImGuiTabItemFlags_Trailing flags to position tabs or button +- Tabs: Added TabItemButton() to submit tab that behave like a button. (#3291) [@Xipiryon] +- Tabs: Added ImGuiTabItemFlags_Leading and ImGuiTabItemFlags_Trailing flags to position tabs or button at either end of the tab bar. Those tabs won't be part of the scrolling region, and when reordering cannot be moving outside of their section. Most often used with TabItemButton(). (#3291) [@Xipiryon] -- Tab Bar: Added ImGuiTabItemFlags_NoReorder flag to disable reordering a given tab. -- Tab Bar: Keep tab item close button visible while dragging a tab (independent of hovering state). -- Tab Bar: Fixed a small bug where closing a tab that is not selected would leave a tab hole for a frame. -- Tab Bar: Fixed a small bug where scrolling buttons (with ImGuiTabBarFlags_FittingPolicyScroll) would +- Tabs: Added ImGuiTabItemFlags_NoReorder flag to disable reordering a given tab. +- Tabs: Keep tab item close button visible while dragging a tab (independent of hovering state). +- Tabs: Fixed a small bug where closing a tab that is not selected would leave a tab hole for a frame. +- Tabs: Fixed a small bug where scrolling buttons (with ImGuiTabBarFlags_FittingPolicyScroll) would generate an unnecessary extra draw call. -- Tab Bar: Fixed a small bug where toggling a tab bar from Reorderable to not Reorderable would leave +- Tabs: Fixed a small bug where toggling a tab bar from Reorderable to not Reorderable would leave tabs reordered in the tab list popup. [@Xipiryon] - Columns: Fix inverted ClipRect being passed to renderer when using certain primitives inside of a fully clipped column. (#3475) [@szreder] @@ -1283,7 +1988,7 @@ Docking+Viewports Branch: VERSION 1.78 (Released 2020-08-18) ----------------------------------------------------------------------- -Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.78 +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.78 Breaking Changes: @@ -1348,7 +2053,7 @@ Other Changes: limits when close-enough by (WindowPadding - ItemPadding), which was a tweak with too many side-effects. The behavior is still present in SetScrollHere functions as they are more explicitly aiming at making widgets visible. May later be moved to a flag. -- Tab Bar: Allow calling SetTabItemClosed() after a tab has been submitted (will process next frame). +- Tabs: Allow calling SetTabItemClosed() after a tab has been submitted (will process next frame). - InvisibleButton: Made public a small selection of ImGuiButtonFlags (previously in imgui_internal.h) and allowed to pass them to InvisibleButton(): ImGuiButtonFlags_MouseButtonLeft/Right/Middle. This is a small but rather important change because lots of multi-button behaviors could previously @@ -1401,7 +2106,7 @@ Docking+Viewports Branch: VERSION 1.77 (Released 2020-06-29) ----------------------------------------------------------------------- -Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.77 +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.77 Breaking Changes: @@ -1503,7 +2208,7 @@ Docking+Viewports Branch: VERSION 1.76 (Released 2020-04-12) ----------------------------------------------------------------------- -Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.76 +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.76 Other Changes: @@ -1589,7 +2294,7 @@ Docking+Viewports Branch: VERSION 1.75 (Released 2020-02-10) ----------------------------------------------------------------------- -Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.75 +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.75 Breaking Changes: @@ -1702,7 +2407,7 @@ Docking+Viewports Branch: VERSION 1.74 (Released 2019-11-25) ----------------------------------------------------------------------- -Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.74 +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.74 Breaking Changes: @@ -1760,7 +2465,7 @@ Other Changes: default implementation of ImFileXXX functions linking with fopen/fclose/fread/fwrite. (#2734) - Docs: Improved and moved FAQ to docs/FAQ.md so it can be readable on the web. [@ButternCream, @ocornut] - Docs: Moved misc/fonts/README.txt to docs/FONTS.txt. -- Docs: Added permanent redirect from https://www.dearimgui.org/faq to FAQ page. +- Docs: Added permanent redirect from https://www.dearimgui.com/faq to FAQ page. - Demo: Added simple item reordering demo in Widgets -> Drag and Drop section. (#2823, #143) [@rokups] - Metrics: Show wire-frame mesh and approximate surface area when hovering ImDrawCmd. [@ShironekoBen] - Metrics: Expose basic details of each window key/value state storage. @@ -1789,7 +2494,7 @@ Docking+Viewports Branch: VERSION 1.73 (Released 2019-09-24) ----------------------------------------------------------------------- -Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.73 +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.73 Other Changes: @@ -1800,11 +2505,11 @@ Other Changes: - ColorPicker: Made rendering aware of global style alpha of the picker can be faded out. (#2711) Note that some elements won't accurately fade down with the same intensity, and the color wheel when enabled will have small overlap glitches with (style.Alpha < 1.0). -- TabBar: Fixed single-tab not shrinking their width down. -- TabBar: Fixed clicking on a tab larger than tab-bar width creating a bouncing feedback loop. -- TabBar: Feed desired width (sum of unclipped tabs width) into layout system to allow for auto-resize. (#2768) +- Tabs: Fixed single-tab not shrinking their width down. +- Tabs: Fixed clicking on a tab larger than tab-bar width creating a bouncing feedback loop. +- Tabs: Feed desired width (sum of unclipped tabs width) into layout system to allow for auto-resize. (#2768) (before 1.71 tab bars fed the sum of current width which created feedback loops in certain situations). -- TabBar: Improved shrinking for large number of tabs to avoid leaving extraneous space on the right side. +- Tabs: Improved shrinking for large number of tabs to avoid leaving extraneous space on the right side. Individuals tabs are given integer-rounded width and remainder is spread between tabs left-to-right. - Columns, Separator: Fixed a bug where non-visible separators within columns would alter the next row position differently than visible ones. @@ -1873,7 +2578,7 @@ Docking+Viewports Branch: VERSION 1.72b (Released 2019-07-31) ----------------------------------------------------------------------- -Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.72b +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.72b Other Changes: @@ -1890,7 +2595,7 @@ Other Changes: VERSION 1.72 (Released 2019-07-27) ----------------------------------------------------------------------- -Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.72 +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.72 Breaking Changes: @@ -1926,7 +2631,7 @@ Other Changes: - Scrollbar: Avoid overlapping the opposite side when window (often a child window) is forcibly too small. - Combo: Hide arrow when there's not enough space even for the square button. - InputText: Testing for newly added ImGuiKey_KeyPadEnter key. (#2677, #2005) [@amc522] -- TabBar: Fixed unfocused tab bar separator color (was using ImGuiCol_Tab, should use ImGuiCol_TabUnfocusedActive). +- Tabs: Fixed unfocused tab bar separator color (was using ImGuiCol_Tab, should use ImGuiCol_TabUnfocusedActive). - Columns: Fixed a regression from 1.71 where the right-side of the contents rectangle within each column would wrongly use a WindowPadding.x instead of ItemSpacing.x like it always did. (#125, #2666) - Columns: Made the right-most edge reaches up to the clipping rectangle (removing half of WindowPadding.x @@ -1948,8 +2653,8 @@ Other Changes: returning true. This also effectively make ColorEdit4() not incorrect trigger IsItemDeactivatedAfterEdit() when clicking the color button to open the picker popup. (#1875) - Misc: Added IMGUI_DISABLE_METRICS_WINDOW imconfig.h setting to explicitly compile out ShowMetricsWindow(). -- Debug, Metrics: Added "Tools->Item Picker" tool which allow clicking on a widget to break in the debugger - within the item code. The tool calls IM_DEBUG_BREAK() which can be redefined in imconfig.h if needed. +- Debug Tools: Added "Metrics->Tools->Item Picker" tool which allow clicking on a widget to break in the + debugger within the item code. The tool calls IM_DEBUG_BREAK() which can be redefined in imconfig.h. - ImDrawList: Fixed CloneOutput() helper crashing. (#1860) [@gviot] - ImDrawList::ChannelsSplit(), ImDrawListSplitter: Fixed an issue with merging draw commands between channel 0 and 1. (#2624) @@ -1994,7 +2699,7 @@ Docking+Viewports Branch: VERSION 1.71 (Released 2019-06-12) ----------------------------------------------------------------------- -Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.71 +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.71 Breaking Changes: @@ -2040,7 +2745,7 @@ Other Changes: viewport triggering the issue. (#2609) - TreeNode, CollapsingHeader: Fixed highlight frame not covering horizontal area fully when using horizontal scrolling. (#2211, #2579) -- TabBar: Fixed BeginTabBar() within a window with horizontal scrolling from creating a feedback +- Tabs: Fixed BeginTabBar() within a window with horizontal scrolling from creating a feedback loop with the horizontal contents size. - Columns: Fixed Columns() within a window with horizontal scrolling from not covering the full horizontal area (previously only worked with an explicit contents size). (#125) @@ -2078,7 +2783,7 @@ Other Changes: VERSION 1.70 (Released 2019-05-06) ----------------------------------------------------------------------- -Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.70 +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.70 Breaking Changes: @@ -2169,7 +2874,7 @@ Other Changes: VERSION 1.69 (Released 2019-03-13) ----------------------------------------------------------------------- -Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.69 +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.69 Breaking Changes: @@ -2209,14 +2914,14 @@ Other Changes: - ColorEdit: Fixed tooltip not honoring the ImGuiColorEditFlags_NoAlpha contract of never reading the 4th float in the array (value was read and discarded). (#2384) [@haldean] - MenuItem, Selectable: Fixed disabled widget interfering with navigation (fix c2db7f63 in 1.67). -- TabBar: Fixed a crash when using many BeginTabBar() recursively (didn't affect docking). (#2371) -- TabBar: Added extra mis-usage error recovery. Past the assert, common mis-usage don't lead to +- Tabs: Fixed a crash when using many BeginTabBar() recursively (didn't affect docking). (#2371) +- Tabs: Added extra mis-usage error recovery. Past the assert, common mis-usage don't lead to hard crashes any more, facilitating integration with scripting languages. (#1651) -- TabBar: Fixed ImGuiTabItemFlags_SetSelected being ignored if the tab is not visible (with +- Tabs: Fixed ImGuiTabItemFlags_SetSelected being ignored if the tab is not visible (with scrolling policy enabled) or if is currently appearing. -- TabBar: Fixed Tab tooltip code making drag and drop tooltip disappear during the frame where +- Tabs: Fixed Tab tooltip code making drag and drop tooltip disappear during the frame where the drag payload activate a tab. -- TabBar: Reworked scrolling policy (when ImGuiTabBarFlags_FittingPolicyScroll is set) to +- Tabs: Reworked scrolling policy (when ImGuiTabBarFlags_FittingPolicyScroll is set) to teleport the view when aiming at a tab far away the visible section, and otherwise accelerate the scrolling speed to cap the scrolling time to 0.3 seconds. - Text: Fixed large Text/TextUnformatted calls not feeding their size into layout when starting @@ -2247,7 +2952,7 @@ Other Changes: VERSION 1.68 (Released 2019-02-19) ----------------------------------------------------------------------- -Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.68 +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.68 Breaking Changes: @@ -2317,7 +3022,7 @@ Other Changes: VERSION 1.67 (Released 2019-01-14) ----------------------------------------------------------------------- -Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.67 +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.67 Breaking Changes: @@ -2383,7 +3088,7 @@ Other Changes: VERSION 1.66b (Released 2018-12-01) ----------------------------------------------------------------------- -Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.66b +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.66b Other Changes: @@ -2402,7 +3107,7 @@ Other Changes: VERSION 1.66 (Released 2018-11-22) ----------------------------------------------------------------------- -Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.66 +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.66 Breaking Changes: @@ -2463,7 +3168,7 @@ Other Changes: VERSION 1.65 (Released 2018-09-06) ----------------------------------------------------------------------- -Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.65 +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.65 Breaking Changes: @@ -2489,7 +3194,7 @@ Other Changes: VERSION 1.64 (Released 2018-08-31) ----------------------------------------------------------------------- -Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.64 +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.64 Changes: @@ -2513,7 +3218,7 @@ Changes: VERSION 1.63 (Released 2018-08-29) ----------------------------------------------------------------------- -Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.63 +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.63 Breaking Changes: @@ -2607,7 +3312,7 @@ Other Changes: VERSION 1.62 (Released 2018-06-22) ----------------------------------------------------------------------- -Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.62 +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.62 Breaking Changes: @@ -2688,7 +3393,7 @@ Other Changes: VERSION 1.61 (Released 2018-05-14) ----------------------------------------------------------------------- -Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.61 +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.61 Breaking Changes: @@ -2764,7 +3469,7 @@ Other Changes: VERSION 1.60 (Released 2018-04-07) ----------------------------------------------------------------------- -Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.60 +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.60 The gamepad/keyboard navigation branch (which has been in the work since July 2016) has been merged. Gamepad/keyboard navigation is still marked as Beta and has to be enabled explicitly. @@ -2930,7 +3635,7 @@ Other Changes: VERSION 1.53 (Released 2017-12-25) ----------------------------------------------------------------------- -Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.53 +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.53 Breaking Changes: @@ -3069,7 +3774,7 @@ Other Changes: VERSION 1.52 (2017-10-27) ----------------------------------------------------------------------- -Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.52 +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.52 Breaking Changes: @@ -3175,7 +3880,7 @@ Beta Navigation Branch: VERSION 1.51 (2017-08-24) ----------------------------------------------------------------------- -Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.51 +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.51 Breaking Changes: @@ -3239,7 +3944,7 @@ Other Changes: VERSION 1.50 (2017-06-02) ----------------------------------------------------------------------- -Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.50 +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.50 Breaking Changes: @@ -3335,7 +4040,7 @@ Other Changes: VERSION 1.49 (2016-05-09) ----------------------------------------------------------------------- -Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.49 +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.49 Breaking Changes: @@ -3413,7 +4118,7 @@ Other changes: VERSION 1.48 (2016-04-09) ----------------------------------------------------------------------- -Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.48 +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.48 Breaking Changes: @@ -3483,7 +4188,7 @@ Other Changes: VERSION 1.47 (2015-12-25) ----------------------------------------------------------------------- -Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.47 +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.47 Changes: @@ -3536,7 +4241,7 @@ Changes: VERSION 1.46 (2015-10-18) ----------------------------------------------------------------------- -Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.46 +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.46 Changes: @@ -3588,7 +4293,7 @@ Changes: VERSION 1.45 (2015-09-01) ----------------------------------------------------------------------- -Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.45 +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.45 Breaking Changes: @@ -3648,7 +4353,7 @@ Other Changes: VERSION 1.44 (2015-08-08) ----------------------------------------------------------------------- -Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.44 +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.44 Breaking Changes: @@ -3692,7 +4397,7 @@ Other Changes: VERSION 1.43 (2015-07-17) ----------------------------------------------------------------------- -Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.43 +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.43 Breaking Changes: @@ -3764,7 +4469,7 @@ Other Changes: VERSION 1.42 (2015-07-08) ----------------------------------------------------------------------- -Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.42 +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.42 Breaking Changes: @@ -3809,7 +4514,7 @@ Other Changes: VERSION 1.41 (2015-06-26) ----------------------------------------------------------------------- -Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.41 +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.41 Breaking Changes: @@ -3853,7 +4558,7 @@ Other Changes: VERSION 1.40 (2015-05-31) ----------------------------------------------------------------------- -Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.40 +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.40 Breaking Changes: @@ -3941,7 +4646,664 @@ Other Changes: - Other fixes, comments, tweaks. +----------------------------------------------------------------------- + VERSION 1.38 (2015-04-20) ----------------------------------------------------------------------- -For older version, see https://github.com/ocornut/imgui/releases +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.38 + +Breaking Changes: + +- Renamed IsClipped() to IsRectClipped(). Kept inline redirection function (will obsolete). +- Renamed ImDrawList::AddArc() to ImDrawList::AddArcFast(). + +Other Changes: + +- Added DragFloat(), DragInt() widget, click and drag to adjust value with given step. + Hold SHIFT/ALT to speed-up/slow-down. Double-click or CTRL+click to input text. + Passing min >= max makes the widget unbounded. +- Added DragFloat2(), DragFloat3(), DragFloat4(), DragInt2(), DragInt3(), DragInt4() helper variants. +- Added ShowMetricsWindow() which is mainly useful to debug ImGui internals. Added IO.MetricsRenderVertices counter. +- Added ResetMouseDragDelta() for iterative dragging operations. +- Added ImFontAtlas::AddFontFromCompressedTTF() helper + binary_to_compressed_c.cpp tool to compress a file and create a .c array from it. +- Added PushId() GetId() variants that takes string range to avoid user making unnecessary copies. +- Added IsItemVisible(). +- Fixed IsRectClipped() incorrectly returning false when log is enabled. +- Slider: visual fix in the unlikely that style.GrabMinSize is larger than a slider. +- SliderFloat: removed support for unbound slider (using FLT_MAX), caused various inconsistency. Use InputFloat()/DragFloat(). +- ColorEdit4: hide components prefix if there's no space for them. +- Combo: adding frame padding inside the combo box. +- Columns: mouse dragging uses absolute mouse coordinates.Fixed dragging left-most column of an auto-resizable window. #125 +- Selectable: render highlight into AutoFitPadding region but do not extend it, fixing visual gap. +- Focus: Allow SetWindowFocus(NULL) to remove focus. +- Focus: Clicking on void (outside an ImGui windows) loses keyboard-focus so application can use TAB. +- Popup: Fixed hovering over a popup's child (popups disable hovering on other windows but not their childs) #197 +- Fixed active widget not releasing its active state while being clipped. +- Fixed user-facing version of IsItemHovered() ignoring overlapping windows. +- Fixed label vertical alignment for InputInt2(), InputInt3(), InputInt4(). +- Fixed new collapsed auto-resizing window with saved .ini settings not calculating their initial width #176 +- Fixed Begin() returning true on collapsed windows that had loaded settings #176 +- Fixed style.DisplaySafeAreaPadding handling from being applied on window prior to them auto-fitting. +- ShowTestWindow(): added examples for DragFloat, DragInt and only custom label embedded in format strings. +- ShowTestWindow(): fixed "manipulating titles" example not doing the right thing, broken in ff35d24 +- Examples: OpenGL/GLFW: Fixed modifier key state setting in GLFW callbacks. +- Examples: OpenGL/GLFW: Added glBindTexture(0) in OpenGL fixed pipeline examples. Save restore current program and texture in the OpenGL3 example. +- Examples: DirectX11: Removed unnecessary vertices conversion and CUSTOMVERTEX types. +- Comments, fixes, tweaks. + + +----------------------------------------------------------------------- + VERSION 1.37 (2015-03-26) +----------------------------------------------------------------------- + +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.37 + +Other Changes: + +- Added a more convenient three parameters version of Begin() which covers the common uses better. +- Added mouse cursor types handling (resize, move, text input cursors, etc.) that user can query with GetMouseCursor(). Added demo and instructions in ShowTestWindow(). +- Added embedded mouse cursor data for MouseDrawCursor software cursor rendering, for consoles/tablets/etc. (#155). +- Added first version of BeginPopup/EndPopup() helper API to create popup menus. Popups automatically lock their position to the mouse cursor when first appearing. They close automatically when clicking outside, and inhibit hovering items from other windows when active (to allow for clicking outside). (#126) +- Added thickness parameter to ImDrawList::AddLine(). +- Added ImDrawList::PushClipRectFullScreen() helper. +- Added style.DisplaySafeAreaPadding which was previously hard-coded (useful if you can't see the edges of your display, e.g. TV screens). +- Added CalcItemRectClosestPoint() helper. +- Added GetMouseDragDelta(), IsMouseDragging() helpers, given a mouse button and an optional "unlock" threshold. Added io.MouseDragThreshold setting. (#167) +- IsItemHovered() return false if another widget is active, aka we can't use what we are hovering now. +- Added IsItemHoveredRect() if old behavior of IsItemHovered() is needed (e.g. for implementing the drop side of a drag'n drop operation). +- IsItemhovered() include space taken by label and behave consistently for all widgets (#145) +- Auto-filling child window feed their content size to parent (#170) +- InputText() removed the odd ~ characters when clipping. +- InputText() update its width in case of resize initiated programmatically while the widget is active. +- InputText() last active preserve scrolling position. Reset scroll if widget size becomes bigger than contents. +- Selectable(): not specifying a width defaults to using max of label width and remaining width. +- Selectable(const char*, bool) version has bool defaulting to false. +- Selectable(): fixed misusage of GetContentRegionMax().x leaking into auto-fitting. +- Windows starting Collapsed runs initial auto-fit to retrieve a width for their title bar (#175) +- Fixed new window from having an incorrect content size on their first frame, if queried by user. Fixed SetWindowPos/SetNextWindowPos having a side-effect size computation (#175) +- InputFloat(): fixed label alignment if total widget width forcefully bigger than space available. +- Auto contents size aware of enforced vertical scrollbar if window is larger than display size. +- Fixed new windows auto-fitting bigger than their .ini saved size. This was a bug but it may be a desirable effect sometimes, may reconsider it. +- Fixed negative clipping rectangle when collapsing windows that could affect manual submission to ImDrawList and end-user rendering function if unhandled (#177) +- Fixed bounding measurement of empty groups (fix #162) +- Fixed assignment order in Begin() making auto-fit size effectively lag by one frame. Also disabling "clamp into view" while windows are auto-fitting so that auto-fitting window in corners don't get pushed away. +- Fixed MouseClickedPos not updated on double-click update (#167) +- Fixed MouseDrawCursor feature submitting an empty trailing command in the draw list. Fixed unmerged draw calls for software mouse cursor. +- Fixed double-clicking on resize grip keeping the grip active if mouse button is kept held. +- Bounding box tests exclude higher bound, so touching items (zero spacing) don't report double hover when cursor is on edge. +- Setting io.LogFilename to NULL disable default LogToFile() (part of #175) +- Tweak stb_textedit integration to be lenient if another piece of code are leaking their STB_TEXTEDIT definitions/symbols. +- Shutdown() freeing a few extra vectors so they don't have to freed by destruction (#169) +- Examples: OpenGL2/3 examples automatically hide the OS mouse cursor if software cursor rendering is used. +- ShowTestWindow: Added Widgets Alignment demo under Layout section +- ShowTestWindow: Added simple dragging widget example. +- ShowTestWindow: Graph has checkbox under the label, also demo using BeginGroup/EndGroup(). +- ShowTestWindow: Using SetNextWindowSize() in examples to encourage its use. +- Fixes, tweaks, comments. + + +----------------------------------------------------------------------- + VERSION 1.36 (2015-03-18) +----------------------------------------------------------------------- + +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.36 + +Other Changes: + +- Added ImGui::GetVersion(), IMGUI_VERSION (#127) +- Added BeginGroup()/EndGroup() layout tools (#160). +- Added Indent() / Unindent(). +- Added InputInt2(), InputInt3(), InputInt4() for completeness. +- Added GetItemRectSize(). +- Added VSliderFloat(), VSliderInt(), vertical sliders. +- Added IsRootWindowFocused(), IsRootWindowOrAnyChildFocused(). +- Added io.KeyAlt + support in examples apps, in prevision for future usage of Alt modifier (was missing). +- Added ImGuiStyleVar_GrabMinSize enum value for PushStyleVar(). +- Various fixes related to vertical alignment of text after widget of varied sizes. Allow for multiple blocks of multiple lines text on the same "line". Added demos. +- Explicit size passed to Plot*(), Button() includes the frame padding. +- Style: Changed default Border and Column border colors to be most subtle. +- Renamed style.TreeNodeSpacing to style.IndentSpacing, ImGuiStyleVar_TreeNodeSpacing to ImGuiStyleVar_IndentSpacing. +- Renamed GetWindowIsFocused() to IsWindowFocused(), kept inline redirection with old name (will obsolete). +- Renamed GetItemRectMin()/GetItemRectMax() to GetItemRectMin()/GetItemRectMax(), kept inline redirection with old name (will obsolete). +- Sliders: Fast-path when power=1.0f, also makes code easier to read. +- Sliders: Fixed parsing of decimal precision back from format string when using %%. +- Sliders: Fixed hovering bounding test excluding padding between outer frame and grab (there was a few pixels dead-zone). +- Separator() logs itself as text when passing through text log. +- Optimisation: TreeNodeV() early out if SkipItems is set without formatting. +- Moved various static buffers into state. Increase the formatted string buffer from 1K to 3K. +- Examples: Example console keeps focus on input box at all times. +- Examples: Updated to GLFW 3.1. Moved to examples/libs/ folder. +- Examples: Added 64-bit projects for MSVC. +- Examples: Increase warning level from /W3 to /W4 for MSVC. +- Examples: DirectX9: fixed duplicate creation of vertex buffer. +- Renamed internal type ImGuiAabb to ImRect. Changed mentions of 'box' or 'aabb' to say 'rect'. +- Tweaks, minor fixes and comments. + + +----------------------------------------------------------------------- + VERSION 1.35 (2015-03-09) +----------------------------------------------------------------------- + +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.35 + +Other Changes: + +- Examples: refactored all examples application to make it easier to isolate and grab the code you need for OpenGL 2/3, DirectX 9/11, and toward a more sensible format for samples. +- Scrollbar grab have a minimum size (style.GrabSizeMin), always visible even with huge scroll amount. (#150). +- Scrollbar: Clicking inside the grab box doesn't modify scroll value. Subsequent movement always relative. +- Added "###" labelling syntax to pass a label that isn't part of the hashed ID (#107), e.g. ("%d###static_id",rand()). +- Added GetColumnIndex(), GetColumnsCount() (#154) +- Added GetScrollPosY(), GetScrollMaxY(). +- Fixed the Chinese/Japanese glyph ranges; include missing punctuations (#156) +- Fixed Combo() and ListBox() labels not included in declared size, for use with SameLine(), etc. (fix #149, #151). +- Fixed ListBoxHeader() incorrect handling of SkipItems early out when window is collapsed. +- Fixed using IsItemHovered() after EndChild() (#151) +- Fixed malformed UTF-8 decoding errors leading to infinite loops (#158) +- InputText() handles buffer limit correctly for multi-byte UTF-8 characters, won't insert an incomplete UTF-8 character when reaching buffer limit (fix #158) +- Handle double-width space (0x3000) in various places the same as single-width spaces, for Chinese/Japanese users. +- Collapse triangle uses text color (not border color). +- Fixed font fallback glyph width. +- Renamed style.ScrollBarWidth to style.ScrollbarWidth to be consistent with other casing. +- Windows: setup a default handler for ImeSetInputScreenPosFn so the IME dialog (for Japanese/Chinese, etc.) is positioned correctly as you input text. +- Windows: default clipboard handlers for Windows handle UTF-8. +- Examples: Fixed DirectX 9/11 examples applications handling of Microsoft IME. +- Examples: Allow DirectX 9/11 examples applications to resize the window. +- ShowTestWindow: Fixed "undo" button of custom rendering applet. +- ShowTestWindow: Added "Manipulating Window Title" example. + + +----------------------------------------------------------------------- + VERSION 1.34 (2015-03-02) +----------------------------------------------------------------------- + +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.34 + +Other Changes: + +- Added Bullet() helper - equivalent to BulletText(""), SameLine(). +- Added SetWindowFocus(), SetWindowFocus(const char*), SetNextWindowFocus() (#146) +- Added SetWindowPos(), SetWindowSize(), SetWindowCollaposed() given a window name. +- Added SetNextTreeNodeOpened() with optional condition flag in replacement of OpenNextNode() and consistent with other API. +- Renamed ImGuiSetCondition_* to ImGuiSetCond_* and ImGuiCondition_FirstUseThisSession to ImGuiCond_Once. +- Added missing definition for ImGui::GetWindowCollapsed(). +- Fixed GetGlyphRangesJapanese() actually missing katakana ranges and a few useful extensions. +- Fixed clicking on a widget in a child window not focusing the parent window (#147). +- Fixed clicking on empty space of child window not setting keyboard focus for the child window (#147). +- Fixed IsItemHovered() behaving differently on Combo() (#145) +- Fixed ColumnOffsets storage not honoring SetStateStorage() (not very useful but consistent). +- Examples: Removed dependency on Glew for OpenGL examples. Removed Glew binaries for Windows. +- Examples: Fixed link warning for OpenGL windows examples. +- Comments, tweaks. + +----------------------------------------------------------------------- + VERSION 1.33b (2015-02-23) +----------------------------------------------------------------------- + +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.33b + +Other Changes: + +- Fixed resizing columns. + + +----------------------------------------------------------------------- + VERSION 1.33 (2015-02-22) +----------------------------------------------------------------------- + +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.33 + +Other Changes: + +- InputText: having a InputText widget active doesn't steal mouse inputs from clicking on a button before losing focus (relate to #134) +- InputText: cursor/selection/undo stack persist when using other widgets and getting back to same (#134). +- InputText: fix effective buffer size being smaller than necessary by 1 byte (so if you give 3 bytes you can input 2 ascii chars + zero terminator, which is correct). +- Added IsAnyItemActive(). +- Child window explicitly inherit collapse state from parent (so if user keeps submitting items even thought Begin has returned 'false' the child items will be clipped faster). +- BeginChild() return a bool the same way Begin() does. if true you can skip submitting content. +- Removed extraneous (1,1) padding on child window (pointed out in #125) +- Columns: doesn't bail out when SkipItems is set (fix #136) +- Columns: Separator() within column correctly vertical offset all cells (pointed out in #125) +- GetColumnOffset() / SetColumnOffset() handles padding values more correctly so matching columns can be lined up between a parent and a child window (cf. #125) +- Fix ImFont::BuildLookupTable() potential dangling pointer dereference (fix #131) +- Fix hovering of child window extending past their parent not taking account of parent clipping rectangle (fix #137) +- Sliders: value text is clipped inside the frame when resizing sliders to be small. +- ImGuITextFilter::Draw() use regular width call rather than computing its own arbitrary width. +- ImGuiTextFilter: can take a default filter string during construction. + + +----------------------------------------------------------------------- + VERSION 1.32 (2015-02-11) +----------------------------------------------------------------------- + +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.32 + +Other Changes: + +- Added Selectable() building block for various list boxes, combo boxes, etc. +- Added ListBox() (#129). +- Added ListBoxHeader(), ListBoxFooter() for customized list traversal and creating multi-selection boxes. +- Fixed title bar text clipping issue (fix #128). +- InputText: added ImGuiInputTextFlags_CallbackCharFilter system for filtering/replacement (#130). Callback now passed an "EventFlag" parameter. +- InputText: Added ImGuiInputTextFlags_CharsUppercase and ImGuiInputTextFlags_CharsNoBlank stock filters. +- PushItemWidth() can take negative value to right-align items. +- Optimisation: Columns offsets cached to avoid unnecessary binary search. +- Optimisation: Optimized CalcTextSize() function by about 25% (they are often the bottleneck when submitting thousands of clipped items). +- Added ImGuiCol_ChildWindowBg, ImGuiStyleVar_ChildWindowRounding for completeness and flexibility. +- Added BeginChild() variant that takes an ImGuiID. +- Tweak default ImGuiCol_HeaderActive color to be less bright. +- Calculate framerate for the user (IO.Framerate), as a purely luxurious feature and to reduce sample code size a little. + + +----------------------------------------------------------------------- + VERSION 1.31 (2015-02-08) +----------------------------------------------------------------------- + +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.31 + +Other Changes: + +- Added ImGuiWindowFlags_NoCollapse flag. +- Added a way to replace the internal state pointer so that we can optionally share it between modules (e.g. multiple DLLs). +- Added tint_col parameter to ImageButton(). +- Added CalcListClipping() helper to perform faster/coarse clipping on user side (when manipulating lists with thousands of items). +- Added GetCursorPosX() / GetCursorPosY() shortcuts. +- Renamed GetTextLineSpacing() to GetTextLineHeightWithSpacing(). +- Combo box always appears above other child windows of a same parent. +- Combo/Label: label is properly clipped inside the frame (#23). +- Added cpu-side text clipping functions which are used in some instances to avoid extra draw calls. +- InputText: Filtering private Unicode range 0xE000-0xF8FF. +- Fixed holding button over scrollbar creating a small feedback loop with calculation of contents size. +- Calling SetCursorPos() automatically extends the contents size. +- Track ownership of mouse clicks. Avoid requesting IO.WantCaptureMouse if initial click was outside of ImGui. +- Removed the dependency on realloc(). +- Other fixes, tweaks and comments. + + +----------------------------------------------------------------------- + VERSION 1.30 (2015-02-01) +----------------------------------------------------------------------- + +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.30 + +Breaking Changes: + +- Big update! Initialisation had to be changed. You don't need to load PNG data anymore. The new system gives you uncompressed texture data. + - This sequence: + const void* png_data; + unsigned int png_size; + ImGui::GetDefaultFontData(NULL, NULL, &png_data, &png_size); + // + - Became: + unsigned char* pixels; + int width, height; + // io.Fonts->AddFontFromFileTTF("myfontfile.ttf", 24.0f); // Optionally load another font + io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height); + // + io.Fonts->TexID = (your_texture_identifier); + - PixelCenterOffset has been removed and isn't a necessary setting anymore. Offset your projection matrix by 0.5 if you have rendering problems. + +Other Changes: + +- Loading TTF files with stb_truetype.h. +- We still embed a compressed pixel-perfect TTF version of ProggyClean for convenience. +- Runtime font rendering is a little faster than previously. +- You can load multiple fonts with multiple size inside the font atlas. Rendering with multiple fonts are still merged into a single draw call whenever possible. +- The system handles UTF-8 and provide ranges to easily load e.g. characters for Japanese display. +- Added PushFont() / PopFont(). +- Added Image() and ImageButton() to display your own texture data. +- Added callback system in command-list. This can be used if you want to do your own rendering (e.g. render a 3D scene) inside ImGui widgets. +- Added IsItemActive() to tell if last widget is being held / modified (as opposed to just being hovered). Useful for custom dragging behaviors. +- Style: Added FrameRounding setting for a more rounded look (default to 0 for now). +- Window: Fixed using multiple Begin/End pair on the same wnidow. +- Window: Fixed style.WindowMinSize not being honored properly. +- Window: Added SetCursorScreenPos() helper (WindowPos+CursorPos = ScreenPos). +- ColorEdit3: clicking on color square change the edition. The toggle button is hidden by default. +- Clipboard: Fixed logging to clipboard on architectures where va_list are passed by reference to vsnprintf. +- Clipboard: Improve memory reserve policy for Clipboard / ImGuiTextBuffer. +- Tooltip: Always auto-resize. +- Tooltip: Fixed TooltigBg color not being honored properly. +- Tooltip: Allow SetNextWindowPos() to be used on tooltips. +- Added io.DisplayVisibleMin / io.DisplayVisibleMax to ease integration of virtual / scrolling display. +- Added Set/GetVoidPtr in ImGuiStorage. +- Added ColorConvertHSVtoRGB, ColorConvertRGBtoHSV, ColorConvertFloat4ToU32 helpers. +- Added ImColor() inline helper to easily convert colors to packed 4x1 byte or 4x1 float formats. +- Added io.MouseDrawCursor option to draw a mouse cursor for now (on systems that don't have one) +- Examples: Added custom drawing app example for using ImDrawList api. +- Lots of others fixes, tweaks and comments! + + +----------------------------------------------------------------------- + VERSION 1.20 (2015-01-07) +----------------------------------------------------------------------- + +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.20 + +- Fixed InputInt() InputFloat() label not declaring their width, breaking usage of SameLine(). +- Fixed hovering of combo boxes that extend beyond the parent window limits. +- Fixed text input of Unicode character in the 128-255 range. +- Fixed clipboard pasting into an InputText box not filtering the characters according to contents semantic. +- Dragging outside area of a widget while it is active doesn't trigger hover on other widgets. +- Activating widget bring parent window to front if not already. +- Checkbox and Radio buttons activate on click-release to be consistent with other widgets and most UI. +- InputText() nows consume input characters immediately so they cannot be reused if ImGui::Update is called again with a call to ImGui::Render(). (fixes #105) +- Examples: Console: added support for History callbacks + some cleanup. +- Various small optimisations. +- Cleanup and other fixes. + + +----------------------------------------------------------------------- + VERSION 1.19 (2014-12-30) +----------------------------------------------------------------------- + +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.19 + +- Tightening default style a little. +- Added ImGuiStyleVar_WindowRounding enum for PushStyleVar() API. +- Added SliderInt2(), SliderInt3(), SliderInt4() for consistency. +- Widgets more consistently handle empty labels (starting with ## mark) for their size calculation. +- Fixed crashing with zero sized frame-buffer. +- Fixed ImGui::Combo() not registering its size properly when clipped out of screen. +- Renamed second parameter to Begin() to 'bool* p_opened' to be a little more self-explanatory. Added more comments on the use of Begin(). +- Logging: Added LogText() to pass text straight to the log output (tty/clipboard/file) without rendering it. +- Logging: Added LogFinish() to stop logging at an arbitrary point. +- Logging: Log depth padding relative to start depth. +- Logging: Tree nodes and headers looking better when logged to text. +- Logging: Log outputs \r\n under Windows to play it nicely with \n unaware tools such as Notepad. +- Style editor: added a button to output colors to clipboard/tty. +- OpenGL3 example: fix growing of VBO. +- Cleanup and other minor fixes. + + +----------------------------------------------------------------------- + VERSION 1.18 (2014-12-11) +----------------------------------------------------------------------- + +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.18 + +- Added ImGuiWindowFlags_NoScrollWithMouse, disable mouse wheel scrolling on a window. +- Added ImGuiWindowFlags_NoSavedSettings, disable loading/saving window state to .ini file. +- Added SetNextWindowPos(), SetNextWindowSize(), SetNextWindowCollapsed() API along with SetWindowPos(), SetWindowSize(), SetWindowCollapsed(). All functions include an optional second parameter to easily set current value vs session default value vs persistent default value. +- Removed rarely useful SetNewWindowDefaultPos() in favor of new API. +- Fixed hovering of lower-right resize grip when it is above a child window. +- Fixed InputInt() writing to output when it doesn't need to. +- Added IMGUI_INCLUDE_IMGUI_USER_H define to include user file at the bottom of imgui.h without modifying the vanilla distribution. +- ImGuiStorage helper can store float + added helpers to get pointer to stored data. +- Setup Travis CI integration. Builds the OpenGL examples on Linux with GCC and Clang. +- Examples: Added a "Fixed overlay" example in ShowTestWindow(). +- Examples: Re-added OpenGL 3 programmable-pipeline example (along with the existing fixed pipeline example). +- Examples: OpenGL examples can now resize the application window. +- Other minor fixes and comments. + + +----------------------------------------------------------------------- + VERSION 1.17 (2014-12-03) +----------------------------------------------------------------------- + +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.17 + +- Added ImGuiWindowFlags_AlwaysAutoResize + example app. +- Calling ImGui::SetWindowSize(0,0) force an autofit without zero-sizing first. +- ImGui::InputText() support for completion/history/custom callback + added fancy completion example in the console demo app. +- Not word-wrapping on apostrophes. +- Increased visibility of check box and radio button with smaller size. +- Smooth mouse scrolling on OSX (uses floating point scroll/wheel input). +- New version of IMGUI_ONCE_UPON_A_FRAME helper macro that works with all compilers. +- Moved IO.Font*** options to inside the IO.Font-> structure.. Added IO.FontGlobalScale setting (in addition to Font->Scale per individual font). +- Fixed more Clang -Weverything warnings. +- Examples: Added DirectX11 example application. +- Examples: Created single .sln solution for all example projects. +- Examples: Fixed DirectX9 example window initially showing an hourglass cursor. +- Examples: Removed Microsoft IME handler in examples, too niche/confusing. Moved equivalent code to imgui.cpp instruction block. + + +----------------------------------------------------------------------- + VERSION 1.16b (2014-11-21) +----------------------------------------------------------------------- + +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.16b + +- Fix broken PopStyleVar() crashing. + + +----------------------------------------------------------------------- + VERSION 1.16 (2014-11-21) +----------------------------------------------------------------------- + +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.16 + +- General fixing of Columns API to allow filling a cell with multiple widgets before switching to the next column. +- Added documentation INDEX to top of imgui.cpp. +- Fixed unaligned memory access for Emscripten compatibility. +- Various pedantic warning fixes (now testing with Clang). +- Added extra asserts to catch incorrect usage. +- PushStyleColor() / PushStyleVar() can be used outside the scope of a window (namely to change variables that are used within the Begin() call). +- PushTextWrapPos() defaults to 0.0 (right-end of current drawing region). +- Fixed compatibility with std::vector if user decide to #define ImVector. +- MouseWheel input is now normalized. +- Added IMGUI_OVERRIDE_DRAWVERT_STRUCT_LAYOUT compile-time option to redefine the vertex layout. +- Style editor: colors listed inside a scrolling region. +- Examples: tweaks and fixes. + + +----------------------------------------------------------------------- + VERSION 1.15 (2014-11-07) +----------------------------------------------------------------------- + +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.15 + +- Renamed IsHovered() to IsItemHovered(). +- Added word-wrapping API: TextWrapped(), PushTextWrapPos(), PopTextWrapPos(). +- Added IsItemFocused() to tell if last widget is being focused for keyboard input. +- Added overloads of ImGui::PlotLines() and ImGui::PlotHistogram() taking a function pointer to get values. +- Added SetWindowSize(). +- Added GetContentRegionMax() supporting columns. Some bug fixes with using columns. +- Added PushStyleVar(),PopStyleVar() helpers to modify style from user code. +- Added dummy IMGUI_API definition in front of all entry-points for silly DLL action. +- Allowing BeginChild() allows to specify negative sizes to specify "use remaining minus xx". +- Windows with the NoResize flag can still use auto-fitting. +- Added a simple example console into the demo window. +- Comments and fixes. + + +----------------------------------------------------------------------- + VERSION 1.14 (2014-10-25) +----------------------------------------------------------------------- + +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.14 + +- Comments and fixes. +- Added SetKeyboardFocusHere() to set input focus from code. +- Added GetWindowFont(), GetWindowFontSize() for users of the low-level ImDrawList API. +- Added a UserData void *pointer so that the callback functions can access user state "Just in case a project has adverse reactions to adding globals or statics in their own code." +- Renamed IMGUI_INCLUDE_IMGUI_USER_CPP to IMGUI_INCLUDE_IMGUI_USER_INL + + +---------------------------------------------------------------------- + VERSION 1.13 (2014-09-30) +----------------------------------------------------------------------- + +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.13 + +- Added support for UTF-8 for international text display and text edition/input (if the font supports it). +- Added sample "M+ font" by Coji Morishita in extra_fonts/ to display Japanese text. +- Added IO.ImeSetInputScreenPosFn callback for positioning OS IME input. +- Added IO.FontFallbackGlyph (default to '?'). +- OpenGL example: added commented code to load custom font from file-system. +- OpenGL example: shared makefile for Linux and MacOSX. + + +---------------------------------------------------------------------- + VERSION 1.12 (2014-09-24) +----------------------------------------------------------------------- + +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.12 + +- Added IO.FontBaseScale value for easy scaling of all windows. +- Added IsMouseHoveringWindow(), IsMouseHoveringAnyWindow(), IsPosHoveringAnyWindow() helpers. +- Added va_list variations of all functions taking ellipsis (...) parameters. +- Added section in documentation to explicitly document cases of API breaking changes (e.g. renamed IM_MALLOC below). +- Moved IM_MALLOC / IM_FREE defines. to IO structure members that can be set at runtime (also allowing precompiled ImGui to cover more use cases). +- Fixed OpenGL samples for Retina display. +- Comments and minor fixes. + + +---------------------------------------------------------------------- + VERSION 1.11 (2014-09-10) +----------------------------------------------------------------------- + +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.11 + +- Added more comments in the code. +- Made radio buttons render ascii when logged into tty/file/clipboard. +- Added ImGuiInputTextFlags_EnterReturnsTrue flag to InputText() and variants. +- Added #define IMGUI_INCLUDE_IMGUI_USER_CPP to optionally include imgui_user.cpp from the end of imgui.cpp +- Fixed file-descriptor leak if ImBitmapFont::LoadFromFile() calls to fseek/ftell fails. + + +---------------------------------------------------------------------- + VERSION 1.10 (2014-08-31) +----------------------------------------------------------------------- + +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.10 + +- User can override memory allocators by #define-ing IM_MALLOC, IM_FREE, IM_REALLOC, +- Added SetCursorPosX(), SetCursorPosY() shortcuts. +- Checkbox() returns true when pressed. +- Added optional external fonts data in extra_fonts/ for reference. +- Removed the need to setup IO.FontHeight when using a custom font. +- Added comments on external fonts usage. + + +---------------------------------------------------------------------- + VERSION 1.09 (2014-08-28) +----------------------------------------------------------------------- + +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.09 + +Breaking Changes: + +- The behaviour of PixelCenterOffset changed! You may need to change your value if you had set it to non-default in your code and/or offset your projection matrix by 0.5 pixels. It is likely that the default PixelCenterOffset value of 0.0 is now suitable unless your rendering uses some form of multisampling. + +Other Changes: + +- Various minor render tweaks and fixes. Better support for renderers using multisampling. +- Moved IMGUI_FONT_TEX_UV_FOR_WHITE #define to a variable in the IO structure so font can be changed at runtime. +- Minor other fixes, tweaks, comments. + + +---------------------------------------------------------------------- + VERSION 1.08 (2014-08-25) +----------------------------------------------------------------------- + +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.09 + +- Fixed ImGuiTextFilter trimming of leading/trailing blanks. +- Fixed file descriptor leak on LoadSettings() failure. +- Fix type conversion compiler warnings. +- Added basic sizes edition in the style editor. +- Added CalcTextSize(), GetCursorScreenPos() functions. +- Disable client state in OpenGL example after rendering. +- Converted all Tabs to Spaces in sources. + + +---------------------------------------------------------------------- + VERSION 1.07 (2014-08-18) +----------------------------------------------------------------------- + +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.07 + +- Added InputFloat4(), SliderFloat4() helpers. +- Added global Alpha in ImGuiStyle structure. When Alpha=0.0, ImGui skips most of logic and all rendering processing. +- Fix clipping of title bar text. +- Fix to allow the user to call NewFrame() multiple times without calling Render(). +- Reduce inner window clipping to take account for the extend of CollapsingHeader() - share same clipping rectangle. +- Fix for child windows with inverted clip rectangles (when scrolled and out of screen, Etc.). +- Minor fixes, tweaks, comments. + + +---------------------------------------------------------------------- + VERSION 1.06 (2014-08-15) +----------------------------------------------------------------------- + +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.06 + +- Added BeginTooltip()/EndTooltip() helpers to create tooltips with custom contents. +- Added TextColored() helper. +- Added a 'stride' parameter to PlotLines() / PlotHistogram(). +- Fixed PlotLines() / PlotHistogram() from occasionally wrapping back to the most-left value. +- TreeNode() / CollapsingHeader() ignore clicks when CTRL or SHIFT are held. +- Slowed down mouse wheel scrolling inside combo boxes. +- Minor tweaks. +- Fixed trailing '\n' in text strings reporting extra line height. +- Fixed tooltip position needlessly leaking into .ini file. +- Fixed invalid .ini file data persistently being saved back into the file. + + +---------------------------------------------------------------------- + VERSION 1.05 (2014-08-14) +----------------------------------------------------------------------- + +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.05 + +- Added default clipboard functions for Windows + "private" clipboard on other systems (user can still override). +- Fixed logarithmic sliders and HSV conversions on Mac/Linux. +- Tidying up example applications so it looks easier to just grab code. +- Added GetItemBoxMin(), GetItemBoxMax(). +- Tweaks, more consistent #define names. +- Fix for doing multiple Begin()/End() during the same frame. + + +---------------------------------------------------------------------- + VERSION 1.04 (2014-08-13) +----------------------------------------------------------------------- + +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.04 + +- Fixes (v1.03 introduced a bug with combo box & scissoring bug OpenGL sample). +- Added ImGui::InputFloat2() and ImGui::SliderFloat2() functions. + + +---------------------------------------------------------------------- + VERSION 1.03 (2014-08-13) +----------------------------------------------------------------------- + +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.03 + +- OpenGL example now use the fixed function-pipeline + cleanups, down by 150 lines. +- Added quick & dirty Makefiles for MacOSX and Linux. +- Simplified the DrawList system, ImDrawCmd include the clipping rectangle + some optimisations. +- Fixed warnings for more stringent compilation settings. + + +---------------------------------------------------------------------- + VERSION 1.02 (2014-08-12) +----------------------------------------------------------------------- + +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.02 + +- Comments. +- Portability fixes. +- Fixing and tidying up sample applications. +- Checkboxes and radio buttons can be clicked on their labels as well as their icon. +- Checkboxes and radio buttons display in a different color when hovered. + + +---------------------------------------------------------------------- + VERSION 1.01 (2014-08-11) +----------------------------------------------------------------------- + +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.01 + +- Added PixelCenterOffset for OpenGL/DirectX compatibility. +- Commented and tweaked samples. +- Added Git ignore list. + + +---------------------------------------------------------------------- + VERSION 1.00 (2014-08-10) +----------------------------------------------------------------------- + +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.00 + +- Initial release. diff --git a/extern/imgui_patched/docs/CONTRIBUTING.md b/extern/imgui_patched/docs/CONTRIBUTING.md new file mode 100644 index 00000000..81a6f0e3 --- /dev/null +++ b/extern/imgui_patched/docs/CONTRIBUTING.md @@ -0,0 +1,80 @@ +# Contributing Guidelines + +## Index + +- [Getting Started & General Advice](#getting-started--general-advice) +- [Issues vs Discussions](#issues-vs-discussions) +- [How to open an Issue](#how-to-open-an-issue) +- [How to open a Pull Request](#how-to-open-a-pull-request) +- [Copyright / Contributor License Agreement](#copyright--contributor-license-agreement) + +## Getting Started & General Advice + +- Article: [How To Ask Good Questions](https://bit.ly/3nwRnx1). +- Please browse the [Wiki](https://github.com/ocornut/imgui/wiki) to find code snippets, links and other resources (e.g. [Useful extensions](https://github.com/ocornut/imgui/wiki/Useful-Extensions)). +- Please read [docs/FAQ.md](https://github.com/ocornut/imgui/blob/master/docs/FAQ.md). +- Please read [docs/FONTS.md](https://github.com/ocornut/imgui/blob/master/docs/FONTS.md) if your question relates to fonts or text. +- Please read one of the [examples/](https://github.com/ocornut/imgui/tree/master/examples) application if your question relates to setting up Dear ImGui. +- Please run `ImGui::ShowDemoWindow()` to explore the demo and its sources. +- Please use the search function of your IDE to search in for comments related to your situation. +- Please use the search function of GitHub to look for similar issues. You may [browse issues by Labels](https://github.com/ocornut/imgui/labels). +- Please use a web search engine to look for similar issues. +- If you get a crash or assert, use a debugger to locate the line triggering it and read the comments around. +- Please don't be a [Help Vampire](https://slash7.com/2006/12/22/vampires/). + +## Issues vs Discussions + +If you: +- Cannot BUILD or LINK examples. +- Cannot BUILD, or LINK, or RUN Dear ImGui in your application or custom engine. +- Cannot LOAD a font. + +Then please [use the Discussions forums](https://github.com/ocornut/imgui/discussions) instead of opening an issue. + +If Dear ImGui is successfully showing in your app and you have used Dear ImGui before, you can open an issue. Any form of discussions is welcome as a new issue. + +## How to open an issue + +You may use the Issue Tracker to submit bug reports, feature requests or suggestions. You may ask for help or advice as well. But **PLEASE CAREFULLY READ THIS WALL OF TEXT. ISSUES IGNORING THOSE GUIDELINES MAY BE CLOSED. USERS IGNORING THOSE GUIDELINES MIGHT BE BLOCKED.** + +Please do your best to clarify your request. The amount of incomplete or ambiguous requests due to people not following those guidelines is often overwhelming. Issues created without the requested information may be closed prematurely. Exceptionally entitled, impolite, or lazy requests may lead to bans. + +**PLEASE UNDERSTAND THAT OPEN-SOURCE SOFTWARE LIVES OR DIES BY THE AMOUNT OF ENERGY MAINTAINERS CAN SPARE. WE HAVE LOTS OF STUFF TO DO. THIS IS AN ATTENTION ECONOMY AND MANY LAZY OR MINOR ISSUES ARE HOGGING OUR ATTENTION AND DRAINING ENERGY, TAKING US AWAY FROM MORE IMPORTANT WORK.** + +Steps: + +- Article: [How To Ask Good Questions](https://bit.ly/3nwRnx1). +- **PLEASE DO FILL THE REQUESTED NEW ISSUE TEMPLATE.** Including Dear ImGui version number, branch name, platform/renderer back-ends (imgui_impl_XXX files), operating system. +- **Try to be explicit with your GOALS, your EXPECTATIONS and what you have tried**. Be mindful of [The XY Problem](http://xyproblem.info/). What you have in mind or in your code is not obvious to other people. People frequently discuss problems and suggest incorrect solutions without first clarifying their goals. When requesting a new feature, please describe the usage context (how you intend to use it, why you need it, etc.). If you tried something and it failed, show us what you tried. +- **Attach screenshots (or GIF/video) to clarify the context**. They often convey useful information that is omitted by the description. You can drag pictures/files in the message edit box. Avoid using 3rd party image hosting services, prefer the long-term longevity of GitHub attachments (you can drag pictures into your post). On Windows, you can use [ScreenToGif](https://www.screentogif.com/) to easily capture .gif files. +- **If you are discussing an assert or a crash, please provide a debugger callstack**. Never state "it crashes" without additional information. If you don't know how to use a debugger and retrieve a callstack, learning about it will be useful. +- **Please make sure that your project has asserts enabled.** Calls to IM_ASSERT() are scattered in the code to help catch common issues. When an assert is triggered read the comments around it. By default IM_ASSERT() calls the standard assert() function. To verify that your asserts are enabled, add the line `IM_ASSERT(false);` in your main() function. Your application should display an error message and abort. If your application doesn't report an error, your asserts are disabled. +- **Please provide a Minimal, Complete, and Verifiable Example ([MCVE](https://stackoverflow.com/help/mcve)) to demonstrate your problem**. An ideal submission includes a small piece of code that anyone can paste into one of the examples applications (examples/../main.cpp) or demo (imgui_demo.cpp) to understand and reproduce it. Narrowing your problem to its shortest and purest form is the easiest way to understand it. Please test your shortened code to ensure it exhibits the problem. **Often while creating the MCVE you will end up solving the problem!** Many questions that are missing a standalone verifiable example are missing the actual cause of their issue in the description, which ends up wasting everyone's time. +- Please state if you have made substantial modifications to your copy of Dear ImGui or the back-end. +- If you are not calling Dear ImGui directly from C++, please provide information about your Language and the wrapper/binding you are using. +- Be mindful that messages are being sent to the mailbox of "Watching" users. Try to proofread your messages before sending them. Edits are not seen by those users unless they browse the site. + +**Some unfortunate words of warning** +- If you are involved in cheating schemes (e.g. DLL injection) for competitive online multiplayer games, please don't try posting here. We won't answer and you will be blocked. It doesn't matter if your question relates to said project. We've had too many of you and need to project our time and sanity. +- Due to frequent abuse of this service from the aforementioned users, if your GitHub account is anonymous and was created five minutes ago please understand that your post will receive more scrutiny and incomplete questions will be harshly dismissed. + +If you have been using Dear ImGui for a while or have been using C/C++ for several years or have demonstrated good behavior here, it is ok to not fulfill every item to the letter. Those are guidelines and experienced users or members of the community will know which information is useful in a given context. + +## How to open a Pull Request + +- **Please understand that by submitting a PR you are also submitting a request for the maintainer to review your code and then take over its maintenance.** PR should be crafted both in the interest of the end-users and also to ease the maintainer into understanding and accepting it. +- Many PRs are useful to demonstrate a need and a possible solution but aren't adequate for merging (causing other issues, not seeing other aspects of the big picture, etc.). In doubt, don't hesitate to push a PR because that is always the first step toward finding the mergeable solution! Even if a PR stays unmerged for a long time, its presence can be useful for other users and helps toward finding a general solution. +- **When adding a feature,** please describe the usage context (how you intend to use it, why you need it, etc.). Be mindful of [The XY Problem](http://xyproblem.info/). +- **When fixing a warning or compilation problem,** please post the compiler log and specify the compiler version and platform you are using. +- **Attach screenshots (or GIF/video) to clarify the context and demonstrate the feature at a glance.** You can drag pictures/files in the message edit box. Prefer the long-term longevity of GitHub attachments over 3rd party hosting (you can drag pictures into your post). +- **Make sure your code follows the coding style already used in the codebase:** 4 spaces indentations (no tabs), `local_variable`, `FunctionName()`, `MemberName`, `// Text Comment`, `//CodeComment();`, C-style casts, etc.. We don't use modern C++ idioms and tend to use only a minimum of C++11 features. The applications under examples/ are generally less consistent because they sometimes try to mimic the coding style often adopted by a certain ecosystem (e.g. DirectX-related code tend to use the style of their sample). +- **Make sure you create a branch dedicated to the pull request**. In Git, 1 PR is associated to 1 branch. If you keep pushing to the same branch after you submitted the PR, your new commits will appear in the PR (we can still cherry-pick individual commits). + +Thank you for reading! + +## Copyright / Contributor License Agreement + +Any code you submit will become part of the repository and be distributed under the [Dear ImGui license](https://github.com/ocornut/imgui/blob/master/LICENSE.txt). By submitting code to the project you agree that the code is your work and that you can give it to the project. + +You also agree by submitting your code that you grant all transferrable rights to the code to the project maintainer, including for example re-licensing the code, modifying the code, and distributing it in source or binary forms. Specifically, this includes a requirement that you assign copyright to the project maintainer. For this reason, do not modify any copyright statements in files in any PRs. + diff --git a/extern/imgui_patched/docs/EXAMPLES.md b/extern/imgui_patched/docs/EXAMPLES.md index 94f78dcd..6c1bac3c 100644 --- a/extern/imgui_patched/docs/EXAMPLES.md +++ b/extern/imgui_patched/docs/EXAMPLES.md @@ -10,67 +10,71 @@ integrating Dear ImGui in your own application/game/engine. **Once Dear ImGui is setup and running, run and refer to `ImGui::ShowDemoWindow()` in imgui_demo.cpp for usage of the end-user API.** You can find Windows binaries for some of those example applications at: - http://www.dearimgui.org/binaries + http://www.dearimgui.com/binaries ### Getting Started Integration in a typical existing application, should take <20 lines when using standard backends. - At initialization: - call ImGui::CreateContext() - call ImGui_ImplXXXX_Init() for each backend. +```cpp +At initialization: + call ImGui::CreateContext() + call ImGui_ImplXXXX_Init() for each backend. - At the beginning of your frame: - call ImGui_ImplXXXX_NewFrame() for each backend. - call ImGui::NewFrame() +At the beginning of your frame: + call ImGui_ImplXXXX_NewFrame() for each backend. + call ImGui::NewFrame() - At the end of your frame: - call ImGui::Render() - call ImGui_ImplXXXX_RenderDrawData() for your Renderer backend. +At the end of your frame: + call ImGui::Render() + call ImGui_ImplXXXX_RenderDrawData() for your Renderer backend. - At shutdown: - call ImGui_ImplXXXX_Shutdown() for each backend. - call ImGui::DestroyContext() +At shutdown: + call ImGui_ImplXXXX_Shutdown() for each backend. + call ImGui::DestroyContext() +``` Example (using [backends/imgui_impl_win32.cpp](https://github.com/ocornut/imgui/blob/master/backends/imgui_impl_win32.cpp) + [backends/imgui_impl_dx11.cpp](https://github.com/ocornut/imgui/blob/master/backends/imgui_impl_dx11.cpp)): - // Create a Dear ImGui context, setup some options - ImGui::CreateContext(); - ImGuiIO& io = ImGui::GetIO(); - io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable some options +```cpp +// Create a Dear ImGui context, setup some options +ImGui::CreateContext(); +ImGuiIO& io = ImGui::GetIO(); +io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable some options - // Initialize Platform + Renderer backends (here: using imgui_impl_win32.cpp + imgui_impl_dx11.cpp) - ImGui_ImplWin32_Init(my_hwnd); - ImGui_ImplDX11_Init(my_d3d_device, my_d3d_device_context); +// Initialize Platform + Renderer backends (here: using imgui_impl_win32.cpp + imgui_impl_dx11.cpp) +ImGui_ImplWin32_Init(my_hwnd); +ImGui_ImplDX11_Init(my_d3d_device, my_d3d_device_context); - // Application main loop - while (true) - { - // Beginning of frame: update Renderer + Platform backend, start Dear ImGui frame - ImGui_ImplDX11_NewFrame(); - ImGui_ImplWin32_NewFrame(); - ImGui::NewFrame(); +// Application main loop +while (true) +{ + // Beginning of frame: update Renderer + Platform backend, start Dear ImGui frame + ImGui_ImplDX11_NewFrame(); + ImGui_ImplWin32_NewFrame(); + ImGui::NewFrame(); - // Any application code here - ImGui::Text("Hello, world!"); + // Any application code here + ImGui::Text("Hello, world!"); - // End of frame: render Dear ImGui - ImGui::Render(); - ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData()); + // End of frame: render Dear ImGui + ImGui::Render(); + ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData()); - // Swap - g_pSwapChain->Present(1, 0); - } + // Swap + g_pSwapChain->Present(1, 0); +} - // Shutdown - ImGui_ImplDX11_Shutdown(); - ImGui_ImplWin32_Shutdown(); - ImGui::DestroyContext(); +// Shutdown +ImGui_ImplDX11_Shutdown(); +ImGui_ImplWin32_Shutdown(); +ImGui::DestroyContext(); +``` Please read 'PROGRAMMER GUIDE' in imgui.cpp for notes on how to setup Dear ImGui in your codebase. Please read the comments and instruction at the top of each file. -Please read FAQ at http://www.dearimgui.org/faq +Please read FAQ at http://www.dearimgui.com/faq If you are using any of the backends provided here, you can add the backends/imgui_impl_xxxx(.cpp,.h) files to your project and use as-in. Each imgui_impl_xxxx.cpp file comes with its own individual @@ -100,15 +104,10 @@ OSX + OpenGL2 example.
(NB: imgui_impl_osx.mm is currently not as feature complete as other platforms backends. You may prefer to use the GLFW Or SDL backends, which will also support Windows and Linux.) -[example_emscripten_opengl3/](https://github.com/ocornut/imgui/blob/master/examples/example_emscripten_opengl3/)
-Emcripten + SDL2 + OpenGL3+/ES2/ES3 example.
-= main.cpp + imgui_impl_sdl.cpp + imgui_impl_opengl3.cpp
-Note that other examples based on SDL or GLFW + OpenGL could easily be modified to work with Emscripten. -We provide this to make the Emscripten differences obvious, and have them not pollute all other examples. - [example_emscripten_wgpu/](https://github.com/ocornut/imgui/blob/master/examples/example_emscripten_wgpu/)
Emcripten + GLFW + WebGPU example.
= main.cpp + imgui_impl_glfw.cpp + imgui_impl_wgpu.cpp +Note that the 'example_glfw_opengl3' and 'example_sdl2_opengl3' examples also supports Emscripten! [example_glfw_metal/](https://github.com/ocornut/imgui/blob/master/examples/example_glfw_metal/)
GLFW (Mac) + Metal example.
@@ -117,18 +116,18 @@ GLFW (Mac) + Metal example.
[example_glfw_opengl2/](https://github.com/ocornut/imgui/blob/master/examples/example_glfw_opengl2/)
GLFW + OpenGL2 example (legacy, fixed pipeline).
= main.cpp + imgui_impl_glfw.cpp + imgui_impl_opengl2.cpp
-**DO NOT USE THIS IF YOUR CODE/ENGINE IS USING MODERN OPENGL (SHADERS, VBO, VAO, etc.)**
+**DO NOT USE THIS IF YOUR CODE/ENGINE IS USING MODERN GL or WEBGL (SHADERS, VBO, VAO, etc.)**
This code is mostly provided as a reference to learn about Dear ImGui integration, because it is shorter. -If your code is using GL3+ context or any semi modern OpenGL calls, using this renderer is likely to -make things more complicated, will require your code to reset many OpenGL attributes to their initial +If your code is using GL3+ context or any semi modern GL calls, using this renderer is likely to +make things more complicated, will require your code to reset many GL attributes to their initial state, and might confuse your GPU driver. One star, not recommended. [example_glfw_opengl3/](https://github.com/ocornut/imgui/blob/master/examples/example_glfw_opengl3/)
GLFW (Win32, Mac, Linux) + OpenGL3+/ES2/ES3 example (modern, programmable pipeline).
= main.cpp + imgui_impl_glfw.cpp + imgui_impl_opengl3.cpp
-This uses more modern OpenGL calls and custom shaders.
-This may actually also work with OpenGL 2.x contexts!
-Prefer using that if you are using modern OpenGL in your application (anything with shaders). +This uses more modern GL calls and custom shaders.
+This support building with Emscripten and targetting WebGL.
+Prefer using that if you are using modern GL or WebGL in your application. [example_glfw_vulkan/](https://github.com/ocornut/imgui/blob/master/examples/example_glfw_vulkan/)
GLFW (Win32, Mac, Linux) + Vulkan example.
@@ -147,39 +146,39 @@ Null example, compile and link imgui, create context, run headless with no input This is used to quickly test compilation of core imgui files in as many setups as possible. Because this application doesn't create a window nor a graphic context, there's no graphics output. -[example_sdl_directx11/](https://github.com/ocornut/imgui/blob/master/examples/example_sdl_directx11/)
+[example_sdl2_directx11/](https://github.com/ocornut/imgui/blob/master/examples/example_sdl2_directx11/)
SDL2 + DirectX11 example, Windows only.
-= main.cpp + imgui_impl_sdl.cpp + imgui_impl_dx11.cpp
-This to demonstrate usage of DirectX with SDL. += main.cpp + imgui_impl_sdl2.cpp + imgui_impl_dx11.cpp
+This to demonstrate usage of DirectX with SDL2. -[example_sdl_metal/](https://github.com/ocornut/imgui/blob/master/examples/example_sdl_metal/)
-SDL2 (Mac) + Metal example.
-= main.mm + imgui_impl_sdl.cpp + imgui_impl_metal.mm +[example_sdl2_metal/](https://github.com/ocornut/imgui/blob/master/examples/example_sdl2_metal/)
+SDL2 + Metal example, Mac only.
+= main.mm + imgui_impl_sdl2.cpp + imgui_impl_metal.mm -[example_sdl_opengl2/](https://github.com/ocornut/imgui/blob/master/examples/example_sdl_opengl2/)
+[example_sdl2_opengl2/](https://github.com/ocornut/imgui/blob/master/examples/example_sdl2_opengl2/)
SDL2 (Win32, Mac, Linux etc.) + OpenGL example (legacy, fixed pipeline).
-= main.cpp + imgui_impl_sdl.cpp + imgui_impl_opengl2.cpp
-**DO NOT USE OPENGL2 CODE IF YOUR CODE/ENGINE IS USING MODERN OPENGL (SHADERS, VBO, VAO, etc.)**
+= main.cpp + imgui_impl_sdl2.cpp + imgui_impl_opengl2.cpp
+**DO NOT USE OPENGL2 CODE IF YOUR CODE/ENGINE IS USING GL OR WEBGL (SHADERS, VBO, VAO, etc.)**
This code is mostly provided as a reference to learn about Dear ImGui integration, because it is shorter. -If your code is using GL3+ context or any semi modern OpenGL calls, using this renderer is likely to -make things more complicated, will require your code to reset many OpenGL attributes to their initial +If your code is using GL3+ context or any semi modern GL calls, using this renderer is likely to +make things more complicated, will require your code to reset many GL attributes to their initial state, and might confuse your GPU driver. One star, not recommended. -[example_sdl_opengl3/](https://github.com/ocornut/imgui/blob/master/examples/example_sdl_opengl3/)
+[example_sdl2_opengl3/](https://github.com/ocornut/imgui/blob/master/examples/example_sdl2_opengl3/)
SDL2 (Win32, Mac, Linux, etc.) + OpenGL3+/ES2/ES3 example.
-= main.cpp + imgui_impl_sdl.cpp + imgui_impl_opengl3.cpp
-This uses more modern OpenGL calls and custom shaders.
-This may actually also work with OpenGL 2.x contexts!
+= main.cpp + imgui_impl_sdl2.cpp + imgui_impl_opengl3.cpp
+This uses more modern GL calls and custom shaders.
+This support building with Emscripten and targetting WebGL.
+Prefer using that if you are using modern GL or WebGL in your application. -[example_sdl_sdlrenderer/](https://github.com/ocornut/imgui/blob/master/examples/example_sdl_sdlrenderer/)
-SDL2 (Win32, Mac, Linux, etc.) + SDL_Renderer (most graphics backends are supported underneath)
-= main.cpp + imgui_impl_sdl.cpp + imgui_impl_sdlrenderer.cpp
-This requires SDL 2.0.17+ (expected to release November 2021)
-We do not really recommend using SDL_Renderer as it is a rather primitive API. +[example_sdl2_sdlrenderer2/](https://github.com/ocornut/imgui/blob/master/examples/example_sdl2_sdlrenderer2/)
+SDL2 (Win32, Mac, Linux, etc.) + SDL_Renderer for SDL2 (most graphics backends are supported underneath)
+= main.cpp + imgui_impl_sdl2.cpp + imgui_impl_sdlrenderer.cpp
+This requires SDL 2.0.18+ (released November 2021)
-[example_sdl_vulkan/](https://github.com/ocornut/imgui/blob/master/examples/example_sdl_vulkan/)
+[example_sdl2_vulkan/](https://github.com/ocornut/imgui/blob/master/examples/example_sdl2_vulkan/)
SDL2 (Win32, Mac, Linux, etc.) + Vulkan example.
-= main.cpp + imgui_impl_sdl.cpp + imgui_impl_vulkan.cpp
+= main.cpp + imgui_impl_sdl2.cpp + imgui_impl_vulkan.cpp
This is quite long and tedious, because: Vulkan.
For this example, the main.cpp file exceptionally use helpers function from imgui_impl_vulkan.h/cpp. @@ -200,8 +199,12 @@ DirectX12 example, Windows only.
= main.cpp + imgui_impl_win32.cpp + imgui_impl_dx12.cpp
This is quite long and tedious, because: DirectX12. +[example_win32_opengl3/](https://github.com/ocornut/imgui/blob/master/examples/example_win32_opengl3/)
+Raw Windows + OpenGL3 + example (modern, programmable pipeline)
+= main.cpp + imgui_impl_win32.cpp + imgui_impl_opengl3.cpp
-### Miscallaneous + +### Miscellaneous **Building** diff --git a/extern/imgui_patched/docs/FAQ.md b/extern/imgui_patched/docs/FAQ.md index 04774a78..2a2c9ebf 100644 --- a/extern/imgui_patched/docs/FAQ.md +++ b/extern/imgui_patched/docs/FAQ.md @@ -1,7 +1,7 @@ -# FAQ (Frequenty Asked Questions) +# FAQ (Frequently Asked Questions) You may link to this document using short form: - https://www.dearimgui.org/faq + https://www.dearimgui.com/faq or its real address: https://github.com/ocornut/imgui/blob/master/docs/FAQ.md or view this file with any Markdown viewer. @@ -25,7 +25,8 @@ or view this file with any Markdown viewer. | **Q&A: Usage** | | **[About the ID Stack system..
Why is my widget not reacting when I click on it?
How can I have widgets with an empty label?
How can I have multiple widgets with the same label?
How can I have multiple windows with the same label?](#q-about-the-id-stack-system)** | | [How can I display an image? What is ImTextureID, how does it work?](#q-how-can-i-display-an-image-what-is-imtextureid-how-does-it-work)| -| [How can I use my own math types instead of ImVec2/ImVec4?](#q-how-can-i-use-my-own-math-types-instead-of-imvec2imvec4) | +| [How can I use maths operators with ImVec2?](#q-how-can-i-use-maths-operators-with-imvec2) | +| [How can I use my own maths types instead of ImVec2/ImVec4?](#q-how-can-i-use-my-own-maths-types-instead-of-imvec2imvec4) | | [How can I interact with standard C++ types (such as std::string and std::vector)?](#q-how-can-i-interact-with-standard-c-types-such-as-stdstring-and-stdvector) | | [How can I display custom shapes? (using low-level ImDrawList API)](#q-how-can-i-display-custom-shapes-using-low-level-imdrawlist-api) | | **Q&A: Fonts, Text** | @@ -56,7 +57,7 @@ or view this file with any Markdown viewer. - The [Glossary](https://github.com/ocornut/imgui/wiki/Glossary) page may be useful. - The [Issues](https://github.com/ocornut/imgui/issues) and [Discussions](https://github.com/ocornut/imgui/discussions) sections can be searched for past questions and issues. - Your programming IDE is your friend, find the type or function declaration to find comments associated with it. -- The `ImGui::ShowMetricsWindow()` function exposes lots of internal information and tools. Although it is primary designed as a debugging tool, having access to that information tends to help understands concepts. +- The `ImGui::ShowMetricsWindow()` function exposes lots of internal information and tools. Although it is primarily designed as a debugging tool, having access to that information tends to help understands concepts. ##### [Return to Index](#index) @@ -123,7 +124,7 @@ void MyLowLevelMouseButtonHandler(int button, bool down) ``` -**Note:** The `io.WantCaptureMouse` is more correct that any manual attempt to "check if the mouse is hovering a window" (don't do that!). It handle mouse dragging correctly (both dragging that started over your application or over a Dear ImGui window) and handle e.g. popup and modal windows blocking inputs. +**Note:** The `io.WantCaptureMouse` is more correct that any manual attempt to "check if the mouse is hovering a window" (don't do that!). It handles mouse dragging correctly (both dragging that started over your application or over a Dear ImGui window) and handle e.g. popup and modal windows blocking inputs. **Note:** Those flags are updated by `ImGui::NewFrame()`. However it is generally more correct and easier that you poll flags from the previous frame, then submit your inputs, then call `NewFrame()`. If you attempt to do the opposite (which is generally harder) you are likely going to submit your inputs after `NewFrame()`, and therefore too late. @@ -139,7 +140,7 @@ void MyLowLevelMouseButtonHandler(int button, bool down) - The gamepad/keyboard navigation is fairly functional and keeps being improved. The initial focus was to support game controllers, but keyboard is becoming increasingly and decently usable. Gamepad support is particularly useful to use Dear ImGui on a game console (e.g. PS4, Switch, XB1) without a mouse connected! - Keyboard: set `io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard` to enable. - Gamepad: set `io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad` to enable (with a supporting backend). -- See [Control Sheets for Gamepads](http://www.dearimgui.org/controls_sheets) (reference PNG/PSD for PS4, XB1, Switch gamepads). +- See [Control Sheets for Gamepads](http://www.dearimgui.com/controls_sheets) (reference PNG/PSD for PS4, XB1, Switch gamepads). - See `USING GAMEPAD/KEYBOARD NAVIGATION CONTROLS` section of [imgui.cpp](https://github.com/ocornut/imgui/blob/master/imgui.cpp) for more details. ##### [Return to Index](#index) @@ -177,8 +178,21 @@ Each draw command needs the triangle rendered using the clipping rectangle provi Rectangles provided by Dear ImGui are defined as `(x1=left,y1=top,x2=right,y2=bottom)` and **NOT** as -`(x1,y1,width,height)` -Refer to rendering backends in the [examples/](https://github.com/ocornut/imgui/tree/master/examples) folder for references of how to handle the `ClipRect` field. +`(x1,y1,width,height)`. +Refer to rendering backends in the [backends/](https://github.com/ocornut/imgui/tree/master/backends) folder for references of how to handle the `ClipRect` field. +For example, the [DirectX11 backend](https://github.com/ocornut/imgui/blob/master/backends/imgui_impl_dx11.cpp) does this: +```cpp +// Project scissor/clipping rectangles into framebuffer space +ImVec2 clip_off = draw_data->DisplayPos; +ImVec2 clip_min(pcmd->ClipRect.x - clip_off.x, pcmd->ClipRect.y - clip_off.y); +ImVec2 clip_max(pcmd->ClipRect.z - clip_off.x, pcmd->ClipRect.w - clip_off.y); +if (clip_max.x <= clip_min.x || clip_max.y <= clip_min.y) + continue; + +// Apply scissor/clipping rectangle +const D3D11_RECT r = { (LONG)clip_min.x, (LONG)clip_min.y, (LONG)clip_max.x, (LONG)clip_max.y }; +ctx->RSSetScissorRects(1, &r); +``` ##### [Return to Index](#index) @@ -198,10 +212,10 @@ Dear ImGui internally needs to uniquely identify UI elements. Elements that are typically not clickable (such as calls to the Text functions) don't need an ID. Interactive widgets (such as calls to Button buttons) need a unique ID. -**Unique ID are used internally to track active widgets and occasionally associate state to widgets.
-Unique ID are implicitly built from the hash of multiple elements that identify the "path" to the UI element.** +**Unique IDs are used internally to track active widgets and occasionally associate state to widgets.
+Unique IDs are implicitly built from the hash of multiple elements that identify the "path" to the UI element.** -Since Dear ImGui 1.85 you can use `Demo>Tools>Stack Tool` or call `ImGui::ShowStackToolWindow()`. The tool display intermediate values leading to the creation of a unique ID, making things easier to debug and understand. +Since Dear ImGui 1.85, you can use `Demo>Tools>Stack Tool` or call `ImGui::ShowStackToolWindow()`. The tool display intermediate values leading to the creation of a unique ID, making things easier to debug and understand. ![Stack tool](https://user-images.githubusercontent.com/8225057/136235657-a0ea5665-dcd1-423f-9be6-dc3f8ced8f12.png) @@ -240,12 +254,12 @@ Button("OK"); // ERROR: ID collision with the first button! Interacting wit Button(""); // ERROR: ID collision with Begin("MyWindow")! End(); ``` -Fear not! this is easy to solve and there are many ways to solve it! +Fear not! This is easy to solve and there are many ways to solve it! - Solving ID conflict in a simple/local context: -When passing a label you can optionally specify extra ID information within string itself. +When passing a label you can optionally specify extra ID information within the string itself. Use "##" to pass a complement to the ID that won't be visible to the end-user. -This helps solving the simple collision cases when you know e.g. at compilation time which items +This helps solve the simple collision cases when you know e.g. at compilation time which items are going to be created: ```cpp Begin("MyWindow"); @@ -259,8 +273,8 @@ End(); ```cpp Checkbox("##On", &b); // Label = "", ID = hash of (..., "##On") // No visible label, just a checkbox! ``` -- Occasionally/rarely you might want change a label while preserving a constant ID. This allows -you to animate labels. For example you may want to include varying information in a window title bar, +- Occasionally/rarely you might want to change a label while preserving a constant ID. This allows +you to animate labels. For example, you may want to include varying information in a window title bar, but windows are uniquely identified by their ID. Use "###" to pass a label that isn't part of ID: ```cpp Button("Hello###ID"); // Label = "Hello", ID = hash of (..., "###ID") @@ -273,9 +287,9 @@ Begin(buf); // Variable title, ID = hash of "MyGame" Use `PushID()` / `PopID()` to create scopes and manipulate the ID stack, as to avoid ID conflicts within the same window. This is the most convenient way of distinguishing ID when iterating and creating many UI elements programmatically. -You can push a pointer, a string or an integer value into the ID stack. -Remember that ID are formed from the concatenation of _everything_ pushed into the ID stack. -At each level of the stack we store the seed used for items at this level of the ID stack. +You can push a pointer, a string, or an integer value into the ID stack. +Remember that IDs are formed from the concatenation of _everything_ pushed into the ID stack. +At each level of the stack, we store the seed used for items at this level of the ID stack. ```cpp Begin("Window"); for (int i = 0; i < 100; i++) @@ -310,7 +324,7 @@ PushID("node"); PopID(); PopID(); ``` -- Tree nodes implicitly creates a scope for you by calling `PushID()`: +- Tree nodes implicitly create a scope for you by calling `PushID()`: ```cpp Button("Click"); // Label = "Click", ID = hash of (..., "Click") if (TreeNode("node")) // <-- this function call will do a PushID() for you (unless instructed not to, with a special flag) @@ -320,8 +334,8 @@ if (TreeNode("node")) // <-- this function call will do a PushID() for you (unl } ``` -When working with trees, ID are used to preserve the open/close state of each tree node. -Depending on your use cases you may want to use strings, indices or pointers as ID. +When working with trees, IDs are used to preserve the open/close state of each tree node. +Depending on your use cases you may want to use strings, indices, or pointers as ID. - e.g. when following a single pointer that may change over time, using a static string as ID will preserve your node open/closed state when the targeted object change. - e.g. when displaying a list of objects, using indices or pointers as ID will preserve the @@ -342,11 +356,11 @@ Short explanation: **Please read documentations or tutorials on your graphics API to understand how to display textures on the screen before moving onward.** Long explanation: -- Dear ImGui's job is to create "meshes", defined in a renderer-agnostic format made of draw commands and vertices. At the end of the frame those meshes (ImDrawList) will be displayed by your rendering function. They are made up of textured polygons and the code to render them is generally fairly short (a few dozen lines). In the examples/ folder we provide functions for popular graphics API (OpenGL, DirectX, etc.). +- Dear ImGui's job is to create "meshes", defined in a renderer-agnostic format made of draw commands and vertices. At the end of the frame, those meshes (ImDrawList) will be displayed by your rendering function. They are made up of textured polygons and the code to render them is generally fairly short (a few dozen lines). In the examples/ folder, we provide functions for popular graphics APIs (OpenGL, DirectX, etc.). - Each rendering function decides on a data type to represent "textures". The concept of what is a "texture" is entirely tied to your underlying engine/graphics API. We carry the information to identify a "texture" in the ImTextureID type. -ImTextureID is nothing more that a void*, aka 4/8 bytes worth of data: just enough to store 1 pointer or 1 integer of your choice. -Dear ImGui doesn't know or understand what you are storing in ImTextureID, it merely pass ImTextureID values until they reach your rendering function. +ImTextureID is nothing more than a void*, aka 4/8 bytes worth of data: just enough to store one pointer or integer of your choice. +Dear ImGui doesn't know or understand what you are storing in ImTextureID, it merely passes ImTextureID values until they reach your rendering function. - In the [examples/](https://github.com/ocornut/imgui/tree/master/examples) backends, for each graphics API we decided on a type that is likely to be a good representation for specifying an image from the end-user perspective. This is what the _examples_ rendering functions are using: ```cpp OpenGL: @@ -371,9 +385,9 @@ DirectX12: For example, in the OpenGL example backend we store raw OpenGL texture identifier (GLuint) inside ImTextureID. Whereas in the DirectX11 example backend we store a pointer to ID3D11ShaderResourceView inside ImTextureID, which is a higher-level structure tying together both the texture and information about its format and how to read it. -- If you have a custom engine built over e.g. OpenGL, instead of passing GLuint around you may decide to use a high-level data type to carry information about the texture as well as how to display it (shaders, etc.). The decision of what to use as ImTextureID can always be made better knowing how your codebase is designed. If your engine has high-level data types for "textures" and "material" then you may want to use them. +- If you have a custom engine built over e.g. OpenGL, instead of passing GLuint around you may decide to use a high-level data type to carry information about the texture as well as how to display it (shaders, etc.). The decision of what to use as ImTextureID can always be made better by knowing how your codebase is designed. If your engine has high-level data types for "textures" and "material" then you may want to use them. If you are starting with OpenGL or DirectX or Vulkan and haven't built much of a rendering engine over them, keeping the default ImTextureID representation suggested by the example backends is probably the best choice. -(Advanced users may also decide to keep a low-level type in ImTextureID, and use ImDrawList callback and pass information to their renderer) +(Advanced users may also decide to keep a low-level type in ImTextureID, use ImDrawList callback and pass information to their renderer) User code may do: ```cpp @@ -387,15 +401,15 @@ The renderer function called after ImGui::Render() will receive that same value MyTexture* texture = (MyTexture*)pcmd->GetTexID(); MyEngineBindTexture2D(texture); ``` -Once you understand this design you will understand that loading image files and turning them into displayable textures is not within the scope of Dear ImGui. -This is by design and is actually a good thing, because it means your code has full control over your data types and how you display them. -If you want to display an image file (e.g. PNG file) into the screen, please refer to documentation and tutorials for the graphics API you are using. +Once you understand this design, you will understand that loading image files and turning them into displayable textures is not within the scope of Dear ImGui. +This is by design and is a good thing because it means your code has full control over your data types and how you display them. +If you want to display an image file (e.g. PNG file) on the screen, please refer to documentation and tutorials for the graphics API you are using. Refer to [Image Loading and Displaying Examples](https://github.com/ocornut/imgui/wiki/Image-Loading-and-Displaying-Examples) on the [Wiki](https://github.com/ocornut/imgui/wiki) to find simplified examples for loading textures with OpenGL, DirectX9 and DirectX11. C/C++ tip: a void* is pointer-sized storage. You may safely store any pointer or integer into it by casting your value to ImTextureID / void*, and vice-versa. Because both end-points (user code and rendering function) are under your control, you know exactly what is stored inside the ImTextureID / void*. -Examples: +Here are some examples: ```cpp GLuint my_tex = XXX; void* my_void_ptr; @@ -413,17 +427,25 @@ Finally, you may call `ImGui::ShowMetricsWindow()` to explore/visualize/understa --- -### Q: How can I use my own math types instead of ImVec2/ImVec4? +### Q: How can I use maths operators with ImVec2? -You can edit [imconfig.h](https://github.com/ocornut/imgui/blob/master/imconfig.h) and setup the `IM_VEC2_CLASS_EXTRA`/`IM_VEC4_CLASS_EXTRA` macros to add implicit type conversions. -This way you'll be able to use your own types everywhere, e.g. passing `MyVector2` or `glm::vec2` to ImGui functions instead of `ImVec2`. +We do not export maths operators by default in imgui.h in order to not conflict with the use of your own maths types and maths operators. As a convenience, you may use `#defne IMGUI_DEFINE_MATH_OPERATORS` + `#include "imgui.h"` to access our basic maths operators. + +##### [Return to Index](#index) + +--- + +### Q: How can I use my own maths types instead of ImVec2/ImVec4? + +You can setup your [imconfig.h](https://github.com/ocornut/imgui/blob/master/imconfig.h) file with `IM_VEC2_CLASS_EXTRA`/`IM_VEC4_CLASS_EXTRA` macros to add implicit type conversions to our own maths types. +This way you will be able to use your own types everywhere, e.g. passing `MyVector2` or `glm::vec2` to ImGui functions instead of `ImVec2`. ##### [Return to Index](#index) --- ### Q: How can I interact with standard C++ types (such as std::string and std::vector)? -- Being highly portable (backends/bindings for several languages, frameworks, programming style, obscure or older platforms/compilers), and aiming for compatibility & performance suitable for every modern real-time game engines, dear imgui does not use any of std C++ types. We use raw types (e.g. char* instead of std::string) because they adapt to more use cases. +- Being highly portable (backends/bindings for several languages, frameworks, programming styles, obscure or older platforms/compilers), and aiming for compatibility & performance suitable for every modern real-time game engine, Dear ImGui does not use any of std C++ types. We use raw types (e.g. char* instead of std::string) because they adapt to more use cases. - To use ImGui::InputText() with a std::string or any resizable string class, see [misc/cpp/imgui_stdlib.h](https://github.com/ocornut/imgui/blob/master/misc/cpp/imgui_stdlib.h). - To use combo boxes and list boxes with `std::vector` or any other data structure: the `BeginCombo()/EndCombo()` API lets you iterate and submit items yourself, so does the `ListBoxHeader()/ListBoxFooter()` API. @@ -432,12 +454,12 @@ Prefer using them over the old and awkward `Combo()/ListBox()` api. You may write your own one-liner wrappers to facilitate user code (tip: add new functions in ImGui:: namespace from your code). - Dear ImGui applications often need to make intensive use of strings. It is expected that many of the strings you will pass to the API are raw literals (free in C/C++) or allocated in a manner that won't incur a large cost on your application. -Please bear in mind that using `std::string` on applications with large amount of UI may incur unsatisfactory performances. +Please bear in mind that using `std::string` on applications with a large amount of UI may incur unsatisfactory performances. Modern implementations of `std::string` often include small-string optimization (which is often a local buffer) but those are not configurable and not the same across implementations. -- If you are finding your UI traversal cost to be too large, make sure your string usage is not leading to excessive amount -of heap allocations. Consider using literals, statically sized buffers and your own helper functions. A common pattern -is that you will need to build lots of strings on the fly, and their maximum length can be easily be scoped ahead. +- If you are finding your UI traversal cost to be too large, make sure your string usage is not leading to an excessive amount +of heap allocations. Consider using literals, statically sized buffers, and your own helper functions. A common pattern +is that you will need to build lots of strings on the fly, and their maximum length can be easily scoped ahead. One possible implementation of a helper to facilitate printf-style building of strings: https://github.com/ocornut/Str This is a small helper where you can instance strings with configurable local buffers length. Many game engines will provide similar or better string helpers. @@ -458,7 +480,7 @@ ImDrawList* draw_list = ImGui::GetWindowDrawList(); ImVec2 p = ImGui::GetCursorScreenPos(); // Draw a red circle -draw_list->AddCircleFilled(ImVec2(p.x + 50, p.y + 50), 30.0f, IM_COL32(255, 0, 0, 255), 16); +draw_list->AddCircleFilled(ImVec2(p.x + 50, p.y + 50), 30.0f, IM_COL32(255, 0, 0, 255)); // Draw a 3 pixel thick yellow line draw_list->AddLine(ImVec2(p.x, p.y), ImVec2(p.x + 100.0f, p.y + 100.0f), IM_COL32(255, 255, 0, 255), 3.0f); @@ -472,8 +494,8 @@ ImGui::End(); - Refer to "Demo > Examples > Custom Rendering" in the demo window and read the code of `ShowExampleAppCustomRendering()` in `imgui_demo.cpp` from more examples. - To generate colors: you can use the macro `IM_COL32(255,255,255,255)` to generate them at compile time, or use `ImGui::GetColorU32(IM_COL32(255,255,255,255))` or `ImGui::GetColorU32(ImVec4(1.0f,1.0f,1.0f,1.0f))` to generate a color that is multiplied by the current value of `style.Alpha`. -- Math operators: if you have setup `IM_VEC2_CLASS_EXTRA` in `imconfig.h` to bind your own math types, you can use your own math types and their natural operators instead of ImVec2. ImVec2 by default doesn't export any math operators in the public API. You may use `#define IMGUI_DEFINE_MATH_OPERATORS` `#include "imgui_internal.h"` to use the internally defined math operators, but instead prefer using your own math library and set it up in `imconfig.h`. -- You can use `ImGui::GetBackgroundDrawList()` or `ImGui::GetForegroundDrawList()` to access draw lists which will be displayed behind and over every other dear imgui windows (one bg/fg drawlist per viewport). This is very convenient if you need to quickly display something on the screen that is not associated to a dear imgui window. +- Math operators: if you have setup `IM_VEC2_CLASS_EXTRA` in `imconfig.h` to bind your own math types, you can use your own math types and their natural operators instead of ImVec2. ImVec2 by default doesn't export any math operators in the public API. You may use `#define IMGUI_DEFINE_MATH_OPERATORS` `#include "imgui.h"` to use our math operators, but instead prefer using your own math library and set it up in `imconfig.h`. +- You can use `ImGui::GetBackgroundDrawList()` or `ImGui::GetForegroundDrawList()` to access draw lists which will be displayed behind and over every other Dear ImGui window (one bg/fg drawlist per viewport). This is very convenient if you need to quickly display something on the screen that is not associated with a Dear ImGui window. - You can also create your own empty window and draw inside it. Call Begin() with the NoBackground | NoDecoration | NoSavedSettings | NoInputs flags (The `ImGuiWindowFlags_NoDecoration` flag itself is a shortcut for NoTitleBar | NoResize | NoScrollbar | NoCollapse). Then you can retrieve the ImDrawList* via `GetWindowDrawList()` and draw to it in any way you like. - You can create your own ImDrawList instance. You'll need to initialize them with `ImGui::GetDrawListSharedData()`, or create your own instancing `ImDrawListSharedData`, and then call your renderer function with your own ImDrawList or ImDrawData data. - Looking for fun? The [ImDrawList coding party 2020](https://github.com/ocornut/imgui/issues/3606) thread is full of "don't do this at home" extreme uses of the ImDrawList API. @@ -486,7 +508,7 @@ ImGui::End(); ### Q: How should I handle DPI in my application? -The short answer is: obtain the desired DPI scale, load your fonts resized with that scale (always round down fonts size to nearest integer), and scale your Style structure accordingly using `style.ScaleAllSizes()`. +The short answer is: obtain the desired DPI scale, load your fonts resized with that scale (always round down fonts size to the nearest integer), and scale your Style structure accordingly using `style.ScaleAllSizes()`. Your application may want to detect DPI change and reload the fonts and reset style between frames. @@ -496,16 +518,24 @@ Down the line Dear ImGui will provide a variety of standardized reference values Applications in the `examples/` folder are not DPI aware partly because they are unable to load a custom font from the file-system (may change that in the future). -The reason DPI is not auto-magically solved in stock examples is that we don't yet have a satisfying solution for the "multi-dpi" problem (using the `docking` branch: when multiple viewport windows are over multiple monitors using different DPI scale). The current way to handle this on the application side is: +The reason DPI is not auto-magically solved in stock examples is that we don't yet have a satisfying solution for the "multi-dpi" problem (using the `docking` branch: when multiple viewport windows are over multiple monitors using different DPI scales). The current way to handle this on the application side is: - Create and maintain one font atlas per active DPI scale (e.g. by iterating `platform_io.Monitors[]` before `NewFrame()`). - Hook `platform_io.OnChangedViewport()` to detect when a `Begin()` call makes a Dear ImGui window change monitor (and therefore DPI). -- In the hook: swap atlas, swap style with correctly sized one, remap the current font from one atlas to the other (may need to maintain a remapping table of your fonts at variying DPI scale). +- In the hook: swap atlas, swap style with correctly sized one, and remap the current font from one atlas to the other (you may need to maintain a remapping table of your fonts at varying DPI scales). -This approach is relatively easy and functional but come with two issues: +This approach is relatively easy and functional but comes with two issues: - It's not possibly to reliably size or position a window ahead of `Begin()` without knowing on which monitor it'll land. - Style override may be lost during the `Begin()` call crossing monitor boundaries. You may need to do some custom scaling mumbo-jumbo if you want your `OnChangedViewport()` handler to preserve style overrides. -Please note that if you are not using multi-viewports with multi-monitors using different DPI scale, you can ignore all of this and use the simpler technique recommended at the top. +Please note that if you are not using multi-viewports with multi-monitors using different DPI scales, you can ignore that and use the simpler technique recommended at the top. + +On Windows, in addition to scaling the font size (make sure to round to an integer) and using `style.ScaleAllSizes()`, you will need to inform Windows that your application is DPI aware. If this is not done, Windows will scale the application window and the UI text will be blurry. Potential solutions to indicate DPI awareness on Windows are: + +- For SDL: the flag `SDL_WINDOW_ALLOW_HIGHDPI` needs to be passed to `SDL_CreateWindow()``. +- For GLFW: this is done automatically. +- For other Windows projects with other backends, or wrapper projects: + - We provide a `ImGui_ImplWin32_EnableDpiAwareness()` helper method in the Win32 backend. + - Use an [application manifest file](https://learn.microsoft.com/en-us/windows/win32/hidpi/setting-the-default-dpi-awareness-for-a-process) to set the `` property. ### Q: How can I load a different font than the default? Use the font atlas to load the TTF/OTF file you want: @@ -527,7 +557,7 @@ backslash \ within a string literal, you need to write it double backslash "\\": ```cpp io.Fonts->AddFontFromFileTTF("MyFolder\MyFont.ttf", size); // WRONG (you are escaping the M here!) -io.Fonts->AddFontFromFileTTF("MyFolder\\MyFont.ttf", size; // CORRECT (Windows only) +io.Fonts->AddFontFromFileTTF("MyFolder\\MyFont.ttf", size); // CORRECT (Windows only) io.Fonts->AddFontFromFileTTF("MyFolder/MyFont.ttf", size); // ALSO CORRECT ``` @@ -536,11 +566,11 @@ io.Fonts->AddFontFromFileTTF("MyFolder/MyFont.ttf", size); // ALSO CORRECT --- ### Q: How can I easily use icons in my application? -The most convenient and practical way is to merge an icon font such as FontAwesome inside you +The most convenient and practical way is to merge an icon font such as FontAwesome inside your main font. Then you can refer to icons within your strings. You may want to see `ImFontConfig::GlyphMinAdvanceX` to make your icon look monospace to facilitate alignment. (Read the [docs/FONTS.md](https://github.com/ocornut/imgui/blob/master/docs/FONTS.md) file for more details about icons font loading.) -With some extra effort, you may use colorful icon by registering custom rectangle space inside the font atlas, +With some extra effort, you may use colorful icons by registering custom rectangle space inside the font atlas, and copying your own graphics data into it. See docs/FONTS.md about using the AddCustomRectFontGlyph API. ##### [Return to Index](#index) @@ -564,7 +594,7 @@ io.Fonts->GetTexDataAsRGBA32() or GetTexDataAsAlpha8() ImFontConfig config; config.OversampleH = 2; config.OversampleV = 1; -config.GlyphOffset.y -= 1.0f; // Move everything by 1 pixels up +config.GlyphOffset.y -= 1.0f; // Move everything by 1 pixel up config.GlyphExtraSpacing.x = 1.0f; // Increase spacing between characters io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_pixels, &config); @@ -574,7 +604,7 @@ ImFontConfig config; config.MergeMode = true; io.Fonts->AddFontDefault(); io.Fonts->AddFontFromFileTTF("fontawesome-webfont.ttf", 16.0f, &config, ranges); // Merge icon font -io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_pixels, NULL, &config, io.Fonts->GetGlyphRangesJapanese()); // Merge japanese glyphs +io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_pixels, nullptr, &config, io.Fonts->GetGlyphRangesJapanese()); // Merge japanese glyphs ``` ##### [Return to Index](#index) @@ -586,7 +616,7 @@ When loading a font, pass custom Unicode ranges to specify the glyphs to load. ```cpp // Add default Japanese ranges -io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_in_pixels, NULL, io.Fonts->GetGlyphRangesJapanese()); +io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_in_pixels, nullptr, io.Fonts->GetGlyphRangesJapanese()); // Or create your own custom ranges (e.g. for a game you can feed your entire game script and only build the characters the game need) ImVector ranges; @@ -595,20 +625,21 @@ builder.AddText("Hello world"); // Add a string (here "He builder.AddChar(0x7262); // Add a specific character builder.AddRanges(io.Fonts->GetGlyphRangesJapanese()); // Add one of the default ranges builder.BuildRanges(&ranges); // Build the final result (ordered ranges with all the unique characters submitted) -io.Fonts->AddFontFromFileTTF("myfontfile.ttf", 16.0f, NULL, ranges.Data); +io.Fonts->AddFontFromFileTTF("myfontfile.ttf", 16.0f, nullptr, ranges.Data); ``` -All your strings needs to use UTF-8 encoding. In C++11 you can encode a string literal in UTF-8 -by using the u8"hello" syntax. Specifying literal in your source code using a local code page -(such as CP-923 for Japanese or CP-1251 for Cyrillic) will NOT work! -Otherwise you can convert yourself to UTF-8 or load text data from file already saved as UTF-8. +All your strings need to use UTF-8 encoding. +You need to tell your compiler to use UTF-8, or in C++11 you can encode a string literal in UTF-8 by using the u8"hello" syntax. +Specifying literal in your source code using a local code page (such as CP-923 for Japanese or CP-1251 for Cyrillic) will NOT work! +See [About UTF-8 Encoding](https://github.com/ocornut/imgui/blob/master/docs/FONTS.md#about-utf-8-encoding) section +of [FONTS.md](https://github.com/ocornut/imgui/blob/master/docs/FONTS.md) for details about UTF-8 Encoding. Text input: it is up to your application to pass the right character code by calling `io.AddInputCharacter()`. The applications in examples/ are doing that. Windows: you can use the WM_CHAR or WM_UNICHAR or WM_IME_CHAR message (depending if your app is built using Unicode or MultiByte mode). -You may also use MultiByteToWideChar() or ToUnicode() to retrieve Unicode codepoints from MultiByte characters or keyboard state. +You may also use `MultiByteToWideChar()` or `ToUnicode()` to retrieve Unicode codepoints from MultiByte characters or keyboard state. Windows: if your language is relying on an Input Method Editor (IME), you can write your HWND to ImGui::GetMainViewport()->PlatformHandleRaw -in order for the default the default implementation of io.SetPlatformImeDataFn() to set your Microsoft IME position correctly. +for the default implementation of io.SetPlatformImeDataFn() to set your Microsoft IME position correctly. ##### [Return to Index](#index) @@ -623,7 +654,7 @@ You may take a look at: - [Quotes](https://github.com/ocornut/imgui/wiki/Quotes) - [Software using Dear ImGui](https://github.com/ocornut/imgui/wiki/Software-using-dear-imgui) - [Sponsors](https://github.com/ocornut/imgui/wiki/Sponsors) -- [Gallery](https://github.com/ocornut/imgui/issues/5243) +- [Gallery](https://github.com/ocornut/imgui/issues/6478) ##### [Return to Index](#index) @@ -631,11 +662,11 @@ You may take a look at: ### Q: Can you create elaborate/serious tools with Dear ImGui? -Yes. People have written game editors, data browsers, debuggers, profilers and all sort of non-trivial tools with the library. In my experience the simplicity of the API is very empowering. Your UI runs close to your live data. Make the tools always-on and everybody in the team will be inclined to create new tools (as opposed to more "offline" UI toolkits where only a fraction of your team effectively creates tools). The list of sponsors below is also an indicator that serious game teams have been using the library. +Yes. People have written game editors, data browsers, debuggers, profilers, and all sorts of non-trivial tools with the library. In my experience, the simplicity of the API is very empowering. Your UI runs close to your live data. Make the tools always-on and everybody in the team will be inclined to create new tools (as opposed to more "offline" UI toolkits where only a fraction of your team effectively creates tools). The list of sponsors below is also an indicator that serious game teams have been using the library. -Dear ImGui is very programmer centric and the immediate-mode GUI paradigm might require you to readjust some habits before you can realize its full potential. Dear ImGui is about making things that are simple, efficient and powerful. +Dear ImGui is very programmer centric and the immediate-mode GUI paradigm might require you to readjust some habits before you can realize its full potential. Dear ImGui is about making things that are simple, efficient, and powerful. -Dear ImGui is built to be efficient and scalable toward the needs for AAA-quality applications running all day. The IMGUI paradigm offers different opportunities for optimization that the more typical RMGUI paradigm. +Dear ImGui is built to be efficient and scalable toward the needs for AAA-quality applications running all day. The IMGUI paradigm offers different opportunities for optimization than the more typical RMGUI paradigm. ##### [Return to Index](#index) @@ -643,9 +674,9 @@ Dear ImGui is built to be efficient and scalable toward the needs for AAA-qualit ### Q: Can you reskin the look of Dear ImGui? -Somehow. You can alter the look of the interface to some degree: changing colors, sizes, padding, rounding, fonts. However, as Dear ImGui is designed and optimized to create debug tools, the amount of skinning you can apply is limited. There is only so much you can stray away from the default look and feel of the interface. Dear ImGui is NOT designed to create user interface for games, although with ingenious use of the low-level API you can do it. +Somewhat. You can alter the look of the interface to some degree: changing colors, sizes, padding, rounding, and fonts. However, as Dear ImGui is designed and optimized to create debug tools, the amount of skinning you can apply is limited. There is only so much you can stray away from the default look and feel of the interface. Dear ImGui is NOT designed to create a user interface for games, although with ingenious use of the low-level API you can do it. -A reasonably skinned application may look like (screenshot from [#2529](https://github.com/ocornut/imgui/issues/2529#issuecomment-524281119)) +A reasonably skinned application may look like (screenshot from [#2529](https://github.com/ocornut/imgui/issues/2529#issuecomment-524281119)): ![minipars](https://user-images.githubusercontent.com/314805/63589441-d9794f00-c5b1-11e9-8d96-cfc1b93702f7.png) ##### [Return to Index](#index) @@ -654,7 +685,7 @@ A reasonably skinned application may look like (screenshot from [#2529](https:// ### Q: Why using C++ (as opposed to C)? -Dear ImGui takes advantage of a few C++ languages features for convenience but nothing anywhere Boost insanity/quagmire. Dear ImGui doesn't use any C++ header file. Dear ImGui uses a very small subset of C++11 features. In particular, function overloading and default parameters are used to make the API easier to use and code more terse. Doing so I believe the API is sitting on a sweet spot and giving up on those features would make the API more cumbersome. Other features such as namespace, constructors and templates (in the case of the ImVector<> class) are also relied on as a convenience. +Dear ImGui takes advantage of a few C++ language features for convenience but nothing anywhere Boost insanity/quagmire. Dear ImGui doesn't use any C++ header file. Dear ImGui uses a very small subset of C++11 features. In particular, function overloading and default parameters are used to make the API easier to use and code terser. Doing so I believe the API is sitting on a sweet spot and giving up on those features would make the API more cumbersome. Other features such as namespace, constructors, and templates (in the case of the ImVector<> class) are also relied on as a convenience. There is an auto-generated [c-api for Dear ImGui (cimgui)](https://github.com/cimgui/cimgui) by Sonoro1234 and Stephan Dilly. It is designed for creating bindings to other languages. If possible, I would suggest using your target language functionalities to try replicating the function overloading and default parameters used in C++ else the API may be harder to use. Also see [Bindings](https://github.com/ocornut/imgui/wiki/Bindings) for various third-party bindings. @@ -665,11 +696,11 @@ There is an auto-generated [c-api for Dear ImGui (cimgui)](https://github.com/ci # Q&A: Community ### Q: How can I help? -- Businesses: please reach out to `contact AT dearimgui.com` if you work in a place using Dear ImGui! We can discuss ways for your company to fund development via invoiced technical support, maintenance or sponsoring contacts. This is among the most useful thing you can do for Dear ImGui. With increased funding, we can hire more people working on this project. +- Businesses: please reach out to `contact AT dearimgui.com` if you work in a place using Dear ImGui! We can discuss ways for your company to fund development via invoiced technical support, maintenance, or sponsoring contacts. This is among the most useful thing you can do for Dear ImGui. With increased funding, we can hire more people to work on this project. - Individuals: you can support continued maintenance and development via PayPal donations. See [README](https://github.com/ocornut/imgui/blob/master/docs/README.md). -- If you are experienced with Dear ImGui and C++, look at [GitHub Issues](https://github.com/ocornut/imgui/issues), [GitHub Discussions](https://github.com/ocornut/imgui/discussions), the [Wiki](https://github.com/ocornut/imgui/wiki), read [docs/TODO.txt](https://github.com/ocornut/imgui/blob/master/docs/TODO.txt) and see how you want to help and can help! -- Disclose your usage of Dear ImGui via a dev blog post, a tweet, a screenshot, a mention somewhere etc. -You may post screenshot or links in the [gallery threads](https://github.com/ocornut/imgui/issues/5243). Visuals are ideal as they inspire other programmers. Disclosing your use of Dear ImGui helps the library grow credibility, and help other teams and programmers with taking decisions. +- If you are experienced with Dear ImGui and C++, look at [GitHub Issues](https://github.com/ocornut/imgui/issues), [GitHub Discussions](https://github.com/ocornut/imgui/discussions), the [Wiki](https://github.com/ocornut/imgui/wiki), read [docs/TODO.txt](https://github.com/ocornut/imgui/blob/master/docs/TODO.txt), and see how you want to help and can help! +- Disclose your usage of Dear ImGui via a dev blog post, a tweet, a screenshot, a mention somewhere, etc. +You may post screenshots or links in the [gallery threads](https://github.com/ocornut/imgui/issues/6478). Visuals are ideal as they inspire other programmers. Disclosing your use of Dear ImGui helps the library grow credibility, and helps other teams and programmers with taking decisions. - If you have issues or if you need to hack into the library, even if you don't expect any support it is useful that you share your issues or sometimes incomplete PR. ##### [Return to Index](#index) diff --git a/extern/imgui_patched/docs/FONTS.md b/extern/imgui_patched/docs/FONTS.md index a0354674..6049fb48 100644 --- a/extern/imgui_patched/docs/FONTS.md +++ b/extern/imgui_patched/docs/FONTS.md @@ -8,45 +8,122 @@ a 13 pixels high, pixel-perfect font used by default. We embed it in the source You may also load external .TTF/.OTF files. In the [misc/fonts/](https://github.com/ocornut/imgui/tree/master/misc/fonts) folder you can find a few suggested fonts, provided as a convenience. -**Also read the FAQ:** https://www.dearimgui.org/faq (there is a Fonts section!) +**Also read the FAQ:** https://www.dearimgui.com/faq (there is a Fonts section!) ## Index - [Readme First](#readme-first) +- [About Filenames](#about-filenames) +- [About UTF-8 Encoding](#about-utf-8-encoding) +- [Debug Tools](#debug-tools) - [How should I handle DPI in my application?](#how-should-i-handle-dpi-in-my-application) -- [Fonts Loading Instructions](#font-loading-instructions) +- [Fonts Loading Instructions](#fonts-loading-instructions) - [Using Icon Fonts](#using-icon-fonts) - [Using FreeType Rasterizer (imgui_freetype)](#using-freetype-rasterizer-imgui_freetype) - [Using Colorful Glyphs/Emojis](#using-colorful-glyphsemojis) - [Using Custom Glyph Ranges](#using-custom-glyph-ranges) - [Using Custom Colorful Icons](#using-custom-colorful-icons) - [Using Font Data Embedded In Source Code](#using-font-data-embedded-in-source-code) -- [About filenames](#about-filenames) - [Credits/Licenses For Fonts Included In Repository](#creditslicenses-for-fonts-included-in-repository) - [Font Links](#font-links) --------------------------------------- - ## Readme First -- You can use the `Metrics/Debugger` window (available in `Demo>Tools`) to browse your fonts and understand what's going on if you have an issue. You can also reach it in `Demo->Tools->Style Editor->Fonts`. The same information are also available in the Style Editor under Fonts. +## Readme First + +**A vast majority of font and text related issues encountered comes from 3 things:** +- Invalid filename due to use of `\` or unexpected working directory. See [About Filenames](#about-filenames). AddFontXXX functions should assert if the filename is incorrect. +- Invalid UTF-8 encoding of your non-ASCII strings. See [About UTF-8 Encoding](#about-utf-8-encoding). Use the encoding viewer to confirm yours is correct. +- You need to load a font with explicit glyph ranges if you want to use non-ASCII characters. See [Fonts Loading Instructions](#fonts-loading-instructions). Use Metrics/Debugger->Fonts to confirm loaded fonts and loaded glyph ranges. + +The third point is a current constraint of Dear ImGui (which we will lift in the future): when loading a font you need to specify which characters glyphs to load. +All loaded fonts glyphs are rendered into a single texture atlas ahead of time. Calling either of `io.Fonts->GetTexDataAsAlpha8()`, `io.Fonts->GetTexDataAsRGBA32()` or `io.Fonts->Build()` will build the atlas. This is generally called by the Renderer backend, e.g. `ImGui_ImplDX11_NewFrame()` calls it. + +**If you use custom glyphs ranges, make sure the array is persistent** and available during the calls to `GetTexDataAsAlpha8()/GetTexDataAsRGBA32()/Build()`. + +##### [Return to Index](#index) + +## About Filenames + +**Please note that many new C/C++ users have issues loading their files _because the filename they provide is wrong_ due to incorrect assumption of what is the current directory.** + +Two things to watch for: + +(1) In C/C++ and most programming languages if you want to use a backslash `\` within a string literal, you need to write it double backslash `\\`. At it happens, Windows uses backslashes as a path separator, so be mindful. +```cpp +io.Fonts->AddFontFromFileTTF("MyFiles\MyImage01.jpg", ...); // This is INCORRECT!! +io.Fonts->AddFontFromFileTTF("MyFiles\\MyImage01.jpg", ...); // This is CORRECT +``` +In some situations, you may also use `/` path separator under Windows. + +(2) Make sure your IDE/debugger settings starts your executable from the right working (current) directory. In Visual Studio you can change your working directory in project `Properties > General > Debugging > Working Directory`. People assume that their execution will start from the root folder of the project, where by default it often starts from the folder where object or executable files are stored. +```cpp +io.Fonts->AddFontFromFileTTF("MyImage01.jpg", ...); // Relative filename depends on your Working Directory when running your program! +io.Fonts->AddFontFromFileTTF("../MyImage01.jpg", ...); // Load from the parent folder of your Working Directory +``` +##### [Return to Index](#index) + + +## About UTF-8 Encoding + +**For non-ASCII characters display, a common user issue is not passing correctly UTF-8 encoded strings.** + +(1) We provide a function `ImGui::DebugTextEncoding(const char* text)` which you can call to verify the content of your UTF-8 strings. +This is a convenient way to confirm that your encoding is correct. + +```cpp +ImGui::SeparatorText("CORRECT"); +ImGui::DebugTextEncoding(u8"こんにちは"); + +ImGui::SeparatorText("INCORRECT"); +ImGui::DebugTextEncoding("こんにちは"); +``` +![UTF-8 Encoding viewer](https://github.com/ocornut/imgui/assets/8225057/61c1696a-9a94-46c5-9627-cf91211111f0) + +You can also find this tool under `Metrics/Debuggers->Tools->UTF-8 Encoding viewer` if you want to paste from clipboard, but this won't validate the UTF-8 encoding done by your compiler. + +(2) To encode in UTF-8: + +There are also compiler-specific ways to enforce UTF-8 encoding by default: + +- Visual Studio compiler: `/utf-8` command-line flag. +- Visual Studio compiler: `#pragma execution_character_set("utf-8")` inside your code. +- Since May 2023 we have changed the Visual Studio projects of all our examples to use `/utf-8` ([see commit](https://github.com/ocornut/imgui/commit/513af1efc9080857bbd10000d98f98f2a0c96803)). + +Or, since C++11, you can use the `u8"my text"` syntax to encode literal strings as UTF-8. e.g.: +```cpp +ImGui::Text(u8"hello"); +ImGui::Text(u8"こんにちは"); // this will always be encoded as UTF-8 +ImGui::Text("こんにちは"); // the encoding of this is depending on compiler settings/flags and may be incorrect. +``` + +Since C++20, because the C++ committee hate its users, they decided to change the `u8""` syntax to not return `const char*` but a new type `const char_t*` which doesn't cast to `const char*`. +Because of type usage of `u8""` in C++20 is a little more tedious: +```cpp +ImGui::Text((const char*)u8"こんにちは"); +``` +We suggest using a macro in your codebase: +```cpp +#define U8(_S) (const char*)u8##_S +ImGui::Text(U8("こんにちは")); +``` +##### [Return to Index](#index) + + +## Debug Tools + +#### Metrics/Debugger->Fonts +You can use the `Metrics/Debugger` window (available in `Demo>Tools`) to browse your fonts and understand what's going on if you have an issue. You can also reach it in `Demo->Tools->Style Editor->Fonts`. The same information are also available in the Style Editor under Fonts. ![Fonts debugging](https://user-images.githubusercontent.com/8225057/135429892-0e41ef8d-33c5-4991-bcf6-f997a0bcfd6b.png) -- You can use the `UTF-8 Encoding viewer` in `Metrics/Debugger` to verify the content of your UTF-8 strings. From C/C++ code, you can call `ImGui::DebugTextEncoding("my string");` function to verify that your UTF-8 encoding is correct. +#### UTF-8 Encoding Viewer** +You can use the `UTF-8 Encoding viewer` in `Metrics/Debugger` to verify the content of your UTF-8 strings. From C/C++ code, you can call `ImGui::DebugTextEncoding("my string");` function to verify that your UTF-8 encoding is correct. ![UTF-8 Encoding viewer](https://user-images.githubusercontent.com/8225057/166505963-8a0d7899-8ee8-4558-abb2-1ae523dc02f9.png) -- All loaded fonts glyphs are rendered into a single texture atlas ahead of time. Calling either of `io.Fonts->GetTexDataAsAlpha8()`, `io.Fonts->GetTexDataAsRGBA32()` or `io.Fonts->Build()` will build the atlas. - -- Make sure your font ranges data are persistent (available during the calls to `GetTexDataAsAlpha8()`/`GetTexDataAsRGBA32()/`Build()`. - -- Use C++11 u8"my text" syntax to encode literal strings as UTF-8. e.g.: -```cpp -u8"hello" -u8"こんにちは" // this will be encoded as UTF-8 -``` - ##### [Return to Index](#index) + ## How should I handle DPI in my application? See [FAQ entry](https://github.com/ocornut/imgui/blob/master/docs/FAQ.md#q-how-should-i-handle-dpi-in-my-application). @@ -54,7 +131,7 @@ See [FAQ entry](https://github.com/ocornut/imgui/blob/master/docs/FAQ.md#q-how-s ##### [Return to Index](#index) -## Font Loading Instructions +## Fonts Loading Instructions **Load default font:** ```cpp @@ -62,7 +139,6 @@ ImGuiIO& io = ImGui::GetIO(); io.Fonts->AddFontDefault(); ``` - **Load .TTF/.OTF file with:** ```cpp ImGuiIO& io = ImGui::GetIO(); @@ -70,7 +146,6 @@ io.Fonts->AddFontFromFileTTF("font.ttf", size_pixels); ``` If you get an assert stating "Could not load font file!", your font filename is likely incorrect. Read "[About filenames](#about-filenames)" carefully. - **Load multiple fonts:** ```cpp // Init @@ -86,7 +161,6 @@ ImGui::Text("Hello with another font"); ImGui::PopFont(); ``` - **For advanced options create a ImFontConfig structure and pass it to the AddFont() function (it will be copied internally):** ```cpp ImFontConfig config; @@ -96,7 +170,6 @@ config.GlyphExtraSpacing.x = 1.0f; ImFont* font = io.Fonts->AddFontFromFileTTF("font.ttf", size_pixels, &config); ``` - **Combine multiple fonts into one:** ```cpp // Load a first font @@ -117,13 +190,13 @@ io.Fonts->Build(); ```cpp // Basic Latin, Extended Latin -io.Fonts->AddFontFromFileTTF("font.ttf", size_pixels, NULL, io.Fonts->GetGlyphRangesDefault()); +io.Fonts->AddFontFromFileTTF("font.ttf", size_pixels, nullptr, io.Fonts->GetGlyphRangesDefault()); // Default + Selection of 2500 Ideographs used by Simplified Chinese -io.Fonts->AddFontFromFileTTF("font.ttf", size_pixels, NULL, io.Fonts->GetGlyphRangesChineseSimplifiedCommon()); +io.Fonts->AddFontFromFileTTF("font.ttf", size_pixels, nullptr, io.Fonts->GetGlyphRangesChineseSimplifiedCommon()); // Default + Hiragana, Katakana, Half-Width, Selection of 1946 Ideographs -io.Fonts->AddFontFromFileTTF("font.ttf", size_pixels, NULL, io.Fonts->GetGlyphRangesJapanese()); +io.Fonts->AddFontFromFileTTF("font.ttf", size_pixels, nullptr, io.Fonts->GetGlyphRangesJapanese()); ``` See [Using Custom Glyph Ranges](#using-custom-glyph-ranges) section to create your own ranges. @@ -132,7 +205,7 @@ See [Using Custom Glyph Ranges](#using-custom-glyph-ranges) section to create yo ```cpp ImGuiIO& io = ImGui::GetIO(); -io.Fonts->AddFontFromFileTTF("NotoSansCJKjp-Medium.otf", 20.0f, NULL, io.Fonts->GetGlyphRangesJapanese()); +io.Fonts->AddFontFromFileTTF("NotoSansCJKjp-Medium.otf", 20.0f, nullptr, io.Fonts->GetGlyphRangesJapanese()); ``` ```cpp ImGui::Text(u8"こんにちは!テスト %d", 123); @@ -149,7 +222,7 @@ ImGui::SliderFloat("float", &f, 0.0f, 1.0f); **Font Atlas too large?** -- If you have very large number of glyphs or multiple fonts, the texture may become too big for your graphics API. The typical result of failing to upload a texture is if every glyphs appears as white rectangles. +- If you have very large number of glyphs or multiple fonts, the texture may become too big for your graphics API. The typical result of failing to upload a texture is if every glyph appears as a white rectangle. - Mind the fact that some graphics drivers have texture size limitation. If you are building a PC application, mind the fact that your users may use hardware with lower limitations than yours. Some solutions: @@ -245,7 +318,7 @@ builder.AddChar(0x7262); // Add a specific charact builder.AddRanges(io.Fonts->GetGlyphRangesJapanese()); // Add one of the default ranges builder.BuildRanges(&ranges); // Build the final result (ordered ranges with all the unique characters submitted) -io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_in_pixels, NULL, ranges.Data); +io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_in_pixels, nullptr, ranges.Data); io.Fonts->Build(); // Build the atlas while 'ranges' is still in scope and not deleted. ``` @@ -271,14 +344,14 @@ rect_ids[1] = io.Fonts->AddCustomRectFontGlyph(font, 'b', 13, 13, 13+1); io.Fonts->Build(); // Retrieve texture in RGBA format -unsigned char* tex_pixels = NULL; +unsigned char* tex_pixels = nullptr; int tex_width, tex_height; io.Fonts->GetTexDataAsRGBA32(&tex_pixels, &tex_width, &tex_height); for (int rect_n = 0; rect_n < IM_ARRAYSIZE(rect_ids); rect_n++) { - int rect_id = rects_ids[rect_n]; - if (const ImFontAtlas::CustomRect* rect = io.Fonts->GetCustomRectByIndex(rect_id)) + int rect_id = rect_ids[rect_n]; + if (const ImFontAtlasCustomRect* rect = io.Fonts->GetCustomRectByIndex(rect_id)) { // Fill the custom rectangle with red pixels (in reality you would draw/copy your bitmap data here!) for (int y = 0; y < rect->Height; y++) @@ -311,28 +384,6 @@ ImFont* font = io.Fonts->AddFontFromMemoryCompressedBase85TTF(compressed_data_ba ##### [Return to Index](#index) -## About filenames - -**Please note that many new C/C++ users have issues loading their files _because the filename they provide is wrong_.** - -Two things to watch for: -- Make sure your IDE/debugger settings starts your executable from the right working directory. In Visual Studio you can change your working directory in project `Properties > General > Debugging > Working Directory`. People assume that their execution will start from the root folder of the project, where by default it oftens start from the folder where object or executable files are stored. -```cpp -// Relative filename depends on your Working Directory when running your program! -io.Fonts->AddFontFromFileTTF("MyImage01.jpg", ...); - -// Load from the parent folder of your Working Directory -io.Fonts->AddFontFromFileTTF("../MyImage01.jpg", ...); -``` -- In C/C++ and most programming languages if you want to use a backslash `\` within a string literal, you need to write it double backslash `\\`. At it happens, Windows uses backslashes as a path separator, so be mindful. -```cpp -io.Fonts->AddFontFromFileTTF("MyFiles\MyImage01.jpg", ...); // This is INCORRECT!! -io.Fonts->AddFontFromFileTTF("MyFiles\\MyImage01.jpg", ...); // This is CORRECT -``` -In some situations, you may also use `/` path separator under Windows. - -##### [Return to Index](#index) - ## Credits/Licenses For Fonts Included In Repository Some fonts files are available in the `misc/fonts/` folder: diff --git a/extern/imgui_patched/docs/README.md b/extern/imgui_patched/docs/README.md index 305466a4..c3159d36 100644 --- a/extern/imgui_patched/docs/README.md +++ b/extern/imgui_patched/docs/README.md @@ -5,49 +5,45 @@ Dear ImGui ---- -[![Build Status](https://github.com/ocornut/imgui/workflows/build/badge.svg)](https://github.com/ocornut/imgui/actions?workflow=build) [![Static Analysis Status](https://github.com/ocornut/imgui/workflows/static-analysis/badge.svg)](https://github.com/ocornut/imgui/actions?workflow=static-analysis) +[![Build Status](https://github.com/ocornut/imgui/workflows/build/badge.svg)](https://github.com/ocornut/imgui/actions?workflow=build) [![Static Analysis Status](https://github.com/ocornut/imgui/workflows/static-analysis/badge.svg)](https://github.com/ocornut/imgui/actions?workflow=static-analysis) [![Tests Status](https://github.com/ocornut/imgui_test_engine/workflows/tests/badge.svg)](https://github.com/ocornut/imgui_test_engine/actions?workflow=tests) (This library is available under a free and permissive license, but needs financial support to sustain its continued improvements. In addition to maintenance and stability there are many desirable features yet to be added. If your company is using Dear ImGui, please consider reaching out.) -Businesses: support continued development and maintenance via invoiced technical support, maintenance, sponsoring contracts: +Businesses: support continued development and maintenance via invoiced sponsoring/support contracts:
  _E-mail: contact @ dearimgui dot com_ - -Individuals: support continued development and maintenance [here](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=WGHNC6MBFLZ2S). Also see [Sponsors](https://github.com/ocornut/imgui/wiki/Sponsors) page. +
Individuals: support continued development and maintenance [here](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=WGHNC6MBFLZ2S). Also see [Sponsors](https://github.com/ocornut/imgui/wiki/Sponsors) page. | [The Pitch](#the-pitch) - [Usage](#usage) - [How it works](#how-it-works) - [Releases & Changelogs](#releases--changelogs) - [Demo](#demo) - [Integration](#integration) | :----------------------------------------------------------: | -| [Upcoming changes](#upcoming-changes) - [Gallery](#gallery) - [Support, FAQ](#support-frequently-asked-questions-faq) - [How to help](#how-to-help) - [Sponsors](#sponsors) - [Credits](#credits) - [License](#license) | +| [Gallery](#gallery) - [Support, FAQ](#support-frequently-asked-questions-faq) - [How to help](#how-to-help) - [Sponsors](https://github.com/ocornut/imgui/wiki/Sponsors) - [Credits](#credits) - [License](#license) | | [Wiki](https://github.com/ocornut/imgui/wiki) - [Languages & frameworks backends/bindings](https://github.com/ocornut/imgui/wiki/Bindings) - [Software using Dear ImGui](https://github.com/ocornut/imgui/wiki/Software-using-dear-imgui) - [User quotes](https://github.com/ocornut/imgui/wiki/Quotes) | ### The Pitch -Dear ImGui is a **bloat-free graphical user interface library for C++**. It outputs optimized vertex buffers that you can render anytime in your 3D-pipeline enabled application. It is fast, portable, renderer agnostic and self-contained (no external dependencies). +Dear ImGui is a **bloat-free graphical user interface library for C++**. It outputs optimized vertex buffers that you can render anytime in your 3D-pipeline-enabled application. It is fast, portable, renderer agnostic, and self-contained (no external dependencies). -Dear ImGui is designed to **enable fast iterations** and to **empower programmers** to create **content creation tools and visualization / debug tools** (as opposed to UI for the average end-user). It favors simplicity and productivity toward this goal, and lacks certain features normally found in more high-level libraries. +Dear ImGui is designed to **enable fast iterations** and to **empower programmers** to create **content creation tools and visualization / debug tools** (as opposed to UI for the average end-user). It favors simplicity and productivity toward this goal and lacks certain features commonly found in more high-level libraries. -Dear ImGui is particularly suited to integration in games engine (for tooling), real-time 3D applications, fullscreen applications, embedded applications, or any applications on consoles platforms where operating system features are non-standard. +Dear ImGui is particularly suited to integration in game engines (for tooling), real-time 3D applications, fullscreen applications, embedded applications, or any applications on console platforms where operating system features are non-standard. + - Minimize state synchronization. + - Minimize state storage on user side. + - Minimize setup and maintenance. + - Easy to use to create dynamic UI which are the reflection of a dynamic data set. - Easy to use to create code-driven and data-driven tools. - Easy to use to create ad hoc short-lived tools and long-lived, more elaborate tools. - Easy to hack and improve. - - Minimize setup and maintenance. - - Minimize state storage on user side. - - Minimize state synchronization. - Portable, minimize dependencies, run on target (consoles, phones, etc.). - Efficient runtime and memory consumption. - - Battle-tested, used by many major actors in the game industry. + - Battle-tested, used by [many major actors in the game industry](https://github.com/ocornut/imgui/wiki/Software-using-dear-imgui). ### Usage -**The core of Dear ImGui is self-contained within a few platform-agnostic files** which you can easily compile in your application/engine. They are all the files in the root folder of the repository (imgui*.cpp, imgui*.h). +**The core of Dear ImGui is self-contained within a few platform-agnostic files** which you can easily compile in your application/engine. They are all the files in the root folder of the repository (imgui*.cpp, imgui*.h). **No specific build process is required**. You can add the .cpp files into your existing project. -**No specific build process is required**. You can add the .cpp files to your existing project. +**Backends for a variety of graphics API and rendering platforms** are provided in the [backends/](https://github.com/ocornut/imgui/tree/master/backends) folder, along with example applications in the [examples/](https://github.com/ocornut/imgui/tree/master/examples) folder. See the [Integration](#integration) section of this document for details. You may also create your own backend. Anywhere where you can render textured triangles, you can render Dear ImGui. -You will need a backend to integrate Dear ImGui in your app. The backend passes mouse/keyboard/gamepad inputs and variety of settings to Dear ImGui, and is in charge of rendering the resulting vertices. **Backends for a variety of graphics api and rendering platforms** are provided in the [backends/](https://github.com/ocornut/imgui/tree/master/backends) folder, along with example applications in the [examples/](https://github.com/ocornut/imgui/tree/master/examples) folder. See the [Integration](#integration) section of this document for details. You may also create your own backend. Anywhere where you can render textured triangles, you can render Dear ImGui. - -After Dear ImGui is setup in your application, you can use it from \_anywhere\_ in your program loop: - -Code: +After Dear ImGui is set up in your application, you can use it from \_anywhere\_ in your program loop: ```cpp ImGui::Text("Hello, world %d", 123); if (ImGui::Button("Save")) @@ -55,10 +51,9 @@ if (ImGui::Button("Save")) ImGui::InputText("string", buf, IM_ARRAYSIZE(buf)); ImGui::SliderFloat("float", &f, 0.0f, 1.0f); ``` -Result: -
![sample code output (dark)](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v175/capture_readme_styles_0001.png) ![sample code output (light)](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v175/capture_readme_styles_0002.png) +![sample code output (dark, segoeui font, freetype)](https://user-images.githubusercontent.com/8225057/191050833-b7ecf528-bfae-4a9f-ac1b-f3d83437a2f4.png) +![sample code output (light, segoeui font, freetype)](https://user-images.githubusercontent.com/8225057/191050838-8742efd4-504d-4334-a9a2-e756d15bc2ab.png) -Code: ```cpp // Create a window called "My First Tool", with a menu bar. ImGui::Begin("My First Tool", &my_tool_active, ImGuiWindowFlags_MenuBar); @@ -74,12 +69,14 @@ if (ImGui::BeginMenuBar()) ImGui::EndMenuBar(); } -// Edit a color (stored as ~4 floats) +// Edit a color stored as 4 floats ImGui::ColorEdit4("Color", my_color); -// Plot some values -const float my_values[] = { 0.2f, 0.1f, 1.0f, 0.5f, 0.9f, 2.2f }; -ImGui::PlotLines("Frame Times", my_values, IM_ARRAYSIZE(my_values)); +// Generate samples and plot them +float samples[100]; +for (int n = 0; n < 100; n++) + samples[n] = sinf(n * 0.2f + ImGui::GetTime() * 1.5f); +ImGui::PlotLines("Samples", samples, 100); // Display contents in a scrolling region ImGui::TextColored(ImVec4(1,1,0,1), "Important Stuff"); @@ -89,82 +86,63 @@ for (int n = 0; n < 50; n++) ImGui::EndChild(); ImGui::End(); ``` -Result: -
![sample code output](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v180/code_sample_04_color.gif) +![my_first_tool_v188](https://user-images.githubusercontent.com/8225057/191055698-690a5651-458f-4856-b5a9-e8cc95c543e2.gif) -Dear ImGui allows you to **create elaborate tools** as well as very short-lived ones. On the extreme side of short-livedness: using the Edit&Continue (hot code reload) feature of modern compilers you can add a few widgets to tweaks variables while your application is running, and remove the code a minute later! Dear ImGui is not just for tweaking values. You can use it to trace a running algorithm by just emitting text commands. You can use it along with your own reflection data to browse your dataset live. You can use it to expose the internals of a subsystem in your engine, to create a logger, an inspection tool, a profiler, a debugger, an entire game making editor/framework, etc. +Dear ImGui allows you to **create elaborate tools** as well as very short-lived ones. On the extreme side of short-livedness: using the Edit&Continue (hot code reload) feature of modern compilers you can add a few widgets to tweak variables while your application is running, and remove the code a minute later! Dear ImGui is not just for tweaking values. You can use it to trace a running algorithm by just emitting text commands. You can use it along with your own reflection data to browse your dataset live. You can use it to expose the internals of a subsystem in your engine, to create a logger, an inspection tool, a profiler, a debugger, an entire game-making editor/framework, etc. ### How it works -Check out the Wiki's [About the IMGUI paradigm](https://github.com/ocornut/imgui/wiki#about-the-imgui-paradigm) section if you want to understand the core principles behind the IMGUI paradigm. An IMGUI tries to minimize superfluous state duplication, state synchronization and state retention from the user's point of view. It is less error prone (less code and less bugs) than traditional retained-mode interfaces, and lends itself to create dynamic user interfaces. +Check out the Wiki's [About the IMGUI paradigm](https://github.com/ocornut/imgui/wiki#about-the-imgui-paradigm) section if you want to understand the core principles behind the IMGUI paradigm. An IMGUI tries to minimize superfluous state duplication, state synchronization, and state retention from the user's point of view. It is less error-prone (less code and fewer bugs) than traditional retained-mode interfaces, and lends itself to creating dynamic user interfaces. Dear ImGui outputs vertex buffers and command lists that you can easily render in your application. The number of draw calls and state changes required to render them is fairly small. Because Dear ImGui doesn't know or touch graphics state directly, you can call its functions anywhere in your code (e.g. in the middle of a running algorithm, or in the middle of your own rendering process). Refer to the sample applications in the examples/ folder for instructions on how to integrate Dear ImGui with your existing codebase. -_A common misunderstanding is to mistake immediate mode gui for immediate mode rendering, which usually implies hammering your driver/GPU with a bunch of inefficient draw calls and state changes as the gui functions are called. This is NOT what Dear ImGui does. Dear ImGui outputs vertex buffers and a small list of draw calls batches. It never touches your GPU directly. The draw call batches are decently optimal and you can render them later, in your app or even remotely._ +_A common misunderstanding is to mistake immediate mode GUI for immediate mode rendering, which usually implies hammering your driver/GPU with a bunch of inefficient draw calls and state changes as the GUI functions are called. This is NOT what Dear ImGui does. Dear ImGui outputs vertex buffers and a small list of draw calls batches. It never touches your GPU directly. The draw call batches are decently optimal and you can render them later, in your app or even remotely._ ### Releases & Changelogs -See [Releases](https://github.com/ocornut/imgui/releases) page. +See [Releases](https://github.com/ocornut/imgui/releases) page for decorated Changelogs. Reading the changelogs is a good way to keep up to date with the things Dear ImGui has to offer, and maybe will give you ideas of some features that you've been ignoring until now! ### Demo -Calling the `ImGui::ShowDemoWindow()` function will create a demo window showcasing variety of features and examples. The code is always available for reference in `imgui_demo.cpp`. +Calling the `ImGui::ShowDemoWindow()` function will create a demo window showcasing a variety of features and examples. The code is always available for reference in `imgui_demo.cpp`. [Here's how the demo looks](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v167/v167-misc.png). -![screenshot demo](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v167/v167-misc.png) +You should be able to build the examples from sources. If you don't, let us know! If you want to have a quick look at some Dear ImGui features, you can download Windows binaries of the demo app here: +- [imgui-demo-binaries-20220504.zip](https://www.dearimgui.com/binaries/imgui-demo-binaries-20220504.zip) (Windows, 1.88 WIP, built 2022/05/04, master) or [older binaries](https://www.dearimgui.com/binaries). -You should be able to build the examples from sources (tested on Windows/Mac/Linux). If you don't, let us know! If you want to have a quick look at some Dear ImGui features, you can download Windows binaries of the demo app here: -- [imgui-demo-binaries-20220504.zip](https://www.dearimgui.org/binaries/imgui-demo-binaries-20220504.zip) (Windows, 1.88 WIP, built 2022/05/04, master branch) or [older demo binaries](https://www.dearimgui.org/binaries). - -The demo applications are not DPI aware so expect some blurriness on a 4K screen. For DPI awareness in your application, you can load/reload your font at different scale, and scale your style with `style.ScaleAllSizes()` (see [FAQ](https://www.dearimgui.org/faq)). +The demo applications are not DPI aware so expect some blurriness on a 4K screen. For DPI awareness in your application, you can load/reload your font at a different scale and scale your style with `style.ScaleAllSizes()` (see [FAQ](https://www.dearimgui.com/faq)). ### Integration -On most platforms and when using C++, **you should be able to use a combination of the [imgui_impl_xxxx](https://github.com/ocornut/imgui/tree/master/backends) backends without modification** (e.g. `imgui_impl_win32.cpp` + `imgui_impl_dx11.cpp`). If your engine supports multiple platforms, consider using more of the imgui_impl_xxxx files instead of rewriting them: this will be less work for you and you can get Dear ImGui running immediately. You can _later_ decide to rewrite a custom backend using your custom engine functions if you wish so. +On most platforms and when using C++, **you should be able to use a combination of the [imgui_impl_xxxx](https://github.com/ocornut/imgui/tree/master/backends) backends without modification** (e.g. `imgui_impl_win32.cpp` + `imgui_impl_dx11.cpp`). If your engine supports multiple platforms, consider using more imgui_impl_xxxx files instead of rewriting them: this will be less work for you, and you can get Dear ImGui running immediately. You can _later_ decide to rewrite a custom backend using your custom engine functions if you wish so. -Integrating Dear ImGui within your custom engine is a matter of 1) wiring mouse/keyboard/gamepad inputs 2) uploading one texture to your GPU/render engine 3) providing a render function that can bind textures and render textured triangles. The [examples/](https://github.com/ocornut/imgui/tree/master/examples) folder is populated with applications doing just that. If you are an experienced programmer at ease with those concepts, it should take you less than two hours to integrate Dear ImGui in your custom engine. **Make sure to spend time reading the [FAQ](https://www.dearimgui.org/faq), comments, and some of the examples/ application!** +Integrating Dear ImGui within your custom engine is a matter of 1) wiring mouse/keyboard/gamepad inputs 2) uploading a texture to your GPU/render engine 3) providing a render function that can bind textures and render textured triangles. The [examples/](https://github.com/ocornut/imgui/tree/master/examples) folder is populated with applications doing just that. If you are an experienced programmer at ease with those concepts, it should take you less than two hours to integrate Dear ImGui into your custom engine. **Make sure to spend time reading the [FAQ](https://www.dearimgui.com/faq), comments, and the examples applications!** Officially maintained backends/bindings (in repository): - Renderers: DirectX9, DirectX10, DirectX11, DirectX12, Metal, OpenGL/ES/ES2, SDL_Renderer, Vulkan, WebGPU. -- Platforms: GLFW, SDL2, Win32, Glut, OSX, Android. +- Platforms: GLFW, SDL2/SDL3, Win32, Glut, OSX, Android. - Frameworks: Allegro5, Emscripten. [Third-party backends/bindings](https://github.com/ocornut/imgui/wiki/Bindings) wiki page: - Languages: C, C# and: Beef, ChaiScript, Crystal, D, Go, Haskell, Haxe/hxcpp, Java, JavaScript, Julia, Kotlin, Lobster, Lua, Odin, Pascal, PureBasic, Python, Ruby, Rust, Swift... - Frameworks: AGS/Adventure Game Studio, Amethyst, Blender, bsf, Cinder, Cocos2d-x, Diligent Engine, Flexium, GML/Game Maker Studio2, GLEQ, Godot, GTK3+OpenGL3, Irrlicht Engine, LÖVE+LUA, Magnum, Monogame, NanoRT, nCine, Nim Game Lib, Nintendo 3DS & Switch (homebrew), Ogre, openFrameworks, OSG/OpenSceneGraph, Orx, Photoshop, px_render, Qt/QtDirect3D, SDL_Renderer, SFML, Sokol, Unity, Unreal Engine 4, vtk, VulkanHpp, VulkanSceneGraph, Win32 GDI, WxWidgets. -- Note that C bindings ([cimgui](https://github.com/cimgui/cimgui)) are auto-generated, you can use its json/lua output to generate bindings for other languages. +- Many bindings are auto-generated (by good old [cimgui](https://github.com/cimgui/cimgui) or newer/experimental [dear_bindings](https://github.com/dearimgui/dear_bindings)), you can use their metadata output to generate bindings for other languages. [Useful Extensions/Widgets](https://github.com/ocornut/imgui/wiki/Useful-Extensions) wiki page: -- Text editors, node editors, timeline editors, plotting, software renderers, remote network access, memory editors, gizmos etc. +- Automation/testing, Text editors, node editors, timeline editors, plotting, software renderers, remote network access, memory editors, gizmos, etc. One of the most notable and well supported extension is [ImPlot](https://github.com/epezent/implot). Also see [Wiki](https://github.com/ocornut/imgui/wiki) for more links and ideas. -### Upcoming Changes - -Some of the goals for 2022 are: -- Work on Docking (see [#2109](https://github.com/ocornut/imgui/issues/2109), in public [docking](https://github.com/ocornut/imgui/tree/docking) branch) -- Work on Multi-Viewport / Multiple OS windows. (see [#1542](https://github.com/ocornut/imgui/issues/1542), in public [docking](https://github.com/ocornut/imgui/tree/docking) branch looking for feedback) -- Work on gamepad/keyboard controls. (see [#787](https://github.com/ocornut/imgui/issues/787)) -- Work on automation and testing system, both to test the library and end-user apps. (see [#435](https://github.com/ocornut/imgui/issues/435)) -- Make the examples look better, improve styles, improve font support, make the examples hi-DPI and multi-DPI aware. - ### Gallery -For more user-submitted screenshots of projects using Dear ImGui, check out the [Gallery Threads](https://github.com/ocornut/imgui/issues/5243)! +For more user-submitted screenshots of projects using Dear ImGui, check out the [Gallery Threads](https://github.com/ocornut/imgui/issues/6478)! For a list of third-party widgets and extensions, check out the [Useful Extensions/Widgets](https://github.com/ocornut/imgui/wiki/Useful-Extensions) wiki page. -Custom engine [ehre](https://github.com/tksuoran/erhe) (docking branch) -[![ehre](https://user-images.githubusercontent.com/8225057/166686854-3f76bf28-0442-4fac-8e65-9fc9650d2ed0.jpg)](https://user-images.githubusercontent.com/994606/147875067-a848991e-2ad2-4fd3-bf71-4aeb8a547bcf.png) - -Custom engine for [Wonder Boy: The Dragon's Trap](http://www.TheDragonsTrap.com) (2017) -[![screenshot game](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v149/gallery_TheDragonsTrap-01-thumb.jpg)](https://cloud.githubusercontent.com/assets/8225057/20628927/33e14cac-b329-11e6-80f6-9524e93b048a.png) - -Custom engine (untitled) -[![screenshot tool](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v160/editor_white_preview.jpg)](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v160/editor_white.png) - -[Tracy Profiler](https://github.com/wolfpld/tracy) -![tracy profiler](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v176/tracy_profiler.png) +| | | +|--|--| +| Custom engine [erhe](https://github.com/tksuoran/erhe) (docking branch)
[![erhe](https://user-images.githubusercontent.com/8225057/190203358-6988b846-0686-480e-8663-1311fbd18abd.jpg)](https://user-images.githubusercontent.com/994606/147875067-a848991e-2ad2-4fd3-bf71-4aeb8a547bcf.png) | Custom engine for [Wonder Boy: The Dragon's Trap](http://www.TheDragonsTrap.com) (2017)
[![the dragon's trap](https://user-images.githubusercontent.com/8225057/190203379-57fcb80e-4aec-4fec-959e-17ddd3cd71e5.jpg)](https://cloud.githubusercontent.com/assets/8225057/20628927/33e14cac-b329-11e6-80f6-9524e93b048a.png) | +| Custom engine (untitled)
[![editor white](https://user-images.githubusercontent.com/8225057/190203393-c5ac9f22-b900-4d1e-bfeb-6027c63e3d92.jpg)](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v160/editor_white.png) | Tracy Profiler ([github](https://github.com/wolfpld/tracy))
[![tracy profiler](https://user-images.githubusercontent.com/8225057/190203401-7b595f6e-607c-44d3-97ea-4c2673244dfb.jpg)](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v176/tracy_profiler.png) | ### Support, Frequently Asked Questions (FAQ) @@ -174,55 +152,38 @@ See: [Wiki](https://github.com/ocornut/imgui/wiki) for many links, references, a See: [Articles about the IMGUI paradigm](https://github.com/ocornut/imgui/wiki#about-the-imgui-paradigm) to read/learn about the Immediate Mode GUI paradigm. -Getting started? For first-time users having issues compiling/linking/running or issues loading fonts, please use [GitHub Discussions](https://github.com/ocornut/imgui/discussions). +See: [Upcoming Changes](https://github.com/ocornut/imgui/wiki/Upcoming-Changes). -For other questions, bug reports, requests, feedback, you may post on [GitHub Issues](https://github.com/ocornut/imgui/issues). Please read and fill the New Issue template carefully. +See: [Dear ImGui Test Engine + Test Suite](https://github.com/ocornut/imgui_test_engine) for Automation & Testing. + +Getting started? For first-time users having issues compiling/linking/running or issues loading fonts, please use [GitHub Discussions](https://github.com/ocornut/imgui/discussions). For other questions, bug reports, requests, feedback, you may post on [GitHub Issues](https://github.com/ocornut/imgui/issues). Please read and fill the New Issue template carefully. Private support is available for paying business customers (E-mail: _contact @ dearimgui dot com_). **Which version should I get?** -We occasionally tag [Releases](https://github.com/ocornut/imgui/releases) but it is generally safe and recommended to sync to master/latest. The library is fairly stable and regressions tend to be fixed fast when reported. - -Advanced users may want to use the `docking` branch with [Multi-Viewport](https://github.com/ocornut/imgui/issues/1542) and [Docking](https://github.com/ocornut/imgui/issues/2109) features. This branch is kept in sync with master regularly. +We occasionally tag [Releases](https://github.com/ocornut/imgui/releases) (with nice releases notes) but it is generally safe and recommended to sync to master/latest. The library is fairly stable and regressions tend to be fixed fast when reported. Advanced users may want to use the `docking` branch with [Multi-Viewport](https://github.com/ocornut/imgui/issues/1542) and [Docking](https://github.com/ocornut/imgui/issues/2109) features. This branch is kept in sync with master regularly. **Who uses Dear ImGui?** -See the [Quotes](https://github.com/ocornut/imgui/wiki/Quotes), [Sponsors](https://github.com/ocornut/imgui/wiki/Sponsors), [Software using dear imgui](https://github.com/ocornut/imgui/wiki/Software-using-dear-imgui) Wiki pages for an idea of who is using Dear ImGui. Please add your game/software if you can! Also see the [Gallery Threads](https://github.com/ocornut/imgui/issues/5243)! +See the [Quotes](https://github.com/ocornut/imgui/wiki/Quotes), [Sponsors](https://github.com/ocornut/imgui/wiki/Sponsors), and [Software using Dear ImGui](https://github.com/ocornut/imgui/wiki/Software-using-dear-imgui) Wiki pages for an idea of who is using Dear ImGui. Please add your game/software if you can! Also, see the [Gallery Threads](https://github.com/ocornut/imgui/issues/6478)! How to help ----------- **How can I help?** -- See [GitHub Forum/issues](https://github.com/ocornut/imgui/issues) and [Github Discussions](https://github.com/ocornut/imgui/discussions). -- You may help with development and submit pull requests! Please understand that by submitting a PR you are also submitting a request for the maintainer to review your code and then take over its maintenance forever. PR should be crafted both in the interest in the end-users and also to ease the maintainer into understanding and accepting it. +- See [GitHub Forum/Issues](https://github.com/ocornut/imgui/issues) and [GitHub Discussions](https://github.com/ocornut/imgui/discussions). +- You may help with development and submit pull requests! Please understand that by submitting a PR you are also submitting a request for the maintainer to review your code and then take over its maintenance forever. PR should be crafted both in the interest of the end-users and also to ease the maintainer into understanding and accepting it. - See [Help wanted](https://github.com/ocornut/imgui/wiki/Help-Wanted) on the [Wiki](https://github.com/ocornut/imgui/wiki/) for some more ideas. -- Have your company financially support this project (please reach by e-mail) - -**How can I help financing further development of Dear ImGui?** - -See [Sponsors](https://github.com/ocornut/imgui/wiki/Sponsors) page. +- Have your company financially support this project with invoiced sponsoring/support contracts or by buying a license for [Dear ImGui Test Engine](https://github.com/ocornut/imgui_test_engine) (please reach out: contact at dearimgui dot com). Sponsors -------- -Ongoing Dear ImGui development is currently financially supported in 2021-2022 by users and private sponsors: - -*Platinum-chocolate sponsors* -- [Blizzard](https://careers.blizzard.com/en-us/openings/engineering/all/all/all/1) - -*Double-chocolate sponsors* -- [Ubisoft](https://montreal.ubisoft.com/en/ubisoft-sponsors-user-interface-library-for-c-dear-imgui), [Supercell](https://supercell.com) - -*Chocolate sponsors* -- [Adobe](https://www.adobe.com/products/medium.html), [Aras Pranckevičius](https://aras-p.info), [Epic](https://www.unrealengine.com/en-US/megagrants), [G3Dvu](). - -*Salty-caramel sponsors* -- [Kylotonn](https://www.kylotonn.com), [O-Net Communications (USA)](http://en.o-netcom.com), [Wonderland Engine](https://wonderlandengine.com/). - -Please see [detailed list of current and past Dear ImGui supporters](https://github.com/ocornut/imgui/wiki/Sponsors) for more. -From November 2014 to December 2019, ongoing development has also been financially supported by its users on Patreon and through individual donations. +Ongoing Dear ImGui development is and has been financially supported by users and private sponsors. +
Please see the **[detailed list of current and past Dear ImGui supporters](https://github.com/ocornut/imgui/wiki/Sponsors)** for details. +
From November 2014 to December 2019, ongoing development has also been financially supported by its users on Patreon and through individual donations. **THANK YOU to all past and present supporters for helping to keep this project alive and thriving!** @@ -236,15 +197,14 @@ Credits Developed by [Omar Cornut](https://www.miracleworld.net) and every direct or indirect [contributors](https://github.com/ocornut/imgui/graphs/contributors) to the GitHub. The early version of this library was developed with the support of [Media Molecule](https://www.mediamolecule.com) and first used internally on the game [Tearaway](https://tearaway.mediamolecule.com) (PS Vita). -Recurring contributors (2022): Omar Cornut [@ocornut](https://github.com/ocornut), Rokas Kupstys [@rokups](https://github.com/rokups) (a large portion of work on automation systems, regression tests and other features are currently unpublished). +Recurring contributors (2022): Omar Cornut [@ocornut](https://github.com/ocornut), Rokas Kupstys [@rokups](https://github.com/rokups) (a good portion of work on automation system and regression tests now available in [Dear ImGui Test Engine](https://github.com/ocornut/imgui_test_engine)). -Sponsoring, support contracts and other B2B transactions are hosted and handled by [Lizardcube](https://www.lizardcube.com). +Sponsoring, support contracts and other B2B transactions are hosted and handled by [Disco Hello](https://www.discohello.com). Omar: "I first discovered the IMGUI paradigm at [Q-Games](https://www.q-games.com) where Atman Binstock had dropped his own simple implementation in the codebase, which I spent quite some time improving and thinking about. It turned out that Atman was exposed to the concept directly by working with Casey. When I moved to Media Molecule I rewrote a new library trying to overcome the flaws and limitations of the first one I've worked with. It became this library and since then I have spent an unreasonable amount of time iterating and improving it." Embeds [ProggyClean.ttf](http://upperbounds.net) font by Tristan Grimmer (MIT license). - -Embeds [stb_textedit.h, stb_truetype.h, stb_rect_pack.h](https://github.com/nothings/stb/) by Sean Barrett (public domain). +
Embeds [stb_textedit.h, stb_truetype.h, stb_rect_pack.h](https://github.com/nothings/stb/) by Sean Barrett (public domain). Inspiration, feedback, and testing for early versions: Casey Muratori, Atman Binstock, Mikko Mononen, Emmanuel Briney, Stefan Kamoda, Anton Mikhailov, Matt Willis. Also thank you to everyone posting feedback, questions and patches on GitHub. diff --git a/extern/imgui_patched/docs/TODO.txt b/extern/imgui_patched/docs/TODO.txt index 002f56e5..2c67c26b 100644 --- a/extern/imgui_patched/docs/TODO.txt +++ b/extern/imgui_patched/docs/TODO.txt @@ -74,7 +74,7 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - input text: reorganize event handling, allow CharFilter to modify buffers, allow multiple events? (#541) - input text: expose CursorPos in char filter event (#816) - input text: try usage idiom of using InputText with data only exposed through get/set accessors, without extraneous copy/alloc. (#3009) - - input text: access public fields via a non-callback API e.g. InputTextGetState("xxx") that may return NULL if not active (available in internals) + - input text: access public fields via a non-callback API e.g. InputTextGetState("xxx") that may return nullptr if not active (available in internals) - input text: flag to disable live update of the user buffer (also applies to float/int text input) (#701) - input text: hover tooltip could show unclamped text - input text: support for INSERT key to toggle overwrite mode. currently disabled because stb_textedit behavior is unsatisfactory on multi-line. (#2863) @@ -113,6 +113,8 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - layout: (R&D) local multi-pass layout mode. - layout: (R&D) bind authored layout data (created by an off-line tool), items fetch their pos/size at submission, self-optimize data structures to stable linear access. + - tables: see https://github.com/ocornut/imgui/issues/2957#issuecomment-569726095 + - group: BeginGroup() needs a border option. (~#1496) - group: IsHovered() after EndGroup() covers whole AABB rather than the intersection of individual items. Is that desirable? - group: merge deactivation/activation within same group (fwd WasEdited flag). (#2550) @@ -321,7 +323,7 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - font: fix AddRemapChar() to work before atlas has been built. - font: (api breaking) remove "TTF" from symbol names. also because it now supports OTF. - font/opt: Considering storing standalone AdvanceX table as 16-bit fixed point integer? - - font/opt: Glyph currently 40 bytes (2+9*4). Consider storing UV as 16 bits integer? (->32 bytes). X0/Y0/X1/Y1 as 16 fixed-point integers? Or X0/Y0 as float and X1/Y1 as fixed8_8? + - font/opt: Glyph currently 40 bytes (2+9*4). Consider storing UV as 16-bits integer? (->32 bytes). X0/Y0/X1/Y1 as 16 fixed-point integers? Or X0/Y0 as float and X1/Y1 as fixed8_8? - nav: some features such as PageUp/Down/Home/End should probably work without ImGuiConfigFlags_NavEnableKeyboard? (where do we draw the line? how about CTRL+Tab) ! nav: never clear NavId on some setup (e.g. gamepad centric) @@ -345,7 +347,7 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - nav/menus: allow pressing Menu to leave a sub-menu. - nav/menus: a way to access the main menu bar with Alt? (currently needs CTRL+TAB) or last focused window menu bar? - nav/menus: when using the main menu bar, even though we restore focus after, the underlying window loses its title bar highlight during menu manipulation. could we prevent it? - - nav/menus: main menu bar currently cannot restore a NULL focus. Could save NavWindow at the time of being focused, similarly to what popup do? + - nav/menus: main menu bar currently cannot restore a nullptr focus. Could save NavWindow at the time of being focused, similarly to what popup do? - nav/menus: Alt,Up could open the first menu (e.g. "File") currently it tends to nav into the window/collapse menu. Do do that we would need custom transition? - nav/windowing: configure fade-in/fade-out delay on Ctrl+Tab? - nav/windowing: when CTRL+Tab/windowing is active, the HoveredWindow detection doesn't take account of the window display re-ordering. diff --git a/extern/imgui_patched/imconfig.h b/extern/imgui_patched/imconfig.h index 9a2aca4b..876cf32f 100644 --- a/extern/imgui_patched/imconfig.h +++ b/extern/imgui_patched/imconfig.h @@ -30,11 +30,11 @@ //#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS //#define IMGUI_DISABLE_OBSOLETE_KEYIO // 1.87: disable legacy io.KeyMap[]+io.KeysDown[] in favor io.AddKeyEvent(). This will be folded into IMGUI_DISABLE_OBSOLETE_FUNCTIONS in a few versions. -//---- Disable all of Dear ImGui or don't implement standard windows. -// It is very strongly recommended to NOT disable the demo windows during development. Please read comments in imgui_demo.cpp. +//---- Disable all of Dear ImGui or don't implement standard windows/tools. +// It is very strongly recommended to NOT disable the demo windows and debug tool during development. They are extremely useful in day to day work. Please read comments in imgui_demo.cpp. //#define IMGUI_DISABLE // Disable everything: all headers and source files will be empty. -//#define IMGUI_DISABLE_DEMO_WINDOWS // Disable demo windows: ShowDemoWindow()/ShowStyleEditor() will be empty. Not recommended. -//#define IMGUI_DISABLE_METRICS_WINDOW // Disable metrics/debugger and other debug tools: ShowMetricsWindow() and ShowStackToolWindow() will be empty. +//#define IMGUI_DISABLE_DEMO_WINDOWS // Disable demo windows: ShowDemoWindow()/ShowStyleEditor() will be empty. +//#define IMGUI_DISABLE_DEBUG_TOOLS // Disable metrics/debugger and other debug tools: ShowMetricsWindow(), ShowDebugLogWindow() and ShowStackToolWindow() will be empty (this was called IMGUI_DISABLE_METRICS_WINDOW before 1.88). //---- Don't implement some functions to reduce linkage requirements. //#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS // [Win32] Don't implement default clipboard handler. Won't use and link with OpenClipboard/GetClipboardData/CloseClipboard etc. (user32.lib/.a, kernel32.lib/.a) @@ -90,6 +90,8 @@ constexpr ImVec4(const MyVec4& f) : x(f.x), y(f.y), z(f.z), w(f.w) {} \ operator MyVec4() const { return MyVec4(x,y,z,w); } */ +//---- ...Or use Dear ImGui's own very basic math operators. +//#define IMGUI_DEFINE_MATH_OPERATORS //---- Use 32-bit vertex indices (default is 16-bit) is one way to allow large meshes with more than 64K vertices. // Your renderer backend will need to support it (most example renderer backends support both 16/32-bit indices). @@ -108,11 +110,6 @@ //#define IM_DEBUG_BREAK IM_ASSERT(0) //#define IM_DEBUG_BREAK __debugbreak() -//---- Debug Tools: Have the Item Picker break in the ItemAdd() function instead of ItemHoverable(), -// (which comes earlier in the code, will catch a few extra items, allow picking items other than Hovered one.) -// This adds a small runtime cost which is why it is not enabled by default. -//#define IMGUI_DEBUG_TOOL_ITEM_PICKER_EX - //---- Debug Tools: Enable slower asserts //#define IMGUI_DEBUG_PARANOID diff --git a/extern/imgui_patched/imgui.cpp b/extern/imgui_patched/imgui.cpp index e2552fe2..90dc211f 100644 --- a/extern/imgui_patched/imgui.cpp +++ b/extern/imgui_patched/imgui.cpp @@ -1,17 +1,17 @@ -// dear imgui, 1.88 WIP +// dear imgui, v1.89.6 // (main code and documentation) // Help: -// - Read FAQ at http://dearimgui.org/faq +// - Read FAQ at http://dearimgui.com/faq // - Newcomers, read 'Programmer guide' below for notes on how to setup Dear ImGui in your codebase. // - Call and read ImGui::ShowDemoWindow() in imgui_demo.cpp. All applications in examples/ are doing that. // Read imgui.cpp for details, links and comments. // Resources: -// - FAQ http://dearimgui.org/faq +// - FAQ http://dearimgui.com/faq // - Homepage & latest https://github.com/ocornut/imgui // - Releases & changelog https://github.com/ocornut/imgui/releases -// - Gallery https://github.com/ocornut/imgui/issues/5243 (please post your screenshots/video there!) +// - Gallery https://github.com/ocornut/imgui/issues/6478 (please post your screenshots/video there!) // - Wiki https://github.com/ocornut/imgui/wiki (lots of good stuff there) // - Glossary https://github.com/ocornut/imgui/wiki/Glossary // - Issues & support https://github.com/ocornut/imgui/issues @@ -39,17 +39,16 @@ Index of this file: DOCUMENTATION - MISSION STATEMENT -- END-USER GUIDE +- CONTROLS GUIDE - PROGRAMMER GUIDE - READ FIRST - HOW TO UPDATE TO A NEWER VERSION OF DEAR IMGUI - GETTING STARTED WITH INTEGRATING DEAR IMGUI IN YOUR CODE/ENGINE - HOW A SIMPLE APPLICATION MAY LOOK LIKE - HOW A SIMPLE RENDERING FUNCTION MAY LOOK LIKE - - USING GAMEPAD/KEYBOARD NAVIGATION CONTROLS - API BREAKING CHANGES (read me when you update!) - FREQUENTLY ASKED QUESTIONS (FAQ) - - Read all answers online: https://www.dearimgui.org/faq, or in docs/FAQ.md (with a Markdown viewer) + - Read all answers online: https://www.dearimgui.com/faq, or in docs/FAQ.md (with a Markdown viewer) CODE (search for "[SECTION]" in the code to find them) @@ -65,10 +64,11 @@ CODE // [SECTION] MISC HELPERS/UTILITIES (Color functions) // [SECTION] ImGuiStorage // [SECTION] ImGuiTextFilter -// [SECTION] ImGuiTextBuffer +// [SECTION] ImGuiTextBuffer, ImGuiTextIndex // [SECTION] ImGuiListClipper // [SECTION] STYLING // [SECTION] RENDER HELPERS +// [SECTION] INITIALIZATION, SHUTDOWN // [SECTION] MAIN CODE (most of the code! lots of stuff, needs tidying up!) // [SECTION] INPUTS // [SECTION] ERROR CHECKING @@ -80,10 +80,12 @@ CODE // [SECTION] DRAG AND DROP // [SECTION] LOGGING/CAPTURING // [SECTION] SETTINGS +// [SECTION] LOCALIZATION // [SECTION] VIEWPORTS, PLATFORM WINDOWS // [SECTION] DOCKING // [SECTION] PLATFORM DEPENDENT HELPERS // [SECTION] METRICS/DEBUGGER WINDOW +// [SECTION] DEBUG LOG WINDOW // [SECTION] OTHER DEBUG TOOLS (ITEM PICKER, STACK TOOL) */ @@ -112,27 +114,73 @@ CODE - Limited layout features, intricate layouts are typically crafted in code. - END-USER GUIDE + CONTROLS GUIDE ============== - - Double-click on title bar to collapse window. - - Click upper right corner to close a window, available when 'bool* p_open' is passed to ImGui::Begin(). - - Click and drag on lower right corner to resize window (double-click to auto fit window to its contents). - - Click and drag on any empty space to move window. - - TAB/SHIFT+TAB to cycle through keyboard editable fields. - - CTRL+Click on a slider or drag box to input value as text. - - Use mouse wheel to scroll. - - Text editor: - - Hold SHIFT or use mouse to select text. - - CTRL+Left/Right to word jump. - - CTRL+Shift+Left/Right to select words. - - CTRL+A our Double-Click to select all. - - CTRL+X,CTRL+C,CTRL+V to use OS clipboard/ - - CTRL+Z,CTRL+Y to undo/redo. - - ESCAPE to revert text to its original value. - - Controls are automatically adjusted for OSX to match standard OSX text editing operations. - - General Keyboard controls: enable with ImGuiConfigFlags_NavEnableKeyboard. - - General Gamepad controls: enable with ImGuiConfigFlags_NavEnableGamepad. See suggested mappings in imgui.h ImGuiNavInput_ + download PNG/PSD at http://dearimgui.org/controls_sheets + - MOUSE CONTROLS + - Mouse wheel: Scroll vertically. + - SHIFT+Mouse wheel: Scroll horizontally. + - Click [X]: Close a window, available when 'bool* p_open' is passed to ImGui::Begin(). + - Click ^, Double-Click title: Collapse window. + - Drag on corner/border: Resize window (double-click to auto fit window to its contents). + - Drag on any empty space: Move window (unless io.ConfigWindowsMoveFromTitleBarOnly = true). + - Left-click outside popup: Close popup stack (right-click over underlying popup: Partially close popup stack). + + - TEXT EDITOR + - Hold SHIFT or Drag Mouse: Select text. + - CTRL+Left/Right: Word jump. + - CTRL+Shift+Left/Right: Select words. + - CTRL+A or Double-Click: Select All. + - CTRL+X, CTRL+C, CTRL+V: Use OS clipboard. + - CTRL+Z, CTRL+Y: Undo, Redo. + - ESCAPE: Revert text to its original value. + - On OSX, controls are automatically adjusted to match standard OSX text editing shortcuts and behaviors. + + - KEYBOARD CONTROLS + - Basic: + - Tab, SHIFT+Tab Cycle through text editable fields. + - CTRL+Tab, CTRL+Shift+Tab Cycle through windows. + - CTRL+Click Input text into a Slider or Drag widget. + - Extended features with `io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard`: + - Tab, SHIFT+Tab: Cycle through every items. + - Arrow keys Move through items using directional navigation. Tweak value. + - Arrow keys + Alt, Shift Tweak slower, tweak faster (when using arrow keys). + - Enter Activate item (prefer text input when possible). + - Space Activate item (prefer tweaking with arrows when possible). + - Escape Deactivate item, leave child window, close popup. + - Page Up, Page Down Previous page, next page. + - Home, End Scroll to top, scroll to bottom. + - Alt Toggle between scrolling layer and menu layer. + - CTRL+Tab then Ctrl+Arrows Move window. Hold SHIFT to resize instead of moving. + - Output when ImGuiConfigFlags_NavEnableKeyboard set, + - io.WantCaptureKeyboard flag is set when keyboard is claimed. + - io.NavActive: true when a window is focused and it doesn't have the ImGuiWindowFlags_NoNavInputs flag set. + - io.NavVisible: true when the navigation cursor is visible (usually goes to back false when mouse is used). + + - GAMEPAD CONTROLS + - Enable with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'. + - Particularly useful to use Dear ImGui on a console system (e.g. PlayStation, Switch, Xbox) without a mouse! + - Download controller mapping PNG/PSD at http://dearimgui.com/controls_sheets + - Backend support: backend needs to: + - Set 'io.BackendFlags |= ImGuiBackendFlags_HasGamepad' + call io.AddKeyEvent/AddKeyAnalogEvent() with ImGuiKey_Gamepad_XXX keys. + - For analog values (0.0f to 1.0f), backend is responsible to handling a dead-zone and rescaling inputs accordingly. + Backend code will probably need to transform your raw inputs (such as e.g. remapping your 0.2..0.9 raw input range to 0.0..1.0 imgui range, etc.). + - BEFORE 1.87, BACKENDS USED TO WRITE TO io.NavInputs[]. This is now obsolete. Please call io functions instead! + - If you need to share inputs between your game and the Dear ImGui interface, the easiest approach is to go all-or-nothing, + with a buttons combo to toggle the target. Please reach out if you think the game vs navigation input sharing could be improved. + + - REMOTE INPUTS SHARING & MOUSE EMULATION + - PS4/PS5 users: Consider emulating a mouse cursor with DualShock touch pad or a spare analog stick as a mouse-emulation fallback. + - Consoles/Tablet/Phone users: Consider using a Synergy 1.x server (on your PC) + run examples/libs/synergy/uSynergy.c (on your console/tablet/phone app) + in order to share your PC mouse/keyboard. + - See https://github.com/ocornut/imgui/wiki/Useful-Extensions#remoting for other remoting solutions. + - On a TV/console system where readability may be lower or mouse inputs may be awkward, you may want to set the ImGuiConfigFlags_NavEnableSetMousePos flag. + Enabling ImGuiConfigFlags_NavEnableSetMousePos + ImGuiBackendFlags_HasSetMousePos instructs Dear ImGui to move your mouse cursor along with navigation movements. + When enabled, the NewFrame() function may alter 'io.MousePos' and set 'io.WantSetMousePos' to notify you that it wants the mouse cursor to be moved. + When that happens your backend NEEDS to move the OS or underlying mouse cursor on the next frame. Some of the backends in examples/ do that. + (If you set the NavEnableSetMousePos flag but don't honor 'io.WantSetMousePos' properly, Dear ImGui will misbehave as it will see your mouse moving back & forth!) + (In a setup when you may not have easy control over the mouse cursor, e.g. uSynergy.c doesn't expose moving remote mouse cursor, you may want + to set a boolean to ignore your other external mouse positions until the external source is moved again.) PROGRAMMER GUIDE @@ -239,7 +287,7 @@ CODE // Build and load the texture atlas into a texture // (In the examples/ app this is usually done within the ImGui_ImplXXX_Init() function from one of the demo Renderer) int width, height; - unsigned char* pixels = NULL; + unsigned char* pixels = nullptr; io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height); // At this point you've got the texture data and you need to upload that to your graphic system: @@ -290,7 +338,7 @@ CODE --------------------------------------------- The backends in impl_impl_XXX.cpp files contain many working implementations of a rendering function. - void void MyImGuiRenderFunction(ImDrawData* draw_data) + void MyImGuiRenderFunction(ImDrawData* draw_data) { // TODO: Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled // TODO: Setup texture sampling state: sample with bilinear filtering (NOT point/nearest filtering). Use 'io.Fonts->Flags |= ImFontAtlasFlags_NoBakedLines;' to allow point/nearest filtering. @@ -342,43 +390,6 @@ CODE } - USING GAMEPAD/KEYBOARD NAVIGATION CONTROLS - ------------------------------------------ - - The gamepad/keyboard navigation is fairly functional and keeps being improved. - - Gamepad support is particularly useful to use Dear ImGui on a console system (e.g. PS4, Switch, XB1) without a mouse! - - You can ask questions and report issues at https://github.com/ocornut/imgui/issues/787 - - The initial focus was to support game controllers, but keyboard is becoming increasingly and decently usable. - - Keyboard: - - Application: Set io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard to enable. - - Internally: NewFrame() will automatically fill io.NavInputs[] based on backend's io.AddKeyEvent() calls. - - When keyboard navigation is active (io.NavActive + ImGuiConfigFlags_NavEnableKeyboard), - the io.WantCaptureKeyboard flag will be set. For more advanced uses, you may want to read from: - - io.NavActive: true when a window is focused and it doesn't have the ImGuiWindowFlags_NoNavInputs flag set. - - io.NavVisible: true when the navigation cursor is visible (and usually goes false when mouse is used). - - or query focus information with e.g. IsWindowFocused(ImGuiFocusedFlags_AnyWindow), IsItemFocused() etc. functions. - Please reach out if you think the game vs navigation input sharing could be improved. - - Gamepad: - - Application: Set io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad to enable. - - Backend: Set io.BackendFlags |= ImGuiBackendFlags_HasGamepad + call io.AddKeyEvent/AddKeyAnalogEvent() with ImGuiKey_Gamepad_XXX keys. - For analog values (0.0f to 1.0f), backend is responsible to handling a dead-zone and rescaling inputs accordingly. - Backend code will probably need to transform your raw inputs (such as e.g. remapping your 0.2..0.9 raw input range to 0.0..1.0 imgui range, etc.). - - Internally: NewFrame() will automatically fill io.NavInputs[] based on backend's io.AddKeyEvent() + io.AddKeyAnalogEvent() calls. - - BEFORE 1.87, BACKENDS USED TO WRITE DIRECTLY TO io.NavInputs[]. This is going to be obsoleted in the future. Please call io functions instead! - - You can download PNG/PSD files depicting the gamepad controls for common controllers at: http://dearimgui.org/controls_sheets - - If you need to share inputs between your game and the Dear ImGui interface, the easiest approach is to go all-or-nothing, - with a buttons combo to toggle the target. Please reach out if you think the game vs navigation input sharing could be improved. - - Mouse: - - PS4/PS5 users: Consider emulating a mouse cursor with DualShock4 touch pad or a spare analog stick as a mouse-emulation fallback. - - Consoles/Tablet/Phone users: Consider using a Synergy 1.x server (on your PC) + uSynergy.c (on your console/tablet/phone app) to share your PC mouse/keyboard. - - On a TV/console system where readability may be lower or mouse inputs may be awkward, you may want to set the ImGuiConfigFlags_NavEnableSetMousePos flag. - Enabling ImGuiConfigFlags_NavEnableSetMousePos + ImGuiBackendFlags_HasSetMousePos instructs dear imgui to move your mouse cursor along with navigation movements. - When enabled, the NewFrame() function may alter 'io.MousePos' and set 'io.WantSetMousePos' to notify you that it wants the mouse cursor to be moved. - When that happens your backend NEEDS to move the OS or underlying mouse cursor on the next frame. Some of the backends in examples/ do that. - (If you set the NavEnableSetMousePos flag but don't honor 'io.WantSetMousePos' properly, imgui will misbehave as it will see your mouse moving back and forth!) - (In a setup when you may not have easy control over the mouse cursor, e.g. uSynergy.c doesn't expose moving remote mouse cursor, you may want - to set a boolean to ignore your other external mouse positions until the external source is moved again.) - - API BREAKING CHANGES ==================== @@ -388,12 +399,78 @@ CODE You can read releases logs https://github.com/ocornut/imgui/releases for more details. (Docking/Viewport Branch) - - 2022/XX/XX (1.XX) - when multi-viewports are enabled, all positions will be in your natural OS coordinates space. It means that: - - reference to hard-coded positions such as in SetNextWindowPos(ImVec2(0,0)) are probably not what you want anymore. - you may use GetMainViewport()->Pos to offset hard-coded positions, e.g. SetNextWindowPos(GetMainViewport()->Pos) - - likewise io.MousePos and GetMousePos() will use OS coordinates. - If you query mouse positions to interact with non-imgui coordinates you will need to offset them, e.g. subtract GetWindowViewport()->Pos. + - 2023/XX/XX (1.XXXX) - when multi-viewports are enabled, all positions will be in your natural OS coordinates space. It means that: + - reference to hard-coded positions such as in SetNextWindowPos(ImVec2(0,0)) are probably not what you want anymore. + you may use GetMainViewport()->Pos to offset hard-coded positions, e.g. SetNextWindowPos(GetMainViewport()->Pos) + - likewise io.MousePos and GetMousePos() will use OS coordinates. + If you query mouse positions to interact with non-imgui coordinates you will need to offset them, e.g. subtract GetWindowViewport()->Pos. + - 2023/05/30 (1.89.6) - backends: renamed "imgui_impl_sdlrenderer.cpp" to "imgui_impl_sdlrenderer2.cpp" and "imgui_impl_sdlrenderer.h" to "imgui_impl_sdlrenderer2.h". This is in prevision for the future release of SDL3. + - 2023/05/22 (1.89.6) - listbox: commented out obsolete/redirecting functions that were marked obsolete more than two years ago: + - ListBoxHeader() -> use BeginListBox() (note how two variants of ListBoxHeader() existed. Check commented versions in imgui.h for reference) + - ListBoxFooter() -> use EndListBox() + - 2023/05/15 (1.89.6) - clipper: commented out obsolete redirection constructor 'ImGuiListClipper(int items_count, float items_height = -1.0f)' that was marked obsolete in 1.79. Use default constructor + clipper.Begin(). + - 2023/05/15 (1.89.6) - clipper: renamed ImGuiListClipper::ForceDisplayRangeByIndices() to ImGuiListClipper::IncludeRangeByIndices(). + - 2023/03/14 (1.89.4) - commented out redirecting enums/functions names that were marked obsolete two years ago: + - ImGuiSliderFlags_ClampOnInput -> use ImGuiSliderFlags_AlwaysClamp + - ImGuiInputTextFlags_AlwaysInsertMode -> use ImGuiInputTextFlags_AlwaysOverwrite + - ImDrawList::AddBezierCurve() -> use ImDrawList::AddBezierCubic() + - ImDrawList::PathBezierCurveTo() -> use ImDrawList::PathBezierCubicCurveTo() + - 2023/03/09 (1.89.4) - renamed PushAllowKeyboardFocus()/PopAllowKeyboardFocus() to PushTabStop()/PopTabStop(). Kept inline redirection functions (will obsolete). + - 2023/03/09 (1.89.4) - tooltips: Added 'bool' return value to BeginTooltip() for API consistency. Please only submit contents and call EndTooltip() if BeginTooltip() returns true. In reality the function will _currently_ always return true, but further changes down the line may change this, best to clarify API sooner. + - 2023/02/15 (1.89.4) - moved the optional "courtesy maths operators" implementation from imgui_internal.h in imgui.h. + Even though we encourage using your own maths types and operators by setting up IM_VEC2_CLASS_EXTRA, + it has been frequently requested by people to use our own. We had an opt-in define which was + previously fulfilled in imgui_internal.h. It is now fulfilled in imgui.h. (#6164) + - OK: #define IMGUI_DEFINE_MATH_OPERATORS / #include "imgui.h" / #include "imgui_internal.h" + - Error: #include "imgui.h" / #define IMGUI_DEFINE_MATH_OPERATORS / #include "imgui_internal.h" + - 2023/02/07 (1.89.3) - backends: renamed "imgui_impl_sdl.cpp" to "imgui_impl_sdl2.cpp" and "imgui_impl_sdl.h" to "imgui_impl_sdl2.h". (#6146) This is in prevision for the future release of SDL3. + - 2022/10/26 (1.89) - commented out redirecting OpenPopupContextItem() which was briefly the name of OpenPopupOnItemClick() from 1.77 to 1.79. + - 2022/10/12 (1.89) - removed runtime patching of invalid "%f"/"%0.f" format strings for DragInt()/SliderInt(). This was obsoleted in 1.61 (May 2018). See 1.61 changelog for details. + - 2022/09/26 (1.89) - renamed and merged keyboard modifiers key enums and flags into a same set. Kept inline redirection enums (will obsolete). + - ImGuiKey_ModCtrl and ImGuiModFlags_Ctrl -> ImGuiMod_Ctrl + - ImGuiKey_ModShift and ImGuiModFlags_Shift -> ImGuiMod_Shift + - ImGuiKey_ModAlt and ImGuiModFlags_Alt -> ImGuiMod_Alt + - ImGuiKey_ModSuper and ImGuiModFlags_Super -> ImGuiMod_Super + the ImGuiKey_ModXXX were introduced in 1.87 and mostly used by backends. + the ImGuiModFlags_XXX have been exposed in imgui.h but not really used by any public api only by third-party extensions. + exceptionally commenting out the older ImGuiKeyModFlags_XXX names ahead of obsolescence schedule to reduce confusion and because they were not meant to be used anyway. + - 2022/09/20 (1.89) - ImGuiKey is now a typed enum, allowing ImGuiKey_XXX symbols to be named in debuggers. + this will require uses of legacy backend-dependent indices to be casted, e.g. + - with imgui_impl_glfw: IsKeyPressed(GLFW_KEY_A) -> IsKeyPressed((ImGuiKey)GLFW_KEY_A); + - with imgui_impl_win32: IsKeyPressed('A') -> IsKeyPressed((ImGuiKey)'A') + - etc. However if you are upgrading code you might well use the better, backend-agnostic IsKeyPressed(ImGuiKey_A) now! + - 2022/09/12 (1.89) - removed the bizarre legacy default argument for 'TreePush(const void* ptr = NULL)', always pass a pointer value explicitly. NULL/nullptr is ok but require cast, e.g. TreePush((void*)nullptr); + - 2022/09/05 (1.89) - commented out redirecting functions/enums names that were marked obsolete in 1.77 and 1.78 (June 2020): + - DragScalar(), DragScalarN(), DragFloat(), DragFloat2(), DragFloat3(), DragFloat4(): For old signatures ending with (..., const char* format, float power = 1.0f) -> use (..., format ImGuiSliderFlags_Logarithmic) if power != 1.0f. + - SliderScalar(), SliderScalarN(), SliderFloat(), SliderFloat2(), SliderFloat3(), SliderFloat4(): For old signatures ending with (..., const char* format, float power = 1.0f) -> use (..., format ImGuiSliderFlags_Logarithmic) if power != 1.0f. + - BeginPopupContextWindow(const char*, ImGuiMouseButton, bool) -> use BeginPopupContextWindow(const char*, ImGuiPopupFlags) + - 2022/09/02 (1.89) - obsoleted using SetCursorPos()/SetCursorScreenPos() to extend parent window/cell boundaries. + this relates to when moving the cursor position beyond current boundaries WITHOUT submitting an item. + - previously this would make the window content size ~200x200: + Begin(...) + SetCursorScreenPos(GetCursorScreenPos() + ImVec2(200,200)) + End(); + - instead, please submit an item: + Begin(...) + SetCursorScreenPos(GetCursorScreenPos() + ImVec2(200,200)) + Dummy(ImVec2(0,0)) + End(); + - alternative: + Begin(...) + Dummy(ImVec2(200,200)) + End(); + - content size is now only extended when submitting an item! + - with '#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS' this will now be detected and assert. + - without '#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS' this will silently be fixed until we obsolete it. + - 2022/08/03 (1.89) - changed signature of ImageButton() function. Kept redirection function (will obsolete). + - added 'const char* str_id' parameter + removed 'int frame_padding = -1' parameter. + - old signature: bool ImageButton(ImTextureID tex_id, ImVec2 size, ImVec2 uv0 = ImVec2(0,0), ImVec2 uv1 = ImVec2(1,1), int frame_padding = -1, ImVec4 bg_col = ImVec4(0,0,0,0), ImVec4 tint_col = ImVec4(1,1,1,1)); + - used the ImTextureID value to create an ID. This was inconsistent with other functions, led to ID conflicts, and caused problems with engines using transient ImTextureID values. + - had a FramePadding override which was inconsistent with other functions and made the already-long signature even longer. + - new signature: bool ImageButton(const char* str_id, ImTextureID tex_id, ImVec2 size, ImVec2 uv0 = ImVec2(0,0), ImVec2 uv1 = ImVec2(1,1), ImVec4 bg_col = ImVec4(0,0,0,0), ImVec4 tint_col = ImVec4(1,1,1,1)); + - requires an explicit identifier. You may still use e.g. PushID() calls and then pass an empty identifier. + - always uses style.FramePadding for padding, to be consistent with other buttons. You may use PushStyleVar() to alter this. + - 2022/07/08 (1.89) - inputs: removed io.NavInputs[] and ImGuiNavInput enum (following 1.87 changes). + - Official backends from 1.87+ -> no issue. + - Official backends from 1.60 to 1.86 -> will build and convert gamepad inputs, unless IMGUI_DISABLE_OBSOLETE_KEYIO is defined. Need updating! + - Custom backends not writing to io.NavInputs[] -> no issue. + - Custom backends writing to io.NavInputs[] -> will build and convert gamepad inputs, unless IMGUI_DISABLE_OBSOLETE_KEYIO is defined. Need fixing! + - TL;DR: Backends should call io.AddKeyEvent()/io.AddKeyAnalogEvent() with ImGuiKey_GamepadXXX values instead of filling io.NavInput[]. + - 2022/06/15 (1.88) - renamed IMGUI_DISABLE_METRICS_WINDOW to IMGUI_DISABLE_DEBUG_TOOLS for correctness. kept support for old define (will obsolete). - 2022/05/03 (1.88) - backends: osx: removed ImGui_ImplOSX_HandleEvent() from backend API in favor of backend automatically handling event capture. All ImGui_ImplOSX_HandleEvent() calls should be removed as they are now unnecessary. - 2022/04/05 (1.88) - inputs: renamed ImGuiKeyModFlags to ImGuiModFlags. Kept inline redirection enums (will obsolete). This was never used in public API functions but technically present in imgui.h and ImGuiIO. - 2022/01/20 (1.87) - inputs: reworded gamepad IO. @@ -405,11 +482,12 @@ CODE - Backend writing to io.MouseWheel -> backend should call io.AddMouseWheelEvent() - Backend writing to io.MouseHoveredViewport -> backend should call io.AddMouseViewportEvent() [Docking branch w/ multi-viewports only] note: for all calls to IO new functions, the Dear ImGui context should be bound/current. + read https://github.com/ocornut/imgui/issues/4921 for details. - 2022/01/10 (1.87) - inputs: reworked keyboard IO. Removed io.KeyMap[], io.KeysDown[] in favor of calling io.AddKeyEvent(). Removed GetKeyIndex(), now unecessary. All IsKeyXXX() functions now take ImGuiKey values. All features are still functional until IMGUI_DISABLE_OBSOLETE_KEYIO is defined. Read Changelog and Release Notes for details. - IsKeyPressed(MY_NATIVE_KEY_XXX) -> use IsKeyPressed(ImGuiKey_XXX) - IsKeyPressed(GetKeyIndex(ImGuiKey_XXX)) -> use IsKeyPressed(ImGuiKey_XXX) - - Backend writing to io.KeyMap[],io.KeysDown[] -> backend should call io.AddKeyEvent() - - Backend writing to io.KeyCtrl, io.KeyShift.. -> backend should call io.AddKeyEvent() with ImGuiKey_ModXXX values. *IF YOU PULLED CODE BETWEEN 2021/01/10 and 2021/01/27: We used to have a io.AddKeyModsEvent() function which was now replaced by io.AddKeyEvent() with ImGuiKey_ModXXX values.* + - Backend writing to io.KeyMap[],io.KeysDown[] -> backend should call io.AddKeyEvent() (+ call io.SetKeyEventNativeData() if you want legacy user code to stil function with legacy key codes). + - Backend writing to io.KeyCtrl, io.KeyShift.. -> backend should call io.AddKeyEvent() with ImGuiMod_XXX values. *IF YOU PULLED CODE BETWEEN 2021/01/10 and 2021/01/27: We used to have a io.AddKeyModsEvent() function which was now replaced by io.AddKeyEvent() with ImGuiMod_XXX values.* - one case won't work with backward compatibility: if your custom backend used ImGuiKey as mock native indices (e.g. "io.KeyMap[ImGuiKey_A] = ImGuiKey_A") because those values are now larger than the legacy KeyDown[] array. Will assert. - inputs: added ImGuiKey_ModCtrl/ImGuiKey_ModShift/ImGuiKey_ModAlt/ImGuiKey_ModSuper values to submit keyboard modifiers using io.AddKeyEvent(), instead of writing directly to io.KeyCtrl, io.KeyShift, io.KeyAlt, io.KeySuper. - 2022/01/05 (1.87) - inputs: renamed ImGuiKey_KeyPadEnter to ImGuiKey_KeypadEnter to align with new symbols. Kept redirection enum. @@ -719,7 +797,7 @@ CODE ================================ Read all answers online: - https://www.dearimgui.org/faq or https://github.com/ocornut/imgui/blob/master/docs/FAQ.md (same url) + https://www.dearimgui.com/faq or https://github.com/ocornut/imgui/blob/master/docs/FAQ.md (same url) Read all answers locally (with a text editor or ideally a Markdown viewer): docs/FAQ.md Some answers are copied down here to facilitate searching in code. @@ -743,7 +821,7 @@ CODE Q: What is this library called? Q: Which version should I get? >> This library is called "Dear ImGui", please don't call it "ImGui" :) - >> See https://www.dearimgui.org/faq for details. + >> See https://www.dearimgui.com/faq for details. Q&A: Integration ================ @@ -753,14 +831,14 @@ CODE Q: How can I tell whether to dispatch mouse/keyboard to Dear ImGui or my application? A: You should read the 'io.WantCaptureMouse', 'io.WantCaptureKeyboard' and 'io.WantTextInput' flags! - >> See https://www.dearimgui.org/faq for a fully detailed answer. You really want to read this. + >> See https://www.dearimgui.com/faq for a fully detailed answer. You really want to read this. Q. How can I enable keyboard controls? Q: How can I use this without a mouse, without a keyboard or without a screen? (gamepad, input share, remote display) Q: I integrated Dear ImGui in my engine and little squares are showing instead of text... Q: I integrated Dear ImGui in my engine and some elements are clipping or disappearing when I move windows around... Q: I integrated Dear ImGui in my engine and some elements are displaying outside their expected windows boundaries... - >> See https://www.dearimgui.org/faq + >> See https://www.dearimgui.com/faq Q&A: Usage ---------- @@ -770,11 +848,11 @@ CODE - How can I have widgets with an empty label? - How can I have multiple widgets with the same label? - How can I have multiple windows with the same label? - Q: How can I display an image? What is ImTextureID, how does it works? + Q: How can I display an image? What is ImTextureID, how does it work? Q: How can I use my own math types instead of ImVec2/ImVec4? Q: How can I interact with standard C++ types (such as std::string and std::vector)? Q: How can I display custom shapes? (using low-level ImDrawList API) - >> See https://www.dearimgui.org/faq + >> See https://www.dearimgui.com/faq Q&A: Fonts, Text ================ @@ -784,7 +862,7 @@ CODE Q: How can I easily use icons in my application? Q: How can I load multiple fonts? Q: How can I display and input non-Latin characters such as Chinese, Japanese, Korean, Cyrillic? - >> See https://www.dearimgui.org/faq and https://github.com/ocornut/imgui/edit/master/docs/FONTS.md + >> See https://www.dearimgui.com/faq and https://github.com/ocornut/imgui/edit/master/docs/FONTS.md Q&A: Concerns ============= @@ -793,7 +871,7 @@ CODE Q: Can you create elaborate/serious tools with Dear ImGui? Q: Can you reskin the look of Dear ImGui? Q: Why using C++ (as opposed to C)? - >> See https://www.dearimgui.org/faq + >> See https://www.dearimgui.com/faq Q&A: Community ============== @@ -820,16 +898,15 @@ CODE #define _CRT_SECURE_NO_WARNINGS #endif -#include "imgui.h" -#ifndef IMGUI_DISABLE - #ifndef IMGUI_DEFINE_MATH_OPERATORS #define IMGUI_DEFINE_MATH_OPERATORS #endif + +#include "imgui.h" +#ifndef IMGUI_DISABLE #include "imgui_internal.h" // System includes -#include // toupper #include // vsnprintf, sscanf, printf #if defined(_MSC_VER) && _MSC_VER <= 1500 // MSVC 2008 or earlier #include // intptr_t @@ -878,7 +955,7 @@ CODE #if defined(_MSC_VER) && _MSC_VER >= 1922 // MSVC 2019 16.2 or later #pragma warning (disable: 5054) // operator '|': deprecated between enumerations of different types #endif -#pragma warning (disable: 26451) // [Static Analyzer] Arithmetic overflow : Using operator 'xxx' on a 4 byte value and then casting the result to a 8 byte value. Cast the value to the wider type before calling operator 'xxx' to avoid overflow(io.2). +#pragma warning (disable: 26451) // [Static Analyzer] Arithmetic overflow : Using operator 'xxx' on a 4 byte value and then casting the result to an 8 byte value. Cast the value to the wider type before calling operator 'xxx' to avoid overflow(io.2). #pragma warning (disable: 26495) // [Static Analyzer] Variable 'XXX' is uninitialized. Always initialize a member variable (type.6). #pragma warning (disable: 26812) // [Static Analyzer] The enum type 'xxx' is unscoped. Prefer 'enum class' over 'enum' (Enum.3). #endif @@ -901,7 +978,7 @@ CODE #pragma clang diagnostic ignored "-Wdouble-promotion" // warning: implicit conversion from 'float' to 'double' when passing argument to function // using printf() is a misery with this as C++ va_arg ellipsis changes float to double. #pragma clang diagnostic ignored "-Wimplicit-int-float-conversion" // warning: implicit conversion from 'xxx' to 'float' may lose precision #elif defined(__GNUC__) -// We disable -Wpragmas because GCC doesn't provide an has_warning equivalent and some forks/patches may not following the warning/version association. +// We disable -Wpragmas because GCC doesn't provide a has_warning equivalent and some forks/patches may not follow the warning/version association. #pragma GCC diagnostic ignored "-Wpragmas" // warning: unknown option after '#pragma GCC diagnostic' kind #pragma GCC diagnostic ignored "-Wunused-function" // warning: 'xxxx' defined but not used #pragma GCC diagnostic ignored "-Wint-to-pointer-cast" // warning: cast to pointer from integer of different size @@ -925,7 +1002,7 @@ static const float NAV_WINDOWING_LIST_APPEAR_DELAY = 0.15f; // Time // Window resizing from edges (when io.ConfigWindowsResizeFromEdges = true and ImGuiBackendFlags_HasMouseCursors is set in io.BackendFlags by backend) static const float WINDOWS_HOVER_PADDING = 4.0f; // Extend outside window for hovering/resizing (maxxed with TouchPadding) and inside windows for borders. Affect FindHoveredWindow(). static const float WINDOWS_RESIZE_FROM_EDGES_FEEDBACK_TIMER = 0.04f; // Reduce visual noise by only highlighting the border after a certain time. -static const float WINDOWS_MOUSE_WHEEL_SCROLL_LOCK_TIMER = 2.00f; // Lock scrolled window (so it doesn't pick child windows that are scrolling through) for a certain time, unless mouse moved. +static const float WINDOWS_MOUSE_WHEEL_SCROLL_LOCK_TIMER = 0.70f; // Lock scrolled window (so it doesn't pick child windows that are scrolling through) for a certain time, unless mouse moved. // Docking static const float DOCKING_TRANSPARENT_PAYLOAD_ALPHA = 0.50f; // For use with io.ConfigDockingTransparentPayload. Apply to Viewport _or_ WindowBg in host viewport. @@ -951,8 +1028,8 @@ static void WindowSettingsHandler_ApplyAll(ImGuiContext*, ImGuiSetti static void WindowSettingsHandler_WriteAll(ImGuiContext*, ImGuiSettingsHandler*, ImGuiTextBuffer* buf); // Platform Dependents default implementation for IO functions -static const char* GetClipboardTextFn_DefaultImpl(void* user_data); -static void SetClipboardTextFn_DefaultImpl(void* user_data, const char* text); +static const char* GetClipboardTextFn_DefaultImpl(void* user_data_ctx); +static void SetClipboardTextFn_DefaultImpl(void* user_data_ctx, const char* text); static void SetPlatformImeDataFn_DefaultImpl(ImGuiViewport* viewport, ImGuiPlatformImeData* data); namespace ImGui @@ -971,7 +1048,7 @@ static void NavEndFrame(); static bool NavScoreItem(ImGuiNavItemData* result); static void NavApplyItemToResult(ImGuiNavItemData* result); static void NavProcessItem(); -static void NavProcessItemForTabbingRequest(ImGuiID id); +static void NavProcessItemForTabbingRequest(ImGuiID id, ImGuiItemFlags item_flags, ImGuiNavMoveFlags move_flags); static ImVec2 NavCalcPreferredRefPos(); static void NavSaveLastChildNavWindowIntoParent(ImGuiWindow* nav_window); static ImGuiWindow* NavRestoreLastChildNavWindow(ImGuiWindow* window); @@ -985,18 +1062,20 @@ static void ErrorCheckEndFrameSanityChecks(); static void UpdateDebugToolItemPicker(); static void UpdateDebugToolStackQueries(); -// Misc -static void UpdateSettings(); +// Inputs static void UpdateKeyboardInputs(); static void UpdateMouseInputs(); static void UpdateMouseWheel(); +static void UpdateKeyRoutingTable(ImGuiKeyRoutingTable* rt); + +// Misc +static void UpdateSettings(); static bool UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& size_auto_fit, int* border_held, int resize_grip_count, ImU32 resize_grip_col[4], const ImRect& visibility_rect); static void RenderWindowOuterBorders(ImGuiWindow* window); static void RenderWindowDecorations(ImGuiWindow* window, const ImRect& title_bar_rect, bool title_bar_is_highlight, bool handle_borders_and_resize_grips, int resize_grip_count, const ImU32 resize_grip_col[4], float resize_grip_draw_size); static void RenderWindowTitleBarContents(ImGuiWindow* window, const ImRect& title_bar_rect, const char* name, bool* p_open); static void RenderDimmedBackgroundBehindWindow(ImGuiWindow* window, ImU32 col); static void RenderDimmedBackgrounds(); -static ImGuiWindow* FindBlockingModal(ImGuiWindow* window); // Viewports const ImGuiID IMGUI_VIEWPORT_DEFAULT_ID = 0x11111111; // Using an arbitrary constant instead of e.g. ImHashStr("ViewportDefault", 0); so it's easier to spot in the debugger. The exact value doesn't matter. @@ -1087,15 +1166,18 @@ ImGuiStyle::ImGuiStyle() ColumnsMinSpacing = 6.0f; // Minimum horizontal spacing between two columns. Preferably > (FramePadding.x + 1). ScrollbarSize = 14.0f; // Width of the vertical scrollbar, Height of the horizontal scrollbar ScrollbarRounding = 9.0f; // Radius of grab corners rounding for scrollbar - GrabMinSize = 10.0f; // Minimum width/height of a grab box for slider/scrollbar + GrabMinSize = 12.0f; // Minimum width/height of a grab box for slider/scrollbar GrabRounding = 0.0f; // Radius of grabs corners rounding. Set to 0.0f to have rectangular slider grabs. LogSliderDeadzone = 4.0f; // The size in pixels of the dead-zone around zero on logarithmic sliders that cross zero. TabRounding = 4.0f; // Radius of upper corners of a tab. Set to 0.0f to have rectangular tabs. TabBorderSize = 0.0f; // Thickness of border around tabs. - TabMinWidthForCloseButton = 0.0f; // Minimum width for close button to appears on an unselected tab when hovered. Set to 0.0f to always show when hovering, set to FLT_MAX to never show close button unless selected. + TabMinWidthForCloseButton = 0.0f; // Minimum width for close button to appear on an unselected tab when hovered. Set to 0.0f to always show when hovering, set to FLT_MAX to never show close button unless selected. ColorButtonPosition = ImGuiDir_Right; // Side of the color button in the ColorEdit4 widget (left/right). Defaults to ImGuiDir_Right. ButtonTextAlign = ImVec2(0.5f,0.5f);// Alignment of button text when button is larger than text. SelectableTextAlign = ImVec2(0.0f,0.0f);// Alignment of selectable text. Defaults to (0.0f, 0.0f) (top-left aligned). It's generally important to keep this left-aligned if you want to lay multiple items on a same line. + SeparatorTextBorderSize = 3.0f; // Thickkness of border in SeparatorText() + SeparatorTextAlign = ImVec2(0.0f,0.5f);// Alignment of text within the separator. Defaults to (0.0f, 0.5f) (left aligned, center). + SeparatorTextPadding = ImVec2(20.0f,3.f);// Horizontal offset of text from each edge of the separator + spacing on other axis. Generally small values. .y is recommended to be == FramePadding.y. DisplayWindowPadding = ImVec2(19,19); // Window position are clamped to be visible within the display area or monitors by at least this amount. Only applies to regular windows. DisplaySafeAreaPadding = ImVec2(3,3); // If you cannot see the edge of your screen (e.g. on a TV) increase the safe area padding. Covers popups/tooltips as well regular windows. MouseCursorScale = 1.0f; // Scale software rendered mouse cursor (when io.MouseDrawCursor is enabled). May be removed later. @@ -1133,6 +1215,7 @@ void ImGuiStyle::ScaleAllSizes(float scale_factor) LogSliderDeadzone = ImFloor(LogSliderDeadzone * scale_factor); TabRounding = ImFloor(TabRounding * scale_factor); TabMinWidthForCloseButton = (TabMinWidthForCloseButton != FLT_MAX) ? ImFloor(TabMinWidthForCloseButton * scale_factor) : FLT_MAX; + SeparatorTextPadding = ImFloor(SeparatorTextPadding * scale_factor); DisplayWindowPadding = ImFloor(DisplayWindowPadding * scale_factor); DisplaySafeAreaPadding = ImFloor(DisplaySafeAreaPadding * scale_factor); MouseCursorScale = ImFloor(MouseCursorScale * scale_factor); @@ -1160,6 +1243,8 @@ ImGuiIO::ImGuiIO() #endif KeyRepeatDelay = 0.275f; KeyRepeatRate = 0.050f; + HoverDelayNormal = 0.30f; + HoverDelayShort = 0.10f; UserData = NULL; Fonts = NULL; @@ -1192,25 +1277,27 @@ ImGuiIO::ImGuiIO() #endif ConfigInputTrickleEventQueue = true; ConfigInputTextCursorBlink = true; + ConfigInputTextEnterKeepActive = false; + ConfigDragClickToInputText = false; ConfigWindowsResizeFromEdges = true; ConfigWindowsMoveFromTitleBarOnly = false; ConfigMemoryCompactTimer = 60.0f; + ConfigDebugBeginReturnValueOnce = false; + ConfigDebugBeginReturnValueLoop = false; // Platform Functions + // Note: Initialize() will setup default clipboard/ime handlers. BackendPlatformName = BackendRendererName = NULL; BackendPlatformUserData = BackendRendererUserData = BackendLanguageUserData = NULL; - GetClipboardTextFn = GetClipboardTextFn_DefaultImpl; // Platform dependent default implementations - SetClipboardTextFn = SetClipboardTextFn_DefaultImpl; - ClipboardUserData = NULL; - SetPlatformImeDataFn = SetPlatformImeDataFn_DefaultImpl; // Input (NB: we already have memset zero the entire structure!) MousePos = ImVec2(-FLT_MAX, -FLT_MAX); MousePosPrev = ImVec2(-FLT_MAX, -FLT_MAX); + MouseSource = ImGuiMouseSource_Mouse; MouseDragThreshold = 6.0f; for (int i = 0; i < IM_ARRAYSIZE(MouseDownDuration); i++) MouseDownDuration[i] = MouseDownDurationPrev[i] = -1.0f; for (int i = 0; i < IM_ARRAYSIZE(KeysData); i++) { KeysData[i].DownDuration = KeysData[i].DownDurationPrev = -1.0f; } - for (int i = 0; i < IM_ARRAYSIZE(NavInputsDownDuration); i++) NavInputsDownDuration[i] = -1.0f; + AppAcceptingEvents = true; BackendUsingLegacyKeyArrays = (ImS8)-1; BackendUsingLegacyNavInputArray = true; // assume using legacy array until proven wrong } @@ -1221,14 +1308,15 @@ ImGuiIO::ImGuiIO() // FIXME: Should in theory be called "AddCharacterEvent()" to be consistent with new API void ImGuiIO::AddInputCharacter(unsigned int c) { - ImGuiContext& g = *GImGui; - IM_ASSERT(&g.IO == this && "Can only add events to current context."); - if (c == 0) + IM_ASSERT(Ctx != NULL); + ImGuiContext& g = *Ctx; + if (c == 0 || !AppAcceptingEvents) return; ImGuiInputEvent e; e.Type = ImGuiInputEventType_Text; e.Source = ImGuiInputSource_Keyboard; + e.EventId = g.InputEventsNextEventId++; e.Text.Char = c; g.InputEventsQueue.push_back(e); } @@ -1237,7 +1325,7 @@ void ImGuiIO::AddInputCharacter(unsigned int c) // we should save the high surrogate. void ImGuiIO::AddInputCharacterUTF16(ImWchar16 c) { - if (c == 0 && InputQueueSurrogate == 0) + if ((c == 0 && InputQueueSurrogate == 0) || !AppAcceptingEvents) return; if ((c & 0xFC00) == 0xD800) // High surrogate, must save @@ -1271,20 +1359,23 @@ void ImGuiIO::AddInputCharacterUTF16(ImWchar16 c) void ImGuiIO::AddInputCharactersUTF8(const char* utf8_chars) { + if (!AppAcceptingEvents) + return; while (*utf8_chars != 0) { unsigned int c = 0; utf8_chars += ImTextCharFromUtf8(&c, utf8_chars, NULL); - if (c != 0) - AddInputCharacter(c); + AddInputCharacter(c); } } +// FIXME: Perhaps we could clear queued events as well? void ImGuiIO::ClearInputCharacters() { InputQueueCharacters.resize(0); } +// FIXME: Perhaps we could clear queued events as well? void ImGuiIO::ClearInputKeys() { #ifndef IMGUI_DISABLE_OBSOLETE_KEYIO @@ -1297,23 +1388,49 @@ void ImGuiIO::ClearInputKeys() KeysData[n].DownDurationPrev = -1.0f; } KeyCtrl = KeyShift = KeyAlt = KeySuper = false; - KeyMods = ImGuiModFlags_None; - for (int n = 0; n < IM_ARRAYSIZE(NavInputsDownDuration); n++) - NavInputsDownDuration[n] = NavInputsDownDurationPrev[n] = -1.0f; + KeyMods = ImGuiMod_None; + MousePos = ImVec2(-FLT_MAX, -FLT_MAX); + for (int n = 0; n < IM_ARRAYSIZE(MouseDown); n++) + { + MouseDown[n] = false; + MouseDownDuration[n] = MouseDownDurationPrev[n] = -1.0f; + } + MouseWheel = MouseWheelH = 0.0f; +} + +static ImGuiInputEvent* FindLatestInputEvent(ImGuiContext* ctx, ImGuiInputEventType type, int arg = -1) +{ + ImGuiContext& g = *ctx; + for (int n = g.InputEventsQueue.Size - 1; n >= 0; n--) + { + ImGuiInputEvent* e = &g.InputEventsQueue[n]; + if (e->Type != type) + continue; + if (type == ImGuiInputEventType_Key && e->Key.Key != arg) + continue; + if (type == ImGuiInputEventType_MouseButton && e->MouseButton.Button != arg) + continue; + return e; + } + return NULL; } // Queue a new key down/up event. // - ImGuiKey key: Translated key (as in, generally ImGuiKey_A matches the key end-user would use to emit an 'A' character) // - bool down: Is the key down? use false to signify a key release. // - float analog_value: 0.0f..1.0f +// IMPORTANT: THIS FUNCTION AND OTHER "ADD" GRABS THE CONTEXT FROM OUR INSTANCE. +// WE NEED TO ENSURE THAT ALL FUNCTION CALLS ARE FULLFILLING THIS, WHICH IS WHY GetKeyData() HAS AN EXPLICIT CONTEXT. void ImGuiIO::AddKeyAnalogEvent(ImGuiKey key, bool down, float analog_value) { - //if (e->Down) { IMGUI_DEBUG_LOG("AddKeyEvent() Key='%s' %d, NativeKeycode = %d, NativeScancode = %d\n", ImGui::GetKeyName(e->Key), e->Down, e->NativeKeycode, e->NativeScancode); } - if (key == ImGuiKey_None) + //if (e->Down) { IMGUI_DEBUG_LOG_IO("AddKeyEvent() Key='%s' %d, NativeKeycode = %d, NativeScancode = %d\n", ImGui::GetKeyName(e->Key), e->Down, e->NativeKeycode, e->NativeScancode); } + IM_ASSERT(Ctx != NULL); + if (key == ImGuiKey_None || !AppAcceptingEvents) return; - ImGuiContext& g = *GImGui; - IM_ASSERT(&g.IO == this && "Can only add events to current context."); - IM_ASSERT(ImGui::IsNamedKey(key)); // Backend needs to pass a valid ImGuiKey_ constant. 0..511 values are legacy native key codes which are not accepted by this API. + ImGuiContext& g = *Ctx; + IM_ASSERT(ImGui::IsNamedKeyOrModKey(key)); // Backend needs to pass a valid ImGuiKey_ constant. 0..511 values are legacy native key codes which are not accepted by this API. + IM_ASSERT(ImGui::IsAliasKey(key) == false); // Backend cannot submit ImGuiKey_MouseXXX values they are automatically inferred from AddMouseXXX() events. + IM_ASSERT(key != ImGuiMod_Shortcut); // We could easily support the translation here but it seems saner to not accept it (TestEngine perform a translation itself) // Verify that backend isn't mixing up using new io.AddKeyEvent() api and old io.KeysDown[] + io.KeyMap[] data. #ifndef IMGUI_DISABLE_OBSOLETE_KEYIO @@ -1326,22 +1443,19 @@ void ImGuiIO::AddKeyAnalogEvent(ImGuiKey key, bool down, float analog_value) if (ImGui::IsGamepadKey(key)) BackendUsingLegacyNavInputArray = false; - // Partial filter of duplicates (not strictly needed, but makes data neater in particular for key mods and gamepad values which are most commonly spmamed) - ImGuiKeyData* key_data = ImGui::GetKeyData(key); - if (key_data->Down == down && key_data->AnalogValue == analog_value) - { - bool found = false; - for (int n = g.InputEventsQueue.Size - 1; n >= 0 && !found; n--) - if (g.InputEventsQueue[n].Type == ImGuiInputEventType_Key && g.InputEventsQueue[n].Key.Key == key) - found = true; - if (!found) - return; - } + // Filter duplicate (in particular: key mods and gamepad analog values are commonly spammed) + const ImGuiInputEvent* latest_event = FindLatestInputEvent(&g, ImGuiInputEventType_Key, (int)key); + const ImGuiKeyData* key_data = ImGui::GetKeyData(&g, key); + const bool latest_key_down = latest_event ? latest_event->Key.Down : key_data->Down; + const float latest_key_analog = latest_event ? latest_event->Key.AnalogValue : key_data->AnalogValue; + if (latest_key_down == down && latest_key_analog == analog_value) + return; // Add event ImGuiInputEvent e; e.Type = ImGuiInputEventType_Key; e.Source = ImGui::IsGamepadKey(key) ? ImGuiInputSource_Gamepad : ImGuiInputSource_Keyboard; + e.EventId = g.InputEventsNextEventId++; e.Key.Key = key; e.Key.Down = down; e.Key.AnalogValue = analog_value; @@ -1350,6 +1464,8 @@ void ImGuiIO::AddKeyAnalogEvent(ImGuiKey key, bool down, float analog_value) void ImGuiIO::AddKeyEvent(ImGuiKey key, bool down) { + if (!AppAcceptingEvents) + return; AddKeyAnalogEvent(key, down, down ? 1.0f : 0.0f); } @@ -1361,14 +1477,14 @@ void ImGuiIO::SetKeyEventNativeData(ImGuiKey key, int native_keycode, int native if (key == ImGuiKey_None) return; IM_ASSERT(ImGui::IsNamedKey(key)); // >= 512 - IM_ASSERT(native_legacy_index == -1 || ImGui::IsLegacyKey(native_legacy_index)); // >= 0 && <= 511 + IM_ASSERT(native_legacy_index == -1 || ImGui::IsLegacyKey((ImGuiKey)native_legacy_index)); // >= 0 && <= 511 IM_UNUSED(native_keycode); // Yet unused IM_UNUSED(native_scancode); // Yet unused // Build native->imgui map so old user code can still call key functions with native 0..511 values. #ifndef IMGUI_DISABLE_OBSOLETE_KEYIO const int legacy_key = (native_legacy_index != -1) ? native_legacy_index : native_keycode; - if (!ImGui::IsLegacyKey(legacy_key)) + if (!ImGui::IsLegacyKey((ImGuiKey)legacy_key)) return; KeyMap[legacy_key] = key; KeyMap[key] = legacy_key; @@ -1378,55 +1494,105 @@ void ImGuiIO::SetKeyEventNativeData(ImGuiKey key, int native_keycode, int native #endif } +// Set master flag for accepting key/mouse/text events (default to true). Useful if you have native dialog boxes that are interrupting your application loop/refresh, and you want to disable events being queued while your app is frozen. +void ImGuiIO::SetAppAcceptingEvents(bool accepting_events) +{ + AppAcceptingEvents = accepting_events; +} + // Queue a mouse move event void ImGuiIO::AddMousePosEvent(float x, float y) { - ImGuiContext& g = *GImGui; - IM_ASSERT(&g.IO == this && "Can only add events to current context."); + IM_ASSERT(Ctx != NULL); + ImGuiContext& g = *Ctx; + if (!AppAcceptingEvents) + return; + + // Apply same flooring as UpdateMouseInputs() + ImVec2 pos((x > -FLT_MAX) ? ImFloorSigned(x) : x, (y > -FLT_MAX) ? ImFloorSigned(y) : y); + + // Filter duplicate + const ImGuiInputEvent* latest_event = FindLatestInputEvent(&g, ImGuiInputEventType_MousePos); + const ImVec2 latest_pos = latest_event ? ImVec2(latest_event->MousePos.PosX, latest_event->MousePos.PosY) : g.IO.MousePos; + if (latest_pos.x == pos.x && latest_pos.y == pos.y) + return; ImGuiInputEvent e; e.Type = ImGuiInputEventType_MousePos; e.Source = ImGuiInputSource_Mouse; - e.MousePos.PosX = x; - e.MousePos.PosY = y; + e.EventId = g.InputEventsNextEventId++; + e.MousePos.PosX = pos.x; + e.MousePos.PosY = pos.y; + e.MouseWheel.MouseSource = g.InputEventsNextMouseSource; g.InputEventsQueue.push_back(e); } void ImGuiIO::AddMouseButtonEvent(int mouse_button, bool down) { - ImGuiContext& g = *GImGui; - IM_ASSERT(&g.IO == this && "Can only add events to current context."); + IM_ASSERT(Ctx != NULL); + ImGuiContext& g = *Ctx; IM_ASSERT(mouse_button >= 0 && mouse_button < ImGuiMouseButton_COUNT); + if (!AppAcceptingEvents) + return; + + // Filter duplicate + const ImGuiInputEvent* latest_event = FindLatestInputEvent(&g, ImGuiInputEventType_MouseButton, (int)mouse_button); + const bool latest_button_down = latest_event ? latest_event->MouseButton.Down : g.IO.MouseDown[mouse_button]; + if (latest_button_down == down) + return; ImGuiInputEvent e; e.Type = ImGuiInputEventType_MouseButton; e.Source = ImGuiInputSource_Mouse; + e.EventId = g.InputEventsNextEventId++; e.MouseButton.Button = mouse_button; e.MouseButton.Down = down; + e.MouseWheel.MouseSource = g.InputEventsNextMouseSource; g.InputEventsQueue.push_back(e); } -// Queue a mouse wheel event (most mouse/API will only have a Y component) +// Queue a mouse wheel event (some mouse/API may only have a Y component) void ImGuiIO::AddMouseWheelEvent(float wheel_x, float wheel_y) { - ImGuiContext& g = *GImGui; - IM_ASSERT(&g.IO == this && "Can only add events to current context."); - if (wheel_x == 0.0f && wheel_y == 0.0f) + IM_ASSERT(Ctx != NULL); + ImGuiContext& g = *Ctx; + + // Filter duplicate (unlike most events, wheel values are relative and easy to filter) + if (!AppAcceptingEvents || (wheel_x == 0.0f && wheel_y == 0.0f)) return; ImGuiInputEvent e; e.Type = ImGuiInputEventType_MouseWheel; e.Source = ImGuiInputSource_Mouse; + e.EventId = g.InputEventsNextEventId++; e.MouseWheel.WheelX = wheel_x; e.MouseWheel.WheelY = wheel_y; + e.MouseWheel.MouseSource = g.InputEventsNextMouseSource; g.InputEventsQueue.push_back(e); } +// This is not a real event, the data is latched in order to be stored in actual Mouse events. +// This is so that duplicate events (e.g. Windows sending extraneous WM_MOUSEMOVE) gets filtered and are not leading to actual source changes. +void ImGuiIO::AddMouseSourceEvent(ImGuiMouseSource source) +{ + IM_ASSERT(Ctx != NULL); + ImGuiContext& g = *Ctx; + g.InputEventsNextMouseSource = source; +} + void ImGuiIO::AddMouseViewportEvent(ImGuiID viewport_id) { - ImGuiContext& g = *GImGui; - IM_ASSERT(&g.IO == this && "Can only add events to current context."); - IM_ASSERT(g.IO.BackendFlags & ImGuiBackendFlags_HasMouseHoveredViewport); + IM_ASSERT(Ctx != NULL); + ImGuiContext& g = *Ctx; + //IM_ASSERT(g.IO.BackendFlags & ImGuiBackendFlags_HasMouseHoveredViewport); + if (!AppAcceptingEvents) + return; + + // Filter duplicate + const ImGuiInputEvent* latest_event = FindLatestInputEvent(&g, ImGuiInputEventType_MouseViewport); + const ImGuiID latest_viewport_id = latest_event ? latest_event->MouseViewport.HoveredViewportID : g.IO.MouseHoveredViewport; + if (latest_viewport_id == viewport_id) + return; ImGuiInputEvent e; e.Type = ImGuiInputEventType_MouseViewport; @@ -1437,11 +1603,18 @@ void ImGuiIO::AddMouseViewportEvent(ImGuiID viewport_id) void ImGuiIO::AddFocusEvent(bool focused) { - ImGuiContext& g = *GImGui; - IM_ASSERT(&g.IO == this && "Can only add events to current context."); + IM_ASSERT(Ctx != NULL); + ImGuiContext& g = *Ctx; + + // Filter duplicate + const ImGuiInputEvent* latest_event = FindLatestInputEvent(&g, ImGuiInputEventType_Focus); + const bool latest_focused = latest_event ? latest_event->AppFocused.Focused : !g.IO.AppFocusLost; + if (latest_focused == focused || (ConfigDebugIgnoreFocusLoss && !focused)) + return; ImGuiInputEvent e; e.Type = ImGuiInputEventType_Focus; + e.EventId = g.InputEventsNextEventId++; e.AppFocused.Focused = focused; g.InputEventsQueue.push_back(e); } @@ -1574,14 +1747,14 @@ ImVec2 ImTriangleClosestPoint(const ImVec2& a, const ImVec2& b, const ImVec2& c, int ImStricmp(const char* str1, const char* str2) { int d; - while ((d = toupper(*str2) - toupper(*str1)) == 0 && *str1) { str1++; str2++; } + while ((d = ImToUpper(*str2) - ImToUpper(*str1)) == 0 && *str1) { str1++; str2++; } return d; } int ImStrnicmp(const char* str1, const char* str2, size_t count) { int d = 0; - while (count > 0 && (d = toupper(*str2) - toupper(*str1)) == 0 && *str1) { str1++; str2++; count--; } + while (count > 0 && (d = ImToUpper(*str2) - ImToUpper(*str1)) == 0 && *str1) { str1++; str2++; count--; } return d; } @@ -1648,14 +1821,14 @@ const char* ImStristr(const char* haystack, const char* haystack_end, const char if (!needle_end) needle_end = needle + strlen(needle); - const char un0 = (char)toupper(*needle); + const char un0 = (char)ImToUpper(*needle); while ((!haystack_end && *haystack) || (haystack_end && haystack < haystack_end)) { - if (toupper(*haystack) == un0) + if (ImToUpper(*haystack) == un0) { const char* b = needle + 1; for (const char* a = haystack + 1; b < needle_end; a++, b++) - if (toupper(*a) != toupper(*b)) + if (ImToUpper(*a) != ImToUpper(*b)) break; if (b == needle_end) return haystack; @@ -1744,6 +1917,43 @@ int ImFormatStringV(char* buf, size_t buf_size, const char* fmt, va_list args) } #endif // #ifdef IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS +void ImFormatStringToTempBuffer(const char** out_buf, const char** out_buf_end, const char* fmt, ...) +{ + ImGuiContext& g = *GImGui; + va_list args; + va_start(args, fmt); + if (fmt[0] == '%' && fmt[1] == 's' && fmt[2] == 0) + { + const char* buf = va_arg(args, const char*); // Skip formatting when using "%s" + *out_buf = buf; + if (out_buf_end) { *out_buf_end = buf + strlen(buf); } + } + else + { + int buf_len = ImFormatStringV(g.TempBuffer.Data, g.TempBuffer.Size, fmt, args); + *out_buf = g.TempBuffer.Data; + if (out_buf_end) { *out_buf_end = g.TempBuffer.Data + buf_len; } + } + va_end(args); +} + +void ImFormatStringToTempBufferV(const char** out_buf, const char** out_buf_end, const char* fmt, va_list args) +{ + ImGuiContext& g = *GImGui; + if (fmt[0] == '%' && fmt[1] == 's' && fmt[2] == 0) + { + const char* buf = va_arg(args, const char*); // Skip formatting when using "%s" + *out_buf = buf; + if (out_buf_end) { *out_buf_end = buf + strlen(buf); } + } + else + { + int buf_len = ImFormatStringV(g.TempBuffer.Data, g.TempBuffer.Size, fmt, args); + *out_buf = g.TempBuffer.Data; + if (out_buf_end) { *out_buf_end = g.TempBuffer.Data + buf_len; } + } +} + // CRC32 needs a 1KB lookup table (not cache friendly) // Although the code to generate the table is simple and shorter than the table itself, using a const table allows us to easily: // - avoid an unnecessary branch/memory tap, - keep the ImHashXXX functions usable by static constructors, - make it thread-safe. @@ -1770,7 +1980,7 @@ static const ImU32 GCrc32LookupTable[256] = // Known size hash // It is ok to call ImHashData on a string with known length but the ### operator won't be supported. // FIXME-OPT: Replace with e.g. FNV1a hash? CRC32 pretty much randomly access 1KB. Need to do proper measurements. -ImGuiID ImHashData(const void* data_p, size_t data_size, ImU32 seed) +ImGuiID ImHashData(const void* data_p, size_t data_size, ImGuiID seed) { ImU32 crc = ~seed; const unsigned char* data = (const unsigned char*)data_p; @@ -1786,7 +1996,7 @@ ImGuiID ImHashData(const void* data_p, size_t data_size, ImU32 seed) // - If we reach ### in the string we discard the hash so far and reset to the seed. // - We don't do 'current += 2; continue;' after handling ### to keep the code smaller/faster (measured ~10% diff in Debug build) // FIXME-OPT: Replace with e.g. FNV1a hash? CRC32 pretty much randomly access 1KB. Need to do proper measurements. -ImGuiID ImHashStr(const char* data_p, size_t data_size, ImU32 seed) +ImGuiID ImHashStr(const char* data_p, size_t data_size, ImGuiID seed) { seed = ~seed; ImU32 crc = seed; @@ -1828,7 +2038,7 @@ ImFileHandle ImFileOpen(const char* filename, const char* mode) // Previously we used ImTextCountCharsFromUtf8/ImTextStrFromUtf8 here but we now need to support ImWchar16 and ImWchar32! const int filename_wsize = ::MultiByteToWideChar(CP_UTF8, 0, filename, -1, NULL, 0); const int mode_wsize = ::MultiByteToWideChar(CP_UTF8, 0, mode, -1, NULL, 0); - ImVector buf; + ImVector buf; buf.resize(filename_wsize + mode_wsize); ::MultiByteToWideChar(CP_UTF8, 0, filename, -1, (wchar_t*)&buf[0], filename_wsize); ::MultiByteToWideChar(CP_UTF8, 0, mode, -1, (wchar_t*)&buf[filename_wsize], mode_wsize); @@ -1891,6 +2101,8 @@ void* ImFileLoadToMemory(const char* filename, const char* mode, size_t* out_f // [SECTION] MISC HELPERS/UTILITIES (ImText* functions) //----------------------------------------------------------------------------- +IM_MSVC_RUNTIME_CHECKS_OFF + // Convert UTF-8 to 32-bit character, process single character input. // A nearly-branchless UTF-8 decoder, based on work of Christopher Wellons (https://github.com/skeeto/branchless-utf8). // We handle UTF-8 decoding error by skipping forward. @@ -1902,7 +2114,7 @@ int ImTextCharFromUtf8(unsigned int* out_char, const char* in_text, const char* static const int shiftc[] = { 0, 18, 12, 6, 0 }; static const int shifte[] = { 0, 6, 4, 2, 0 }; int len = lengths[*(const unsigned char*)in_text >> 3]; - int wanted = len + !len; + int wanted = len + (len ? 0 : 1); if (in_text_end == NULL) in_text_end = in_text + wanted; // Max length, nulls will be taken into account. @@ -1954,8 +2166,6 @@ int ImTextStrFromUtf8(ImWchar* buf, int buf_size, const char* in_text, const cha { unsigned int c; in_text += ImTextCharFromUtf8(&c, in_text, in_text_end); - if (c == 0) - break; *buf_out++ = (ImWchar)c; } *buf_out = 0; @@ -1971,8 +2181,6 @@ int ImTextCountCharsFromUtf8(const char* in_text, const char* in_text_end) { unsigned int c; in_text += ImTextCharFromUtf8(&c, in_text, in_text_end); - if (c == 0) - break; char_count++; } return char_count; @@ -2066,6 +2274,7 @@ int ImTextCountUtf8BytesFromStr(const ImWchar* in_text, const ImWchar* in_text_e } return bytes_count; } +IM_MSVC_RUNTIME_CHECKS_RESTORE //----------------------------------------------------------------------------- // [SECTION] MISC HELPERS/UTILITIES (Color functions) @@ -2400,7 +2609,7 @@ bool ImGuiTextFilter::PassFilter(const char* text, const char* text_end) const } //----------------------------------------------------------------------------- -// [SECTION] ImGuiTextBuffer +// [SECTION] ImGuiTextBuffer, ImGuiTextIndex //----------------------------------------------------------------------------- // On some platform vsnprintf() takes va_list by reference and modifies it. @@ -2468,6 +2677,20 @@ void ImGuiTextBuffer::appendfv(const char* fmt, va_list args) va_end(args_copy); } +void ImGuiTextIndex::append(const char* base, int old_size, int new_size) +{ + IM_ASSERT(old_size >= 0 && new_size >= old_size && new_size >= EndOffset); + if (old_size == new_size) + return; + if (EndOffset == 0 || base[EndOffset - 1] == '\n') + LineOffsets.push_back(EndOffset); + const char* base_end = base + new_size; + for (const char* p = base + old_size; (p = (const char*)memchr(p, '\n', base_end - p)) != 0; ) + if (++p < base_end) // Don't push a trailing offset on last \n + LineOffsets.push_back((int)(intptr_t)(p - base)); + EndOffset = ImMax(EndOffset, new_size); +} + //----------------------------------------------------------------------------- // [SECTION] ImGuiListClipper // This is currently not as flexible/powerful as it should be and really confusing/spaghetti, mostly because we changed @@ -2484,7 +2707,7 @@ static bool GetSkipItemForListClipping() #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS // Legacy helper to calculate coarse clipping of large list of evenly sized items. -// This legacy API is not ideal because it assume we will return a single contiguous rectangle. +// This legacy API is not ideal because it assumes we will return a single contiguous rectangle. // Prefer using ImGuiListClipper which can returns non-contiguous ranges. void ImGui::CalcListClipping(int items_count, float items_height, int* out_items_display_start, int* out_items_display_end) { @@ -2591,6 +2814,8 @@ static void ImGuiListClipper_SeekCursorForItem(ImGuiListClipper* clipper, int it ImGuiListClipper::ImGuiListClipper() { memset(this, 0, sizeof(*this)); + Ctx = ImGui::GetCurrentContext(); + IM_ASSERT(Ctx != NULL); ItemsCount = -1; } @@ -2599,13 +2824,11 @@ ImGuiListClipper::~ImGuiListClipper() End(); } -// Use case A: Begin() called from constructor with items_height<0, then called again from Step() in StepNo 1 -// Use case B: Begin() called from constructor with items_height>0 -// FIXME-LEGACY: Ideally we should remove the Begin/End functions but they are part of the legacy API we still support. This is why some of the code in Step() calling Begin() and reassign some fields, spaghetti style. void ImGuiListClipper::Begin(int items_count, float items_height) { - ImGuiContext& g = *GImGui; + ImGuiContext& g = *Ctx; ImGuiWindow* window = g.CurrentWindow; + IMGUI_DEBUG_LOG_CLIPPER("Clipper: Begin(%d,%.2f) in '%s'\n", items_count, items_height, window->Name); if (ImGuiTable* table = g.CurrentTable) if (table->IsInsideRow) @@ -2628,10 +2851,11 @@ void ImGuiListClipper::Begin(int items_count, float items_height) void ImGuiListClipper::End() { - ImGuiContext& g = *GImGui; + ImGuiContext& g = *Ctx; if (ImGuiListClipperData* data = (ImGuiListClipperData*)TempData) { // In theory here we should assert that we are already at the right position, but it seems saner to just seek at the end and not assert/crash the user. + IMGUI_DEBUG_LOG_CLIPPER("Clipper: End() in '%s'\n", g.CurrentWindow->Name); if (ItemsCount >= 0 && ItemsCount < INT_MAX && DisplayStart >= 0) ImGuiListClipper_SeekCursorForItem(this, ItemsCount); @@ -2648,20 +2872,20 @@ void ImGuiListClipper::End() ItemsCount = -1; } -void ImGuiListClipper::ForceDisplayRangeByIndices(int item_min, int item_max) +void ImGuiListClipper::IncludeRangeByIndices(int item_begin, int item_end) { ImGuiListClipperData* data = (ImGuiListClipperData*)TempData; IM_ASSERT(DisplayStart < 0); // Only allowed after Begin() and if there has not been a specified range yet. - IM_ASSERT(item_min <= item_max); - if (item_min < item_max) - data->Ranges.push_back(ImGuiListClipperRange::FromIndices(item_min, item_max)); + IM_ASSERT(item_begin <= item_end); + if (item_begin < item_end) + data->Ranges.push_back(ImGuiListClipperRange::FromIndices(item_begin, item_end)); } -bool ImGuiListClipper::Step() +static bool ImGuiListClipper_StepInternal(ImGuiListClipper* clipper) { - ImGuiContext& g = *GImGui; + ImGuiContext& g = *clipper->Ctx; ImGuiWindow* window = g.CurrentWindow; - ImGuiListClipperData* data = (ImGuiListClipperData*)TempData; + ImGuiListClipperData* data = (ImGuiListClipperData*)clipper->TempData; IM_ASSERT(data != NULL && "Called ImGuiListClipper::Step() too many times, or before ImGuiListClipper::Begin() ?"); ImGuiTable* table = g.CurrentTable; @@ -2669,18 +2893,17 @@ bool ImGuiListClipper::Step() ImGui::TableEndRow(table); // No items - if (ItemsCount == 0 || GetSkipItemForListClipping()) - return (void)End(), false; + if (clipper->ItemsCount == 0 || GetSkipItemForListClipping()) + return false; // While we are in frozen row state, keep displaying items one by one, unclipped // FIXME: Could be stored as a table-agnostic state. if (data->StepNo == 0 && table != NULL && !table->IsUnfrozenRows) { - DisplayStart = data->ItemsFrozen; - DisplayEnd = data->ItemsFrozen + 1; - if (DisplayStart >= ItemsCount) - return (void)End(), false; - data->ItemsFrozen++; + clipper->DisplayStart = data->ItemsFrozen; + clipper->DisplayEnd = ImMin(data->ItemsFrozen + 1, clipper->ItemsCount); + if (clipper->DisplayStart < clipper->DisplayEnd) + data->ItemsFrozen++; return true; } @@ -2688,15 +2911,13 @@ bool ImGuiListClipper::Step() bool calc_clipping = false; if (data->StepNo == 0) { - StartPosY = window->DC.CursorPos.y; - if (ItemsHeight <= 0.0f) + clipper->StartPosY = window->DC.CursorPos.y; + if (clipper->ItemsHeight <= 0.0f) { // Submit the first item (or range) so we can measure its height (generally the first range is 0..1) data->Ranges.push_front(ImGuiListClipperRange::FromIndices(data->ItemsFrozen, data->ItemsFrozen + 1)); - DisplayStart = ImMax(data->Ranges[0].Min, data->ItemsFrozen); - DisplayEnd = ImMin(data->Ranges[0].Max, ItemsCount); - if (DisplayStart == DisplayEnd) - return (void)End(), false; + clipper->DisplayStart = ImMax(data->Ranges[0].Min, data->ItemsFrozen); + clipper->DisplayEnd = ImMin(data->Ranges[0].Max, clipper->ItemsCount); data->StepNo = 1; return true; } @@ -2704,29 +2925,29 @@ bool ImGuiListClipper::Step() } // Step 1: Let the clipper infer height from first range - if (ItemsHeight <= 0.0f) + if (clipper->ItemsHeight <= 0.0f) { IM_ASSERT(data->StepNo == 1); if (table) - IM_ASSERT(table->RowPosY1 == StartPosY && table->RowPosY2 == window->DC.CursorPos.y); + IM_ASSERT(table->RowPosY1 == clipper->StartPosY && table->RowPosY2 == window->DC.CursorPos.y); - ItemsHeight = (window->DC.CursorPos.y - StartPosY) / (float)(DisplayEnd - DisplayStart); - bool affected_by_floating_point_precision = ImIsFloatAboveGuaranteedIntegerPrecision(StartPosY) || ImIsFloatAboveGuaranteedIntegerPrecision(window->DC.CursorPos.y); + clipper->ItemsHeight = (window->DC.CursorPos.y - clipper->StartPosY) / (float)(clipper->DisplayEnd - clipper->DisplayStart); + bool affected_by_floating_point_precision = ImIsFloatAboveGuaranteedIntegerPrecision(clipper->StartPosY) || ImIsFloatAboveGuaranteedIntegerPrecision(window->DC.CursorPos.y); if (affected_by_floating_point_precision) - ItemsHeight = window->DC.PrevLineSize.y + g.Style.ItemSpacing.y; // FIXME: Technically wouldn't allow multi-line entries. + clipper->ItemsHeight = window->DC.PrevLineSize.y + g.Style.ItemSpacing.y; // FIXME: Technically wouldn't allow multi-line entries. - IM_ASSERT(ItemsHeight > 0.0f && "Unable to calculate item height! First item hasn't moved the cursor vertically!"); + IM_ASSERT(clipper->ItemsHeight > 0.0f && "Unable to calculate item height! First item hasn't moved the cursor vertically!"); calc_clipping = true; // If item height had to be calculated, calculate clipping afterwards. } // Step 0 or 1: Calculate the actual ranges of visible elements. - const int already_submitted = DisplayEnd; + const int already_submitted = clipper->DisplayEnd; if (calc_clipping) { if (g.LogEnabled) { // If logging is active, do not perform any clipping - data->Ranges.push_back(ImGuiListClipperRange::FromIndices(0, ItemsCount)); + data->Ranges.push_back(ImGuiListClipperRange::FromIndices(0, clipper->ItemsCount)); } else { @@ -2735,7 +2956,7 @@ bool ImGuiListClipper::Step() if (is_nav_request) data->Ranges.push_back(ImGuiListClipperRange::FromPositions(g.NavScoringNoClipRect.Min.y, g.NavScoringNoClipRect.Max.y, 0, 0)); if (is_nav_request && (g.NavMoveFlags & ImGuiNavMoveFlags_Tabbing) && g.NavTabbingDir == -1) - data->Ranges.push_back(ImGuiListClipperRange::FromIndices(ItemsCount - 1, ItemsCount)); + data->Ranges.push_back(ImGuiListClipperRange::FromIndices(clipper->ItemsCount - 1, clipper->ItemsCount)); // Add focused/active item ImRect nav_rect_abs = ImGui::WindowRectRelToAbs(window, window->NavRectRel[0]); @@ -2755,10 +2976,10 @@ bool ImGuiListClipper::Step() for (int i = 0; i < data->Ranges.Size; i++) if (data->Ranges[i].PosToIndexConvert) { - int m1 = (int)(((double)data->Ranges[i].Min - window->DC.CursorPos.y - data->LossynessOffset) / ItemsHeight); - int m2 = (int)((((double)data->Ranges[i].Max - window->DC.CursorPos.y - data->LossynessOffset) / ItemsHeight) + 0.999999f); - data->Ranges[i].Min = ImClamp(already_submitted + m1 + data->Ranges[i].PosToIndexOffsetMin, already_submitted, ItemsCount - 1); - data->Ranges[i].Max = ImClamp(already_submitted + m2 + data->Ranges[i].PosToIndexOffsetMax, data->Ranges[i].Min + 1, ItemsCount); + int m1 = (int)(((double)data->Ranges[i].Min - window->DC.CursorPos.y - data->LossynessOffset) / clipper->ItemsHeight); + int m2 = (int)((((double)data->Ranges[i].Max - window->DC.CursorPos.y - data->LossynessOffset) / clipper->ItemsHeight) + 0.999999f); + data->Ranges[i].Min = ImClamp(already_submitted + m1 + data->Ranges[i].PosToIndexOffsetMin, already_submitted, clipper->ItemsCount - 1); + data->Ranges[i].Max = ImClamp(already_submitted + m2 + data->Ranges[i].PosToIndexOffsetMax, data->Ranges[i].Min + 1, clipper->ItemsCount); data->Ranges[i].PosToIndexConvert = false; } ImGuiListClipper_SortAndFuseRanges(data->Ranges, data->StepNo); @@ -2767,23 +2988,45 @@ bool ImGuiListClipper::Step() // Step 0+ (if item height is given in advance) or 1+: Display the next range in line. if (data->StepNo < data->Ranges.Size) { - DisplayStart = ImMax(data->Ranges[data->StepNo].Min, already_submitted); - DisplayEnd = ImMin(data->Ranges[data->StepNo].Max, ItemsCount); - if (DisplayStart > already_submitted) //-V1051 - ImGuiListClipper_SeekCursorForItem(this, DisplayStart); + clipper->DisplayStart = ImMax(data->Ranges[data->StepNo].Min, already_submitted); + clipper->DisplayEnd = ImMin(data->Ranges[data->StepNo].Max, clipper->ItemsCount); + if (clipper->DisplayStart > already_submitted) //-V1051 + ImGuiListClipper_SeekCursorForItem(clipper, clipper->DisplayStart); data->StepNo++; return true; } // After the last step: Let the clipper validate that we have reached the expected Y position (corresponding to element DisplayEnd), // Advance the cursor to the end of the list and then returns 'false' to end the loop. - if (ItemsCount < INT_MAX) - ImGuiListClipper_SeekCursorForItem(this, ItemsCount); + if (clipper->ItemsCount < INT_MAX) + ImGuiListClipper_SeekCursorForItem(clipper, clipper->ItemsCount); - End(); return false; } +bool ImGuiListClipper::Step() +{ + ImGuiContext& g = *Ctx; + bool need_items_height = (ItemsHeight <= 0.0f); + bool ret = ImGuiListClipper_StepInternal(this); + if (ret && (DisplayStart == DisplayEnd)) + ret = false; + if (g.CurrentTable && g.CurrentTable->IsUnfrozenRows == false) + IMGUI_DEBUG_LOG_CLIPPER("Clipper: Step(): inside frozen table row.\n"); + if (need_items_height && ItemsHeight > 0.0f) + IMGUI_DEBUG_LOG_CLIPPER("Clipper: Step(): computed ItemsHeight: %.2f.\n", ItemsHeight); + if (ret) + { + IMGUI_DEBUG_LOG_CLIPPER("Clipper: Step(): display %d to %d.\n", DisplayStart, DisplayEnd); + } + else + { + IMGUI_DEBUG_LOG_CLIPPER("Clipper: Step(): End.\n"); + End(); + } + return ret; +} + //----------------------------------------------------------------------------- // [SECTION] STYLING //----------------------------------------------------------------------------- @@ -2850,6 +3093,11 @@ void ImGui::PushStyleColor(ImGuiCol idx, const ImVec4& col) void ImGui::PopStyleColor(int count) { ImGuiContext& g = *GImGui; + if (g.ColorStack.Size < count) + { + IM_ASSERT_USER_ERROR(g.ColorStack.Size > count, "Calling PopStyleColor() too many times: stack underflow."); + count = g.ColorStack.Size; + } while (count > 0) { ImGuiColorMod& backup = g.ColorStack.back(); @@ -2859,20 +3107,12 @@ void ImGui::PopStyleColor(int count) } } -struct ImGuiStyleVarInfo -{ - ImGuiDataType Type; - ImU32 Count; - ImU32 Offset; - void* GetVarPtr(ImGuiStyle* style) const { return (void*)((unsigned char*)style + Offset); } -}; - static const ImGuiCol GWindowDockStyleColors[ImGuiWindowDockStyleCol_COUNT] = { ImGuiCol_Text, ImGuiCol_Tab, ImGuiCol_TabHovered, ImGuiCol_TabActive, ImGuiCol_TabUnfocused, ImGuiCol_TabUnfocusedActive }; -static const ImGuiStyleVarInfo GStyleVarInfo[] = +static const ImGuiDataVarInfo GStyleVarInfo[] = { { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, Alpha) }, // ImGuiStyleVar_Alpha { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, DisabledAlpha) }, // ImGuiStyleVar_DisabledAlpha @@ -2900,51 +3140,59 @@ static const ImGuiStyleVarInfo GStyleVarInfo[] = { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, TabRounding) }, // ImGuiStyleVar_TabRounding { ImGuiDataType_Float, 2, (ImU32)IM_OFFSETOF(ImGuiStyle, ButtonTextAlign) }, // ImGuiStyleVar_ButtonTextAlign { ImGuiDataType_Float, 2, (ImU32)IM_OFFSETOF(ImGuiStyle, SelectableTextAlign) }, // ImGuiStyleVar_SelectableTextAlign + { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, SeparatorTextBorderSize) },// ImGuiStyleVar_SeparatorTextBorderSize + { ImGuiDataType_Float, 2, (ImU32)IM_OFFSETOF(ImGuiStyle, SeparatorTextAlign) }, // ImGuiStyleVar_SeparatorTextAlign + { ImGuiDataType_Float, 2, (ImU32)IM_OFFSETOF(ImGuiStyle, SeparatorTextPadding) }, // ImGuiStyleVar_SeparatorTextPadding }; -static const ImGuiStyleVarInfo* GetStyleVarInfo(ImGuiStyleVar idx) +const ImGuiDataVarInfo* ImGui::GetStyleVarInfo(ImGuiStyleVar idx) { IM_ASSERT(idx >= 0 && idx < ImGuiStyleVar_COUNT); - IM_ASSERT(IM_ARRAYSIZE(GStyleVarInfo) == ImGuiStyleVar_COUNT); + IM_STATIC_ASSERT(IM_ARRAYSIZE(GStyleVarInfo) == ImGuiStyleVar_COUNT); return &GStyleVarInfo[idx]; } void ImGui::PushStyleVar(ImGuiStyleVar idx, float val) { - const ImGuiStyleVarInfo* var_info = GetStyleVarInfo(idx); + ImGuiContext& g = *GImGui; + const ImGuiDataVarInfo* var_info = GetStyleVarInfo(idx); if (var_info->Type == ImGuiDataType_Float && var_info->Count == 1) { - ImGuiContext& g = *GImGui; float* pvar = (float*)var_info->GetVarPtr(&g.Style); g.StyleVarStack.push_back(ImGuiStyleMod(idx, *pvar)); *pvar = val; return; } - IM_ASSERT(0 && "Called PushStyleVar() float variant but variable is not a float!"); + IM_ASSERT_USER_ERROR(0, "Called PushStyleVar() variant with wrong type!"); } void ImGui::PushStyleVar(ImGuiStyleVar idx, const ImVec2& val) { - const ImGuiStyleVarInfo* var_info = GetStyleVarInfo(idx); + ImGuiContext& g = *GImGui; + const ImGuiDataVarInfo* var_info = GetStyleVarInfo(idx); if (var_info->Type == ImGuiDataType_Float && var_info->Count == 2) { - ImGuiContext& g = *GImGui; ImVec2* pvar = (ImVec2*)var_info->GetVarPtr(&g.Style); g.StyleVarStack.push_back(ImGuiStyleMod(idx, *pvar)); *pvar = val; return; } - IM_ASSERT(0 && "Called PushStyleVar() ImVec2 variant but variable is not a ImVec2!"); + IM_ASSERT_USER_ERROR(0, "Called PushStyleVar() variant with wrong type!"); } void ImGui::PopStyleVar(int count) { ImGuiContext& g = *GImGui; + if (g.StyleVarStack.Size < count) + { + IM_ASSERT_USER_ERROR(g.StyleVarStack.Size > count, "Calling PopStyleVar() too many times: stack underflow."); + count = g.StyleVarStack.Size; + } while (count > 0) { // We avoid a generic memcpy(data, &backup.Backup.., GDataTypeSize[info->Type] * info->Count), the overhead in Debug is not worth it. ImGuiStyleMod& backup = g.StyleVarStack.back(); - const ImGuiStyleVarInfo* info = GetStyleVarInfo(backup.VarIdx); + const ImGuiDataVarInfo* info = GetStyleVarInfo(backup.VarIdx); void* data = info->GetVarPtr(&g.Style); if (info->Type == ImGuiDataType_Float && info->Count == 1) { ((float*)data)[0] = backup.BackupFloat[0]; } else if (info->Type == ImGuiDataType_Float && info->Count == 2) { ((float*)data)[0] = backup.BackupFloat[0]; ((float*)data)[1] = backup.BackupFloat[1]; } @@ -3083,6 +3331,9 @@ void ImGui::RenderTextWrapped(ImVec2 pos, const char* text, const char* text_end // Default clip_rect uses (pos_min,pos_max) // Handle clipping on CPU immediately (vs typically let the GPU clip the triangles that are overlapping the clipping rectangle edges) +// FIXME-OPT: Since we have or calculate text_size we could coarse clip whole block immediately, especally for text above draw_list->DrawList. +// Effectively as this is called from widget doing their own coarse clipping it's not very valuable presently. Next time function will take +// better advantage of the render function taking size into account for coarse clipping. void ImGui::RenderTextClippedEx(ImDrawList* draw_list, const ImVec2& pos_min, const ImVec2& pos_max, const char* text, const char* text_display_end, const ImVec2* text_size_if_known, const ImVec2& align, const ImRect* clip_rect) { // Perform CPU side clipping for single clipped element to avoid using scissor state @@ -3126,7 +3377,6 @@ void ImGui::RenderTextClipped(const ImVec2& pos_min, const ImVec2& pos_max, cons LogRenderedText(&pos_min, text, text_display_end); } - // Another overly complex function until we reorganize everything into a nice all-in-one helper. // This is made more complex because we have dissociated the layout rectangle (pos_min..pos_max) which define _where_ the ellipsis is, from actual clipping of text and limit of the ellipsis display. // This is because in the context of tabs we selectively hide part of the text when the Close Button appears, but we don't want the ellipsis to move. @@ -3150,30 +3400,12 @@ void ImGui::RenderTextEllipsis(ImDrawList* draw_list, const ImVec2& pos_min, con const ImFont* font = draw_list->_Data->Font; const float font_size = draw_list->_Data->FontSize; + const float font_scale = font_size / font->FontSize; const char* text_end_ellipsis = NULL; - - ImWchar ellipsis_char = font->EllipsisChar; - int ellipsis_char_count = 1; - if (ellipsis_char == (ImWchar)-1) - { - ellipsis_char = font->DotChar; - ellipsis_char_count = 3; - } - const ImFontGlyph* glyph = font->FindGlyph(ellipsis_char); - - float ellipsis_glyph_width = glyph->X1; // Width of the glyph with no padding on either side - float ellipsis_total_width = ellipsis_glyph_width; // Full width of entire ellipsis - - if (ellipsis_char_count > 1) - { - // Full ellipsis size without free spacing after it. - const float spacing_between_dots = 1.0f * (draw_list->_Data->FontSize / font->FontSize); - ellipsis_glyph_width = glyph->X1 - glyph->X0 + spacing_between_dots; - ellipsis_total_width = ellipsis_glyph_width * (float)ellipsis_char_count - spacing_between_dots; - } + const float ellipsis_width = font->EllipsisWidth * font_scale; // We can now claim the space between pos_max.x and ellipsis_max.x - const float text_avail_width = ImMax((ImMax(pos_max.x, ellipsis_max_x) - ellipsis_total_width) - pos_min.x, 1.0f); + const float text_avail_width = ImMax((ImMax(pos_max.x, ellipsis_max_x) - ellipsis_width) - pos_min.x, 1.0f); float text_size_clipped_x = font->CalcTextSizeA(font_size, text_avail_width, 0.0f, text, text_end_full, &text_end_ellipsis).x; if (text == text_end_ellipsis && text_end_ellipsis < text_end_full) { @@ -3190,13 +3422,10 @@ void ImGui::RenderTextEllipsis(ImDrawList* draw_list, const ImVec2& pos_min, con // Render text, render ellipsis RenderTextClippedEx(draw_list, pos_min, ImVec2(clip_max_x, pos_max.y), text, text_end_ellipsis, &text_size, ImVec2(0.0f, 0.0f)); - float ellipsis_x = pos_min.x + text_size_clipped_x; - if (ellipsis_x + ellipsis_total_width <= ellipsis_max_x) - for (int i = 0; i < ellipsis_char_count; i++) - { - font->RenderChar(draw_list, font_size, ImVec2(ellipsis_x, pos_min.y), GetColorU32(ImGuiCol_Text), ellipsis_char); - ellipsis_x += ellipsis_glyph_width; - } + ImVec2 ellipsis_pos = ImFloor(ImVec2(pos_min.x + text_size_clipped_x, pos_min.y)); + if (ellipsis_pos.x + ellipsis_width <= ellipsis_max_x) + for (int i = 0; i < font->EllipsisCharCount; i++, ellipsis_pos.x += font->EllipsisCharStep * font_scale) + font->RenderChar(draw_list, font_size, ellipsis_pos, GetColorU32(ImGuiCol_Text), font->EllipsisChar); } else { @@ -3299,15 +3528,247 @@ void ImGui::RenderMouseCursor(ImVec2 base_pos, float base_scale, ImGuiMouseCurso } } +//----------------------------------------------------------------------------- +// [SECTION] INITIALIZATION, SHUTDOWN +//----------------------------------------------------------------------------- + +// Internal state access - if you want to share Dear ImGui state between modules (e.g. DLL) or allocate it yourself +// Note that we still point to some static data and members (such as GFontAtlas), so the state instance you end up using will point to the static data within its module +ImGuiContext* ImGui::GetCurrentContext() +{ + return GImGui; +} + +void ImGui::SetCurrentContext(ImGuiContext* ctx) +{ +#ifdef IMGUI_SET_CURRENT_CONTEXT_FUNC + IMGUI_SET_CURRENT_CONTEXT_FUNC(ctx); // For custom thread-based hackery you may want to have control over this. +#else + GImGui = ctx; +#endif +} + +void ImGui::SetAllocatorFunctions(ImGuiMemAllocFunc alloc_func, ImGuiMemFreeFunc free_func, void* user_data) +{ + GImAllocatorAllocFunc = alloc_func; + GImAllocatorFreeFunc = free_func; + GImAllocatorUserData = user_data; +} + +// This is provided to facilitate copying allocators from one static/DLL boundary to another (e.g. retrieve default allocator of your executable address space) +void ImGui::GetAllocatorFunctions(ImGuiMemAllocFunc* p_alloc_func, ImGuiMemFreeFunc* p_free_func, void** p_user_data) +{ + *p_alloc_func = GImAllocatorAllocFunc; + *p_free_func = GImAllocatorFreeFunc; + *p_user_data = GImAllocatorUserData; +} + +ImGuiContext* ImGui::CreateContext(ImFontAtlas* shared_font_atlas) +{ + ImGuiContext* prev_ctx = GetCurrentContext(); + ImGuiContext* ctx = IM_NEW(ImGuiContext)(shared_font_atlas); + SetCurrentContext(ctx); + Initialize(); + if (prev_ctx != NULL) + SetCurrentContext(prev_ctx); // Restore previous context if any, else keep new one. + return ctx; +} + +void ImGui::DestroyContext(ImGuiContext* ctx) +{ + ImGuiContext* prev_ctx = GetCurrentContext(); + if (ctx == NULL) //-V1051 + ctx = prev_ctx; + SetCurrentContext(ctx); + Shutdown(); + SetCurrentContext((prev_ctx != ctx) ? prev_ctx : NULL); + IM_DELETE(ctx); +} + +// IMPORTANT: ###xxx suffixes must be same in ALL languages +static const ImGuiLocEntry GLocalizationEntriesEnUS[] = +{ + { ImGuiLocKey_TableSizeOne, "Size column to fit###SizeOne" }, + { ImGuiLocKey_TableSizeAllFit, "Size all columns to fit###SizeAll" }, + { ImGuiLocKey_TableSizeAllDefault, "Size all columns to default###SizeAll" }, + { ImGuiLocKey_TableResetOrder, "Reset order###ResetOrder" }, + { ImGuiLocKey_WindowingMainMenuBar, "(Main menu bar)" }, + { ImGuiLocKey_WindowingPopup, "(Popup)" }, + { ImGuiLocKey_WindowingUntitled, "(Untitled)" }, + { ImGuiLocKey_DockingHideTabBar, "Hide tab bar###HideTabBar" }, +}; + +void ImGui::Initialize() +{ + ImGuiContext& g = *GImGui; + IM_ASSERT(!g.Initialized && !g.SettingsLoaded); + + // Add .ini handle for ImGuiWindow and ImGuiTable types + { + ImGuiSettingsHandler ini_handler; + ini_handler.TypeName = "Window"; + ini_handler.TypeHash = ImHashStr("Window"); + ini_handler.ClearAllFn = WindowSettingsHandler_ClearAll; + ini_handler.ReadOpenFn = WindowSettingsHandler_ReadOpen; + ini_handler.ReadLineFn = WindowSettingsHandler_ReadLine; + ini_handler.ApplyAllFn = WindowSettingsHandler_ApplyAll; + ini_handler.WriteAllFn = WindowSettingsHandler_WriteAll; + AddSettingsHandler(&ini_handler); + } + TableSettingsAddSettingsHandler(); + + // Setup default localization table + LocalizeRegisterEntries(GLocalizationEntriesEnUS, IM_ARRAYSIZE(GLocalizationEntriesEnUS)); + + // Setup default platform clipboard/IME handlers. + g.IO.GetClipboardTextFn = GetClipboardTextFn_DefaultImpl; // Platform dependent default implementations + g.IO.SetClipboardTextFn = SetClipboardTextFn_DefaultImpl; + g.IO.ClipboardUserData = (void*)&g; // Default implementation use the ImGuiContext as user data (ideally those would be arguments to the function) + g.IO.SetPlatformImeDataFn = SetPlatformImeDataFn_DefaultImpl; + + // Create default viewport + ImGuiViewportP* viewport = IM_NEW(ImGuiViewportP)(); + viewport->ID = IMGUI_VIEWPORT_DEFAULT_ID; + viewport->Idx = 0; + viewport->PlatformWindowCreated = true; + viewport->Flags = ImGuiViewportFlags_OwnedByApp; + g.Viewports.push_back(viewport); + g.TempBuffer.resize(1024 * 3 + 1, 0); + g.PlatformIO.Viewports.push_back(g.Viewports[0]); + +#ifdef IMGUI_HAS_DOCK + // Initialize Docking + DockContextInitialize(&g); +#endif + + g.Initialized = true; +} + +// This function is merely here to free heap allocations. +void ImGui::Shutdown() +{ + // The fonts atlas can be used prior to calling NewFrame(), so we clear it even if g.Initialized is FALSE (which would happen if we never called NewFrame) + ImGuiContext& g = *GImGui; + if (g.IO.Fonts && g.FontAtlasOwnedByContext) + { + g.IO.Fonts->Locked = false; + IM_DELETE(g.IO.Fonts); + } + g.IO.Fonts = NULL; + g.DrawListSharedData.TempBuffer.clear(); + + // Cleanup of other data are conditional on actually having initialized Dear ImGui. + if (!g.Initialized) + return; + + // Save settings (unless we haven't attempted to load them: CreateContext/DestroyContext without a call to NewFrame shouldn't save an empty file) + if (g.SettingsLoaded && g.IO.IniFilename != NULL) + SaveIniSettingsToDisk(g.IO.IniFilename); + + // Destroy platform windows + DestroyPlatformWindows(); + + // Shutdown extensions + DockContextShutdown(&g); + + CallContextHooks(&g, ImGuiContextHookType_Shutdown); + + // Clear everything else + g.Windows.clear_delete(); + g.WindowsFocusOrder.clear(); + g.WindowsTempSortBuffer.clear(); + g.CurrentWindow = NULL; + g.CurrentWindowStack.clear(); + g.WindowsById.Clear(); + g.NavWindow = NULL; + g.HoveredWindow = g.HoveredWindowUnderMovingWindow = NULL; + g.ActiveIdWindow = g.ActiveIdPreviousFrameWindow = NULL; + g.MovingWindow = NULL; + + g.KeysRoutingTable.Clear(); + + g.ColorStack.clear(); + g.StyleVarStack.clear(); + g.FontStack.clear(); + g.OpenPopupStack.clear(); + g.BeginPopupStack.clear(); + + g.CurrentViewport = g.MouseViewport = g.MouseLastHoveredViewport = NULL; + g.Viewports.clear_delete(); + + g.TabBars.Clear(); + g.CurrentTabBarStack.clear(); + g.ShrinkWidthBuffer.clear(); + + g.ClipperTempData.clear_destruct(); + + g.Tables.Clear(); + g.TablesTempData.clear_destruct(); + g.DrawChannelsTempMergeBuffer.clear(); + + g.ClipboardHandlerData.clear(); + g.MenusIdSubmittedThisFrame.clear(); + g.InputTextState.ClearFreeMemory(); + g.InputTextDeactivatedState.ClearFreeMemory(); + + g.SettingsWindows.clear(); + g.SettingsHandlers.clear(); + + if (g.LogFile) + { +#ifndef IMGUI_DISABLE_TTY_FUNCTIONS + if (g.LogFile != stdout) +#endif + ImFileClose(g.LogFile); + g.LogFile = NULL; + } + g.LogBuffer.clear(); + g.DebugLogBuf.clear(); + g.DebugLogIndex.clear(); + + g.Initialized = false; +} + +// No specific ordering/dependency support, will see as needed +ImGuiID ImGui::AddContextHook(ImGuiContext* ctx, const ImGuiContextHook* hook) +{ + ImGuiContext& g = *ctx; + IM_ASSERT(hook->Callback != NULL && hook->HookId == 0 && hook->Type != ImGuiContextHookType_PendingRemoval_); + g.Hooks.push_back(*hook); + g.Hooks.back().HookId = ++g.HookIdNext; + return g.HookIdNext; +} + +// Deferred removal, avoiding issue with changing vector while iterating it +void ImGui::RemoveContextHook(ImGuiContext* ctx, ImGuiID hook_id) +{ + ImGuiContext& g = *ctx; + IM_ASSERT(hook_id != 0); + for (int n = 0; n < g.Hooks.Size; n++) + if (g.Hooks[n].HookId == hook_id) + g.Hooks[n].Type = ImGuiContextHookType_PendingRemoval_; +} + +// Call context hooks (used by e.g. test engine) +// We assume a small number of hooks so all stored in same array +void ImGui::CallContextHooks(ImGuiContext* ctx, ImGuiContextHookType hook_type) +{ + ImGuiContext& g = *ctx; + for (int n = 0; n < g.Hooks.Size; n++) + if (g.Hooks[n].Type == hook_type) + g.Hooks[n].Callback(&g, &g.Hooks[n]); +} + //----------------------------------------------------------------------------- // [SECTION] MAIN CODE (most of the code! lots of stuff, needs tidying up!) //----------------------------------------------------------------------------- // ImGuiWindow is mostly a dumb struct. It merely has a constructor and a few helper methods -ImGuiWindow::ImGuiWindow(ImGuiContext* context, const char* name) : DrawListInst(NULL) +ImGuiWindow::ImGuiWindow(ImGuiContext* ctx, const char* name) : DrawListInst(NULL) { memset(this, 0, sizeof(*this)); + Ctx = ctx; Name = ImStrdup(name); NameBufLen = (int)strlen(name) + 1; ID = ImHashStr(name); @@ -3321,7 +3782,7 @@ ImGuiWindow::ImGuiWindow(ImGuiContext* context, const char* name) : DrawListInst InertialScrollSpeed = ImVec2(0.0f, 0.0f); AutoFitFramesX = AutoFitFramesY = -1; AutoPosLastDirection = ImGuiDir_None; - SetWindowPosAllowFlags = SetWindowSizeAllowFlags = SetWindowCollapsedAllowFlags = SetWindowDockAllowFlags = ImGuiCond_Always | ImGuiCond_Once | ImGuiCond_FirstUseEver | ImGuiCond_Appearing; + SetWindowPosAllowFlags = SetWindowSizeAllowFlags = SetWindowCollapsedAllowFlags = SetWindowDockAllowFlags = 0; SetWindowPosVal = SetWindowPosPivot = ImVec2(FLT_MAX, FLT_MAX); LastFrameActive = -1; LastFrameJustFocused = -1; @@ -3330,8 +3791,9 @@ ImGuiWindow::ImGuiWindow(ImGuiContext* context, const char* name) : DrawListInst SettingsOffset = -1; DockOrder = -1; DrawList = &DrawListInst; - DrawList->_Data = &context->DrawListSharedData; + DrawList->_Data = &Ctx->DrawListSharedData; DrawList->_OwnerName = Name; + NavPreferredScoringPosRel[0] = NavPreferredScoringPosRel[1] = ImVec2(FLT_MAX, FLT_MAX); IM_PLACEMENT_NEW(&WindowClass) ImGuiWindowClass(); } @@ -3346,7 +3808,7 @@ ImGuiID ImGuiWindow::GetID(const char* str, const char* str_end) { ImGuiID seed = IDStack.back(); ImGuiID id = ImHashStr(str, str_end ? (str_end - str) : 0, seed); - ImGuiContext& g = *GImGui; + ImGuiContext& g = *Ctx; if (g.DebugHookIdInfo == id) ImGui::DebugHookIdInfo(id, ImGuiDataType_String, str, str_end); return id; @@ -3356,7 +3818,7 @@ ImGuiID ImGuiWindow::GetID(const void* ptr) { ImGuiID seed = IDStack.back(); ImGuiID id = ImHashData(&ptr, sizeof(void*), seed); - ImGuiContext& g = *GImGui; + ImGuiContext& g = *Ctx; if (g.DebugHookIdInfo == id) ImGui::DebugHookIdInfo(id, ImGuiDataType_Pointer, ptr, NULL); return id; @@ -3366,7 +3828,7 @@ ImGuiID ImGuiWindow::GetID(int n) { ImGuiID seed = IDStack.back(); ImGuiID id = ImHashData(&n, sizeof(n), seed); - ImGuiContext& g = *GImGui; + ImGuiContext& g = *Ctx; if (g.DebugHookIdInfo == id) ImGui::DebugHookIdInfo(id, ImGuiDataType_S32, (void*)(intptr_t)n, NULL); return id; @@ -3387,7 +3849,10 @@ static void SetCurrentWindow(ImGuiWindow* window) g.CurrentWindow = window; g.CurrentTable = window && window->DC.CurrentTableIdx != -1 ? g.Tables.GetByIndex(window->DC.CurrentTableIdx) : NULL; if (window) + { g.FontSize = g.DrawListSharedData.FontSize = window->CalcFontSize(); + ImGui::NavUpdateCurrentWindowIsScrollPushableX(); + } } void ImGui::GcCompactTransientMiscBuffers() @@ -3427,9 +3892,31 @@ void ImGui::GcAwakeTransientWindowBuffers(ImGuiWindow* window) void ImGui::SetActiveID(ImGuiID id, ImGuiWindow* window) { ImGuiContext& g = *GImGui; + + // Clear previous active id + if (g.ActiveId != 0) + { + // While most behaved code would make an effort to not steal active id during window move/drag operations, + // we at least need to be resilient to it. Canceling the move is rather aggressive and users of 'master' branch + // may prefer the weird ill-defined half working situation ('docking' did assert), so may need to rework that. + if (g.MovingWindow != NULL && g.ActiveId == g.MovingWindow->MoveId) + { + IMGUI_DEBUG_LOG_ACTIVEID("SetActiveID() cancel MovingWindow\n"); + g.MovingWindow = NULL; + } + + // This could be written in a more general way (e.g associate a hook to ActiveId), + // but since this is currently quite an exception we'll leave it as is. + // One common scenario leading to this is: pressing Key ->NavMoveRequestApplyResult() -> ClearActiveId() + if (g.InputTextState.ID == g.ActiveId) + InputTextDeactivateHook(g.ActiveId); + } + + // Set active id g.ActiveIdIsJustActivated = (g.ActiveId != id); if (g.ActiveIdIsJustActivated) { + IMGUI_DEBUG_LOG_ACTIVEID("SetActiveID() old:0x%08X (window \"%s\") -> new:0x%08X (window \"%s\")\n", g.ActiveId, g.ActiveIdWindow ? g.ActiveIdWindow->Name : "", id, window ? window->Name : ""); g.ActiveIdTimer = 0.0f; g.ActiveIdHasBeenPressedBefore = false; g.ActiveIdHasBeenEditedBefore = false; @@ -3448,19 +3935,21 @@ void ImGui::SetActiveID(ImGuiID id, ImGuiWindow* window) if (id) { g.ActiveIdIsAlive = id; - g.ActiveIdSource = (g.NavActivateId == id || g.NavActivateInputId == id || g.NavJustMovedToId == id) ? (ImGuiInputSource)ImGuiInputSource_Nav : ImGuiInputSource_Mouse; + g.ActiveIdSource = (g.NavActivateId == id || g.NavJustMovedToId == id) ? g.NavInputSource : ImGuiInputSource_Mouse; // TODO: check whether this works if (g.LastItemData.InFlags & ImGuiItemFlags_NoInertialScroll) { g.InertialScrollInhibited=true; } + IM_ASSERT(g.ActiveIdSource != ImGuiInputSource_None); } // Clear declaration of inputs claimed by the widget // (Please note that this is WIP and not all keys/inputs are thoroughly declared by all widgets yet) - g.ActiveIdUsingMouseWheel = false; g.ActiveIdUsingNavDirMask = 0x00; + g.ActiveIdUsingAllKeyboardKeys = false; +#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO g.ActiveIdUsingNavInputMask = 0x00; - g.ActiveIdUsingKeyInputMask.ClearAllBits(); +#endif } void ImGui::ClearActiveID() @@ -3473,7 +3962,6 @@ void ImGui::SetHoveredID(ImGuiID id) ImGuiContext& g = *GImGui; g.HoveredId = id; g.HoveredIdAllowOverlap = false; - g.HoveredIdUsingMouseWheel = false; if (id != 0 && g.HoveredIdPreviousFrame != id) g.HoveredIdTimer = g.HoveredIdNotActiveTimer = 0.0f; } @@ -3498,17 +3986,23 @@ void ImGui::KeepAliveID(ImGuiID id) void ImGui::MarkItemEdited(ImGuiID id) { // This marking is solely to be able to provide info for IsItemDeactivatedAfterEdit(). - // ActiveId might have been released by the time we call this (as in the typical press/release button behavior) but still need need to fill the data. + // ActiveId might have been released by the time we call this (as in the typical press/release button behavior) but still need to fill the data. ImGuiContext& g = *GImGui; - IM_ASSERT(g.ActiveId == id || g.ActiveId == 0 || g.DragDropActive); - IM_UNUSED(id); // Avoid unused variable warnings when asserts are compiled out. + if (g.ActiveId == id || g.ActiveId == 0) + { + g.ActiveIdHasBeenEditedThisFrame = true; + g.ActiveIdHasBeenEditedBefore = true; + } + + // We accept a MarkItemEdited() on drag and drop targets (see https://github.com/ocornut/imgui/issues/1875#issuecomment-978243343) + // We accept 'ActiveIdPreviousFrame == id' for InputText() returning an edit after it has been taken ActiveId away (#4714) + IM_ASSERT(g.DragDropActive || g.ActiveId == id || g.ActiveId == 0 || g.ActiveIdPreviousFrame == id); + //IM_ASSERT(g.CurrentWindow->DC.LastItemId == id); - g.ActiveIdHasBeenEditedThisFrame = true; - g.ActiveIdHasBeenEditedBefore = true; g.LastItemData.StatusFlags |= ImGuiItemStatusFlags_Edited; } -static inline bool IsWindowContentHoverable(ImGuiWindow* window, ImGuiHoveredFlags flags) +bool ImGui::IsWindowContentHoverable(ImGuiWindow* window, ImGuiHoveredFlags flags) { // An active popup disable hovering on other windows (apart from its own children) // FIXME-OPT: This could be cached/stored within the window. @@ -3518,11 +4012,17 @@ static inline bool IsWindowContentHoverable(ImGuiWindow* window, ImGuiHoveredFla if (focused_root_window->WasActive && focused_root_window != window->RootWindowDockTree) { // For the purpose of those flags we differentiate "standard popup" from "modal popup" - // NB: The order of those two tests is important because Modal windows are also Popups. + // NB: The 'else' is important because Modal windows are also Popups. + bool want_inhibit = false; if (focused_root_window->Flags & ImGuiWindowFlags_Modal) - return false; - if ((focused_root_window->Flags & ImGuiWindowFlags_Popup) && !(flags & ImGuiHoveredFlags_AllowWhenBlockedByPopup)) - return false; + want_inhibit = true; + else if ((focused_root_window->Flags & ImGuiWindowFlags_Popup) && !(flags & ImGuiHoveredFlags_AllowWhenBlockedByPopup)) + want_inhibit = true; + + // Inhibit hover unless the window is within the stack of our modal/popup + if (want_inhibit) + if (!IsWindowWithinBeginStackOf(window->RootWindow, focused_root_window)) + return false; } // Filter by viewport @@ -3557,6 +4057,7 @@ bool ImGui::IsItemHovered(ImGuiHoveredFlags flags) return false; IM_ASSERT((flags & (ImGuiHoveredFlags_AnyWindow | ImGuiHoveredFlags_RootWindow | ImGuiHoveredFlags_ChildWindows | ImGuiHoveredFlags_NoPopupHierarchy | ImGuiHoveredFlags_DockHierarchy)) == 0); // Flags not supported by this function + // Done with rectangle culling so we can perform heavier checks now // Test if we are hovering the right window (our window could be behind another window) // [2021/03/02] Reworked / reverted the revert, finally. Note we want e.g. BeginGroup/ItemAdd/EndGroup to work as well. (#3851) // [2017/10/16] Reverted commit 344d48be3 and testing RootWindow instead. I believe it is correct to NOT test for RootWindow but this leaves us unable @@ -3574,7 +4075,7 @@ bool ImGui::IsItemHovered(ImGuiHoveredFlags flags) // Test if interactions on this window are blocked by an active popup or modal. // The ImGuiHoveredFlags_AllowWhenBlockedByPopup flag will be tested here. - if (!IsWindowContentHoverable(window, flags)) + if (!IsWindowContentHoverable(window, flags) && !(g.LastItemData.InFlags & ImGuiItemFlags_NoWindowHoverableCheck)) return false; // Test if the item is disabled @@ -3592,6 +4093,24 @@ bool ImGui::IsItemHovered(ImGuiHoveredFlags flags) return false; } + // Handle hover delay + // (some ideas: https://www.nngroup.com/articles/timing-exposing-content) + float delay; + if (flags & ImGuiHoveredFlags_DelayNormal) + delay = g.IO.HoverDelayNormal; + else if (flags & ImGuiHoveredFlags_DelayShort) + delay = g.IO.HoverDelayShort; + else + delay = 0.0f; + if (delay > 0.0f) + { + ImGuiID hover_delay_id = (g.LastItemData.ID != 0) ? g.LastItemData.ID : window->GetIDFromRectangle(g.LastItemData.Rect); + if ((flags & ImGuiHoveredFlags_NoSharedDelay) && (g.HoverDelayIdPreviousFrame != hover_delay_id)) + g.HoverDelayTimer = 0.0f; + g.HoverDelayId = hover_delay_id; + return g.HoverDelayTimer >= delay; + } + return true; } @@ -3609,7 +4128,10 @@ bool ImGui::ItemHoverable(const ImRect& bb, ImGuiID id) return false; if (!IsMouseHoveringRect(bb.Min, bb.Max)) return false; - if (!IsWindowContentHoverable(window, ImGuiHoveredFlags_None)) + + // Done with rectangle culling so we can perform heavier checks now. + ImGuiItemFlags item_flags = (g.LastItemData.ID == id ? g.LastItemData.InFlags : g.CurrentItemFlags); + if (!(item_flags & ImGuiItemFlags_NoWindowHoverableCheck) && !IsWindowContentHoverable(window, ImGuiHoveredFlags_None)) { g.HoveredIdDisabled = true; return false; @@ -3622,7 +4144,6 @@ bool ImGui::ItemHoverable(const ImRect& bb, ImGuiID id) // When disabled we'll return false but still set HoveredId // Same thing if swiping - ImGuiItemFlags item_flags = (g.LastItemData.ID == id ? g.LastItemData.InFlags : g.CurrentItemFlags); if (item_flags & ImGuiItemFlags_Disabled || window->InertialScroll) { // Release active id if turning disabled @@ -3637,8 +4158,7 @@ bool ImGui::ItemHoverable(const ImRect& bb, ImGuiID id) // [DEBUG] Item Picker tool! // We perform the check here because SetHoveredID() is not frequently called (1~ time a frame), making // the cost of this tool near-zero. We can get slightly better call-stack and support picking non-hovered - // items if we perform the test in ItemAdd(), but that would incur a small runtime cost. - // #define IMGUI_DEBUG_TOOL_ITEM_PICKER_EX in imconfig.h if you want this check to also be performed in ItemAdd(). + // items if we performed the test in ItemAdd(), but that would incur a small runtime cost. if (g.DebugItemPickerActive && g.HoveredIdPreviousFrame == id) GetForegroundDrawList()->AddRect(bb.Min, bb.Max, IM_COL32(255, 255, 0, 255)); if (g.DebugItemPickerBreakId == id) @@ -3651,6 +4171,7 @@ bool ImGui::ItemHoverable(const ImRect& bb, ImGuiID id) return true; } +// FIXME: This is inlined/duplicated in ItemAdd() bool ImGui::IsClippedEx(const ImRect& bb, ImGuiID id) { ImGuiContext& g = *GImGui; @@ -3663,14 +4184,14 @@ bool ImGui::IsClippedEx(const ImRect& bb, ImGuiID id) } // This is also inlined in ItemAdd() -// Note: if ImGuiItemStatusFlags_HasDisplayRect is set, user needs to set window->DC.LastItemDisplayRect! +// Note: if ImGuiItemStatusFlags_HasDisplayRect is set, user needs to set g.LastItemData.DisplayRect. void ImGui::SetLastItemData(ImGuiID item_id, ImGuiItemFlags in_flags, ImGuiItemStatusFlags item_flags, const ImRect& item_rect) { ImGuiContext& g = *GImGui; g.LastItemData.ID = item_id; g.LastItemData.InFlags = in_flags; g.LastItemData.StatusFlags = item_flags; - g.LastItemData.Rect = item_rect; + g.LastItemData.Rect = g.LastItemData.NavRect = item_rect; } float ImGui::CalcWrapWidthForPos(const ImVec2& pos, float wrap_pos_x) @@ -3732,89 +4253,6 @@ const char* ImGui::GetVersion() return IMGUI_VERSION; } -// Internal state access - if you want to share Dear ImGui state between modules (e.g. DLL) or allocate it yourself -// Note that we still point to some static data and members (such as GFontAtlas), so the state instance you end up using will point to the static data within its module -ImGuiContext* ImGui::GetCurrentContext() -{ - return GImGui; -} - -void ImGui::SetCurrentContext(ImGuiContext* ctx) -{ -#ifdef IMGUI_SET_CURRENT_CONTEXT_FUNC - IMGUI_SET_CURRENT_CONTEXT_FUNC(ctx); // For custom thread-based hackery you may want to have control over this. -#else - GImGui = ctx; -#endif -} - -void ImGui::SetAllocatorFunctions(ImGuiMemAllocFunc alloc_func, ImGuiMemFreeFunc free_func, void* user_data) -{ - GImAllocatorAllocFunc = alloc_func; - GImAllocatorFreeFunc = free_func; - GImAllocatorUserData = user_data; -} - -// This is provided to facilitate copying allocators from one static/DLL boundary to another (e.g. retrieve default allocator of your executable address space) -void ImGui::GetAllocatorFunctions(ImGuiMemAllocFunc* p_alloc_func, ImGuiMemFreeFunc* p_free_func, void** p_user_data) -{ - *p_alloc_func = GImAllocatorAllocFunc; - *p_free_func = GImAllocatorFreeFunc; - *p_user_data = GImAllocatorUserData; -} - -ImGuiContext* ImGui::CreateContext(ImFontAtlas* shared_font_atlas) -{ - ImGuiContext* prev_ctx = GetCurrentContext(); - ImGuiContext* ctx = IM_NEW(ImGuiContext)(shared_font_atlas); - SetCurrentContext(ctx); - Initialize(); - if (prev_ctx != NULL) - SetCurrentContext(prev_ctx); // Restore previous context if any, else keep new one. - return ctx; -} - -void ImGui::DestroyContext(ImGuiContext* ctx) -{ - ImGuiContext* prev_ctx = GetCurrentContext(); - if (ctx == NULL) //-V1051 - ctx = prev_ctx; - SetCurrentContext(ctx); - Shutdown(); - SetCurrentContext((prev_ctx != ctx) ? prev_ctx : NULL); - IM_DELETE(ctx); -} - -// No specific ordering/dependency support, will see as needed -ImGuiID ImGui::AddContextHook(ImGuiContext* ctx, const ImGuiContextHook* hook) -{ - ImGuiContext& g = *ctx; - IM_ASSERT(hook->Callback != NULL && hook->HookId == 0 && hook->Type != ImGuiContextHookType_PendingRemoval_); - g.Hooks.push_back(*hook); - g.Hooks.back().HookId = ++g.HookIdNext; - return g.HookIdNext; -} - -// Deferred removal, avoiding issue with changing vector while iterating it -void ImGui::RemoveContextHook(ImGuiContext* ctx, ImGuiID hook_id) -{ - ImGuiContext& g = *ctx; - IM_ASSERT(hook_id != 0); - for (int n = 0; n < g.Hooks.Size; n++) - if (g.Hooks[n].HookId == hook_id) - g.Hooks[n].Type = ImGuiContextHookType_PendingRemoval_; -} - -// Call context hooks (used by e.g. test engine) -// We assume a small number of hooks so all stored in same array -void ImGui::CallContextHooks(ImGuiContext* ctx, ImGuiContextHookType hook_type) -{ - ImGuiContext& g = *ctx; - for (int n = 0; n < g.Hooks.Size; n++) - if (g.Hooks[n].Type == hook_type) - g.Hooks[n].Callback(&g, &g.Hooks[n]); -} - ImGuiIO& ImGui::GetIO() { IM_ASSERT(GImGui != NULL && "No current context. Did you call ImGui::CreateContext() and ImGui::SetCurrentContext() ?"); @@ -3907,7 +4345,7 @@ void ImGui::StartMouseMovingWindow(ImGuiWindow* window) g.NavDisableHighlight = true; g.ActiveIdClickOffset = g.IO.MouseClickedPos[0] - window->RootWindowDockTree->Pos; g.ActiveIdNoClearOnFocusLoss = true; - SetActiveIdUsingNavAndKeys(); + SetActiveIdUsingAllKeyboardKeys(); bool can_move_window = true; if ((window->Flags & ImGuiWindowFlags_NoMove) || (window->RootWindowDockTree->Flags & ImGuiWindowFlags_NoMove)) @@ -3964,13 +4402,12 @@ void ImGui::UpdateMouseMovingWindowNewFrame() ImGuiWindow* moving_window = g.MovingWindow->RootWindowDockTree; // When a window stop being submitted while being dragged, it may will its viewport until next Begin() - const bool window_disappared = (!moving_window->WasActive || moving_window->Viewport == NULL); + const bool window_disappared = ((!moving_window->WasActive && !moving_window->Active) || moving_window->Viewport == NULL); if (g.IO.MouseDown[0] && IsMousePosValid(&g.IO.MousePos) && !window_disappared) { ImVec2 pos = g.IO.MousePos - g.ActiveIdClickOffset; if (moving_window->Pos.x != pos.x || moving_window->Pos.y != pos.y) { - MarkIniSettingsDirty(moving_window); SetWindowPos(moving_window, pos, ImGuiCond_Always); g.InertialScrollInhibited=true; if (moving_window->ViewportOwned) // Synchronize viewport immediately because some overlays may relies on clipping rectangle before we Begin() into the window. @@ -4049,10 +4486,10 @@ void ImGui::UpdateMouseMovingWindowEndFrame() if (g.HoveredIdDisabled) g.MovingWindow = NULL; } - else if (root_window == NULL && g.NavWindow != NULL && GetTopMostPopupModal() == NULL) + else if (root_window == NULL && g.NavWindow != NULL) { // Clicking on void disable focus - FocusWindow(NULL); + FocusWindow(NULL, ImGuiFocusRequestFlags_UnlessBelowModal); } } @@ -4097,252 +4534,6 @@ static bool IsWindowActiveAndVisible(ImGuiWindow* window) return (window->Active) && (!window->Hidden); } -static void ImGui::UpdateKeyboardInputs() -{ - ImGuiContext& g = *GImGui; - ImGuiIO& io = g.IO; - - // Import legacy keys or verify they are not used -#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO - if (io.BackendUsingLegacyKeyArrays == 0) - { - // Backend used new io.AddKeyEvent() API: Good! Verify that old arrays are never written to externally. - for (int n = 0; n < ImGuiKey_LegacyNativeKey_END; n++) - IM_ASSERT((io.KeysDown[n] == false || IsKeyDown(n)) && "Backend needs to either only use io.AddKeyEvent(), either only fill legacy io.KeysDown[] + io.KeyMap[]. Not both!"); - } - else - { - if (g.FrameCount == 0) - for (int n = ImGuiKey_LegacyNativeKey_BEGIN; n < ImGuiKey_LegacyNativeKey_END; n++) - IM_ASSERT(g.IO.KeyMap[n] == -1 && "Backend is not allowed to write to io.KeyMap[0..511]!"); - - // Build reverse KeyMap (Named -> Legacy) - for (int n = ImGuiKey_NamedKey_BEGIN; n < ImGuiKey_NamedKey_END; n++) - if (io.KeyMap[n] != -1) - { - IM_ASSERT(IsLegacyKey((ImGuiKey)io.KeyMap[n])); - io.KeyMap[io.KeyMap[n]] = n; - } - - // Import legacy keys into new ones - for (int n = ImGuiKey_LegacyNativeKey_BEGIN; n < ImGuiKey_LegacyNativeKey_END; n++) - if (io.KeysDown[n] || io.BackendUsingLegacyKeyArrays == 1) - { - const ImGuiKey key = (ImGuiKey)(io.KeyMap[n] != -1 ? io.KeyMap[n] : n); - IM_ASSERT(io.KeyMap[n] == -1 || IsNamedKey(key)); - io.KeysData[key].Down = io.KeysDown[n]; - if (key != n) - io.KeysDown[key] = io.KeysDown[n]; // Allow legacy code using io.KeysDown[GetKeyIndex()] with old backends - io.BackendUsingLegacyKeyArrays = 1; - } - if (io.BackendUsingLegacyKeyArrays == 1) - { - io.KeysData[ImGuiKey_ModCtrl].Down = io.KeyCtrl; - io.KeysData[ImGuiKey_ModShift].Down = io.KeyShift; - io.KeysData[ImGuiKey_ModAlt].Down = io.KeyAlt; - io.KeysData[ImGuiKey_ModSuper].Down = io.KeySuper; - } - } -#endif - - // Synchronize io.KeyMods with individual modifiers io.KeyXXX bools - io.KeyMods = GetMergedModFlags(); - - // Clear gamepad data if disabled - if ((io.BackendFlags & ImGuiBackendFlags_HasGamepad) == 0) - for (int i = ImGuiKey_Gamepad_BEGIN; i < ImGuiKey_Gamepad_END; i++) - { - io.KeysData[i - ImGuiKey_KeysData_OFFSET].Down = false; - io.KeysData[i - ImGuiKey_KeysData_OFFSET].AnalogValue = 0.0f; - } - - // Update keys - for (int i = 0; i < IM_ARRAYSIZE(io.KeysData); i++) - { - ImGuiKeyData* key_data = &io.KeysData[i]; - key_data->DownDurationPrev = key_data->DownDuration; - key_data->DownDuration = key_data->Down ? (key_data->DownDuration < 0.0f ? 0.0f : key_data->DownDuration + io.DeltaTime) : -1.0f; - } -} - -static void ImGui::UpdateMouseInputs() -{ - ImGuiContext& g = *GImGui; - ImGuiIO& io = g.IO; - - // Round mouse position to avoid spreading non-rounded position (e.g. UpdateManualResize doesn't support them well) - if (IsMousePosValid(&io.MousePos)) - io.MousePos = g.MouseLastValidPos = ImFloorSigned(io.MousePos); - - io.MouseDeltaPrev=io.MouseDelta; - - // If mouse just appeared or disappeared (usually denoted by -FLT_MAX components) we cancel out movement in MouseDelta - if (IsMousePosValid(&io.MousePos) && IsMousePosValid(&io.MousePosPrev)) - io.MouseDelta = io.MousePos - io.MousePosPrev; - else - io.MouseDelta = ImVec2(0.0f, 0.0f); - - // If mouse moved we re-enable mouse hovering in case it was disabled by gamepad/keyboard. In theory should use a >0.0f threshold but would need to reset in everywhere we set this to true. - if (io.MouseDelta.x != 0.0f || io.MouseDelta.y != 0.0f) - g.NavDisableMouseHover = false; - - // Update mouse speed - if (ImFabs(io.MouseDelta.x)>ImFabs(io.MouseDeltaPrev.x)) { - io.MouseSpeed.x=io.MouseDelta.x; - } else { - io.MouseSpeed.x=io.MouseDeltaPrev.x; - } - if (ImFabs(io.MouseDelta.y)>ImFabs(io.MouseDeltaPrev.y)) { - io.MouseSpeed.y=io.MouseDelta.y; - } else { - io.MouseSpeed.y=io.MouseDeltaPrev.y; - } - - io.MousePosPrev = io.MousePos; - for (int i = 0; i < IM_ARRAYSIZE(io.MouseDown); i++) - { - io.MouseClicked[i] = io.MouseDown[i] && io.MouseDownDuration[i] < 0.0f; - io.MouseClickedCount[i] = 0; // Will be filled below - io.MouseReleased[i] = !io.MouseDown[i] && io.MouseDownDuration[i] >= 0.0f; - io.MouseDownDurationPrev[i] = io.MouseDownDuration[i]; - io.MouseDownDuration[i] = io.MouseDown[i] ? (io.MouseDownDuration[i] < 0.0f ? 0.0f : io.MouseDownDuration[i] + io.DeltaTime) : -1.0f; - if (io.MouseClicked[i]) - { - bool is_repeated_click = false; - if ((float)(g.Time - io.MouseClickedTime[i]) < io.MouseDoubleClickTime) - { - ImVec2 delta_from_click_pos = IsMousePosValid(&io.MousePos) ? (io.MousePos - io.MouseClickedPos[i]) : ImVec2(0.0f, 0.0f); - if (ImLengthSqr(delta_from_click_pos) < io.MouseDoubleClickMaxDist * io.MouseDoubleClickMaxDist) - is_repeated_click = true; - } - if (is_repeated_click) - io.MouseClickedLastCount[i]++; - else - io.MouseClickedLastCount[i] = 1; - io.MouseClickedTime[i] = g.Time; - io.MouseClickedPos[i] = io.MousePos; - io.MouseClickedCount[i] = io.MouseClickedLastCount[i]; - io.MouseDragMaxDistanceAbs[i] = ImVec2(0.0f, 0.0f); - io.MouseDragMaxDistanceSqr[i] = 0.0f; - } - else if (io.MouseDown[i]) - { - // Maintain the maximum distance we reaching from the initial click position, which is used with dragging threshold - ImVec2 delta_from_click_pos = IsMousePosValid(&io.MousePos) ? (io.MousePos - io.MouseClickedPos[i]) : ImVec2(0.0f, 0.0f); - io.MouseDragMaxDistanceSqr[i] = ImMax(io.MouseDragMaxDistanceSqr[i], ImLengthSqr(delta_from_click_pos)); - io.MouseDragMaxDistanceAbs[i].x = ImMax(io.MouseDragMaxDistanceAbs[i].x, delta_from_click_pos.x < 0.0f ? -delta_from_click_pos.x : delta_from_click_pos.x); - io.MouseDragMaxDistanceAbs[i].y = ImMax(io.MouseDragMaxDistanceAbs[i].y, delta_from_click_pos.y < 0.0f ? -delta_from_click_pos.y : delta_from_click_pos.y); - } - - // We provide io.MouseDoubleClicked[] as a legacy service - io.MouseDoubleClicked[i] = (io.MouseClickedCount[i] == 2); - - // Clicking any mouse button reactivate mouse hovering which may have been deactivated by gamepad/keyboard navigation - if (io.MouseClicked[i]) - g.NavDisableMouseHover = false; - } -} - -static void StartLockWheelingWindow(ImGuiWindow* window) -{ - ImGuiContext& g = *GImGui; - if (g.WheelingWindow == window) - return; - g.WheelingWindow = window; - g.WheelingWindowRefMousePos = g.IO.MousePos; - g.WheelingWindowTimer = WINDOWS_MOUSE_WHEEL_SCROLL_LOCK_TIMER; -} - -void ImGui::UpdateMouseWheel() -{ - ImGuiContext& g = *GImGui; - - // Reset the locked window if we move the mouse or after the timer elapses - if (g.WheelingWindow != NULL) - { - g.WheelingWindowTimer -= g.IO.DeltaTime; - if (IsMousePosValid() && ImLengthSqr(g.IO.MousePos - g.WheelingWindowRefMousePos) > g.IO.MouseDragThreshold * g.IO.MouseDragThreshold) - g.WheelingWindowTimer = 0.0f; - if (g.WheelingWindowTimer <= 0.0f) - { - g.WheelingWindow = NULL; - g.WheelingWindowTimer = 0.0f; - } - } - - float wheel_x = g.IO.MouseWheelH; - float wheel_y = g.IO.MouseWheel; - if (wheel_x == 0.0f && wheel_y == 0.0f) - return; - - if ((g.ActiveId != 0 && g.ActiveIdUsingMouseWheel) || (g.HoveredIdPreviousFrame != 0 && g.HoveredIdPreviousFrameUsingMouseWheel)) - return; - - ImGuiWindow* window = g.WheelingWindow ? g.WheelingWindow : g.HoveredWindow; - if (!window || window->Collapsed) - return; - - // Zoom / Scale window - // FIXME-OBSOLETE: This is an old feature, it still works but pretty much nobody is using it and may be best redesigned. - if (wheel_y != 0.0f && g.IO.KeyCtrl && g.IO.FontAllowUserScaling) - { - StartLockWheelingWindow(window); - const float new_font_scale = ImClamp(window->FontWindowScale + g.IO.MouseWheel * 0.10f, 0.50f, 2.50f); - const float scale = new_font_scale / window->FontWindowScale; - window->FontWindowScale = new_font_scale; - if (window == window->RootWindow) - { - const ImVec2 offset = window->Size * (1.0f - scale) * (g.IO.MousePos - window->Pos) / window->Size; - SetWindowPos(window, window->Pos + offset, 0); - window->Size = ImFloor(window->Size * scale); - window->SizeFull = ImFloor(window->SizeFull * scale); - } - return; - } - - // Mouse wheel scrolling - // If a child window has the ImGuiWindowFlags_NoScrollWithMouse flag, we give a chance to scroll its parent - if (g.IO.KeyCtrl) - return; - - // As a standard behavior holding SHIFT while using Vertical Mouse Wheel triggers Horizontal scroll instead - // (we avoid doing it on OSX as it the OS input layer handles this already) - const bool swap_axis = g.IO.KeyShift && !g.IO.ConfigMacOSXBehaviors; - if (swap_axis) - { - wheel_x = wheel_y; - wheel_y = 0.0f; - } - - // Vertical Mouse Wheel scrolling - if (wheel_y != 0.0f) - { - StartLockWheelingWindow(window); - while ((window->Flags & ImGuiWindowFlags_ChildWindow) && ((window->ScrollMax.y == 0.0f) || ((window->Flags & ImGuiWindowFlags_NoScrollWithMouse) && !(window->Flags & ImGuiWindowFlags_NoMouseInputs)))) - window = window->ParentWindow; - if (!(window->Flags & ImGuiWindowFlags_NoScrollWithMouse) && !(window->Flags & ImGuiWindowFlags_NoMouseInputs)) - { - float max_step = window->InnerRect.GetHeight() * 0.67f; - float scroll_step = ImFloor(ImMin(5 * window->CalcFontSize(), max_step)); - SetScrollY(window, window->Scroll.y - wheel_y * scroll_step); - } - } - - // Horizontal Mouse Wheel scrolling, or Vertical Mouse Wheel w/ Shift held - if (wheel_x != 0.0f) - { - StartLockWheelingWindow(window); - while ((window->Flags & ImGuiWindowFlags_ChildWindow) && ((window->ScrollMax.x == 0.0f) || ((window->Flags & ImGuiWindowFlags_NoScrollWithMouse) && !(window->Flags & ImGuiWindowFlags_NoMouseInputs)))) - window = window->ParentWindow; - if (!(window->Flags & ImGuiWindowFlags_NoScrollWithMouse) && !(window->Flags & ImGuiWindowFlags_NoMouseInputs)) - { - float max_step = window->InnerRect.GetWidth() * 0.67f; - float scroll_step = ImFloor(ImMin(2 * window->CalcFontSize(), max_step)); - SetScrollX(window, window->Scroll.x - wheel_x * scroll_step); - } - } -} - // The reason this is exposed in imgui_internal.h is: on touch-based system that don't have hovering, we want to dispatch inputs to the right target (imgui vs imgui+app) void ImGui::UpdateHoveredWindowAndCaptureFlags() { @@ -4421,18 +4612,6 @@ void ImGui::UpdateHoveredWindowAndCaptureFlags() io.WantTextInput = (g.WantTextInputNextFrame != -1) ? (g.WantTextInputNextFrame != 0) : false; } -// [Internal] Do not use directly (can read io.KeyMods instead) -ImGuiModFlags ImGui::GetMergedModFlags() -{ - ImGuiContext& g = *GImGui; - ImGuiModFlags key_mods = ImGuiModFlags_None; - if (g.IO.KeyCtrl) { key_mods |= ImGuiModFlags_Ctrl; } - if (g.IO.KeyShift) { key_mods |= ImGuiModFlags_Shift; } - if (g.IO.KeyAlt) { key_mods |= ImGuiModFlags_Alt; } - if (g.IO.KeySuper) { key_mods |= ImGuiModFlags_Super; } - return key_mods; -} - void ImGui::NewFrame() { IM_ASSERT(GImGui != NULL && "No current context. Did you call ImGui::CreateContext() and ImGui::SetCurrentContext() ?"); @@ -4469,6 +4648,11 @@ void ImGui::NewFrame() g.IO.Framerate = (g.FramerateSecPerFrameAccum > 0.0f) ? (1.0f / (g.FramerateSecPerFrameAccum / (float)g.FramerateSecPerFrameCount)) : FLT_MAX; g.IO.IsSomethingHappening = false; + // Process input queue (trickle as many events as possible), turn events into writes to IO structure + g.InputEventsTrail.resize(0); + UpdateInputEvents(g.IO.ConfigInputTrickleEventQueue); + + // Update viewports (after processing input queue, so io.MouseHoveredViewport is set) UpdateViewportsNewFrame(); // Setup current font and draw list shared data @@ -4514,15 +4698,20 @@ void ImGui::NewFrame() if (g.HoveredId && g.ActiveId != g.HoveredId) g.HoveredIdNotActiveTimer += g.IO.DeltaTime; g.HoveredIdPreviousFrame = g.HoveredId; - g.HoveredIdPreviousFrameUsingMouseWheel = g.HoveredIdUsingMouseWheel; g.HoveredId = 0; g.HoveredIdAllowOverlap = false; - g.HoveredIdUsingMouseWheel = false; g.HoveredIdDisabled = false; - // Update ActiveId data (clear reference to active widget if the widget isn't alive anymore) - if (g.ActiveIdIsAlive != g.ActiveId && g.ActiveIdPreviousFrame == g.ActiveId && g.ActiveId != 0) + // Clear ActiveID if the item is not alive anymore. + // In 1.87, the common most call to KeepAliveID() was moved from GetID() to ItemAdd(). + // As a result, custom widget using ButtonBehavior() _without_ ItemAdd() need to call KeepAliveID() themselves. + if (g.ActiveId != 0 && g.ActiveIdIsAlive != g.ActiveId && g.ActiveIdPreviousFrame == g.ActiveId) + { + IMGUI_DEBUG_LOG_ACTIVEID("NewFrame(): ClearActiveID() because it isn't marked alive anymore!\n"); ClearActiveID(); + } + + // Update ActiveId data (clear reference to active widget if the widget isn't alive anymore) if (g.ActiveId) g.ActiveIdTimer += g.IO.DeltaTime; g.LastActiveIdTimer += g.IO.DeltaTime; @@ -4538,8 +4727,41 @@ void ImGui::NewFrame() if (g.ActiveId == 0) { g.ActiveIdUsingNavDirMask = 0x00; + g.ActiveIdUsingAllKeyboardKeys = false; +#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO g.ActiveIdUsingNavInputMask = 0x00; - g.ActiveIdUsingKeyInputMask.ClearAllBits(); +#endif + } + +#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO + if (g.ActiveId == 0) + g.ActiveIdUsingNavInputMask = 0; + else if (g.ActiveIdUsingNavInputMask != 0) + { + // If your custom widget code used: { g.ActiveIdUsingNavInputMask |= (1 << ImGuiNavInput_Cancel); } + // Since IMGUI_VERSION_NUM >= 18804 it should be: { SetKeyOwner(ImGuiKey_Escape, g.ActiveId); SetKeyOwner(ImGuiKey_NavGamepadCancel, g.ActiveId); } + if (g.ActiveIdUsingNavInputMask & (1 << ImGuiNavInput_Cancel)) + SetKeyOwner(ImGuiKey_Escape, g.ActiveId); + if (g.ActiveIdUsingNavInputMask & ~(1 << ImGuiNavInput_Cancel)) + IM_ASSERT(0); // Other values unsupported + } +#endif + + // Update hover delay for IsItemHovered() with delays and tooltips + g.HoverDelayIdPreviousFrame = g.HoverDelayId; + if (g.HoverDelayId != 0) + { + //if (g.IO.MouseDelta.x == 0.0f && g.IO.MouseDelta.y == 0.0f) // Need design/flags + g.HoverDelayTimer += g.IO.DeltaTime; + g.HoverDelayClearTimer = 0.0f; + g.HoverDelayId = 0; + } + else if (g.HoverDelayTimer > 0.0f) + { + // This gives a little bit of leeway before clearing the hover timer, allowing mouse to cross gaps + g.HoverDelayClearTimer += g.IO.DeltaTime; + if (g.HoverDelayClearTimer >= ImMax(0.20f, g.IO.DeltaTime * 2.0f)) // ~6 frames at 30 Hz + allow for low framerate + g.HoverDelayTimer = g.HoverDelayClearTimer = 0.0f; // May want a decaying timer, in which case need to clamp at max first, based on max of caller last requested timer. } // Drag and drop @@ -4554,10 +4776,6 @@ void ImGui::NewFrame() //if (g.IO.AppFocusLost) // ClosePopupsExceptModals(); - // Process input queue (trickle as many events as possible) - g.InputEventsTrail.resize(0); - UpdateInputEvents(g.IO.ConfigInputTrickleEventQueue); - // Update keyboard input state UpdateKeyboardInputs(); @@ -4606,9 +4824,10 @@ void ImGui::NewFrame() { ImGuiWindow* window = g.Windows[i]; window->WasActive = window->Active; - window->BeginCount = 0; window->Active = false; window->WriteAccessed = false; + window->BeginCountPreviousFrame = window->BeginCount; + window->BeginCount = 0; // Garbage collect transient buffers of recently unused windows if (!window->WasActive && !window->MemoryCompacted && window->LastTimeActive < memory_compact_start_time) @@ -4628,7 +4847,7 @@ void ImGui::NewFrame() // Closing the focused window restore focus to the first active root window in descending z-order if (g.NavWindow && !g.NavWindow->WasActive) - FocusTopMostWindowUnderOne(NULL, NULL); + FocusTopMostWindowUnderOne(NULL, NULL, NULL, ImGuiFocusRequestFlags_RestoreFocusedChild); // No window should be open at the beginning of the frame. // But in order to allow the user to call NewFrame() multiple times without calling Render(), we are doing an explicit clear. @@ -4644,134 +4863,32 @@ void ImGui::NewFrame() // [DEBUG] Update debug features UpdateDebugToolItemPicker(); UpdateDebugToolStackQueries(); + if (g.DebugLocateFrames > 0 && --g.DebugLocateFrames == 0) + g.DebugLocateId = 0; + if (g.DebugLogClipperAutoDisableFrames > 0 && --g.DebugLogClipperAutoDisableFrames == 0) + { + DebugLog("(Auto-disabled ImGuiDebugLogFlags_EventClipper to avoid spamming)\n"); + g.DebugLogFlags &= ~ImGuiDebugLogFlags_EventClipper; + } // Create implicit/fallback window - which we will only render it if the user has added something to it. // We don't use "Debug" to avoid colliding with user trying to create a "Debug" window with custom flags. - // This fallback is particularly important as it avoid ImGui:: calls from crashing. + // This fallback is particularly important as it prevents ImGui:: calls from crashing. g.WithinFrameScopeWithImplicitWindow = true; SetNextWindowSize(ImVec2(400, 400), ImGuiCond_FirstUseEver); Begin("Debug##Default"); IM_ASSERT(g.CurrentWindow->IsFallbackWindow == true); + // [DEBUG] When io.ConfigDebugBeginReturnValue is set, we make Begin()/BeginChild() return false at different level of the window-stack, + // allowing to validate correct Begin/End behavior in user code. + if (g.IO.ConfigDebugBeginReturnValueLoop) + g.DebugBeginReturnValueCullDepth = (g.DebugBeginReturnValueCullDepth == -1) ? 0 : ((g.DebugBeginReturnValueCullDepth + ((g.FrameCount % 4) == 0 ? 1 : 0)) % 10); + else + g.DebugBeginReturnValueCullDepth = -1; + CallContextHooks(&g, ImGuiContextHookType_NewFramePost); } -void ImGui::Initialize() -{ - ImGuiContext& g = *GImGui; - IM_ASSERT(!g.Initialized && !g.SettingsLoaded); - - // Add .ini handle for ImGuiWindow type - { - ImGuiSettingsHandler ini_handler; - ini_handler.TypeName = "Window"; - ini_handler.TypeHash = ImHashStr("Window"); - ini_handler.ClearAllFn = WindowSettingsHandler_ClearAll; - ini_handler.ReadOpenFn = WindowSettingsHandler_ReadOpen; - ini_handler.ReadLineFn = WindowSettingsHandler_ReadLine; - ini_handler.ApplyAllFn = WindowSettingsHandler_ApplyAll; - ini_handler.WriteAllFn = WindowSettingsHandler_WriteAll; - AddSettingsHandler(&ini_handler); - } - - // Add .ini handle for ImGuiTable type - TableSettingsAddSettingsHandler(); - - // Create default viewport - ImGuiViewportP* viewport = IM_NEW(ImGuiViewportP)(); - viewport->ID = IMGUI_VIEWPORT_DEFAULT_ID; - viewport->Idx = 0; - viewport->PlatformWindowCreated = true; - viewport->Flags = ImGuiViewportFlags_OwnedByApp; - g.Viewports.push_back(viewport); - g.PlatformIO.Viewports.push_back(g.Viewports[0]); - -#ifdef IMGUI_HAS_DOCK - // Initialize Docking - DockContextInitialize(&g); -#endif - - g.Initialized = true; -} - -// This function is merely here to free heap allocations. -void ImGui::Shutdown() -{ - // The fonts atlas can be used prior to calling NewFrame(), so we clear it even if g.Initialized is FALSE (which would happen if we never called NewFrame) - ImGuiContext& g = *GImGui; - if (g.IO.Fonts && g.FontAtlasOwnedByContext) - { - g.IO.Fonts->Locked = false; - IM_DELETE(g.IO.Fonts); - } - g.IO.Fonts = NULL; - - // Cleanup of other data are conditional on actually having initialized Dear ImGui. - if (!g.Initialized) - return; - - // Save settings (unless we haven't attempted to load them: CreateContext/DestroyContext without a call to NewFrame shouldn't save an empty file) - if (g.SettingsLoaded && g.IO.IniFilename != NULL) - SaveIniSettingsToDisk(g.IO.IniFilename); - - // Destroy platform windows - DestroyPlatformWindows(); - - // Shutdown extensions - DockContextShutdown(&g); - - CallContextHooks(&g, ImGuiContextHookType_Shutdown); - - // Clear everything else - g.Windows.clear_delete(); - g.WindowsFocusOrder.clear(); - g.WindowsTempSortBuffer.clear(); - g.CurrentWindow = NULL; - g.CurrentWindowStack.clear(); - g.WindowsById.Clear(); - g.NavWindow = NULL; - g.HoveredWindow = g.HoveredWindowUnderMovingWindow = NULL; - g.ActiveIdWindow = g.ActiveIdPreviousFrameWindow = NULL; - g.MovingWindow = NULL; - g.ColorStack.clear(); - g.StyleVarStack.clear(); - g.FontStack.clear(); - g.OpenPopupStack.clear(); - g.BeginPopupStack.clear(); - - g.CurrentViewport = g.MouseViewport = g.MouseLastHoveredViewport = NULL; - g.Viewports.clear_delete(); - - g.TabBars.Clear(); - g.CurrentTabBarStack.clear(); - g.ShrinkWidthBuffer.clear(); - - g.ClipperTempData.clear_destruct(); - - g.Tables.Clear(); - g.TablesTempData.clear_destruct(); - g.DrawChannelsTempMergeBuffer.clear(); - - g.ClipboardHandlerData.clear(); - g.MenusIdSubmittedThisFrame.clear(); - g.InputTextState.ClearFreeMemory(); - - g.SettingsWindows.clear(); - g.SettingsHandlers.clear(); - - if (g.LogFile) - { -#ifndef IMGUI_DISABLE_TTY_FUNCTIONS - if (g.LogFile != stdout) -#endif - ImFileClose(g.LogFile); - g.LogFile = NULL; - } - g.LogBuffer.clear(); - - g.Initialized = false; -} - // FIXME: Add a more explicit sort order in the window structure. static int IMGUI_CDECL ChildWindowComparer(const void* lhs, const void* rhs) { @@ -4887,7 +5004,7 @@ static void SetupViewportDrawData(ImGuiViewportP* viewport, ImVectorFlags & ImGuiViewportFlags_Minimized) != 0; + const bool is_minimized = (viewport->Flags & ImGuiViewportFlags_IsMinimized) != 0; ImGuiIO& io = ImGui::GetIO(); ImDrawData* draw_data = &viewport->DrawDataP; @@ -5065,10 +5182,25 @@ void ImGui::EndFrame() ErrorCheckEndFrameSanityChecks(); // Notify Platform/OS when our Input Method Editor cursor has moved (e.g. CJK inputs using Microsoft IME) - if (g.IO.SetPlatformImeDataFn && memcmp(&g.PlatformImeData, &g.PlatformImeDataPrev, sizeof(ImGuiPlatformImeData)) != 0) + ImGuiPlatformImeData* ime_data = &g.PlatformImeData; + if (g.IO.SetPlatformImeDataFn && memcmp(ime_data, &g.PlatformImeDataPrev, sizeof(ImGuiPlatformImeData)) != 0) { ImGuiViewport* viewport = FindViewportByID(g.PlatformImeViewport); - g.IO.SetPlatformImeDataFn(viewport ? viewport : GetMainViewport(), &g.PlatformImeData); + IMGUI_DEBUG_LOG_IO("[io] Calling io.SetPlatformImeDataFn(): WantVisible: %d, InputPos (%.2f,%.2f)\n", ime_data->WantVisible, ime_data->InputPos.x, ime_data->InputPos.y); + if (viewport == NULL) + viewport = GetMainViewport(); +#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS + if (viewport->PlatformHandleRaw == NULL && g.IO.ImeWindowHandle != NULL) + { + viewport->PlatformHandleRaw = g.IO.ImeWindowHandle; + g.IO.SetPlatformImeDataFn(viewport, ime_data); + viewport->PlatformHandleRaw = NULL; + } + else +#endif + { + g.IO.SetPlatformImeDataFn(viewport, ime_data); + } } // Hide implicit/fallback "Debug" window if it hasn't been used @@ -5138,9 +5270,9 @@ void ImGui::EndFrame() g.IO.Fonts->Locked = false; // Clear Input data for next frame + g.IO.AppFocusLost = false; g.IO.MouseWheel = g.IO.MouseWheelH = 0.0f; g.IO.InputQueueCharacters.resize(0); - memset(g.IO.NavInputs, 0, sizeof(g.IO.NavInputs)); CallContextHooks(&g, ImGuiContextHookType_EndFramePost); } @@ -5395,7 +5527,7 @@ bool ImGui::IsAnyItemFocused() bool ImGui::IsItemVisible() { ImGuiContext& g = *GImGui; - return g.CurrentWindow->ClipRect.Overlaps(g.LastItemData.Rect); + return (g.LastItemData.StatusFlags & ImGuiItemStatusFlags_Visible) != 0; } bool ImGui::IsItemEdited() @@ -5416,26 +5548,22 @@ void ImGui::SetItemAllowOverlap() g.ActiveIdAllowOverlap = true; } -void ImGui::SetItemUsingMouseWheel() -{ - ImGuiContext& g = *GImGui; - ImGuiID id = g.LastItemData.ID; - if (g.HoveredId == id) - g.HoveredIdUsingMouseWheel = true; - if (g.ActiveId == id) - g.ActiveIdUsingMouseWheel = true; -} - -void ImGui::SetActiveIdUsingNavAndKeys() +// FIXME: It might be undesirable that this will likely disable KeyOwner-aware shortcuts systems. Consider a more fine-tuned version for the two users of this function. +void ImGui::SetActiveIdUsingAllKeyboardKeys() { ImGuiContext& g = *GImGui; IM_ASSERT(g.ActiveId != 0); - g.ActiveIdUsingNavDirMask = ~(ImU32)0; - g.ActiveIdUsingNavInputMask = ~(ImU32)0; - g.ActiveIdUsingKeyInputMask.SetAllBits(); + g.ActiveIdUsingNavDirMask = (1 << ImGuiDir_COUNT) - 1; + g.ActiveIdUsingAllKeyboardKeys = true; NavMoveRequestCancel(); } +ImGuiID ImGui::GetItemID() +{ + ImGuiContext& g = *GImGui; + return g.LastItemData.ID; +} + ImVec2 ImGui::GetItemRectMin() { ImGuiContext& g = *GImGui; @@ -5467,21 +5595,22 @@ bool ImGui::BeginChildEx(const char* name, ImGuiID id, const ImVec2& size_arg, b ImVec2 size = ImFloor(size_arg); const int auto_fit_axises = ((size.x == 0.0f) ? (1 << ImGuiAxis_X) : 0x00) | ((size.y == 0.0f) ? (1 << ImGuiAxis_Y) : 0x00); if (size.x <= 0.0f) - size.x = ImMax(content_avail.x + size.x, 4.0f); // Arbitrary minimum child size (0.0f causing too much issues) + size.x = ImMax(content_avail.x + size.x, 4.0f); // Arbitrary minimum child size (0.0f causing too many issues) if (size.y <= 0.0f) size.y = ImMax(content_avail.y + size.y, 4.0f); SetNextWindowSize(size); // Build up name. If you need to append to a same child from multiple location in the ID stack, use BeginChild(ImGuiID id) with a stable value. + const char* temp_window_name; if (name) - ImFormatString(g.TempBuffer, IM_ARRAYSIZE(g.TempBuffer), "%s/%s_%08X", parent_window->Name, name, id); + ImFormatStringToTempBuffer(&temp_window_name, NULL, "%s/%s_%08X", parent_window->Name, name, id); else - ImFormatString(g.TempBuffer, IM_ARRAYSIZE(g.TempBuffer), "%s/%08X", parent_window->Name, id); + ImFormatStringToTempBuffer(&temp_window_name, NULL, "%s/%08X", parent_window->Name, id); const float backup_border_size = g.Style.ChildBorderSize; if (!border) g.Style.ChildBorderSize = 0.0f; - bool ret = Begin(g.TempBuffer, NULL, flags); + bool ret = Begin(temp_window_name, NULL, flags); g.Style.ChildBorderSize = backup_border_size; ImGuiWindow* child_window = g.CurrentWindow; @@ -5494,12 +5623,16 @@ bool ImGui::BeginChildEx(const char* name, ImGuiID id, const ImVec2& size_arg, b parent_window->DC.CursorPos = child_window->Pos; // Process navigation-in immediately so NavInit can run on first frame - if (g.NavActivateId == id && !(flags & ImGuiWindowFlags_NavFlattened) && (child_window->DC.NavLayersActiveMask != 0 || child_window->DC.NavHasScroll)) + // Can enter a child if (A) it has navigatable items or (B) it can be scrolled. + const ImGuiID temp_id_for_activation = (id + 1); + if (g.ActiveId == temp_id_for_activation) + ClearActiveID(); + if (g.NavActivateId == id && !(flags & ImGuiWindowFlags_NavFlattened) && (child_window->DC.NavLayersActiveMask != 0 || child_window->DC.NavWindowHasScrollY)) { FocusWindow(child_window); NavInitWindow(child_window, false); - SetActiveID(id + 1, child_window); // Steal ActiveId with another arbitrary id so that key-press won't activate child item - g.ActiveIdSource = ImGuiInputSource_Nav; + SetActiveID(temp_id_for_activation, child_window); // Steal ActiveId with another arbitrary id so that key-press won't activate child item + g.ActiveIdSource = g.NavInputSource; } return ret; } @@ -5541,7 +5674,7 @@ void ImGui::EndChild() ImGuiWindow* parent_window = g.CurrentWindow; ImRect bb(parent_window->DC.CursorPos, parent_window->DC.CursorPos + sz); ItemSize(sz); - if ((window->DC.NavLayersActiveMask != 0 || window->DC.NavHasScroll) && !(window->Flags & ImGuiWindowFlags_NavFlattened)) + if ((window->DC.NavLayersActiveMask != 0 || window->DC.NavWindowHasScrollY) && !(window->Flags & ImGuiWindowFlags_NavFlattened)) { ItemAdd(bb, window->ChildId); RenderNavHighlight(bb, window->ChildId); @@ -5554,6 +5687,10 @@ void ImGui::EndChild() { // Not navigable into ItemAdd(bb, 0); + + // But when flattened we directly reach items, adjust active layer mask accordingly + if (window->Flags & ImGuiWindowFlags_NavFlattened) + parent_window->DC.NavLayersActiveMaskNext |= window->DC.NavLayersActiveMaskNext; } if (g.HoveredWindow == window) g.LastItemData.StatusFlags |= ImGuiItemStatusFlags_HoveredWindow; @@ -5623,7 +5760,7 @@ static void UpdateWindowInFocusOrderList(ImGuiWindow* window, bool just_created, { ImGuiContext& g = *GImGui; - const bool new_is_explicit_child = (new_flags & ImGuiWindowFlags_ChildWindow) != 0; + const bool new_is_explicit_child = (new_flags & ImGuiWindowFlags_ChildWindow) != 0 && ((new_flags & ImGuiWindowFlags_Popup) == 0 || (new_flags & ImGuiWindowFlags_ChildMenu) != 0); const bool child_flag_changed = new_is_explicit_child != window->IsExplicitChild; if ((just_created || child_flag_changed) && !new_is_explicit_child) { @@ -5642,33 +5779,23 @@ static void UpdateWindowInFocusOrderList(ImGuiWindow* window, bool just_created, window->IsExplicitChild = new_is_explicit_child; } -static ImGuiWindow* CreateNewWindow(const char* name, ImGuiWindowFlags flags) +static void InitOrLoadWindowSettings(ImGuiWindow* window, ImGuiWindowSettings* settings) { - ImGuiContext& g = *GImGui; - //IMGUI_DEBUG_LOG("CreateNewWindow '%s', flags = 0x%08X\n", name, flags); - - // Create window the first time - ImGuiWindow* window = IM_NEW(ImGuiWindow)(&g, name); - window->Flags = flags; - g.WindowsById.SetVoidPtr(window->ID, window); - - // Default/arbitrary window position. Use SetNextWindowPos() with the appropriate condition flag to change the initial position of a window. + // Initial window state with e.g. default/arbitrary window position + // Use SetNextWindowPos() with the appropriate condition flag to change the initial position of a window. const ImGuiViewport* main_viewport = ImGui::GetMainViewport(); window->Pos = main_viewport->Pos + ImVec2(60, 60); window->ViewportPos = main_viewport->Pos; + window->SetWindowPosAllowFlags = window->SetWindowSizeAllowFlags = window->SetWindowCollapsedAllowFlags = window->SetWindowDockAllowFlags = ImGuiCond_Always | ImGuiCond_Once | ImGuiCond_FirstUseEver | ImGuiCond_Appearing; - // User can disable loading and saving of settings. Tooltip and child windows also don't store settings. - if (!(flags & ImGuiWindowFlags_NoSavedSettings)) - if (ImGuiWindowSettings* settings = ImGui::FindWindowSettings(window->ID)) - { - // Retrieve settings from .ini file - window->SettingsOffset = g.SettingsWindows.offset_from_ptr(settings); - SetWindowConditionAllowFlags(window, ImGuiCond_FirstUseEver, false); - ApplyWindowSettings(window, settings); - } + if (settings != NULL) + { + SetWindowConditionAllowFlags(window, ImGuiCond_FirstUseEver, false); + ApplyWindowSettings(window, settings); + } window->DC.CursorStartPos = window->DC.CursorMaxPos = window->DC.IdealMaxPos = window->Pos; // So first call to CalcWindowContentSizes() doesn't return crazy values - if ((flags & ImGuiWindowFlags_AlwaysAutoResize) != 0) + if ((window->Flags & ImGuiWindowFlags_AlwaysAutoResize) != 0) { window->AutoFitFramesX = window->AutoFitFramesY = 2; window->AutoFitOnlyGrows = false; @@ -5681,12 +5808,28 @@ static ImGuiWindow* CreateNewWindow(const char* name, ImGuiWindowFlags flags) window->AutoFitFramesY = 2; window->AutoFitOnlyGrows = (window->AutoFitFramesX > 0) || (window->AutoFitFramesY > 0); } +} + +static ImGuiWindow* CreateNewWindow(const char* name, ImGuiWindowFlags flags) +{ + // Create window the first time + //IMGUI_DEBUG_LOG("CreateNewWindow '%s', flags = 0x%08X\n", name, flags); + ImGuiContext& g = *GImGui; + ImGuiWindow* window = IM_NEW(ImGuiWindow)(&g, name); + window->Flags = flags; + g.WindowsById.SetVoidPtr(window->ID, window); + + ImGuiWindowSettings* settings = NULL; + if (!(flags & ImGuiWindowFlags_NoSavedSettings)) + if ((settings = ImGui::FindWindowSettingsByWindow(window)) != 0) + window->SettingsOffset = g.SettingsWindows.offset_from_ptr(settings); + + InitOrLoadWindowSettings(window, settings); if (flags & ImGuiWindowFlags_NoBringToFrontOnFocus) g.Windows.push_front(window); // Quite slow but rare and only once else g.Windows.push_back(window); - UpdateWindowInFocusOrderList(window, true, window->Flags); return window; } @@ -5729,9 +5872,9 @@ static ImVec2 CalcWindowSizeAfterConstraint(ImGuiWindow* window, const ImVec2& s if (!(window->Flags & (ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_AlwaysAutoResize))) { ImGuiWindow* window_for_height = GetWindowForTitleAndMenuHeight(window); - const float decoration_up_height = window_for_height->TitleBarHeight() + window_for_height->MenuBarHeight(); new_size = ImMax(new_size, g.Style.WindowMinSize); - new_size.y = ImMax(new_size.y, decoration_up_height + ImMax(0.0f, g.Style.WindowRounding - 1.0f)); // Reduce artifacts with very small windows + const float minimum_height = window_for_height->TitleBarHeight() + window_for_height->MenuBarHeight() + ImMax(0.0f, g.Style.WindowRounding - 1.0f); + new_size.y = ImMax(new_size.y, minimum_height); // Reduce artifacts with very small windows } return new_size; } @@ -5760,9 +5903,10 @@ static ImVec2 CalcWindowAutoFitSize(ImGuiWindow* window, const ImVec2& size_cont { ImGuiContext& g = *GImGui; ImGuiStyle& style = g.Style; - const float decoration_up_height = window->TitleBarHeight() + window->MenuBarHeight(); + const float decoration_w_without_scrollbars = window->DecoOuterSizeX1 + window->DecoOuterSizeX2 - window->ScrollbarSizes.x; + const float decoration_h_without_scrollbars = window->DecoOuterSizeY1 + window->DecoOuterSizeY2 - window->ScrollbarSizes.y; ImVec2 size_pad = window->WindowPadding * 2.0f; - ImVec2 size_desired = size_contents + size_pad + ImVec2(0.0f, decoration_up_height); + ImVec2 size_desired = size_contents + size_pad + ImVec2(decoration_w_without_scrollbars, decoration_h_without_scrollbars); if (window->Flags & ImGuiWindowFlags_Tooltip) { // Tooltip always resize @@ -5777,8 +5921,7 @@ static ImVec2 CalcWindowAutoFitSize(ImGuiWindow* window, const ImVec2& size_cont if (is_popup || is_menu) // Popups and menus bypass style.WindowMinSize by default, but we give then a non-zero minimum size to facilitate understanding problematic cases (e.g. empty popups) size_min = ImMin(size_min, ImVec2(4.0f, 4.0f)); - // FIXME-VIEWPORT-WORKAREA: May want to use GetWorkSize() instead of Size depending on the type of windows? - ImVec2 avail_size = window->Viewport->Size; + ImVec2 avail_size = window->Viewport->WorkSize; if (window->ViewportOwned) avail_size = ImVec2(FLT_MAX, FLT_MAX); const int monitor_idx = window->ViewportAllowPlatformMonitorExtend; @@ -5789,8 +5932,8 @@ static ImVec2 CalcWindowAutoFitSize(ImGuiWindow* window, const ImVec2& size_cont // When the window cannot fit all contents (either because of constraints, either because screen is too small), // we are growing the size on the other axis to compensate for expected scrollbar. FIXME: Might turn bigger than ViewportSize-WindowPadding. ImVec2 size_auto_fit_after_constraint = CalcWindowSizeAfterConstraint(window, size_auto_fit); - bool will_have_scrollbar_x = (size_auto_fit_after_constraint.x - size_pad.x - 0.0f < size_contents.x && !(window->Flags & ImGuiWindowFlags_NoScrollbar) && (window->Flags & ImGuiWindowFlags_HorizontalScrollbar)) || (window->Flags & ImGuiWindowFlags_AlwaysHorizontalScrollbar); - bool will_have_scrollbar_y = (size_auto_fit_after_constraint.y - size_pad.y - decoration_up_height < size_contents.y && !(window->Flags & ImGuiWindowFlags_NoScrollbar)) || (window->Flags & ImGuiWindowFlags_AlwaysVerticalScrollbar); + bool will_have_scrollbar_x = (size_auto_fit_after_constraint.x - size_pad.x - decoration_w_without_scrollbars < size_contents.x && !(window->Flags & ImGuiWindowFlags_NoScrollbar) && (window->Flags & ImGuiWindowFlags_HorizontalScrollbar)) || (window->Flags & ImGuiWindowFlags_AlwaysHorizontalScrollbar); + bool will_have_scrollbar_y = (size_auto_fit_after_constraint.y - size_pad.y - decoration_h_without_scrollbars < size_contents.y && !(window->Flags & ImGuiWindowFlags_NoScrollbar)) || (window->Flags & ImGuiWindowFlags_AlwaysVerticalScrollbar); if (will_have_scrollbar_x) size_auto_fit.y += style.ScrollbarSize; if (will_have_scrollbar_y) @@ -5897,7 +6040,7 @@ ImGuiID ImGui::GetWindowResizeBorderID(ImGuiWindow* window, ImGuiDir dir) } // Handle resize for: Resize Grips, Borders, Gamepad -// Return true when using auto-fit (double click on resize grip) +// Return true when using auto-fit (double-click on resize grip) static bool ImGui::UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& size_auto_fit, int* border_held, int resize_grip_count, ImU32 resize_grip_col[4], const ImRect& visibility_rect) { ImGuiContext& g = *GImGui; @@ -5905,7 +6048,7 @@ static bool ImGui::UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& s if ((flags & ImGuiWindowFlags_NoResize) || (flags & ImGuiWindowFlags_AlwaysAutoResize) || window->AutoFitFramesX > 0 || window->AutoFitFramesY > 0) return false; - if (window->WasActive == false) // Early out to avoid running this code for e.g. an hidden implicit/fallback Debug window. + if (window->WasActive == false) // Early out to avoid running this code for e.g. a hidden implicit/fallback Debug window. return false; bool ret_auto_fit = false; @@ -5914,6 +6057,11 @@ static bool ImGui::UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& s const float grip_hover_inner_size = IM_FLOOR(grip_draw_size * 0.75f); const float grip_hover_outer_size = g.IO.ConfigWindowsResizeFromEdges ? WINDOWS_HOVER_PADDING : 0.0f; + ImRect clamp_rect = visibility_rect; + const bool window_move_from_title_bar = g.IO.ConfigWindowsMoveFromTitleBarOnly && !(window->Flags & ImGuiWindowFlags_NoTitleBar); + if (window_move_from_title_bar) + clamp_rect.Min.y -= window->TitleBarHeight(); + ImVec2 pos_target(FLT_MAX, FLT_MAX); ImVec2 size_target(FLT_MAX, FLT_MAX); @@ -5943,7 +6091,7 @@ static bool ImGui::UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& s if (resize_rect.Min.x > resize_rect.Max.x) ImSwap(resize_rect.Min.x, resize_rect.Max.x); if (resize_rect.Min.y > resize_rect.Max.y) ImSwap(resize_rect.Min.y, resize_rect.Max.y); ImGuiID resize_grip_id = window->GetID(resize_grip_n); // == GetWindowResizeCornerID() - KeepAliveID(resize_grip_id); + ItemAdd(resize_rect, resize_grip_id, NULL, ImGuiItemFlags_NoNav); ButtonBehavior(resize_rect, resize_grip_id, &hovered, &held, ImGuiButtonFlags_FlattenChildren | ImGuiButtonFlags_NoNavFocus); //GetForegroundDrawList(window)->AddRect(resize_rect.Min, resize_rect.Max, IM_COL32(255, 255, 0, 255)); if (hovered || held) @@ -5960,8 +6108,8 @@ static bool ImGui::UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& s { // Resize from any of the four corners // We don't use an incremental MouseDelta but rather compute an absolute target size based on mouse position - ImVec2 clamp_min = ImVec2(def.CornerPosN.x == 1.0f ? visibility_rect.Min.x : -FLT_MAX, def.CornerPosN.y == 1.0f ? visibility_rect.Min.y : -FLT_MAX); - ImVec2 clamp_max = ImVec2(def.CornerPosN.x == 0.0f ? visibility_rect.Max.x : +FLT_MAX, def.CornerPosN.y == 0.0f ? visibility_rect.Max.y : +FLT_MAX); + ImVec2 clamp_min = ImVec2(def.CornerPosN.x == 1.0f ? clamp_rect.Min.x : -FLT_MAX, (def.CornerPosN.y == 1.0f || (def.CornerPosN.y == 0.0f && window_move_from_title_bar)) ? clamp_rect.Min.y : -FLT_MAX); + ImVec2 clamp_max = ImVec2(def.CornerPosN.x == 0.0f ? clamp_rect.Max.x : +FLT_MAX, def.CornerPosN.y == 0.0f ? clamp_rect.Max.y : +FLT_MAX); ImVec2 corner_target = g.IO.MousePos - g.ActiveIdClickOffset + ImLerp(def.InnerDir * grip_hover_outer_size, def.InnerDir * -grip_hover_inner_size, def.CornerPosN); // Corner of the window corresponding to our corner grip corner_target = ImClamp(corner_target, clamp_min, clamp_max); CalcResizePosSizeFromAnyCorner(window, corner_target, def.CornerPosN, &pos_target, &size_target); @@ -5979,7 +6127,7 @@ static bool ImGui::UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& s bool hovered, held; ImRect border_rect = GetResizeBorderRect(window, border_n, grip_hover_inner_size, WINDOWS_HOVER_PADDING); ImGuiID border_id = window->GetID(border_n + 4); // == GetWindowResizeBorderID() - KeepAliveID(border_id); + ItemAdd(border_rect, border_id, NULL, ImGuiItemFlags_NoNav); ButtonBehavior(border_rect, border_id, &hovered, &held, ImGuiButtonFlags_FlattenChildren | ImGuiButtonFlags_NoNavFocus); //GetForegroundDrawLists(window)->AddRect(border_rect.Min, border_rect.Max, IM_COL32(255, 255, 0, 255)); if ((hovered && g.HoveredIdTimer > WINDOWS_RESIZE_FROM_EDGES_FEEDBACK_TIMER) || held) @@ -5990,8 +6138,8 @@ static bool ImGui::UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& s } if (held) { - ImVec2 clamp_min(border_n == ImGuiDir_Right ? visibility_rect.Min.x : -FLT_MAX, border_n == ImGuiDir_Down ? visibility_rect.Min.y : -FLT_MAX); - ImVec2 clamp_max(border_n == ImGuiDir_Left ? visibility_rect.Max.x : +FLT_MAX, border_n == ImGuiDir_Up ? visibility_rect.Max.y : +FLT_MAX); + ImVec2 clamp_min(border_n == ImGuiDir_Right ? clamp_rect.Min.x : -FLT_MAX, border_n == ImGuiDir_Down || (border_n == ImGuiDir_Up && window_move_from_title_bar) ? clamp_rect.Min.y : -FLT_MAX); + ImVec2 clamp_max(border_n == ImGuiDir_Left ? clamp_rect.Max.x : +FLT_MAX, border_n == ImGuiDir_Up ? clamp_rect.Max.y : +FLT_MAX); ImVec2 border_target = window->Pos; border_target[axis] = g.IO.MousePos[axis] - g.ActiveIdClickOffset[axis] + WINDOWS_HOVER_PADDING; border_target = ImClamp(border_target, clamp_min, clamp_max); @@ -6004,23 +6152,31 @@ static bool ImGui::UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& s window->DC.NavLayerCurrent = ImGuiNavLayer_Main; // Navigation resize (keyboard/gamepad) + // FIXME: This cannot be moved to NavUpdateWindowing() because CalcWindowSizeAfterConstraint() need to callback into user. + // Not even sure the callback works here. if (g.NavWindowingTarget && g.NavWindowingTarget->RootWindowDockTree == window) { - ImVec2 nav_resize_delta; + ImVec2 nav_resize_dir; if (g.NavInputSource == ImGuiInputSource_Keyboard && g.IO.KeyShift) - nav_resize_delta = GetNavInputAmount2d(ImGuiNavDirSourceFlags_RawKeyboard, ImGuiNavReadMode_Down); + nav_resize_dir = GetKeyMagnitude2d(ImGuiKey_LeftArrow, ImGuiKey_RightArrow, ImGuiKey_UpArrow, ImGuiKey_DownArrow); if (g.NavInputSource == ImGuiInputSource_Gamepad) - nav_resize_delta = GetNavInputAmount2d(ImGuiNavDirSourceFlags_PadDPad, ImGuiNavReadMode_Down); - if (nav_resize_delta.x != 0.0f || nav_resize_delta.y != 0.0f) + nav_resize_dir = GetKeyMagnitude2d(ImGuiKey_GamepadDpadLeft, ImGuiKey_GamepadDpadRight, ImGuiKey_GamepadDpadUp, ImGuiKey_GamepadDpadDown); + if (nav_resize_dir.x != 0.0f || nav_resize_dir.y != 0.0f) { const float NAV_RESIZE_SPEED = 600.0f; - nav_resize_delta *= ImFloor(NAV_RESIZE_SPEED * g.IO.DeltaTime * ImMin(g.IO.DisplayFramebufferScale.x, g.IO.DisplayFramebufferScale.y)); - nav_resize_delta = ImMax(nav_resize_delta, visibility_rect.Min - window->Pos - window->Size); + const float resize_step = NAV_RESIZE_SPEED * g.IO.DeltaTime * ImMin(g.IO.DisplayFramebufferScale.x, g.IO.DisplayFramebufferScale.y); + g.NavWindowingAccumDeltaSize += nav_resize_dir * resize_step; + g.NavWindowingAccumDeltaSize = ImMax(g.NavWindowingAccumDeltaSize, clamp_rect.Min - window->Pos - window->Size); // We need Pos+Size >= clmap_rect.Min, so Size >= clmap_rect.Min - Pos, so size_delta >= clmap_rect.Min - window->Pos - window->Size g.NavWindowingToggleLayer = false; g.NavDisableMouseHover = true; resize_grip_col[0] = GetColorU32(ImGuiCol_ResizeGripActive); - // FIXME-NAV: Should store and accumulate into a separate size buffer to handle sizing constraints properly, right now a constraint will make us stuck. - size_target = CalcWindowSizeAfterConstraint(window, window->SizeFull + nav_resize_delta); + ImVec2 accum_floored = ImFloor(g.NavWindowingAccumDeltaSize); + if (accum_floored.x != 0.0f || accum_floored.y != 0.0f) + { + // FIXME-NAV: Should store and accumulate into a separate size buffer to handle sizing constraints properly, right now a constraint will make us stuck. + size_target = CalcWindowSizeAfterConstraint(window, window->SizeFull + accum_floored); + g.NavWindowingAccumDeltaSize -= accum_floored; + } } } @@ -6041,7 +6197,7 @@ static bool ImGui::UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& s return ret_auto_fit; } -static inline void ClampWindowRect(ImGuiWindow* window, const ImRect& visibility_rect) +static inline void ClampWindowPos(ImGuiWindow* window, const ImRect& visibility_rect) { ImGuiContext& g = *GImGui; ImVec2 size_for_clamping = window->Size; @@ -6087,15 +6243,17 @@ void ImGui::RenderWindowDecorations(ImGuiWindow* window, const ImRect& title_bar window->SkipItems = false; // Draw window + handle manual resize - // As we highlight the title bar when want_focus is set, multiple reappearing windows will have have their title bar highlighted on their reappearing frame. + // As we highlight the title bar when want_focus is set, multiple reappearing windows will have their title bar highlighted on their reappearing frame. const float window_rounding = window->WindowRounding; const float window_border_size = window->WindowBorderSize; if (window->Collapsed) { // Title bar only - float backup_border_size = style.FrameBorderSize; + const float backup_border_size = style.FrameBorderSize; g.Style.FrameBorderSize = window->WindowBorderSize; ImU32 title_bar_col = GetColorU32((title_bar_is_highlight && !g.NavDisableHighlight) ? ImGuiCol_TitleBgActive : ImGuiCol_TitleBgCollapsed); + if (window->ViewportOwned) + title_bar_col |= IM_COL32_A_MASK; // No alpha (we don't support is_docking_transparent_payload here because simpler and less meaningful, but could with a bit of code shuffle/reuse) RenderFrame(title_bar_rect.Min, title_bar_rect.Max, title_bar_col, true, window_rounding); g.Style.FrameBorderSize = backup_border_size; } @@ -6112,8 +6270,7 @@ void ImGui::RenderWindowDecorations(ImGuiWindow* window, const ImRect& title_bar ImU32 bg_col = GetColorU32(GetWindowBgColorIdx(window)); if (window->ViewportOwned) { - // No alpha - bg_col = (bg_col | IM_COL32_A_MASK); + bg_col |= IM_COL32_A_MASK; // No alpha if (is_docking_transparent_payload) window->Viewport->Alpha *= DOCKING_TRANSPARENT_PAYLOAD_ALPHA; } @@ -6137,16 +6294,14 @@ void ImGui::RenderWindowDecorations(ImGuiWindow* window, const ImRect& title_bar } // Render, for docked windows and host windows we ensure bg goes before decorations - ImDrawList* bg_draw_list = window->DockIsActive ? window->DockNode->HostWindow->DrawList : window->DrawList; - if (window->DockIsActive || (flags & ImGuiWindowFlags_DockNodeHost)) - bg_draw_list->ChannelsSetCurrent(0); if (window->DockIsActive) window->DockNode->LastBgColor = bg_col; - - bg_draw_list->AddRectFilled(window->Pos + ImVec2(0, window->TitleBarHeight()), window->Pos + window->Size, bg_col, window_rounding, (flags & ImGuiWindowFlags_NoTitleBar) ? 0 : ImDrawFlags_RoundCornersBottom); - + ImDrawList* bg_draw_list = window->DockIsActive ? window->DockNode->HostWindow->DrawList : window->DrawList; if (window->DockIsActive || (flags & ImGuiWindowFlags_DockNodeHost)) - bg_draw_list->ChannelsSetCurrent(1); + bg_draw_list->ChannelsSetCurrent(DOCKING_HOST_DRAW_CHANNEL_BG); + bg_draw_list->AddRectFilled(window->Pos + ImVec2(0, window->TitleBarHeight()), window->Pos + window->Size, bg_col, window_rounding, (flags & ImGuiWindowFlags_NoTitleBar) ? 0 : ImDrawFlags_RoundCornersBottom); + if (window->DockIsActive || (flags & ImGuiWindowFlags_DockNodeHost)) + bg_draw_list->ChannelsSetCurrent(DOCKING_HOST_DRAW_CHANNEL_FG); } if (window->DockIsActive) window->DockNode->IsBgDrawnThisFrame = true; @@ -6178,8 +6333,10 @@ void ImGui::RenderWindowDecorations(ImGuiWindow* window, const ImRect& title_bar float unhide_sz_hit = ImFloor(g.FontSize * 0.55f); ImVec2 p = node->Pos; ImRect r(p, p + ImVec2(unhide_sz_hit, unhide_sz_hit)); + ImGuiID unhide_id = window->GetID("#UNHIDE"); + KeepAliveID(unhide_id); bool hovered, held; - if (ButtonBehavior(r, window->GetID("#UNHIDE"), &hovered, &held, ImGuiButtonFlags_FlattenChildren)) + if (ButtonBehavior(r, unhide_id, &hovered, &held, ImGuiButtonFlags_FlattenChildren)) node->WantHiddenTabBarToggle = true; else if (held && IsMouseDragging(0)) StartMouseMovingWindowOrNode(window, node, true); @@ -6202,12 +6359,15 @@ void ImGui::RenderWindowDecorations(ImGuiWindow* window, const ImRect& title_bar { for (int resize_grip_n = 0; resize_grip_n < resize_grip_count; resize_grip_n++) { + const ImU32 col = resize_grip_col[resize_grip_n]; + if ((col & IM_COL32_A_MASK) == 0) + continue; const ImGuiResizeGripDef& grip = resize_grip_def[resize_grip_n]; const ImVec2 corner = ImLerp(window->Pos, window->Pos + window->Size, grip.CornerPosN); window->DrawList->PathLineTo(corner + grip.InnerDir * ((resize_grip_n & 1) ? ImVec2(window_border_size, resize_grip_draw_size) : ImVec2(resize_grip_draw_size, window_border_size))); window->DrawList->PathLineTo(corner + grip.InnerDir * ((resize_grip_n & 1) ? ImVec2(resize_grip_draw_size, window_border_size) : ImVec2(window_border_size, resize_grip_draw_size))); window->DrawList->PathArcToFast(ImVec2(corner.x + grip.InnerDir.x * (window_rounding + window_border_size), corner.y + grip.InnerDir.y * (window_rounding + window_border_size)), window_rounding, grip.AngleMin12, grip.AngleMax12); - window->DrawList->PathFillConvex(resize_grip_col[resize_grip_n]); + window->DrawList->PathFillConvex(col); } } @@ -6217,8 +6377,8 @@ void ImGui::RenderWindowDecorations(ImGuiWindow* window, const ImRect& title_bar } } -// Render title text, collapse button, close button // When inside a dock node, this is handled in DockNodeCalcTabBarLayout() instead. +// Render title text, collapse button, close button void ImGui::RenderWindowTitleBarContents(ImGuiWindow* window, const ImRect& title_bar_rect, const char* name, bool* p_open) { ImGuiContext& g = *GImGui; @@ -6319,7 +6479,7 @@ void ImGui::UpdateWindowParentAndRootLinks(ImGuiWindow* window, ImGuiWindowFlags } if (parent_window && (flags & ImGuiWindowFlags_Popup)) window->RootWindowPopupTree = parent_window->RootWindowPopupTree; - if (parent_window && !(flags & ImGuiWindowFlags_Modal) && (flags & (ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_Popup))) + if (parent_window && !(flags & ImGuiWindowFlags_Modal) && (flags & (ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_Popup))) // FIXME: simply use _NoTitleBar ? window->RootWindowForTitleBarHighlight = parent_window->RootWindowForTitleBarHighlight; while (window->RootWindowForNav->Flags & ImGuiWindowFlags_NavFlattened) { @@ -6337,7 +6497,10 @@ void ImGui::UpdateWindowParentAndRootLinks(ImGuiWindow* window, ImGuiWindowFlags // - Window // .. returns Modal2 // - Window // .. returns Modal2 // - Modal2 // .. returns Modal2 -static ImGuiWindow* ImGui::FindBlockingModal(ImGuiWindow* window) +// Notes: +// - FindBlockingModal(NULL) == NULL is generally equivalent to GetTopMostPopupModal() == NULL. +// Only difference is here we check for ->Active/WasActive but it may be unecessary. +ImGuiWindow* ImGui::FindBlockingModal(ImGuiWindow* window) { ImGuiContext& g = *GImGui; if (g.OpenPopupStack.Size <= 0) @@ -6351,6 +6514,8 @@ static ImGuiWindow* ImGui::FindBlockingModal(ImGuiWindow* window) continue; if (!popup_window->Active && !popup_window->WasActive) // Check WasActive, because this code may run before popup renders on current frame, also check Active to handle newly created windows. continue; + if (window == NULL) // FindBlockingModal(NULL) test for if FocusWindow(NULL) is naturally possible via a mouse click. + return popup_window; if (IsWindowWithinBeginStackOf(window, popup_window)) // Window is rendered over last modal, no render order change needed. break; for (ImGuiWindow* parent = popup_window->ParentWindowInBeginStack->RootWindow; parent != NULL; parent = parent->ParentWindowInBeginStack->RootWindow) @@ -6380,8 +6545,6 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) const bool window_just_created = (window == NULL); if (window_just_created) window = CreateNewWindow(name, flags); - else - UpdateWindowInFocusOrderList(window, window_just_created, flags); // Automatically disable manual moving/resizing when NoInputs is set if ((flags & ImGuiWindowFlags_NoInputs) == ImGuiWindowFlags_NoInputs) @@ -6407,10 +6570,10 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) const bool window_was_appearing = window->Appearing; if (first_begin_of_the_frame) { + UpdateWindowInFocusOrderList(window, window_just_created, flags); window->Appearing = window_just_activated_by_user; if (window->Appearing) SetWindowConditionAllowFlags(window, ImGuiCond_Appearing, true); - window->FlagsPreviousFrame = window->Flags; window->Flags = (ImGuiWindowFlags)flags; window->LastFrameActive = current_frame; @@ -6458,7 +6621,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) } // Parent window is latched only on the first call to Begin() of the frame, so further append-calls can be done from a different window stack - ImGuiWindow* parent_window_in_stack = window->DockIsActive ? window->DockNode->HostWindow : g.CurrentWindowStack.empty() ? NULL : g.CurrentWindowStack.back().Window; + ImGuiWindow* parent_window_in_stack = (window->DockIsActive && window->DockNode->HostWindow) ? window->DockNode->HostWindow : g.CurrentWindowStack.empty() ? NULL : g.CurrentWindowStack.back().Window; ImGuiWindow* parent_window = first_begin_of_the_frame ? ((flags & (ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_Popup)) ? parent_window_in_stack : NULL) : window->ParentWindow; IM_ASSERT(parent_window != NULL || !(flags & ImGuiWindowFlags_ChildWindow)); @@ -6472,20 +6635,11 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) ImGuiWindowStackData window_stack_data; window_stack_data.Window = window; window_stack_data.ParentLastItemDataBackup = g.LastItemData; - window_stack_data.StackSizesOnBegin.SetToCurrentState(); + window_stack_data.StackSizesOnBegin.SetToContextState(&g); g.CurrentWindowStack.push_back(window_stack_data); - g.CurrentWindow = NULL; if (flags & ImGuiWindowFlags_ChildMenu) g.BeginMenuCount++; - if (flags & ImGuiWindowFlags_Popup) - { - ImGuiPopupData& popup_ref = g.OpenPopupStack[g.BeginPopupStack.Size]; - popup_ref.Window = window; - g.BeginPopupStack.push_back(popup_ref); - window->PopupId = popup_ref.PopupId; - } - // Update ->RootWindow and others pointers (before any possible call to FocusWindow) if (first_begin_of_the_frame) { @@ -6493,6 +6647,21 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) window->ParentWindowInBeginStack = parent_window_in_stack; } + // Add to focus scope stack + PushFocusScope(window->ID); + window->NavRootFocusScopeId = g.CurrentFocusScopeId; + g.CurrentWindow = NULL; + + // Add to popup stack + if (flags & ImGuiWindowFlags_Popup) + { + ImGuiPopupData& popup_ref = g.OpenPopupStack[g.BeginPopupStack.Size]; + popup_ref.Window = window; + popup_ref.ParentNavLayer = parent_window_in_stack->DC.NavLayerCurrent; + g.BeginPopupStack.push_back(popup_ref); + window->PopupId = popup_ref.PopupId; + } + // Process SetNextWindow***() calls // (FIXME: Consider splitting the HasXXX flags into X/Y components bool window_pos_set_by_api = false; @@ -6560,7 +6729,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) if (flags & ImGuiWindowFlags_DockNodeHost) { window->DrawList->ChannelsSplit(2); - window->DrawList->ChannelsSetCurrent(1); // Render decorations on channel 1 as we will render the backgrounds manually later + window->DrawList->ChannelsSetCurrent(DOCKING_HOST_DRAW_CHANNEL_FG); // Render decorations on channel 1 as we will render the backgrounds manually later } // Restore buffer capacity when woken from a compacted state, to avoid @@ -6640,6 +6809,9 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) window->DC.MenuBarOffset.x = ImMax(ImMax(window->WindowPadding.x, style.ItemSpacing.x), g.NextWindowData.MenuBarOffsetMinVal.x); window->DC.MenuBarOffset.y = g.NextWindowData.MenuBarOffsetMinVal.y; + bool use_current_size_for_scrollbar_x = window_just_created; + bool use_current_size_for_scrollbar_y = window_just_created; + // Collapse window by double-clicking on title bar // At this point we don't have a clipping rectangle setup yet, so we can use the title bar area for hit detection and drawing if (!(flags & ImGuiWindowFlags_NoTitleBar) && !(flags & ImGuiWindowFlags_NoCollapse) && !window->DockIsActive) @@ -6651,6 +6823,8 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) if (window->WantCollapseToggle) { window->Collapsed = !window->Collapsed; + if (!window->Collapsed) + use_current_size_for_scrollbar_y = true; MarkIniSettingsDirty(window); } } @@ -6662,10 +6836,17 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) // SIZE + // Outer Decoration Sizes + // (we need to clear ScrollbarSize immediatly as CalcWindowAutoFitSize() needs it and can be called from other locations). + const ImVec2 scrollbar_sizes_from_last_frame = window->ScrollbarSizes; + window->DecoOuterSizeX1 = 0.0f; + window->DecoOuterSizeX2 = 0.0f; + window->DecoOuterSizeY1 = window->TitleBarHeight() + window->MenuBarHeight(); + window->DecoOuterSizeY2 = 0.0f; + window->ScrollbarSizes = ImVec2(0.0f, 0.0f); + // Calculate auto-fit size, handle automatic resize const ImVec2 size_auto_fit = CalcWindowAutoFitSize(window, window->ContentSizeIdeal); - bool use_current_size_for_scrollbar_x = window_just_created; - bool use_current_size_for_scrollbar_y = window_just_created; if ((flags & ImGuiWindowFlags_AlwaysAutoResize) && !window->Collapsed) { // Using SetNextWindowSize() overrides ImGuiWindowFlags_AlwaysAutoResize, so it can be used on tooltips/popups, etc. @@ -6702,9 +6883,6 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) window->SizeFull = CalcWindowSizeAfterConstraint(window, window->SizeFull); window->Size = window->Collapsed && !(flags & ImGuiWindowFlags_ChildWindow) ? window->TitleBarRect().GetSize() : window->SizeFull; - // Decoration size - const float decoration_up_height = window->TitleBarHeight() + window->MenuBarHeight(); - // POSITION // Popup latch its initial position, will position itself when it appears next frame @@ -6736,7 +6914,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) window->Pos = FindBestWindowPosForPopup(window); // Late create viewport if we don't fit within our current host viewport. - if (window->ViewportAllowPlatformMonitorExtend >= 0 && !window->ViewportOwned && !(window->Viewport->Flags & ImGuiViewportFlags_Minimized)) + if (window->ViewportAllowPlatformMonitorExtend >= 0 && !window->ViewportOwned && !(window->Viewport->Flags & ImGuiViewportFlags_IsMinimized)) if (!window->Viewport->GetMainRect().Contains(window->Rect())) { // This is based on the assumption that the DPI will be known ahead (same as the DPI of the selection done in UpdateSelectWindowViewport) @@ -6763,11 +6941,11 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) // Clamp position/size so window stays visible within its viewport or monitor // Ignore zero-sized display explicitly to avoid losing positions if a window manager reports zero-sized window when initializing or minimizing. // FIXME: Similar to code in GetWindowAllowedExtentRect() - if (!window_pos_set_by_api && !(flags & ImGuiWindowFlags_ChildWindow) && window->AutoFitFramesX <= 0 && window->AutoFitFramesY <= 0) + if (!window_pos_set_by_api && !(flags & ImGuiWindowFlags_ChildWindow)) { if (!window->ViewportOwned && viewport_rect.GetWidth() > 0 && viewport_rect.GetHeight() > 0.0f) { - ClampWindowRect(window, visibility_rect); + ClampWindowPos(window, visibility_rect); } else if (window->ViewportOwned && g.PlatformIO.Monitors.Size > 0) { @@ -6775,7 +6953,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) const ImGuiPlatformMonitor* monitor = GetViewportPlatformMonitor(window->Viewport); visibility_rect.Min = monitor->WorkPos + visibility_padding; visibility_rect.Max = monitor->WorkPos + monitor->WorkSize - visibility_padding; - ClampWindowRect(window, visibility_rect); + ClampWindowPos(window, visibility_rect); } } window->Pos = ImFloor(window->Pos); @@ -6799,31 +6977,15 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) want_focus = true; else if ((window->DockIsActive || (flags & ImGuiWindowFlags_ChildWindow) == 0) && !(flags & ImGuiWindowFlags_Tooltip)) want_focus = true; - - ImGuiWindow* modal = GetTopMostPopupModal(); - if (modal != NULL && !IsWindowWithinBeginStackOf(window, modal)) - { - // Avoid focusing a window that is created outside of active modal. This will prevent active modal from being closed. - // Since window is not focused it would reappear at the same display position like the last time it was visible. - // In case of completely new windows it would go to the top (over current modal), but input to such window would still be blocked by modal. - // Position window behind a modal that is not a begin-parent of this window. - want_focus = false; - if (window == window->RootWindow) - { - ImGuiWindow* blocking_modal = FindBlockingModal(window); - IM_ASSERT(blocking_modal != NULL); - BringWindowToDisplayBehind(window, blocking_modal); - } - } } - // [Test Engine] Register whole window in the item system + // [Test Engine] Register whole window in the item system (before submitting further decorations) #ifdef IMGUI_ENABLE_TEST_ENGINE if (g.TestEngineHookItems) { IM_ASSERT(window->IDStack.Size == 1); - window->IDStack.Size = 0; - IMGUI_TEST_ENGINE_ITEM_ADD(window->Rect(), window->ID); + window->IDStack.Size = 0; // As window->IDStack[0] == window->ID here, make sure TestEngine doesn't erroneously see window as parent of itself. + IMGUI_TEST_ENGINE_ITEM_ADD(window->ID, window->Rect(), NULL); IMGUI_TEST_ENGINE_ITEM_INFO(window->ID, window->Name, (g.HoveredWindow == window) ? ImGuiItemStatusFlags_HoveredRect : 0); window->IDStack.Size = 1; } @@ -6862,9 +7024,10 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) if (!window->Collapsed) { // When reading the current size we need to read it after size constraints have been applied. - // When we use InnerRect here we are intentionally reading last frame size, same for ScrollbarSizes values before we set them again. - ImVec2 avail_size_from_current_frame = ImVec2(window->SizeFull.x, window->SizeFull.y - decoration_up_height); - ImVec2 avail_size_from_last_frame = window->InnerRect.GetSize() + window->ScrollbarSizes; + // Intentionally use previous frame values for InnerRect and ScrollbarSizes. + // And when we use window->DecorationUp here it doesn't have ScrollbarSizes.y applied yet. + ImVec2 avail_size_from_current_frame = ImVec2(window->SizeFull.x, window->SizeFull.y - (window->DecoOuterSizeY1 + window->DecoOuterSizeY2)); + ImVec2 avail_size_from_last_frame = window->InnerRect.GetSize() + scrollbar_sizes_from_last_frame; ImVec2 needed_size_from_last_frame = window_just_created ? ImVec2(0, 0) : window->ContentSize + window->WindowPadding * 2.0f; float size_x_for_scrollbars = use_current_size_for_scrollbar_x ? avail_size_from_current_frame.x : avail_size_from_last_frame.x; float size_y_for_scrollbars = use_current_size_for_scrollbar_y ? avail_size_from_current_frame.y : avail_size_from_last_frame.y; @@ -6874,10 +7037,14 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) if (window->ScrollbarX && !window->ScrollbarY) window->ScrollbarY = (needed_size_from_last_frame.y > size_y_for_scrollbars) && !(flags & ImGuiWindowFlags_NoScrollbar); window->ScrollbarSizes = ImVec2(window->ScrollbarY ? style.ScrollbarSize : 0.0f, window->ScrollbarX ? style.ScrollbarSize : 0.0f); + + // Amend the partially filled window->DecorationXXX values. + window->DecoOuterSizeX2 += window->ScrollbarSizes.x; + window->DecoOuterSizeY2 += window->ScrollbarSizes.y; } // UPDATE RECTANGLES (1- THOSE NOT AFFECTED BY SCROLLING) - // Update various regions. Variables they depends on should be set above in this function. + // Update various regions. Variables they depend on should be set above in this function. // We set this up after processing the resize grip so that our rectangles doesn't lag by a frame. // Outer rectangle @@ -6899,10 +7066,10 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) // - ScrollToRectEx() // - NavUpdatePageUpPageDown() // - Scrollbar() - window->InnerRect.Min.x = window->Pos.x; - window->InnerRect.Min.y = window->Pos.y + decoration_up_height; - window->InnerRect.Max.x = window->Pos.x + window->Size.x - window->ScrollbarSizes.x; - window->InnerRect.Max.y = window->Pos.y + window->Size.y - window->ScrollbarSizes.y; + window->InnerRect.Min.x = window->Pos.x + window->DecoOuterSizeX1; + window->InnerRect.Min.y = window->Pos.y + window->DecoOuterSizeY1; + window->InnerRect.Max.x = window->Pos.x + window->Size.x - window->DecoOuterSizeX2; + window->InnerRect.Max.y = window->Pos.y + window->Size.y - window->DecoOuterSizeY2; // Inner clipping rectangle. // Will extend a little bit outside the normal work region. @@ -7003,6 +7170,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) // Apply scrolling window->Scroll = CalcNextScrollFromScrollTargetAndClamp(window); window->ScrollTarget = ImVec2(FLT_MAX, FLT_MAX); + window->DecoInnerSizeX1 = window->DecoInnerSizeY1 = 0.0f; // DRAWING @@ -7024,8 +7192,8 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) // - We disable this when the parent window has zero vertices, which is a common pattern leading to laying out multiple overlapping childs ImGuiWindow* previous_child = parent_window->DC.ChildWindows.Size >= 2 ? parent_window->DC.ChildWindows[parent_window->DC.ChildWindows.Size - 2] : NULL; bool previous_child_overlapping = previous_child ? previous_child->Rect().Overlaps(window->Rect()) : false; - bool parent_is_empty = parent_window->DrawList->VtxBuffer.Size > 0; - if (window->DrawList->CmdBuffer.back().ElemCount == 0 && parent_is_empty && !previous_child_overlapping) + bool parent_is_empty = (parent_window->DrawList->VtxBuffer.Size == 0); + if (window->DrawList->CmdBuffer.back().ElemCount == 0 && !parent_is_empty && !previous_child_overlapping) render_decorations_in_parent = true; } if (render_decorations_in_parent) @@ -7049,8 +7217,8 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) // - BeginTabBar() for right-most edge const bool allow_scrollbar_x = !(flags & ImGuiWindowFlags_NoScrollbar) && (flags & ImGuiWindowFlags_HorizontalScrollbar); const bool allow_scrollbar_y = !(flags & ImGuiWindowFlags_NoScrollbar); - const float work_rect_size_x = (window->ContentSizeExplicit.x != 0.0f ? window->ContentSizeExplicit.x : ImMax(allow_scrollbar_x ? window->ContentSize.x : 0.0f, window->Size.x - window->WindowPadding.x * 2.0f - window->ScrollbarSizes.x)); - const float work_rect_size_y = (window->ContentSizeExplicit.y != 0.0f ? window->ContentSizeExplicit.y : ImMax(allow_scrollbar_y ? window->ContentSize.y : 0.0f, window->Size.y - window->WindowPadding.y * 2.0f - decoration_up_height - window->ScrollbarSizes.y)); + const float work_rect_size_x = (window->ContentSizeExplicit.x != 0.0f ? window->ContentSizeExplicit.x : ImMax(allow_scrollbar_x ? window->ContentSize.x : 0.0f, window->Size.x - window->WindowPadding.x * 2.0f - (window->DecoOuterSizeX1 + window->DecoOuterSizeX2))); + const float work_rect_size_y = (window->ContentSizeExplicit.y != 0.0f ? window->ContentSizeExplicit.y : ImMax(allow_scrollbar_y ? window->ContentSize.y : 0.0f, window->Size.y - window->WindowPadding.y * 2.0f - (window->DecoOuterSizeY1 + window->DecoOuterSizeY2))); window->WorkRect.Min.x = ImFloor(window->InnerRect.Min.x - window->Scroll.x + ImMax(window->WindowPadding.x, window->WindowBorderSize)); window->WorkRect.Min.y = ImFloor(window->InnerRect.Min.y - window->Scroll.y + ImMax(window->WindowPadding.y, window->WindowBorderSize)); window->WorkRect.Max.x = window->WorkRect.Min.x + work_rect_size_x; @@ -7061,21 +7229,21 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) // FIXME-OBSOLETE: window->ContentRegionRect.Max is currently very misleading / partly faulty, but some BeginChild() patterns relies on it. // Used by: // - Mouse wheel scrolling + many other things - window->ContentRegionRect.Min.x = window->Pos.x - window->Scroll.x + window->WindowPadding.x; - window->ContentRegionRect.Min.y = window->Pos.y - window->Scroll.y + window->WindowPadding.y + decoration_up_height; - window->ContentRegionRect.Max.x = window->ContentRegionRect.Min.x + (window->ContentSizeExplicit.x != 0.0f ? window->ContentSizeExplicit.x : (window->Size.x - window->WindowPadding.x * 2.0f - window->ScrollbarSizes.x)); - window->ContentRegionRect.Max.y = window->ContentRegionRect.Min.y + (window->ContentSizeExplicit.y != 0.0f ? window->ContentSizeExplicit.y : (window->Size.y - window->WindowPadding.y * 2.0f - decoration_up_height - window->ScrollbarSizes.y)); + window->ContentRegionRect.Min.x = window->Pos.x - window->Scroll.x + window->WindowPadding.x + window->DecoOuterSizeX1; + window->ContentRegionRect.Min.y = window->Pos.y - window->Scroll.y + window->WindowPadding.y + window->DecoOuterSizeY1; + window->ContentRegionRect.Max.x = window->ContentRegionRect.Min.x + (window->ContentSizeExplicit.x != 0.0f ? window->ContentSizeExplicit.x : (window->Size.x - window->WindowPadding.x * 2.0f - (window->DecoOuterSizeX1 + window->DecoOuterSizeX2))); + window->ContentRegionRect.Max.y = window->ContentRegionRect.Min.y + (window->ContentSizeExplicit.y != 0.0f ? window->ContentSizeExplicit.y : (window->Size.y - window->WindowPadding.y * 2.0f - (window->DecoOuterSizeY1 + window->DecoOuterSizeY2))); // Setup drawing context // (NB: That term "drawing context / DC" lost its meaning a long time ago. Initially was meant to hold transient data only. Nowadays difference between window-> and window->DC-> is dubious.) - window->DC.Indent.x = 0.0f + window->WindowPadding.x - window->Scroll.x; + window->DC.Indent.x = window->DecoOuterSizeX1 + window->WindowPadding.x - window->Scroll.x; window->DC.GroupOffset.x = 0.0f; window->DC.ColumnsOffset.x = 0.0f; // Record the loss of precision of CursorStartPos which can happen due to really large scrolling amount. // This is used by clipper to compensate and fix the most common use case of large scroll area. Easy and cheap, next best thing compared to switching everything to double or ImU64. - double start_pos_highp_x = (double)window->Pos.x + window->WindowPadding.x - (double)window->Scroll.x + window->DC.ColumnsOffset.x; - double start_pos_highp_y = (double)window->Pos.y + window->WindowPadding.y - (double)window->Scroll.y + decoration_up_height; + double start_pos_highp_x = (double)window->Pos.x + window->WindowPadding.x - (double)window->Scroll.x + window->DecoOuterSizeX1 + window->DC.ColumnsOffset.x; + double start_pos_highp_y = (double)window->Pos.y + window->WindowPadding.y - (double)window->Scroll.y + window->DecoOuterSizeY1; window->DC.CursorStartPos = ImVec2((float)start_pos_highp_x, (float)start_pos_highp_y); window->DC.CursorStartPosLossyness = ImVec2((float)(start_pos_highp_x - window->DC.CursorStartPos.x), (float)(start_pos_highp_y - window->DC.CursorStartPos.y)); window->DC.CursorPos = window->DC.CursorStartPos; @@ -7084,12 +7252,14 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) window->DC.IdealMaxPos = window->DC.CursorStartPos; window->DC.CurrLineSize = window->DC.PrevLineSize = ImVec2(0.0f, 0.0f); window->DC.CurrLineTextBaseOffset = window->DC.PrevLineTextBaseOffset = 0.0f; - window->DC.IsSameLine = false; + window->DC.IsSameLine = window->DC.IsSetPos = false; window->DC.NavLayerCurrent = ImGuiNavLayer_Main; window->DC.NavLayersActiveMask = window->DC.NavLayersActiveMaskNext; + window->DC.NavLayersActiveMaskNext = 0x00; + window->DC.NavIsScrollPushableX = true; window->DC.NavHideHighlightOneFrame = false; - window->DC.NavHasScroll = (window->ScrollMax.y > 0.0f); + window->DC.NavWindowHasScrollY = (window->ScrollMax.y > 0.0f); window->DC.MenuBarAppending = false; window->DC.MenuColumns.Update(style.ItemSpacing.x, window_just_activated_by_user); @@ -7112,11 +7282,13 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) window->AutoFitFramesY--; // Apply focus (we need to call FocusWindow() AFTER setting DC.CursorStartPos so our initial navigation reference rectangle can start around there) + // We ImGuiFocusRequestFlags_UnlessBelowModal to: + // - Avoid focusing a window that is created outside of a modal. This will prevent active modal from being closed. + // - Position window behind the modal that is not a begin-parent of this window. if (want_focus) - { - FocusWindow(window); + FocusWindow(window, ImGuiFocusRequestFlags_UnlessBelowModal); + if (want_focus && window == g.NavWindow) NavInitWindow(window, false); // <-- this is in the way for us to be able to defer and sort reappearing FocusWindow() calls - } // Close requested by platform window if (p_open != NULL && window->Viewport->PlatformRequestClose && window->Viewport != GetMainViewport()) @@ -7125,7 +7297,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) { window->Viewport->PlatformRequestClose = false; g.NavWindowingToggleLayer = false; // Assume user mapped PlatformRequestClose on ALT-F4 so we disable ALT for menu toggle. False positive not an issue. - IMGUI_DEBUG_LOG_VIEWPORT("Window '%s' PlatformRequestClose\n", window->Name); + IMGUI_DEBUG_LOG_VIEWPORT("[viewport] Window '%s' PlatformRequestClose\n", window->Name); *p_open = false; } } @@ -7143,7 +7315,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) /* //if (g.NavWindow == window && g.ActiveId == 0) if (g.ActiveId == window->MoveId) - if (g.IO.KeyCtrl && IsKeyPressedMap(ImGuiKey_C)) + if (g.IO.KeyCtrl && IsKeyPressed(ImGuiKey_C)) LogToClipboard(); */ @@ -7169,9 +7341,17 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) else SetLastItemData(window->MoveId, g.CurrentItemFlags, IsMouseHoveringRect(title_bar_rect.Min, title_bar_rect.Max, false) ? ImGuiItemStatusFlags_HoveredRect : 0, title_bar_rect); - // [Test Engine] Register title bar / tab + // [DEBUG] +#ifndef IMGUI_DISABLE_DEBUG_TOOLS + if (g.DebugLocateId != 0 && (window->ID == g.DebugLocateId || window->MoveId == g.DebugLocateId)) + DebugLocateItemResolveWithLastItem(); +#endif + + // [Test Engine] Register title bar / tab with MoveId. +#ifdef IMGUI_ENABLE_TEST_ENGINE if (!(window->Flags & ImGuiWindowFlags_NoTitleBar)) - IMGUI_TEST_ENGINE_ITEM_ADD(g.LastItemData.Rect, g.LastItemData.ID); + IMGUI_TEST_ENGINE_ITEM_ADD(g.LastItemData.ID, g.LastItemData.Rect, &g.LastItemData); +#endif } else { @@ -7180,9 +7360,6 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) SetCurrentWindow(window); } - // Pull/inherit current state - window->DC.NavFocusScopeIdCurrent = (flags & ImGuiWindowFlags_ChildWindow) ? parent_window->DC.NavFocusScopeIdCurrent : window->GetID("#FOCUSSCOPE"); // Inherit from parent only // -V595 - if (!(flags & ImGuiWindowFlags_DockNodeHost)) PushClipRect(window->InnerClipRect.Min, window->InnerClipRect.Max, true); @@ -7248,9 +7425,9 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) skip_items = true; window->SkipItems = skip_items; - // Only clear NavLayersActiveMaskNext when marked as visible, so a CTRL+Tab back can use a safe value. - if (!window->SkipItems) - window->DC.NavLayersActiveMaskNext = 0x00; + // Restore NavLayersActiveMaskNext to previous value when not visible, so a CTRL+Tab back can use a safe value. + if (window->SkipItems) + window->DC.NavLayersActiveMaskNext = window->DC.NavLayersActiveMask; // Sanity check: there are two spots which can set Appearing = true // - when 'window_just_activated_by_user' is set -> HiddenFramesCannotSkipItems is set -> SkipItems always false @@ -7259,6 +7436,15 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) IM_ASSERT(window->Appearing == false); // Please report on GitHub if this triggers: https://github.com/ocornut/imgui/issues/4177 } + // [DEBUG] io.ConfigDebugBeginReturnValue override return value to test Begin/End and BeginChild/EndChild behaviors. + // (The implicit fallback window is NOT automatically ended allowing it to always be able to receive commands without crashing) + if (!window->IsFallbackWindow && ((g.IO.ConfigDebugBeginReturnValueOnce && window_just_created) || (g.IO.ConfigDebugBeginReturnValueLoop && g.DebugBeginReturnValueCullDepth == g.CurrentWindowStack.Size))) + { + if (window->AutoFitFramesX > 0) { window->AutoFitFramesX++; } + if (window->AutoFitFramesY > 0) { window->AutoFitFramesY++; } + return false; + } + return !window->SkipItems; } @@ -7284,11 +7470,15 @@ void ImGui::End() EndColumns(); if (!(window->Flags & ImGuiWindowFlags_DockNodeHost)) // Pop inner window clip rectangle PopClipRect(); + PopFocusScope(); // Stop logging if (!(window->Flags & ImGuiWindowFlags_ChildWindow)) // FIXME: add more options for scope of logging LogFinish(); + if (window->DC.IsSetPos) + ErrorCheckUsingSetCursorPosToExtendParentBoundaries(); + // Docking: report contents sizes to parent to allow for auto-resize if (window->DockNode && window->DockTabIsVisible) if (ImGuiWindow* host_window = window->DockNode->HostWindow) // FIXME-DOCK @@ -7300,7 +7490,7 @@ void ImGui::End() g.BeginMenuCount--; if (window->Flags & ImGuiWindowFlags_Popup) g.BeginPopupStack.pop_back(); - g.CurrentWindowStack.back().StackSizesOnBegin.CompareWithCurrentState(); + g.CurrentWindowStack.back().StackSizesOnBegin.CompareWithContextState(&g); g.CurrentWindowStack.pop_back(); SetCurrentWindow(g.CurrentWindowStack.Size == 0 ? NULL : g.CurrentWindowStack.back().Window); if (g.CurrentWindow) @@ -7386,26 +7576,38 @@ int ImGui::FindWindowDisplayIndex(ImGuiWindow* window) } // Moving window to front of display and set focus (which happens to be back of our sorted list) -void ImGui::FocusWindow(ImGuiWindow* window) +void ImGui::FocusWindow(ImGuiWindow* window, ImGuiFocusRequestFlags flags) { ImGuiContext& g = *GImGui; + // Modal check? + if ((flags & ImGuiFocusRequestFlags_UnlessBelowModal) && (g.NavWindow != window)) // Early out in common case. + if (ImGuiWindow* blocking_modal = FindBlockingModal(window)) + { + IMGUI_DEBUG_LOG_FOCUS("[focus] FocusWindow(\"%s\", UnlessBelowModal): prevented by \"%s\".\n", window ? window->Name : "", blocking_modal->Name); + if (window && window == window->RootWindow && (window->Flags & ImGuiWindowFlags_NoBringToFrontOnFocus) == 0) + BringWindowToDisplayBehind(window, blocking_modal); // Still bring to right below modal. + return; + } + + // Find last focused child (if any) and focus it instead. + if ((flags & ImGuiFocusRequestFlags_RestoreFocusedChild) && window != NULL) + window = NavRestoreLastChildNavWindow(window); + + // Apply focus if (g.NavWindow != window) { - g.NavWindow = window; + SetNavWindow(window); if (window && g.NavDisableMouseHover) g.NavMousePosDirty = true; g.NavId = window ? window->NavLastIds[0] : 0; // Restore NavId - g.NavFocusScopeId = 0; - g.NavIdIsAlive = false; g.NavLayer = ImGuiNavLayer_Main; - g.NavInitRequest = g.NavMoveSubmitted = g.NavMoveScoringItems = false; - NavUpdateAnyRequestFlag(); - //IMGUI_DEBUG_LOG("FocusWindow(\"%s\")\n", window ? window->Name : NULL); - } + g.NavFocusScopeId = window ? window->NavRootFocusScopeId : 0; + g.NavIdIsAlive = false; - // Close popups if any - ClosePopupsOverWindow(window, false); + // Close popups if any + ClosePopupsOverWindow(window, false); + } // Move the root window to the top of the pile IM_ASSERT(window == NULL || window->RootWindowDockTree != NULL); @@ -7437,7 +7639,7 @@ void ImGui::FocusWindow(ImGuiWindow* window) BringWindowToDisplayFront(display_front_window); } -void ImGui::FocusTopMostWindowUnderOne(ImGuiWindow* under_this_window, ImGuiWindow* ignore_window) +void ImGui::FocusTopMostWindowUnderOne(ImGuiWindow* under_this_window, ImGuiWindow* ignore_window, ImGuiViewport* filter_viewport, ImGuiFocusRequestFlags flags) { ImGuiContext& g = *GImGui; int start_idx = g.WindowsFocusOrder.Size - 1; @@ -7457,19 +7659,22 @@ void ImGui::FocusTopMostWindowUnderOne(ImGuiWindow* under_this_window, ImGuiWind // We may later decide to test for different NoXXXInputs based on the active navigation input (mouse vs nav) but that may feel more confusing to the user. ImGuiWindow* window = g.WindowsFocusOrder[i]; IM_ASSERT(window == window->RootWindow); - if (window != ignore_window && window->WasActive) - if ((window->Flags & (ImGuiWindowFlags_NoMouseInputs | ImGuiWindowFlags_NoNavInputs)) != (ImGuiWindowFlags_NoMouseInputs | ImGuiWindowFlags_NoNavInputs)) - { - // FIXME-DOCK: This is failing (lagging by one frame) for docked windows. - // If A and B are docked into window and B disappear, at the NewFrame() call site window->NavLastChildNavWindow will still point to B. - // We might leverage the tab order implicitly stored in window->DockNodeAsHost->TabBar (essentially the 'most_recently_selected_tab' code in tab bar will do that but on next update) - // to tell which is the "previous" window. Or we may leverage 'LastFrameFocused/LastFrameJustFocused' and have this function handle child window itself? - ImGuiWindow* focus_window = NavRestoreLastChildNavWindow(window); - FocusWindow(focus_window); - return; - } + if (window == ignore_window || !window->WasActive) + continue; + if (filter_viewport != NULL && window->Viewport != filter_viewport) + continue; + if ((window->Flags & (ImGuiWindowFlags_NoMouseInputs | ImGuiWindowFlags_NoNavInputs)) != (ImGuiWindowFlags_NoMouseInputs | ImGuiWindowFlags_NoNavInputs)) + { + // FIXME-DOCK: When ImGuiFocusRequestFlags_RestoreFocusedChild is set... + // This is failing (lagging by one frame) for docked windows. + // If A and B are docked into window and B disappear, at the NewFrame() call site window->NavLastChildNavWindow will still point to B. + // We might leverage the tab order implicitly stored in window->DockNodeAsHost->TabBar (essentially the 'most_recently_selected_tab' code in tab bar will do that but on next update) + // to tell which is the "previous" window. Or we may leverage 'LastFrameFocused/LastFrameJustFocused' and have this function handle child window itself? + FocusWindow(window, flags); + return; + } } - FocusWindow(NULL); + FocusWindow(NULL, flags); } // Important: this alone doesn't alter current ImDrawList state. This is called by PushFont/PopFont only. @@ -7591,13 +7796,12 @@ void ImGui::InhibitInertialScroll() g.InertialScrollInhibited=true; } -// FIXME: Look into renaming this once we have settled the new Focus/Activation/TabStop system. -void ImGui::PushAllowKeyboardFocus(bool allow_keyboard_focus) +void ImGui::PushTabStop(bool tab_stop) { - PushItemFlag(ImGuiItemFlags_NoTabStop, !allow_keyboard_focus); + PushItemFlag(ImGuiItemFlags_NoTabStop, !tab_stop); } -void ImGui::PopAllowKeyboardFocus() +void ImGui::PopTabStop() { PopItemFlag(); } @@ -7800,6 +8004,9 @@ void ImGui::SetWindowPos(ImGuiWindow* window, const ImVec2& pos, ImGuiCond cond) const ImVec2 old_pos = window->Pos; window->Pos = ImFloor(pos); ImVec2 offset = window->Pos - old_pos; + if (offset.x == 0.0f && offset.y == 0.0f) + return; + MarkIniSettingsDirty(window); // FIXME: share code with TranslateWindow(), need to confirm whether the 3 rect modified by TranslateWindow() are desirable here. window->DC.CursorPos += offset; // As we happen to move the window while it is being appended to (which is a bad idea - will smear) let's at least offset the cursor window->DC.CursorMaxPos += offset; // And more importantly we need to offset CursorMaxPos/CursorStartPos this so ContentSize calculation doesn't get affected. @@ -7835,26 +8042,19 @@ void ImGui::SetWindowSize(ImGuiWindow* window, const ImVec2& size, ImGuiCond con window->SetWindowSizeAllowFlags &= ~(ImGuiCond_Once | ImGuiCond_FirstUseEver | ImGuiCond_Appearing); // Set - if (size.x > 0.0f) - { - window->AutoFitFramesX = 0; + ImVec2 old_size = window->SizeFull; + window->AutoFitFramesX = (size.x <= 0.0f) ? 2 : 0; + window->AutoFitFramesY = (size.y <= 0.0f) ? 2 : 0; + if (size.x <= 0.0f) + window->AutoFitOnlyGrows = false; + else window->SizeFull.x = IM_FLOOR(size.x); - } - else - { - window->AutoFitFramesX = 2; + if (size.y <= 0.0f) window->AutoFitOnlyGrows = false; - } - if (size.y > 0.0f) - { - window->AutoFitFramesY = 0; + else window->SizeFull.y = IM_FLOOR(size.y); - } - else - { - window->AutoFitFramesY = 2; - window->AutoFitOnlyGrows = false; - } + if (old_size.x != window->SizeFull.x || old_size.y != window->SizeFull.y) + MarkIniSettingsDirty(window); } void ImGui::SetWindowSize(const ImVec2& size, ImGuiCond cond) @@ -7886,6 +8086,12 @@ void ImGui::SetWindowHitTestHole(ImGuiWindow* window, const ImVec2& pos, const I window->HitTestHoleOffset = ImVec2ih(pos - window->Pos); } +void ImGui::SetWindowHiddendAndSkipItemsForCurrentFrame(ImGuiWindow* window) +{ + window->Hidden = window->SkipItems = true; + window->HiddenFramesCanSkipItems = 1; +} + void ImGui::SetWindowCollapsed(bool collapsed, ImGuiCond cond) { SetWindowCollapsed(GImGui->CurrentWindow, collapsed, cond); @@ -8070,26 +8276,38 @@ void ImGui::ActivateItem(ImGuiID id) void ImGui::PushFocusScope(ImGuiID id) { ImGuiContext& g = *GImGui; - ImGuiWindow* window = g.CurrentWindow; - g.FocusScopeStack.push_back(window->DC.NavFocusScopeIdCurrent); - window->DC.NavFocusScopeIdCurrent = id; + g.FocusScopeStack.push_back(id); + g.CurrentFocusScopeId = id; } void ImGui::PopFocusScope() { ImGuiContext& g = *GImGui; - ImGuiWindow* window = g.CurrentWindow; IM_ASSERT(g.FocusScopeStack.Size > 0); // Too many PopFocusScope() ? - window->DC.NavFocusScopeIdCurrent = g.FocusScopeStack.back(); g.FocusScopeStack.pop_back(); + g.CurrentFocusScopeId = g.FocusScopeStack.Size ? g.FocusScopeStack.back() : 0; } +// Note: this will likely be called ActivateItem() once we rework our Focus/Activation system! void ImGui::SetKeyboardFocusHere(int offset) { ImGuiContext& g = *GImGui; ImGuiWindow* window = g.CurrentWindow; IM_ASSERT(offset >= -1); // -1 is allowed but not below - g.NavWindow = window; + IMGUI_DEBUG_LOG_ACTIVEID("SetKeyboardFocusHere(%d) in window \"%s\"\n", offset, window->Name); + + // It makes sense in the vast majority of cases to never interrupt a drag and drop. + // When we refactor this function into ActivateItem() we may want to make this an option. + // MovingWindow is protected from most user inputs using SetActiveIdUsingNavAndKeys(), but + // is also automatically dropped in the event g.ActiveId is stolen. + if (g.DragDropActive || g.MovingWindow != NULL) + { + IMGUI_DEBUG_LOG_ACTIVEID("SetKeyboardFocusHere() ignored while DragDropActive!\n"); + return; + } + + SetNavWindow(window); + ImGuiScrollFlags scroll_flags = window->Appearing ? ImGuiScrollFlags_KeepVisibleEdgeX | ImGuiScrollFlags_AlwaysCenterY : ImGuiScrollFlags_KeepVisibleEdgeX | ImGuiScrollFlags_KeepVisibleEdgeY; NavMoveRequestSubmit(ImGuiDir_None, offset < 0 ? ImGuiDir_Up : ImGuiDir_Down, ImGuiNavMoveFlags_Tabbing | ImGuiNavMoveFlags_FocusApi, scroll_flags); // FIXME-NAV: Once we refactor tabbing, add LegacyApi flag to not activate non-inputable. if (offset == -1) @@ -8109,16 +8327,15 @@ void ImGui::SetItemDefaultFocus() ImGuiWindow* window = g.CurrentWindow; if (!window->Appearing) return; - if (g.NavWindow != window->RootWindowForNav || (!g.NavInitRequest && g.NavInitResultId == 0) || g.NavLayer != window->DC.NavLayerCurrent) + if (g.NavWindow != window->RootWindowForNav || (!g.NavInitRequest && g.NavInitResult.ID == 0) || g.NavLayer != window->DC.NavLayerCurrent) return; g.NavInitRequest = false; - g.NavInitResultId = g.LastItemData.ID; - g.NavInitResultRectRel = WindowRectAbsToRel(window, g.LastItemData.Rect); + NavApplyItemToResult(&g.NavInitResult); NavUpdateAnyRequestFlag(); - // Scroll could be done in NavInitRequestApplyResult() via a opt-in flag (we however don't want regular init requests to scroll) - if (!IsItemVisible()) + // Scroll could be done in NavInitRequestApplyResult() via an opt-in flag (we however don't want regular init requests to scroll) + if (!window->ClipRect.Contains(g.LastItemData.Rect)) ScrollToRectEx(window, g.LastItemData.Rect, ImGuiScrollFlags_None); } @@ -8182,13 +8399,21 @@ void ImGui::PushOverrideID(ImGuiID id) ImGuiID ImGui::GetIDWithSeed(const char* str, const char* str_end, ImGuiID seed) { ImGuiID id = ImHashStr(str, str_end ? (str_end - str) : 0, seed); - KeepAliveID(id); ImGuiContext& g = *GImGui; if (g.DebugHookIdInfo == id) DebugHookIdInfo(id, ImGuiDataType_String, str, str_end); return id; } +ImGuiID ImGui::GetIDWithSeed(int n, ImGuiID seed) +{ + ImGuiID id = ImHashData(&n, sizeof(n), seed); + ImGuiContext& g = *GImGui; + if (g.DebugHookIdInfo == id) + DebugHookIdInfo(id, ImGuiDataType_S32, (void*)(intptr_t)n, NULL); + return id; +} + void ImGui::PopID() { ImGuiWindow* window = GImGui->CurrentWindow; @@ -8230,52 +8455,91 @@ bool ImGui::IsRectVisible(const ImVec2& rect_min, const ImVec2& rect_max) //----------------------------------------------------------------------------- // [SECTION] INPUTS //----------------------------------------------------------------------------- +// - GetKeyData() [Internal] +// - GetKeyIndex() [Internal] +// - GetKeyName() +// - GetKeyChordName() [Internal] +// - CalcTypematicRepeatAmount() [Internal] +// - GetTypematicRepeatRate() [Internal] +// - GetKeyPressedAmount() [Internal] +// - GetKeyMagnitude2d() [Internal] +//----------------------------------------------------------------------------- +// - UpdateKeyRoutingTable() [Internal] +// - GetRoutingIdFromOwnerId() [Internal] +// - GetShortcutRoutingData() [Internal] +// - CalcRoutingScore() [Internal] +// - SetShortcutRouting() [Internal] +// - TestShortcutRouting() [Internal] +//----------------------------------------------------------------------------- +// - IsKeyDown() +// - IsKeyPressed() +// - IsKeyReleased() +//----------------------------------------------------------------------------- +// - IsMouseDown() +// - IsMouseClicked() +// - IsMouseReleased() +// - IsMouseDoubleClicked() +// - GetMouseClickedCount() +// - IsMouseHoveringRect() [Internal] +// - IsMouseDragPastThreshold() [Internal] +// - IsMouseDragging() +// - GetMousePos() +// - GetMousePosOnOpeningCurrentPopup() +// - IsMousePosValid() +// - IsAnyMouseDown() +// - GetMouseDragDelta() +// - ResetMouseDragDelta() +// - GetMouseCursor() +// - SetMouseCursor() +//----------------------------------------------------------------------------- +// - UpdateAliasKey() +// - GetMergedModsFromKeys() +// - UpdateKeyboardInputs() +// - UpdateMouseInputs() +//----------------------------------------------------------------------------- +// - LockWheelingWindow [Internal] +// - FindBestWheelingWindow [Internal] +// - UpdateMouseWheel() [Internal] +//----------------------------------------------------------------------------- +// - SetNextFrameWantCaptureKeyboard() +// - SetNextFrameWantCaptureMouse() +//----------------------------------------------------------------------------- +// - GetInputSourceName() [Internal] +// - DebugPrintInputEvent() [Internal] +// - UpdateInputEvents() [Internal] +//----------------------------------------------------------------------------- +// - GetKeyOwner() [Internal] +// - TestKeyOwner() [Internal] +// - SetKeyOwner() [Internal] +// - SetItemKeyOwner() [Internal] +// - Shortcut() [Internal] +//----------------------------------------------------------------------------- -// Test if mouse cursor is hovering given rectangle -// NB- Rectangle is clipped by our current clip setting -// NB- Expand the rectangle to be generous on imprecise inputs systems (g.Style.TouchExtraPadding) -bool ImGui::IsMouseHoveringRect(const ImVec2& r_min, const ImVec2& r_max, bool clip) +ImGuiKeyData* ImGui::GetKeyData(ImGuiContext* ctx, ImGuiKey key) { - ImGuiContext& g = *GImGui; + ImGuiContext& g = *ctx; - // Clip - ImRect rect_clipped(r_min, r_max); - if (clip) - rect_clipped.ClipWith(g.CurrentWindow->ClipRect); + // Special storage location for mods + if (key & ImGuiMod_Mask_) + key = ConvertSingleModFlagToKey(ctx, key); - // Expand for touch input - const ImRect rect_for_touch(rect_clipped.Min - g.Style.TouchExtraPadding, rect_clipped.Max + g.Style.TouchExtraPadding); - if (!rect_for_touch.Contains(g.IO.MousePos)) - return false; - if (!g.MouseViewport->GetMainRect().Overlaps(rect_clipped)) - return false; - return true; -} - -ImGuiKeyData* ImGui::GetKeyData(ImGuiKey key) -{ - ImGuiContext& g = *GImGui; - int index; #ifndef IMGUI_DISABLE_OBSOLETE_KEYIO IM_ASSERT(key >= ImGuiKey_LegacyNativeKey_BEGIN && key < ImGuiKey_NamedKey_END); - if (IsLegacyKey(key)) - index = (g.IO.KeyMap[key] != -1) ? g.IO.KeyMap[key] : key; // Remap native->imgui or imgui->native - else - index = key; + if (IsLegacyKey(key) && g.IO.KeyMap[key] != -1) + key = (ImGuiKey)g.IO.KeyMap[key]; // Remap native->imgui or imgui->native #else IM_ASSERT(IsNamedKey(key) && "Support for user key indices was dropped in favor of ImGuiKey. Please update backend & user code."); - index = key - ImGuiKey_NamedKey_BEGIN; #endif - return &g.IO.KeysData[index]; + return &g.IO.KeysData[key - ImGuiKey_KeysData_OFFSET]; } #ifndef IMGUI_DISABLE_OBSOLETE_KEYIO -int ImGui::GetKeyIndex(ImGuiKey key) +ImGuiKey ImGui::GetKeyIndex(ImGuiKey key) { ImGuiContext& g = *GImGui; IM_ASSERT(IsNamedKey(key)); const ImGuiKeyData* key_data = GetKeyData(key); - return (int)(key_data - g.IO.KeysData); + return (ImGuiKey)(key_data - g.IO.KeysData); } #endif @@ -8293,37 +8557,55 @@ static const char* const GKeyNames[] = "Pause", "Keypad0", "Keypad1", "Keypad2", "Keypad3", "Keypad4", "Keypad5", "Keypad6", "Keypad7", "Keypad8", "Keypad9", "KeypadDecimal", "KeypadDivide", "KeypadMultiply", "KeypadSubtract", "KeypadAdd", "KeypadEnter", "KeypadEqual", - "GamepadStart", "GamepadBack", "GamepadFaceUp", "GamepadFaceDown", "GamepadFaceLeft", "GamepadFaceRight", - "GamepadDpadUp", "GamepadDpadDown", "GamepadDpadLeft", "GamepadDpadRight", + "GamepadStart", "GamepadBack", + "GamepadFaceLeft", "GamepadFaceRight", "GamepadFaceUp", "GamepadFaceDown", + "GamepadDpadLeft", "GamepadDpadRight", "GamepadDpadUp", "GamepadDpadDown", "GamepadL1", "GamepadR1", "GamepadL2", "GamepadR2", "GamepadL3", "GamepadR3", - "GamepadLStickUp", "GamepadLStickDown", "GamepadLStickLeft", "GamepadLStickRight", - "GamepadRStickUp", "GamepadRStickDown", "GamepadRStickLeft", "GamepadRStickRight", - "ModCtrl", "ModShift", "ModAlt", "ModSuper" + "GamepadLStickLeft", "GamepadLStickRight", "GamepadLStickUp", "GamepadLStickDown", + "GamepadRStickLeft", "GamepadRStickRight", "GamepadRStickUp", "GamepadRStickDown", + "MouseLeft", "MouseRight", "MouseMiddle", "MouseX1", "MouseX2", "MouseWheelX", "MouseWheelY", + "ModCtrl", "ModShift", "ModAlt", "ModSuper", // ReservedForModXXX are showing the ModXXX names. }; IM_STATIC_ASSERT(ImGuiKey_NamedKey_COUNT == IM_ARRAYSIZE(GKeyNames)); const char* ImGui::GetKeyName(ImGuiKey key) { + ImGuiContext& g = *GImGui; #ifdef IMGUI_DISABLE_OBSOLETE_KEYIO IM_ASSERT((IsNamedKey(key) || key == ImGuiKey_None) && "Support for user key indices was dropped in favor of ImGuiKey. Please update backend and user code."); #else if (IsLegacyKey(key)) { - ImGuiIO& io = GetIO(); - if (io.KeyMap[key] == -1) + if (g.IO.KeyMap[key] == -1) return "N/A"; - IM_ASSERT(IsNamedKey((ImGuiKey)io.KeyMap[key])); - key = (ImGuiKey)io.KeyMap[key]; + IM_ASSERT(IsNamedKey((ImGuiKey)g.IO.KeyMap[key])); + key = (ImGuiKey)g.IO.KeyMap[key]; } #endif if (key == ImGuiKey_None) return "None"; + if (key & ImGuiMod_Mask_) + key = ConvertSingleModFlagToKey(&g, key); if (!IsNamedKey(key)) return "Unknown"; return GKeyNames[key - ImGuiKey_NamedKey_BEGIN]; } +// ImGuiMod_Shortcut is translated to either Ctrl or Super. +void ImGui::GetKeyChordName(ImGuiKeyChord key_chord, char* out_buf, int out_buf_size) +{ + ImGuiContext& g = *GImGui; + if (key_chord & ImGuiMod_Shortcut) + key_chord = ConvertShortcutMod(key_chord); + ImFormatString(out_buf, (size_t)out_buf_size, "%s%s%s%s%s", + (key_chord & ImGuiMod_Ctrl) ? "Ctrl+" : "", + (key_chord & ImGuiMod_Shift) ? "Shift+" : "", + (key_chord & ImGuiMod_Alt) ? "Alt+" : "", + (key_chord & ImGuiMod_Super) ? (g.IO.ConfigMacOSXBehaviors ? "Cmd+" : "Super+") : "", + GetKeyName((ImGuiKey)(key_chord & ~ImGuiMod_Mask_))); +} + // t0 = previous time (e.g.: g.Time - g.IO.DeltaTime) // t1 = current time (e.g.: g.Time) // An event is triggered at: @@ -8342,42 +8624,276 @@ int ImGui::CalcTypematicRepeatAmount(float t0, float t1, float repeat_delay, flo return count; } +void ImGui::GetTypematicRepeatRate(ImGuiInputFlags flags, float* repeat_delay, float* repeat_rate) +{ + ImGuiContext& g = *GImGui; + switch (flags & ImGuiInputFlags_RepeatRateMask_) + { + case ImGuiInputFlags_RepeatRateNavMove: *repeat_delay = g.IO.KeyRepeatDelay * 0.72f; *repeat_rate = g.IO.KeyRepeatRate * 0.80f; return; + case ImGuiInputFlags_RepeatRateNavTweak: *repeat_delay = g.IO.KeyRepeatDelay * 0.72f; *repeat_rate = g.IO.KeyRepeatRate * 0.30f; return; + case ImGuiInputFlags_RepeatRateDefault: default: *repeat_delay = g.IO.KeyRepeatDelay * 1.00f; *repeat_rate = g.IO.KeyRepeatRate * 1.00f; return; + } +} + +// Return value representing the number of presses in the last time period, for the given repeat rate +// (most often returns 0 or 1. The result is generally only >1 when RepeatRate is smaller than DeltaTime, aka large DeltaTime or fast RepeatRate) int ImGui::GetKeyPressedAmount(ImGuiKey key, float repeat_delay, float repeat_rate) { ImGuiContext& g = *GImGui; const ImGuiKeyData* key_data = GetKeyData(key); + if (!key_data->Down) // In theory this should already be encoded as (DownDuration < 0.0f), but testing this facilitates eating mechanism (until we finish work on key ownership) + return 0; const float t = key_data->DownDuration; return CalcTypematicRepeatAmount(t - g.IO.DeltaTime, t, repeat_delay, repeat_rate); } +// Return 2D vector representing the combination of four cardinal direction, with analog value support (for e.g. ImGuiKey_GamepadLStick* values). +ImVec2 ImGui::GetKeyMagnitude2d(ImGuiKey key_left, ImGuiKey key_right, ImGuiKey key_up, ImGuiKey key_down) +{ + return ImVec2( + GetKeyData(key_right)->AnalogValue - GetKeyData(key_left)->AnalogValue, + GetKeyData(key_down)->AnalogValue - GetKeyData(key_up)->AnalogValue); +} + +// Rewrite routing data buffers to strip old entries + sort by key to make queries not touch scattered data. +// Entries D,A,B,B,A,C,B --> A,A,B,B,B,C,D +// Index A:1 B:2 C:5 D:0 --> A:0 B:2 C:5 D:6 +// See 'Metrics->Key Owners & Shortcut Routing' to visualize the result of that operation. +static void ImGui::UpdateKeyRoutingTable(ImGuiKeyRoutingTable* rt) +{ + ImGuiContext& g = *GImGui; + rt->EntriesNext.resize(0); + for (ImGuiKey key = ImGuiKey_NamedKey_BEGIN; key < ImGuiKey_NamedKey_END; key = (ImGuiKey)(key + 1)) + { + const int new_routing_start_idx = rt->EntriesNext.Size; + ImGuiKeyRoutingData* routing_entry; + for (int old_routing_idx = rt->Index[key - ImGuiKey_NamedKey_BEGIN]; old_routing_idx != -1; old_routing_idx = routing_entry->NextEntryIndex) + { + routing_entry = &rt->Entries[old_routing_idx]; + routing_entry->RoutingCurr = routing_entry->RoutingNext; // Update entry + routing_entry->RoutingNext = ImGuiKeyOwner_None; + routing_entry->RoutingNextScore = 255; + if (routing_entry->RoutingCurr == ImGuiKeyOwner_None) + continue; + rt->EntriesNext.push_back(*routing_entry); // Write alive ones into new buffer + + // Apply routing to owner if there's no owner already (RoutingCurr == None at this point) + if (routing_entry->Mods == g.IO.KeyMods) + { + ImGuiKeyOwnerData* owner_data = GetKeyOwnerData(&g, key); + if (owner_data->OwnerCurr == ImGuiKeyOwner_None) + owner_data->OwnerCurr = routing_entry->RoutingCurr; + } + } + + // Rewrite linked-list + rt->Index[key - ImGuiKey_NamedKey_BEGIN] = (ImGuiKeyRoutingIndex)(new_routing_start_idx < rt->EntriesNext.Size ? new_routing_start_idx : -1); + for (int n = new_routing_start_idx; n < rt->EntriesNext.Size; n++) + rt->EntriesNext[n].NextEntryIndex = (ImGuiKeyRoutingIndex)((n + 1 < rt->EntriesNext.Size) ? n + 1 : -1); + } + rt->Entries.swap(rt->EntriesNext); // Swap new and old indexes +} + +// owner_id may be None/Any, but routing_id needs to be always be set, so we default to GetCurrentFocusScope(). +static inline ImGuiID GetRoutingIdFromOwnerId(ImGuiID owner_id) +{ + ImGuiContext& g = *GImGui; + return (owner_id != ImGuiKeyOwner_None && owner_id != ImGuiKeyOwner_Any) ? owner_id : g.CurrentFocusScopeId; +} + +ImGuiKeyRoutingData* ImGui::GetShortcutRoutingData(ImGuiKeyChord key_chord) +{ + // Majority of shortcuts will be Key + any number of Mods + // We accept _Single_ mod with ImGuiKey_None. + // - Shortcut(ImGuiKey_S | ImGuiMod_Ctrl); // Legal + // - Shortcut(ImGuiKey_S | ImGuiMod_Ctrl | ImGuiMod_Shift); // Legal + // - Shortcut(ImGuiMod_Ctrl); // Legal + // - Shortcut(ImGuiMod_Ctrl | ImGuiMod_Shift); // Not legal + ImGuiContext& g = *GImGui; + ImGuiKeyRoutingTable* rt = &g.KeysRoutingTable; + ImGuiKeyRoutingData* routing_data; + if (key_chord & ImGuiMod_Shortcut) + key_chord = ConvertShortcutMod(key_chord); + ImGuiKey key = (ImGuiKey)(key_chord & ~ImGuiMod_Mask_); + ImGuiKey mods = (ImGuiKey)(key_chord & ImGuiMod_Mask_); + if (key == ImGuiKey_None) + key = ConvertSingleModFlagToKey(&g, mods); + IM_ASSERT(IsNamedKey(key)); + + // Get (in the majority of case, the linked list will have one element so this should be 2 reads. + // Subsequent elements will be contiguous in memory as list is sorted/rebuilt in NewFrame). + for (ImGuiKeyRoutingIndex idx = rt->Index[key - ImGuiKey_NamedKey_BEGIN]; idx != -1; idx = routing_data->NextEntryIndex) + { + routing_data = &rt->Entries[idx]; + if (routing_data->Mods == mods) + return routing_data; + } + + // Add to linked-list + ImGuiKeyRoutingIndex routing_data_idx = (ImGuiKeyRoutingIndex)rt->Entries.Size; + rt->Entries.push_back(ImGuiKeyRoutingData()); + routing_data = &rt->Entries[routing_data_idx]; + routing_data->Mods = (ImU16)mods; + routing_data->NextEntryIndex = rt->Index[key - ImGuiKey_NamedKey_BEGIN]; // Setup linked list + rt->Index[key - ImGuiKey_NamedKey_BEGIN] = routing_data_idx; + return routing_data; +} + +// Current score encoding (lower is highest priority): +// - 0: ImGuiInputFlags_RouteGlobalHigh +// - 1: ImGuiInputFlags_RouteFocused (if item active) +// - 2: ImGuiInputFlags_RouteGlobal +// - 3+: ImGuiInputFlags_RouteFocused (if window in focus-stack) +// - 254: ImGuiInputFlags_RouteGlobalLow +// - 255: never route +// 'flags' should include an explicit routing policy +static int CalcRoutingScore(ImGuiWindow* location, ImGuiID owner_id, ImGuiInputFlags flags) +{ + if (flags & ImGuiInputFlags_RouteFocused) + { + ImGuiContext& g = *GImGui; + ImGuiWindow* focused = g.NavWindow; + + // ActiveID gets top priority + // (we don't check g.ActiveIdUsingAllKeys here. Routing is applied but if input ownership is tested later it may discard it) + if (owner_id != 0 && g.ActiveId == owner_id) + return 1; + + // Score based on distance to focused window (lower is better) + // Assuming both windows are submitting a routing request, + // - When Window....... is focused -> Window scores 3 (best), Window/ChildB scores 255 (no match) + // - When Window/ChildB is focused -> Window scores 4, Window/ChildB scores 3 (best) + // Assuming only WindowA is submitting a routing request, + // - When Window/ChildB is focused -> Window scores 4 (best), Window/ChildB doesn't have a score. + if (focused != NULL && focused->RootWindow == location->RootWindow) + for (int next_score = 3; focused != NULL; next_score++) + { + if (focused == location) + { + IM_ASSERT(next_score < 255); + return next_score; + } + focused = (focused->RootWindow != focused) ? focused->ParentWindow : NULL; // FIXME: This could be later abstracted as a focus path + } + return 255; + } + + // ImGuiInputFlags_RouteGlobalHigh is default, so calls without flags are not conditional + if (flags & ImGuiInputFlags_RouteGlobal) + return 2; + if (flags & ImGuiInputFlags_RouteGlobalLow) + return 254; + return 0; +} + +// Request a desired route for an input chord (key + mods). +// Return true if the route is available this frame. +// - Routes and key ownership are attributed at the beginning of next frame based on best score and mod state. +// (Conceptually this does a "Submit for next frame" + "Test for current frame". +// As such, it could be called TrySetXXX or SubmitXXX, or the Submit and Test operations should be separate.) +// - Using 'owner_id == ImGuiKeyOwner_Any/0': auto-assign an owner based on current focus scope (each window has its focus scope by default) +// - Using 'owner_id == ImGuiKeyOwner_None': allows disabling/locking a shortcut. +bool ImGui::SetShortcutRouting(ImGuiKeyChord key_chord, ImGuiID owner_id, ImGuiInputFlags flags) +{ + ImGuiContext& g = *GImGui; + if ((flags & ImGuiInputFlags_RouteMask_) == 0) + flags |= ImGuiInputFlags_RouteGlobalHigh; // IMPORTANT: This is the default for SetShortcutRouting() but NOT Shortcut() + else + IM_ASSERT(ImIsPowerOfTwo(flags & ImGuiInputFlags_RouteMask_)); // Check that only 1 routing flag is used + + if (flags & ImGuiInputFlags_RouteUnlessBgFocused) + if (g.NavWindow == NULL) + return false; + if (flags & ImGuiInputFlags_RouteAlways) + return true; + + const int score = CalcRoutingScore(g.CurrentWindow, owner_id, flags); + if (score == 255) + return false; + + // Submit routing for NEXT frame (assuming score is sufficient) + // FIXME: Could expose a way to use a "serve last" policy for same score resolution (using <= instead of <). + ImGuiKeyRoutingData* routing_data = GetShortcutRoutingData(key_chord); + const ImGuiID routing_id = GetRoutingIdFromOwnerId(owner_id); + //const bool set_route = (flags & ImGuiInputFlags_ServeLast) ? (score <= routing_data->RoutingNextScore) : (score < routing_data->RoutingNextScore); + if (score < routing_data->RoutingNextScore) + { + routing_data->RoutingNext = routing_id; + routing_data->RoutingNextScore = (ImU8)score; + } + + // Return routing state for CURRENT frame + return routing_data->RoutingCurr == routing_id; +} + +// Currently unused by core (but used by tests) +// Note: this cannot be turned into GetShortcutRouting() because we do the owner_id->routing_id translation, name would be more misleading. +bool ImGui::TestShortcutRouting(ImGuiKeyChord key_chord, ImGuiID owner_id) +{ + const ImGuiID routing_id = GetRoutingIdFromOwnerId(owner_id); + ImGuiKeyRoutingData* routing_data = GetShortcutRoutingData(key_chord); // FIXME: Could avoid creating entry. + return routing_data->RoutingCurr == routing_id; +} + // Note that Dear ImGui doesn't know the meaning/semantic of ImGuiKey from 0..511: they are legacy native keycodes. // Consider transitioning from 'IsKeyDown(MY_ENGINE_KEY_A)' (<1.87) to IsKeyDown(ImGuiKey_A) (>= 1.87) bool ImGui::IsKeyDown(ImGuiKey key) +{ + return IsKeyDown(key, ImGuiKeyOwner_Any); +} + +bool ImGui::IsKeyDown(ImGuiKey key, ImGuiID owner_id) { const ImGuiKeyData* key_data = GetKeyData(key); if (!key_data->Down) return false; + if (!TestKeyOwner(key, owner_id)) + return false; return true; } bool ImGui::IsKeyPressed(ImGuiKey key, bool repeat) { - ImGuiContext& g = *GImGui; + return IsKeyPressed(key, ImGuiKeyOwner_Any, repeat ? ImGuiInputFlags_Repeat : ImGuiInputFlags_None); +} + +// Important: unless legacy IsKeyPressed(ImGuiKey, bool repeat=true) which DEFAULT to repeat, this requires EXPLICIT repeat. +bool ImGui::IsKeyPressed(ImGuiKey key, ImGuiID owner_id, ImGuiInputFlags flags) +{ const ImGuiKeyData* key_data = GetKeyData(key); + if (!key_data->Down) // In theory this should already be encoded as (DownDuration < 0.0f), but testing this facilitates eating mechanism (until we finish work on key ownership) + return false; const float t = key_data->DownDuration; if (t < 0.0f) return false; - const bool pressed = (t == 0.0f) || (repeat && t > g.IO.KeyRepeatDelay && GetKeyPressedAmount(key, g.IO.KeyRepeatDelay, g.IO.KeyRepeatRate) > 0); + IM_ASSERT((flags & ~ImGuiInputFlags_SupportedByIsKeyPressed) == 0); // Passing flags not supported by this function! + + bool pressed = (t == 0.0f); + if (!pressed && ((flags & ImGuiInputFlags_Repeat) != 0)) + { + float repeat_delay, repeat_rate; + GetTypematicRepeatRate(flags, &repeat_delay, &repeat_rate); + pressed = (t > repeat_delay) && GetKeyPressedAmount(key, repeat_delay, repeat_rate) > 0; + } if (!pressed) return false; + if (!TestKeyOwner(key, owner_id)) + return false; return true; } bool ImGui::IsKeyReleased(ImGuiKey key) +{ + return IsKeyReleased(key, ImGuiKeyOwner_Any); +} + +bool ImGui::IsKeyReleased(ImGuiKey key, ImGuiID owner_id) { const ImGuiKeyData* key_data = GetKeyData(key); if (key_data->DownDurationPrev < 0.0f || key_data->Down) return false; + if (!TestKeyOwner(key, owner_id)) + return false; return true; } @@ -8385,33 +8901,62 @@ bool ImGui::IsMouseDown(ImGuiMouseButton button) { ImGuiContext& g = *GImGui; IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown)); - return g.IO.MouseDown[button]; + return g.IO.MouseDown[button] && TestKeyOwner(MouseButtonToKey(button), ImGuiKeyOwner_Any); // should be same as IsKeyDown(MouseButtonToKey(button), ImGuiKeyOwner_Any), but this allows legacy code hijacking the io.Mousedown[] array. +} + +bool ImGui::IsMouseDown(ImGuiMouseButton button, ImGuiID owner_id) +{ + ImGuiContext& g = *GImGui; + IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown)); + return g.IO.MouseDown[button] && TestKeyOwner(MouseButtonToKey(button), owner_id); // Should be same as IsKeyDown(MouseButtonToKey(button), owner_id), but this allows legacy code hijacking the io.Mousedown[] array. } bool ImGui::IsMouseClicked(ImGuiMouseButton button, bool repeat) +{ + return IsMouseClicked(button, ImGuiKeyOwner_Any, repeat ? ImGuiInputFlags_Repeat : ImGuiInputFlags_None); +} + +bool ImGui::IsMouseClicked(ImGuiMouseButton button, ImGuiID owner_id, ImGuiInputFlags flags) { ImGuiContext& g = *GImGui; IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown)); + if (!g.IO.MouseDown[button]) // In theory this should already be encoded as (DownDuration < 0.0f), but testing this facilitates eating mechanism (until we finish work on key ownership) + return false; const float t = g.IO.MouseDownDuration[button]; - if (t == 0.0f) - return true; - if (repeat && t > g.IO.KeyRepeatDelay) - return CalcTypematicRepeatAmount(t - g.IO.DeltaTime, t, g.IO.KeyRepeatDelay, g.IO.KeyRepeatRate) > 0; - return false; + if (t < 0.0f) + return false; + IM_ASSERT((flags & ~ImGuiInputFlags_SupportedByIsKeyPressed) == 0); // Passing flags not supported by this function! + + const bool repeat = (flags & ImGuiInputFlags_Repeat) != 0; + const bool pressed = (t == 0.0f) || (repeat && t > g.IO.KeyRepeatDelay && CalcTypematicRepeatAmount(t - g.IO.DeltaTime, t, g.IO.KeyRepeatDelay, g.IO.KeyRepeatRate) > 0); + if (!pressed) + return false; + + if (!TestKeyOwner(MouseButtonToKey(button), owner_id)) + return false; + + return true; } bool ImGui::IsMouseReleased(ImGuiMouseButton button) { ImGuiContext& g = *GImGui; IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown)); - return g.IO.MouseReleased[button]; + return g.IO.MouseReleased[button] && TestKeyOwner(MouseButtonToKey(button), ImGuiKeyOwner_Any); // Should be same as IsKeyReleased(MouseButtonToKey(button), ImGuiKeyOwner_Any) +} + +bool ImGui::IsMouseReleased(ImGuiMouseButton button, ImGuiID owner_id) +{ + ImGuiContext& g = *GImGui; + IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown)); + return g.IO.MouseReleased[button] && TestKeyOwner(MouseButtonToKey(button), owner_id); // Should be same as IsKeyReleased(MouseButtonToKey(button), owner_id) } bool ImGui::IsMouseDoubleClicked(ImGuiMouseButton button) { ImGuiContext& g = *GImGui; IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown)); - return g.IO.MouseClickedCount[button] == 2; + return g.IO.MouseClickedCount[button] == 2 && TestKeyOwner(MouseButtonToKey(button), ImGuiKeyOwner_Any); } int ImGui::GetMouseClickedCount(ImGuiMouseButton button) @@ -8421,6 +8966,27 @@ int ImGui::GetMouseClickedCount(ImGuiMouseButton button) return g.IO.MouseClickedCount[button]; } +// Test if mouse cursor is hovering given rectangle +// NB- Rectangle is clipped by our current clip setting +// NB- Expand the rectangle to be generous on imprecise inputs systems (g.Style.TouchExtraPadding) +bool ImGui::IsMouseHoveringRect(const ImVec2& r_min, const ImVec2& r_max, bool clip) +{ + ImGuiContext& g = *GImGui; + + // Clip + ImRect rect_clipped(r_min, r_max); + if (clip) + rect_clipped.ClipWith(g.CurrentWindow->ClipRect); + + // Expand for touch input + const ImRect rect_for_touch(rect_clipped.Min - g.Style.TouchExtraPadding, rect_clipped.Max + g.Style.TouchExtraPadding); + if (!rect_for_touch.Contains(g.IO.MousePos)) + return false; + if (!g.MouseViewport->GetMainRect().Overlaps(rect_clipped)) + return false; + return true; +} + // Return if a mouse click/drag went past the given threshold. Valid to call during the MouseReleased frame. // [Internal] This doesn't test if the button is pressed bool ImGui::IsMouseDragPastThreshold(ImGuiMouseButton button, float lock_threshold) @@ -8501,6 +9067,10 @@ void ImGui::ResetMouseDragDelta(ImGuiMouseButton button) g.IO.MouseClickedPos[button] = g.IO.MousePos; } +// Get desired mouse cursor shape. +// Important: this is meant to be used by a platform backend, it is reset in ImGui::NewFrame(), +// updated during the frame, and locked in EndFrame()/Render(). +// If you use software rendering by setting io.MouseDrawCursor then Dear ImGui will render those for you ImGuiMouseCursor ImGui::GetMouseCursor() { ImGuiContext& g = *GImGui; @@ -8513,34 +9083,410 @@ void ImGui::SetMouseCursor(ImGuiMouseCursor cursor_type) g.MouseCursor = cursor_type; } -void ImGui::CaptureKeyboardFromApp(bool capture) +static void UpdateAliasKey(ImGuiKey key, bool v, float analog_value) { - ImGuiContext& g = *GImGui; - g.WantCaptureKeyboardNextFrame = capture ? 1 : 0; + IM_ASSERT(ImGui::IsAliasKey(key)); + ImGuiKeyData* key_data = ImGui::GetKeyData(key); + key_data->Down = v; + key_data->AnalogValue = analog_value; } -void ImGui::CaptureMouseFromApp(bool capture) +// [Internal] Do not use directly +static ImGuiKeyChord GetMergedModsFromKeys() { - ImGuiContext& g = *GImGui; - g.WantCaptureMouseNextFrame = capture ? 1 : 0; + ImGuiKeyChord mods = 0; + if (ImGui::IsKeyDown(ImGuiMod_Ctrl)) { mods |= ImGuiMod_Ctrl; } + if (ImGui::IsKeyDown(ImGuiMod_Shift)) { mods |= ImGuiMod_Shift; } + if (ImGui::IsKeyDown(ImGuiMod_Alt)) { mods |= ImGuiMod_Alt; } + if (ImGui::IsKeyDown(ImGuiMod_Super)) { mods |= ImGuiMod_Super; } + return mods; } +static void ImGui::UpdateKeyboardInputs() +{ + ImGuiContext& g = *GImGui; + ImGuiIO& io = g.IO; + + // Import legacy keys or verify they are not used +#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO + if (io.BackendUsingLegacyKeyArrays == 0) + { + // Backend used new io.AddKeyEvent() API: Good! Verify that old arrays are never written to externally. + for (int n = 0; n < ImGuiKey_LegacyNativeKey_END; n++) + IM_ASSERT((io.KeysDown[n] == false || IsKeyDown((ImGuiKey)n)) && "Backend needs to either only use io.AddKeyEvent(), either only fill legacy io.KeysDown[] + io.KeyMap[]. Not both!"); + } + else + { + if (g.FrameCount == 0) + for (int n = ImGuiKey_LegacyNativeKey_BEGIN; n < ImGuiKey_LegacyNativeKey_END; n++) + IM_ASSERT(g.IO.KeyMap[n] == -1 && "Backend is not allowed to write to io.KeyMap[0..511]!"); + + // Build reverse KeyMap (Named -> Legacy) + for (int n = ImGuiKey_NamedKey_BEGIN; n < ImGuiKey_NamedKey_END; n++) + if (io.KeyMap[n] != -1) + { + IM_ASSERT(IsLegacyKey((ImGuiKey)io.KeyMap[n])); + io.KeyMap[io.KeyMap[n]] = n; + } + + // Import legacy keys into new ones + for (int n = ImGuiKey_LegacyNativeKey_BEGIN; n < ImGuiKey_LegacyNativeKey_END; n++) + if (io.KeysDown[n] || io.BackendUsingLegacyKeyArrays == 1) + { + const ImGuiKey key = (ImGuiKey)(io.KeyMap[n] != -1 ? io.KeyMap[n] : n); + IM_ASSERT(io.KeyMap[n] == -1 || IsNamedKey(key)); + io.KeysData[key].Down = io.KeysDown[n]; + if (key != n) + io.KeysDown[key] = io.KeysDown[n]; // Allow legacy code using io.KeysDown[GetKeyIndex()] with old backends + io.BackendUsingLegacyKeyArrays = 1; + } + if (io.BackendUsingLegacyKeyArrays == 1) + { + GetKeyData(ImGuiMod_Ctrl)->Down = io.KeyCtrl; + GetKeyData(ImGuiMod_Shift)->Down = io.KeyShift; + GetKeyData(ImGuiMod_Alt)->Down = io.KeyAlt; + GetKeyData(ImGuiMod_Super)->Down = io.KeySuper; + } + } + +#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO + const bool nav_gamepad_active = (io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) != 0 && (io.BackendFlags & ImGuiBackendFlags_HasGamepad) != 0; + if (io.BackendUsingLegacyNavInputArray && nav_gamepad_active) + { + #define MAP_LEGACY_NAV_INPUT_TO_KEY1(_KEY, _NAV1) do { io.KeysData[_KEY].Down = (io.NavInputs[_NAV1] > 0.0f); io.KeysData[_KEY].AnalogValue = io.NavInputs[_NAV1]; } while (0) + #define MAP_LEGACY_NAV_INPUT_TO_KEY2(_KEY, _NAV1, _NAV2) do { io.KeysData[_KEY].Down = (io.NavInputs[_NAV1] > 0.0f) || (io.NavInputs[_NAV2] > 0.0f); io.KeysData[_KEY].AnalogValue = ImMax(io.NavInputs[_NAV1], io.NavInputs[_NAV2]); } while (0) + MAP_LEGACY_NAV_INPUT_TO_KEY1(ImGuiKey_GamepadFaceDown, ImGuiNavInput_Activate); + MAP_LEGACY_NAV_INPUT_TO_KEY1(ImGuiKey_GamepadFaceRight, ImGuiNavInput_Cancel); + MAP_LEGACY_NAV_INPUT_TO_KEY1(ImGuiKey_GamepadFaceLeft, ImGuiNavInput_Menu); + MAP_LEGACY_NAV_INPUT_TO_KEY1(ImGuiKey_GamepadFaceUp, ImGuiNavInput_Input); + MAP_LEGACY_NAV_INPUT_TO_KEY1(ImGuiKey_GamepadDpadLeft, ImGuiNavInput_DpadLeft); + MAP_LEGACY_NAV_INPUT_TO_KEY1(ImGuiKey_GamepadDpadRight, ImGuiNavInput_DpadRight); + MAP_LEGACY_NAV_INPUT_TO_KEY1(ImGuiKey_GamepadDpadUp, ImGuiNavInput_DpadUp); + MAP_LEGACY_NAV_INPUT_TO_KEY1(ImGuiKey_GamepadDpadDown, ImGuiNavInput_DpadDown); + MAP_LEGACY_NAV_INPUT_TO_KEY2(ImGuiKey_GamepadL1, ImGuiNavInput_FocusPrev, ImGuiNavInput_TweakSlow); + MAP_LEGACY_NAV_INPUT_TO_KEY2(ImGuiKey_GamepadR1, ImGuiNavInput_FocusNext, ImGuiNavInput_TweakFast); + MAP_LEGACY_NAV_INPUT_TO_KEY1(ImGuiKey_GamepadLStickLeft, ImGuiNavInput_LStickLeft); + MAP_LEGACY_NAV_INPUT_TO_KEY1(ImGuiKey_GamepadLStickRight, ImGuiNavInput_LStickRight); + MAP_LEGACY_NAV_INPUT_TO_KEY1(ImGuiKey_GamepadLStickUp, ImGuiNavInput_LStickUp); + MAP_LEGACY_NAV_INPUT_TO_KEY1(ImGuiKey_GamepadLStickDown, ImGuiNavInput_LStickDown); + #undef NAV_MAP_KEY + } +#endif +#endif + + // Update aliases + for (int n = 0; n < ImGuiMouseButton_COUNT; n++) + UpdateAliasKey(MouseButtonToKey(n), io.MouseDown[n], io.MouseDown[n] ? 1.0f : 0.0f); + UpdateAliasKey(ImGuiKey_MouseWheelX, io.MouseWheelH != 0.0f, io.MouseWheelH); + UpdateAliasKey(ImGuiKey_MouseWheelY, io.MouseWheel != 0.0f, io.MouseWheel); + + // Synchronize io.KeyMods and io.KeyXXX values. + // - New backends (1.87+): send io.AddKeyEvent(ImGuiMod_XXX) -> -> (here) deriving io.KeyMods + io.KeyXXX from key array. + // - Legacy backends: set io.KeyXXX bools -> (above) set key array from io.KeyXXX -> (here) deriving io.KeyMods + io.KeyXXX from key array. + // So with legacy backends the 4 values will do a unnecessary back-and-forth but it makes the code simpler and future facing. + io.KeyMods = GetMergedModsFromKeys(); + io.KeyCtrl = (io.KeyMods & ImGuiMod_Ctrl) != 0; + io.KeyShift = (io.KeyMods & ImGuiMod_Shift) != 0; + io.KeyAlt = (io.KeyMods & ImGuiMod_Alt) != 0; + io.KeySuper = (io.KeyMods & ImGuiMod_Super) != 0; + + // Clear gamepad data if disabled + if ((io.BackendFlags & ImGuiBackendFlags_HasGamepad) == 0) + for (int i = ImGuiKey_Gamepad_BEGIN; i < ImGuiKey_Gamepad_END; i++) + { + io.KeysData[i - ImGuiKey_KeysData_OFFSET].Down = false; + io.KeysData[i - ImGuiKey_KeysData_OFFSET].AnalogValue = 0.0f; + } + + // Update keys + for (int i = 0; i < ImGuiKey_KeysData_SIZE; i++) + { + ImGuiKeyData* key_data = &io.KeysData[i]; + key_data->DownDurationPrev = key_data->DownDuration; + key_data->DownDuration = key_data->Down ? (key_data->DownDuration < 0.0f ? 0.0f : key_data->DownDuration + io.DeltaTime) : -1.0f; + } + + // Update keys/input owner (named keys only): one entry per key + for (ImGuiKey key = ImGuiKey_NamedKey_BEGIN; key < ImGuiKey_NamedKey_END; key = (ImGuiKey)(key + 1)) + { + ImGuiKeyData* key_data = &io.KeysData[key - ImGuiKey_KeysData_OFFSET]; + ImGuiKeyOwnerData* owner_data = &g.KeysOwnerData[key - ImGuiKey_NamedKey_BEGIN]; + owner_data->OwnerCurr = owner_data->OwnerNext; + if (!key_data->Down) // Important: ownership is released on the frame after a release. Ensure a 'MouseDown -> CloseWindow -> MouseUp' chain doesn't lead to someone else seeing the MouseUp. + owner_data->OwnerNext = ImGuiKeyOwner_None; + owner_data->LockThisFrame = owner_data->LockUntilRelease = owner_data->LockUntilRelease && key_data->Down; // Clear LockUntilRelease when key is not Down anymore + } + + UpdateKeyRoutingTable(&g.KeysRoutingTable); +} + +static void ImGui::UpdateMouseInputs() +{ + ImGuiContext& g = *GImGui; + ImGuiIO& io = g.IO; + + // Mouse Wheel swapping flag + // As a standard behavior holding SHIFT while using Vertical Mouse Wheel triggers Horizontal scroll instead + // - We avoid doing it on OSX as it the OS input layer handles this already. + // - FIXME: However this means when running on OSX over Emscripten, Shift+WheelY will incur two swapping (1 in OS, 1 here), canceling the feature. + // - FIXME: When we can distinguish e.g. touchpad scroll events from mouse ones, we'll set this accordingly based on input source. + io.MouseWheelRequestAxisSwap = io.KeyShift && !io.ConfigMacOSXBehaviors; + + // Round mouse position to avoid spreading non-rounded position (e.g. UpdateManualResize doesn't support them well) + if (IsMousePosValid(&io.MousePos)) + io.MousePos = g.MouseLastValidPos = ImFloorSigned(io.MousePos); + + io.MouseDeltaPrev=io.MouseDelta; + + // If mouse just appeared or disappeared (usually denoted by -FLT_MAX components) we cancel out movement in MouseDelta + if (IsMousePosValid(&io.MousePos) && IsMousePosValid(&io.MousePosPrev)) + io.MouseDelta = io.MousePos - io.MousePosPrev; + else + io.MouseDelta = ImVec2(0.0f, 0.0f); + + // If mouse moved we re-enable mouse hovering in case it was disabled by gamepad/keyboard. In theory should use a >0.0f threshold but would need to reset in everywhere we set this to true. + if (io.MouseDelta.x != 0.0f || io.MouseDelta.y != 0.0f) + g.NavDisableMouseHover = false; + + // Update mouse speed + if (ImFabs(io.MouseDelta.x)>ImFabs(io.MouseDeltaPrev.x)) { + io.MouseSpeed.x=io.MouseDelta.x; + } else { + io.MouseSpeed.x=io.MouseDeltaPrev.x; + } + if (ImFabs(io.MouseDelta.y)>ImFabs(io.MouseDeltaPrev.y)) { + io.MouseSpeed.y=io.MouseDelta.y; + } else { + io.MouseSpeed.y=io.MouseDeltaPrev.y; + } + + io.MousePosPrev = io.MousePos; + for (int i = 0; i < IM_ARRAYSIZE(io.MouseDown); i++) + { + io.MouseClicked[i] = io.MouseDown[i] && io.MouseDownDuration[i] < 0.0f; + io.MouseClickedCount[i] = 0; // Will be filled below + io.MouseReleased[i] = !io.MouseDown[i] && io.MouseDownDuration[i] >= 0.0f; + io.MouseDownDurationPrev[i] = io.MouseDownDuration[i]; + io.MouseDownDuration[i] = io.MouseDown[i] ? (io.MouseDownDuration[i] < 0.0f ? 0.0f : io.MouseDownDuration[i] + io.DeltaTime) : -1.0f; + if (io.MouseClicked[i]) + { + bool is_repeated_click = false; + if ((float)(g.Time - io.MouseClickedTime[i]) < io.MouseDoubleClickTime) + { + ImVec2 delta_from_click_pos = IsMousePosValid(&io.MousePos) ? (io.MousePos - io.MouseClickedPos[i]) : ImVec2(0.0f, 0.0f); + if (ImLengthSqr(delta_from_click_pos) < io.MouseDoubleClickMaxDist * io.MouseDoubleClickMaxDist) + is_repeated_click = true; + } + if (is_repeated_click) + io.MouseClickedLastCount[i]++; + else + io.MouseClickedLastCount[i] = 1; + io.MouseClickedTime[i] = g.Time; + io.MouseClickedPos[i] = io.MousePos; + io.MouseClickedCount[i] = io.MouseClickedLastCount[i]; + io.MouseDragMaxDistanceAbs[i] = ImVec2(0.0f, 0.0f); + io.MouseDragMaxDistanceSqr[i] = 0.0f; + } + else if (io.MouseDown[i]) + { + // Maintain the maximum distance we reaching from the initial click position, which is used with dragging threshold + ImVec2 delta_from_click_pos = IsMousePosValid(&io.MousePos) ? (io.MousePos - io.MouseClickedPos[i]) : ImVec2(0.0f, 0.0f); + io.MouseDragMaxDistanceSqr[i] = ImMax(io.MouseDragMaxDistanceSqr[i], ImLengthSqr(delta_from_click_pos)); + io.MouseDragMaxDistanceAbs[i].x = ImMax(io.MouseDragMaxDistanceAbs[i].x, delta_from_click_pos.x < 0.0f ? -delta_from_click_pos.x : delta_from_click_pos.x); + io.MouseDragMaxDistanceAbs[i].y = ImMax(io.MouseDragMaxDistanceAbs[i].y, delta_from_click_pos.y < 0.0f ? -delta_from_click_pos.y : delta_from_click_pos.y); + } + + // We provide io.MouseDoubleClicked[] as a legacy service + io.MouseDoubleClicked[i] = (io.MouseClickedCount[i] == 2); + + // Clicking any mouse button reactivate mouse hovering which may have been deactivated by gamepad/keyboard navigation + if (io.MouseClicked[i]) + g.NavDisableMouseHover = false; + } +} + +static void LockWheelingWindow(ImGuiWindow* window, float wheel_amount) +{ + ImGuiContext& g = *GImGui; + if (window) + g.WheelingWindowReleaseTimer = ImMin(g.WheelingWindowReleaseTimer + ImAbs(wheel_amount) * WINDOWS_MOUSE_WHEEL_SCROLL_LOCK_TIMER, WINDOWS_MOUSE_WHEEL_SCROLL_LOCK_TIMER); + else + g.WheelingWindowReleaseTimer = 0.0f; + if (g.WheelingWindow == window) + return; + IMGUI_DEBUG_LOG_IO("[io] LockWheelingWindow() \"%s\"\n", window ? window->Name : "NULL"); + g.WheelingWindow = window; + g.WheelingWindowRefMousePos = g.IO.MousePos; + if (window == NULL) + { + g.WheelingWindowStartFrame = -1; + g.WheelingAxisAvg = ImVec2(0.0f, 0.0f); + } +} + +static ImGuiWindow* FindBestWheelingWindow(const ImVec2& wheel) +{ + // For each axis, find window in the hierarchy that may want to use scrolling + ImGuiContext& g = *GImGui; + ImGuiWindow* windows[2] = { NULL, NULL }; + for (int axis = 0; axis < 2; axis++) + if (wheel[axis] != 0.0f) + for (ImGuiWindow* window = windows[axis] = g.HoveredWindow; window->Flags & ImGuiWindowFlags_ChildWindow; window = windows[axis] = window->ParentWindow) + { + // Bubble up into parent window if: + // - a child window doesn't allow any scrolling. + // - a child window has the ImGuiWindowFlags_NoScrollWithMouse flag. + //// - a child window doesn't need scrolling because it is already at the edge for the direction we are going in (FIXME-WIP) + const bool has_scrolling = (window->ScrollMax[axis] != 0.0f); + const bool inputs_disabled = (window->Flags & ImGuiWindowFlags_NoScrollWithMouse) && !(window->Flags & ImGuiWindowFlags_NoMouseInputs); + //const bool scrolling_past_limits = (wheel_v < 0.0f) ? (window->Scroll[axis] <= 0.0f) : (window->Scroll[axis] >= window->ScrollMax[axis]); + if (has_scrolling && !inputs_disabled) // && !scrolling_past_limits) + break; // select this window + } + if (windows[0] == NULL && windows[1] == NULL) + return NULL; + + // If there's only one window or only one axis then there's no ambiguity + if (windows[0] == windows[1] || windows[0] == NULL || windows[1] == NULL) + return windows[1] ? windows[1] : windows[0]; + + // If candidate are different windows we need to decide which one to prioritize + // - First frame: only find a winner if one axis is zero. + // - Subsequent frames: only find a winner when one is more than the other. + if (g.WheelingWindowStartFrame == -1) + g.WheelingWindowStartFrame = g.FrameCount; + if ((g.WheelingWindowStartFrame == g.FrameCount && wheel.x != 0.0f && wheel.y != 0.0f) || (g.WheelingAxisAvg.x == g.WheelingAxisAvg.y)) + { + g.WheelingWindowWheelRemainder = wheel; + return NULL; + } + return (g.WheelingAxisAvg.x > g.WheelingAxisAvg.y) ? windows[0] : windows[1]; +} + +// Called by NewFrame() +void ImGui::UpdateMouseWheel() +{ + // Reset the locked window if we move the mouse or after the timer elapses. + // FIXME: Ideally we could refactor to have one timer for "changing window w/ same axis" and a shorter timer for "changing window or axis w/ other axis" (#3795) + ImGuiContext& g = *GImGui; + if (g.WheelingWindow != NULL) + { + g.WheelingWindowReleaseTimer -= g.IO.DeltaTime; + if (IsMousePosValid() && ImLengthSqr(g.IO.MousePos - g.WheelingWindowRefMousePos) > g.IO.MouseDragThreshold * g.IO.MouseDragThreshold) + g.WheelingWindowReleaseTimer = 0.0f; + if (g.WheelingWindowReleaseTimer <= 0.0f) + LockWheelingWindow(NULL, 0.0f); + } + + ImVec2 wheel; + wheel.x = TestKeyOwner(ImGuiKey_MouseWheelX, ImGuiKeyOwner_None) ? g.IO.MouseWheelH : 0.0f; + wheel.y = TestKeyOwner(ImGuiKey_MouseWheelY, ImGuiKeyOwner_None) ? g.IO.MouseWheel : 0.0f; + + //IMGUI_DEBUG_LOG("MouseWheel X:%.3f Y:%.3f\n", wheel_x, wheel_y); + ImGuiWindow* mouse_window = g.WheelingWindow ? g.WheelingWindow : g.HoveredWindow; + if (!mouse_window || mouse_window->Collapsed) + return; + + // Zoom / Scale window + // FIXME-OBSOLETE: This is an old feature, it still works but pretty much nobody is using it and may be best redesigned. + if (wheel.y != 0.0f && g.IO.KeyCtrl && g.IO.FontAllowUserScaling) + { + LockWheelingWindow(mouse_window, wheel.y); + ImGuiWindow* window = mouse_window; + const float new_font_scale = ImClamp(window->FontWindowScale + g.IO.MouseWheel * 0.10f, 0.50f, 2.50f); + const float scale = new_font_scale / window->FontWindowScale; + window->FontWindowScale = new_font_scale; + if (window == window->RootWindow) + { + const ImVec2 offset = window->Size * (1.0f - scale) * (g.IO.MousePos - window->Pos) / window->Size; + SetWindowPos(window, window->Pos + offset, 0); + window->Size = ImFloor(window->Size * scale); + window->SizeFull = ImFloor(window->SizeFull * scale); + } + return; + } + if (g.IO.KeyCtrl) + return; + + // Mouse wheel scrolling + // Read about io.MouseWheelRequestAxisSwap and its issue on Mac+Emscripten in UpdateMouseInputs() + if (g.IO.MouseWheelRequestAxisSwap) + wheel = ImVec2(wheel.y, 0.0f); + + // Maintain a rough average of moving magnitude on both axises + // FIXME: should by based on wall clock time rather than frame-counter + g.WheelingAxisAvg.x = ImExponentialMovingAverage(g.WheelingAxisAvg.x, ImAbs(wheel.x), 30); + g.WheelingAxisAvg.y = ImExponentialMovingAverage(g.WheelingAxisAvg.y, ImAbs(wheel.y), 30); + + // In the rare situation where FindBestWheelingWindow() had to defer first frame of wheeling due to ambiguous main axis, reinject it now. + wheel += g.WheelingWindowWheelRemainder; + g.WheelingWindowWheelRemainder = ImVec2(0.0f, 0.0f); + if (wheel.x == 0.0f && wheel.y == 0.0f) + return; + + // Mouse wheel scrolling: find target and apply + // - don't renew lock if axis doesn't apply on the window. + // - select a main axis when both axises are being moved. + if (ImGuiWindow* window = (g.WheelingWindow ? g.WheelingWindow : FindBestWheelingWindow(wheel))) + if (!(window->Flags & ImGuiWindowFlags_NoScrollWithMouse) && !(window->Flags & ImGuiWindowFlags_NoMouseInputs)) + { + bool do_scroll[2] = { wheel.x != 0.0f && window->ScrollMax.x != 0.0f, wheel.y != 0.0f && window->ScrollMax.y != 0.0f }; + if (do_scroll[ImGuiAxis_X] && do_scroll[ImGuiAxis_Y]) + do_scroll[(g.WheelingAxisAvg.x > g.WheelingAxisAvg.y) ? ImGuiAxis_Y : ImGuiAxis_X] = false; + if (do_scroll[ImGuiAxis_X]) + { + LockWheelingWindow(window, wheel.x); + float max_step = window->InnerRect.GetWidth() * 0.67f; + float scroll_step = ImFloor(ImMin(2 * window->CalcFontSize(), max_step)); + SetScrollX(window, window->Scroll.x - wheel.x * scroll_step); + } + if (do_scroll[ImGuiAxis_Y]) + { + LockWheelingWindow(window, wheel.y); + float max_step = window->InnerRect.GetHeight() * 0.67f; + float scroll_step = ImFloor(ImMin(5 * window->CalcFontSize(), max_step)); + SetScrollY(window, window->Scroll.y - wheel.y * scroll_step); + } + } +} + +void ImGui::SetNextFrameWantCaptureKeyboard(bool want_capture_keyboard) +{ + ImGuiContext& g = *GImGui; + g.WantCaptureKeyboardNextFrame = want_capture_keyboard ? 1 : 0; +} + +void ImGui::SetNextFrameWantCaptureMouse(bool want_capture_mouse) +{ + ImGuiContext& g = *GImGui; + g.WantCaptureMouseNextFrame = want_capture_mouse ? 1 : 0; +} + +#ifndef IMGUI_DISABLE_DEBUG_TOOLS static const char* GetInputSourceName(ImGuiInputSource source) { - const char* input_source_names[] = { "None", "Mouse", "Keyboard", "Gamepad", "Nav", "Clipboard" }; + const char* input_source_names[] = { "None", "Mouse", "Keyboard", "Gamepad", "Clipboard" }; IM_ASSERT(IM_ARRAYSIZE(input_source_names) == ImGuiInputSource_COUNT && source >= 0 && source < ImGuiInputSource_COUNT); return input_source_names[source]; } - -/*static void DebugLogInputEvent(const char* prefix, const ImGuiInputEvent* e) +static const char* GetMouseSourceName(ImGuiMouseSource source) { - if (e->Type == ImGuiInputEventType_MousePos) { IMGUI_DEBUG_LOG("%s: MousePos (%.1f %.1f)\n", prefix, e->MousePos.PosX, e->MousePos.PosY); return; } - if (e->Type == ImGuiInputEventType_MouseButton) { IMGUI_DEBUG_LOG("%s: MouseButton %d %s\n", prefix, e->MouseButton.Button, e->MouseButton.Down ? "Down" : "Up"); return; } - if (e->Type == ImGuiInputEventType_MouseWheel) { IMGUI_DEBUG_LOG("%s: MouseWheel (%.1f %.1f)\n", prefix, e->MouseWheel.WheelX, e->MouseWheel.WheelY); return; } - if (e->Type == ImGuiInputEventType_Key) { IMGUI_DEBUG_LOG("%s: Key \"%s\" %s\n", prefix, ImGui::GetKeyName(e->Key.Key), e->Key.Down ? "Down" : "Up"); return; } - if (e->Type == ImGuiInputEventType_Text) { IMGUI_DEBUG_LOG("%s: Text: %c (U+%08X)\n", prefix, e->Text.Char, e->Text.Char); return; } - if (e->Type == ImGuiInputEventType_Focus) { IMGUI_DEBUG_LOG("%s: AppFocused %d\n", prefix, e->AppFocused.Focused); return; } -}*/ + const char* mouse_source_names[] = { "Mouse", "TouchScreen", "Pen" }; + IM_ASSERT(IM_ARRAYSIZE(mouse_source_names) == ImGuiMouseSource_COUNT && source >= 0 && source < ImGuiMouseSource_COUNT); + return mouse_source_names[source]; +} +static void DebugPrintInputEvent(const char* prefix, const ImGuiInputEvent* e) +{ + ImGuiContext& g = *GImGui; + if (e->Type == ImGuiInputEventType_MousePos) { if (e->MousePos.PosX == -FLT_MAX && e->MousePos.PosY == -FLT_MAX) IMGUI_DEBUG_LOG_IO("[io] %s: MousePos (-FLT_MAX, -FLT_MAX)\n", prefix); else IMGUI_DEBUG_LOG_IO("[io] %s: MousePos (%.1f, %.1f) (%s)\n", prefix, e->MousePos.PosX, e->MousePos.PosY, GetMouseSourceName(e->MouseWheel.MouseSource)); return; } + if (e->Type == ImGuiInputEventType_MouseButton) { IMGUI_DEBUG_LOG_IO("[io] %s: MouseButton %d %s (%s)\n", prefix, e->MouseButton.Button, e->MouseButton.Down ? "Down" : "Up", GetMouseSourceName(e->MouseWheel.MouseSource)); return; } + if (e->Type == ImGuiInputEventType_MouseWheel) { IMGUI_DEBUG_LOG_IO("[io] %s: MouseWheel (%.3f, %.3f) (%s)\n", prefix, e->MouseWheel.WheelX, e->MouseWheel.WheelY, GetMouseSourceName(e->MouseWheel.MouseSource)); return; } + if (e->Type == ImGuiInputEventType_MouseViewport){IMGUI_DEBUG_LOG_IO("[io] %s: MouseViewport (0x%08X)\n", prefix, e->MouseViewport.HoveredViewportID); return; } + if (e->Type == ImGuiInputEventType_Key) { IMGUI_DEBUG_LOG_IO("[io] %s: Key \"%s\" %s\n", prefix, ImGui::GetKeyName(e->Key.Key), e->Key.Down ? "Down" : "Up"); return; } + if (e->Type == ImGuiInputEventType_Text) { IMGUI_DEBUG_LOG_IO("[io] %s: Text: %c (U+%08X)\n", prefix, e->Text.Char, e->Text.Char); return; } + if (e->Type == ImGuiInputEventType_Focus) { IMGUI_DEBUG_LOG_IO("[io] %s: AppFocused %d\n", prefix, e->AppFocused.Focused); return; } +} +#endif // Process input queue // We always call this with the value of 'bool g.IO.ConfigInputTrickleEventQueue'. @@ -8563,45 +9509,39 @@ void ImGui::UpdateInputEvents(bool trickle_fast_inputs) int event_n = 0; for (; event_n < g.InputEventsQueue.Size; event_n++) { - const ImGuiInputEvent* e = &g.InputEventsQueue[event_n]; + ImGuiInputEvent* e = &g.InputEventsQueue[event_n]; if (e->Type == ImGuiInputEventType_MousePos) { + // Trickling Rule: Stop processing queued events if we already handled a mouse button change ImVec2 event_pos(e->MousePos.PosX, e->MousePos.PosY); - if (IsMousePosValid(&event_pos)) - event_pos = ImVec2(ImFloorSigned(event_pos.x), ImFloorSigned(event_pos.y)); // Apply same flooring as UpdateMouseInputs() - if (io.MousePos.x != event_pos.x || io.MousePos.y != event_pos.y) - { - // Trickling Rule: Stop processing queued events if we already handled a mouse button change - if (trickle_fast_inputs && (mouse_button_changed != 0 || mouse_wheeled || key_changed || text_inputted)) - break; - io.MousePos = event_pos; - mouse_moved = true; - } + if (trickle_fast_inputs && (mouse_button_changed != 0 || mouse_wheeled || key_changed || text_inputted)) + break; + io.MousePos = event_pos; + io.MouseSource = e->MousePos.MouseSource; + mouse_moved = true; } else if (e->Type == ImGuiInputEventType_MouseButton) { + // Trickling Rule: Stop processing queued events if we got multiple action on the same button const ImGuiMouseButton button = e->MouseButton.Button; IM_ASSERT(button >= 0 && button < ImGuiMouseButton_COUNT); - if (io.MouseDown[button] != e->MouseButton.Down) - { - // Trickling Rule: Stop processing queued events if we got multiple action on the same button - if (trickle_fast_inputs && ((mouse_button_changed & (1 << button)) || mouse_wheeled)) - break; - io.MouseDown[button] = e->MouseButton.Down; - mouse_button_changed |= (1 << button); - } + if (trickle_fast_inputs && ((mouse_button_changed & (1 << button)) || mouse_wheeled)) + break; + if (trickle_fast_inputs && e->MouseButton.MouseSource == ImGuiMouseSource_TouchScreen && mouse_moved) // #2702: TouchScreen have no initial hover. + break; + io.MouseDown[button] = e->MouseButton.Down; + io.MouseSource = e->MouseButton.MouseSource; + mouse_button_changed |= (1 << button); } else if (e->Type == ImGuiInputEventType_MouseWheel) { - if (e->MouseWheel.WheelX != 0.0f || e->MouseWheel.WheelY != 0.0f) - { - // Trickling Rule: Stop processing queued events if we got multiple action on the event - if (trickle_fast_inputs && (mouse_wheeled || mouse_button_changed != 0)) - break; - io.MouseWheelH += e->MouseWheel.WheelX; - io.MouseWheel += e->MouseWheel.WheelY; - mouse_wheeled = true; - } + // Trickling Rule: Stop processing queued events if we got multiple action on the event + if (trickle_fast_inputs && (mouse_moved || mouse_button_changed != 0)) + break; + io.MouseWheelH += e->MouseWheel.WheelX; + io.MouseWheel += e->MouseWheel.WheelY; + io.MouseSource = e->MouseWheel.MouseSource; + mouse_wheeled = true; } else if (e->Type == ImGuiInputEventType_MouseViewport) { @@ -8609,36 +9549,24 @@ void ImGui::UpdateInputEvents(bool trickle_fast_inputs) } else if (e->Type == ImGuiInputEventType_Key) { + // Trickling Rule: Stop processing queued events if we got multiple action on the same button ImGuiKey key = e->Key.Key; IM_ASSERT(key != ImGuiKey_None); - const int keydata_index = (key - ImGuiKey_KeysData_OFFSET); - ImGuiKeyData* keydata = &io.KeysData[keydata_index]; - if (keydata->Down != e->Key.Down || keydata->AnalogValue != e->Key.AnalogValue) - { - // Trickling Rule: Stop processing queued events if we got multiple action on the same button - if (trickle_fast_inputs && keydata->Down != e->Key.Down && (key_changed_mask.TestBit(keydata_index) || text_inputted || mouse_button_changed != 0)) - break; - keydata->Down = e->Key.Down; - keydata->AnalogValue = e->Key.AnalogValue; - key_changed = true; - key_changed_mask.SetBit(keydata_index); + ImGuiKeyData* key_data = GetKeyData(key); + const int key_data_index = (int)(key_data - g.IO.KeysData); + if (trickle_fast_inputs && key_data->Down != e->Key.Down && (key_changed_mask.TestBit(key_data_index) || text_inputted || mouse_button_changed != 0)) + break; + key_data->Down = e->Key.Down; + key_data->AnalogValue = e->Key.AnalogValue; + key_changed = true; + key_changed_mask.SetBit(key_data_index); - if (key == ImGuiKey_ModCtrl || key == ImGuiKey_ModShift || key == ImGuiKey_ModAlt || key == ImGuiKey_ModSuper) - { - if (key == ImGuiKey_ModCtrl) { io.KeyCtrl = keydata->Down; } - if (key == ImGuiKey_ModShift) { io.KeyShift = keydata->Down; } - if (key == ImGuiKey_ModAlt) { io.KeyAlt = keydata->Down; } - if (key == ImGuiKey_ModSuper) { io.KeySuper = keydata->Down; } - io.KeyMods = GetMergedModFlags(); - } - - // Allow legacy code using io.KeysDown[GetKeyIndex()] with new backends + // Allow legacy code using io.KeysDown[GetKeyIndex()] with new backends #ifndef IMGUI_DISABLE_OBSOLETE_KEYIO - io.KeysDown[key] = keydata->Down; - if (io.KeyMap[key] != -1) - io.KeysDown[io.KeyMap[key]] = keydata->Down; + io.KeysDown[key_data_index] = key_data->Down; + if (io.KeyMap[key_data_index] != -1) + io.KeysDown[io.KeyMap[key_data_index]] = key_data->Down; #endif - } } else if (e->Type == ImGuiInputEventType_Text) { @@ -8652,9 +9580,10 @@ void ImGui::UpdateInputEvents(bool trickle_fast_inputs) } else if (e->Type == ImGuiInputEventType_Focus) { - // We intentionally overwrite this and process lower, in order to give a chance + // We intentionally overwrite this and process in NewFrame(), in order to give a chance // to multi-viewports backends to queue AddFocusEvent(false) + AddFocusEvent(true) in same frame. - io.AppFocusLost = !e->AppFocused.Focused; + const bool focus_lost = !e->AppFocused.Focused; + io.AppFocusLost = focus_lost; } else { @@ -8663,14 +9592,16 @@ void ImGui::UpdateInputEvents(bool trickle_fast_inputs) } // Record trail (for domain-specific applications wanting to access a precise trail) - //if (event_n != 0) IMGUI_DEBUG_LOG("Processed: %d / Remaining: %d\n", event_n, g.InputEventsQueue.Size - event_n); + //if (event_n != 0) IMGUI_DEBUG_LOG_IO("Processed: %d / Remaining: %d\n", event_n, g.InputEventsQueue.Size - event_n); for (int n = 0; n < event_n; n++) g.InputEventsTrail.push_back(g.InputEventsQueue[n]); // [DEBUG] - /*if (event_n != 0) +#ifndef IMGUI_DISABLE_DEBUG_TOOLS + if (event_n != 0 && (g.DebugLogFlags & ImGuiDebugLogFlags_EventIO)) for (int n = 0; n < g.InputEventsQueue.Size; n++) - DebugLogInputEvent(n < event_n ? "Processed" : "Remaining", &g.InputEventsQueue[n]);*/ + DebugPrintInputEvent(n < event_n ? "Processed" : "Remaining", &g.InputEventsQueue[n]); +#endif // Remaining events will be processed on the next frame if (event_n == g.InputEventsQueue.Size) @@ -8679,12 +9610,139 @@ void ImGui::UpdateInputEvents(bool trickle_fast_inputs) g.InputEventsQueue.erase(g.InputEventsQueue.Data, g.InputEventsQueue.Data + event_n); // Clear buttons state when focus is lost - // (this is useful so e.g. releasing Alt after focus loss on Alt-Tab doesn't trigger the Alt menu toggle) + // - this is useful so e.g. releasing Alt after focus loss on Alt-Tab doesn't trigger the Alt menu toggle. + // - we clear in EndFrame() and not now in order allow application/user code polling this flag + // (e.g. custom backend may want to clear additional data, custom widgets may want to react with a "canceling" event). if (g.IO.AppFocusLost) - { g.IO.ClearInputKeys(); - g.IO.AppFocusLost = false; +} + +ImGuiID ImGui::GetKeyOwner(ImGuiKey key) +{ + if (!IsNamedKeyOrModKey(key)) + return ImGuiKeyOwner_None; + + ImGuiContext& g = *GImGui; + ImGuiKeyOwnerData* owner_data = GetKeyOwnerData(&g, key); + ImGuiID owner_id = owner_data->OwnerCurr; + + if (g.ActiveIdUsingAllKeyboardKeys && owner_id != g.ActiveId && owner_id != ImGuiKeyOwner_Any) + if (key >= ImGuiKey_Keyboard_BEGIN && key < ImGuiKey_Keyboard_END) + return ImGuiKeyOwner_None; + + return owner_id; +} + +// TestKeyOwner(..., ID) : (owner == None || owner == ID) +// TestKeyOwner(..., None) : (owner == None) +// TestKeyOwner(..., Any) : no owner test +// All paths are also testing for key not being locked, for the rare cases that key have been locked with using ImGuiInputFlags_LockXXX flags. +bool ImGui::TestKeyOwner(ImGuiKey key, ImGuiID owner_id) +{ + if (!IsNamedKeyOrModKey(key)) + return true; + + ImGuiContext& g = *GImGui; + if (g.ActiveIdUsingAllKeyboardKeys && owner_id != g.ActiveId && owner_id != ImGuiKeyOwner_Any) + if (key >= ImGuiKey_Keyboard_BEGIN && key < ImGuiKey_Keyboard_END) + return false; + + ImGuiKeyOwnerData* owner_data = GetKeyOwnerData(&g, key); + if (owner_id == ImGuiKeyOwner_Any) + return (owner_data->LockThisFrame == false); + + // Note: SetKeyOwner() sets OwnerCurr. It is not strictly required for most mouse routing overlap (because of ActiveId/HoveredId + // are acting as filter before this has a chance to filter), but sane as soon as user tries to look into things. + // Setting OwnerCurr in SetKeyOwner() is more consistent than testing OwnerNext here: would be inconsistent with getter and other functions. + if (owner_data->OwnerCurr != owner_id) + { + if (owner_data->LockThisFrame) + return false; + if (owner_data->OwnerCurr != ImGuiKeyOwner_None) + return false; } + + return true; +} + +// _LockXXX flags are useful to lock keys away from code which is not input-owner aware. +// When using _LockXXX flags, you can use ImGuiKeyOwner_Any to lock keys from everyone. +// - SetKeyOwner(..., None) : clears owner +// - SetKeyOwner(..., Any, !Lock) : illegal (assert) +// - SetKeyOwner(..., Any or None, Lock) : set lock +void ImGui::SetKeyOwner(ImGuiKey key, ImGuiID owner_id, ImGuiInputFlags flags) +{ + IM_ASSERT(IsNamedKeyOrModKey(key) && (owner_id != ImGuiKeyOwner_Any || (flags & (ImGuiInputFlags_LockThisFrame | ImGuiInputFlags_LockUntilRelease)))); // Can only use _Any with _LockXXX flags (to eat a key away without an ID to retrieve it) + IM_ASSERT((flags & ~ImGuiInputFlags_SupportedBySetKeyOwner) == 0); // Passing flags not supported by this function! + + ImGuiContext& g = *GImGui; + ImGuiKeyOwnerData* owner_data = GetKeyOwnerData(&g, key); + owner_data->OwnerCurr = owner_data->OwnerNext = owner_id; + + // We cannot lock by default as it would likely break lots of legacy code. + // In the case of using LockUntilRelease while key is not down we still lock during the frame (no key_data->Down test) + owner_data->LockUntilRelease = (flags & ImGuiInputFlags_LockUntilRelease) != 0; + owner_data->LockThisFrame = (flags & ImGuiInputFlags_LockThisFrame) != 0 || (owner_data->LockUntilRelease); +} + +// Rarely used helper +void ImGui::SetKeyOwnersForKeyChord(ImGuiKeyChord key_chord, ImGuiID owner_id, ImGuiInputFlags flags) +{ + if (key_chord & ImGuiMod_Ctrl) { SetKeyOwner(ImGuiMod_Ctrl, owner_id, flags); } + if (key_chord & ImGuiMod_Shift) { SetKeyOwner(ImGuiMod_Shift, owner_id, flags); } + if (key_chord & ImGuiMod_Alt) { SetKeyOwner(ImGuiMod_Alt, owner_id, flags); } + if (key_chord & ImGuiMod_Super) { SetKeyOwner(ImGuiMod_Super, owner_id, flags); } + if (key_chord & ImGuiMod_Shortcut) { SetKeyOwner(ImGuiMod_Shortcut, owner_id, flags); } + if (key_chord & ~ImGuiMod_Mask_) { SetKeyOwner((ImGuiKey)(key_chord & ~ImGuiMod_Mask_), owner_id, flags); } +} + +// This is more or less equivalent to: +// if (IsItemHovered() || IsItemActive()) +// SetKeyOwner(key, GetItemID()); +// Extensive uses of that (e.g. many calls for a single item) may want to manually perform the tests once and then call SetKeyOwner() multiple times. +// More advanced usage scenarios may want to call SetKeyOwner() manually based on different condition. +// Worth noting is that only one item can be hovered and only one item can be active, therefore this usage pattern doesn't need to bother with routing and priority. +void ImGui::SetItemKeyOwner(ImGuiKey key, ImGuiInputFlags flags) +{ + ImGuiContext& g = *GImGui; + ImGuiID id = g.LastItemData.ID; + if (id == 0 || (g.HoveredId != id && g.ActiveId != id)) + return; + if ((flags & ImGuiInputFlags_CondMask_) == 0) + flags |= ImGuiInputFlags_CondDefault_; + if ((g.HoveredId == id && (flags & ImGuiInputFlags_CondHovered)) || (g.ActiveId == id && (flags & ImGuiInputFlags_CondActive))) + { + IM_ASSERT((flags & ~ImGuiInputFlags_SupportedBySetItemKeyOwner) == 0); // Passing flags not supported by this function! + SetKeyOwner(key, id, flags & ~ImGuiInputFlags_CondMask_); + } +} + +bool ImGui::Shortcut(ImGuiKeyChord key_chord, ImGuiID owner_id, ImGuiInputFlags flags) +{ + ImGuiContext& g = *GImGui; + + // When using (owner_id == 0/Any): SetShortcutRouting() will use CurrentFocusScopeId and filter with this, so IsKeyPressed() is fine with he 0/Any. + if ((flags & ImGuiInputFlags_RouteMask_) == 0) + flags |= ImGuiInputFlags_RouteFocused; + if (!SetShortcutRouting(key_chord, owner_id, flags)) + return false; + + if (key_chord & ImGuiMod_Shortcut) + key_chord = ConvertShortcutMod(key_chord); + ImGuiKey mods = (ImGuiKey)(key_chord & ImGuiMod_Mask_); + if (g.IO.KeyMods != mods) + return false; + + // Special storage location for mods + ImGuiKey key = (ImGuiKey)(key_chord & ~ImGuiMod_Mask_); + if (key == ImGuiKey_None) + key = ConvertSingleModFlagToKey(&g, mods); + + if (!IsKeyPressed(key, owner_id, (flags & (ImGuiInputFlags_Repeat | (ImGuiInputFlags)ImGuiInputFlags_RepeatRateMask_)))) + return false; + IM_ASSERT((flags & ~ImGuiInputFlags_SupportedByShortcut) == 0); // Passing flags not supported by this function! + + return true; } @@ -8713,6 +9771,38 @@ bool ImGui::DebugCheckVersionAndDataLayout(const char* version, size_t sz_io, si return !error; } +// Until 1.89 (IMGUI_VERSION_NUM < 18814) it was legal to use SetCursorPos() to extend the boundary of a parent (e.g. window or table cell) +// This is causing issues and ambiguity and we need to retire that. +// See https://github.com/ocornut/imgui/issues/5548 for more details. +// [Scenario 1] +// Previously this would make the window content size ~200x200: +// Begin(...) + SetCursorScreenPos(GetCursorScreenPos() + ImVec2(200,200)) + End(); // NOT OK +// Instead, please submit an item: +// Begin(...) + SetCursorScreenPos(GetCursorScreenPos() + ImVec2(200,200)) + Dummy(ImVec2(0,0)) + End(); // OK +// Alternative: +// Begin(...) + Dummy(ImVec2(200,200)) + End(); // OK +// [Scenario 2] +// For reference this is one of the issue what we aim to fix with this change: +// BeginGroup() + SomeItem("foobar") + SetCursorScreenPos(GetCursorScreenPos()) + EndGroup() +// The previous logic made SetCursorScreenPos(GetCursorScreenPos()) have a side-effect! It would erroneously incorporate ItemSpacing.y after the item into content size, making the group taller! +// While this code is a little twisted, no-one would expect SetXXX(GetXXX()) to have a side-effect. Using vertical alignment patterns could trigger this issue. +void ImGui::ErrorCheckUsingSetCursorPosToExtendParentBoundaries() +{ + ImGuiContext& g = *GImGui; + ImGuiWindow* window = g.CurrentWindow; + IM_ASSERT(window->DC.IsSetPos); + window->DC.IsSetPos = false; +#ifdef IMGUI_DISABLE_OBSOLETE_FUNCTIONS + if (window->DC.CursorPos.x <= window->DC.CursorMaxPos.x && window->DC.CursorPos.y <= window->DC.CursorMaxPos.y) + return; + if (window->SkipItems) + return; + IM_ASSERT(0 && "Code uses SetCursorPos()/SetCursorScreenPos() to extend window/parent boundaries. Please submit an item e.g. Dummy() to validate extent."); +#else + window->DC.CursorMaxPos = ImMax(window->DC.CursorMaxPos, window->DC.CursorPos); +#endif +} + static void ImGui::ErrorCheckNewFrameSanityChecks() { ImGuiContext& g = *GImGui; @@ -8725,6 +9815,13 @@ static void ImGui::ErrorCheckNewFrameSanityChecks() // #define IM_ASSERT(EXPR) do { if (SomeCode(EXPR)) SomeMoreCode(); } while (0) // Correct! if (true) IM_ASSERT(1); else IM_ASSERT(0); + // Emscripten backends are often imprecise in their submission of DeltaTime. (#6114, #3644) + // Ideally the Emscripten app/backend should aim to fix or smooth this value and avoid feeding zero, but we tolerate it. +#ifdef __EMSCRIPTEN__ + if (g.IO.DeltaTime <= 0.0f && g.FrameCount > 0) + g.IO.DeltaTime = 0.00001f; +#endif + // Check user data // (We pass an error message in the assert expression to make it visible to programmers who are not using a debugger, as most assert handlers display their argument) IM_ASSERT(g.Initialized); @@ -8800,9 +9897,9 @@ static void ImGui::ErrorCheckEndFrameSanityChecks() // One possible reason leading to this assert is that your backends update inputs _AFTER_ NewFrame(). // It is known that when some modal native windows called mid-frame takes focus away, some backends such as GLFW will // send key release events mid-frame. This would normally trigger this assertion and lead to sheared inputs. - // We silently accommodate for this case by ignoring/ the case where all io.KeyXXX modifiers were released (aka key_mod_flags == 0), + // We silently accommodate for this case by ignoring the case where all io.KeyXXX modifiers were released (aka key_mod_flags == 0), // while still correctly asserting on mid-frame key press events. - const ImGuiModFlags key_mods = GetMergedModFlags(); + const ImGuiKeyChord key_mods = GetMergedModsFromKeys(); IM_ASSERT((key_mods == 0 || g.IO.KeyMods == key_mods) && "Mismatching io.KeyCtrl/io.KeyShift/io.KeyAlt/io.KeySuper vs io.KeyMods"); IM_UNUSED(key_mods); @@ -8815,7 +9912,9 @@ static void ImGui::ErrorCheckEndFrameSanityChecks() { if (g.CurrentWindowStack.Size > 1) { + ImGuiWindow* window = g.CurrentWindowStack.back().Window; // <-- This window was not Ended! IM_ASSERT_USER_ERROR(g.CurrentWindowStack.Size == 1, "Mismatched Begin/BeginChild vs End/EndChild calls: did you forget to call End/EndChild?"); + IM_UNUSED(window); while (g.CurrentWindowStack.Size > 1) End(); } @@ -8912,7 +10011,12 @@ void ImGui::ErrorCheckEndWindowRecover(ImGuiErrorLogCallback log_callback, vo if (log_callback) log_callback(user_data, "Recovered from missing PopStyleVar() in '%s'", window->Name); PopStyleVar(); } - while (g.FocusScopeStack.Size > stack_sizes->SizeOfFocusScopeStack) //-V1044 + while (g.FontStack.Size > stack_sizes->SizeOfFontStack) //-V1044 + { + if (log_callback) log_callback(user_data, "Recovered from missing PopFont() in '%s'", window->Name); + PopFont(); + } + while (g.FocusScopeStack.Size > stack_sizes->SizeOfFocusScopeStack + 1) //-V1044 { if (log_callback) log_callback(user_data, "Recovered from missing PopFocusScope() in '%s'", window->Name); PopFocusScope(); @@ -8920,9 +10024,9 @@ void ImGui::ErrorCheckEndWindowRecover(ImGuiErrorLogCallback log_callback, vo } // Save current stack sizes for later compare -void ImGuiStackSizes::SetToCurrentState() +void ImGuiStackSizes::SetToContextState(ImGuiContext* ctx) { - ImGuiContext& g = *GImGui; + ImGuiContext& g = *ctx; ImGuiWindow* window = g.CurrentWindow; SizeOfIDStack = (short)window->IDStack.Size; SizeOfColorStack = (short)g.ColorStack.Size; @@ -8936,9 +10040,9 @@ void ImGuiStackSizes::SetToCurrentState() } // Compare to detect usage errors -void ImGuiStackSizes::CompareWithCurrentState() +void ImGuiStackSizes::CompareWithContextState(ImGuiContext* ctx) { - ImGuiContext& g = *GImGui; + ImGuiContext& g = *ctx; ImGuiWindow* window = g.CurrentWindow; IM_UNUSED(window); @@ -9014,7 +10118,7 @@ void ImGui::ItemSize(const ImVec2& size, float text_baseline_y) window->DC.CursorPosPrevLine.x = window->DC.CursorPos.x + size.x; window->DC.CursorPosPrevLine.y = line_y1; window->DC.CursorPos.x = IM_FLOOR(window->Pos.x + window->DC.Indent.x + window->DC.ColumnsOffset.x); // Next line - window->DC.CursorPos.y = IM_FLOOR(line_y1 + line_height + g.Style.ItemSpacing.y); // Next line + window->DC.CursorPos.y = IM_FLOOR(line_y1 + line_height + g.Style.ItemSpacing.y); // Next line window->DC.CursorMaxPos.x = ImMax(window->DC.CursorMaxPos.x, window->DC.CursorPosPrevLine.x); window->DC.CursorMaxPos.y = ImMax(window->DC.CursorMaxPos.y, window->DC.CursorPos.y - g.Style.ItemSpacing.y); //if (g.IO.KeyAlt) window->DrawList->AddCircle(window->DC.CursorMaxPos, 3.0f, IM_COL32(255,0,0,255), 4); // [DEBUG] @@ -9023,7 +10127,7 @@ void ImGui::ItemSize(const ImVec2& size, float text_baseline_y) window->DC.CurrLineSize.y = 0.0f; window->DC.PrevLineTextBaseOffset = ImMax(window->DC.CurrLineTextBaseOffset, text_baseline_y); window->DC.CurrLineTextBaseOffset = 0.0f; - window->DC.IsSameLine = false; + window->DC.IsSameLine = window->DC.IsSetPos = false; // Horizontal layout mode if (window->DC.LayoutType == ImGuiLayoutType_Horizontal) @@ -9060,40 +10164,50 @@ bool ImGui::ItemAdd(const ImRect& bb, ImGuiID id, const ImRect* nav_bb_arg, ImGu // to reach unclipped widgets. This would work if user had explicit scrolling control (e.g. mapped on a stick). // We intentionally don't check if g.NavWindow != NULL because g.NavAnyRequest should only be set when it is non null. // If we crash on a NULL g.NavWindow we need to fix the bug elsewhere. - window->DC.NavLayersActiveMaskNext |= (1 << window->DC.NavLayerCurrent); - if (g.NavId == id || g.NavAnyRequest) - if (g.NavWindow->RootWindowForNav == window->RootWindowForNav) - if (window == g.NavWindow || ((window->Flags | g.NavWindow->Flags) & ImGuiWindowFlags_NavFlattened)) - NavProcessItem(); + if (!(g.LastItemData.InFlags & ImGuiItemFlags_NoNav)) + { + window->DC.NavLayersActiveMaskNext |= (1 << window->DC.NavLayerCurrent); + if (g.NavId == id || g.NavAnyRequest) + if (g.NavWindow->RootWindowForNav == window->RootWindowForNav) + if (window == g.NavWindow || ((window->Flags | g.NavWindow->Flags) & ImGuiWindowFlags_NavFlattened)) + NavProcessItem(); + } // [DEBUG] People keep stumbling on this problem and using "" as identifier in the root of a window instead of "##something". // Empty identifier are valid and useful in a small amount of cases, but 99.9% of the time you want to use "##something". - // READ THE FAQ: https://dearimgui.org/faq + // READ THE FAQ: https://dearimgui.com/faq IM_ASSERT(id != window->ID && "Cannot have an empty ID at the root of a window. If you need an empty label, use ## and read the FAQ about how the ID Stack works!"); - - // [DEBUG] Item Picker tool, when enabling the "extended" version we perform the check in ItemAdd() -#ifdef IMGUI_DEBUG_TOOL_ITEM_PICKER_EX - if (id == g.DebugItemPickerBreakId) - { - IM_DEBUG_BREAK(); - g.DebugItemPickerBreakId = 0; - } -#endif } g.NextItemData.Flags = ImGuiNextItemDataFlags_None; #ifdef IMGUI_ENABLE_TEST_ENGINE if (id != 0) - IMGUI_TEST_ENGINE_ITEM_ADD(nav_bb_arg ? *nav_bb_arg : bb, id); + IMGUI_TEST_ENGINE_ITEM_ADD(id, g.LastItemData.NavRect, &g.LastItemData); #endif // Clipping test - const bool is_clipped = IsClippedEx(bb, id); - if (is_clipped) - return false; + // (FIXME: This is a modified copy of IsClippedEx() so we can reuse the is_rect_visible value) + //const bool is_clipped = IsClippedEx(bb, id); + //if (is_clipped) + // return false; + const bool is_rect_visible = bb.Overlaps(window->ClipRect); + if (!is_rect_visible) + if (id == 0 || (id != g.ActiveId && id != g.ActiveIdPreviousFrame && id != g.NavId)) + if (!g.LogEnabled) + return false; + + // [DEBUG] +#ifndef IMGUI_DISABLE_DEBUG_TOOLS + if (id != 0 && id == g.DebugLocateId) + DebugLocateItemResolveWithLastItem(); +#endif //if (g.IO.KeyAlt) window->DrawList->AddRect(bb.Min, bb.Max, IM_COL32(255,255,0,120)); // [DEBUG] + //if ((g.LastItemData.InFlags & ImGuiItemFlags_NoNav) == 0) + // window->DrawList->AddRect(g.LastItemData.NavRect.Min, g.LastItemData.NavRect.Max, IM_COL32(255,255,0,255)); // [DEBUG] // We need to calculate this now to take account of the current clipping rectangle (as items like Selectable may change them) + if (is_rect_visible) + g.LastItemData.StatusFlags |= ImGuiItemStatusFlags_Visible; if (IsMouseHoveringRect(bb.Min, bb.Max)) g.LastItemData.StatusFlags |= ImGuiItemStatusFlags_HoveredRect; return true; @@ -9136,11 +10250,15 @@ ImVec2 ImGui::GetCursorScreenPos() return window->DC.CursorPos; } +// 2022/08/05: Setting cursor position also extend boundaries (via modifying CursorMaxPos) used to compute window size, group size etc. +// I believe this was is a judicious choice but it's probably being relied upon (it has been the case since 1.31 and 1.50) +// It would be sane if we requested user to use SetCursorPos() + Dummy(ImVec2(0,0)) to extend CursorMaxPos... void ImGui::SetCursorScreenPos(const ImVec2& pos) { ImGuiWindow* window = GetCurrentWindow(); window->DC.CursorPos = pos; - window->DC.CursorMaxPos = ImMax(window->DC.CursorMaxPos, window->DC.CursorPos); + //window->DC.CursorMaxPos = ImMax(window->DC.CursorMaxPos, window->DC.CursorPos); + window->DC.IsSetPos = true; } // User generally sees positions in window coordinates. Internally we store CursorPos in absolute screen coordinates because it is more convenient. @@ -9167,21 +10285,24 @@ void ImGui::SetCursorPos(const ImVec2& local_pos) { ImGuiWindow* window = GetCurrentWindow(); window->DC.CursorPos = window->Pos - window->Scroll + local_pos; - window->DC.CursorMaxPos = ImMax(window->DC.CursorMaxPos, window->DC.CursorPos); + //window->DC.CursorMaxPos = ImMax(window->DC.CursorMaxPos, window->DC.CursorPos); + window->DC.IsSetPos = true; } void ImGui::SetCursorPosX(float x) { ImGuiWindow* window = GetCurrentWindow(); window->DC.CursorPos.x = window->Pos.x - window->Scroll.x + x; - window->DC.CursorMaxPos.x = ImMax(window->DC.CursorMaxPos.x, window->DC.CursorPos.x); + //window->DC.CursorMaxPos.x = ImMax(window->DC.CursorMaxPos.x, window->DC.CursorPos.x); + window->DC.IsSetPos = true; } void ImGui::SetCursorPosY(float y) { ImGuiWindow* window = GetCurrentWindow(); window->DC.CursorPos.y = window->Pos.y - window->Scroll.y + y; - window->DC.CursorMaxPos.y = ImMax(window->DC.CursorMaxPos.y, window->DC.CursorPos.y); + //window->DC.CursorMaxPos.y = ImMax(window->DC.CursorMaxPos.y, window->DC.CursorPos.y); + window->DC.IsSetPos = true; } ImVec2 ImGui::GetCursorStartPos() @@ -9398,6 +10519,9 @@ void ImGui::EndGroup() ImGuiGroupData& group_data = g.GroupStack.back(); IM_ASSERT(group_data.WindowID == window->ID); // EndGroup() in wrong window? + if (window->DC.IsSetPos) + ErrorCheckUsingSetCursorPosToExtendParentBoundaries(); + ImRect group_bb(group_data.BackupCursorPos, ImMax(window->DC.CursorMaxPos, group_data.BackupCursorPos)); window->DC.CursorPos = group_data.BackupCursorPos; @@ -9420,7 +10544,7 @@ void ImGui::EndGroup() ItemAdd(group_bb, 0, NULL, ImGuiItemFlags_NoTabStop); // If the current ActiveId was declared within the boundary of our group, we copy it to LastItemId so IsItemActive(), IsItemDeactivated() etc. will be functional on the entire group. - // It would be be neater if we replaced window.DC.LastItemId by e.g. 'bool LastItemIsActive', but would put a little more burden on individual widgets. + // It would be neater if we replaced window.DC.LastItemId by e.g. 'bool LastItemIsActive', but would put a little more burden on individual widgets. // Also if you grep for LastItemId you'll notice it is only used in that context. // (The two tests not the same because ActiveIdIsAlive is an ID itself, in order to be able to handle ActiveId being overwritten during the frame.) const bool group_contains_curr_active_id = (group_data.BackupActiveIdIsAlive != g.ActiveId) && (g.ActiveIdIsAlive == g.ActiveId) && g.ActiveId; @@ -9470,38 +10594,24 @@ static float CalcScrollEdgeSnap(float target, float snap_min, float snap_max, fl static ImVec2 CalcNextScrollFromScrollTargetAndClamp(ImGuiWindow* window) { ImVec2 scroll = window->Scroll; - if (window->ScrollTarget.x < FLT_MAX) + ImVec2 decoration_size(window->DecoOuterSizeX1 + window->DecoInnerSizeX1 + window->DecoOuterSizeX2, window->DecoOuterSizeY1 + window->DecoInnerSizeY1 + window->DecoOuterSizeY2); + for (int axis = 0; axis < 2; axis++) { - float decoration_total_width = window->ScrollbarSizes.x; - float center_x_ratio = window->ScrollTargetCenterRatio.x; - float scroll_target_x = window->ScrollTarget.x; - if (window->ScrollTargetEdgeSnapDist.x > 0.0f) + if (window->ScrollTarget[axis] < FLT_MAX) { - float snap_x_min = 0.0f; - float snap_x_max = window->ScrollMax.x + window->SizeFull.x - decoration_total_width; - scroll_target_x = CalcScrollEdgeSnap(scroll_target_x, snap_x_min, snap_x_max, window->ScrollTargetEdgeSnapDist.x, center_x_ratio); + float center_ratio = window->ScrollTargetCenterRatio[axis]; + float scroll_target = window->ScrollTarget[axis]; + if (window->ScrollTargetEdgeSnapDist[axis] > 0.0f) + { + float snap_min = 0.0f; + float snap_max = window->ScrollMax[axis] + window->SizeFull[axis] - decoration_size[axis]; + scroll_target = CalcScrollEdgeSnap(scroll_target, snap_min, snap_max, window->ScrollTargetEdgeSnapDist[axis], center_ratio); + } + scroll[axis] = scroll_target - center_ratio * (window->SizeFull[axis] - decoration_size[axis]); } - scroll.x = scroll_target_x - center_x_ratio * (window->SizeFull.x - decoration_total_width); - } - if (window->ScrollTarget.y < FLT_MAX) - { - float decoration_total_height = window->TitleBarHeight() + window->MenuBarHeight() + window->ScrollbarSizes.y; - float center_y_ratio = window->ScrollTargetCenterRatio.y; - float scroll_target_y = window->ScrollTarget.y; - if (window->ScrollTargetEdgeSnapDist.y > 0.0f) - { - float snap_y_min = 0.0f; - float snap_y_max = window->ScrollMax.y + window->SizeFull.y - decoration_total_height; - scroll_target_y = CalcScrollEdgeSnap(scroll_target_y, snap_y_min, snap_y_max, window->ScrollTargetEdgeSnapDist.y, center_y_ratio); - } - scroll.y = scroll_target_y - center_y_ratio * (window->SizeFull.y - decoration_total_height); - } - scroll.x = IM_FLOOR(ImMax(scroll.x, 0.0f)); - scroll.y = IM_FLOOR(ImMax(scroll.y, 0.0f)); - if (!window->Collapsed && !window->SkipItems) - { - scroll.x = ImMin(scroll.x, window->ScrollMax.x); - scroll.y = ImMin(scroll.y, window->ScrollMax.y); + scroll[axis] = IM_FLOOR(ImMax(scroll[axis], 0.0f)); + if (!window->Collapsed && !window->SkipItems) + scroll[axis] = ImMin(scroll[axis], window->ScrollMax[axis]); } return scroll; } @@ -9522,8 +10632,11 @@ void ImGui::ScrollToRect(ImGuiWindow* window, const ImRect& item_rect, ImGuiScro ImVec2 ImGui::ScrollToRectEx(ImGuiWindow* window, const ImRect& item_rect, ImGuiScrollFlags flags) { ImGuiContext& g = *GImGui; - ImRect window_rect(window->InnerRect.Min - ImVec2(1, 1), window->InnerRect.Max + ImVec2(1, 1)); - //GetForegroundDrawList(window)->AddRect(window_rect.Min, window_rect.Max, IM_COL32_WHITE); // [DEBUG] + ImRect scroll_rect(window->InnerRect.Min - ImVec2(1, 1), window->InnerRect.Max + ImVec2(1, 1)); + scroll_rect.Min.x = ImMin(scroll_rect.Min.x + window->DecoInnerSizeX1, scroll_rect.Max.x); + scroll_rect.Min.y = ImMin(scroll_rect.Min.y + window->DecoInnerSizeY1, scroll_rect.Max.y); + //GetForegroundDrawList(window)->AddRect(item_rect.Min, item_rect.Max, IM_COL32(255,0,0,255), 0.0f, 0, 5.0f); // [DEBUG] + //GetForegroundDrawList(window)->AddRect(scroll_rect.Min, scroll_rect.Max, IM_COL32_WHITE); // [DEBUG] // Check that only one behavior is selected per axis IM_ASSERT((flags & ImGuiScrollFlags_MaskX_) == 0 || ImIsPowerOfTwo(flags & ImGuiScrollFlags_MaskX_)); @@ -9536,35 +10649,39 @@ ImVec2 ImGui::ScrollToRectEx(ImGuiWindow* window, const ImRect& item_rect, ImGui if ((flags & ImGuiScrollFlags_MaskY_) == 0) flags |= window->Appearing ? ImGuiScrollFlags_AlwaysCenterY : ImGuiScrollFlags_KeepVisibleEdgeY; - const bool fully_visible_x = item_rect.Min.x >= window_rect.Min.x && item_rect.Max.x <= window_rect.Max.x; - const bool fully_visible_y = item_rect.Min.y >= window_rect.Min.y && item_rect.Max.y <= window_rect.Max.y; - const bool can_be_fully_visible_x = (item_rect.GetWidth() + g.Style.ItemSpacing.x * 2.0f) <= window_rect.GetWidth(); - const bool can_be_fully_visible_y = (item_rect.GetHeight() + g.Style.ItemSpacing.y * 2.0f) <= window_rect.GetHeight(); + const bool fully_visible_x = item_rect.Min.x >= scroll_rect.Min.x && item_rect.Max.x <= scroll_rect.Max.x; + const bool fully_visible_y = item_rect.Min.y >= scroll_rect.Min.y && item_rect.Max.y <= scroll_rect.Max.y; + const bool can_be_fully_visible_x = (item_rect.GetWidth() + g.Style.ItemSpacing.x * 2.0f) <= scroll_rect.GetWidth() || (window->AutoFitFramesX > 0) || (window->Flags & ImGuiWindowFlags_AlwaysAutoResize) != 0; + const bool can_be_fully_visible_y = (item_rect.GetHeight() + g.Style.ItemSpacing.y * 2.0f) <= scroll_rect.GetHeight() || (window->AutoFitFramesY > 0) || (window->Flags & ImGuiWindowFlags_AlwaysAutoResize) != 0; if ((flags & ImGuiScrollFlags_KeepVisibleEdgeX) && !fully_visible_x) { - if (item_rect.Min.x < window_rect.Min.x || !can_be_fully_visible_x) + if (item_rect.Min.x < scroll_rect.Min.x || !can_be_fully_visible_x) SetScrollFromPosX(window, item_rect.Min.x - g.Style.ItemSpacing.x - window->Pos.x, 0.0f); - else if (item_rect.Max.x >= window_rect.Max.x) + else if (item_rect.Max.x >= scroll_rect.Max.x) SetScrollFromPosX(window, item_rect.Max.x + g.Style.ItemSpacing.x - window->Pos.x, 1.0f); } else if (((flags & ImGuiScrollFlags_KeepVisibleCenterX) && !fully_visible_x) || (flags & ImGuiScrollFlags_AlwaysCenterX)) { - float target_x = can_be_fully_visible_x ? ImFloor((item_rect.Min.x + item_rect.Max.x - window->InnerRect.GetWidth()) * 0.5f) : item_rect.Min.x; - SetScrollFromPosX(window, target_x - window->Pos.x, 0.0f); + if (can_be_fully_visible_x) + SetScrollFromPosX(window, ImFloor((item_rect.Min.x + item_rect.Max.x) * 0.5f) - window->Pos.x, 0.5f); + else + SetScrollFromPosX(window, item_rect.Min.x - window->Pos.x, 0.0f); } if ((flags & ImGuiScrollFlags_KeepVisibleEdgeY) && !fully_visible_y) { - if (item_rect.Min.y < window_rect.Min.y || !can_be_fully_visible_y) + if (item_rect.Min.y < scroll_rect.Min.y || !can_be_fully_visible_y) SetScrollFromPosY(window, item_rect.Min.y - g.Style.ItemSpacing.y - window->Pos.y, 0.0f); - else if (item_rect.Max.y >= window_rect.Max.y) + else if (item_rect.Max.y >= scroll_rect.Max.y) SetScrollFromPosY(window, item_rect.Max.y + g.Style.ItemSpacing.y - window->Pos.y, 1.0f); } else if (((flags & ImGuiScrollFlags_KeepVisibleCenterY) && !fully_visible_y) || (flags & ImGuiScrollFlags_AlwaysCenterY)) { - float target_y = can_be_fully_visible_y ? ImFloor((item_rect.Min.y + item_rect.Max.y - window->InnerRect.GetHeight()) * 0.5f) : item_rect.Min.y; - SetScrollFromPosY(window, target_y - window->Pos.y, 0.0f); + if (can_be_fully_visible_y) + SetScrollFromPosY(window, ImFloor((item_rect.Min.y + item_rect.Max.y) * 0.5f) - window->Pos.y, 0.5f); + else + SetScrollFromPosY(window, item_rect.Min.y - window->Pos.y, 0.0f); } ImVec2 next_scroll = CalcNextScrollFromScrollTargetAndClamp(window); @@ -9639,7 +10756,7 @@ void ImGui::SetScrollY(float scroll_y) // - local_pos = (absolution_pos - window->Pos) // - So local_x/local_y are 0.0f for a position at the upper-left corner of a window, // and generally local_x/local_y are >(padding+decoration) && <(size-padding-decoration) when in the visible area. -// - They mostly exists because of legacy API. +// - They mostly exist because of legacy API. // Following the rules above, when trying to work with scrolling code, consider that: // - SetScrollFromPosY(0.0f) == SetScrollY(0.0f + scroll.y) == has no effect! // - SetScrollFromPosY(-scroll.y) == SetScrollY(-scroll.y + scroll.y) == SetScrollY(0.0f) == reset scroll. Of course writing SetScrollY(0.0f) directly then makes more sense @@ -9647,7 +10764,7 @@ void ImGui::SetScrollY(float scroll_y) void ImGui::SetScrollFromPosX(ImGuiWindow* window, float local_x, float center_x_ratio) { IM_ASSERT(center_x_ratio >= 0.0f && center_x_ratio <= 1.0f); - window->ScrollTarget.x = IM_FLOOR(local_x + window->Scroll.x); // Convert local position to scroll offset + window->ScrollTarget.x = IM_FLOOR(local_x - window->DecoOuterSizeX1 - window->DecoInnerSizeX1 + window->Scroll.x); // Convert local position to scroll offset window->ScrollTargetCenterRatio.x = center_x_ratio; window->ScrollTargetEdgeSnapDist.x = 0.0f; } @@ -9655,9 +10772,7 @@ void ImGui::SetScrollFromPosX(ImGuiWindow* window, float local_x, float center_x void ImGui::SetScrollFromPosY(ImGuiWindow* window, float local_y, float center_y_ratio) { IM_ASSERT(center_y_ratio >= 0.0f && center_y_ratio <= 1.0f); - const float decoration_up_height = window->TitleBarHeight() + window->MenuBarHeight(); // FIXME: Would be nice to have a more standardized access to our scrollable/client rect; - local_y -= decoration_up_height; - window->ScrollTarget.y = IM_FLOOR(local_y + window->Scroll.y); // Convert local position to scroll offset + window->ScrollTarget.y = IM_FLOOR(local_y - window->DecoOuterSizeY1 - window->DecoInnerSizeY1 + window->Scroll.y); // Convert local position to scroll offset window->ScrollTargetCenterRatio.y = center_y_ratio; window->ScrollTargetEdgeSnapDist.y = 0.0f; } @@ -9704,12 +10819,12 @@ void ImGui::SetScrollHereY(float center_y_ratio) // [SECTION] TOOLTIPS //----------------------------------------------------------------------------- -void ImGui::BeginTooltip() +bool ImGui::BeginTooltip() { - BeginTooltipEx(ImGuiTooltipFlags_None, ImGuiWindowFlags_None); + return BeginTooltipEx(ImGuiTooltipFlags_None, ImGuiWindowFlags_None); } -void ImGui::BeginTooltipEx(ImGuiTooltipFlags tooltip_flags, ImGuiWindowFlags extra_window_flags) +bool ImGui::BeginTooltipEx(ImGuiTooltipFlags tooltip_flags, ImGuiWindowFlags extra_window_flags) { ImGuiContext& g = *GImGui; @@ -9733,12 +10848,17 @@ void ImGui::BeginTooltipEx(ImGuiTooltipFlags tooltip_flags, ImGuiWindowFlags ext if (window->Active) { // Hide previous tooltip from being displayed. We can't easily "reset" the content of a window so we create a new one. - window->Hidden = true; - window->HiddenFramesCanSkipItems = 1; // FIXME: This may not be necessary? + SetWindowHiddendAndSkipItemsForCurrentFrame(window); ImFormatString(window_name, IM_ARRAYSIZE(window_name), "##Tooltip_%02d", ++g.TooltipOverrideCount); } ImGuiWindowFlags flags = ImGuiWindowFlags_Tooltip | ImGuiWindowFlags_NoInputs | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoDocking; Begin(window_name, NULL, flags | extra_window_flags); + // 2023-03-09: Added bool return value to the API, but currently always returning true. + // If this ever returns false we need to update BeginDragDropSource() accordingly. + //if (!ret) + // End(); + //return ret; + return true; } void ImGui::EndTooltip() @@ -9749,7 +10869,8 @@ void ImGui::EndTooltip() void ImGui::SetTooltipV(const char* fmt, va_list args) { - BeginTooltipEx(ImGuiTooltipFlags_OverridePreviousTooltip, ImGuiWindowFlags_None); + if (!BeginTooltipEx(ImGuiTooltipFlags_OverridePreviousTooltip, ImGuiWindowFlags_None)) + return; TextV(fmt, args); EndTooltip(); } @@ -9807,6 +10928,7 @@ bool ImGui::IsPopupOpen(const char* str_id, ImGuiPopupFlags popup_flags) return IsPopupOpen(id, popup_flags); } +// Also see FindBlockingModal(NULL) ImGuiWindow* ImGui::GetTopMostPopupModal() { ImGuiContext& g = *GImGui; @@ -9817,6 +10939,7 @@ ImGuiWindow* ImGui::GetTopMostPopupModal() return NULL; } +// See Demo->Stacked Modal to confirm what this is for. ImGuiWindow* ImGui::GetTopMostAndVisiblePopupModal() { ImGuiContext& g = *GImGui; @@ -9830,7 +10953,9 @@ ImGuiWindow* ImGui::GetTopMostAndVisiblePopupModal() void ImGui::OpenPopup(const char* str_id, ImGuiPopupFlags popup_flags) { ImGuiContext& g = *GImGui; - OpenPopupEx(g.CurrentWindow->GetID(str_id), popup_flags); + ImGuiID id = g.CurrentWindow->GetID(str_id); + IMGUI_DEBUG_LOG_POPUP("[popup] OpenPopup(\"%s\" -> 0x%08X)\n", str_id, id); + OpenPopupEx(id, popup_flags); } void ImGui::OpenPopup(ImGuiID id, ImGuiPopupFlags popup_flags) @@ -9849,19 +10974,19 @@ void ImGui::OpenPopupEx(ImGuiID id, ImGuiPopupFlags popup_flags) const int current_stack_size = g.BeginPopupStack.Size; if (popup_flags & ImGuiPopupFlags_NoOpenOverExistingPopup) - if (IsPopupOpen(0u, ImGuiPopupFlags_AnyPopupId)) + if (IsPopupOpen((ImGuiID)0, ImGuiPopupFlags_AnyPopupId)) return; ImGuiPopupData popup_ref; // Tagged as new ref as Window will be set back to NULL if we write this into OpenPopupStack. popup_ref.PopupId = id; popup_ref.Window = NULL; - popup_ref.SourceWindow = g.NavWindow; + popup_ref.BackupNavWindow = g.NavWindow; // When popup closes focus may be restored to NavWindow (depend on window type). popup_ref.OpenFrameCount = g.FrameCount; popup_ref.OpenParentId = parent_window->IDStack.back(); popup_ref.OpenPopupPos = NavCalcPreferredRefPos(); popup_ref.OpenMousePos = IsMousePosValid(&g.IO.MousePos) ? g.IO.MousePos : popup_ref.OpenPopupPos; - IMGUI_DEBUG_LOG_POPUP("OpenPopupEx(0x%08X)\n", id); + IMGUI_DEBUG_LOG_POPUP("[popup] OpenPopupEx(0x%08X)\n", id); if (g.OpenPopupStack.Size < current_stack_size + 1) { g.OpenPopupStack.push_back(popup_ref); @@ -9931,7 +11056,7 @@ void ImGui::ClosePopupsOverWindow(ImGuiWindow* ref_window, bool restore_focus_to } if (popup_count_to_keep < g.OpenPopupStack.Size) // This test is not required but it allows to set a convenient breakpoint on the statement below { - IMGUI_DEBUG_LOG_POPUP("ClosePopupsOverWindow(\"%s\") -> ClosePopupToLevel(%d)\n", ref_window->Name, popup_count_to_keep); + IMGUI_DEBUG_LOG_POPUP("[popup] ClosePopupsOverWindow(\"%s\")\n", ref_window ? ref_window->Name : ""); ClosePopupToLevel(popup_count_to_keep, restore_focus_to_window_under_popup); } } @@ -9944,7 +11069,7 @@ void ImGui::ClosePopupsExceptModals() for (popup_count_to_keep = g.OpenPopupStack.Size; popup_count_to_keep > 0; popup_count_to_keep--) { ImGuiWindow* window = g.OpenPopupStack[popup_count_to_keep - 1].Window; - if (!window || window->Flags & ImGuiWindowFlags_Modal) + if (!window || (window->Flags & ImGuiWindowFlags_Modal)) break; } if (popup_count_to_keep < g.OpenPopupStack.Size) // This test is not required but it allows to set a convenient breakpoint on the statement below @@ -9954,27 +11079,21 @@ void ImGui::ClosePopupsExceptModals() void ImGui::ClosePopupToLevel(int remaining, bool restore_focus_to_window_under_popup) { ImGuiContext& g = *GImGui; - IMGUI_DEBUG_LOG_POPUP("ClosePopupToLevel(%d), restore_focus_to_window_under_popup=%d\n", remaining, restore_focus_to_window_under_popup); + IMGUI_DEBUG_LOG_POPUP("[popup] ClosePopupToLevel(%d), restore_focus_to_window_under_popup=%d\n", remaining, restore_focus_to_window_under_popup); IM_ASSERT(remaining >= 0 && remaining < g.OpenPopupStack.Size); // Trim open popup stack - ImGuiWindow* focus_window = g.OpenPopupStack[remaining].SourceWindow; ImGuiWindow* popup_window = g.OpenPopupStack[remaining].Window; + ImGuiWindow* popup_backup_nav_window = g.OpenPopupStack[remaining].BackupNavWindow; g.OpenPopupStack.resize(remaining); if (restore_focus_to_window_under_popup) { + ImGuiWindow* focus_window = (popup_window && popup_window->Flags & ImGuiWindowFlags_ChildMenu) ? popup_window->ParentWindow : popup_backup_nav_window; if (focus_window && !focus_window->WasActive && popup_window) - { - // Fallback - FocusTopMostWindowUnderOne(popup_window, NULL); - } + FocusTopMostWindowUnderOne(popup_window, NULL, NULL, ImGuiFocusRequestFlags_RestoreFocusedChild); // Fallback else - { - if (g.NavLayer == ImGuiNavLayer_Main && focus_window) - focus_window = NavRestoreLastChildNavWindow(focus_window); - FocusWindow(focus_window); - } + FocusWindow(focus_window, (g.NavLayer == ImGuiNavLayer_Main) ? ImGuiFocusRequestFlags_RestoreFocusedChild : ImGuiFocusRequestFlags_None); } } @@ -9999,7 +11118,7 @@ void ImGui::CloseCurrentPopup() break; popup_idx--; } - IMGUI_DEBUG_LOG_POPUP("CloseCurrentPopup %d -> %d\n", g.BeginPopupStack.Size - 1, popup_idx); + IMGUI_DEBUG_LOG_POPUP("[popup] CloseCurrentPopup %d -> %d\n", g.BeginPopupStack.Size - 1, popup_idx); ClosePopupToLevel(popup_idx, true); // A common pattern is to close a popup when selecting a menu item/selectable that will open another window. @@ -10218,7 +11337,7 @@ ImVec2 ImGui::FindBestWindowPosForPopupEx(const ImVec2& ref_pos, const ImVec2& s const float avail_w = (dir == ImGuiDir_Left ? r_avoid.Min.x : r_outer.Max.x) - (dir == ImGuiDir_Right ? r_avoid.Max.x : r_outer.Min.x); const float avail_h = (dir == ImGuiDir_Up ? r_avoid.Min.y : r_outer.Max.y) - (dir == ImGuiDir_Down ? r_avoid.Max.y : r_outer.Min.y); - // If there not enough room on one axis, there's no point in positioning on a side on this axis (e.g. when not enough width, use a top/bottom position to maximize available width) + // If there's not enough room on one axis, there's no point in positioning on a side on this axis (e.g. when not enough width, use a top/bottom position to maximize available width) if (avail_w < size.x && (dir == ImGuiDir_Left || dir == ImGuiDir_Right)) continue; if (avail_h < size.y && (dir == ImGuiDir_Up || dir == ImGuiDir_Down)) @@ -10315,8 +11434,28 @@ ImVec2 ImGui::FindBestWindowPosForPopup(ImGuiWindow* window) // [SECTION] KEYBOARD/GAMEPAD NAVIGATION //----------------------------------------------------------------------------- -// FIXME-NAV: The existence of SetNavID vs SetFocusID properly needs to be clarified/reworked. -// In our terminology those should be interchangeable. Those two functions are merely a legacy artifact, so at minimum naming should be clarified. +// FIXME-NAV: The existence of SetNavID vs SetFocusID vs FocusWindow() needs to be clarified/reworked. +// In our terminology those should be interchangeable, yet right now this is super confusing. +// Those two functions are merely a legacy artifact, so at minimum naming should be clarified. + +void ImGui::SetNavWindow(ImGuiWindow* window) +{ + ImGuiContext& g = *GImGui; + if (g.NavWindow != window) + { + IMGUI_DEBUG_LOG_FOCUS("[focus] SetNavWindow(\"%s\")\n", window ? window->Name : ""); + g.NavWindow = window; + } + g.NavInitRequest = g.NavMoveSubmitted = g.NavMoveScoringItems = false; + NavUpdateAnyRequestFlag(); +} + +void ImGui::NavClearPreferredPosForAxis(ImGuiAxis axis) +{ + ImGuiContext& g = *GImGui; + g.NavWindow->RootWindowForNav->NavPreferredScoringPosRel[g.NavLayer][axis] = FLT_MAX; +} + void ImGui::SetNavID(ImGuiID id, ImGuiNavLayer nav_layer, ImGuiID focus_scope_id, const ImRect& rect_rel) { ImGuiContext& g = *GImGui; @@ -10327,6 +11466,10 @@ void ImGui::SetNavID(ImGuiID id, ImGuiNavLayer nav_layer, ImGuiID focus_scope_id g.NavFocusScopeId = focus_scope_id; g.NavWindow->NavLastIds[nav_layer] = id; g.NavWindow->NavRectRel[nav_layer] = rect_rel; + + // Clear preferred scoring position (NavMoveRequestApplyResult() will tend to restore it) + NavClearPreferredPosForAxis(ImGuiAxis_X); + NavClearPreferredPosForAxis(ImGuiAxis_Y); } void ImGui::SetFocusID(ImGuiID id, ImGuiWindow* window) @@ -10334,55 +11477,45 @@ void ImGui::SetFocusID(ImGuiID id, ImGuiWindow* window) ImGuiContext& g = *GImGui; IM_ASSERT(id != 0); - // Assume that SetFocusID() is called in the context where its window->DC.NavLayerCurrent and window->DC.NavFocusScopeIdCurrent are valid. + if (g.NavWindow != window) + SetNavWindow(window); + + // Assume that SetFocusID() is called in the context where its window->DC.NavLayerCurrent and g.CurrentFocusScopeId are valid. // Note that window may be != g.CurrentWindow (e.g. SetFocusID call in InputTextEx for multi-line text) const ImGuiNavLayer nav_layer = window->DC.NavLayerCurrent; - if (g.NavWindow != window) - g.NavInitRequest = false; - g.NavWindow = window; g.NavId = id; g.NavLayer = nav_layer; - g.NavFocusScopeId = window->DC.NavFocusScopeIdCurrent; + g.NavFocusScopeId = g.CurrentFocusScopeId; window->NavLastIds[nav_layer] = id; if (g.LastItemData.ID == id) window->NavRectRel[nav_layer] = WindowRectAbsToRel(window, g.LastItemData.NavRect); - if (g.ActiveIdSource == ImGuiInputSource_Nav) + if (g.ActiveIdSource == ImGuiInputSource_Keyboard || g.ActiveIdSource == ImGuiInputSource_Gamepad) g.NavDisableMouseHover = true; else g.NavDisableHighlight = true; + + // Clear preferred scoring position (NavMoveRequestApplyResult() will tend to restore it) + NavClearPreferredPosForAxis(ImGuiAxis_X); + NavClearPreferredPosForAxis(ImGuiAxis_Y); } -ImGuiDir ImGetDirQuadrantFromDelta(float dx, float dy) +static ImGuiDir ImGetDirQuadrantFromDelta(float dx, float dy) { if (ImFabs(dx) > ImFabs(dy)) return (dx > 0.0f) ? ImGuiDir_Right : ImGuiDir_Left; return (dy > 0.0f) ? ImGuiDir_Down : ImGuiDir_Up; } -static float inline NavScoreItemDistInterval(float a0, float a1, float b0, float b1) +static float inline NavScoreItemDistInterval(float cand_min, float cand_max, float curr_min, float curr_max) { - if (a1 < b0) - return a1 - b0; - if (b1 < a0) - return a0 - b1; + if (cand_max < curr_min) + return cand_max - curr_min; + if (curr_max < cand_min) + return cand_min - curr_max; return 0.0f; } -static void inline NavClampRectToVisibleAreaForMoveDir(ImGuiDir move_dir, ImRect& r, const ImRect& clip_rect) -{ - if (move_dir == ImGuiDir_Left || move_dir == ImGuiDir_Right) - { - r.Min.y = ImClamp(r.Min.y, clip_rect.Min.y, clip_rect.Max.y); - r.Max.y = ImClamp(r.Max.y, clip_rect.Min.y, clip_rect.Max.y); - } - else // FIXME: PageUp/PageDown are leaving move_dir == None - { - r.Min.x = ImClamp(r.Min.x, clip_rect.Min.x, clip_rect.Max.x); - r.Max.x = ImClamp(r.Max.x, clip_rect.Min.x, clip_rect.Max.x); - } -} - // Scoring function for gamepad/keyboard directional navigation. Based on https://gist.github.com/rygorous/6981057 static bool ImGui::NavScoreItem(ImGuiNavItemData* result) { @@ -10405,10 +11538,6 @@ static bool ImGui::NavScoreItem(ImGuiNavItemData* result) cand.ClipWithFull(window->ClipRect); // This allows the scored item to not overlap other candidates in the parent window } - // We perform scoring on items bounding box clipped by the current clipping rectangle on the other axis (clipping on our movement axis would give us equal scores for all clipped items) - // For example, this ensure that items in one column are not reached when moving vertically from items in another column. - NavClampRectToVisibleAreaForMoveDir(g.NavMoveClipDir, cand, window->ClipRect); - // Compute distance between boxes // FIXME-NAV: Introducing biases for vertical navigation, needs to be removed. float dbx = NavScoreItemDistInterval(cand.Min.x, cand.Max.x, curr.Min.x, curr.Max.x); @@ -10447,32 +11576,41 @@ static bool ImGui::NavScoreItem(ImGuiNavItemData* result) quadrant = (g.LastItemData.ID < g.NavId) ? ImGuiDir_Left : ImGuiDir_Right; } + const ImGuiDir move_dir = g.NavMoveDir; #if IMGUI_DEBUG_NAV_SCORING - char buf[128]; - if (IsMouseHoveringRect(cand.Min, cand.Max)) + char buf[200]; + if (g.IO.KeyCtrl) // Hold CTRL to preview score in matching quadrant. CTRL+Arrow to rotate. { - ImFormatString(buf, IM_ARRAYSIZE(buf), "dbox (%.2f,%.2f->%.4f)\ndcen (%.2f,%.2f->%.4f)\nd (%.2f,%.2f->%.4f)\nnav %c, quadrant %c", dbx, dby, dist_box, dcx, dcy, dist_center, dax, day, dist_axial, "WENS"[g.NavMoveDir], "WENS"[quadrant]); - ImDrawList* draw_list = GetForegroundDrawList(window); - draw_list->AddRect(curr.Min, curr.Max, IM_COL32(255,200,0,100)); - draw_list->AddRect(cand.Min, cand.Max, IM_COL32(255,255,0,200)); - draw_list->AddRectFilled(cand.Max - ImVec2(4, 4), cand.Max + CalcTextSize(buf) + ImVec2(4, 4), IM_COL32(40,0,0,150)); - draw_list->AddText(cand.Max, ~0U, buf); - } - else if (g.IO.KeyCtrl) // Hold to preview score in matching quadrant. Press C to rotate. - { - if (quadrant == g.NavMoveDir) + if (quadrant == move_dir) { ImFormatString(buf, IM_ARRAYSIZE(buf), "%.0f/%.0f", dist_box, dist_center); ImDrawList* draw_list = GetForegroundDrawList(window); - draw_list->AddRectFilled(cand.Min, cand.Max, IM_COL32(255, 0, 0, 200)); + draw_list->AddRectFilled(cand.Min, cand.Max, IM_COL32(255, 0, 0, 80)); + draw_list->AddRectFilled(cand.Min, cand.Min + CalcTextSize(buf), IM_COL32(255, 0, 0, 200)); draw_list->AddText(cand.Min, IM_COL32(255, 255, 255, 255), buf); } } + const bool debug_hovering = IsMouseHoveringRect(cand.Min, cand.Max); + const bool debug_tty = (g.IO.KeyCtrl && IsKeyPressed(ImGuiKey_Space)); + if (debug_hovering || debug_tty) + { + ImFormatString(buf, IM_ARRAYSIZE(buf), + "d-box (%7.3f,%7.3f) -> %7.3f\nd-center (%7.3f,%7.3f) -> %7.3f\nd-axial (%7.3f,%7.3f) -> %7.3f\nnav %c, quadrant %c", + dbx, dby, dist_box, dcx, dcy, dist_center, dax, day, dist_axial, "-WENS"[move_dir+1], "-WENS"[quadrant+1]); + if (debug_hovering) + { + ImDrawList* draw_list = GetForegroundDrawList(window); + draw_list->AddRect(curr.Min, curr.Max, IM_COL32(255, 200, 0, 100)); + draw_list->AddRect(cand.Min, cand.Max, IM_COL32(255, 255, 0, 200)); + draw_list->AddRectFilled(cand.Max - ImVec2(4, 4), cand.Max + CalcTextSize(buf) + ImVec2(4, 4), IM_COL32(40, 0, 0, 200)); + draw_list->AddText(cand.Max, ~0U, buf); + } + if (debug_tty) { IMGUI_DEBUG_LOG_NAV("id 0x%08X\n%s\n", g.LastItemData.ID, buf); } + } #endif - // Is it in the quadrant we're interesting in moving to? + // Is it in the quadrant we're interested in moving to? bool new_best = false; - const ImGuiDir move_dir = g.NavMoveDir; if (quadrant == move_dir) { // Does it beat the current best candidate? @@ -10523,11 +11661,20 @@ static void ImGui::NavApplyItemToResult(ImGuiNavItemData* result) ImGuiWindow* window = g.CurrentWindow; result->Window = window; result->ID = g.LastItemData.ID; - result->FocusScopeId = window->DC.NavFocusScopeIdCurrent; + result->FocusScopeId = g.CurrentFocusScopeId; result->InFlags = g.LastItemData.InFlags; result->RectRel = WindowRectAbsToRel(window, g.LastItemData.NavRect); } +// True when current work location may be scrolled horizontally when moving left / right. +// This is generally always true UNLESS within a column. We don't have a vertical equivalent. +void ImGui::NavUpdateCurrentWindowIsScrollPushableX() +{ + ImGuiContext& g = *GImGui; + ImGuiWindow* window = g.CurrentWindow; + window->DC.NavIsScrollPushableX = (g.CurrentTable == NULL && window->DC.CurrentColumns == NULL); +} + // We get there when either NavId == id, or when g.NavAnyRequest is set (which is updated by NavUpdateAnyRequestFlag above) // This is called after LastItemData is set. static void ImGui::NavProcessItem() @@ -10535,18 +11682,24 @@ static void ImGui::NavProcessItem() ImGuiContext& g = *GImGui; ImGuiWindow* window = g.CurrentWindow; const ImGuiID id = g.LastItemData.ID; - const ImRect nav_bb = g.LastItemData.NavRect; const ImGuiItemFlags item_flags = g.LastItemData.InFlags; + // When inside a container that isn't scrollable with Left<>Right, clip NavRect accordingly (#2221) + if (window->DC.NavIsScrollPushableX == false) + { + g.LastItemData.NavRect.Min.x = ImClamp(g.LastItemData.NavRect.Min.x, window->ClipRect.Min.x, window->ClipRect.Max.x); + g.LastItemData.NavRect.Max.x = ImClamp(g.LastItemData.NavRect.Max.x, window->ClipRect.Min.x, window->ClipRect.Max.x); + } + const ImRect nav_bb = g.LastItemData.NavRect; + // Process Init Request if (g.NavInitRequest && g.NavLayer == window->DC.NavLayerCurrent && (item_flags & ImGuiItemFlags_Disabled) == 0) { // Even if 'ImGuiItemFlags_NoNavDefaultFocus' is on (typically collapse/close button) we record the first ResultId so they can be used as a fallback const bool candidate_for_nav_default_focus = (item_flags & ImGuiItemFlags_NoNavDefaultFocus) == 0; - if (candidate_for_nav_default_focus || g.NavInitResultId == 0) + if (candidate_for_nav_default_focus || g.NavInitResult.ID == 0) { - g.NavInitResultId = id; - g.NavInitResultRectRel = WindowRectAbsToRel(window, nav_bb); + NavApplyItemToResult(&g.NavInitResult); } if (candidate_for_nav_default_focus) { @@ -10557,41 +11710,37 @@ static void ImGui::NavProcessItem() // Process Move Request (scoring for navigation) // FIXME-NAV: Consider policy for double scoring (scoring from NavScoringRect + scoring from a rect wrapped according to current wrapping policy) - if (g.NavMoveScoringItems) + if (g.NavMoveScoringItems && (item_flags & ImGuiItemFlags_Disabled) == 0) { - const bool is_tab_stop = (item_flags & ImGuiItemFlags_Inputable) && (item_flags & (ImGuiItemFlags_NoTabStop | ImGuiItemFlags_Disabled)) == 0; const bool is_tabbing = (g.NavMoveFlags & ImGuiNavMoveFlags_Tabbing) != 0; if (is_tabbing) { - if (is_tab_stop || (g.NavMoveFlags & ImGuiNavMoveFlags_FocusApi)) - NavProcessItemForTabbingRequest(id); + NavProcessItemForTabbingRequest(id, item_flags, g.NavMoveFlags); } - else if ((g.NavId != id || (g.NavMoveFlags & ImGuiNavMoveFlags_AllowCurrentNavId)) && !(item_flags & (ImGuiItemFlags_Disabled | ImGuiItemFlags_NoNav))) + else if (g.NavId != id || (g.NavMoveFlags & ImGuiNavMoveFlags_AllowCurrentNavId)) { ImGuiNavItemData* result = (window == g.NavWindow) ? &g.NavMoveResultLocal : &g.NavMoveResultOther; - if (!is_tabbing) - { - if (NavScoreItem(result)) - NavApplyItemToResult(result); + if (NavScoreItem(result)) + NavApplyItemToResult(result); - // Features like PageUp/PageDown need to maintain a separate score for the visible set of items. - const float VISIBLE_RATIO = 0.70f; - if ((g.NavMoveFlags & ImGuiNavMoveFlags_AlsoScoreVisibleSet) && window->ClipRect.Overlaps(nav_bb)) - if (ImClamp(nav_bb.Max.y, window->ClipRect.Min.y, window->ClipRect.Max.y) - ImClamp(nav_bb.Min.y, window->ClipRect.Min.y, window->ClipRect.Max.y) >= (nav_bb.Max.y - nav_bb.Min.y) * VISIBLE_RATIO) - if (NavScoreItem(&g.NavMoveResultLocalVisible)) - NavApplyItemToResult(&g.NavMoveResultLocalVisible); - } + // Features like PageUp/PageDown need to maintain a separate score for the visible set of items. + const float VISIBLE_RATIO = 0.70f; + if ((g.NavMoveFlags & ImGuiNavMoveFlags_AlsoScoreVisibleSet) && window->ClipRect.Overlaps(nav_bb)) + if (ImClamp(nav_bb.Max.y, window->ClipRect.Min.y, window->ClipRect.Max.y) - ImClamp(nav_bb.Min.y, window->ClipRect.Min.y, window->ClipRect.Max.y) >= (nav_bb.Max.y - nav_bb.Min.y) * VISIBLE_RATIO) + if (NavScoreItem(&g.NavMoveResultLocalVisible)) + NavApplyItemToResult(&g.NavMoveResultLocalVisible); } } - // Update window-relative bounding box of navigated item + // Update information for currently focused/navigated item if (g.NavId == id) { - g.NavWindow = window; // Always refresh g.NavWindow, because some operations such as FocusItem() don't have a window. + if (g.NavWindow != window) + SetNavWindow(window); // Always refresh g.NavWindow, because some operations such as FocusItem() may not have a window. g.NavLayer = window->DC.NavLayerCurrent; - g.NavFocusScopeId = window->DC.NavFocusScopeIdCurrent; + g.NavFocusScopeId = g.CurrentFocusScopeId; g.NavIdIsAlive = true; - window->NavRectRel[window->DC.NavLayerCurrent] = WindowRectAbsToRel(window, nav_bb); // Store item bounding box (relative to window position) + window->NavRectRel[window->DC.NavLayerCurrent] = WindowRectAbsToRel(window, nav_bb); // Store item bounding box (relative to window position) } } @@ -10602,18 +11751,31 @@ static void ImGui::NavProcessItem() // - Case 3: tab forward wrap: set result to first eligible item (preemptively), on ref id set counter, on next frame if counter hasn't elapsed store result. // FIXME-TABBING: Could be done as a next-frame forwarded request // - Case 4: tab backward: store all results, on ref id pick prev, stop storing // - Case 5: tab backward wrap: store all results, on ref id if no result keep storing until last // FIXME-TABBING: Could be done as next-frame forwarded requested -void ImGui::NavProcessItemForTabbingRequest(ImGuiID id) +void ImGui::NavProcessItemForTabbingRequest(ImGuiID id, ImGuiItemFlags item_flags, ImGuiNavMoveFlags move_flags) { ImGuiContext& g = *GImGui; + if ((move_flags & ImGuiNavMoveFlags_FocusApi) == 0) + if (g.NavLayer != g.CurrentWindow->DC.NavLayerCurrent) + return; + + // - Can always land on an item when using API call. + // - Tabbing with _NavEnableKeyboard (space/enter/arrows): goes through every item. + // - Tabbing without _NavEnableKeyboard: goes through inputable items only. + bool can_stop; + if (move_flags & ImGuiNavMoveFlags_FocusApi) + can_stop = true; + else + can_stop = (item_flags & ImGuiItemFlags_NoTabStop) == 0 && ((g.IO.ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard) || (item_flags & ImGuiItemFlags_Inputable)); + // Always store in NavMoveResultLocal (unlike directional request which uses NavMoveResultOther on sibling/flattened windows) ImGuiNavItemData* result = &g.NavMoveResultLocal; if (g.NavTabbingDir == +1) { // Tab Forward or SetKeyboardFocusHere() with >= 0 - if (g.NavTabbingResultFirst.ID == 0) + if (can_stop && g.NavTabbingResultFirst.ID == 0) NavApplyItemToResult(&g.NavTabbingResultFirst); - if (--g.NavTabbingCounter == 0) + if (can_stop && g.NavTabbingCounter > 0 && --g.NavTabbingCounter == 0) NavMoveRequestResolveWithLastItem(result); else if (g.NavId == id) g.NavTabbingCounter = 1; @@ -10629,16 +11791,18 @@ void ImGui::NavProcessItemForTabbingRequest(ImGuiID id) NavUpdateAnyRequestFlag(); } } - else + else if (can_stop) { + // Keep applying until reaching NavId NavApplyItemToResult(result); } } else if (g.NavTabbingDir == 0) { - // Tab Init - if (g.NavTabbingResultFirst.ID == 0) - NavMoveRequestResolveWithLastItem(&g.NavTabbingResultFirst); + if (can_stop && g.NavId == id) + NavMoveRequestResolveWithLastItem(result); + if (can_stop && g.NavTabbingResultFirst.ID == 0) // Tab init + NavApplyItemToResult(&g.NavTabbingResultFirst); } } @@ -10665,10 +11829,11 @@ void ImGui::NavMoveRequestSubmit(ImGuiDir move_dir, ImGuiDir clip_dir, ImGuiNavM g.NavMoveScrollFlags = scroll_flags; g.NavMoveForwardToNextFrame = false; g.NavMoveKeyMods = g.IO.KeyMods; - g.NavTabbingCounter = 0; g.NavMoveResultLocal.Clear(); g.NavMoveResultLocalVisible.Clear(); g.NavMoveResultOther.Clear(); + g.NavTabbingCounter = 0; + g.NavTabbingResultFirst.Clear(); NavUpdateAnyRequestFlag(); } @@ -10705,10 +11870,12 @@ void ImGui::NavMoveRequestForward(ImGuiDir move_dir, ImGuiDir clip_dir, ImGuiNav void ImGui::NavMoveRequestTryWrapping(ImGuiWindow* window, ImGuiNavMoveFlags wrap_flags) { ImGuiContext& g = *GImGui; - IM_ASSERT(wrap_flags != 0); // Call with _WrapX, _WrapY, _LoopX, _LoopY - // In theory we should test for NavMoveRequestButNoResultYet() but there's no point doing it, NavEndFrame() will do the same test + IM_ASSERT((wrap_flags & ImGuiNavMoveFlags_WrapMask_ ) != 0 && (wrap_flags & ~ImGuiNavMoveFlags_WrapMask_) == 0); // Call with _WrapX, _WrapY, _LoopX, _LoopY + + // In theory we should test for NavMoveRequestButNoResultYet() but there's no point doing it: + // as NavEndFrame() will do the same test. It will end up calling NavUpdateCreateWrappingRequest(). if (g.NavWindow == window && g.NavMoveScoringItems && g.NavLayer == ImGuiNavLayer_Main) - g.NavMoveFlags |= wrap_flags; + g.NavMoveFlags = (g.NavMoveFlags & ~ImGuiNavMoveFlags_WrapMask_) | wrap_flags; } // FIXME: This could be replaced by updating a frame number in each window when (window == NavWindow) and (NavLayer == 0). @@ -10738,7 +11905,12 @@ void ImGui::NavRestoreLayer(ImGuiNavLayer layer) { ImGuiContext& g = *GImGui; if (layer == ImGuiNavLayer_Main) - g.NavWindow = NavRestoreLastChildNavWindow(g.NavWindow); + { + ImGuiWindow* prev_nav_window = g.NavWindow; + g.NavWindow = NavRestoreLastChildNavWindow(g.NavWindow); // FIXME-NAV: Should clear ongoing nav requests? + if (prev_nav_window) + IMGUI_DEBUG_LOG_FOCUS("[focus] NavRestoreLayer: from \"%s\" to SetNavWindow(\"%s\")\n", prev_nav_window->Name, g.NavWindow->Name); + } ImGuiWindow* window = g.NavWindow; if (window->NavLastIds[layer] != 0) { @@ -10775,7 +11947,8 @@ void ImGui::NavInitWindow(ImGuiWindow* window, bool force_reinit) if (window->Flags & ImGuiWindowFlags_NoNavInputs) { - g.NavId = g.NavFocusScopeId = 0; + g.NavId = 0; + g.NavFocusScopeId = window->NavRootFocusScopeId; return; } @@ -10785,17 +11958,16 @@ void ImGui::NavInitWindow(ImGuiWindow* window, bool force_reinit) IMGUI_DEBUG_LOG_NAV("[nav] NavInitRequest: from NavInitWindow(), init_for_nav=%d, window=\"%s\", layer=%d\n", init_for_nav, window->Name, g.NavLayer); if (init_for_nav) { - SetNavID(0, g.NavLayer, 0, ImRect()); + SetNavID(0, g.NavLayer, window->NavRootFocusScopeId, ImRect()); g.NavInitRequest = true; g.NavInitRequestFromMove = false; - g.NavInitResultId = 0; - g.NavInitResultRectRel = ImRect(); + g.NavInitResult.ID = 0; NavUpdateAnyRequestFlag(); } else { g.NavId = window->NavLastIds[0]; - g.NavFocusScopeId = 0; + g.NavFocusScopeId = window->NavRootFocusScopeId; } } @@ -10827,56 +11999,27 @@ static ImVec2 ImGui::NavCalcPreferredRefPos() } } -const char* ImGui::GetNavInputName(ImGuiNavInput n) -{ - static const char* names[] = - { - "Activate", "Cancel", "Input", "Menu", "DpadLeft", "DpadRight", "DpadUp", "DpadDown", "LStickLeft", "LStickRight", "LStickUp", "LStickDown", - "FocusPrev", "FocusNext", "TweakSlow", "TweakFast", "KeyLeft", "KeyRight", "KeyUp", "KeyDown" - }; - IM_ASSERT(IM_ARRAYSIZE(names) == ImGuiNavInput_COUNT); - IM_ASSERT(n >= 0 && n < ImGuiNavInput_COUNT); - return names[n]; -} - -float ImGui::GetNavInputAmount(ImGuiNavInput n, ImGuiNavReadMode mode) +float ImGui::GetNavTweakPressedAmount(ImGuiAxis axis) { ImGuiContext& g = *GImGui; - if (mode == ImGuiNavReadMode_Down) - return g.IO.NavInputs[n]; // Instant, read analog input (0.0f..1.0f, as provided by user) + float repeat_delay, repeat_rate; + GetTypematicRepeatRate(ImGuiInputFlags_RepeatRateNavTweak, &repeat_delay, &repeat_rate); - const float t = g.IO.NavInputsDownDuration[n]; - if (t < 0.0f && mode == ImGuiNavReadMode_Released) // Return 1.0f when just released, no repeat, ignore analog input. - return (g.IO.NavInputsDownDurationPrev[n] >= 0.0f ? 1.0f : 0.0f); - if (t < 0.0f) - return 0.0f; - if (mode == ImGuiNavReadMode_Pressed) // Return 1.0f when just pressed, no repeat, ignore analog input. - return (t == 0.0f) ? 1.0f : 0.0f; - if (mode == ImGuiNavReadMode_Repeat) - return (float)CalcTypematicRepeatAmount(t - g.IO.DeltaTime, t, g.IO.KeyRepeatDelay * 0.72f, g.IO.KeyRepeatRate * 0.80f); - if (mode == ImGuiNavReadMode_RepeatSlow) - return (float)CalcTypematicRepeatAmount(t - g.IO.DeltaTime, t, g.IO.KeyRepeatDelay * 1.25f, g.IO.KeyRepeatRate * 2.00f); - if (mode == ImGuiNavReadMode_RepeatFast) - return (float)CalcTypematicRepeatAmount(t - g.IO.DeltaTime, t, g.IO.KeyRepeatDelay * 0.72f, g.IO.KeyRepeatRate * 0.30f); - return 0.0f; -} - -ImVec2 ImGui::GetNavInputAmount2d(ImGuiNavDirSourceFlags dir_sources, ImGuiNavReadMode mode, float slow_factor, float fast_factor) -{ - ImVec2 delta(0.0f, 0.0f); - if (dir_sources & ImGuiNavDirSourceFlags_RawKeyboard) - delta += ImVec2((float)IsKeyDown(ImGuiKey_RightArrow) - (float)IsKeyDown(ImGuiKey_LeftArrow), (float)IsKeyDown(ImGuiKey_DownArrow) - (float)IsKeyDown(ImGuiKey_UpArrow)); - if (dir_sources & ImGuiNavDirSourceFlags_Keyboard) - delta += ImVec2(GetNavInputAmount(ImGuiNavInput_KeyRight_, mode) - GetNavInputAmount(ImGuiNavInput_KeyLeft_, mode), GetNavInputAmount(ImGuiNavInput_KeyDown_, mode) - GetNavInputAmount(ImGuiNavInput_KeyUp_, mode)); - if (dir_sources & ImGuiNavDirSourceFlags_PadDPad) - delta += ImVec2(GetNavInputAmount(ImGuiNavInput_DpadRight, mode) - GetNavInputAmount(ImGuiNavInput_DpadLeft, mode), GetNavInputAmount(ImGuiNavInput_DpadDown, mode) - GetNavInputAmount(ImGuiNavInput_DpadUp, mode)); - if (dir_sources & ImGuiNavDirSourceFlags_PadLStick) - delta += ImVec2(GetNavInputAmount(ImGuiNavInput_LStickRight, mode) - GetNavInputAmount(ImGuiNavInput_LStickLeft, mode), GetNavInputAmount(ImGuiNavInput_LStickDown, mode) - GetNavInputAmount(ImGuiNavInput_LStickUp, mode)); - if (slow_factor != 0.0f && IsNavInputDown(ImGuiNavInput_TweakSlow)) - delta *= slow_factor; - if (fast_factor != 0.0f && IsNavInputDown(ImGuiNavInput_TweakFast)) - delta *= fast_factor; - return delta; + ImGuiKey key_less, key_more; + if (g.NavInputSource == ImGuiInputSource_Gamepad) + { + key_less = (axis == ImGuiAxis_X) ? ImGuiKey_GamepadDpadLeft : ImGuiKey_GamepadDpadUp; + key_more = (axis == ImGuiAxis_X) ? ImGuiKey_GamepadDpadRight : ImGuiKey_GamepadDpadDown; + } + else + { + key_less = (axis == ImGuiAxis_X) ? ImGuiKey_LeftArrow : ImGuiKey_UpArrow; + key_more = (axis == ImGuiAxis_X) ? ImGuiKey_RightArrow : ImGuiKey_DownArrow; + } + float amount = (float)GetKeyPressedAmount(key_more, repeat_delay, repeat_rate) - (float)GetKeyPressedAmount(key_less, repeat_delay, repeat_rate); + if (amount != 0.0f && IsKeyDown(key_less) && IsKeyDown(key_more)) // Cancel when opposite directions are held, regardless of repeat phase + amount = 0.0f; + return amount; } static void ImGui::NavUpdate() @@ -10885,64 +12028,30 @@ static void ImGui::NavUpdate() ImGuiIO& io = g.IO; io.WantSetMousePos = false; - //if (g.NavScoringDebugCount > 0) IMGUI_DEBUG_LOG("NavScoringDebugCount %d for '%s' layer %d (Init:%d, Move:%d)\n", g.NavScoringDebugCount, g.NavWindow ? g.NavWindow->Name : "NULL", g.NavLayer, g.NavInitRequest || g.NavInitResultId != 0, g.NavMoveRequest); + //if (g.NavScoringDebugCount > 0) IMGUI_DEBUG_LOG_NAV("[nav] NavScoringDebugCount %d for '%s' layer %d (Init:%d, Move:%d)\n", g.NavScoringDebugCount, g.NavWindow ? g.NavWindow->Name : "NULL", g.NavLayer, g.NavInitRequest || g.NavInitResultId != 0, g.NavMoveRequest); - // Update Gamepad->Nav inputs mapping - // Set input source as Gamepad when buttons are pressed (as some features differs when used with Gamepad vs Keyboard) + // Set input source based on which keys are last pressed (as some features differs when used with Gamepad vs Keyboard) + // FIXME-NAV: Now that keys are separated maybe we can get rid of NavInputSource? const bool nav_gamepad_active = (io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) != 0 && (io.BackendFlags & ImGuiBackendFlags_HasGamepad) != 0; - if (nav_gamepad_active && g.IO.BackendUsingLegacyNavInputArray == false) - { - for (int n = 0; n < ImGuiNavInput_COUNT; n++) - IM_ASSERT(io.NavInputs[n] == 0.0f && "Backend needs to either only use io.AddKeyEvent()/io.AddKeyAnalogEvent(), either only fill legacy io.NavInputs[]. Not both!"); - #define NAV_MAP_KEY(_KEY, _NAV_INPUT, _ACTIVATE_NAV) do { io.NavInputs[_NAV_INPUT] = io.KeysData[_KEY - ImGuiKey_KeysData_OFFSET].AnalogValue; if (_ACTIVATE_NAV && io.NavInputs[_NAV_INPUT] > 0.0f) { g.NavInputSource = ImGuiInputSource_Gamepad; } } while (0) - NAV_MAP_KEY(ImGuiKey_GamepadFaceDown, ImGuiNavInput_Activate, true); - NAV_MAP_KEY(ImGuiKey_GamepadFaceRight, ImGuiNavInput_Cancel, true); - NAV_MAP_KEY(ImGuiKey_GamepadFaceLeft, ImGuiNavInput_Menu, true); - NAV_MAP_KEY(ImGuiKey_GamepadFaceUp, ImGuiNavInput_Input, true); - NAV_MAP_KEY(ImGuiKey_GamepadDpadLeft, ImGuiNavInput_DpadLeft, true); - NAV_MAP_KEY(ImGuiKey_GamepadDpadRight, ImGuiNavInput_DpadRight, true); - NAV_MAP_KEY(ImGuiKey_GamepadDpadUp, ImGuiNavInput_DpadUp, true); - NAV_MAP_KEY(ImGuiKey_GamepadDpadDown, ImGuiNavInput_DpadDown, true); - NAV_MAP_KEY(ImGuiKey_GamepadL1, ImGuiNavInput_FocusPrev, false); - NAV_MAP_KEY(ImGuiKey_GamepadR1, ImGuiNavInput_FocusNext, false); - NAV_MAP_KEY(ImGuiKey_GamepadL1, ImGuiNavInput_TweakSlow, false); - NAV_MAP_KEY(ImGuiKey_GamepadR1, ImGuiNavInput_TweakFast, false); - NAV_MAP_KEY(ImGuiKey_GamepadLStickLeft, ImGuiNavInput_LStickLeft, false); - NAV_MAP_KEY(ImGuiKey_GamepadLStickRight, ImGuiNavInput_LStickRight, false); - NAV_MAP_KEY(ImGuiKey_GamepadLStickUp, ImGuiNavInput_LStickUp, false); - NAV_MAP_KEY(ImGuiKey_GamepadLStickDown, ImGuiNavInput_LStickDown, false); - #undef NAV_MAP_KEY - } - - // Update Keyboard->Nav inputs mapping + const ImGuiKey nav_gamepad_keys_to_change_source[] = { ImGuiKey_GamepadFaceRight, ImGuiKey_GamepadFaceLeft, ImGuiKey_GamepadFaceUp, ImGuiKey_GamepadFaceDown, ImGuiKey_GamepadDpadRight, ImGuiKey_GamepadDpadLeft, ImGuiKey_GamepadDpadUp, ImGuiKey_GamepadDpadDown }; + if (nav_gamepad_active) + for (ImGuiKey key : nav_gamepad_keys_to_change_source) + if (IsKeyDown(key)) + g.NavInputSource = ImGuiInputSource_Gamepad; const bool nav_keyboard_active = (io.ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard) != 0; + const ImGuiKey nav_keyboard_keys_to_change_source[] = { ImGuiKey_Space, ImGuiKey_Enter, ImGuiKey_Escape, ImGuiKey_RightArrow, ImGuiKey_LeftArrow, ImGuiKey_UpArrow, ImGuiKey_DownArrow }; if (nav_keyboard_active) - { - #define NAV_MAP_KEY(_KEY, _NAV_INPUT) do { if (IsKeyDown(_KEY)) { io.NavInputs[_NAV_INPUT] = 1.0f; g.NavInputSource = ImGuiInputSource_Keyboard; } } while (0) - NAV_MAP_KEY(ImGuiKey_Space, ImGuiNavInput_Activate ); - NAV_MAP_KEY(ImGuiKey_Enter, ImGuiNavInput_Input ); - NAV_MAP_KEY(ImGuiKey_Escape, ImGuiNavInput_Cancel ); - NAV_MAP_KEY(ImGuiKey_LeftArrow, ImGuiNavInput_KeyLeft_ ); - NAV_MAP_KEY(ImGuiKey_RightArrow,ImGuiNavInput_KeyRight_); - NAV_MAP_KEY(ImGuiKey_UpArrow, ImGuiNavInput_KeyUp_ ); - NAV_MAP_KEY(ImGuiKey_DownArrow, ImGuiNavInput_KeyDown_ ); - if (io.KeyCtrl) - io.NavInputs[ImGuiNavInput_TweakSlow] = 1.0f; - if (io.KeyShift) - io.NavInputs[ImGuiNavInput_TweakFast] = 1.0f; - #undef NAV_MAP_KEY - } - memcpy(io.NavInputsDownDurationPrev, io.NavInputsDownDuration, sizeof(io.NavInputsDownDuration)); - for (int i = 0; i < IM_ARRAYSIZE(io.NavInputs); i++) - io.NavInputsDownDuration[i] = (io.NavInputs[i] > 0.0f) ? (io.NavInputsDownDuration[i] < 0.0f ? 0.0f : io.NavInputsDownDuration[i] + io.DeltaTime) : -1.0f; + for (ImGuiKey key : nav_keyboard_keys_to_change_source) + if (IsKeyDown(key)) + g.NavInputSource = ImGuiInputSource_Keyboard; // Process navigation init request (select first/default focus) - if (g.NavInitResultId != 0) + g.NavJustMovedToId = 0; + if (g.NavInitResult.ID != 0) NavInitRequestApplyResult(); g.NavInitRequest = false; g.NavInitRequestFromMove = false; - g.NavInitResultId = 0; - g.NavJustMovedToId = 0; + g.NavInitResult.ID = 0; // Process navigation move request if (g.NavMoveSubmitted) @@ -10975,14 +12084,14 @@ static void ImGui::NavUpdate() NavUpdateCancelRequest(); // Process manual activation request - g.NavActivateId = g.NavActivateDownId = g.NavActivatePressedId = g.NavActivateInputId = 0; + g.NavActivateId = g.NavActivateDownId = g.NavActivatePressedId = 0; g.NavActivateFlags = ImGuiActivateFlags_None; if (g.NavId != 0 && !g.NavDisableHighlight && !g.NavWindowingTarget && g.NavWindow && !(g.NavWindow->Flags & ImGuiWindowFlags_NoNavInputs)) { - bool activate_down = IsNavInputDown(ImGuiNavInput_Activate); - bool input_down = IsNavInputDown(ImGuiNavInput_Input); - bool activate_pressed = activate_down && IsNavInputTest(ImGuiNavInput_Activate, ImGuiNavReadMode_Pressed); - bool input_pressed = input_down && IsNavInputTest(ImGuiNavInput_Input, ImGuiNavReadMode_Pressed); + const bool activate_down = (nav_keyboard_active && IsKeyDown(ImGuiKey_Space)) || (nav_gamepad_active && IsKeyDown(ImGuiKey_NavGamepadActivate)); + const bool activate_pressed = activate_down && ((nav_keyboard_active && IsKeyPressed(ImGuiKey_Space, false)) || (nav_gamepad_active && IsKeyPressed(ImGuiKey_NavGamepadActivate, false))); + const bool input_down = (nav_keyboard_active && IsKeyDown(ImGuiKey_Enter)) || (nav_gamepad_active && IsKeyDown(ImGuiKey_NavGamepadInput)); + const bool input_pressed = input_down && ((nav_keyboard_active && IsKeyPressed(ImGuiKey_Enter, false)) || (nav_gamepad_active && IsKeyPressed(ImGuiKey_NavGamepadInput, false))); if (g.ActiveId == 0 && activate_pressed) { g.NavActivateId = g.NavId; @@ -10990,12 +12099,12 @@ static void ImGui::NavUpdate() } if ((g.ActiveId == 0 || g.ActiveId == g.NavId) && input_pressed) { - g.NavActivateInputId = g.NavId; + g.NavActivateId = g.NavId; g.NavActivateFlags = ImGuiActivateFlags_PreferInput; } - if ((g.ActiveId == 0 || g.ActiveId == g.NavId) && activate_down) + if ((g.ActiveId == 0 || g.ActiveId == g.NavId) && (activate_down || input_down)) g.NavActivateDownId = g.NavId; - if ((g.ActiveId == 0 || g.ActiveId == g.NavId) && activate_pressed) + if ((g.ActiveId == 0 || g.ActiveId == g.NavId) && (activate_pressed || input_pressed)) g.NavActivatePressedId = g.NavId; } if (g.NavWindow && (g.NavWindow->Flags & ImGuiWindowFlags_NoNavInputs)) @@ -11007,10 +12116,7 @@ static void ImGui::NavUpdate() // FIXME-NAV: Those should eventually be queued (unlike focus they don't cancel each others) if (g.NavNextActivateId != 0) { - if (g.NavNextActivateFlags & ImGuiActivateFlags_PreferInput) - g.NavActivateInputId = g.NavNextActivateId; - else - g.NavActivateId = g.NavActivateDownId = g.NavActivatePressedId = g.NavNextActivateId; + g.NavActivateId = g.NavActivateDownId = g.NavActivatePressedId = g.NavNextActivateId; g.NavActivateFlags = g.NavNextActivateFlags; } g.NavNextActivateId = 0; @@ -11029,7 +12135,7 @@ static void ImGui::NavUpdate() ImGuiWindow* window = g.NavWindow; const float scroll_speed = IM_ROUND(window->CalcFontSize() * 100 * io.DeltaTime); // We need round the scrolling speed because sub-pixel scroll isn't reliably supported. const ImGuiDir move_dir = g.NavMoveDir; - if (window->DC.NavLayersActiveMask == 0x00 && window->DC.NavHasScroll && move_dir != ImGuiDir_None) + if (window->DC.NavLayersActiveMask == 0x00 && window->DC.NavWindowHasScrollY && move_dir != ImGuiDir_None) { if (move_dir == ImGuiDir_Left || move_dir == ImGuiDir_Right) SetScrollX(window, ImFloor(window->Scroll.x + ((move_dir == ImGuiDir_Left) ? -1.0f : +1.0f) * scroll_speed)); @@ -11037,13 +12143,17 @@ static void ImGui::NavUpdate() SetScrollY(window, ImFloor(window->Scroll.y + ((move_dir == ImGuiDir_Up) ? -1.0f : +1.0f) * scroll_speed)); } - // *Normal* Manual scroll with NavScrollXXX keys + // *Normal* Manual scroll with LStick // Next movement request will clamp the NavId reference rectangle to the visible area, so navigation will resume within those bounds. - ImVec2 scroll_dir = GetNavInputAmount2d(ImGuiNavDirSourceFlags_PadLStick, ImGuiNavReadMode_Down, 1.0f / 10.0f, 10.0f); - if (scroll_dir.x != 0.0f && window->ScrollbarX) - SetScrollX(window, ImFloor(window->Scroll.x + scroll_dir.x * scroll_speed)); - if (scroll_dir.y != 0.0f) - SetScrollY(window, ImFloor(window->Scroll.y + scroll_dir.y * scroll_speed)); + if (nav_gamepad_active) + { + const ImVec2 scroll_dir = GetKeyMagnitude2d(ImGuiKey_GamepadLStickLeft, ImGuiKey_GamepadLStickRight, ImGuiKey_GamepadLStickUp, ImGuiKey_GamepadLStickDown); + const float tweak_factor = IsKeyDown(ImGuiKey_NavGamepadTweakSlow) ? 1.0f / 10.0f : IsKeyDown(ImGuiKey_NavGamepadTweakFast) ? 10.0f : 1.0f; + if (scroll_dir.x != 0.0f && window->ScrollbarX) + SetScrollX(window, ImFloor(window->Scroll.x + scroll_dir.x * scroll_speed * tweak_factor)); + if (scroll_dir.y != 0.0f) + SetScrollY(window, ImFloor(window->Scroll.y + scroll_dir.y * scroll_speed * tweak_factor)); + } } // Always prioritize mouse highlight if navigation is disabled @@ -11059,17 +12169,17 @@ static void ImGui::NavUpdate() { io.MousePos = io.MousePosPrev = NavCalcPreferredRefPos(); io.WantSetMousePos = true; - //IMGUI_DEBUG_LOG("SetMousePos: (%.1f,%.1f)\n", io.MousePos.x, io.MousePos.y); + //IMGUI_DEBUG_LOG_IO("SetMousePos: (%.1f,%.1f)\n", io.MousePos.x, io.MousePos.y); } // [DEBUG] g.NavScoringDebugCount = 0; #if IMGUI_DEBUG_NAV_RECTS - if (g.NavWindow) + if (ImGuiWindow* debug_window = g.NavWindow) { - ImDrawList* draw_list = GetForegroundDrawList(g.NavWindow); - if (1) { for (int layer = 0; layer < 2; layer++) { ImRect r = WindowRectRelToAbs(g.NavWindow, g.NavWindow->NavRectRel[layer]); draw_list->AddRect(r.Min, r.Max, IM_COL32(255,200,0,255)); } } // [DEBUG] - if (1) { ImU32 col = (!g.NavWindow->Hidden) ? IM_COL32(255,0,255,255) : IM_COL32(255,0,0,255); ImVec2 p = NavCalcPreferredRefPos(); char buf[32]; ImFormatString(buf, 32, "%d", g.NavLayer); draw_list->AddCircleFilled(p, 3.0f, col); draw_list->AddText(NULL, 13.0f, p + ImVec2(8,-4), col, buf); } + ImDrawList* draw_list = GetForegroundDrawList(debug_window); + int layer = g.NavLayer; /* for (int layer = 0; layer < 2; layer++)*/ { ImRect r = WindowRectRelToAbs(debug_window, debug_window->NavRectRel[layer]); draw_list->AddRect(r.Min, r.Max, IM_COL32(255, 200, 0, 255)); } + //if (1) { ImU32 col = (!debug_window->Hidden) ? IM_COL32(255,0,255,255) : IM_COL32(255,0,0,255); ImVec2 p = NavCalcPreferredRefPos(); char buf[32]; ImFormatString(buf, 32, "%d", g.NavLayer); draw_list->AddCircleFilled(p, 3.0f, col); draw_list->AddText(NULL, 13.0f, p + ImVec2(8,-4), col, buf); } } #endif } @@ -11081,20 +12191,55 @@ void ImGui::NavInitRequestApplyResult() if (!g.NavWindow) return; + ImGuiNavItemData* result = &g.NavInitResult; + if (g.NavId != result->ID) + { + g.NavJustMovedToId = result->ID; + g.NavJustMovedToFocusScopeId = result->FocusScopeId; + g.NavJustMovedToKeyMods = 0; + } + // Apply result from previous navigation init request (will typically select the first item, unless SetItemDefaultFocus() has been called) // FIXME-NAV: On _NavFlattened windows, g.NavWindow will only be updated during subsequent frame. Not a problem currently. - IMGUI_DEBUG_LOG_NAV("[nav] NavInitRequest: result NavID 0x%08X in Layer %d Window \"%s\"\n", g.NavInitResultId, g.NavLayer, g.NavWindow->Name); - SetNavID(g.NavInitResultId, g.NavLayer, 0, g.NavInitResultRectRel); + IMGUI_DEBUG_LOG_NAV("[nav] NavInitRequest: ApplyResult: NavID 0x%08X in Layer %d Window \"%s\"\n", result->ID, g.NavLayer, g.NavWindow->Name); + SetNavID(result->ID, g.NavLayer, result->FocusScopeId, result->RectRel); g.NavIdIsAlive = true; // Mark as alive from previous frame as we got a result if (g.NavInitRequestFromMove) NavRestoreHighlightAfterMove(); } +// Bias scoring rect ahead of scoring + update preferred pos (if missing) using source position +static void NavBiasScoringRect(ImRect& r, ImVec2& preferred_pos_rel, ImGuiDir move_dir, ImGuiNavMoveFlags move_flags) +{ + // Bias initial rect + ImGuiContext& g = *GImGui; + const ImVec2 rel_to_abs_offset = g.NavWindow->DC.CursorStartPos; + + // Initialize bias on departure if we don't have any. So mouse-click + arrow will record bias. + // - We default to L/U bias, so moving down from a large source item into several columns will land on left-most column. + // - But each successful move sets new bias on one axis, only cleared when using mouse. + if ((move_flags & ImGuiNavMoveFlags_Forwarded) == 0) + { + if (preferred_pos_rel.x == FLT_MAX) + preferred_pos_rel.x = ImMin(r.Min.x + 1.0f, r.Max.x) - rel_to_abs_offset.x; + if (preferred_pos_rel.y == FLT_MAX) + preferred_pos_rel.y = r.GetCenter().y - rel_to_abs_offset.y; + } + + // Apply general bias on the other axis + if ((move_dir == ImGuiDir_Up || move_dir == ImGuiDir_Down) && preferred_pos_rel.x != FLT_MAX) + r.Min.x = r.Max.x = preferred_pos_rel.x + rel_to_abs_offset.x; + else if ((move_dir == ImGuiDir_Left || move_dir == ImGuiDir_Right) && preferred_pos_rel.y != FLT_MAX) + r.Min.y = r.Max.y = preferred_pos_rel.y + rel_to_abs_offset.y; +} + void ImGui::NavUpdateCreateMoveRequest() { ImGuiContext& g = *GImGui; ImGuiIO& io = g.IO; ImGuiWindow* window = g.NavWindow; + const bool nav_gamepad_active = (io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) != 0 && (io.BackendFlags & ImGuiBackendFlags_HasGamepad) != 0; + const bool nav_keyboard_active = (io.ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard) != 0; if (g.NavMoveForwardToNextFrame && window != NULL) { @@ -11112,11 +12257,11 @@ void ImGui::NavUpdateCreateMoveRequest() g.NavMoveScrollFlags = ImGuiScrollFlags_None; if (window && !g.NavWindowingTarget && !(window->Flags & ImGuiWindowFlags_NoNavInputs)) { - const ImGuiNavReadMode read_mode = ImGuiNavReadMode_Repeat; - if (!IsActiveIdUsingNavDir(ImGuiDir_Left) && (IsNavInputTest(ImGuiNavInput_DpadLeft, read_mode) || IsNavInputTest(ImGuiNavInput_KeyLeft_, read_mode))) { g.NavMoveDir = ImGuiDir_Left; } - if (!IsActiveIdUsingNavDir(ImGuiDir_Right) && (IsNavInputTest(ImGuiNavInput_DpadRight, read_mode) || IsNavInputTest(ImGuiNavInput_KeyRight_, read_mode))) { g.NavMoveDir = ImGuiDir_Right; } - if (!IsActiveIdUsingNavDir(ImGuiDir_Up) && (IsNavInputTest(ImGuiNavInput_DpadUp, read_mode) || IsNavInputTest(ImGuiNavInput_KeyUp_, read_mode))) { g.NavMoveDir = ImGuiDir_Up; } - if (!IsActiveIdUsingNavDir(ImGuiDir_Down) && (IsNavInputTest(ImGuiNavInput_DpadDown, read_mode) || IsNavInputTest(ImGuiNavInput_KeyDown_, read_mode))) { g.NavMoveDir = ImGuiDir_Down; } + const ImGuiInputFlags repeat_mode = ImGuiInputFlags_Repeat | (ImGuiInputFlags)ImGuiInputFlags_RepeatRateNavMove; + if (!IsActiveIdUsingNavDir(ImGuiDir_Left) && ((nav_gamepad_active && IsKeyPressed(ImGuiKey_GamepadDpadLeft, ImGuiKeyOwner_None, repeat_mode)) || (nav_keyboard_active && IsKeyPressed(ImGuiKey_LeftArrow, ImGuiKeyOwner_None, repeat_mode)))) { g.NavMoveDir = ImGuiDir_Left; } + if (!IsActiveIdUsingNavDir(ImGuiDir_Right) && ((nav_gamepad_active && IsKeyPressed(ImGuiKey_GamepadDpadRight, ImGuiKeyOwner_None, repeat_mode)) || (nav_keyboard_active && IsKeyPressed(ImGuiKey_RightArrow, ImGuiKeyOwner_None, repeat_mode)))) { g.NavMoveDir = ImGuiDir_Right; } + if (!IsActiveIdUsingNavDir(ImGuiDir_Up) && ((nav_gamepad_active && IsKeyPressed(ImGuiKey_GamepadDpadUp, ImGuiKeyOwner_None, repeat_mode)) || (nav_keyboard_active && IsKeyPressed(ImGuiKey_UpArrow, ImGuiKeyOwner_None, repeat_mode)))) { g.NavMoveDir = ImGuiDir_Up; } + if (!IsActiveIdUsingNavDir(ImGuiDir_Down) && ((nav_gamepad_active && IsKeyPressed(ImGuiKey_GamepadDpadDown, ImGuiKeyOwner_None, repeat_mode)) || (nav_keyboard_active && IsKeyPressed(ImGuiKey_DownArrow, ImGuiKeyOwner_None, repeat_mode)))) { g.NavMoveDir = ImGuiDir_Down; } } g.NavMoveClipDir = g.NavMoveDir; g.NavScoringNoClipRect = ImRect(+FLT_MAX, +FLT_MAX, -FLT_MAX, -FLT_MAX); @@ -11124,7 +12269,6 @@ void ImGui::NavUpdateCreateMoveRequest() // Update PageUp/PageDown/Home/End scroll // FIXME-NAV: Consider enabling those keys even without the master ImGuiConfigFlags_NavEnableKeyboard flag? - const bool nav_keyboard_active = (io.ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard) != 0; float scoring_rect_offset_y = 0.0f; if (window && g.NavMoveDir == ImGuiDir_None && nav_keyboard_active) scoring_rect_offset_y = NavUpdatePageUpPageDown(); @@ -11134,13 +12278,15 @@ void ImGui::NavUpdateCreateMoveRequest() g.NavScoringNoClipRect.TranslateY(scoring_rect_offset_y); } - // [DEBUG] Always send a request + // [DEBUG] Always send a request when holding CTRL. Hold CTRL + Arrow change the direction. #if IMGUI_DEBUG_NAV_SCORING - if (io.KeyCtrl && IsKeyPressed(ImGuiKey_C)) - g.NavMoveDirForDebug = (ImGuiDir)((g.NavMoveDirForDebug + 1) & 3); - if (io.KeyCtrl && g.NavMoveDir == ImGuiDir_None) + //if (io.KeyCtrl && IsKeyPressed(ImGuiKey_C)) + // g.NavMoveDirForDebug = (ImGuiDir)((g.NavMoveDirForDebug + 1) & 3); + if (io.KeyCtrl) { - g.NavMoveDir = g.NavMoveDirForDebug; + if (g.NavMoveDir == ImGuiDir_None) + g.NavMoveDir = g.NavMoveDirForDebug; + g.NavMoveClipDir = g.NavMoveDir; g.NavMoveFlags |= ImGuiNavMoveFlags_DebugNoResult; } #endif @@ -11150,23 +12296,28 @@ void ImGui::NavUpdateCreateMoveRequest() if (g.NavMoveDir != ImGuiDir_None) NavMoveRequestSubmit(g.NavMoveDir, g.NavMoveClipDir, g.NavMoveFlags, g.NavMoveScrollFlags); - // Moving with no reference triggers a init request (will be used as a fallback if the direction fails to find a match) + // Moving with no reference triggers an init request (will be used as a fallback if the direction fails to find a match) if (g.NavMoveSubmitted && g.NavId == 0) { - IMGUI_DEBUG_LOG_NAV("[nav] NavInitRequest: from move, window \"%s\", layer=%d\n", g.NavWindow->Name, g.NavLayer); + IMGUI_DEBUG_LOG_NAV("[nav] NavInitRequest: from move, window \"%s\", layer=%d\n", window ? window->Name : "", g.NavLayer); g.NavInitRequest = g.NavInitRequestFromMove = true; - g.NavInitResultId = 0; + g.NavInitResult.ID = 0; g.NavDisableHighlight = false; } // When using gamepad, we project the reference nav bounding box into window visible area. - // This is to allow resuming navigation inside the visible area after doing a large amount of scrolling, since with gamepad every movements are relative - // (can't focus a visible object like we can with the mouse). + // This is to allow resuming navigation inside the visible area after doing a large amount of scrolling, + // since with gamepad all movements are relative (can't focus a visible object like we can with the mouse). if (g.NavMoveSubmitted && g.NavInputSource == ImGuiInputSource_Gamepad && g.NavLayer == ImGuiNavLayer_Main && window != NULL)// && (g.NavMoveFlags & ImGuiNavMoveFlags_Forwarded)) { bool clamp_x = (g.NavMoveFlags & (ImGuiNavMoveFlags_LoopX | ImGuiNavMoveFlags_WrapX)) == 0; bool clamp_y = (g.NavMoveFlags & (ImGuiNavMoveFlags_LoopY | ImGuiNavMoveFlags_WrapY)) == 0; ImRect inner_rect_rel = WindowRectAbsToRel(window, ImRect(window->InnerRect.Min - ImVec2(1, 1), window->InnerRect.Max + ImVec2(1, 1))); + + // Take account of changing scroll to handle triggering a new move request on a scrolling frame. (#6171) + // Otherwise 'inner_rect_rel' would be off on the move result frame. + inner_rect_rel.Translate(CalcNextScrollFromScrollTargetAndClamp(window) - window->Scroll); + if ((clamp_x || clamp_y) && !inner_rect_rel.Contains(window->NavRectRel[g.NavLayer])) { IMGUI_DEBUG_LOG_NAV("[nav] NavMoveRequest: clamp NavRectRel for gamepad move\n"); @@ -11177,7 +12328,7 @@ void ImGui::NavUpdateCreateMoveRequest() inner_rect_rel.Min.y = clamp_y ? (inner_rect_rel.Min.y + pad_y) : -FLT_MAX; inner_rect_rel.Max.y = clamp_y ? (inner_rect_rel.Max.y - pad_y) : +FLT_MAX; window->NavRectRel[g.NavLayer].ClipWithFull(inner_rect_rel); - g.NavId = g.NavFocusScopeId = 0; + g.NavId = 0; } } @@ -11188,9 +12339,9 @@ void ImGui::NavUpdateCreateMoveRequest() ImRect nav_rect_rel = !window->NavRectRel[g.NavLayer].IsInverted() ? window->NavRectRel[g.NavLayer] : ImRect(0, 0, 0, 0); scoring_rect = WindowRectRelToAbs(window, nav_rect_rel); scoring_rect.TranslateY(scoring_rect_offset_y); - scoring_rect.Min.x = ImMin(scoring_rect.Min.x + 1.0f, scoring_rect.Max.x); - scoring_rect.Max.x = scoring_rect.Min.x; - IM_ASSERT(!scoring_rect.IsInverted()); // Ensure if we have a finite, non-inverted bounding box here will allows us to remove extraneous ImFabs() calls in NavScoreItem(). + if (g.NavMoveSubmitted) + NavBiasScoringRect(scoring_rect, window->RootWindowForNav->NavPreferredScoringPosRel[g.NavLayer], g.NavMoveDir, g.NavMoveFlags); + IM_ASSERT(!scoring_rect.IsInverted()); // Ensure if we have a finite, non-inverted bounding box here will allow us to remove extraneous ImFabs() calls in NavScoreItem(). //GetForegroundDrawList()->AddRect(scoring_rect.Min, scoring_rect.Max, IM_COL32(255,200,0,255)); // [DEBUG] //if (!g.NavScoringNoClipRect.IsInverted()) { GetForegroundDrawList()->AddRect(g.NavScoringNoClipRect.Min, g.NavScoringNoClipRect.Max, IM_COL32(255, 200, 0, 255)); } // [DEBUG] } @@ -11206,7 +12357,7 @@ void ImGui::NavUpdateCreateTabbingRequest() if (window == NULL || g.NavWindowingTarget != NULL || (window->Flags & ImGuiWindowFlags_NoNavInputs)) return; - const bool tab_pressed = IsKeyPressed(ImGuiKey_Tab, true) && !IsActiveIdUsingKey(ImGuiKey_Tab) && !g.IO.KeyCtrl && !g.IO.KeyAlt; + const bool tab_pressed = IsKeyPressed(ImGuiKey_Tab, ImGuiKeyOwner_None, ImGuiInputFlags_Repeat) && !g.IO.KeyCtrl && !g.IO.KeyAlt; if (!tab_pressed) return; @@ -11214,12 +12365,14 @@ void ImGui::NavUpdateCreateTabbingRequest() // (this is ALWAYS ENABLED, regardless of ImGuiConfigFlags_NavEnableKeyboard flag!) // Initially this was designed to use counters and modulo arithmetic, but that could not work with unsubmitted items (list clipper). Instead we use a strategy close to other move requests. // See NavProcessItemForTabbingRequest() for a description of the various forward/backward tabbing cases with and without wrapping. - //// FIXME: We use (g.ActiveId == 0) but (g.NavDisableHighlight == false) might be righter once we can tab through anything - g.NavTabbingDir = g.IO.KeyShift ? -1 : (g.ActiveId == 0) ? 0 : +1; + const bool nav_keyboard_active = (g.IO.ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard) != 0; + if (nav_keyboard_active) + g.NavTabbingDir = g.IO.KeyShift ? -1 : (g.NavDisableHighlight == true && g.ActiveId == 0) ? 0 : +1; + else + g.NavTabbingDir = g.IO.KeyShift ? -1 : (g.ActiveId == 0) ? 0 : +1; ImGuiScrollFlags scroll_flags = window->Appearing ? ImGuiScrollFlags_KeepVisibleEdgeX | ImGuiScrollFlags_AlwaysCenterY : ImGuiScrollFlags_KeepVisibleEdgeX | ImGuiScrollFlags_KeepVisibleEdgeY; ImGuiDir clip_dir = (g.NavTabbingDir < 0) ? ImGuiDir_Up : ImGuiDir_Down; NavMoveRequestSubmit(ImGuiDir_None, clip_dir, ImGuiNavMoveFlags_Tabbing, scroll_flags); // FIXME-NAV: Once we refactor tabbing, add LegacyApi flag to not activate non-inputable. - g.NavTabbingResultFirst.Clear(); g.NavTabbingCounter = -1; } @@ -11236,17 +12389,20 @@ void ImGui::NavMoveRequestApplyResult() ImGuiNavItemData* result = (g.NavMoveResultLocal.ID != 0) ? &g.NavMoveResultLocal : (g.NavMoveResultOther.ID != 0) ? &g.NavMoveResultOther : NULL; // Tabbing forward wrap - if (g.NavMoveFlags & ImGuiNavMoveFlags_Tabbing) + if ((g.NavMoveFlags & ImGuiNavMoveFlags_Tabbing) && result == NULL) if ((g.NavTabbingCounter == 1 || g.NavTabbingDir == 0) && g.NavTabbingResultFirst.ID) result = &g.NavTabbingResultFirst; - // In a situation when there is no results but NavId != 0, re-enable the Navigation highlight (because g.NavId is not considered as a possible result) + // In a situation when there are no results but NavId != 0, re-enable the Navigation highlight (because g.NavId is not considered as a possible result) + const ImGuiAxis axis = (g.NavMoveDir == ImGuiDir_Up || g.NavMoveDir == ImGuiDir_Down) ? ImGuiAxis_Y : ImGuiAxis_X; if (result == NULL) { if (g.NavMoveFlags & ImGuiNavMoveFlags_Tabbing) g.NavMoveFlags |= ImGuiNavMoveFlags_DontSetNavHighlight; if (g.NavId != 0 && (g.NavMoveFlags & ImGuiNavMoveFlags_DontSetNavHighlight) == 0) NavRestoreHighlightAfterMove(); + NavClearPreferredPosForAxis(axis); // On a failed move, clear preferred pos for this axis. + IMGUI_DEBUG_LOG_NAV("[nav] NavMoveSubmitted but not led to a result!\n"); return; } @@ -11264,20 +12420,22 @@ void ImGui::NavMoveRequestApplyResult() // Scroll to keep newly navigated item fully into view. if (g.NavLayer == ImGuiNavLayer_Main) { + ImRect rect_abs = WindowRectRelToAbs(result->Window, result->RectRel); + ScrollToRectEx(result->Window, rect_abs, g.NavMoveScrollFlags); + if (g.NavMoveFlags & ImGuiNavMoveFlags_ScrollToEdgeY) { - // FIXME: Should remove this + // FIXME: Should remove this? Or make more precise: use ScrollToRectEx() with edge? float scroll_target = (g.NavMoveDir == ImGuiDir_Up) ? result->Window->ScrollMax.y : 0.0f; SetScrollY(result->Window, scroll_target); } - else - { - ImRect rect_abs = WindowRectRelToAbs(result->Window, result->RectRel); - ScrollToRectEx(result->Window, rect_abs, g.NavMoveScrollFlags); - } } - g.NavWindow = result->Window; + if (g.NavWindow != result->Window) + { + IMGUI_DEBUG_LOG_FOCUS("[focus] NavMoveRequest: SetNavWindow(\"%s\")\n", result->Window->Name); + g.NavWindow = result->Window; + } if (g.ActiveId != result->ID) ClearActiveID(); if (g.NavId != result->ID) @@ -11288,10 +12446,19 @@ void ImGui::NavMoveRequestApplyResult() g.NavJustMovedToKeyMods = g.NavMoveKeyMods; } - // Focus + // Apply new NavID/Focus IMGUI_DEBUG_LOG_NAV("[nav] NavMoveRequest: result NavID 0x%08X in Layer %d Window \"%s\"\n", result->ID, g.NavLayer, g.NavWindow->Name); + ImVec2 preferred_scoring_pos_rel = g.NavWindow->RootWindowForNav->NavPreferredScoringPosRel[g.NavLayer]; SetNavID(result->ID, g.NavLayer, result->FocusScopeId, result->RectRel); + // Restore last preferred position for current axis + // (storing in RootWindowForNav-> as the info is desirable at the beginning of a Move Request. In theory all storage should use RootWindowForNav..) + if ((g.NavMoveFlags & ImGuiNavMoveFlags_Tabbing) == 0) + { + preferred_scoring_pos_rel[axis] = result->RectRel.GetCenter()[axis]; + g.NavWindow->RootWindowForNav->NavPreferredScoringPosRel[g.NavLayer] = preferred_scoring_pos_rel; + } + // Tabbing: Activates Inputable or Focus non-Inputable if ((g.NavMoveFlags & ImGuiNavMoveFlags_Tabbing) && (result->InFlags & ImGuiItemFlags_Inputable)) { @@ -11319,14 +12486,15 @@ void ImGui::NavMoveRequestApplyResult() static void ImGui::NavUpdateCancelRequest() { ImGuiContext& g = *GImGui; - if (!IsNavInputTest(ImGuiNavInput_Cancel, ImGuiNavReadMode_Pressed)) + const bool nav_gamepad_active = (g.IO.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) != 0 && (g.IO.BackendFlags & ImGuiBackendFlags_HasGamepad) != 0; + const bool nav_keyboard_active = (g.IO.ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard) != 0; + if (!(nav_keyboard_active && IsKeyPressed(ImGuiKey_Escape, ImGuiKeyOwner_None)) && !(nav_gamepad_active && IsKeyPressed(ImGuiKey_NavGamepadCancel, ImGuiKeyOwner_None))) return; - IMGUI_DEBUG_LOG_NAV("[nav] ImGuiNavInput_Cancel\n"); + IMGUI_DEBUG_LOG_NAV("[nav] NavUpdateCancelRequest()\n"); if (g.ActiveId != 0) { - if (!IsActiveIdUsingNavInput(ImGuiNavInput_Cancel)) - ClearActiveID(); + ClearActiveID(); } else if (g.NavLayer != ImGuiNavLayer_Main) { @@ -11345,18 +12513,17 @@ static void ImGui::NavUpdateCancelRequest() SetNavID(child_window->ChildId, ImGuiNavLayer_Main, 0, WindowRectAbsToRel(parent_window, child_rect)); NavRestoreHighlightAfterMove(); } - else if (g.OpenPopupStack.Size > 0) + else if (g.OpenPopupStack.Size > 0 && g.OpenPopupStack.back().Window != NULL && !(g.OpenPopupStack.back().Window->Flags & ImGuiWindowFlags_Modal)) { // Close open popup/menu - if (!(g.OpenPopupStack.back().Window->Flags & ImGuiWindowFlags_Modal)) - ClosePopupToLevel(g.OpenPopupStack.Size - 1, true); + ClosePopupToLevel(g.OpenPopupStack.Size - 1, true); } else { // Clear NavLastId for popups but keep it for regular child window so we can leave one and come back where we were if (g.NavWindow && ((g.NavWindow->Flags & ImGuiWindowFlags_Popup) || !(g.NavWindow->Flags & ImGuiWindowFlags_ChildWindow))) g.NavWindow->NavLastIds[0] = 0; - g.NavId = g.NavFocusScopeId = 0; + g.NavId = 0; } } @@ -11371,22 +12538,22 @@ static float ImGui::NavUpdatePageUpPageDown() if ((window->Flags & ImGuiWindowFlags_NoNavInputs) || g.NavWindowingTarget != NULL) return 0.0f; - const bool page_up_held = IsKeyDown(ImGuiKey_PageUp) && !IsActiveIdUsingKey(ImGuiKey_PageUp); - const bool page_down_held = IsKeyDown(ImGuiKey_PageDown) && !IsActiveIdUsingKey(ImGuiKey_PageDown); - const bool home_pressed = IsKeyPressed(ImGuiKey_Home) && !IsActiveIdUsingKey(ImGuiKey_Home); - const bool end_pressed = IsKeyPressed(ImGuiKey_End) && !IsActiveIdUsingKey(ImGuiKey_End); + const bool page_up_held = IsKeyDown(ImGuiKey_PageUp, ImGuiKeyOwner_None); + const bool page_down_held = IsKeyDown(ImGuiKey_PageDown, ImGuiKeyOwner_None); + const bool home_pressed = IsKeyPressed(ImGuiKey_Home, ImGuiKeyOwner_None, ImGuiInputFlags_Repeat); + const bool end_pressed = IsKeyPressed(ImGuiKey_End, ImGuiKeyOwner_None, ImGuiInputFlags_Repeat); if (page_up_held == page_down_held && home_pressed == end_pressed) // Proceed if either (not both) are pressed, otherwise early out return 0.0f; if (g.NavLayer != ImGuiNavLayer_Main) NavRestoreLayer(ImGuiNavLayer_Main); - if (window->DC.NavLayersActiveMask == 0x00 && window->DC.NavHasScroll) + if (window->DC.NavLayersActiveMask == 0x00 && window->DC.NavWindowHasScrollY) { // Fallback manual-scroll when window has no navigable item - if (IsKeyPressed(ImGuiKey_PageUp, true)) + if (IsKeyPressed(ImGuiKey_PageUp, ImGuiKeyOwner_None, ImGuiInputFlags_Repeat)) SetScrollY(window, window->Scroll.y - window->InnerRect.GetHeight()); - else if (IsKeyPressed(ImGuiKey_PageDown, true)) + else if (IsKeyPressed(ImGuiKey_PageDown, ImGuiKeyOwner_None, ImGuiInputFlags_Repeat)) SetScrollY(window, window->Scroll.y + window->InnerRect.GetHeight()); else if (home_pressed) SetScrollY(window, 0.0f); @@ -11449,8 +12616,7 @@ static void ImGui::NavEndFrame() // Perform wrap-around in menus // FIXME-NAV: Wrap may need to apply a weight bias on the other axis. e.g. 4x4 grid with 2 last items missing on last item won't handle LoopY/WrapY correctly. // FIXME-NAV: Wrap (not Loop) support could be handled by the scoring function and then WrapX would function without an extra frame. - const ImGuiNavMoveFlags wanted_flags = ImGuiNavMoveFlags_WrapX | ImGuiNavMoveFlags_LoopX | ImGuiNavMoveFlags_WrapY | ImGuiNavMoveFlags_LoopY; - if (g.NavWindow && NavMoveRequestButNoResultYet() && (g.NavMoveFlags & wanted_flags) && (g.NavMoveFlags & ImGuiNavMoveFlags_Forwarded) == 0) + if (g.NavWindow && NavMoveRequestButNoResultYet() && (g.NavMoveFlags & ImGuiNavMoveFlags_WrapMask_) && (g.NavMoveFlags & ImGuiNavMoveFlags_Forwarded) == 0) NavUpdateCreateWrappingRequest(); } @@ -11462,7 +12628,9 @@ static void ImGui::NavUpdateCreateWrappingRequest() bool do_forward = false; ImRect bb_rel = window->NavRectRel[g.NavLayer]; ImGuiDir clip_dir = g.NavMoveDir; + const ImGuiNavMoveFlags move_flags = g.NavMoveFlags; + //const ImGuiAxis move_axis = (g.NavMoveDir == ImGuiDir_Up || g.NavMoveDir == ImGuiDir_Down) ? ImGuiAxis_Y : ImGuiAxis_X; if (g.NavMoveDir == ImGuiDir_Left && (move_flags & (ImGuiNavMoveFlags_WrapX | ImGuiNavMoveFlags_LoopX))) { bb_rel.Min.x = bb_rel.Max.x = window->ContentSize.x + window->WindowPadding.x; @@ -11506,6 +12674,8 @@ static void ImGui::NavUpdateCreateWrappingRequest() if (!do_forward) return; window->NavRectRel[g.NavLayer] = bb_rel; + NavClearPreferredPosForAxis(ImGuiAxis_X); + NavClearPreferredPosForAxis(ImGuiAxis_Y); NavMoveRequestForward(g.NavMoveDir, clip_dir, move_flags, g.NavMoveScrollFlags); } @@ -11540,7 +12710,10 @@ static void NavUpdateWindowingHighlightWindow(int focus_change_dir) if (!window_target) window_target = FindWindowNavFocusable((focus_change_dir < 0) ? (g.WindowsFocusOrder.Size - 1) : 0, i_current, focus_change_dir); if (window_target) // Don't reset windowing target if there's a single window in the list + { g.NavWindowingTarget = g.NavWindowingTargetAnim = window_target; + g.NavWindowingAccumDeltaPos = g.NavWindowingAccumDeltaSize = ImVec2(0.0f, 0.0f); + } g.NavWindowingToggleLayer = false; } @@ -11556,7 +12729,7 @@ static void ImGui::NavUpdateWindowing() bool apply_toggle_layer = false; ImGuiWindow* modal_window = GetTopMostPopupModal(); - bool allow_windowing = (modal_window == NULL); + bool allow_windowing = (modal_window == NULL); // FIXME: This prevent CTRL+TAB from being usable with windows that are inside the Begin-stack of that modal. if (!allow_windowing) g.NavWindowingTarget = NULL; @@ -11569,15 +12742,25 @@ static void ImGui::NavUpdateWindowing() } // Start CTRL+Tab or Square+L/R window selection - const bool start_windowing_with_gamepad = allow_windowing && !g.NavWindowingTarget && IsNavInputTest(ImGuiNavInput_Menu, ImGuiNavReadMode_Pressed); - const bool start_windowing_with_keyboard = allow_windowing && !g.NavWindowingTarget && io.KeyCtrl && IsKeyPressed(ImGuiKey_Tab); + const ImGuiID owner_id = ImHashStr("###NavUpdateWindowing"); + const bool nav_gamepad_active = (io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) != 0 && (io.BackendFlags & ImGuiBackendFlags_HasGamepad) != 0; + const bool nav_keyboard_active = (io.ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard) != 0; + const bool keyboard_next_window = allow_windowing && g.ConfigNavWindowingKeyNext && Shortcut(g.ConfigNavWindowingKeyNext, owner_id, ImGuiInputFlags_Repeat | ImGuiInputFlags_RouteAlways); + const bool keyboard_prev_window = allow_windowing && g.ConfigNavWindowingKeyPrev && Shortcut(g.ConfigNavWindowingKeyPrev, owner_id, ImGuiInputFlags_Repeat | ImGuiInputFlags_RouteAlways); + const bool start_windowing_with_gamepad = allow_windowing && nav_gamepad_active && !g.NavWindowingTarget && IsKeyPressed(ImGuiKey_NavGamepadMenu, 0, ImGuiInputFlags_None); + const bool start_windowing_with_keyboard = allow_windowing && !g.NavWindowingTarget && (keyboard_next_window || keyboard_prev_window); // Note: enabled even without NavEnableKeyboard! if (start_windowing_with_gamepad || start_windowing_with_keyboard) if (ImGuiWindow* window = g.NavWindow ? g.NavWindow : FindWindowNavFocusable(g.WindowsFocusOrder.Size - 1, -INT_MAX, -1)) { g.NavWindowingTarget = g.NavWindowingTargetAnim = window->RootWindow; g.NavWindowingTimer = g.NavWindowingHighlightAlpha = 0.0f; + g.NavWindowingAccumDeltaPos = g.NavWindowingAccumDeltaSize = ImVec2(0.0f, 0.0f); g.NavWindowingToggleLayer = start_windowing_with_gamepad ? true : false; // Gamepad starts toggling layer g.NavInputSource = start_windowing_with_keyboard ? ImGuiInputSource_Keyboard : ImGuiInputSource_Gamepad; + + // Register ownership of our mods. Using ImGuiInputFlags_RouteGlobalHigh in the Shortcut() calls instead would probably be correct but may have more side-effects. + if (keyboard_next_window || keyboard_prev_window) + SetKeyOwnersForKeyChord((g.ConfigNavWindowingKeyNext | g.ConfigNavWindowingKeyPrev) & ImGuiMod_Mask_, owner_id); } // Gamepad update @@ -11588,7 +12771,7 @@ static void ImGui::NavUpdateWindowing() g.NavWindowingHighlightAlpha = ImMax(g.NavWindowingHighlightAlpha, ImSaturate((g.NavWindowingTimer - NAV_WINDOWING_HIGHLIGHT_DELAY) / 0.05f)); // Select window to focus - const int focus_change_dir = (int)IsNavInputTest(ImGuiNavInput_FocusPrev, ImGuiNavReadMode_RepeatSlow) - (int)IsNavInputTest(ImGuiNavInput_FocusNext, ImGuiNavReadMode_RepeatSlow); + const int focus_change_dir = (int)IsKeyPressed(ImGuiKey_GamepadL1) - (int)IsKeyPressed(ImGuiKey_GamepadR1); if (focus_change_dir != 0) { NavUpdateWindowingHighlightWindow(focus_change_dir); @@ -11596,7 +12779,7 @@ static void ImGui::NavUpdateWindowing() } // Single press toggles NavLayer, long press with L/R apply actual focus on release (until then the window was merely rendered top-most) - if (!IsNavInputDown(ImGuiNavInput_Menu)) + if (!IsKeyDown(ImGuiKey_NavGamepadMenu)) { g.NavWindowingToggleLayer &= (g.NavWindowingHighlightAlpha < 1.0f); // Once button was held long enough we don't consider it a tap-to-toggle-layer press anymore. if (g.NavWindowingToggleLayer && g.NavWindow) @@ -11611,18 +12794,19 @@ static void ImGui::NavUpdateWindowing() if (g.NavWindowingTarget && g.NavInputSource == ImGuiInputSource_Keyboard) { // Visuals only appears after a brief time after pressing TAB the first time, so that a fast CTRL+TAB doesn't add visual noise + ImGuiKeyChord shared_mods = ((g.ConfigNavWindowingKeyNext ? g.ConfigNavWindowingKeyNext : ImGuiMod_Mask_) & (g.ConfigNavWindowingKeyPrev ? g.ConfigNavWindowingKeyPrev : ImGuiMod_Mask_)) & ImGuiMod_Mask_; + IM_ASSERT(shared_mods != 0); // Next/Prev shortcut currently needs a shared modifier to "hold", otherwise Prev actions would keep cycling between two windows. g.NavWindowingHighlightAlpha = ImMax(g.NavWindowingHighlightAlpha, ImSaturate((g.NavWindowingTimer - NAV_WINDOWING_HIGHLIGHT_DELAY) / 0.05f)); // 1.0f - if (IsKeyPressed(ImGuiKey_Tab, true)) - NavUpdateWindowingHighlightWindow(io.KeyShift ? +1 : -1); - if (!io.KeyCtrl) + if (keyboard_next_window || keyboard_prev_window) + NavUpdateWindowingHighlightWindow(keyboard_next_window ? -1 : +1); + else if ((io.KeyMods & shared_mods) != shared_mods) apply_focus_window = g.NavWindowingTarget; } // Keyboard: Press and Release ALT to toggle menu layer // - Testing that only Alt is tested prevents Alt+Shift or AltGR from toggling menu layer. // - AltGR is normally Alt+Ctrl but we can't reliably detect it (not all backends/systems/layout emit it as Alt+Ctrl). But even on keyboards without AltGR we don't want Alt+Ctrl to open menu anyway. - const bool nav_keyboard_active = (io.ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard) != 0; - if (nav_keyboard_active && IsKeyPressed(ImGuiKey_ModAlt)) + if (nav_keyboard_active && IsKeyPressed(ImGuiMod_Alt, ImGuiKeyOwner_None)) { g.NavWindowingToggleLayer = true; g.NavInputSource = ImGuiInputSource_Keyboard; @@ -11631,47 +12815,55 @@ static void ImGui::NavUpdateWindowing() { // We cancel toggling nav layer when any text has been typed (generally while holding Alt). (See #370) // We cancel toggling nav layer when other modifiers are pressed. (See #4439) - if (io.InputQueueCharacters.Size > 0 || io.KeyCtrl || io.KeyShift || io.KeySuper) + // We cancel toggling nav layer if an owner has claimed the key. + if (io.InputQueueCharacters.Size > 0 || io.KeyCtrl || io.KeyShift || io.KeySuper || TestKeyOwner(ImGuiMod_Alt, ImGuiKeyOwner_None) == false) g.NavWindowingToggleLayer = false; // Apply layer toggle on release // Important: as before version <18314 we lacked an explicit IO event for focus gain/loss, we also compare mouse validity to detect old backends clearing mouse pos on focus loss. - if (IsKeyReleased(ImGuiKey_ModAlt) && g.NavWindowingToggleLayer) + if (IsKeyReleased(ImGuiMod_Alt) && g.NavWindowingToggleLayer) if (g.ActiveId == 0 || g.ActiveIdAllowOverlap) if (IsMousePosValid(&io.MousePos) == IsMousePosValid(&io.MousePosPrev)) apply_toggle_layer = true; - if (!IsKeyDown(ImGuiKey_ModAlt)) + if (!IsKeyDown(ImGuiMod_Alt)) g.NavWindowingToggleLayer = false; } // Move window if (g.NavWindowingTarget && !(g.NavWindowingTarget->Flags & ImGuiWindowFlags_NoMove)) { - ImVec2 move_delta; + ImVec2 nav_move_dir; if (g.NavInputSource == ImGuiInputSource_Keyboard && !io.KeyShift) - move_delta = GetNavInputAmount2d(ImGuiNavDirSourceFlags_RawKeyboard, ImGuiNavReadMode_Down); + nav_move_dir = GetKeyMagnitude2d(ImGuiKey_LeftArrow, ImGuiKey_RightArrow, ImGuiKey_UpArrow, ImGuiKey_DownArrow); if (g.NavInputSource == ImGuiInputSource_Gamepad) - move_delta = GetNavInputAmount2d(ImGuiNavDirSourceFlags_PadLStick, ImGuiNavReadMode_Down); - if (move_delta.x != 0.0f || move_delta.y != 0.0f) + nav_move_dir = GetKeyMagnitude2d(ImGuiKey_GamepadLStickLeft, ImGuiKey_GamepadLStickRight, ImGuiKey_GamepadLStickUp, ImGuiKey_GamepadLStickDown); + if (nav_move_dir.x != 0.0f || nav_move_dir.y != 0.0f) { const float NAV_MOVE_SPEED = 800.0f; - const float move_speed = ImFloor(NAV_MOVE_SPEED * io.DeltaTime * ImMin(io.DisplayFramebufferScale.x, io.DisplayFramebufferScale.y)); // FIXME: Doesn't handle variable framerate very well - ImGuiWindow* moving_window = g.NavWindowingTarget->RootWindowDockTree; - SetWindowPos(moving_window, moving_window->Pos + move_delta * move_speed, ImGuiCond_Always); - MarkIniSettingsDirty(moving_window); + const float move_step = NAV_MOVE_SPEED * io.DeltaTime * ImMin(io.DisplayFramebufferScale.x, io.DisplayFramebufferScale.y); + g.NavWindowingAccumDeltaPos += nav_move_dir * move_step; g.NavDisableMouseHover = true; + ImVec2 accum_floored = ImFloor(g.NavWindowingAccumDeltaPos); + if (accum_floored.x != 0.0f || accum_floored.y != 0.0f) + { + ImGuiWindow* moving_window = g.NavWindowingTarget->RootWindowDockTree; + SetWindowPos(moving_window, moving_window->Pos + accum_floored, ImGuiCond_Always); + g.NavWindowingAccumDeltaPos -= accum_floored; + } } } // Apply final focus if (apply_focus_window && (g.NavWindow == NULL || apply_focus_window != g.NavWindow->RootWindow)) { + // FIXME: Many actions here could be part of a higher-level/reused function. Why aren't they in FocusWindow() + // Investigate for each of them: ClearActiveID(), NavRestoreHighlightAfterMove(), NavRestoreLastChildNavWindow(), ClosePopupsOverWindow(), NavInitWindow() ImGuiViewport* previous_viewport = g.NavWindow ? g.NavWindow->Viewport : NULL; ClearActiveID(); NavRestoreHighlightAfterMove(); - apply_focus_window = NavRestoreLastChildNavWindow(apply_focus_window); ClosePopupsOverWindow(apply_focus_window, false); - FocusWindow(apply_focus_window); + FocusWindow(apply_focus_window, ImGuiFocusRequestFlags_RestoreFocusedChild); + apply_focus_window = g.NavWindow; if (apply_focus_window->NavLastIds[0] == 0) NavInitWindow(apply_focus_window, false); @@ -11729,12 +12921,12 @@ static void ImGui::NavUpdateWindowing() static const char* GetFallbackWindowNameForWindowingList(ImGuiWindow* window) { if (window->Flags & ImGuiWindowFlags_Popup) - return "(Popup)"; + return ImGui::LocalizeGetMsg(ImGuiLocKey_WindowingPopup); if ((window->Flags & ImGuiWindowFlags_MenuBar) && strcmp(window->Name, "##MainMenuBar") == 0) - return "(Main menu bar)"; + return ImGui::LocalizeGetMsg(ImGuiLocKey_WindowingMainMenuBar); if (window->DockNodeAsHost) - return "(Dock node)"; - return "(Untitled)"; + return "(Dock node)"; // Not normally shown to user. + return ImGui::LocalizeGetMsg(ImGuiLocKey_WindowingUntitled); } // Overlay displayed when using CTRL+TAB. Called by EndFrame(). @@ -11773,6 +12965,12 @@ void ImGui::NavUpdateWindowingOverlay() // [SECTION] DRAG AND DROP //----------------------------------------------------------------------------- +bool ImGui::IsDragDropActive() +{ + ImGuiContext& g = *GImGui; + return g.DragDropActive; +} + void ImGui::ClearDragDrop() { ImGuiContext& g = *GImGui; @@ -11858,7 +13056,7 @@ bool ImGui::BeginDragDropSource(ImGuiDragDropFlags flags) source_drag_active = IsMouseDragging(mouse_button); // Disable navigation and key inputs while dragging + cancel existing request if any - SetActiveIdUsingNavAndKeys(); + SetActiveIdUsingAllKeyboardKeys(); } else { @@ -11889,13 +13087,12 @@ bool ImGui::BeginDragDropSource(ImGuiDragDropFlags flags) { // Target can request the Source to not display its tooltip (we use a dedicated flag to make this request explicit) // We unfortunately can't just modify the source flags and skip the call to BeginTooltip, as caller may be emitting contents. - BeginTooltip(); + bool ret = BeginTooltip(); + IM_ASSERT(ret); // FIXME-NEWBEGIN: If this ever becomes false, we need to Begin("##Hidden", NULL, ImGuiWindowFlags_NoSavedSettings) + SetWindowHiddendAndSkipItemsForCurrentFrame(). + IM_UNUSED(ret); + if (g.DragDropAcceptIdPrev && (g.DragDropAcceptFlags & ImGuiDragDropFlags_AcceptNoPreviewTooltip)) - { - ImGuiWindow* tooltip_window = g.CurrentWindow; - tooltip_window->Hidden = tooltip_window->SkipItems = true; - tooltip_window->HiddenFramesCanSkipItems = 1; - } + SetWindowHiddendAndSkipItemsForCurrentFrame(g.CurrentWindow); } if (!(flags & ImGuiDragDropFlags_SourceNoDisableHover) && !(flags & ImGuiDragDropFlags_SourceExtern)) @@ -11990,7 +13187,7 @@ bool ImGui::BeginDragDropTargetCustom(const ImRect& bb, ImGuiID id) } // We don't use BeginDragDropTargetCustom() and duplicate its code because: -// 1) we use LastItemRectHoveredRect which handles items that pushes a temporarily clip rectangle in their code. Calling BeginDragDropTargetCustom(LastItemRect) would not handle them. +// 1) we use LastItemRectHoveredRect which handles items that push a temporarily clip rectangle in their code. Calling BeginDragDropTargetCustom(LastItemRect) would not handle them. // 2) and it's faster. as this code may be very frequently called, we want to early out as fast as we can. // Also note how the HoveredWindow test is positioned differently in both functions (in both functions we optimize for the cheapest early out case) bool ImGui::BeginDragDropTarget() @@ -12044,41 +13241,51 @@ const ImGuiPayload* ImGui::AcceptDragDropPayload(const char* type, ImGuiDragDrop const bool was_accepted_previously = (g.DragDropAcceptIdPrev == g.DragDropTargetId); ImRect r = g.DragDropTargetRect; float r_surface = r.GetWidth() * r.GetHeight(); - if (r_surface <= g.DragDropAcceptIdCurrRectSurface) - { - g.DragDropAcceptFlags = flags; - g.DragDropAcceptIdCurr = g.DragDropTargetId; - g.DragDropAcceptIdCurrRectSurface = r_surface; - } + if (r_surface > g.DragDropAcceptIdCurrRectSurface) + return NULL; + + g.DragDropAcceptFlags = flags; + g.DragDropAcceptIdCurr = g.DragDropTargetId; + g.DragDropAcceptIdCurrRectSurface = r_surface; + //IMGUI_DEBUG_LOG("AcceptDragDropPayload(): %08X: accept\n", g.DragDropTargetId); // Render default drop visuals - // FIXME-DRAGDROP: Settle on a proper default visuals for drop target. payload.Preview = was_accepted_previously; - flags |= (g.DragDropSourceFlags & ImGuiDragDropFlags_AcceptNoDrawDefaultRect); // Source can also inhibit the preview (useful for external sources that lives for 1 frame) + flags |= (g.DragDropSourceFlags & ImGuiDragDropFlags_AcceptNoDrawDefaultRect); // Source can also inhibit the preview (useful for external sources that live for 1 frame) if (!(flags & ImGuiDragDropFlags_AcceptNoDrawDefaultRect) && payload.Preview) window->DrawList->AddRect(r.Min - ImVec2(3.5f,3.5f), r.Max + ImVec2(3.5f, 3.5f), GetColorU32(ImGuiCol_DragDropTarget), 0.0f, 0, 2.0f); g.DragDropAcceptFrameCount = g.FrameCount; - payload.Delivery = was_accepted_previously && !IsMouseDown(g.DragDropMouseButton); // For extern drag sources affecting os window focus, it's easier to just test !IsMouseDown() instead of IsMouseReleased() + payload.Delivery = was_accepted_previously && !IsMouseDown(g.DragDropMouseButton); // For extern drag sources affecting OS window focus, it's easier to just test !IsMouseDown() instead of IsMouseReleased() if (!payload.Delivery && !(flags & ImGuiDragDropFlags_AcceptBeforeDelivery)) return NULL; + //IMGUI_DEBUG_LOG("AcceptDragDropPayload(): %08X: return payload\n", g.DragDropTargetId); return &payload; } +// FIXME-DRAGDROP: Settle on a proper default visuals for drop target. +void ImGui::RenderDragDropTargetRect(const ImRect& bb) +{ + GetWindowDrawList()->AddRect(bb.Min - ImVec2(3.5f, 3.5f), bb.Max + ImVec2(3.5f, 3.5f), GetColorU32(ImGuiCol_DragDropTarget), 0.0f, 0, 2.0f); +} + const ImGuiPayload* ImGui::GetDragDropPayload() { ImGuiContext& g = *GImGui; - return g.DragDropActive ? &g.DragDropPayload : NULL; + return (g.DragDropActive && g.DragDropPayload.DataFrameCount != -1) ? &g.DragDropPayload : NULL; } -// We don't really use/need this now, but added it for the sake of consistency and because we might need it later. void ImGui::EndDragDropTarget() { ImGuiContext& g = *GImGui; IM_ASSERT(g.DragDropActive); IM_ASSERT(g.DragDropWithinTarget); g.DragDropWithinTarget = false; + + // Clear drag and drop state payload right after delivery + if (g.DragDropPayload.Delivery) + ClearDragDrop(); } //----------------------------------------------------------------------------- @@ -12312,10 +13519,10 @@ void ImGui::LogButtons() #endif const bool log_to_file = Button("Log To File"); SameLine(); const bool log_to_clipboard = Button("Log To Clipboard"); SameLine(); - PushAllowKeyboardFocus(false); + PushTabStop(false); SetNextItemWidth(80.0f); SliderInt("Default Depth", &g.LogDepthToExpandDefault, 0, 9, NULL); - PopAllowKeyboardFocus(); + PopTabStop(); PopID(); // Start logging at the end of the function so that the buttons don't appear in the log @@ -12333,15 +13540,17 @@ void ImGui::LogButtons() //----------------------------------------------------------------------------- // - UpdateSettings() [Internal] // - MarkIniSettingsDirty() [Internal] -// - CreateNewWindowSettings() [Internal] -// - FindWindowSettings() [Internal] -// - FindOrCreateWindowSettings() [Internal] // - FindSettingsHandler() [Internal] // - ClearIniSettings() [Internal] // - LoadIniSettingsFromDisk() // - LoadIniSettingsFromMemory() // - SaveIniSettingsToDisk() // - SaveIniSettingsToMemory() +//----------------------------------------------------------------------------- +// - CreateNewWindowSettings() [Internal] +// - FindWindowSettingsByID() [Internal] +// - FindWindowSettingsByWindow() [Internal] +// - ClearWindowSettings() [Internal] // - WindowSettingsHandler_***() [Internal] //----------------------------------------------------------------------------- @@ -12388,44 +13597,6 @@ void ImGui::MarkIniSettingsDirty(ImGuiWindow* window) g.SettingsDirtyTimer = g.IO.IniSavingRate; } -ImGuiWindowSettings* ImGui::CreateNewWindowSettings(const char* name) -{ - ImGuiContext& g = *GImGui; - -#if !IMGUI_DEBUG_INI_SETTINGS - // Skip to the "###" marker if any. We don't skip past to match the behavior of GetID() - // Preserve the full string when IMGUI_DEBUG_INI_SETTINGS is set to make .ini inspection easier. - if (const char* p = strstr(name, "###")) - name = p; -#endif - const size_t name_len = strlen(name); - - // Allocate chunk - const size_t chunk_size = sizeof(ImGuiWindowSettings) + name_len + 1; - ImGuiWindowSettings* settings = g.SettingsWindows.alloc_chunk(chunk_size); - IM_PLACEMENT_NEW(settings) ImGuiWindowSettings(); - settings->ID = ImHashStr(name, name_len); - memcpy(settings->GetName(), name, name_len + 1); // Store with zero terminator - - return settings; -} - -ImGuiWindowSettings* ImGui::FindWindowSettings(ImGuiID id) -{ - ImGuiContext& g = *GImGui; - for (ImGuiWindowSettings* settings = g.SettingsWindows.begin(); settings != NULL; settings = g.SettingsWindows.next_chunk(settings)) - if (settings->ID == id) - return settings; - return NULL; -} - -ImGuiWindowSettings* ImGui::FindOrCreateWindowSettings(const char* name) -{ - if (ImGuiWindowSettings* settings = FindWindowSettings(ImHashStr(name))) - return settings; - return CreateNewWindowSettings(name); -} - void ImGui::AddSettingsHandler(const ImGuiSettingsHandler* handler) { ImGuiContext& g = *GImGui; @@ -12450,6 +13621,7 @@ ImGuiSettingsHandler* ImGui::FindSettingsHandler(const char* type_name) return NULL; } +// Clear all settings (windows, tables, docking etc.) void ImGui::ClearIniSettings() { ImGuiContext& g = *GImGui; @@ -12500,12 +13672,14 @@ bool ImGui::LoadIniSettingsFromDisk(const char* ini_filename, bool redundancy) } if (!file_data) return false; - LoadIniSettingsFromMemory(file_data, (size_t)file_data_size); + if (file_data_size > 0) + LoadIniSettingsFromMemory(file_data, (size_t)file_data_size); IM_FREE(file_data); return true; } // Zero-tolerance, no error reporting, cheap .ini parsing +// Set ini_size==0 to let us use strlen(ini_data). Do not call this function with a 0 if your buffer is actually empty! void ImGui::LoadIniSettingsFromMemory(const char* ini_data, size_t ini_size) { ImGuiContext& g = *GImGui; @@ -12634,6 +13808,65 @@ const char* ImGui::SaveIniSettingsToMemory(size_t* out_size) return g.SettingsIniData.c_str(); } +ImGuiWindowSettings* ImGui::CreateNewWindowSettings(const char* name) +{ + ImGuiContext& g = *GImGui; + +#if !IMGUI_DEBUG_INI_SETTINGS + // Skip to the "###" marker if any. We don't skip past to match the behavior of GetID() + // Preserve the full string when IMGUI_DEBUG_INI_SETTINGS is set to make .ini inspection easier. + if (const char* p = strstr(name, "###")) + name = p; +#endif + const size_t name_len = strlen(name); + + // Allocate chunk + const size_t chunk_size = sizeof(ImGuiWindowSettings) + name_len + 1; + ImGuiWindowSettings* settings = g.SettingsWindows.alloc_chunk(chunk_size); + IM_PLACEMENT_NEW(settings) ImGuiWindowSettings(); + settings->ID = ImHashStr(name, name_len); + memcpy(settings->GetName(), name, name_len + 1); // Store with zero terminator + + return settings; +} + +// We don't provide a FindWindowSettingsByName() because Docking system doesn't always hold on names. +// This is called once per window .ini entry + once per newly instantiated window. +ImGuiWindowSettings* ImGui::FindWindowSettingsByID(ImGuiID id) +{ + ImGuiContext& g = *GImGui; + for (ImGuiWindowSettings* settings = g.SettingsWindows.begin(); settings != NULL; settings = g.SettingsWindows.next_chunk(settings)) + if (settings->ID == id && !settings->WantDelete) + return settings; + return NULL; +} + +// This is faster if you are holding on a Window already as we don't need to perform a search. +ImGuiWindowSettings* ImGui::FindWindowSettingsByWindow(ImGuiWindow* window) +{ + ImGuiContext& g = *GImGui; + if (window->SettingsOffset != -1) + return g.SettingsWindows.ptr_from_offset(window->SettingsOffset); + return FindWindowSettingsByID(window->ID); +} + +// This will revert window to its initial state, including enabling the ImGuiCond_FirstUseEver/ImGuiCond_Once conditions once more. +void ImGui::ClearWindowSettings(const char* name) +{ + //IMGUI_DEBUG_LOG("ClearWindowSettings('%s')\n", name); + ImGuiContext& g = *GImGui; + ImGuiWindow* window = FindWindowByName(name); + if (window != NULL) + { + window->Flags |= ImGuiWindowFlags_NoSavedSettings; + InitOrLoadWindowSettings(window, NULL); + if (window->DockId != 0) + DockContextProcessUndockWindow(&g, window, true); + } + if (ImGuiWindowSettings* settings = window ? FindWindowSettingsByWindow(window) : FindWindowSettingsByID(ImHashStr(name))) + settings->WantDelete = true; +} + static void WindowSettingsHandler_ClearAll(ImGuiContext* ctx, ImGuiSettingsHandler*) { ImGuiContext& g = *ctx; @@ -12644,9 +13877,12 @@ static void WindowSettingsHandler_ClearAll(ImGuiContext* ctx, ImGuiSettingsHandl static void* WindowSettingsHandler_ReadOpen(ImGuiContext*, ImGuiSettingsHandler*, const char* name) { - ImGuiWindowSettings* settings = ImGui::FindOrCreateWindowSettings(name); - ImGuiID id = settings->ID; - *settings = ImGuiWindowSettings(); // Clear existing if recycling previous entry + ImGuiID id = ImHashStr(name); + ImGuiWindowSettings* settings = ImGui::FindWindowSettingsByID(id); + if (settings) + *settings = ImGuiWindowSettings(); // Clear existing if recycling previous entry + else + settings = ImGui::CreateNewWindowSettings(name); settings->ID = id; settings->WantApply = true; return (void*)settings; @@ -12692,7 +13928,7 @@ static void WindowSettingsHandler_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandl if (window->Flags & ImGuiWindowFlags_NoSavedSettings) continue; - ImGuiWindowSettings* settings = (window->SettingsOffset != -1) ? g.SettingsWindows.ptr_from_offset(window->SettingsOffset) : ImGui::FindWindowSettings(window->ID); + ImGuiWindowSettings* settings = ImGui::FindWindowSettingsByWindow(window); if (!settings) { settings = ImGui::CreateNewWindowSettings(window->Name); @@ -12708,12 +13944,15 @@ static void WindowSettingsHandler_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandl settings->ClassId = window->WindowClass.ClassId; settings->DockOrder = window->DockOrder; settings->Collapsed = window->Collapsed; + settings->WantDelete = false; } // Write to text buffer buf->reserve(buf->size() + g.SettingsWindows.size() * 6); // ballpark reserve for (ImGuiWindowSettings* settings = g.SettingsWindows.begin(); settings != NULL; settings = g.SettingsWindows.next_chunk(settings)) { + if (settings->WantDelete) + continue; const char* settings_name = settings->GetName(); buf->appendf("[%s][%s]\n", handler->TypeName, settings_name); if (settings->ViewportId != 0 && settings->ViewportId != ImGui::IMGUI_VIEWPORT_DEFAULT_ID) @@ -12741,6 +13980,18 @@ static void WindowSettingsHandler_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandl } +//----------------------------------------------------------------------------- +// [SECTION] LOCALIZATION +//----------------------------------------------------------------------------- + +void ImGui::LocalizeRegisterEntries(const ImGuiLocEntry* entries, int count) +{ + ImGuiContext& g = *GImGui; + for (int n = 0; n < count; n++) + g.LocalizationTable[entries[n].Key] = entries[n].Text; +} + + //----------------------------------------------------------------------------- // [SECTION] VIEWPORTS, PLATFORM WINDOWS //----------------------------------------------------------------------------- @@ -12805,7 +14056,7 @@ void ImGui::SetCurrentViewport(ImGuiWindow* current_window, ImGuiViewportP* view return; g.CurrentDpiScale = viewport ? viewport->DpiScale : 1.0f; g.CurrentViewport = viewport; - //IMGUI_DEBUG_LOG_VIEWPORT("SetCurrentViewport changed '%s' 0x%08X\n", current_window ? current_window->Name : NULL, viewport ? viewport->ID : 0); + //IMGUI_DEBUG_LOG_VIEWPORT("[viewport] SetCurrentViewport changed '%s' 0x%08X\n", current_window ? current_window->Name : NULL, viewport ? viewport->ID : 0); // Notify platform layer of viewport changes // FIXME-DPI: This is only currently used for experimenting with handling of multiple DPI @@ -12844,7 +14095,7 @@ static bool ImGui::UpdateTryMergeWindowIntoHostViewport(ImGuiWindow* window, ImG return false; if ((viewport->Flags & ImGuiViewportFlags_CanHostOtherWindows) == 0) return false; - if ((viewport->Flags & ImGuiViewportFlags_Minimized) != 0) + if ((viewport->Flags & ImGuiViewportFlags_IsMinimized) != 0) return false; if (!viewport->GetMainRect().Contains(window->Rect())) return false; @@ -12927,8 +14178,8 @@ ImGuiViewportP* ImGui::FindHoveredViewportFromPlatformWindowStack(const ImVec2& for (int n = 0; n < g.Viewports.Size; n++) { ImGuiViewportP* viewport = g.Viewports[n]; - if (!(viewport->Flags & (ImGuiViewportFlags_NoInputs | ImGuiViewportFlags_Minimized)) && viewport->GetMainRect().Contains(mouse_platform_pos)) - if (best_candidate == NULL || best_candidate->LastFrontMostStampCount < viewport->LastFrontMostStampCount) + if (!(viewport->Flags & (ImGuiViewportFlags_NoInputs | ImGuiViewportFlags_IsMinimized)) && viewport->GetMainRect().Contains(mouse_platform_pos)) + if (best_candidate == NULL || best_candidate->LastFocusedStampCount < viewport->LastFocusedStampCount) best_candidate = viewport; } return best_candidate; @@ -12942,22 +14193,71 @@ static void ImGui::UpdateViewportsNewFrame() IM_ASSERT(g.PlatformIO.Viewports.Size <= g.Viewports.Size); // Update Minimized status (we need it first in order to decide if we'll apply Pos/Size of the main viewport) + // Update Focused status const bool viewports_enabled = (g.ConfigFlagsCurrFrame & ImGuiConfigFlags_ViewportsEnable) != 0; if (viewports_enabled) { + ImGuiViewportP* focused_viewport = NULL; for (int n = 0; n < g.Viewports.Size; n++) { ImGuiViewportP* viewport = g.Viewports[n]; const bool platform_funcs_available = viewport->PlatformWindowCreated; if (g.PlatformIO.Platform_GetWindowMinimized && platform_funcs_available) { - bool minimized = g.PlatformIO.Platform_GetWindowMinimized(viewport); - if (minimized) - viewport->Flags |= ImGuiViewportFlags_Minimized; + bool is_minimized = g.PlatformIO.Platform_GetWindowMinimized(viewport); + if (is_minimized) + viewport->Flags |= ImGuiViewportFlags_IsMinimized; else - viewport->Flags &= ~ImGuiViewportFlags_Minimized; + viewport->Flags &= ~ImGuiViewportFlags_IsMinimized; + } + + // Update our implicit z-order knowledge of platform windows, which is used when the backend cannot provide io.MouseHoveredViewport. + // When setting Platform_GetWindowFocus, it is expected that the platform backend can handle calls without crashing if it doesn't have data stored. + if (g.PlatformIO.Platform_GetWindowFocus && platform_funcs_available) + { + bool is_focused = g.PlatformIO.Platform_GetWindowFocus(viewport); + if (is_focused) + viewport->Flags |= ImGuiViewportFlags_IsFocused; + else + viewport->Flags &= ~ImGuiViewportFlags_IsFocused; + if (is_focused) + focused_viewport = viewport; } } + + // Focused viewport has changed? + if (focused_viewport && g.PlatformLastFocusedViewportId != focused_viewport->ID) + { + IMGUI_DEBUG_LOG_VIEWPORT("[viewport] Focused viewport changed %08X -> %08X, attempting to apply our focus.\n", g.PlatformLastFocusedViewportId, focused_viewport->ID); + const ImGuiViewport* prev_focused_viewport = FindViewportByID(g.PlatformLastFocusedViewportId); + const bool prev_focused_has_been_destroyed = (prev_focused_viewport == NULL) || (prev_focused_viewport->PlatformWindowCreated == false); + + // Store a tag so we can infer z-order easily from all our windows + // We compare PlatformLastFocusedViewportId so newly created viewports with _NoFocusOnAppearing flag + // will keep the front most stamp instead of losing it back to their parent viewport. + if (focused_viewport->LastFocusedStampCount != g.ViewportFocusedStampCount) + focused_viewport->LastFocusedStampCount = ++g.ViewportFocusedStampCount; + g.PlatformLastFocusedViewportId = focused_viewport->ID; + + // Focus associated dear imgui window + // - if focus didn't happen with a click within imgui boundaries, e.g. Clicking platform title bar. (#6299) + // - if focus didn't happen because we destroyed another window (#6462) + // FIXME: perhaps 'FocusTopMostWindowUnderOne()' can handle the 'focused_window->Window != NULL' case as well. + const bool apply_imgui_focus_on_focused_viewport = !IsAnyMouseDown() && !prev_focused_has_been_destroyed; + if (apply_imgui_focus_on_focused_viewport) + { + focused_viewport->LastFocusedHadNavWindow |= (g.NavWindow != NULL) && (g.NavWindow->Viewport == focused_viewport); // Update so a window changing viewport won't lose focus. + ImGuiFocusRequestFlags focus_request_flags = ImGuiFocusRequestFlags_UnlessBelowModal | ImGuiFocusRequestFlags_RestoreFocusedChild; + if (focused_viewport->Window != NULL) + FocusWindow(focused_viewport->Window, focus_request_flags); + else if (focused_viewport->LastFocusedHadNavWindow) + FocusTopMostWindowUnderOne(NULL, NULL, focused_viewport, focus_request_flags); // Focus top most in viewport + else + FocusWindow(NULL, focus_request_flags); // No window had focus last time viewport was focused + } + } + if (focused_viewport) + focused_viewport->LastFocusedHadNavWindow = (g.NavWindow != NULL) && (g.NavWindow->Viewport == focused_viewport); } // Create/update main viewport with current platform position. @@ -12967,7 +14267,7 @@ static void ImGui::UpdateViewportsNewFrame() IM_ASSERT(main_viewport->Window == NULL); ImVec2 main_viewport_pos = viewports_enabled ? g.PlatformIO.Platform_GetWindowPos(main_viewport) : ImVec2(0.0f, 0.0f); ImVec2 main_viewport_size = g.IO.DisplaySize; - if (viewports_enabled && (main_viewport->Flags & ImGuiViewportFlags_Minimized)) + if (viewports_enabled && (main_viewport->Flags & ImGuiViewportFlags_IsMinimized)) { main_viewport_pos = main_viewport->Pos; // Preserve last pos/size when minimized (FIXME: We don't do the same for Size outside of the viewport path) main_viewport_size = main_viewport->Size; @@ -12995,7 +14295,7 @@ static void ImGui::UpdateViewportsNewFrame() { // Update Position and Size (from Platform Window to ImGui) if requested. // We do it early in the frame instead of waiting for UpdatePlatformWindows() to avoid a frame of lag when moving/resizing using OS facilities. - if (!(viewport->Flags & ImGuiViewportFlags_Minimized) && platform_funcs_available) + if (!(viewport->Flags & ImGuiViewportFlags_IsMinimized) && platform_funcs_available) { // Viewport->WorkPos and WorkSize will be updated below if (viewport->PlatformRequestMove) @@ -13156,7 +14456,7 @@ ImGuiViewportP* ImGui::AddUpdateViewport(ImGuiWindow* window, ImGuiID id, const viewport->Pos = pos; if (!viewport->PlatformRequestResize || viewport->ID == IMGUI_VIEWPORT_DEFAULT_ID) viewport->Size = size; - viewport->Flags = flags | (viewport->Flags & ImGuiViewportFlags_Minimized); // Preserve existing flags + viewport->Flags = flags | (viewport->Flags & (ImGuiViewportFlags_IsMinimized | ImGuiViewportFlags_IsFocused)); // Preserve existing flags } else { @@ -13169,7 +14469,7 @@ ImGuiViewportP* ImGui::AddUpdateViewport(ImGuiWindow* window, ImGuiID id, const viewport->Flags = flags; UpdateViewportPlatformMonitor(viewport); g.Viewports.push_back(viewport); - IMGUI_DEBUG_LOG_VIEWPORT("Add Viewport %08X (%s)\n", id, window->Name); + IMGUI_DEBUG_LOG_VIEWPORT("[viewport] Add Viewport %08X '%s'\n", id, window ? window->Name : ""); // We normally setup for all viewports in NewFrame() but here need to handle the mid-frame creation of a new viewport. // We need to extend the fullscreen clip rect so the OverlayDrawList clip is correct for that the first frame @@ -13211,7 +14511,7 @@ static void ImGui::DestroyViewport(ImGuiViewportP* viewport) g.MouseLastHoveredViewport = NULL; // Destroy - IMGUI_DEBUG_LOG_VIEWPORT("Delete Viewport %08X (%s)\n", viewport->ID, viewport->Window ? viewport->Window->Name : "n/a"); + IMGUI_DEBUG_LOG_VIEWPORT("[viewport] Delete Viewport %08X '%s'\n", viewport->ID, viewport->Window ? viewport->Window->Name : "n/a"); DestroyPlatformWindow(viewport); // In most circumstances the platform window will already be destroyed here. IM_ASSERT(g.PlatformIO.Viewports.contains(viewport) == false); IM_ASSERT(g.Viewports[viewport->Idx] == viewport); @@ -13327,7 +14627,7 @@ static void ImGui::WindowSelectViewport(ImGuiWindow* window) if ((window->Flags & ImGuiWindowFlags_DockNodeHost) && window->Viewport->LastFrameActive < g.FrameCount && will_be_visible) { // Steal/transfer ownership - IMGUI_DEBUG_LOG_VIEWPORT("Window '%s' steal Viewport %08X from Window '%s'\n", window->Name, window->Viewport->ID, window->Viewport->Window->Name); + IMGUI_DEBUG_LOG_VIEWPORT("[viewport] Window '%s' steal Viewport %08X from Window '%s'\n", window->Name, window->Viewport->ID, window->Viewport->Window->Name); window->Viewport->Window = window; window->Viewport->ID = window->ID; window->Viewport->LastNameHash = 0; @@ -13474,10 +14774,10 @@ void ImGui::UpdatePlatformWindows() continue; // Create window - bool is_new_platform_window = (viewport->PlatformWindowCreated == false); + const bool is_new_platform_window = (viewport->PlatformWindowCreated == false); if (is_new_platform_window) { - IMGUI_DEBUG_LOG_VIEWPORT("Create Platform Window %08X (%s)\n", viewport->ID, viewport->Window ? viewport->Window->Name : "n/a"); + IMGUI_DEBUG_LOG_VIEWPORT("[viewport] Create Platform Window %08X '%s'\n", viewport->ID, viewport->Window ? viewport->Window->Name : "n/a"); g.PlatformIO.Platform_CreateWindow(viewport); if (g.PlatformIO.Renderer_CreateWindow != NULL) g.PlatformIO.Renderer_CreateWindow(viewport); @@ -13533,38 +14833,13 @@ void ImGui::UpdatePlatformWindows() // Even without focus, we assume the window becomes front-most. // This is useful for our platform z-order heuristic when io.MouseHoveredViewport is not available. - if (viewport->LastFrontMostStampCount != g.ViewportFrontMostStampCount) - viewport->LastFrontMostStampCount = ++g.ViewportFrontMostStampCount; - } + if (viewport->LastFocusedStampCount != g.ViewportFocusedStampCount) + viewport->LastFocusedStampCount = ++g.ViewportFocusedStampCount; + } // Clear request flags viewport->ClearRequestFlags(); } - - // Update our implicit z-order knowledge of platform windows, which is used when the backend cannot provide io.MouseHoveredViewport. - // When setting Platform_GetWindowFocus, it is expected that the platform backend can handle calls without crashing if it doesn't have data stored. - // FIXME-VIEWPORT: We should use this information to also set dear imgui-side focus, allowing us to handle os-level alt+tab. - if (g.PlatformIO.Platform_GetWindowFocus != NULL) - { - ImGuiViewportP* focused_viewport = NULL; - for (int n = 0; n < g.Viewports.Size && focused_viewport == NULL; n++) - { - ImGuiViewportP* viewport = g.Viewports[n]; - if (viewport->PlatformWindowCreated) - if (g.PlatformIO.Platform_GetWindowFocus(viewport)) - focused_viewport = viewport; - } - - // Store a tag so we can infer z-order easily from all our windows - // We compare PlatformLastFocusedViewportId so newly created viewports with _NoFocusOnAppearing flag - // will keep the front most stamp instead of losing it back to their parent viewport. - if (focused_viewport && g.PlatformLastFocusedViewportId != focused_viewport->ID) - { - if (focused_viewport->LastFrontMostStampCount != g.ViewportFrontMostStampCount) - focused_viewport->LastFrontMostStampCount = ++g.ViewportFrontMostStampCount; - g.PlatformLastFocusedViewportId = focused_viewport->ID; - } - } } // This is a default/basic function for performing the rendering/swap of multiple Platform Windows. @@ -13586,7 +14861,7 @@ void ImGui::RenderPlatformWindowsDefault(void* platform_render_arg, void* render for (int i = 1; i < platform_io.Viewports.Size; i++) { ImGuiViewport* viewport = platform_io.Viewports[i]; - if (viewport->Flags & ImGuiViewportFlags_Minimized) + if (viewport->Flags & ImGuiViewportFlags_IsMinimized) continue; if (platform_io.Platform_RenderWindow) platform_io.Platform_RenderWindow(viewport, platform_render_arg); if (platform_io.Renderer_RenderWindow) platform_io.Renderer_RenderWindow(viewport, renderer_render_arg); @@ -13594,7 +14869,7 @@ void ImGui::RenderPlatformWindowsDefault(void* platform_render_arg, void* render for (int i = 1; i < platform_io.Viewports.Size; i++) { ImGuiViewport* viewport = platform_io.Viewports[i]; - if (viewport->Flags & ImGuiViewportFlags_Minimized) + if (viewport->Flags & ImGuiViewportFlags_IsMinimized) continue; if (platform_io.Platform_SwapBuffers) platform_io.Platform_SwapBuffers(viewport, platform_render_arg); if (platform_io.Renderer_SwapBuffers) platform_io.Renderer_SwapBuffers(viewport, renderer_render_arg); @@ -13669,6 +14944,7 @@ void ImGui::DestroyPlatformWindow(ImGuiViewportP* viewport) ImGuiContext& g = *GImGui; if (viewport->PlatformWindowCreated) { + IMGUI_DEBUG_LOG_VIEWPORT("[viewport] Destroy Platform Window %08X '%s'\n", viewport->ID, viewport->Window ? viewport->Window->Name : "n/a"); if (g.PlatformIO.Renderer_DestroyWindow) g.PlatformIO.Renderer_DestroyWindow(viewport); if (g.PlatformIO.Platform_DestroyWindow) @@ -13847,10 +15123,7 @@ namespace ImGui static void DockContextRemoveNode(ImGuiContext* ctx, ImGuiDockNode* node, bool merge_sibling_into_parent_node); static void DockContextQueueNotifyRemovedNode(ImGuiContext* ctx, ImGuiDockNode* node); static void DockContextProcessDock(ImGuiContext* ctx, ImGuiDockRequest* req); - static void DockContextProcessUndockWindow(ImGuiContext* ctx, ImGuiWindow* window, bool clear_persistent_docking_ref = true); - static void DockContextProcessUndockNode(ImGuiContext* ctx, ImGuiDockNode* node); static void DockContextPruneUnusedSettingsNodes(ImGuiContext* ctx); - static ImGuiDockNode* DockContextFindNodeByID(ImGuiContext* ctx, ImGuiID id); static ImGuiDockNode* DockContextBindNodeToWindow(ImGuiContext* ctx, ImGuiWindow* window); static void DockContextBuildNodesFromSettings(ImGuiContext* ctx, ImGuiDockNodeSettings* node_settings_array, int node_settings_count); static void DockContextBuildAddWindowsToNodes(ImGuiContext* ctx, ImGuiID root_id); // Use root_id==0 to add all @@ -13870,11 +15143,11 @@ namespace ImGui static void DockNodeUpdateTabBar(ImGuiDockNode* node, ImGuiWindow* host_window); static void DockNodeAddTabBar(ImGuiDockNode* node); static void DockNodeRemoveTabBar(ImGuiDockNode* node); - static ImGuiID DockNodeUpdateWindowMenu(ImGuiDockNode* node, ImGuiTabBar* tab_bar); + static void DockNodeWindowMenuUpdate(ImGuiDockNode* node, ImGuiTabBar* tab_bar); static void DockNodeUpdateVisibleFlag(ImGuiDockNode* node); static void DockNodeStartMouseMovingWindow(ImGuiDockNode* node, ImGuiWindow* window); static bool DockNodeIsDropAllowed(ImGuiWindow* host_window, ImGuiWindow* payload_window); - static void DockNodePreviewDockSetup(ImGuiWindow* host_window, ImGuiDockNode* host_node, ImGuiWindow* payload_window, ImGuiDockPreviewData* preview_data, bool is_explicit_target, bool is_outer_docking); + static void DockNodePreviewDockSetup(ImGuiWindow* host_window, ImGuiDockNode* host_node, ImGuiWindow* payload_window, ImGuiDockNode* payload_node, ImGuiDockPreviewData* preview_data, bool is_explicit_target, bool is_outer_docking); static void DockNodePreviewDockRender(ImGuiWindow* host_window, ImGuiDockNode* host_node, ImGuiWindow* payload_window, const ImGuiDockPreviewData* preview_data); static void DockNodeCalcTabBarLayout(const ImGuiDockNode* node, ImRect* out_title_rect, ImRect* out_tab_bar_rect, ImVec2* out_window_menu_button_pos, ImVec2* out_close_button_pos); static void DockNodeCalcSplitRects(ImVec2& pos_old, ImVec2& size_old, ImVec2& pos_new, ImVec2& size_new, ImGuiDir dir, ImVec2 size_new_desired); @@ -13944,6 +15217,8 @@ void ImGui::DockContextInitialize(ImGuiContext* ctx) ini_handler.ApplyAllFn = DockSettingsHandler_ApplyAll; ini_handler.WriteAllFn = DockSettingsHandler_WriteAll; g.SettingsHandlers.push_back(ini_handler); + + g.DockNodeWindowMenuHandler = &DockNodeWindowMenuHandler_Default; } void ImGui::DockContextShutdown(ImGuiContext* ctx) @@ -13966,8 +15241,9 @@ void ImGui::DockContextClearNodes(ImGuiContext* ctx, ImGuiID root_id, bool clear // (Different from DockSettingsHandler_ClearAll() + DockSettingsHandler_ApplyAll() because this reuses current settings!) void ImGui::DockContextRebuildNodes(ImGuiContext* ctx) { - IMGUI_DEBUG_LOG_DOCKING("DockContextRebuild()\n"); - ImGuiDockContext* dc = &ctx->DockContext; + ImGuiContext& g = *ctx; + ImGuiDockContext* dc = &ctx->DockContext; + IMGUI_DEBUG_LOG_DOCKING("[docking] DockContextRebuildNodes\n"); SaveIniSettingsToMemory(); ImGuiID root_id = 0; // Rebuild all DockContextClearNodes(ctx, root_id, false); @@ -13979,7 +15255,7 @@ void ImGui::DockContextRebuildNodes(ImGuiContext* ctx) void ImGui::DockContextNewFrameUpdateUndocking(ImGuiContext* ctx) { ImGuiContext& g = *ctx; - ImGuiDockContext* dc = &ctx->DockContext; + ImGuiDockContext* dc = &ctx->DockContext; if (!(g.IO.ConfigFlags & ImGuiConfigFlags_DockingEnable)) { if (dc->Nodes.Data.Size > 0 || dc->Requests.Size > 0) @@ -14030,13 +15306,13 @@ void ImGui::DockContextNewFrameUpdateDocking(ImGuiContext* ctx) // [DEBUG] Store hovered dock node. // We could in theory use DockNodeTreeFindVisibleNodeByPos() on the root host dock node, but using ->DockNode is a good shortcut. // Note this is mostly a debug thing and isn't actually used for docking target, because docking involve more detailed filtering. - g.HoveredDockNode = NULL; + g.DebugHoveredDockNode = NULL; if (ImGuiWindow* hovered_window = g.HoveredWindowUnderMovingWindow) { if (hovered_window->DockNodeAsHost) - g.HoveredDockNode = DockNodeTreeFindVisibleNodeByPos(hovered_window->DockNodeAsHost, g.IO.MousePos); + g.DebugHoveredDockNode = DockNodeTreeFindVisibleNodeByPos(hovered_window->DockNodeAsHost, g.IO.MousePos); else if (hovered_window->RootWindow->DockNode) - g.HoveredDockNode = hovered_window->RootWindow->DockNode; + g.DebugHoveredDockNode = hovered_window->RootWindow->DockNode; } // Process Docking requests @@ -14064,12 +15340,12 @@ void ImGui::DockContextEndFrame(ImGuiContext* ctx) { ImRect bg_rect(node->Pos + ImVec2(0.0f, GetFrameHeight()), node->Pos + node->Size); ImDrawFlags bg_rounding_flags = CalcRoundingFlagsForRectInRect(bg_rect, node->HostWindow->Rect(), DOCKING_SPLITTER_SIZE); - node->HostWindow->DrawList->ChannelsSetCurrent(0); + node->HostWindow->DrawList->ChannelsSetCurrent(DOCKING_HOST_DRAW_CHANNEL_BG); node->HostWindow->DrawList->AddRectFilled(bg_rect.Min, bg_rect.Max, node->LastBgColor, node->HostWindow->WindowRounding, bg_rounding_flags); } } -static ImGuiDockNode* ImGui::DockContextFindNodeByID(ImGuiContext* ctx, ImGuiID id) +ImGuiDockNode* ImGui::DockContextFindNodeByID(ImGuiContext* ctx, ImGuiID id) { return (ImGuiDockNode*)ctx->DockContext.Nodes.GetVoidPtr(id); } @@ -14088,13 +15364,14 @@ ImGuiID ImGui::DockContextGenNodeID(ImGuiContext* ctx) static ImGuiDockNode* ImGui::DockContextAddNode(ImGuiContext* ctx, ImGuiID id) { // Generate an ID for the new node (the exact ID value doesn't matter as long as it is not already used) and add the first window. + ImGuiContext& g = *ctx; if (id == 0) id = DockContextGenNodeID(ctx); else IM_ASSERT(DockContextFindNodeByID(ctx, id) == NULL); // We don't set node->LastFrameAlive on construction. Nodes are always created at all time to reflect .ini settings! - IMGUI_DEBUG_LOG_DOCKING("DockContextAddNode 0x%08X\n", id); + IMGUI_DEBUG_LOG_DOCKING("[docking] DockContextAddNode 0x%08X\n", id); ImGuiDockNode* node = IM_NEW(ImGuiDockNode)(id); ctx->DockContext.Nodes.SetVoidPtr(node->ID, node); return node; @@ -14105,7 +15382,7 @@ static void ImGui::DockContextRemoveNode(ImGuiContext* ctx, ImGuiDockNode* node, ImGuiContext& g = *ctx; ImGuiDockContext* dc = &ctx->DockContext; - IMGUI_DEBUG_LOG_DOCKING("DockContextRemoveNode 0x%08X\n", node->ID); + IMGUI_DEBUG_LOG_DOCKING("[docking] DockContextRemoveNode 0x%08X\n", node->ID); IM_ASSERT(DockContextFindNodeByID(ctx, node->ID) == node); IM_ASSERT(node->ChildNodes[0] == NULL && node->ChildNodes[1] == NULL); IM_ASSERT(node->Windows.Size == 0); @@ -14172,7 +15449,7 @@ static void ImGui::DockContextPruneUnusedSettingsNodes(ImGuiContext* ctx) { ImGuiDockNodeSettings* settings = &dc->NodesSettings[settings_n]; if (settings->ParentWindowId != 0) - if (ImGuiWindowSettings* window_settings = FindWindowSettings(settings->ParentWindowId)) + if (ImGuiWindowSettings* window_settings = FindWindowSettingsByID(settings->ParentWindowId)) if (window_settings->DockId) if (ImGuiDockContextPruneNodeData* data = pool.GetByKey(window_settings->DockId)) data->CountChildNodes++; @@ -14204,7 +15481,7 @@ static void ImGui::DockContextPruneUnusedSettingsNodes(ImGuiContext* ctx) remove |= (data_root->CountChildWindows == 0); if (remove) { - IMGUI_DEBUG_LOG_DOCKING("DockContextPruneUnusedSettingsNodes: Prune 0x%08X\n", settings->ID); + IMGUI_DEBUG_LOG_DOCKING("[docking] DockContextPruneUnusedSettingsNodes: Prune 0x%08X\n", settings->ID); DockSettingsRemoveNodeReferences(&settings->ID, 1); settings->ID = 0; } @@ -14323,9 +15600,9 @@ void ImGui::DockContextProcessDock(ImGuiContext* ctx, ImGuiDockRequest* req) ImGuiWindow* target_window = req->DockTargetWindow; ImGuiDockNode* node = req->DockTargetNode; if (payload_window) - IMGUI_DEBUG_LOG_DOCKING("DockContextProcessDock node 0x%08X target '%s' dock window '%s', split_dir %d\n", node ? node->ID : 0, target_window ? target_window->Name : "NULL", payload_window ? payload_window->Name : "NULL", req->DockSplitDir); + IMGUI_DEBUG_LOG_DOCKING("[docking] DockContextProcessDock node 0x%08X target '%s' dock window '%s', split_dir %d\n", node ? node->ID : 0, target_window ? target_window->Name : "NULL", payload_window->Name, req->DockSplitDir); else - IMGUI_DEBUG_LOG_DOCKING("DockContextProcessDock node 0x%08X, split_dir %d\n", node ? node->ID : 0, req->DockSplitDir); + IMGUI_DEBUG_LOG_DOCKING("[docking] DockContextProcessDock node 0x%08X, split_dir %d\n", node ? node->ID : 0, req->DockSplitDir); // Decide which Tab will be selected at the end of the operation ImGuiID next_selected_id = 0; @@ -14474,8 +15751,8 @@ static ImVec2 FixLargeWindowsWhenUndocking(const ImVec2& size, ImGuiViewport* re void ImGui::DockContextProcessUndockWindow(ImGuiContext* ctx, ImGuiWindow* window, bool clear_persistent_docking_ref) { - IMGUI_DEBUG_LOG_DOCKING("DockContextProcessUndockWindow window '%s', clear_persistent_docking_ref = %d\n", window->Name, clear_persistent_docking_ref); - IM_UNUSED(ctx); + ImGuiContext& g = *ctx; + IMGUI_DEBUG_LOG_DOCKING("[docking] DockContextProcessUndockWindow window '%s', clear_persistent_docking_ref = %d\n", window->Name, clear_persistent_docking_ref); if (window->DockNode) DockNodeRemoveWindow(window->DockNode, window, clear_persistent_docking_ref ? 0 : window->DockId); else @@ -14490,7 +15767,8 @@ void ImGui::DockContextProcessUndockWindow(ImGuiContext* ctx, ImGuiWindow* windo void ImGui::DockContextProcessUndockNode(ImGuiContext* ctx, ImGuiDockNode* node) { - IMGUI_DEBUG_LOG_DOCKING("DockContextProcessUndockNode node %08X\n", node->ID); + ImGuiContext& g = *ctx; + IMGUI_DEBUG_LOG_DOCKING("[docking] DockContextProcessUndockNode node %08X\n", node->ID); IM_ASSERT(node->IsLeafNode()); IM_ASSERT(node->Windows.Size >= 1); @@ -14503,14 +15781,6 @@ void ImGui::DockContextProcessUndockNode(ImGuiContext* ctx, ImGuiDockNode* node) new_node->SizeRef = node->SizeRef; DockNodeMoveWindows(new_node, node); DockSettingsRenameNodeReferences(node->ID, new_node->ID); - for (int n = 0; n < new_node->Windows.Size; n++) - { - ImGuiWindow* window = new_node->Windows[n]; - window->Flags &= ~ImGuiWindowFlags_ChildWindow; - if (window->ParentWindow) - window->ParentWindow->DC.ChildWindows.find_erase(window); - UpdateWindowParentAndRootLinks(window, window->Flags, NULL); - } node = new_node; } else @@ -14523,6 +15793,14 @@ void ImGui::DockContextProcessUndockNode(ImGuiContext* ctx, ImGuiDockNode* node) node->ParentNode->AuthorityForViewport = ImGuiDataAuthority_Window; // The node that stays in place keeps the viewport, so our newly dragged out node will create a new viewport node->ParentNode = NULL; } + for (int n = 0; n < node->Windows.Size; n++) + { + ImGuiWindow* window = node->Windows[n]; + window->Flags &= ~ImGuiWindowFlags_ChildWindow; + if (window->ParentWindow) + window->ParentWindow->DC.ChildWindows.find_erase(window); + UpdateWindowParentAndRootLinks(window, window->Flags, NULL); + } node->AuthorityForPos = node->AuthorityForSize = ImGuiDataAuthority_DockNode; node->Size = FixLargeWindowsWhenUndocking(node->Size, node->Windows[0]->Viewport); node->WantMouseMove = true; @@ -14530,14 +15808,14 @@ void ImGui::DockContextProcessUndockNode(ImGuiContext* ctx, ImGuiDockNode* node) } // This is mostly used for automation. -bool ImGui::DockContextCalcDropPosForDocking(ImGuiWindow* target, ImGuiDockNode* target_node, ImGuiWindow* payload, ImGuiDir split_dir, bool split_outer, ImVec2* out_pos) +bool ImGui::DockContextCalcDropPosForDocking(ImGuiWindow* target, ImGuiDockNode* target_node, ImGuiWindow* payload_window, ImGuiDockNode* payload_node, ImGuiDir split_dir, bool split_outer, ImVec2* out_pos) { // In DockNodePreviewDockSetup() for a root central node instead of showing both "inner" and "outer" drop rects // (which would be functionally identical) we only show the outer one. Reflect this here. if (target_node && target_node->ParentNode == NULL && target_node->IsCentralNode() && split_dir != ImGuiDir_None) split_outer = true; ImGuiDockPreviewData split_data; - DockNodePreviewDockSetup(target, target_node, payload, &split_data, false, split_outer); + DockNodePreviewDockSetup(target, target_node, payload_window, payload_node, &split_data, false, split_outer); if (split_data.DropRectsDraw[split_dir+1].IsInverted()) return false; *out_pos = split_data.DropRectsDraw[split_dir+1].GetCenter(); @@ -14615,7 +15893,7 @@ int ImGui::DockNodeGetTabOrder(ImGuiWindow* window) if (tab_bar == NULL) return -1; ImGuiTabItem* tab = TabBarFindTabByID(tab_bar, window->TabId); - return tab ? tab_bar->GetTabOrder(tab) : -1; + return tab ? TabBarGetTabOrder(tab_bar, tab) : -1; } static void DockNodeHideWindowDuringHostWindowCreation(ImGuiWindow* window) @@ -14634,7 +15912,7 @@ static void ImGui::DockNodeAddWindow(ImGuiDockNode* node, ImGuiWindow* window, b DockNodeRemoveWindow(window->DockNode, window, 0); } IM_ASSERT(window->DockNode == NULL || window->DockNodeAsHost == NULL); - IMGUI_DEBUG_LOG_DOCKING("DockNodeAddWindow node 0x%08X window '%s'\n", node->ID, window->Name); + IMGUI_DEBUG_LOG_DOCKING("[docking] DockNodeAddWindow node 0x%08X window '%s'\n", node->ID, window->Name); // If more than 2 windows appeared on the same frame leading to the creation of a new hosting window, // we'll hide windows until the host window is ready. Hide the 1st window after its been output (so it is not visible for one frame). @@ -14690,7 +15968,7 @@ static void ImGui::DockNodeRemoveWindow(ImGuiDockNode* node, ImGuiWindow* window //IM_ASSERT(window->RootWindowDockTree == node->HostWindow); //IM_ASSERT(window->LastFrameActive < g.FrameCount); // We may call this from Begin() IM_ASSERT(save_dock_id == 0 || save_dock_id == node->ID); - IMGUI_DEBUG_LOG_DOCKING("DockNodeRemoveWindow node 0x%08X window '%s'\n", node->ID, window->Name); + IMGUI_DEBUG_LOG_DOCKING("[docking] DockNodeRemoveWindow node 0x%08X window '%s'\n", node->ID, window->Name); window->DockNode = NULL; window->DockIsActive = window->DockTabWantClose = false; @@ -14737,7 +16015,7 @@ static void ImGui::DockNodeRemoveWindow(ImGuiDockNode* node, ImGuiWindow* window if (node->HostWindow->ViewportOwned && node->IsRootNode()) { // Transfer viewport back to the remaining loose window - IMGUI_DEBUG_LOG_VIEWPORT("Node %08X transfer Viewport %08X=>%08X for Window '%s'\n", node->ID, node->HostWindow->Viewport->ID, remaining_window->ID, remaining_window->Name); + IMGUI_DEBUG_LOG_VIEWPORT("[viewport] Node %08X transfer Viewport %08X=>%08X for Window '%s'\n", node->ID, node->HostWindow->Viewport->ID, remaining_window->ID, remaining_window->Name); IM_ASSERT(node->HostWindow->Viewport->Window == node->HostWindow); node->HostWindow->Viewport->Window = remaining_window; node->HostWindow->Viewport->ID = remaining_window->ID; @@ -14779,15 +16057,12 @@ static void ImGui::DockNodeMoveWindows(ImGuiDockNode* dst_node, ImGuiDockNode* s src_node->TabBar = NULL; } - for (int n = 0; n < src_node->Windows.Size; n++) + // Tab order is not important here, it is preserved by sorting in DockNodeUpdateTabBar(). + for (ImGuiWindow* window : src_node->Windows) { - // DockNode's TabBar may have non-window Tabs manually appended by user - if (ImGuiWindow* window = src_tab_bar ? src_tab_bar->Tabs[n].Window : src_node->Windows[n]) - { - window->DockNode = NULL; - window->DockIsActive = false; - DockNodeAddWindow(dst_node, window, move_tab_bar ? false : true); - } + window->DockNode = NULL; + window->DockIsActive = false; + DockNodeAddWindow(dst_node, window, !move_tab_bar); } src_node->Windows.clear(); @@ -15219,8 +16494,17 @@ static void ImGui::DockNodeUpdate(ImGuiDockNode* node) if (node->IsSplitNode()) IM_ASSERT(node->TabBar == NULL); if (node->IsRootNode()) - if (g.NavWindow && g.NavWindow->RootWindow->DockNode && g.NavWindow->RootWindow->ParentWindow == host_window) - node->LastFocusedNodeId = g.NavWindow->RootWindow->DockNode->ID; + if (ImGuiWindow* p_window = g.NavWindow ? g.NavWindow->RootWindow : NULL) + while (p_window != NULL && p_window->DockNode != NULL) + { + ImGuiDockNode* p_node = DockNodeGetRootNode(p_window->DockNode); + if (p_node == node) + { + node->LastFocusedNodeId = p_window->DockNode->ID; // Note: not using root node ID! + break; + } + p_window = p_node->HostWindow ? p_node->HostWindow->RootWindow : NULL; + } // Register a hit-test hole in the window unless we are currently dragging a window that is compatible with our dockspace ImGuiDockNode* central_node = node->CentralNode; @@ -15255,7 +16539,6 @@ static void ImGui::DockNodeUpdate(ImGuiDockNode* node) // Update position/size, process and draw resizing splitters if (node->IsRootNode() && host_window) { - host_window->DrawList->ChannelsSetCurrent(1); DockNodeTreeUpdatePosSize(node, host_window->Pos, host_window->Size); DockNodeTreeUpdateSplitter(node); } @@ -15263,7 +16546,7 @@ static void ImGui::DockNodeUpdate(ImGuiDockNode* node) // Draw empty node background (currently can only be the Central Node) if (host_window && node->IsEmpty() && node->IsVisible) { - host_window->DrawList->ChannelsSetCurrent(0); + host_window->DrawList->ChannelsSetCurrent(DOCKING_HOST_DRAW_CHANNEL_BG); node->LastBgColor = (node_flags & ImGuiDockNodeFlags_PassthruCentralNode) ? 0 : GetColorU32(ImGuiCol_DockingEmptyBg); if (node->LastBgColor != 0) host_window->DrawList->AddRectFilled(node->Pos, node->Pos + node->Size, node->LastBgColor); @@ -15276,7 +16559,7 @@ static void ImGui::DockNodeUpdate(ImGuiDockNode* node) const bool render_dockspace_bg = node->IsRootNode() && host_window && (node_flags & ImGuiDockNodeFlags_PassthruCentralNode) != 0; if (render_dockspace_bg && node->IsVisible) { - host_window->DrawList->ChannelsSetCurrent(0); + host_window->DrawList->ChannelsSetCurrent(DOCKING_HOST_DRAW_CHANNEL_BG); if (central_node_hole) RenderRectFilledWithHole(host_window->DrawList, node->Rect(), central_node->Rect(), GetColorU32(ImGuiCol_WindowBg), 0.0f); else @@ -15285,7 +16568,7 @@ static void ImGui::DockNodeUpdate(ImGuiDockNode* node) // Draw and populate Tab Bar if (host_window) - host_window->DrawList->ChannelsSetCurrent(1); + host_window->DrawList->ChannelsSetCurrent(DOCKING_HOST_DRAW_CHANNEL_FG); if (host_window && node->Windows.Size > 0) { DockNodeUpdateTabBar(node, host_window); @@ -15299,7 +16582,7 @@ static void ImGui::DockNodeUpdate(ImGuiDockNode* node) if (node->TabBar && node->TabBar->SelectedTabId) node->SelectedTabId = node->TabBar->SelectedTabId; else if (node->Windows.Size > 0) - node->SelectedTabId = node->Windows[0]->ID; + node->SelectedTabId = node->Windows[0]->TabId; // Draw payload drop target if (host_window && node->IsVisible) @@ -15320,13 +16603,7 @@ static void ImGui::DockNodeUpdate(ImGuiDockNode* node) // Render outer borders last (after the tab bar) if (node->IsRootNode()) - { - host_window->DrawList->ChannelsSetCurrent(1); RenderWindowOuterBorders(host_window); - } - - // Further rendering (= hosted windows background) will be drawn on layer 0 - host_window->DrawList->ChannelsSetCurrent(0); } // End host window @@ -15344,11 +16621,39 @@ static int IMGUI_CDECL TabItemComparerByDockOrder(const void* lhs, const void* r return (a->BeginOrderWithinContext - b->BeginOrderWithinContext); } -static ImGuiID ImGui::DockNodeUpdateWindowMenu(ImGuiDockNode* node, ImGuiTabBar* tab_bar) +// Default handler for g.DockNodeWindowMenuHandler(): display the list of windows for a given dock-node. +// This is exceptionally stored in a function pointer to also user applications to tweak this menu (undocumented) +// Custom overrides may want to decorate, group, sort entries. +// Please note those are internal structures: if you copy this expect occasional breakage. +void ImGui::DockNodeWindowMenuHandler_Default(ImGuiContext* ctx, ImGuiDockNode* node, ImGuiTabBar* tab_bar) +{ + IM_UNUSED(ctx); + if (tab_bar->Tabs.Size == 1) + { + // "Hide tab bar" option. Being one of our rare user-facing string we pull it from a table. + if (MenuItem(LocalizeGetMsg(ImGuiLocKey_DockingHideTabBar), NULL, node->IsHiddenTabBar())) + node->WantHiddenTabBarToggle = true; + } + else + { + // Display a selectable list of windows in this docking node + for (int tab_n = 0; tab_n < tab_bar->Tabs.Size; tab_n++) + { + ImGuiTabItem* tab = &tab_bar->Tabs[tab_n]; + if (tab->Flags & ImGuiTabItemFlags_Button) + continue; + if (Selectable(TabBarGetTabName(tab_bar, tab), tab->ID == tab_bar->SelectedTabId)) + TabBarQueueFocus(tab_bar, tab); + SameLine(); + Text(" "); + } + } +} + +static void ImGui::DockNodeWindowMenuUpdate(ImGuiDockNode* node, ImGuiTabBar* tab_bar) { // Try to position the menu so it is more likely to stays within the same viewport ImGuiContext& g = *GImGui; - ImGuiID ret_tab_id = 0; if (g.Style.WindowMenuButtonPosition == ImGuiDir_Left) SetNextWindowPos(ImVec2(node->Pos.x, node->Pos.y + GetFrameHeight()), ImGuiCond_Always, ImVec2(0.0f, 0.0f)); else @@ -15356,27 +16661,9 @@ static ImGuiID ImGui::DockNodeUpdateWindowMenu(ImGuiDockNode* node, ImGuiTabBar* if (BeginPopup("#WindowMenu")) { node->IsFocused = true; - if (tab_bar->Tabs.Size == 1) - { - if (MenuItem("Hide tab bar", NULL, node->IsHiddenTabBar())) - node->WantHiddenTabBarToggle = true; - } - else - { - for (int tab_n = 0; tab_n < tab_bar->Tabs.Size; tab_n++) - { - ImGuiTabItem* tab = &tab_bar->Tabs[tab_n]; - if (tab->Flags & ImGuiTabItemFlags_Button) - continue; - if (Selectable(tab_bar->GetTabName(tab), tab->ID == tab_bar->SelectedTabId)) - ret_tab_id = tab->ID; - SameLine(); - Text(" "); - } - } + g.DockNodeWindowMenuHandler(&g, node, tab_bar); EndPopup(); } - return ret_tab_id; } // User helper to append/amend into a dock node tab bar. Most commonly used to add e.g. a "+" button. @@ -15401,6 +16688,28 @@ void ImGui::DockNodeEndAmendTabBar() End(); } +static bool IsDockNodeTitleBarHighlighted(ImGuiDockNode* node, ImGuiDockNode* root_node) +{ + // CTRL+Tab highlight (only highlighting leaf node, not whole hierarchy) + ImGuiContext& g = *GImGui; + if (g.NavWindowingTarget) + return (g.NavWindowingTarget->DockNode == node); + + // FIXME-DOCKING: May want alternative to treat central node void differently? e.g. if (g.NavWindow == host_window) + if (g.NavWindow && root_node->LastFocusedNodeId == node->ID) + { + // FIXME: This could all be backed in RootWindowForTitleBarHighlight? Probably need to reorganize for both dock nodes + other RootWindowForTitleBarHighlight users (not-node) + ImGuiWindow* parent_window = g.NavWindow->RootWindow; + while (parent_window->Flags & ImGuiWindowFlags_ChildMenu) + parent_window = parent_window->ParentWindow->RootWindow; + ImGuiDockNode* start_parent_node = parent_window->DockNodeAsHost ? parent_window->DockNodeAsHost : parent_window->DockNode; + for (ImGuiDockNode* parent_node = start_parent_node; parent_node != NULL; parent_node = parent_node->HostWindow ? parent_node->HostWindow->RootWindow->DockNode : NULL) + if ((parent_node = ImGui::DockNodeGetRootNode(parent_node)) == root_node) + return true; + } + return false; +} + // Submit the tab bar corresponding to a dock node and various housekeeping details. static void ImGui::DockNodeUpdateTabBar(ImGuiDockNode* node, ImGuiWindow* host_window) { @@ -15416,9 +16725,7 @@ static void ImGui::DockNodeUpdateTabBar(ImGuiDockNode* node, ImGuiWindow* host_w // Decide if we should use a focused title bar color bool is_focused = false; ImGuiDockNode* root_node = DockNodeGetRootNode(node); - if (g.NavWindowingTarget) - is_focused = (g.NavWindowingTarget->DockNode == node); - else if (g.NavWindow && g.NavWindow->RootWindowForTitleBarHighlight == host_window->RootWindowDockTree && root_node->LastFocusedNodeId == node->ID) + if (IsDockNodeTitleBarHighlighted(node, root_node)) is_focused = true; // Hidden tab bar will show a triangle on the upper-left (in Begin) @@ -15469,8 +16776,10 @@ static void ImGui::DockNodeUpdateTabBar(ImGuiDockNode* node, ImGuiWindow* host_w // FIXME-DOCK FIXME-OPT: Could we recycle popups id across multiple dock nodes? if (has_window_menu_button && IsPopupOpen("#WindowMenu")) { - if (ImGuiID tab_id = DockNodeUpdateWindowMenu(node, tab_bar)) - focus_tab_id = tab_bar->NextSelectedTabId = tab_id; + ImGuiID next_selected_tab_id = tab_bar->NextSelectedTabId; + DockNodeWindowMenuUpdate(node, tab_bar); + if (tab_bar->NextSelectedTabId != 0 && tab_bar->NextSelectedTabId != next_selected_tab_id) + focus_tab_id = tab_bar->NextSelectedTabId; is_focused |= node->IsFocused; } @@ -15515,16 +16824,16 @@ static void ImGui::DockNodeUpdateTabBar(ImGuiDockNode* node, ImGuiWindow* host_w } if (tab_bar->Tabs.Size > tabs_unsorted_start) { - IMGUI_DEBUG_LOG_DOCKING("In node 0x%08X: %d new appearing tabs:%s\n", node->ID, tab_bar->Tabs.Size - tabs_unsorted_start, (tab_bar->Tabs.Size > tabs_unsorted_start + 1) ? " (will sort)" : ""); + IMGUI_DEBUG_LOG_DOCKING("[docking] In node 0x%08X: %d new appearing tabs:%s\n", node->ID, tab_bar->Tabs.Size - tabs_unsorted_start, (tab_bar->Tabs.Size > tabs_unsorted_start + 1) ? " (will sort)" : ""); for (int tab_n = tabs_unsorted_start; tab_n < tab_bar->Tabs.Size; tab_n++) - IMGUI_DEBUG_LOG_DOCKING(" - Tab '%s' Order %d\n", tab_bar->Tabs[tab_n].Window->Name, tab_bar->Tabs[tab_n].Window->DockOrder); + IMGUI_DEBUG_LOG_DOCKING("[docking] - Tab '%s' Order %d\n", tab_bar->Tabs[tab_n].Window->Name, tab_bar->Tabs[tab_n].Window->DockOrder); if (tab_bar->Tabs.Size > tabs_unsorted_start + 1) ImQsort(tab_bar->Tabs.Data + tabs_unsorted_start, tab_bar->Tabs.Size - tabs_unsorted_start, sizeof(ImGuiTabItem), TabItemComparerByDockOrder); } // Apply NavWindow focus back to the tab bar if (g.NavWindow && g.NavWindow->RootWindow->DockNode == node) - tab_bar->SelectedTabId = g.NavWindow->RootWindow->ID; + tab_bar->SelectedTabId = g.NavWindow->RootWindow->TabId; // Selected newly added tabs, or persistent tab ID if the tab bar was just recreated if (tab_bar_is_recreated && TabBarFindTabByID(tab_bar, node->SelectedTabId) != NULL) @@ -15856,20 +17165,21 @@ bool ImGui::DockNodeCalcDropRectsAndTestMousePos(const ImRect& parent, ImGuiDir // host_node may be NULL if the window doesn't have a DockNode already. // FIXME-DOCK: This is misnamed since it's also doing the filtering. -static void ImGui::DockNodePreviewDockSetup(ImGuiWindow* host_window, ImGuiDockNode* host_node, ImGuiWindow* root_payload, ImGuiDockPreviewData* data, bool is_explicit_target, bool is_outer_docking) +static void ImGui::DockNodePreviewDockSetup(ImGuiWindow* host_window, ImGuiDockNode* host_node, ImGuiWindow* payload_window, ImGuiDockNode* payload_node, ImGuiDockPreviewData* data, bool is_explicit_target, bool is_outer_docking) { ImGuiContext& g = *GImGui; // There is an edge case when docking into a dockspace which only has inactive nodes. // In this case DockNodeTreeFindNodeByPos() will have selected a leaf node which is inactive. // Because the inactive leaf node doesn't have proper pos/size yet, we'll use the root node as reference. - ImGuiDockNode* root_payload_as_host = root_payload->DockNodeAsHost; + if (payload_node == NULL) + payload_node = payload_window->DockNodeAsHost; ImGuiDockNode* ref_node_for_rect = (host_node && !host_node->IsVisible) ? DockNodeGetRootNode(host_node) : host_node; if (ref_node_for_rect) - IM_ASSERT(ref_node_for_rect->IsVisible); + IM_ASSERT(ref_node_for_rect->IsVisible == true); // Filter, figure out where we are allowed to dock - ImGuiDockNodeFlags src_node_flags = root_payload_as_host ? root_payload_as_host->MergedFlags : root_payload->WindowClass.DockNodeFlagsOverrideSet; + ImGuiDockNodeFlags src_node_flags = payload_node ? payload_node->MergedFlags : payload_window->WindowClass.DockNodeFlagsOverrideSet; ImGuiDockNodeFlags dst_node_flags = host_node ? host_node->MergedFlags : host_window->WindowClass.DockNodeFlagsOverrideSet; data->IsCenterAvailable = true; if (is_outer_docking) @@ -15878,7 +17188,7 @@ static void ImGui::DockNodePreviewDockSetup(ImGuiWindow* host_window, ImGuiDockN data->IsCenterAvailable = false; else if (host_node && (dst_node_flags & ImGuiDockNodeFlags_NoDockingInCentralNode) && host_node->IsCentralNode()) data->IsCenterAvailable = false; - else if ((!host_node || !host_node->IsEmpty()) && root_payload_as_host && root_payload_as_host->IsSplitNode() && (root_payload_as_host->OnlyNodeWithWindows == NULL)) // Is _visibly_ split? + else if ((!host_node || !host_node->IsEmpty()) && payload_node && payload_node->IsSplitNode() && (payload_node->OnlyNodeWithWindows == NULL)) // Is _visibly_ split? data->IsCenterAvailable = false; else if (dst_node_flags & ImGuiDockNodeFlags_NoDockingOverMe) data->IsCenterAvailable = false; @@ -15896,7 +17206,7 @@ static void ImGui::DockNodePreviewDockSetup(ImGuiWindow* host_window, ImGuiDockN data->IsSidesAvailable = false; // Build a tentative future node (reuse same structure because it is practical. Shape will be readjusted when previewing a split) - data->FutureNode.HasCloseButton = (host_node ? host_node->HasCloseButton : host_window->HasCloseButton) || (root_payload->HasCloseButton); + data->FutureNode.HasCloseButton = (host_node ? host_node->HasCloseButton : host_window->HasCloseButton) || (payload_window->HasCloseButton); data->FutureNode.HasWindowMenuButton = host_node ? true : ((host_window->Flags & ImGuiWindowFlags_NoCollapse) == 0); data->FutureNode.Pos = ref_node_for_rect ? ref_node_for_rect->Pos : host_window->Pos; data->FutureNode.Size = ref_node_for_rect ? ref_node_for_rect->Size : host_window->Size; @@ -15933,7 +17243,7 @@ static void ImGui::DockNodePreviewDockSetup(ImGuiWindow* host_window, ImGuiDockN ImGuiAxis split_axis = (split_dir == ImGuiDir_Left || split_dir == ImGuiDir_Right) ? ImGuiAxis_X : ImGuiAxis_Y; ImVec2 pos_new, pos_old = data->FutureNode.Pos; ImVec2 size_new, size_old = data->FutureNode.Size; - DockNodeCalcSplitRects(pos_old, size_old, pos_new, size_new, split_dir, root_payload->Size); + DockNodeCalcSplitRects(pos_old, size_old, pos_new, size_new, split_dir, payload_window->Size); // Calculate split ratio so we can pass it down the docking request float split_ratio = ImSaturate(size_new[split_axis] / data->FutureNode.Size[split_axis]); @@ -15989,11 +17299,11 @@ static void ImGui::DockNodePreviewDockRender(ImGuiWindow* host_window, ImGuiDock if (!host_node->IsHiddenTabBar() && !host_node->IsNoTabBar()) tab_pos.x += host_node->TabBar->WidthAllTabs + g.Style.ItemInnerSpacing.x; // We don't use OffsetNewTab because when using non-persistent-order tab bar it is incremented with each Tab submission. else - tab_pos.x += g.Style.ItemInnerSpacing.x + TabItemCalcSize(host_node->Windows[0]->Name, host_node->Windows[0]->HasCloseButton).x; + tab_pos.x += g.Style.ItemInnerSpacing.x + TabItemCalcSize(host_node->Windows[0]).x; } else if (!(host_window->Flags & ImGuiWindowFlags_DockNodeHost)) { - tab_pos.x += g.Style.ItemInnerSpacing.x + TabItemCalcSize(host_window->Name, host_window->HasCloseButton).x; // Account for slight offset which will be added when changing from title bar to tab bar + tab_pos.x += g.Style.ItemInnerSpacing.x + TabItemCalcSize(host_window).x; // Account for slight offset which will be added when changing from title bar to tab bar } // Draw tab shape/label preview (payload may be a loose window or a host window carrying multiple tabbed windows) @@ -16011,7 +17321,7 @@ static void ImGui::DockNodePreviewDockRender(ImGuiWindow* host_window, ImGuiDock continue; // Calculate the tab bounding box for each payload window - ImVec2 tab_size = TabItemCalcSize(payload_window->Name, payload_window->HasCloseButton); + ImVec2 tab_size = TabItemCalcSize(payload_window); ImRect tab_bb(tab_pos.x, tab_pos.y, tab_pos.x + tab_size.x, tab_pos.y + tab_size.y); tab_pos.x += tab_size.x + g.Style.ItemInnerSpacing.x; const ImU32 overlay_col_text = GetColorU32(payload_window->DockStyle.Colors[ImGuiWindowDockStyleCol_Text]); @@ -16118,6 +17428,7 @@ void ImGui::DockNodeTreeSplit(ImGuiContext* ctx, ImGuiDockNode* parent_node, ImG void ImGui::DockNodeTreeMerge(ImGuiContext* ctx, ImGuiDockNode* parent_node, ImGuiDockNode* merge_lead_child) { // When called from DockContextProcessUndockNode() it is possible that one of the child is NULL. + ImGuiContext& g = *GImGui; ImGuiDockNode* child_0 = parent_node->ChildNodes[0]; ImGuiDockNode* child_1 = parent_node->ChildNodes[1]; IM_ASSERT(child_0 || child_1); @@ -16127,7 +17438,7 @@ void ImGui::DockNodeTreeMerge(ImGuiContext* ctx, ImGuiDockNode* parent_node, ImG IM_ASSERT(parent_node->TabBar == NULL); IM_ASSERT(parent_node->Windows.Size == 0); } - IMGUI_DEBUG_LOG_DOCKING("DockNodeTreeMerge 0x%08X & 0x%08X back into parent 0x%08X\n", child_0 ? child_0->ID : 0, child_1 ? child_1->ID : 0, parent_node->ID); + IMGUI_DEBUG_LOG_DOCKING("[docking] DockNodeTreeMerge: 0x%08X + 0x%08X back into parent 0x%08X\n", child_0 ? child_0->ID : 0, child_1 ? child_1->ID : 0, parent_node->ID); ImVec2 backup_last_explicit_size = parent_node->SizeRef; DockNodeMoveChildNodes(parent_node, merge_lead_child); @@ -16425,7 +17736,8 @@ ImGuiDockNode* ImGui::DockNodeTreeFindVisibleNodeByPos(ImGuiDockNode* node, ImVe if (ImGuiDockNode* hovered_node = DockNodeTreeFindVisibleNodeByPos(node->ChildNodes[1], pos)) return hovered_node; - return NULL; + // This means we are hovering over the splitter/spacing of a parent node + return node; } //----------------------------------------------------------------------------- @@ -16476,11 +17788,12 @@ void ImGui::SetWindowDock(ImGuiWindow* window, ImGuiID dock_id, ImGuiCond cond) // Create an explicit dockspace node within an existing window. Also expose dock node flags and creates a CentralNode by default. // The Central Node is always displayed even when empty and shrink/extend according to the requested size of its neighbors. // DockSpace() needs to be submitted _before_ any window they can host. If you use a dockspace, submit it early in your app. +// When ImGuiDockNodeFlags_KeepAliveOnly is set, nothing is submitted in the current window (function may be called from any location). ImGuiID ImGui::DockSpace(ImGuiID id, const ImVec2& size_arg, ImGuiDockNodeFlags flags, const ImGuiWindowClass* window_class) { ImGuiContext* ctx = GImGui; ImGuiContext& g = *ctx; - ImGuiWindow* window = GetCurrentWindow(); + ImGuiWindow* window = GetCurrentWindowRead(); if (!(g.IO.ConfigFlags & ImGuiConfigFlags_DockingEnable)) return 0; @@ -16489,18 +17802,20 @@ ImGuiID ImGui::DockSpace(ImGuiID id, const ImVec2& size_arg, ImGuiDockNodeFlags // If for whichever reason this is causing problem we would need to ensure that DockNodeUpdateTabBar() ends up clearing NextSelectedTabId even if SkipItems=true. if (window->SkipItems) flags |= ImGuiDockNodeFlags_KeepAliveOnly; + if ((flags & ImGuiDockNodeFlags_KeepAliveOnly) == 0) + window = GetCurrentWindow(); // call to set window->WriteAccessed = true; IM_ASSERT((flags & ImGuiDockNodeFlags_DockSpace) == 0); IM_ASSERT(id != 0); ImGuiDockNode* node = DockContextFindNodeByID(ctx, id); if (!node) { - IMGUI_DEBUG_LOG_DOCKING("DockSpace: dockspace node 0x%08X created\n", id); + IMGUI_DEBUG_LOG_DOCKING("[docking] DockSpace: dockspace node 0x%08X created\n", id); node = DockContextAddNode(ctx, id); node->SetLocalFlags(ImGuiDockNodeFlags_CentralNode); } if (window_class && window_class->ClassId != node->WindowClass.ClassId) - IMGUI_DEBUG_LOG_DOCKING("DockSpace: dockspace node 0x%08X: setup WindowClass 0x%08X -> 0x%08X\n", id, node->WindowClass.ClassId, window_class->ClassId); + IMGUI_DEBUG_LOG_DOCKING("[docking] DockSpace: dockspace node 0x%08X: setup WindowClass 0x%08X -> 0x%08X\n", id, node->WindowClass.ClassId, window_class->ClassId); node->SharedFlags = flags; node->WindowClass = window_class ? *window_class : ImGuiWindowClass(); @@ -16569,7 +17884,13 @@ ImGuiID ImGui::DockSpace(ImGuiID id, const ImVec2& size_arg, ImGuiDockNodeFlags DockNodeUpdate(node); End(); + + ImRect bb(node->Pos, node->Pos + size); ItemSize(size); + ItemAdd(bb, id, NULL, ImGuiItemFlags_NoNav); // Not a nav point (could be, would need to draw the nav rect and replicate/refactor activation from BeginChild(), but seems like CTRL+Tab works better here?) + if ((g.LastItemData.StatusFlags & ImGuiItemStatusFlags_HoveredRect) && IsWindowChildOf(g.HoveredWindow, host_window, false, true)) // To fullfill IsItemHovered(), similar to EndChild() + g.LastItemData.StatusFlags |= ImGuiItemStatusFlags_HoveredWindow; + return id; } @@ -16644,7 +17965,7 @@ void ImGui::DockBuilderDockWindow(const char* window_name, ImGuiID node_id) else { // Apply to settings - ImGuiWindowSettings* settings = FindWindowSettings(window_id); + ImGuiWindowSettings* settings = FindWindowSettingsByID(window_id); if (settings == NULL) settings = CreateNewWindowSettings(window_name); settings->DockId = node_id; @@ -16836,11 +18157,11 @@ void ImGui::DockBuilderRemoveNodeDockedWindows(ImGuiID root_id, bool clear_setti // FIXME-DOCK: We are not exposing nor using split_outer. ImGuiID ImGui::DockBuilderSplitNode(ImGuiID id, ImGuiDir split_dir, float size_ratio_for_node_at_dir, ImGuiID* out_id_at_dir, ImGuiID* out_id_at_opposite_dir) { - ImGuiContext* ctx = GImGui; + ImGuiContext& g = *GImGui; IM_ASSERT(split_dir != ImGuiDir_None); - IMGUI_DEBUG_LOG_DOCKING("DockBuilderSplitNode node 0x%08X, split_dir %d\n", id, split_dir); + IMGUI_DEBUG_LOG_DOCKING("[docking] DockBuilderSplitNode: node 0x%08X, split_dir %d\n", id, split_dir); - ImGuiDockNode* node = DockContextFindNodeByID(ctx, id); + ImGuiDockNode* node = DockContextFindNodeByID(&g, id); if (node == NULL) { IM_ASSERT(node != NULL); @@ -16857,7 +18178,7 @@ ImGuiID ImGui::DockBuilderSplitNode(ImGuiID id, ImGuiDir split_dir, float size_r req.DockSplitDir = split_dir; req.DockSplitRatio = ImSaturate((split_dir == ImGuiDir_Left || split_dir == ImGuiDir_Up) ? size_ratio_for_node_at_dir : 1.0f - size_ratio_for_node_at_dir); req.DockSplitOuter = false; - DockContextProcessDock(ctx, &req); + DockContextProcessDock(&g, &req); ImGuiID id_at_dir = node->ChildNodes[(split_dir == ImGuiDir_Left || split_dir == ImGuiDir_Up) ? 0 : 1]->ID; ImGuiID id_at_opposite_dir = node->ChildNodes[(split_dir == ImGuiDir_Left || split_dir == ImGuiDir_Up) ? 1 : 0]->ID; @@ -16870,8 +18191,8 @@ ImGuiID ImGui::DockBuilderSplitNode(ImGuiID id, ImGuiDir split_dir, float size_r static ImGuiDockNode* DockBuilderCopyNodeRec(ImGuiDockNode* src_node, ImGuiID dst_node_id_if_known, ImVector* out_node_remap_pairs) { - ImGuiContext* ctx = GImGui; - ImGuiDockNode* dst_node = ImGui::DockContextAddNode(ctx, dst_node_id_if_known); + ImGuiContext& g = *GImGui; + ImGuiDockNode* dst_node = ImGui::DockContextAddNode(&g, dst_node_id_if_known); dst_node->SharedFlags = src_node->SharedFlags; dst_node->LocalFlags = src_node->LocalFlags; dst_node->LocalFlagsInWindows = ImGuiDockNodeFlags_None; @@ -16891,7 +18212,7 @@ static ImGuiDockNode* DockBuilderCopyNodeRec(ImGuiDockNode* src_node, ImGuiID ds dst_node->ChildNodes[child_n]->ParentNode = dst_node; } - IMGUI_DEBUG_LOG_DOCKING("Fork node %08X -> %08X (%d childs)\n", src_node->ID, dst_node->ID, dst_node->IsSplitNode() ? 2 : 0); + IMGUI_DEBUG_LOG_DOCKING("[docking] Fork node %08X -> %08X (%d childs)\n", src_node->ID, dst_node->ID, dst_node->IsSplitNode() ? 2 : 0); return dst_node; } @@ -16925,8 +18246,11 @@ void ImGui::DockBuilderCopyWindowSettings(const char* src_name, const char* dst_ dst_window->SizeFull = src_window->SizeFull; dst_window->Collapsed = src_window->Collapsed; } - else if (ImGuiWindowSettings* dst_settings = FindOrCreateWindowSettings(dst_name)) + else { + ImGuiWindowSettings* dst_settings = FindWindowSettingsByID(ImHashStr(dst_name)); + if (!dst_settings) + dst_settings = CreateNewWindowSettings(dst_name); ImVec2ih window_pos_2ih = ImVec2ih(src_window->Pos); if (src_window->ViewportId != 0 && src_window->ViewportId != IMGUI_VIEWPORT_DEFAULT_ID) { @@ -16946,6 +18270,7 @@ void ImGui::DockBuilderCopyWindowSettings(const char* src_name, const char* dst_ // FIXME: Will probably want to change this signature, in particular how the window remapping pairs are passed. void ImGui::DockBuilderCopyDockSpace(ImGuiID src_dockspace_id, ImGuiID dst_dockspace_id, ImVector* in_window_remap_pairs) { + ImGuiContext& g = *GImGui; IM_ASSERT(src_dockspace_id != 0); IM_ASSERT(dst_dockspace_id != 0); IM_ASSERT(in_window_remap_pairs != NULL); @@ -16971,7 +18296,7 @@ void ImGui::DockBuilderCopyDockSpace(ImGuiID src_dockspace_id, ImGuiID dst_docks ImGuiID src_dock_id = 0; if (ImGuiWindow* src_window = FindWindowByID(src_window_id)) src_dock_id = src_window->DockId; - else if (ImGuiWindowSettings* src_window_settings = FindWindowSettings(src_window_id)) + else if (ImGuiWindowSettings* src_window_settings = FindWindowSettingsByID(src_window_id)) src_dock_id = src_window_settings->DockId; ImGuiID dst_dock_id = 0; for (int dock_remap_n = 0; dock_remap_n < node_remap_pairs.Size; dock_remap_n += 2) @@ -16985,20 +18310,23 @@ void ImGui::DockBuilderCopyDockSpace(ImGuiID src_dockspace_id, ImGuiID dst_docks if (dst_dock_id != 0) { // Docked windows gets redocked into the new node hierarchy. - IMGUI_DEBUG_LOG_DOCKING("Remap live window '%s' 0x%08X -> '%s' 0x%08X\n", src_window_name, src_dock_id, dst_window_name, dst_dock_id); + IMGUI_DEBUG_LOG_DOCKING("[docking] Remap live window '%s' 0x%08X -> '%s' 0x%08X\n", src_window_name, src_dock_id, dst_window_name, dst_dock_id); DockBuilderDockWindow(dst_window_name, dst_dock_id); } else { // Floating windows gets their settings transferred (regardless of whether the new window already exist or not) // When this is leading to a Copy and not a Move, we would get two overlapping floating windows. Could we possibly dock them together? - IMGUI_DEBUG_LOG_DOCKING("Remap window settings '%s' -> '%s'\n", src_window_name, dst_window_name); + IMGUI_DEBUG_LOG_DOCKING("[docking] Remap window settings '%s' -> '%s'\n", src_window_name, dst_window_name); DockBuilderCopyWindowSettings(src_window_name, dst_window_name); } } - // Anything else in the source nodes of 'node_remap_pairs' are windows that were docked in src_dockspace_id but are not owned by it (unaffiliated windows, e.g. "ImGui Demo") + // Anything else in the source nodes of 'node_remap_pairs' are windows that are not included in the remapping list. // Find those windows and move to them to the cloned dock node. This may be optional? + // Dock those are a second step as undocking would invalidate source dock nodes. + struct DockRemainingWindowTask { ImGuiWindow* Window; ImGuiID DockId; DockRemainingWindowTask(ImGuiWindow* window, ImGuiID dock_id) { Window = window; DockId = dock_id; } }; + ImVector dock_remaining_windows; for (int dock_remap_n = 0; dock_remap_n < node_remap_pairs.Size; dock_remap_n += 2) if (ImGuiID src_dock_id = node_remap_pairs[dock_remap_n]) { @@ -17011,10 +18339,12 @@ void ImGui::DockBuilderCopyDockSpace(ImGuiID src_dockspace_id, ImGuiID dst_docks continue; // Docked windows gets redocked into the new node hierarchy. - IMGUI_DEBUG_LOG_DOCKING("Remap window '%s' %08X -> %08X\n", window->Name, src_dock_id, dst_dock_id); - DockBuilderDockWindow(window->Name, dst_dock_id); + IMGUI_DEBUG_LOG_DOCKING("[docking] Remap window '%s' %08X -> %08X\n", window->Name, src_dock_id, dst_dock_id); + dock_remaining_windows.push_back(DockRemainingWindowTask(window, dst_dock_id)); } } + for (const DockRemainingWindowTask& task : dock_remaining_windows) + DockBuilderDockWindow(task.Window->Name, task.DockId); } // FIXME-DOCK: This is awkward because in series of split user is likely to loose access to its root node. @@ -17293,17 +18623,19 @@ void ImGui::BeginDockableDragDropTarget(ImGuiWindow* window) const bool do_preview = payload->IsPreview() || payload->IsDelivery(); if (do_preview && (node != NULL || dock_into_floating_window)) { + // If we have a non-leaf node it means we are hovering the border of a parent node, in which case only outer markers will appear. ImGuiDockPreviewData split_inner; ImGuiDockPreviewData split_outer; ImGuiDockPreviewData* split_data = &split_inner; - if (node && (node->ParentNode || node->IsCentralNode())) + if (node && (node->ParentNode || node->IsCentralNode() || !node->IsLeafNode())) if (ImGuiDockNode* root_node = DockNodeGetRootNode(node)) { - DockNodePreviewDockSetup(window, root_node, payload_window, &split_outer, is_explicit_target, true); + DockNodePreviewDockSetup(window, root_node, payload_window, NULL, &split_outer, is_explicit_target, true); if (split_outer.IsSplitDirExplicit) split_data = &split_outer; } - DockNodePreviewDockSetup(window, node, payload_window, &split_inner, is_explicit_target, false); + if (!node || node->IsLeafNode()) + DockNodePreviewDockSetup(window, node, payload_window, NULL, &split_inner, is_explicit_target, false); if (split_data == &split_outer) split_inner.IsDropAllowed = false; @@ -17335,7 +18667,7 @@ void ImGui::BeginDockableDragDropTarget(ImGuiWindow* window) static void ImGui::DockSettingsRenameNodeReferences(ImGuiID old_node_id, ImGuiID new_node_id) { ImGuiContext& g = *GImGui; - IMGUI_DEBUG_LOG_DOCKING("DockSettingsRenameNodeReferences: from 0x%08X -> to 0x%08X\n", old_node_id, new_node_id); + IMGUI_DEBUG_LOG_DOCKING("[docking] DockSettingsRenameNodeReferences: from 0x%08X -> to 0x%08X\n", old_node_id, new_node_id); for (int window_n = 0; window_n < g.Windows.Size; window_n++) { ImGuiWindow* window = g.Windows[window_n]; @@ -17556,9 +18888,9 @@ static void ImGui::DockSettingsHandler_WriteAll(ImGuiContext* ctx, ImGuiSettings // Win32 clipboard implementation // We use g.ClipboardHandlerData for temporary storage to ensure it is freed on Shutdown() -static const char* GetClipboardTextFn_DefaultImpl(void*) +static const char* GetClipboardTextFn_DefaultImpl(void* user_data_ctx) { - ImGuiContext& g = *GImGui; + ImGuiContext& g = *(ImGuiContext*)user_data_ctx; g.ClipboardHandlerData.clear(); if (!::OpenClipboard(NULL)) return NULL; @@ -17619,8 +18951,9 @@ static void SetClipboardTextFn_DefaultImpl(void*, const char* text) } } -static const char* GetClipboardTextFn_DefaultImpl(void*) +static const char* GetClipboardTextFn_DefaultImpl(void* user_data_ctx) { + ImGuiContext& g = *(ImGuiContext*)user_data_ctx; if (!main_clipboard) PasteboardCreate(kPasteboardClipboard, &main_clipboard); PasteboardSynchronize(main_clipboard); @@ -17638,7 +18971,6 @@ static const char* GetClipboardTextFn_DefaultImpl(void*) CFDataRef cf_data; if (PasteboardCopyItemFlavorData(main_clipboard, item_id, CFSTR("public.utf8-plain-text"), &cf_data) == noErr) { - ImGuiContext& g = *GImGui; g.ClipboardHandlerData.clear(); int length = (int)CFDataGetLength(cf_data); g.ClipboardHandlerData.resize(length + 1); @@ -17655,15 +18987,15 @@ static const char* GetClipboardTextFn_DefaultImpl(void*) #else // Local Dear ImGui-only clipboard implementation, if user hasn't defined better clipboard handlers. -static const char* GetClipboardTextFn_DefaultImpl(void*) +static const char* GetClipboardTextFn_DefaultImpl(void* user_data_ctx) { - ImGuiContext& g = *GImGui; + ImGuiContext& g = *(ImGuiContext*)user_data_ctx; return g.ClipboardHandlerData.empty() ? NULL : g.ClipboardHandlerData.begin(); } -static void SetClipboardTextFn_DefaultImpl(void*, const char* text) +static void SetClipboardTextFn_DefaultImpl(void* user_data_ctx, const char* text) { - ImGuiContext& g = *GImGui; + ImGuiContext& g = *(ImGuiContext*)user_data_ctx; g.ClipboardHandlerData.clear(); const char* text_end = text + strlen(text); g.ClipboardHandlerData.resize((int)(text_end - text) + 1); @@ -17685,15 +19017,10 @@ static void SetPlatformImeDataFn_DefaultImpl(ImGuiViewport* viewport, ImGuiPlatf { // Notify OS Input Method Editor of text input position HWND hwnd = (HWND)viewport->PlatformHandleRaw; -#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS - if (hwnd == 0) - hwnd = (HWND)ImGui::GetIO().ImeWindowHandle; -#endif if (hwnd == 0) return; - ::ImmAssociateContextEx(hwnd, NULL, data->WantVisible ? IACE_DEFAULT : 0); - + //::ImmAssociateContextEx(hwnd, NULL, data->WantVisible ? IACE_DEFAULT : 0); if (HIMC himc = ::ImmGetContext(hwnd)) { COMPOSITIONFORM composition_form = {}; @@ -17740,7 +19067,7 @@ static void SetPlatformImeDataFn_DefaultImpl(ImGuiViewport*, ImGuiPlatformImeDat // - DebugNodeWindowsListByBeginStackParent() [Internal] //----------------------------------------------------------------------------- -#ifndef IMGUI_DISABLE_METRICS_WINDOW +#ifndef IMGUI_DISABLE_DEBUG_TOOLS void ImGui::DebugRenderViewportThumbnail(ImDrawList* draw_list, ImGuiViewportP* viewport, const ImRect& bb) { @@ -17749,7 +19076,7 @@ void ImGui::DebugRenderViewportThumbnail(ImDrawList* draw_list, ImGuiViewportP* ImVec2 scale = bb.GetSize() / viewport->Size; ImVec2 off = bb.Min - viewport->Pos * scale; - float alpha_mul = (viewport->Flags & ImGuiViewportFlags_Minimized) ? 0.30f : 1.00f; + float alpha_mul = (viewport->Flags & ImGuiViewportFlags_IsMinimized) ? 0.30f : 1.00f; window->DrawList->AddRectFilled(bb.Min, bb.Max, ImGui::GetColorU32(ImGuiCol_Border, alpha_mul * 0.40f)); for (int i = 0; i != g.Windows.Size; i++) { @@ -17795,18 +19122,67 @@ static void RenderViewportsThumbnails() ImGui::Dummy(bb_full.GetSize() * SCALE); } -static int IMGUI_CDECL ViewportComparerByFrontMostStampCount(const void* lhs, const void* rhs) +static int IMGUI_CDECL ViewportComparerByLastFocusedStampCount(const void* lhs, const void* rhs) { const ImGuiViewportP* a = *(const ImGuiViewportP* const*)lhs; const ImGuiViewportP* b = *(const ImGuiViewportP* const*)rhs; - return b->LastFrontMostStampCount - a->LastFrontMostStampCount; + return b->LastFocusedStampCount - a->LastFocusedStampCount; +} + +// Draw an arbitrary US keyboard layout to visualize translated keys +void ImGui::DebugRenderKeyboardPreview(ImDrawList* draw_list) +{ + const ImVec2 key_size = ImVec2(35.0f, 35.0f); + const float key_rounding = 3.0f; + const ImVec2 key_face_size = ImVec2(25.0f, 25.0f); + const ImVec2 key_face_pos = ImVec2(5.0f, 3.0f); + const float key_face_rounding = 2.0f; + const ImVec2 key_label_pos = ImVec2(7.0f, 4.0f); + const ImVec2 key_step = ImVec2(key_size.x - 1.0f, key_size.y - 1.0f); + const float key_row_offset = 9.0f; + + ImVec2 board_min = GetCursorScreenPos(); + ImVec2 board_max = ImVec2(board_min.x + 3 * key_step.x + 2 * key_row_offset + 10.0f, board_min.y + 3 * key_step.y + 10.0f); + ImVec2 start_pos = ImVec2(board_min.x + 5.0f - key_step.x, board_min.y); + + struct KeyLayoutData { int Row, Col; const char* Label; ImGuiKey Key; }; + const KeyLayoutData keys_to_display[] = + { + { 0, 0, "", ImGuiKey_Tab }, { 0, 1, "Q", ImGuiKey_Q }, { 0, 2, "W", ImGuiKey_W }, { 0, 3, "E", ImGuiKey_E }, { 0, 4, "R", ImGuiKey_R }, + { 1, 0, "", ImGuiKey_CapsLock }, { 1, 1, "A", ImGuiKey_A }, { 1, 2, "S", ImGuiKey_S }, { 1, 3, "D", ImGuiKey_D }, { 1, 4, "F", ImGuiKey_F }, + { 2, 0, "", ImGuiKey_LeftShift },{ 2, 1, "Z", ImGuiKey_Z }, { 2, 2, "X", ImGuiKey_X }, { 2, 3, "C", ImGuiKey_C }, { 2, 4, "V", ImGuiKey_V } + }; + + // Elements rendered manually via ImDrawList API are not clipped automatically. + // While not strictly necessary, here IsItemVisible() is used to avoid rendering these shapes when they are out of view. + Dummy(board_max - board_min); + if (!IsItemVisible()) + return; + draw_list->PushClipRect(board_min, board_max, true); + for (int n = 0; n < IM_ARRAYSIZE(keys_to_display); n++) + { + const KeyLayoutData* key_data = &keys_to_display[n]; + ImVec2 key_min = ImVec2(start_pos.x + key_data->Col * key_step.x + key_data->Row * key_row_offset, start_pos.y + key_data->Row * key_step.y); + ImVec2 key_max = key_min + key_size; + draw_list->AddRectFilled(key_min, key_max, IM_COL32(204, 204, 204, 255), key_rounding); + draw_list->AddRect(key_min, key_max, IM_COL32(24, 24, 24, 255), key_rounding); + ImVec2 face_min = ImVec2(key_min.x + key_face_pos.x, key_min.y + key_face_pos.y); + ImVec2 face_max = ImVec2(face_min.x + key_face_size.x, face_min.y + key_face_size.y); + draw_list->AddRect(face_min, face_max, IM_COL32(193, 193, 193, 255), key_face_rounding, ImDrawFlags_None, 2.0f); + draw_list->AddRectFilled(face_min, face_max, IM_COL32(252, 252, 252, 255), key_face_rounding); + ImVec2 label_min = ImVec2(key_min.x + key_label_pos.x, key_min.y + key_label_pos.y); + draw_list->AddText(label_min, IM_COL32(64, 64, 64, 255), key_data->Label); + if (IsKeyDown(key_data->Key)) + draw_list->AddRectFilled(key_min, key_max, IM_COL32(255, 0, 0, 128), key_rounding); + } + draw_list->PopClipRect(); } // Helper tool to diagnose between text encoding issues and font loading issues. Pass your UTF-8 string and verify that there are correct. void ImGui::DebugTextEncoding(const char* str) { Text("Text: \"%s\"", str); - if (!BeginTable("list", 4, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg | ImGuiTableFlags_SizingFixedFit)) + if (!BeginTable("##DebugTextEncoding", 4, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg | ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_Resizable)) return; TableSetupColumn("Offset"); TableSetupColumn("UTF-8"); @@ -17842,9 +19218,8 @@ void ImGui::DebugTextEncoding(const char* str) static void MetricsHelpMarker(const char* desc) { ImGui::TextDisabled("(?)"); - if (ImGui::IsItemHovered()) + if (ImGui::IsItemHovered(ImGuiHoveredFlags_DelayShort) && ImGui::BeginTooltip()) { - ImGui::BeginTooltip(); ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f); ImGui::TextUnformatted(desc); ImGui::PopTextWrapPos(); @@ -17862,10 +19237,13 @@ void ImGui::ShowFontAtlas(ImFontAtlas* atlas) DebugNodeFont(font); PopID(); } - if (TreeNode("Atlas texture", "Atlas texture (%dx%d pixels)", atlas->TexWidth, atlas->TexHeight)) + if (TreeNode("Font Atlas", "Font Atlas (%dx%d pixels)", atlas->TexWidth, atlas->TexHeight)) { - ImVec4 tint_col = ImVec4(1.0f, 1.0f, 1.0f, 1.0f); - ImVec4 border_col = ImVec4(1.0f, 1.0f, 1.0f, 0.5f); + ImGuiContext& g = *GImGui; + ImGuiMetricsConfig* cfg = &g.DebugMetricsConfig; + Checkbox("Tint with Text Color", &cfg->ShowAtlasTintedWithTextColor); // Using text color ensure visibility of core atlas data, but will alter custom colored icons + ImVec4 tint_col = cfg->ShowAtlasTintedWithTextColor ? GetStyleColorVec4(ImGuiCol_Text) : ImVec4(1.0f, 1.0f, 1.0f, 1.0f); + ImVec4 border_col = GetStyleColorVec4(ImGuiCol_Border); Image(atlas->TexID, ImVec2((float)atlas->TexWidth, (float)atlas->TexHeight), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f), tint_col, border_col); TreePop(); } @@ -17876,6 +19254,8 @@ void ImGui::ShowMetricsWindow(bool* p_open) ImGuiContext& g = *GImGui; ImGuiIO& io = g.IO; ImGuiMetricsConfig* cfg = &g.DebugMetricsConfig; + if (cfg->ShowDebugLog) + ShowDebugLogWindow(&cfg->ShowDebugLog); if (cfg->ShowStackTool) ShowStackToolWindow(&cfg->ShowStackTool); @@ -17920,8 +19300,8 @@ void ImGui::ShowMetricsWindow(bool* p_open) else if (rect_type == TRT_ColumnsClipRect) { ImGuiTableColumn* c = &table->Columns[n]; return c->ClipRect; } else if (rect_type == TRT_ColumnsContentHeadersUsed){ ImGuiTableColumn* c = &table->Columns[n]; return ImRect(c->WorkMinX, table->InnerClipRect.Min.y, c->ContentMaxXHeadersUsed, table->InnerClipRect.Min.y + table_instance->LastFirstRowHeight); } // Note: y1/y2 not always accurate else if (rect_type == TRT_ColumnsContentHeadersIdeal){ImGuiTableColumn* c = &table->Columns[n]; return ImRect(c->WorkMinX, table->InnerClipRect.Min.y, c->ContentMaxXHeadersIdeal, table->InnerClipRect.Min.y + table_instance->LastFirstRowHeight); } - else if (rect_type == TRT_ColumnsContentFrozen) { ImGuiTableColumn* c = &table->Columns[n]; return ImRect(c->WorkMinX, table->InnerClipRect.Min.y, c->ContentMaxXFrozen, table->InnerClipRect.Min.y + table_instance->LastFirstRowHeight); } - else if (rect_type == TRT_ColumnsContentUnfrozen) { ImGuiTableColumn* c = &table->Columns[n]; return ImRect(c->WorkMinX, table->InnerClipRect.Min.y + table_instance->LastFirstRowHeight, c->ContentMaxXUnfrozen, table->InnerClipRect.Max.y); } + else if (rect_type == TRT_ColumnsContentFrozen) { ImGuiTableColumn* c = &table->Columns[n]; return ImRect(c->WorkMinX, table->InnerClipRect.Min.y, c->ContentMaxXFrozen, table->InnerClipRect.Min.y + table_instance->LastFrozenHeight); } + else if (rect_type == TRT_ColumnsContentUnfrozen) { ImGuiTableColumn* c = &table->Columns[n]; return ImRect(c->WorkMinX, table->InnerClipRect.Min.y + table_instance->LastFrozenHeight, c->ContentMaxXUnfrozen, table->InnerClipRect.Max.y); } IM_ASSERT(0); return ImRect(); } @@ -17957,8 +19337,19 @@ void ImGui::ShowMetricsWindow(bool* p_open) TreePop(); } + // The Item Picker tool is super useful to visually select an item and break into the call-stack of where it was submitted. + if (Checkbox("Show Item Picker", &g.DebugItemPickerActive) && g.DebugItemPickerActive) + DebugStartItemPicker(); + SameLine(); + MetricsHelpMarker("Will call the IM_DEBUG_BREAK() macro to break in debugger.\nWarning: If you don't have a debugger attached, this will probably crash."); + // Stack Tool is your best friend! - Checkbox("Show stack tool", &cfg->ShowStackTool); + Checkbox("Show Debug Log", &cfg->ShowDebugLog); + SameLine(); + MetricsHelpMarker("You can also call ImGui::ShowDebugLogWindow() from your code."); + + // Stack Tool is your best friend! + Checkbox("Show Stack Tool", &cfg->ShowStackTool); SameLine(); MetricsHelpMarker("You can also call ImGui::ShowStackToolWindow() from your code."); @@ -18024,11 +19415,9 @@ void ImGui::ShowMetricsWindow(bool* p_open) } } - // The Item Picker tool is super useful to visually select an item and break into the call-stack of where it was submitted. - if (Button("Item Picker..")) - DebugStartItemPicker(); + Checkbox("Debug Begin/BeginChild return value", &io.ConfigDebugBeginReturnValueLoop); SameLine(); - MetricsHelpMarker("Will call the IM_DEBUG_BREAK() macro to break in debugger.\nWarning: If you don't have a debugger attached, this will probably crash."); + MetricsHelpMarker("Some calls to Begin()/BeginChild() will return false.\n\nWill cycle through window depths then repeat. Windows should be flickering while running."); TreePop(); } @@ -18110,12 +19499,14 @@ void ImGui::ShowMetricsWindow(bool* p_open) viewports.resize(g.Viewports.Size); memcpy(viewports.Data, g.Viewports.Data, g.Viewports.size_in_bytes()); if (viewports.Size > 1) - ImQsort(viewports.Data, viewports.Size, sizeof(ImGuiViewport*), ViewportComparerByFrontMostStampCount); - for (int i = 0; i < viewports.Size; i++) - BulletText("Viewport #%d, ID: 0x%08X, FrontMostStampCount = %08d, Window: \"%s\"", viewports[i]->Idx, viewports[i]->ID, viewports[i]->LastFrontMostStampCount, viewports[i]->Window ? viewports[i]->Window->Name : "N/A"); + ImQsort(viewports.Data, viewports.Size, sizeof(ImGuiViewport*), ViewportComparerByLastFocusedStampCount); + for (ImGuiViewportP* viewport : viewports) + BulletText("Viewport #%d, ID: 0x%08X, LastFocused = %08d, PlatformFocused = %s, Window: \"%s\"", + viewport->Idx, viewport->ID, viewport->LastFocusedStampCount, + (g.PlatformIO.Platform_GetWindowFocus && viewport->PlatformWindowCreated) ? (g.PlatformIO.Platform_GetWindowFocus(viewport) ? "1" : "0") : "N/A", + viewport->Window ? viewport->Window->Name : "N/A"); TreePop(); } - for (int i = 0; i < g.Viewports.Size; i++) DebugNodeViewport(g.Viewports[i]); TreePop(); @@ -18126,8 +19517,12 @@ void ImGui::ShowMetricsWindow(bool* p_open) { for (int i = 0; i < g.OpenPopupStack.Size; i++) { - ImGuiWindow* window = g.OpenPopupStack[i].Window; - BulletText("PopupID: %08x, Window: '%s'%s%s", g.OpenPopupStack[i].PopupId, window ? window->Name : "NULL", window && (window->Flags & ImGuiWindowFlags_ChildWindow) ? " ChildWindow" : "", window && (window->Flags & ImGuiWindowFlags_ChildMenu) ? " ChildMenu" : ""); + // As it's difficult to interact with tree nodes while popups are open, we display everything inline. + const ImGuiPopupData* popup_data = &g.OpenPopupStack[i]; + ImGuiWindow* window = popup_data->Window; + BulletText("PopupID: %08x, Window: '%s' (%s%s), BackupNavWindow '%s', ParentWindow '%s'", + popup_data->PopupId, window ? window->Name : "NULL", window && (window->Flags & ImGuiWindowFlags_ChildWindow) ? "Child;" : "", window && (window->Flags & ImGuiWindowFlags_ChildMenu) ? "Menu;" : "", + popup_data->BackupNavWindow ? popup_data->BackupNavWindow->Name : "NULL", window && window->ParentWindow ? window->ParentWindow->Name : "NULL"); } TreePop(); } @@ -18162,6 +19557,13 @@ void ImGui::ShowMetricsWindow(bool* p_open) TreePop(); } + // Details for InputText + if (TreeNode("InputText")) + { + DebugNodeInputTextState(&g.InputTextState); + TreePop(); + } + // Details for Docking #ifdef IMGUI_HAS_DOCK if (TreeNode("Docking")) @@ -18235,7 +19637,7 @@ void ImGui::ShowMetricsWindow(bool* p_open) { if (ImGuiWindow* window = FindWindowByID(settings->SelectedTabId)) selected_tab_name = window->Name; - else if (ImGuiWindowSettings* window_settings = FindWindowSettings(settings->SelectedTabId)) + else if (ImGuiWindowSettings* window_settings = FindWindowSettingsByID(settings->SelectedTabId)) selected_tab_name = window_settings->GetName(); } BulletText("Node %08X, Parent %08X, SelectedTab %08X ('%s')", settings->ID, settings->ParentNodeId, settings->SelectedTabId, selected_tab_name ? selected_tab_name : settings->SelectedTabId ? "N/A" : ""); @@ -18252,7 +19654,99 @@ void ImGui::ShowMetricsWindow(bool* p_open) TreePop(); } - // Misc Details + if (TreeNode("Inputs")) + { + Text("KEYBOARD/GAMEPAD/MOUSE KEYS"); + { + // We iterate both legacy native range and named ImGuiKey ranges, which is a little odd but this allows displaying the data for old/new backends. + // User code should never have to go through such hoops! You can generally iterate between ImGuiKey_NamedKey_BEGIN and ImGuiKey_NamedKey_END. + Indent(); +#ifdef IMGUI_DISABLE_OBSOLETE_KEYIO + struct funcs { static bool IsLegacyNativeDupe(ImGuiKey) { return false; } }; +#else + struct funcs { static bool IsLegacyNativeDupe(ImGuiKey key) { return key < 512 && GetIO().KeyMap[key] != -1; } }; // Hide Native<>ImGuiKey duplicates when both exists in the array + //Text("Legacy raw:"); for (ImGuiKey key = ImGuiKey_KeysData_OFFSET; key < ImGuiKey_COUNT; key++) { if (io.KeysDown[key]) { SameLine(); Text("\"%s\" %d", GetKeyName(key), key); } } +#endif + Text("Keys down:"); for (ImGuiKey key = ImGuiKey_KeysData_OFFSET; key < ImGuiKey_COUNT; key = (ImGuiKey)(key + 1)) { if (funcs::IsLegacyNativeDupe(key) || !IsKeyDown(key)) continue; SameLine(); Text(IsNamedKey(key) ? "\"%s\"" : "\"%s\" %d", GetKeyName(key), key); SameLine(); Text("(%.02f)", GetKeyData(key)->DownDuration); } + Text("Keys pressed:"); for (ImGuiKey key = ImGuiKey_KeysData_OFFSET; key < ImGuiKey_COUNT; key = (ImGuiKey)(key + 1)) { if (funcs::IsLegacyNativeDupe(key) || !IsKeyPressed(key)) continue; SameLine(); Text(IsNamedKey(key) ? "\"%s\"" : "\"%s\" %d", GetKeyName(key), key); } + Text("Keys released:"); for (ImGuiKey key = ImGuiKey_KeysData_OFFSET; key < ImGuiKey_COUNT; key = (ImGuiKey)(key + 1)) { if (funcs::IsLegacyNativeDupe(key) || !IsKeyReleased(key)) continue; SameLine(); Text(IsNamedKey(key) ? "\"%s\"" : "\"%s\" %d", GetKeyName(key), key); } + Text("Keys mods: %s%s%s%s", io.KeyCtrl ? "CTRL " : "", io.KeyShift ? "SHIFT " : "", io.KeyAlt ? "ALT " : "", io.KeySuper ? "SUPER " : ""); + Text("Chars queue:"); for (int i = 0; i < io.InputQueueCharacters.Size; i++) { ImWchar c = io.InputQueueCharacters[i]; SameLine(); Text("\'%c\' (0x%04X)", (c > ' ' && c <= 255) ? (char)c : '?', c); } // FIXME: We should convert 'c' to UTF-8 here but the functions are not public. + DebugRenderKeyboardPreview(GetWindowDrawList()); + Unindent(); + } + + Text("MOUSE STATE"); + { + Indent(); + if (IsMousePosValid()) + Text("Mouse pos: (%g, %g)", io.MousePos.x, io.MousePos.y); + else + Text("Mouse pos: "); + Text("Mouse delta: (%g, %g)", io.MouseDelta.x, io.MouseDelta.y); + int count = IM_ARRAYSIZE(io.MouseDown); + Text("Mouse down:"); for (int i = 0; i < count; i++) if (IsMouseDown(i)) { SameLine(); Text("b%d (%.02f secs)", i, io.MouseDownDuration[i]); } + Text("Mouse clicked:"); for (int i = 0; i < count; i++) if (IsMouseClicked(i)) { SameLine(); Text("b%d (%d)", i, io.MouseClickedCount[i]); } + Text("Mouse released:"); for (int i = 0; i < count; i++) if (IsMouseReleased(i)) { SameLine(); Text("b%d", i); } + Text("Mouse wheel: %.1f", io.MouseWheel); + Text("Mouse source: %s", GetMouseSourceName(io.MouseSource)); + Text("Pen Pressure: %.1f", io.PenPressure); // Note: currently unused + Unindent(); + } + + Text("MOUSE WHEELING"); + { + Indent(); + Text("WheelingWindow: '%s'", g.WheelingWindow ? g.WheelingWindow->Name : "NULL"); + Text("WheelingWindowReleaseTimer: %.2f", g.WheelingWindowReleaseTimer); + Text("WheelingAxisAvg[] = { %.3f, %.3f }, Main Axis: %s", g.WheelingAxisAvg.x, g.WheelingAxisAvg.y, (g.WheelingAxisAvg.x > g.WheelingAxisAvg.y) ? "X" : (g.WheelingAxisAvg.x < g.WheelingAxisAvg.y) ? "Y" : ""); + Unindent(); + } + + Text("KEY OWNERS"); + { + Indent(); + if (BeginListBox("##owners", ImVec2(-FLT_MIN, GetTextLineHeightWithSpacing() * 6))) + { + for (ImGuiKey key = ImGuiKey_NamedKey_BEGIN; key < ImGuiKey_NamedKey_END; key = (ImGuiKey)(key + 1)) + { + ImGuiKeyOwnerData* owner_data = GetKeyOwnerData(&g, key); + if (owner_data->OwnerCurr == ImGuiKeyOwner_None) + continue; + Text("%s: 0x%08X%s", GetKeyName(key), owner_data->OwnerCurr, + owner_data->LockUntilRelease ? " LockUntilRelease" : owner_data->LockThisFrame ? " LockThisFrame" : ""); + DebugLocateItemOnHover(owner_data->OwnerCurr); + } + EndListBox(); + } + Unindent(); + } + Text("SHORTCUT ROUTING"); + { + Indent(); + if (BeginListBox("##routes", ImVec2(-FLT_MIN, GetTextLineHeightWithSpacing() * 6))) + { + for (ImGuiKey key = ImGuiKey_NamedKey_BEGIN; key < ImGuiKey_NamedKey_END; key = (ImGuiKey)(key + 1)) + { + ImGuiKeyRoutingTable* rt = &g.KeysRoutingTable; + for (ImGuiKeyRoutingIndex idx = rt->Index[key - ImGuiKey_NamedKey_BEGIN]; idx != -1; ) + { + char key_chord_name[64]; + ImGuiKeyRoutingData* routing_data = &rt->Entries[idx]; + GetKeyChordName(key | routing_data->Mods, key_chord_name, IM_ARRAYSIZE(key_chord_name)); + Text("%s: 0x%08X", key_chord_name, routing_data->RoutingCurr); + DebugLocateItemOnHover(routing_data->RoutingCurr); + idx = routing_data->NextEntryIndex; + } + } + EndListBox(); + } + Text("(ActiveIdUsing: AllKeyboardKeys: %d, NavDirMask: 0x%X)", g.ActiveIdUsingAllKeyboardKeys, g.ActiveIdUsingNavDirMask); + Unindent(); + } + TreePop(); + } + if (TreeNode("Internal state")) { Text("WINDOWING"); @@ -18260,7 +19754,7 @@ void ImGui::ShowMetricsWindow(bool* p_open) Text("HoveredWindow: '%s'", g.HoveredWindow ? g.HoveredWindow->Name : "NULL"); Text("HoveredWindow->Root: '%s'", g.HoveredWindow ? g.HoveredWindow->RootWindowDockTree->Name : "NULL"); Text("HoveredWindowUnderMovingWindow: '%s'", g.HoveredWindowUnderMovingWindow ? g.HoveredWindowUnderMovingWindow->Name : "NULL"); - Text("HoveredDockNode: 0x%08X", g.HoveredDockNode ? g.HoveredDockNode->ID : 0); + Text("HoveredDockNode: 0x%08X", g.DebugHoveredDockNode ? g.DebugHoveredDockNode->ID : 0); Text("MovingWindow: '%s'", g.MovingWindow ? g.MovingWindow->Name : "NULL"); Text("MouseViewport: 0x%08X (UserHovered 0x%08X, LastHovered 0x%08X)", g.MouseViewport->ID, g.IO.MouseHoveredViewport, g.MouseLastHoveredViewport ? g.MouseLastHoveredViewport->ID : 0); Unindent(); @@ -18268,23 +19762,23 @@ void ImGui::ShowMetricsWindow(bool* p_open) Text("ITEMS"); Indent(); Text("ActiveId: 0x%08X/0x%08X (%.2f sec), AllowOverlap: %d, Source: %s", g.ActiveId, g.ActiveIdPreviousFrame, g.ActiveIdTimer, g.ActiveIdAllowOverlap, GetInputSourceName(g.ActiveIdSource)); + DebugLocateItemOnHover(g.ActiveId); Text("ActiveIdWindow: '%s'", g.ActiveIdWindow ? g.ActiveIdWindow->Name : "NULL"); - - int active_id_using_key_input_count = 0; - for (int n = ImGuiKey_NamedKey_BEGIN; n < ImGuiKey_NamedKey_END; n++) - active_id_using_key_input_count += g.ActiveIdUsingKeyInputMask[n] ? 1 : 0; - Text("ActiveIdUsing: Wheel: %d, NavDirMask: %X, NavInputMask: %X, KeyInputMask: %d key(s)", g.ActiveIdUsingMouseWheel, g.ActiveIdUsingNavDirMask, g.ActiveIdUsingNavInputMask, active_id_using_key_input_count); + Text("ActiveIdUsing: AllKeyboardKeys: %d, NavDirMask: %X", g.ActiveIdUsingAllKeyboardKeys, g.ActiveIdUsingNavDirMask); Text("HoveredId: 0x%08X (%.2f sec), AllowOverlap: %d", g.HoveredIdPreviousFrame, g.HoveredIdTimer, g.HoveredIdAllowOverlap); // Not displaying g.HoveredId as it is update mid-frame + Text("HoverDelayId: 0x%08X, Timer: %.2f, ClearTimer: %.2f", g.HoverDelayId, g.HoverDelayTimer, g.HoverDelayClearTimer); Text("DragDrop: %d, SourceId = 0x%08X, Payload \"%s\" (%d bytes)", g.DragDropActive, g.DragDropPayload.SourceId, g.DragDropPayload.DataType, g.DragDropPayload.DataSize); + DebugLocateItemOnHover(g.DragDropPayload.SourceId); Unindent(); Text("NAV,FOCUS"); Indent(); Text("NavWindow: '%s'", g.NavWindow ? g.NavWindow->Name : "NULL"); Text("NavId: 0x%08X, NavLayer: %d", g.NavId, g.NavLayer); + DebugLocateItemOnHover(g.NavId); Text("NavInputSource: %s", GetInputSourceName(g.NavInputSource)); Text("NavActive: %d, NavVisible: %d", g.IO.NavActive, g.IO.NavVisible); - Text("NavActivateId/DownId/PressedId/InputId: %08X/%08X/%08X/%08X", g.NavActivateId, g.NavActivateDownId, g.NavActivatePressedId, g.NavActivateInputId); + Text("NavActivateId/DownId/PressedId: %08X/%08X/%08X", g.NavActivateId, g.NavActivateDownId, g.NavActivatePressedId); Text("NavActivateFlags: %04X", g.NavActivateFlags); Text("NavDisableHighlight: %d, NavDisableMouseHover: %d", g.NavDisableHighlight, g.NavDisableMouseHover); Text("NavFocusScopeId = 0x%08X", g.NavFocusScopeId); @@ -18348,11 +19842,11 @@ void ImGui::ShowMetricsWindow(bool* p_open) #ifdef IMGUI_HAS_DOCK // Overlay: Display Docking info - if (cfg->ShowDockingNodes && g.IO.KeyCtrl && g.HoveredDockNode) + if (cfg->ShowDockingNodes && g.IO.KeyCtrl && g.DebugHoveredDockNode) { char buf[64] = ""; char* p = buf; - ImGuiDockNode* node = g.HoveredDockNode; + ImGuiDockNode* node = g.DebugHoveredDockNode; ImDrawList* overlay_draw_list = node->HostWindow ? GetForegroundDrawList(node->HostWindow) : GetForegroundDrawList(GetMainViewport()); p += ImFormatString(p, buf + IM_ARRAYSIZE(buf) - p, "DockId: %X%s\n", node->ID, node->IsCentralNode() ? " *CentralNode*" : ""); p += ImFormatString(p, buf + IM_ARRAYSIZE(buf) - p, "WindowClass: %08X\n", node->WindowClass.ClassId); @@ -18416,10 +19910,11 @@ void ImGui::DebugNodeDockNode(ImGuiDockNode* node, const char* label) const bool is_active = (g.FrameCount - node->LastFrameActive < 2); // Submitted if (!is_alive) { PushStyleColor(ImGuiCol_Text, GetStyleColorVec4(ImGuiCol_TextDisabled)); } bool open; + ImGuiTreeNodeFlags tree_node_flags = node->IsFocused ? ImGuiTreeNodeFlags_Selected : ImGuiTreeNodeFlags_None; if (node->Windows.Size > 0) - open = TreeNode((void*)(intptr_t)node->ID, "%s 0x%04X%s: %d windows (vis: '%s')", label, node->ID, node->IsVisible ? "" : " (hidden)", node->Windows.Size, node->VisibleWindow ? node->VisibleWindow->Name : "NULL"); + open = TreeNodeEx((void*)(intptr_t)node->ID, tree_node_flags, "%s 0x%04X%s: %d windows (vis: '%s')", label, node->ID, node->IsVisible ? "" : " (hidden)", node->Windows.Size, node->VisibleWindow ? node->VisibleWindow->Name : "NULL"); else - open = TreeNode((void*)(intptr_t)node->ID, "%s 0x%04X%s: %s split (vis: '%s')", label, node->ID, node->IsVisible ? "" : " (hidden)", (node->SplitAxis == ImGuiAxis_X) ? "horizontal" : (node->SplitAxis == ImGuiAxis_Y) ? "vertical" : "n/a", node->VisibleWindow ? node->VisibleWindow->Name : "NULL"); + open = TreeNodeEx((void*)(intptr_t)node->ID, tree_node_flags, "%s 0x%04X%s: %s (vis: '%s')", label, node->ID, node->IsVisible ? "" : " (hidden)", (node->SplitAxis == ImGuiAxis_X) ? "horizontal split" : (node->SplitAxis == ImGuiAxis_Y) ? "vertical split" : "empty", node->VisibleWindow ? node->VisibleWindow->Name : "NULL"); if (!is_alive) { PopStyleColor(); } if (is_active && IsItemHovered()) if (ImGuiWindow* window = node->HostWindow ? node->HostWindow : node->VisibleWindow) @@ -18433,10 +19928,10 @@ void ImGui::DebugNodeDockNode(ImGuiDockNode* node, const char* label) DebugNodeWindow(node->HostWindow, "HostWindow"); DebugNodeWindow(node->VisibleWindow, "VisibleWindow"); BulletText("SelectedTabID: 0x%08X, LastFocusedNodeID: 0x%08X", node->SelectedTabId, node->LastFocusedNodeId); - BulletText("Misc:%s%s%s%s%s%s", + BulletText("Misc:%s%s%s%s%s%s%s", node->IsDockSpace() ? " IsDockSpace" : "", node->IsCentralNode() ? " IsCentralNode" : "", - is_alive ? " IsAlive" : "", is_active ? " IsActive" : "", + is_alive ? " IsAlive" : "", is_active ? " IsActive" : "", node->IsFocused ? " IsFocused" : "", node->WantLockSizeOnce ? " WantLockSizeOnce" : "", node->HasCentralNodeChild ? " HasCentralNodeChild" : ""); if (TreeNode("flags", "Flags Merged: 0x%04X, Local: 0x%04X, InWindows: 0x%04X, Shared: 0x%04X", node->MergedFlags, node->LocalFlags, node->LocalFlagsInWindows, node->SharedFlags)) @@ -18459,6 +19954,8 @@ void ImGui::DebugNodeDockNode(ImGuiDockNode* node, const char* label) DebugNodeDockNode(node->ChildNodes[1], "Child[1]"); if (node->TabBar) DebugNodeTabBar(node->TabBar, "TabBar"); + DebugNodeWindowsList(&node->Windows, "Windows"); + TreePop(); } } @@ -18665,9 +20162,8 @@ void ImGui::DebugNodeFont(ImFont* font) if (!glyph) continue; font->RenderChar(draw_list, cell_size, cell_p1, glyph_col, (ImWchar)(base + n)); - if (IsMouseHoveringRect(cell_p1, cell_p2)) + if (IsMouseHoveringRect(cell_p1, cell_p2) && BeginTooltip()) { - BeginTooltip(); DebugNodeFontGlyph(font, glyph); EndTooltip(); } @@ -18711,13 +20207,11 @@ void ImGui::DebugNodeTabBar(ImGuiTabBar* tab_bar, const char* label) char* p = buf; const char* buf_end = buf + IM_ARRAYSIZE(buf); const bool is_active = (tab_bar->PrevFrameVisible >= GetFrameCount() - 2); - p += ImFormatString(p, buf_end - p, "%s 0x%08X (%d tabs)%s", label, tab_bar->ID, tab_bar->Tabs.Size, is_active ? "" : " *Inactive*"); - p += ImFormatString(p, buf_end - p, " { "); + p += ImFormatString(p, buf_end - p, "%s 0x%08X (%d tabs)%s {", label, tab_bar->ID, tab_bar->Tabs.Size, is_active ? "" : " *Inactive*"); for (int tab_n = 0; tab_n < ImMin(tab_bar->Tabs.Size, 3); tab_n++) { ImGuiTabItem* tab = &tab_bar->Tabs[tab_n]; - p += ImFormatString(p, buf_end - p, "%s'%s'", - tab_n > 0 ? ", " : "", (tab->Window || tab->NameOffset != -1) ? tab_bar->GetTabName(tab) : "???"); + p += ImFormatString(p, buf_end - p, "%s'%s'", tab_n > 0 ? ", " : "", TabBarGetTabName(tab_bar, tab)); } p += ImFormatString(p, buf_end - p, (tab_bar->Tabs.Size > 3) ? " ... }" : " } "); if (!is_active) { PushStyleColor(ImGuiCol_Text, GetStyleColorVec4(ImGuiCol_TextDisabled)); } @@ -18734,12 +20228,12 @@ void ImGui::DebugNodeTabBar(ImGuiTabBar* tab_bar, const char* label) { for (int tab_n = 0; tab_n < tab_bar->Tabs.Size; tab_n++) { - const ImGuiTabItem* tab = &tab_bar->Tabs[tab_n]; + ImGuiTabItem* tab = &tab_bar->Tabs[tab_n]; PushID(tab); if (SmallButton("<")) { TabBarQueueReorder(tab_bar, tab, -1); } SameLine(0, 2); if (SmallButton(">")) { TabBarQueueReorder(tab_bar, tab, +1); } SameLine(); - Text("%02d%c Tab 0x%08X '%s' Offset: %.1f, Width: %.1f/%.1f", - tab_n, (tab->ID == tab_bar->SelectedTabId) ? '*' : ' ', tab->ID, (tab->Window || tab->NameOffset != -1) ? tab_bar->GetTabName(tab) : "???", tab->Offset, tab->Width, tab->ContentWidth); + Text("%02d%c Tab 0x%08X '%s' Offset: %.2f, Width: %.2f/%.2f", + tab_n, (tab->ID == tab_bar->SelectedTabId) ? '*' : ' ', tab->ID, TabBarGetTabName(tab_bar, tab), tab->Offset, tab->Width, tab->ContentWidth); PopID(); } TreePop(); @@ -18757,9 +20251,11 @@ void ImGui::DebugNodeViewport(ImGuiViewportP* viewport) viewport->WorkOffsetMin.x, viewport->WorkOffsetMin.y, viewport->WorkOffsetMax.x, viewport->WorkOffsetMax.y, viewport->PlatformMonitor, viewport->DpiScale * 100.0f); if (viewport->Idx > 0) { SameLine(); if (SmallButton("Reset Pos")) { viewport->Pos = ImVec2(200, 200); viewport->UpdateWorkRect(); if (viewport->Window) viewport->Window->Pos = viewport->Pos; } } - BulletText("Flags: 0x%04X =%s%s%s%s%s%s%s%s%s%s%s%s", viewport->Flags, + BulletText("Flags: 0x%04X =%s%s%s%s%s%s%s%s%s%s%s%s%s", viewport->Flags, //(flags & ImGuiViewportFlags_IsPlatformWindow) ? " IsPlatformWindow" : "", // Omitting because it is the standard (flags & ImGuiViewportFlags_IsPlatformMonitor) ? " IsPlatformMonitor" : "", + (flags & ImGuiViewportFlags_IsMinimized) ? " IsMinimized" : "", + (flags & ImGuiViewportFlags_IsFocused) ? " IsFocused" : "", (flags & ImGuiViewportFlags_OwnedByApp) ? " OwnedByApp" : "", (flags & ImGuiViewportFlags_NoDecoration) ? " NoDecoration" : "", (flags & ImGuiViewportFlags_NoTaskBarIcon) ? " NoTaskBarIcon" : "", @@ -18767,9 +20263,8 @@ void ImGui::DebugNodeViewport(ImGuiViewportP* viewport) (flags & ImGuiViewportFlags_NoFocusOnClick) ? " NoFocusOnClick" : "", (flags & ImGuiViewportFlags_NoInputs) ? " NoInputs" : "", (flags & ImGuiViewportFlags_NoRendererClear) ? " NoRendererClear" : "", - (flags & ImGuiViewportFlags_TopMost) ? " TopMost" : "", - (flags & ImGuiViewportFlags_Minimized) ? " Minimized" : "", (flags & ImGuiViewportFlags_NoAutoMerge) ? " NoAutoMerge" : "", + (flags & ImGuiViewportFlags_TopMost) ? " TopMost" : "", (flags & ImGuiViewportFlags_CanHostOtherWindows) ? " CanHostOtherWindows" : ""); for (int layer_i = 0; layer_i < IM_ARRAYSIZE(viewport->DrawDataBuilder.Layers); layer_i++) for (int draw_list_i = 0; draw_list_i < viewport->DrawDataBuilder.Layers[layer_i].Size; draw_list_i++) @@ -18816,14 +20311,14 @@ void ImGui::DebugNodeWindow(ImGuiWindow* window, const char* label) { ImRect r = window->NavRectRel[layer]; if (r.Min.x >= r.Max.y && r.Min.y >= r.Max.y) - { BulletText("NavLastIds[%d]: 0x%08X", layer, window->NavLastIds[layer]); - continue; - } - BulletText("NavLastIds[%d]: 0x%08X at +(%.1f,%.1f)(%.1f,%.1f)", layer, window->NavLastIds[layer], r.Min.x, r.Min.y, r.Max.x, r.Max.y); - if (IsItemHovered()) - GetForegroundDrawList(window)->AddRect(r.Min + window->Pos, r.Max + window->Pos, IM_COL32(255, 255, 0, 255)); + else + BulletText("NavLastIds[%d]: 0x%08X at +(%.1f,%.1f)(%.1f,%.1f)", layer, window->NavLastIds[layer], r.Min.x, r.Min.y, r.Max.x, r.Max.y); + DebugLocateItemOnHover(window->NavLastIds[layer]); } + const ImVec2* pr = window->NavPreferredScoringPosRel; + for (int layer = 0; layer < ImGuiNavLayer_COUNT; layer++) + BulletText("NavPreferredScoringPosRel[%d] = {%.1f,%.1f)", layer, (pr[layer].x == FLT_MAX ? -99999.0f : pr[layer].x), (pr[layer].y == FLT_MAX ? -99999.0f : pr[layer].y)); // Display as 99999.0f so it looks neater. BulletText("NavLayersActiveMask: %X, NavLastChildNavWindow: %s", window->DC.NavLayersActiveMask, window->NavLastChildNavWindow ? window->NavLastChildNavWindow->Name : "NULL"); BulletText("Viewport: %d%s, ViewportId: 0x%08X, ViewportPos: (%.1f,%.1f)", window->Viewport ? window->Viewport->Idx : -1, window->ViewportOwned ? " (Owned)" : "", window->ViewportId, window->ViewportPos.x, window->ViewportPos.y); @@ -18848,8 +20343,12 @@ void ImGui::DebugNodeWindow(ImGuiWindow* window, const char* label) void ImGui::DebugNodeWindowSettings(ImGuiWindowSettings* settings) { + if (settings->WantDelete) + BeginDisabled(); Text("0x%08X \"%s\" Pos (%d,%d) Size (%d,%d) Collapsed=%d", settings->ID, settings->GetName(), settings->Pos.x, settings->Pos.y, settings->Size.x, settings->Size.y, settings->Collapsed); + if (settings->WantDelete) + EndDisabled(); } void ImGui::DebugNodeWindowsList(ImVector* windows, const char* label) @@ -18883,10 +20382,127 @@ void ImGui::DebugNodeWindowsListByBeginStackParent(ImGuiWindow** windows, int wi } } +//----------------------------------------------------------------------------- +// [SECTION] DEBUG LOG WINDOW +//----------------------------------------------------------------------------- + +void ImGui::DebugLog(const char* fmt, ...) +{ + va_list args; + va_start(args, fmt); + DebugLogV(fmt, args); + va_end(args); +} + +void ImGui::DebugLogV(const char* fmt, va_list args) +{ + ImGuiContext& g = *GImGui; + const int old_size = g.DebugLogBuf.size(); + g.DebugLogBuf.appendf("[%05d] ", g.FrameCount); + g.DebugLogBuf.appendfv(fmt, args); + if (g.DebugLogFlags & ImGuiDebugLogFlags_OutputToTTY) + IMGUI_DEBUG_PRINTF("%s", g.DebugLogBuf.begin() + old_size); + g.DebugLogIndex.append(g.DebugLogBuf.c_str(), old_size, g.DebugLogBuf.size()); +} + +void ImGui::ShowDebugLogWindow(bool* p_open) +{ + ImGuiContext& g = *GImGui; + if (!(g.NextWindowData.Flags & ImGuiNextWindowDataFlags_HasSize)) + SetNextWindowSize(ImVec2(0.0f, GetFontSize() * 12.0f), ImGuiCond_FirstUseEver); + if (!Begin("Dear ImGui Debug Log", p_open) || GetCurrentWindow()->BeginCount > 1) + { + End(); + return; + } + + CheckboxFlags("All", &g.DebugLogFlags, ImGuiDebugLogFlags_EventMask_); + SameLine(); CheckboxFlags("ActiveId", &g.DebugLogFlags, ImGuiDebugLogFlags_EventActiveId); + SameLine(); CheckboxFlags("Focus", &g.DebugLogFlags, ImGuiDebugLogFlags_EventFocus); + SameLine(); CheckboxFlags("Popup", &g.DebugLogFlags, ImGuiDebugLogFlags_EventPopup); + SameLine(); CheckboxFlags("Nav", &g.DebugLogFlags, ImGuiDebugLogFlags_EventNav); + SameLine(); if (CheckboxFlags("Clipper", &g.DebugLogFlags, ImGuiDebugLogFlags_EventClipper)) { g.DebugLogClipperAutoDisableFrames = 2; } if (IsItemHovered()) SetTooltip("Clipper log auto-disabled after 2 frames"); + //SameLine(); CheckboxFlags("Selection", &g.DebugLogFlags, ImGuiDebugLogFlags_EventSelection); + SameLine(); CheckboxFlags("IO", &g.DebugLogFlags, ImGuiDebugLogFlags_EventIO); + SameLine(); CheckboxFlags("Docking", &g.DebugLogFlags, ImGuiDebugLogFlags_EventDocking); + SameLine(); CheckboxFlags("Viewport", &g.DebugLogFlags, ImGuiDebugLogFlags_EventViewport); + + if (SmallButton("Clear")) + { + g.DebugLogBuf.clear(); + g.DebugLogIndex.clear(); + } + SameLine(); + if (SmallButton("Copy")) + SetClipboardText(g.DebugLogBuf.c_str()); + BeginChild("##log", ImVec2(0.0f, 0.0f), true, ImGuiWindowFlags_AlwaysVerticalScrollbar | ImGuiWindowFlags_AlwaysHorizontalScrollbar); + + ImGuiListClipper clipper; + clipper.Begin(g.DebugLogIndex.size()); + while (clipper.Step()) + for (int line_no = clipper.DisplayStart; line_no < clipper.DisplayEnd; line_no++) + { + const char* line_begin = g.DebugLogIndex.get_line_begin(g.DebugLogBuf.c_str(), line_no); + const char* line_end = g.DebugLogIndex.get_line_end(g.DebugLogBuf.c_str(), line_no); + TextUnformatted(line_begin, line_end); + ImRect text_rect = g.LastItemData.Rect; + if (IsItemHovered()) + for (const char* p = line_begin; p <= line_end - 10; p++) + { + ImGuiID id = 0; + if (p[0] != '0' || (p[1] != 'x' && p[1] != 'X') || sscanf(p + 2, "%X", &id) != 1) + continue; + ImVec2 p0 = CalcTextSize(line_begin, p); + ImVec2 p1 = CalcTextSize(p, p + 10); + g.LastItemData.Rect = ImRect(text_rect.Min + ImVec2(p0.x, 0.0f), text_rect.Min + ImVec2(p0.x + p1.x, p1.y)); + if (IsMouseHoveringRect(g.LastItemData.Rect.Min, g.LastItemData.Rect.Max, true)) + DebugLocateItemOnHover(id); + p += 10; + } + } + if (GetScrollY() >= GetScrollMaxY()) + SetScrollHereY(1.0f); + EndChild(); + + End(); +} + //----------------------------------------------------------------------------- // [SECTION] OTHER DEBUG TOOLS (ITEM PICKER, STACK TOOL) //----------------------------------------------------------------------------- +static const ImU32 DEBUG_LOCATE_ITEM_COLOR = IM_COL32(0, 255, 0, 255); // Green + +void ImGui::DebugLocateItem(ImGuiID target_id) +{ + ImGuiContext& g = *GImGui; + g.DebugLocateId = target_id; + g.DebugLocateFrames = 2; +} + +void ImGui::DebugLocateItemOnHover(ImGuiID target_id) +{ + if (target_id == 0 || !IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem | ImGuiHoveredFlags_AllowWhenBlockedByPopup)) + return; + ImGuiContext& g = *GImGui; + DebugLocateItem(target_id); + GetForegroundDrawList(g.CurrentWindow)->AddRect(g.LastItemData.Rect.Min - ImVec2(3.0f, 3.0f), g.LastItemData.Rect.Max + ImVec2(3.0f, 3.0f), DEBUG_LOCATE_ITEM_COLOR); +} + +void ImGui::DebugLocateItemResolveWithLastItem() +{ + ImGuiContext& g = *GImGui; + ImGuiLastItemData item_data = g.LastItemData; + g.DebugLocateId = 0; + ImDrawList* draw_list = GetForegroundDrawList(g.CurrentWindow); + ImRect r = item_data.Rect; + r.Expand(3.0f); + ImVec2 p1 = g.IO.MousePos; + ImVec2 p2 = ImVec2((p1.x < r.Min.x) ? r.Min.x : (p1.x > r.Max.x) ? r.Max.x : p1.x, (p1.y < r.Min.y) ? r.Min.y : (p1.y > r.Max.y) ? r.Max.y : p1.y); + draw_list->AddRect(r.Min, r.Max, DEBUG_LOCATE_ITEM_COLOR); + draw_list->AddLine(p1, p2, DEBUG_LOCATE_ITEM_COLOR); +} + // [DEBUG] Item picker tool - start with DebugStartItemPicker() - useful to visually select an item and break into its call-stack. void ImGui::UpdateDebugToolItemPicker() { @@ -18899,16 +20515,25 @@ void ImGui::UpdateDebugToolItemPicker() SetMouseCursor(ImGuiMouseCursor_Hand); if (IsKeyPressed(ImGuiKey_Escape)) g.DebugItemPickerActive = false; - if (IsMouseClicked(0) && hovered_id) + const bool change_mapping = g.IO.KeyMods == (ImGuiMod_Ctrl | ImGuiMod_Shift); + if (!change_mapping && IsMouseClicked(g.DebugItemPickerMouseButton) && hovered_id) { g.DebugItemPickerBreakId = hovered_id; g.DebugItemPickerActive = false; } - SetNextWindowBgAlpha(0.60f); - BeginTooltip(); + for (int mouse_button = 0; mouse_button < 3; mouse_button++) + if (change_mapping && IsMouseClicked(mouse_button)) + g.DebugItemPickerMouseButton = (ImU8)mouse_button; + SetNextWindowBgAlpha(0.70f); + if (!BeginTooltip()) + return; Text("HoveredId: 0x%08X", hovered_id); Text("Press ESC to abort picking."); - TextColored(GetStyleColorVec4(hovered_id ? ImGuiCol_Text : ImGuiCol_TextDisabled), "Click to break in debugger!"); + const char* mouse_button_names[] = { "Left", "Right", "Middle" }; + if (change_mapping) + Text("Remap w/ Ctrl+Shift: click anywhere to select new mouse button."); + else + TextColored(GetStyleColorVec4(hovered_id ? ImGuiCol_Text : ImGuiCol_TextDisabled), "Click %s Button to break in debugger! (remap w/ Ctrl+Shift)", mouse_button_names[g.DebugItemPickerMouseButton]); EndTooltip(); } @@ -18960,7 +20585,7 @@ void ImGui::DebugHookIdInfo(ImGuiID id, ImGuiDataType data_type, const void* dat ImGuiStackTool* tool = &g.DebugStackTool; // Step 0: stack query - // This assume that the ID was computed with the current ID stack, which tends to be the case for our widget. + // This assumes that the ID was computed with the current ID stack, which tends to be the case for our widget. if (tool->StackLevel == -1) { tool->StackLevel++; @@ -19046,11 +20671,11 @@ void ImGui::ShowStackToolWindow(bool* p_open) Checkbox("Ctrl+C: copy path to clipboard", &tool->CopyToClipboardOnCtrlC); SameLine(); TextColored((time_since_copy >= 0.0f && time_since_copy < 0.75f && ImFmod(time_since_copy, 0.25f) < 0.25f * 0.5f) ? ImVec4(1.f, 1.f, 0.3f, 1.f) : ImVec4(), "*COPIED*"); - if (tool->CopyToClipboardOnCtrlC && IsKeyDown(ImGuiKey_ModCtrl) && IsKeyPressed(ImGuiKey_C)) + if (tool->CopyToClipboardOnCtrlC && IsKeyDown(ImGuiMod_Ctrl) && IsKeyPressed(ImGuiKey_C)) { tool->CopyToClipboardLastTime = (float)g.Time; - char* p = g.TempBuffer; - char* p_end = p + IM_ARRAYSIZE(g.TempBuffer); + char* p = g.TempBuffer.Data; + char* p_end = p + g.TempBuffer.Size; for (int stack_n = 0; stack_n < tool->Results.Size && p + 3 < p_end; stack_n++) { *p++ = '/'; @@ -19064,7 +20689,7 @@ void ImGui::ShowStackToolWindow(bool* p_open) } } *p = '\0'; - SetClipboardText(g.TempBuffer); + SetClipboardText(g.TempBuffer.Data); } // Display decorated stack @@ -19082,8 +20707,8 @@ void ImGui::ShowStackToolWindow(bool* p_open) TableNextColumn(); Text("0x%08X", (n > 0) ? tool->Results[n - 1].ID : 0); TableNextColumn(); - StackToolFormatLevelInfo(tool, n, true, g.TempBuffer, IM_ARRAYSIZE(g.TempBuffer)); - TextUnformatted(g.TempBuffer); + StackToolFormatLevelInfo(tool, n, true, g.TempBuffer.Data, g.TempBuffer.Size); + TextUnformatted(g.TempBuffer.Data); TableNextColumn(); Text("0x%08X", info->ID); if (n == tool->Results.Size - 1) @@ -19109,12 +20734,15 @@ void ImGui::DebugNodeWindowSettings(ImGuiWindowSettings*) {} void ImGui::DebugNodeWindowsList(ImVector*, const char*) {} void ImGui::DebugNodeViewport(ImGuiViewportP*) {} +void ImGui::DebugLog(const char*, ...) {} +void ImGui::DebugLogV(const char*, va_list) {} +void ImGui::ShowDebugLogWindow(bool*) {} void ImGui::ShowStackToolWindow(bool*) {} void ImGui::DebugHookIdInfo(ImGuiID, ImGuiDataType, const void*, const void*) {} void ImGui::UpdateDebugToolItemPicker() {} void ImGui::UpdateDebugToolStackQueries() {} -#endif // #ifndef IMGUI_DISABLE_METRICS_WINDOW +#endif // #ifndef IMGUI_DISABLE_DEBUG_TOOLS //----------------------------------------------------------------------------- diff --git a/extern/imgui_patched/imgui.h b/extern/imgui_patched/imgui.h index 7aa62aa6..f7801136 100644 --- a/extern/imgui_patched/imgui.h +++ b/extern/imgui_patched/imgui.h @@ -1,17 +1,17 @@ -// dear imgui, v1.88 WIP +// dear imgui, v1.89.6 // (headers) // Help: -// - Read FAQ at http://dearimgui.org/faq +// - Read FAQ at http://dearimgui.com/faq // - Newcomers, read 'Programmer guide' in imgui.cpp for notes on how to setup Dear ImGui in your codebase. // - Call and read ImGui::ShowDemoWindow() in imgui_demo.cpp. All applications in examples/ are doing that. // Read imgui.cpp for details, links and comments. // Resources: -// - FAQ http://dearimgui.org/faq +// - FAQ http://dearimgui.com/faq // - Homepage & latest https://github.com/ocornut/imgui // - Releases & changelog https://github.com/ocornut/imgui/releases -// - Gallery https://github.com/ocornut/imgui/issues/5243 (please post your screenshots/video there!) +// - Gallery https://github.com/ocornut/imgui/issues/6478 (please post your screenshots/video there!) // - Wiki https://github.com/ocornut/imgui/wiki (lots of good stuff there) // - Glossary https://github.com/ocornut/imgui/wiki/Glossary // - Issues & support https://github.com/ocornut/imgui/issues @@ -20,6 +20,14 @@ // - For first-time users having issues compiling/linking/running or issues loading fonts: // please post in https://github.com/ocornut/imgui/discussions if you cannot find a solution in resources above. +// Library Version +// (Integer encoded as XYYZZ for use in #if preprocessor conditionals, e.g. '#if IMGUI_VERSION_NUM >= 12345') +#define IMGUI_VERSION "1.89.6" +#define IMGUI_VERSION_NUM 18960 +#define IMGUI_HAS_TABLE +#define IMGUI_HAS_VIEWPORT // Viewport WIP branch +#define IMGUI_HAS_DOCK // Docking WIP branch + /* Index of this file: @@ -31,7 +39,7 @@ Index of this file: // [SECTION] ImGuiStyle // [SECTION] ImGuiIO // [SECTION] Misc data structures (ImGuiInputTextCallbackData, ImGuiSizeCallbackData, ImGuiWindowClass, ImGuiPayload, ImGuiTableSortSpecs, ImGuiTableColumnSortSpecs) -// [SECTION] Helpers (ImGuiOnceUponAFrame, ImGuiTextFilter, ImGuiTextBuffer, ImGuiStorage, ImGuiListClipper, ImColor) +// [SECTION] Helpers (ImGuiOnceUponAFrame, ImGuiTextFilter, ImGuiTextBuffer, ImGuiStorage, ImGuiListClipper, Math Operators, ImColor) // [SECTION] Drawing API (ImDrawCallback, ImDrawCmd, ImDrawIdx, ImDrawVert, ImDrawChannel, ImDrawListSplitter, ImDrawFlags, ImDrawListFlags, ImDrawList, ImDrawData) // [SECTION] Font API (ImFontConfig, ImFontGlyph, ImFontGlyphRangesBuilder, ImFontAtlasFlags, ImFontAtlas, ImFont) // [SECTION] Viewports (ImGuiViewportFlags, ImGuiViewport) @@ -42,13 +50,12 @@ Index of this file: #pragma once -// Configuration file with compile-time options (edit imconfig.h or '#define IMGUI_USER_CONFIG "myfilename.h" from your build system') +// Configuration file with compile-time options +// (edit imconfig.h or '#define IMGUI_USER_CONFIG "myfilename.h" from your build system') #ifdef IMGUI_USER_CONFIG #include IMGUI_USER_CONFIG #endif -#if !defined(IMGUI_DISABLE_INCLUDE_IMCONFIG_H) || defined(IMGUI_INCLUDE_IMCONFIG_H) #include "imconfig.h" -#endif #ifndef IMGUI_DISABLE @@ -62,15 +69,6 @@ Index of this file: #include // ptrdiff_t, NULL #include // memset, memmove, memcpy, strlen, strchr, strcpy, strcmp -// Version -// (Integer encoded as XYYZZ for use in #if preprocessor conditionals. Work in progress versions typically starts at XYY99 then bounce up to XYY00, XYY01 etc. when release tagging happens) -#define IMGUI_VERSION "1.88 WIP" -#define IMGUI_VERSION_NUM 18721 -#define IMGUI_CHECKVERSION() ImGui::DebugCheckVersionAndDataLayout(IMGUI_VERSION, sizeof(ImGuiIO), sizeof(ImGuiStyle), sizeof(ImVec2), sizeof(ImVec4), sizeof(ImDrawVert), sizeof(ImDrawIdx)) -#define IMGUI_HAS_TABLE -#define IMGUI_HAS_VIEWPORT // Viewport WIP branch -#define IMGUI_HAS_DOCK // Docking WIP branch - // Define attributes of all API symbols declarations (e.g. for DLL under Windows) // IMGUI_API is used for core imgui functions, IMGUI_IMPL_API is used for the default backends files (imgui_impl_xxx.h) // Using dear imgui via a shared library is not recommended, because we don't guarantee backward nor forward ABI compatibility (also function call overhead, as dear imgui is a call-heavy API) @@ -89,6 +87,7 @@ Index of this file: #define IM_ARRAYSIZE(_ARR) ((int)(sizeof(_ARR) / sizeof(*(_ARR)))) // Size of a static C-style array. Don't use on pointers! #define IM_UNUSED(_VAR) ((void)(_VAR)) // Used to silence "unused variable warnings". Often useful as asserts may be stripped out from final builds. #define IM_OFFSETOF(_TYPE,_MEMBER) offsetof(_TYPE, _MEMBER) // Offset of _MEMBER within _TYPE. Standardized as offsetof() in C++11 +#define IMGUI_CHECKVERSION() ImGui::DebugCheckVersionAndDataLayout(IMGUI_VERSION, sizeof(ImGuiIO), sizeof(ImGuiStyle), sizeof(ImVec2), sizeof(ImVec4), sizeof(ImDrawVert), sizeof(ImDrawIdx)) // Helper Macros - IM_FMTARGS, IM_FMTLIST: Apply printf-style warnings to our formatting functions. #if !defined(IMGUI_USE_STB_SPRINTF) && defined(__MINGW32__) && !defined(__clang__) @@ -167,21 +166,27 @@ struct ImGuiTextFilter; // Helper to parse and apply text filters (e struct ImGuiViewport; // A Platform Window (always 1 unless multi-viewport are enabled. One per platform window to output to). In the future may represent Platform Monitor struct ImGuiWindowClass; // Window class (rare/advanced uses: provide hints to the platform backend via altered viewport flags and parent/child info) -// Enums/Flags (declared as int for compatibility with old C++, to allow using as flags without overhead, and to not pollute the top of this file) +// Enumerations +// - We don't use strongly typed enums much because they add constraints (can't extend in private code, can't store typed in bit fields, extra casting on iteration) // - Tip: Use your programming IDE navigation facilities on the names in the _central column_ below to find the actual flags/enum lists! // In Visual Studio IDE: CTRL+comma ("Edit.GoToAll") can follow symbols in comments, whereas CTRL+F12 ("Edit.GoToImplementation") cannot. // With Visual Assist installed: ALT+G ("VAssistX.GoToImplementation") can also follow symbols in comments. +enum ImGuiKey : int; // -> enum ImGuiKey // Enum: A key identifier (ImGuiKey_XXX or ImGuiMod_XXX value) +enum ImGuiMouseSource : int; // -> enum ImGuiMouseSource // Enum; A mouse input source identifier (Mouse, TouchScreen, Pen) typedef int ImGuiCol; // -> enum ImGuiCol_ // Enum: A color identifier for styling typedef int ImGuiCond; // -> enum ImGuiCond_ // Enum: A condition for many Set*() functions typedef int ImGuiDataType; // -> enum ImGuiDataType_ // Enum: A primary data type typedef int ImGuiDir; // -> enum ImGuiDir_ // Enum: A cardinal direction -typedef int ImGuiKey; // -> enum ImGuiKey_ // Enum: A key identifier -typedef int ImGuiNavInput; // -> enum ImGuiNavInput_ // Enum: An input identifier for navigation typedef int ImGuiMouseButton; // -> enum ImGuiMouseButton_ // Enum: A mouse button identifier (0=left, 1=right, 2=middle) -typedef int ImGuiMouseCursor; // -> enum ImGuiMouseCursor_ // Enum: A mouse cursor identifier +typedef int ImGuiMouseCursor; // -> enum ImGuiMouseCursor_ // Enum: A mouse cursor shape typedef int ImGuiSortDirection; // -> enum ImGuiSortDirection_ // Enum: A sorting direction (ascending or descending) typedef int ImGuiStyleVar; // -> enum ImGuiStyleVar_ // Enum: A variable identifier for styling typedef int ImGuiTableBgTarget; // -> enum ImGuiTableBgTarget_ // Enum: A color target for TableSetBgColor() + +// Flags (declared as int for compatibility with old C++, to allow using as flags without overhead, and to not pollute the top of this file) +// - Tip: Use your programming IDE navigation facilities on the names in the _central column_ below to find the actual flags/enum lists! +// In Visual Studio IDE: CTRL+comma ("Edit.GoToAll") can follow symbols in comments, whereas CTRL+F12 ("Edit.GoToImplementation") cannot. +// With Visual Assist installed: ALT+G ("VAssistX.GoToImplementation") can also follow symbols in comments. typedef int ImDrawFlags; // -> enum ImDrawFlags_ // Flags: for ImDrawList functions typedef int ImDrawListFlags; // -> enum ImDrawListFlags_ // Flags: for ImDrawList instance typedef int ImFontAtlasFlags; // -> enum ImFontAtlasFlags_ // Flags: for ImFontAtlas build @@ -195,7 +200,7 @@ typedef int ImGuiDragDropFlags; // -> enum ImGuiDragDropFlags_ // Flags: f typedef int ImGuiFocusedFlags; // -> enum ImGuiFocusedFlags_ // Flags: for IsWindowFocused() typedef int ImGuiHoveredFlags; // -> enum ImGuiHoveredFlags_ // Flags: for IsItemHovered(), IsWindowHovered() etc. typedef int ImGuiInputTextFlags; // -> enum ImGuiInputTextFlags_ // Flags: for InputText(), InputTextMultiline() -typedef int ImGuiModFlags; // -> enum ImGuiModFlags_ // Flags: for io.KeyMods (Ctrl/Shift/Alt/Super) +typedef int ImGuiKeyChord; // -> ImGuiKey | ImGuiMod_XXX // Flags: for storage only for now: an ImGuiKey optionally OR-ed with one or more ImGuiMod_XXX values. typedef int ImGuiPopupFlags; // -> enum ImGuiPopupFlags_ // Flags: for OpenPopup*(), BeginPopupContext*(), IsPopupOpen() typedef int ImGuiSelectableFlags; // -> enum ImGuiSelectableFlags_ // Flags: for Selectable() typedef int ImGuiSliderFlags; // -> enum ImGuiSliderFlags_ // Flags: for DragFloat(), DragInt(), SliderFloat(), SliderInt() etc. @@ -257,8 +262,8 @@ struct ImVec2 float x, y; constexpr ImVec2() : x(0.0f), y(0.0f) { } constexpr ImVec2(float _x, float _y) : x(_x), y(_y) { } - float operator[] (size_t idx) const { IM_ASSERT(idx <= 1); return (&x)[idx]; } // We very rarely use this [] operator, the assert overhead is fine. - float& operator[] (size_t idx) { IM_ASSERT(idx <= 1); return (&x)[idx]; } // We very rarely use this [] operator, the assert overhead is fine. + float& operator[] (size_t idx) { IM_ASSERT(idx == 0 || idx == 1); return ((float*)(void*)(char*)this)[idx]; } // We very rarely use this [] operator, so the assert overhead is fine. + float operator[] (size_t idx) const { IM_ASSERT(idx == 0 || idx == 1); return ((const float*)(const void*)(const char*)this)[idx]; } #ifdef IM_VEC2_CLASS_EXTRA IM_VEC2_CLASS_EXTRA // Define additional constructors and implicit cast operators in imconfig.h to convert back and forth between your math types and ImVec2. #endif @@ -303,12 +308,13 @@ namespace ImGui // Demo, Debug, Information IMGUI_API void ShowDemoWindow(bool* p_open = NULL); // create Demo window. demonstrate most ImGui features. call this to learn about the library! try to make it always available in your application! IMGUI_API void ShowMetricsWindow(bool* p_open = NULL); // create Metrics/Debugger window. display Dear ImGui internals: windows, draw commands, various internal state, etc. + IMGUI_API void ShowDebugLogWindow(bool* p_open = NULL); // create Debug Log window. display a simplified log of important dear imgui events. IMGUI_API void ShowStackToolWindow(bool* p_open = NULL); // create Stack Tool window. hover items with mouse to query information about the source of their unique ID. IMGUI_API void ShowAboutWindow(bool* p_open = NULL); // create About window. display Dear ImGui version, credits and build/system information. IMGUI_API void ShowStyleEditor(ImGuiStyle* ref = NULL); // add style editor block (not a window). you can pass in a reference ImGuiStyle structure to compare to, revert to and save to (else it uses the default style) IMGUI_API bool ShowStyleSelector(const char* label); // add style selector block (not a window), essentially a combo listing the default styles. IMGUI_API void ShowFontSelector(const char* label); // add font selector block (not a window), essentially a combo listing the loaded fonts. - IMGUI_API void ShowUserGuide(); // add basic help/info block (not a window): how to manipulate ImGui as a end-user (mouse/keyboard controls). + IMGUI_API void ShowUserGuide(); // add basic help/info block (not a window): how to manipulate ImGui as an end-user (mouse/keyboard controls). IMGUI_API const char* GetVersion(); // get the compiled version string e.g. "1.80 WIP" (essentially the value for IMGUI_VERSION from the compiled version of imgui.cpp) // Styles @@ -365,6 +371,7 @@ namespace ImGui IMGUI_API void SetNextWindowContentSize(const ImVec2& size); // set next window content size (~ scrollable client area, which enforce the range of scrollbars). Not including window decorations (title bar, menu bar, etc.) nor WindowPadding. set an axis to 0.0f to leave it automatic. call before Begin() IMGUI_API void SetNextWindowCollapsed(bool collapsed, ImGuiCond cond = 0); // set next window collapsed state. call before Begin() IMGUI_API void SetNextWindowFocus(); // set next window to be focused / top-most. call before Begin() + IMGUI_API void SetNextWindowScroll(const ImVec2& scroll); // set next window scrolling value (use < 0.0f to not affect a given axis). IMGUI_API void SetNextWindowBgAlpha(float alpha); // set next window background color alpha. helper to easily override the Alpha component of ImGuiCol_WindowBg/ChildBg/PopupBg. you may also use ImGuiWindowFlags_NoBackground. IMGUI_API void SetNextWindowViewport(ImGuiID viewport_id); // set next window viewport IMGUI_API void SetWindowPos(const ImVec2& pos, ImGuiCond cond = 0); // (not recommended) set current window position - call within Begin()/End(). prefer using SetNextWindowPos(), as this may incur tearing and side-effects. @@ -383,9 +390,11 @@ namespace ImGui IMGUI_API ImVec2 GetContentRegionAvail(); // == GetContentRegionMax() - GetCursorPos() IMGUI_API ImVec2 GetContentRegionMax(); // current content boundaries (typically window boundaries including scrolling, or current column boundaries), in windows coordinates IMGUI_API ImVec2 GetWindowContentRegionMin(); // content boundaries min for the full window (roughly (0,0)-Scroll), in window coordinates - IMGUI_API ImVec2 GetWindowContentRegionMax(); // content boundaries max for the full window (roughly (0,0)+Size-Scroll) where Size can be override with SetNextWindowContentSize(), in window coordinates + IMGUI_API ImVec2 GetWindowContentRegionMax(); // content boundaries max for the full window (roughly (0,0)+Size-Scroll) where Size can be overridden with SetNextWindowContentSize(), in window coordinates // Windows Scrolling + // - Any change of Scroll will be applied at the beginning of next frame in the first call to Begin(). + // - You may instead use SetNextWindowScroll() prior to calling Begin() to avoid this delay, as an alternative to using SetScrollX()/SetScrollY(). IMGUI_API float GetScrollX(); // get scrolling amount [0 .. GetScrollMaxX()] IMGUI_API float GetScrollY(); // get scrolling amount [0 .. GetScrollMaxY()] IMGUI_API void SetScrollX(float scroll_x); // set scrolling amount [0 .. GetScrollMaxX()] @@ -406,8 +415,8 @@ namespace ImGui IMGUI_API void PushStyleVar(ImGuiStyleVar idx, float val); // modify a style float variable. always use this if you modify the style after NewFrame(). IMGUI_API void PushStyleVar(ImGuiStyleVar idx, const ImVec2& val); // modify a style ImVec2 variable. always use this if you modify the style after NewFrame(). IMGUI_API void PopStyleVar(int count = 1); - IMGUI_API void PushAllowKeyboardFocus(bool allow_keyboard_focus); // == tab stop enable. Allow focusing using TAB/Shift-TAB, enabled by default but you can disable it for certain widgets - IMGUI_API void PopAllowKeyboardFocus(); + IMGUI_API void PushTabStop(bool tab_stop); // == tab stop enable. Allow focusing using TAB/Shift-TAB, enabled by default but you can disable it for certain widgets + IMGUI_API void PopTabStop(); IMGUI_API void PushButtonRepeat(bool repeat); // in 'repeat' mode, Button*() functions return repeated true in a typematic manner (using io.KeyRepeatDelay/io.KeyRepeatRate setting). Note that you can call IsItemActive() after any Button() to tell if the button is held in the current frame. IMGUI_API void PopButtonRepeat(); @@ -420,7 +429,7 @@ namespace ImGui IMGUI_API void PopTextWrapPos(); // Style read access - // - Use the style editor (ShowStyleEditor() function) to interactively see what the colors are) + // - Use the ShowStyleEditor() function to interactively see/edit the colors. IMGUI_API ImFont* GetFont(); // get current font IMGUI_API float GetFontSize(); // get current font size (= height in pixels) of current font with current scale applied IMGUI_API ImVec2 GetFontTexUvWhitePixel(); // get UV coordinate for a while pixel, useful to draw custom shapes via the ImDrawList API @@ -438,7 +447,7 @@ namespace ImGui // Absolute coordinate: GetCursorScreenPos(), SetCursorScreenPos(), all ImDrawList:: functions. IMGUI_API void Separator(); // separator, generally horizontal. inside a menu bar or in horizontal layout mode, this becomes a vertical separator. IMGUI_API void SameLine(float offset_from_start_x=0.0f, float spacing=-1.0f); // call between widgets or groups to layout them horizontally. X position given in window coordinates. - IMGUI_API void NewLine(); // undo a SameLine() or force a new line when in an horizontal-layout context. + IMGUI_API void NewLine(); // undo a SameLine() or force a new line when in a horizontal-layout context. IMGUI_API void Spacing(); // add vertical spacing. IMGUI_API void Dummy(const ImVec2& size); // add a dummy item of given size. unlike InvisibleButton(), Dummy() won't take the mouse click or be navigable into. IMGUI_API void Indent(float indent_w = 0.0f); // move content position toward the right, by indent_w, or style.IndentSpacing if indent_w <= 0 @@ -461,7 +470,7 @@ namespace ImGui IMGUI_API float GetFrameHeightWithSpacing(); // ~ FontSize + style.FramePadding.y * 2 + style.ItemSpacing.y (distance in pixels between 2 consecutive lines of framed widgets) // ID stack/scopes - // Read the FAQ (docs/FAQ.md or http://dearimgui.org/faq) for more details about how ID are handled in dear imgui. + // Read the FAQ (docs/FAQ.md or http://dearimgui.com/faq) for more details about how ID are handled in dear imgui. // - Those questions are answered and impacted by understanding of the ID stack system: // - "Q: Why is my widget not reacting when I click on it?" // - "Q: How can I have widgets with an empty label?" @@ -494,6 +503,7 @@ namespace ImGui IMGUI_API void LabelTextV(const char* label, const char* fmt, va_list args) IM_FMTLIST(2); IMGUI_API void BulletText(const char* fmt, ...) IM_FMTARGS(1); // shortcut for Bullet()+Text() IMGUI_API void BulletTextV(const char* fmt, va_list args) IM_FMTLIST(1); + IMGUI_API void SeparatorText(const char* label); // currently: formatted text with an horizontal line // Widgets: Main // - Most widgets return true when the value has been changed or when pressed/selected @@ -502,8 +512,6 @@ namespace ImGui IMGUI_API bool SmallButton(const char* label); // button with FramePadding=(0,0) to easily embed within text IMGUI_API bool InvisibleButton(const char* str_id, const ImVec2& size, ImGuiButtonFlags flags = 0); // flexible button behavior without the visuals, frequently useful to build custom behaviors using the public api (along with IsItemActive, IsItemHovered, etc.) IMGUI_API bool ArrowButton(const char* str_id, ImGuiDir dir); // square button with an arrow shape - IMGUI_API void Image(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0 = ImVec2(0, 0), const ImVec2& uv1 = ImVec2(1,1), const ImVec4& tint_col = ImVec4(1,1,1,1), const ImVec4& border_col = ImVec4(0,0,0,0)); - IMGUI_API bool ImageButton(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0 = ImVec2(0, 0), const ImVec2& uv1 = ImVec2(1,1), int frame_padding = -1, const ImVec4& bg_col = ImVec4(0,0,0,0), const ImVec4& tint_col = ImVec4(1,1,1,1)); // <0 frame_padding uses default frame padding settings. 0 for no padding IMGUI_API bool Checkbox(const char* label, bool* v); IMGUI_API bool CheckboxFlags(const char* label, int* flags, int flags_value); IMGUI_API bool CheckboxFlags(const char* label, unsigned int* flags, unsigned int flags_value); @@ -512,7 +520,12 @@ namespace ImGui IMGUI_API void ProgressBar(float fraction, const ImVec2& size_arg = ImVec2(-FLT_MIN, 0), const char* overlay = NULL); IMGUI_API void Bullet(); // draw a small circle + keep the cursor on the same line. advance cursor x position by GetTreeNodeToLabelSpacing(), same distance that TreeNode() uses - // Widgets: Combo Box + // Widgets: Images + // - Read about ImTextureID here: https://github.com/ocornut/imgui/wiki/Image-Loading-and-Displaying-Examples + IMGUI_API void Image(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0 = ImVec2(0, 0), const ImVec2& uv1 = ImVec2(1, 1), const ImVec4& tint_col = ImVec4(1, 1, 1, 1), const ImVec4& border_col = ImVec4(0, 0, 0, 0)); + IMGUI_API bool ImageButton(const char* str_id, ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0 = ImVec2(0, 0), const ImVec2& uv1 = ImVec2(1, 1), const ImVec4& bg_col = ImVec4(0, 0, 0, 0), const ImVec4& tint_col = ImVec4(1, 1, 1, 1)); + + // Widgets: Combo Box (Dropdown) // - The BeginCombo()/EndCombo() api allows you to manage your contents and selection state however you want it, by creating e.g. Selectable() items. // - The old Combo() api are helpers over BeginCombo()/EndCombo() which are kept available for convenience purpose. This is analogous to how ListBox are created. IMGUI_API bool BeginCombo(const char* label, const char* preview_value, ImGuiComboFlags flags = 0); @@ -523,7 +536,7 @@ namespace ImGui // Widgets: Drag Sliders // - CTRL+Click on any drag box to turn them into an input box. Manually input values aren't clamped by default and can go off-bounds. Use ImGuiSliderFlags_AlwaysClamp to always clamp. - // - For all the Float2/Float3/Float4/Int2/Int3/Int4 versions of every functions, note that a 'float v[X]' function argument is the same as 'float* v', + // - For all the Float2/Float3/Float4/Int2/Int3/Int4 versions of every function, note that a 'float v[X]' function argument is the same as 'float* v', // the array syntax is just a way to document the number of elements that are expected to be accessible. You can pass address of your first element out of a contiguous set, e.g. &myvector.x // - Adjust format string to decorate the value with a prefix, a suffix, or adapt the editing and display precision e.g. "%.3f" -> 1.234; "%5.2f secs" -> 01.23 secs; "Biscuit: %.0f" -> Biscuit: 1; etc. // - Format string may also be set to NULL or use the default format ("%f" or "%d"). @@ -531,7 +544,7 @@ namespace ImGui // - Use v_min < v_max to clamp edits to given limits. Note that CTRL+Click manual input can override those limits if ImGuiSliderFlags_AlwaysClamp is not used. // - Use v_max = FLT_MAX / INT_MAX etc to avoid clamping to a maximum, same with v_min = -FLT_MAX / INT_MIN to avoid clamping to a minimum. // - We use the same sets of flags for DragXXX() and SliderXXX() functions as the features are the same and it makes it easier to swap them. - // - Legacy: Pre-1.78 there are DragXXX() function signatures that takes a final `float power=1.0f' argument instead of the `ImGuiSliderFlags flags=0' argument. + // - Legacy: Pre-1.78 there are DragXXX() function signatures that take a final `float power=1.0f' argument instead of the `ImGuiSliderFlags flags=0' argument. // If you get a warning converting a float to ImGuiSliderFlags, read https://github.com/ocornut/imgui/issues/3361 IMGUI_API bool DragFloat(const char* label, float* v, float v_speed = 1.0f, float v_min = 0.0f, float v_max = 0.0f, const char* format = "%.3f", ImGuiSliderFlags flags = 0); // If v_min >= v_max we have no bound IMGUI_API bool DragFloat2(const char* label, float v[2], float v_speed = 1.0f, float v_min = 0.0f, float v_max = 0.0f, const char* format = "%.3f", ImGuiSliderFlags flags = 0); @@ -550,7 +563,7 @@ namespace ImGui // - CTRL+Click on any slider to turn them into an input box. Manually input values aren't clamped by default and can go off-bounds. Use ImGuiSliderFlags_AlwaysClamp to always clamp. // - Adjust format string to decorate the value with a prefix, a suffix, or adapt the editing and display precision e.g. "%.3f" -> 1.234; "%5.2f secs" -> 01.23 secs; "Biscuit: %.0f" -> Biscuit: 1; etc. // - Format string may also be set to NULL or use the default format ("%f" or "%d"). - // - Legacy: Pre-1.78 there are SliderXXX() function signatures that takes a final `float power=1.0f' argument instead of the `ImGuiSliderFlags flags=0' argument. + // - Legacy: Pre-1.78 there are SliderXXX() function signatures that take a final `float power=1.0f' argument instead of the `ImGuiSliderFlags flags=0' argument. // If you get a warning converting a float to ImGuiSliderFlags, read https://github.com/ocornut/imgui/issues/3361 IMGUI_API bool SliderFloat(const char* label, float* v, float v_min, float v_max, const char* format = "%.3f", ImGuiSliderFlags flags = 0); // adjust format to decorate the value with a prefix or a suffix for in-slider labels or unit display. IMGUI_API bool SliderFloat2(const char* label, float v[2], float v_min, float v_max, const char* format = "%.3f", ImGuiSliderFlags flags = 0); @@ -608,7 +621,7 @@ namespace ImGui IMGUI_API bool TreeNodeExV(const char* str_id, ImGuiTreeNodeFlags flags, const char* fmt, va_list args) IM_FMTLIST(3); IMGUI_API bool TreeNodeExV(const void* ptr_id, ImGuiTreeNodeFlags flags, const char* fmt, va_list args) IM_FMTLIST(3); IMGUI_API void TreePush(const char* str_id); // ~ Indent()+PushId(). Already called by TreeNode() when returning true, but you can call TreePush/TreePop yourself if desired. - IMGUI_API void TreePush(const void* ptr_id = NULL); // " + IMGUI_API void TreePush(const void* ptr_id); // " IMGUI_API void TreePop(); // ~ Unindent()+PopId() IMGUI_API float GetTreeNodeToLabelSpacing(); // horizontal distance preceding label when using TreeNode*() or Bullet() == (g.FontSize + style.FramePadding.x*2) for a regular unframed TreeNode IMGUI_API bool CollapsingHeader(const char* label, ImGuiTreeNodeFlags flags = 0); // if returning 'true' the header is open. doesn't indent nor push on ID stack. user doesn't have to call TreePop(). @@ -662,8 +675,8 @@ namespace ImGui // Tooltips // - Tooltip are windows following the mouse. They do not take focus away. - IMGUI_API void BeginTooltip(); // begin/append a tooltip window. to create full-featured tooltip (with any kind of items). - IMGUI_API void EndTooltip(); + IMGUI_API bool BeginTooltip(); // begin/append a tooltip window. to create full-featured tooltip (with any kind of items). + IMGUI_API void EndTooltip(); // only call EndTooltip() if BeginTooltip() returns true! IMGUI_API void SetTooltip(const char* fmt, ...) IM_FMTARGS(1); // set a text-only tooltip, typically use with ImGui::IsItemHovered(). override any previous call to SetTooltip(). IMGUI_API void SetTooltipV(const char* fmt, va_list args) IM_FMTLIST(1); @@ -678,7 +691,7 @@ namespace ImGui // Popups: begin/end functions // - BeginPopup(): query popup state, if open start appending into the window. Call EndPopup() afterwards. ImGuiWindowFlags are forwarded to the window. - // - BeginPopupModal(): block every interactions behind the window, cannot be closed by user, add a dimming background, has a title bar. + // - BeginPopupModal(): block every interaction behind the window, cannot be closed by user, add a dimming background, has a title bar. IMGUI_API bool BeginPopup(const char* str_id, ImGuiWindowFlags flags = 0); // return true if the popup is open, and you can start outputting to it. IMGUI_API bool BeginPopupModal(const char* name, bool* p_open = NULL, ImGuiWindowFlags flags = 0); // return true if the modal is open, and you can start outputting to it. IMGUI_API void EndPopup(); // only call EndPopup() if BeginPopupXXX() returns true! @@ -722,7 +735,7 @@ namespace ImGui // - 4. Optionally call TableHeadersRow() to submit a header row. Names are pulled from TableSetupColumn() data. // - 5. Populate contents: // - In most situations you can use TableNextRow() + TableSetColumnIndex(N) to start appending into a column. - // - If you are using tables as a sort of grid, where every columns is holding the same type of contents, + // - If you are using tables as a sort of grid, where every column is holding the same type of contents, // you may prefer using TableNextColumn() instead of TableNextRow() + TableSetColumnIndex(). // TableNextColumn() will automatically wrap-around into the next row if needed. // - IMPORTANT: Comparatively to the old Columns() API, we need to call TableNextColumn() for the first column! @@ -780,7 +793,7 @@ namespace ImGui IMGUI_API int GetColumnsCount(); // Tab Bars, Tabs - // Note: Tabs are automatically created by the docking system. Use this to create tab bars/tabs yourself without docking being involved. + // - Note: Tabs are automatically created by the docking system (when in 'docking' branch). Use this to create tab bars/tabs yourself. IMGUI_API bool BeginTabBar(const char* str_id, ImGuiTabBarFlags flags = 0); // create and append into a TabBar IMGUI_API void EndTabBar(); // only call EndTabBar() if BeginTabBar() returns true! IMGUI_API bool BeginTabItem(const char* label, bool* p_open = NULL, ImGuiTabItemFlags flags = 0); // create a Tab. Returns true if the Tab is selected. @@ -859,16 +872,17 @@ namespace ImGui IMGUI_API bool IsItemHovered(ImGuiHoveredFlags flags = 0); // is the last item hovered? (and usable, aka not blocked by a popup, etc.). See ImGuiHoveredFlags for more options. IMGUI_API bool IsItemActive(); // is the last item active? (e.g. button being held, text field being edited. This will continuously return true while holding mouse button on an item. Items that don't interact will always return false) IMGUI_API bool IsItemFocused(); // is the last item focused for keyboard/gamepad navigation? - IMGUI_API bool IsItemClicked(ImGuiMouseButton mouse_button = 0); // is the last item hovered and mouse clicked on? (**) == IsMouseClicked(mouse_button) && IsItemHovered()Important. (**) this it NOT equivalent to the behavior of e.g. Button(). Read comments in function definition. + IMGUI_API bool IsItemClicked(ImGuiMouseButton mouse_button = 0); // is the last item hovered and mouse clicked on? (**) == IsMouseClicked(mouse_button) && IsItemHovered()Important. (**) this is NOT equivalent to the behavior of e.g. Button(). Read comments in function definition. IMGUI_API bool IsItemVisible(); // is the last item visible? (items may be out of sight because of clipping/scrolling) IMGUI_API bool IsItemEdited(); // did the last item modify its underlying value this frame? or was pressed? This is generally the same as the "bool" return value of many widgets. IMGUI_API bool IsItemActivated(); // was the last item just made active (item was previously inactive). - IMGUI_API bool IsItemDeactivated(); // was the last item just made inactive (item was previously active). Useful for Undo/Redo patterns with widgets that requires continuous editing. - IMGUI_API bool IsItemDeactivatedAfterEdit(); // was the last item just made inactive and made a value change when it was active? (e.g. Slider/Drag moved). Useful for Undo/Redo patterns with widgets that requires continuous editing. Note that you may get false positives (some widgets such as Combo()/ListBox()/Selectable() will return true even when clicking an already selected item). + IMGUI_API bool IsItemDeactivated(); // was the last item just made inactive (item was previously active). Useful for Undo/Redo patterns with widgets that require continuous editing. + IMGUI_API bool IsItemDeactivatedAfterEdit(); // was the last item just made inactive and made a value change when it was active? (e.g. Slider/Drag moved). Useful for Undo/Redo patterns with widgets that require continuous editing. Note that you may get false positives (some widgets such as Combo()/ListBox()/Selectable() will return true even when clicking an already selected item). IMGUI_API bool IsItemToggledOpen(); // was the last item open state toggled? set by TreeNode(). IMGUI_API bool IsAnyItemHovered(); // is any item hovered? IMGUI_API bool IsAnyItemActive(); // is any item active? IMGUI_API bool IsAnyItemFocused(); // is any item focused? + IMGUI_API ImGuiID GetItemID(); // get ID of last item (~~ often same ImGui::GetID(label) beforehand) IMGUI_API ImVec2 GetItemRectMin(); // get upper-left bounding rectangle of the last item (screen space) IMGUI_API ImVec2 GetItemRectMax(); // get lower-right bounding rectangle of the last item (screen space) IMGUI_API ImVec2 GetItemRectSize(); // get size of last item @@ -907,20 +921,19 @@ namespace ImGui IMGUI_API void ColorConvertRGBtoHSV(float r, float g, float b, float& out_h, float& out_s, float& out_v); IMGUI_API void ColorConvertHSVtoRGB(float h, float s, float v, float& out_r, float& out_g, float& out_b); - // Inputs Utilities: Keyboard - // Without IMGUI_DISABLE_OBSOLETE_KEYIO: (legacy support) - // - For 'ImGuiKey key' you can still use your legacy native/user indices according to how your backend/engine stored them in io.KeysDown[]. - // With IMGUI_DISABLE_OBSOLETE_KEYIO: (this is the way forward) - // - Any use of 'ImGuiKey' will assert when key < 512 will be passed, previously reserved as native/user keys indices - // - GetKeyIndex() is pass-through and therefore deprecated (gone if IMGUI_DISABLE_OBSOLETE_KEYIO is defined) + // Inputs Utilities: Keyboard/Mouse/Gamepad + // - the ImGuiKey enum contains all possible keyboard, mouse and gamepad inputs (e.g. ImGuiKey_A, ImGuiKey_MouseLeft, ImGuiKey_GamepadDpadUp...). + // - before v1.87, we used ImGuiKey to carry native/user indices as defined by each backends. About use of those legacy ImGuiKey values: + // - without IMGUI_DISABLE_OBSOLETE_KEYIO (legacy support): you can still use your legacy native/user indices (< 512) according to how your backend/engine stored them in io.KeysDown[], but need to cast them to ImGuiKey. + // - with IMGUI_DISABLE_OBSOLETE_KEYIO (this is the way forward): any use of ImGuiKey will assert with key < 512. GetKeyIndex() is pass-through and therefore deprecated (gone if IMGUI_DISABLE_OBSOLETE_KEYIO is defined). IMGUI_API bool IsKeyDown(ImGuiKey key); // is key being held. IMGUI_API bool IsKeyPressed(ImGuiKey key, bool repeat = true); // was key pressed (went from !Down to Down)? if repeat=true, uses io.KeyRepeatDelay / KeyRepeatRate IMGUI_API bool IsKeyReleased(ImGuiKey key); // was key released (went from Down to !Down)? IMGUI_API int GetKeyPressedAmount(ImGuiKey key, float repeat_delay, float rate); // uses provided repeat rate/delay. return a count, most often 0 or 1 but might be >1 if RepeatRate is small enough that DeltaTime > RepeatRate IMGUI_API const char* GetKeyName(ImGuiKey key); // [DEBUG] returns English name of the key. Those names a provided for debugging purpose and are not meant to be saved persistently not compared. - IMGUI_API void CaptureKeyboardFromApp(bool want_capture_keyboard_value = true); // attention: misleading name! manually override io.WantCaptureKeyboard flag next frame (said flag is entirely left for your application to handle). e.g. force capture keyboard when your widget is being hovered. This is equivalent to setting "io.WantCaptureKeyboard = want_capture_keyboard_value"; after the next NewFrame() call. + IMGUI_API void SetNextFrameWantCaptureKeyboard(bool want_capture_keyboard); // Override io.WantCaptureKeyboard flag next frame (said flag is left for your application to handle, typically when true it instructs your app to ignore inputs). e.g. force capture keyboard when your widget is being hovered. This is equivalent to setting "io.WantCaptureKeyboard = want_capture_keyboard"; after the next NewFrame() call. - // Inputs Utilities: Mouse + // Inputs Utilities: Mouse specific // - To refer to a mouse button, you may use named enums in your code e.g. ImGuiMouseButton_Left, ImGuiMouseButton_Right. // - You can also use regular integer: it is forever guaranteed that 0=Left, 1=Right, 2=Middle. // - Dragging operations are only reported after mouse has moved a certain distance away from the initial clicking position (see 'lock_threshold' and 'io.MouseDraggingThreshold') @@ -937,9 +950,9 @@ namespace ImGui IMGUI_API bool IsMouseDragging(ImGuiMouseButton button, float lock_threshold = -1.0f); // is mouse dragging? (if lock_threshold < -1.0f, uses io.MouseDraggingThreshold) IMGUI_API ImVec2 GetMouseDragDelta(ImGuiMouseButton button = 0, float lock_threshold = -1.0f); // return the delta from the initial clicking position while the mouse button is pressed or was just released. This is locked and return 0.0f until the mouse moves past a distance threshold at least once (if lock_threshold < -1.0f, uses io.MouseDraggingThreshold) IMGUI_API void ResetMouseDragDelta(ImGuiMouseButton button = 0); // - IMGUI_API ImGuiMouseCursor GetMouseCursor(); // get desired cursor type, reset in ImGui::NewFrame(), this is updated during the frame. valid before Render(). If you use software rendering by setting io.MouseDrawCursor ImGui will render those for you - IMGUI_API void SetMouseCursor(ImGuiMouseCursor cursor_type); // set desired cursor type - IMGUI_API void CaptureMouseFromApp(bool want_capture_mouse_value = true); // attention: misleading name! manually override io.WantCaptureMouse flag next frame (said flag is entirely left for your application to handle). This is equivalent to setting "io.WantCaptureMouse = want_capture_mouse_value;" after the next NewFrame() call. + IMGUI_API ImGuiMouseCursor GetMouseCursor(); // get desired mouse cursor shape. Important: reset in ImGui::NewFrame(), this is updated during the frame. valid before Render(). If you use software rendering by setting io.MouseDrawCursor ImGui will render those for you + IMGUI_API void SetMouseCursor(ImGuiMouseCursor cursor_type); // set desired mouse cursor shape + IMGUI_API void SetNextFrameWantCaptureMouse(bool want_capture_mouse); // Override io.WantCaptureMouse flag next frame (said flag is left for your application to handle, typical when true it instucts your app to ignore inputs). This is equivalent to setting "io.WantCaptureMouse = want_capture_mouse;" after the next NewFrame() call. // Clipboard Utilities // - Also see the LogToClipboard() function to capture GUI into clipboard, or easily output text data to the clipboard. @@ -985,6 +998,7 @@ namespace ImGui //----------------------------------------------------------------------------- // Flags for ImGui::Begin() +// (Those are per-window flags. There are shared flags in ImGuiIO: io.ConfigWindowsResizeFromEdges and io.ConfigWindowsMoveFromTitleBarOnly) enum ImGuiWindowFlags_ { ImGuiWindowFlags_None = 0, @@ -1021,13 +1035,11 @@ enum ImGuiWindowFlags_ ImGuiWindowFlags_Popup = 1 << 26, // Don't use! For internal use by BeginPopup() ImGuiWindowFlags_Modal = 1 << 27, // Don't use! For internal use by BeginPopupModal() ImGuiWindowFlags_ChildMenu = 1 << 28, // Don't use! For internal use by BeginMenu() - ImGuiWindowFlags_DockNodeHost = 1 << 29 // Don't use! For internal use by Begin()/NewFrame() - - // [Obsolete] - //ImGuiWindowFlags_ResizeFromAnySide = 1 << 17, // [Obsolete] --> Set io.ConfigWindowsResizeFromEdges=true and make sure mouse cursors are supported by backend (io.BackendFlags & ImGuiBackendFlags_HasMouseCursors) + ImGuiWindowFlags_DockNodeHost = 1 << 29, // Don't use! For internal use by Begin()/NewFrame() }; // Flags for ImGui::InputText() +// (Those are per-item flags. There are shared flags in ImGuiIO: io.ConfigInputTextCursorBlink and io.ConfigInputTextEnterKeepActive) enum ImGuiInputTextFlags_ { ImGuiInputTextFlags_None = 0, @@ -1050,12 +1062,11 @@ enum ImGuiInputTextFlags_ ImGuiInputTextFlags_UndoRedo = 1 << 16, // Enable undo/redo. Note that input text owns the text data while active, if you want to provide your own undo/redo stack you need e.g. to call ClearActiveID(). ImGuiInputTextFlags_CharsScientific = 1 << 17, // Allow 0123456789.+-*/eE (Scientific notation input) ImGuiInputTextFlags_CallbackResize = 1 << 18, // Callback on buffer capacity changes request (beyond 'buf_size' parameter value), allowing the string to grow. Notify when the string wants to be resized (for string types which hold a cache of their Size). You will be provided a new BufSize in the callback and NEED to honor it. (see misc/cpp/imgui_stdlib.h for an example of using this) - ImGuiInputTextFlags_CallbackEdit = 1 << 19 // Callback on any edit (note that InputText() already returns true on edit, the callback is useful mainly to manipulate the underlying buffer while focus is active) + ImGuiInputTextFlags_CallbackEdit = 1 << 19, // Callback on any edit (note that InputText() already returns true on edit, the callback is useful mainly to manipulate the underlying buffer while focus is active) + ImGuiInputTextFlags_EscapeClearsAll = 1 << 20, // Escape key clears content if not empty, and deactivate otherwise (contrast to default behavior of Escape to revert) - // Obsolete names (will be removed soon) -#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS - , ImGuiInputTextFlags_AlwaysInsertMode = ImGuiInputTextFlags_AlwaysOverwrite // [renamed in 1.82] name was not matching behavior -#endif + // Obsolete names + //ImGuiInputTextFlags_AlwaysInsertMode = ImGuiInputTextFlags_AlwaysOverwrite // [renamed in 1.82] name was not matching behavior }; // Flags for ImGui::TreeNodeEx(), ImGui::CollapsingHeader*() @@ -1077,7 +1088,7 @@ enum ImGuiTreeNodeFlags_ ImGuiTreeNodeFlags_SpanFullWidth = 1 << 12, // Extend hit box to the left-most and right-most edges (bypass the indented area). ImGuiTreeNodeFlags_NavLeftJumpsBackHere = 1 << 13, // (WIP) Nav: left direction may move to this TreeNode() from any of its child (items submitted between TreeNode and TreePop) //ImGuiTreeNodeFlags_NoScrollOnOpen = 1 << 14, // FIXME: TODO: Disable automatic scroll on TreePop() if node got just open and contents is not visible - ImGuiTreeNodeFlags_CollapsingHeader = ImGuiTreeNodeFlags_Framed | ImGuiTreeNodeFlags_NoTreePushOnOpen | ImGuiTreeNodeFlags_NoAutoOpenOnLog + ImGuiTreeNodeFlags_CollapsingHeader = ImGuiTreeNodeFlags_Framed | ImGuiTreeNodeFlags_NoTreePushOnOpen | ImGuiTreeNodeFlags_NoAutoOpenOnLog, }; // Flags for OpenPopup*(), BeginPopupContext*(), IsPopupOpen() functions. @@ -1086,7 +1097,7 @@ enum ImGuiTreeNodeFlags_ // It is therefore guaranteed to be legal to pass a mouse button index in ImGuiPopupFlags. // - For the same reason, we exceptionally default the ImGuiPopupFlags argument of BeginPopupContextXXX functions to 1 instead of 0. // IMPORTANT: because the default parameter is 1 (==ImGuiPopupFlags_MouseButtonRight), if you rely on the default parameter -// and want to another another flag, you need to pass in the ImGuiPopupFlags_MouseButtonRight flag. +// and want to use another flag, you need to pass in the ImGuiPopupFlags_MouseButtonRight flag explicitly. // - Multiple buttons currently cannot be combined/or-ed in those functions (we could allow it later). enum ImGuiPopupFlags_ { @@ -1100,18 +1111,18 @@ enum ImGuiPopupFlags_ ImGuiPopupFlags_NoOpenOverItems = 1 << 6, // For BeginPopupContextWindow(): don't return true when hovering items, only when hovering empty space ImGuiPopupFlags_AnyPopupId = 1 << 7, // For IsPopupOpen(): ignore the ImGuiID parameter and test for any popup. ImGuiPopupFlags_AnyPopupLevel = 1 << 8, // For IsPopupOpen(): search/test at any level of the popup stack (default test in the current level) - ImGuiPopupFlags_AnyPopup = ImGuiPopupFlags_AnyPopupId | ImGuiPopupFlags_AnyPopupLevel + ImGuiPopupFlags_AnyPopup = ImGuiPopupFlags_AnyPopupId | ImGuiPopupFlags_AnyPopupLevel, }; // Flags for ImGui::Selectable() enum ImGuiSelectableFlags_ { ImGuiSelectableFlags_None = 0, - ImGuiSelectableFlags_DontClosePopups = 1 << 0, // Clicking this don't close parent popup window + ImGuiSelectableFlags_DontClosePopups = 1 << 0, // Clicking this doesn't close parent popup window ImGuiSelectableFlags_SpanAllColumns = 1 << 1, // Selectable frame can span all columns (text will still fit in current column) ImGuiSelectableFlags_AllowDoubleClick = 1 << 2, // Generate press events on double clicks too ImGuiSelectableFlags_Disabled = 1 << 3, // Cannot be selected, display grayed out text - ImGuiSelectableFlags_AllowItemOverlap = 1 << 4 // (WIP) Hit testing to allow subsequent widgets to overlap this one + ImGuiSelectableFlags_AllowItemOverlap = 1 << 4, // (WIP) Hit testing to allow subsequent widgets to overlap this one }; // Flags for ImGui::BeginCombo() @@ -1125,7 +1136,7 @@ enum ImGuiComboFlags_ ImGuiComboFlags_HeightLargest = 1 << 4, // As many fitting items as possible ImGuiComboFlags_NoArrowButton = 1 << 5, // Display on the preview box without the square arrow button ImGuiComboFlags_NoPreview = 1 << 6, // Display only a square arrow button - ImGuiComboFlags_HeightMask_ = ImGuiComboFlags_HeightSmall | ImGuiComboFlags_HeightRegular | ImGuiComboFlags_HeightLarge | ImGuiComboFlags_HeightLargest + ImGuiComboFlags_HeightMask_ = ImGuiComboFlags_HeightSmall | ImGuiComboFlags_HeightRegular | ImGuiComboFlags_HeightLarge | ImGuiComboFlags_HeightLargest, }; // Flags for ImGui::BeginTabBar() @@ -1141,7 +1152,7 @@ enum ImGuiTabBarFlags_ ImGuiTabBarFlags_FittingPolicyResizeDown = 1 << 6, // Resize tabs when they don't fit ImGuiTabBarFlags_FittingPolicyScroll = 1 << 7, // Add scroll buttons when tabs don't fit ImGuiTabBarFlags_FittingPolicyMask_ = ImGuiTabBarFlags_FittingPolicyResizeDown | ImGuiTabBarFlags_FittingPolicyScroll, - ImGuiTabBarFlags_FittingPolicyDefault_ = ImGuiTabBarFlags_FittingPolicyResizeDown + ImGuiTabBarFlags_FittingPolicyDefault_ = ImGuiTabBarFlags_FittingPolicyResizeDown, }; // Flags for ImGui::BeginTabItem() @@ -1155,7 +1166,7 @@ enum ImGuiTabItemFlags_ ImGuiTabItemFlags_NoTooltip = 1 << 4, // Disable tooltip for the given tab ImGuiTabItemFlags_NoReorder = 1 << 5, // Disable reordering this tab or having another tab cross over this tab ImGuiTabItemFlags_Leading = 1 << 6, // Enforce the tab position to the left of the tab bar (after the tab list popup button) - ImGuiTabItemFlags_Trailing = 1 << 7 // Enforce the tab position to the right of the tab bar (before the scrolling buttons) + ImGuiTabItemFlags_Trailing = 1 << 7, // Enforce the tab position to the right of the tab bar (before the scrolling buttons) }; // Flags for ImGui::BeginTable() @@ -1175,7 +1186,7 @@ enum ImGuiTabItemFlags_ // - When ScrollX is on: // - Table defaults to ImGuiTableFlags_SizingFixedFit -> all Columns defaults to ImGuiTableColumnFlags_WidthFixed // - Columns sizing policy allowed: Fixed/Auto mostly. -// - Fixed Columns can be enlarged as needed. Table will show an horizontal scrollbar if needed. +// - Fixed Columns can be enlarged as needed. Table will show a horizontal scrollbar if needed. // - When using auto-resizing (non-resizable) fixed columns, querying the content width to use item right-alignment e.g. SetNextItemWidth(-FLT_MIN) doesn't make sense, would create a feedback loop. // - Using Stretch columns OFTEN DOES NOT MAKE SENSE if ScrollX is on, UNLESS you have specified a value for 'inner_width' in BeginTable(). // If you specify a value for 'inner_width' then effectively the scrolling space is known and Stretch or mixed Fixed/Stretch columns become meaningful again. @@ -1201,8 +1212,8 @@ enum ImGuiTableFlags_ ImGuiTableFlags_BordersInner = ImGuiTableFlags_BordersInnerV | ImGuiTableFlags_BordersInnerH, // Draw inner borders. ImGuiTableFlags_BordersOuter = ImGuiTableFlags_BordersOuterV | ImGuiTableFlags_BordersOuterH, // Draw outer borders. ImGuiTableFlags_Borders = ImGuiTableFlags_BordersInner | ImGuiTableFlags_BordersOuter, // Draw all borders. - ImGuiTableFlags_NoBordersInBody = 1 << 11, // [ALPHA] Disable vertical borders in columns Body (borders will always appears in Headers). -> May move to style - ImGuiTableFlags_NoBordersInBodyUntilResize = 1 << 12, // [ALPHA] Disable vertical borders in columns Body until hovered for resize (borders will always appears in Headers). -> May move to style + ImGuiTableFlags_NoBordersInBody = 1 << 11, // [ALPHA] Disable vertical borders in columns Body (borders will always appear in Headers). -> May move to style + ImGuiTableFlags_NoBordersInBodyUntilResize = 1 << 12, // [ALPHA] Disable vertical borders in columns Body until hovered for resize (borders will always appear in Headers). -> May move to style // Sizing Policy (read above for defaults) ImGuiTableFlags_SizingFixedFit = 1 << 13, // Columns default to _WidthFixed or _WidthAuto (if resizable or not resizable), matching contents width. ImGuiTableFlags_SizingFixedSame = 2 << 13, // Columns default to _WidthFixed or _WidthAuto (if resizable or not resizable), matching the maximum contents width of all columns. Implicitly enable ImGuiTableFlags_NoKeepColumnsVisible. @@ -1216,11 +1227,11 @@ enum ImGuiTableFlags_ // Clipping ImGuiTableFlags_NoClip = 1 << 20, // Disable clipping rectangle for every individual columns (reduce draw command count, items will be able to overflow into other columns). Generally incompatible with TableSetupScrollFreeze(). // Padding - ImGuiTableFlags_PadOuterX = 1 << 21, // Default if BordersOuterV is on. Enable outer-most padding. Generally desirable if you have headers. - ImGuiTableFlags_NoPadOuterX = 1 << 22, // Default if BordersOuterV is off. Disable outer-most padding. + ImGuiTableFlags_PadOuterX = 1 << 21, // Default if BordersOuterV is on. Enable outermost padding. Generally desirable if you have headers. + ImGuiTableFlags_NoPadOuterX = 1 << 22, // Default if BordersOuterV is off. Disable outermost padding. ImGuiTableFlags_NoPadInnerX = 1 << 23, // Disable inner padding between columns (double inner padding if BordersOuterV is on, single inner padding if BordersOuterV is off). // Scrolling - ImGuiTableFlags_ScrollX = 1 << 24, // Enable horizontal scrolling. Require 'outer_size' parameter of BeginTable() to specify the container size. Changes default sizing policy. Because this create a child window, ScrollY is currently generally recommended when using ScrollX. + ImGuiTableFlags_ScrollX = 1 << 24, // Enable horizontal scrolling. Require 'outer_size' parameter of BeginTable() to specify the container size. Changes default sizing policy. Because this creates a child window, ScrollY is currently generally recommended when using ScrollX. ImGuiTableFlags_ScrollY = 1 << 25, // Enable vertical scrolling. Require 'outer_size' parameter of BeginTable() to specify the container size. // Sorting ImGuiTableFlags_SortMulti = 1 << 26, // Hold shift when clicking headers to sort on multiple column. TableGetSortSpecs() may return specs where (SpecsCount > 1). @@ -1229,13 +1240,7 @@ enum ImGuiTableFlags_ ImGuiTableFlags_NoBordersInFrozenArea = 1 << 28, // Disable vertical borders in frozen area. // [Internal] Combinations and masks - ImGuiTableFlags_SizingMask_ = ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_SizingFixedSame | ImGuiTableFlags_SizingStretchProp | ImGuiTableFlags_SizingStretchSame - - // Obsolete names (will be removed soon) -#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS - //, ImGuiTableFlags_ColumnsWidthFixed = ImGuiTableFlags_SizingFixedFit, ImGuiTableFlags_ColumnsWidthStretch = ImGuiTableFlags_SizingStretchSame // WIP Tables 2020/12 - //, ImGuiTableFlags_SizingPolicyFixed = ImGuiTableFlags_SizingFixedFit, ImGuiTableFlags_SizingPolicyStretch = ImGuiTableFlags_SizingStretchSame // WIP Tables 2021/01 -#endif + ImGuiTableFlags_SizingMask_ = ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_SizingFixedSame | ImGuiTableFlags_SizingStretchProp | ImGuiTableFlags_SizingStretchSame, }; // Flags for ImGui::TableSetupColumn() @@ -1272,19 +1277,14 @@ enum ImGuiTableColumnFlags_ ImGuiTableColumnFlags_WidthMask_ = ImGuiTableColumnFlags_WidthStretch | ImGuiTableColumnFlags_WidthFixed, ImGuiTableColumnFlags_IndentMask_ = ImGuiTableColumnFlags_IndentEnable | ImGuiTableColumnFlags_IndentDisable, ImGuiTableColumnFlags_StatusMask_ = ImGuiTableColumnFlags_IsEnabled | ImGuiTableColumnFlags_IsVisible | ImGuiTableColumnFlags_IsSorted | ImGuiTableColumnFlags_IsHovered, - ImGuiTableColumnFlags_NoDirectResize_ = 1 << 30 // [Internal] Disable user resizing this column directly (it may however we resized indirectly from its left edge) - - // Obsolete names (will be removed soon) -#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS - //ImGuiTableColumnFlags_WidthAuto = ImGuiTableColumnFlags_WidthFixed | ImGuiTableColumnFlags_NoResize, // Column will not stretch and keep resizing based on submitted contents. -#endif + ImGuiTableColumnFlags_NoDirectResize_ = 1 << 30, // [Internal] Disable user resizing this column directly (it may however we resized indirectly from its left edge) }; // Flags for ImGui::TableNextRow() enum ImGuiTableRowFlags_ { - ImGuiTableRowFlags_None = 0, - ImGuiTableRowFlags_Headers = 1 << 0 // Identify header row (set default background color + width of its contents accounted differently for auto column width) + ImGuiTableRowFlags_None = 0, + ImGuiTableRowFlags_Headers = 1 << 0, // Identify header row (set default background color + width of its contents accounted differently for auto column width) }; // Enum for ImGui::TableSetBgColor() @@ -1292,16 +1292,16 @@ enum ImGuiTableRowFlags_ // - Layer 0: draw with RowBg0 color if set, otherwise draw with ColumnBg0 if set. // - Layer 1: draw with RowBg1 color if set, otherwise draw with ColumnBg1 if set. // - Layer 2: draw with CellBg color if set. -// The purpose of the two row/columns layers is to let you decide if a background color changes should override or blend with the existing color. +// The purpose of the two row/columns layers is to let you decide if a background color change should override or blend with the existing color. // When using ImGuiTableFlags_RowBg on the table, each row has the RowBg0 color automatically set for odd/even rows. // If you set the color of RowBg0 target, your color will override the existing RowBg0 color. // If you set the color of RowBg1 or ColumnBg1 target, your color will blend over the RowBg0 color. enum ImGuiTableBgTarget_ { - ImGuiTableBgTarget_None = 0, - ImGuiTableBgTarget_RowBg0 = 1, // Set row background color 0 (generally used for background, automatically set when ImGuiTableFlags_RowBg is used) - ImGuiTableBgTarget_RowBg1 = 2, // Set row background color 1 (generally used for selection marking) - ImGuiTableBgTarget_CellBg = 3 // Set cell background color (top-most color) + ImGuiTableBgTarget_None = 0, + ImGuiTableBgTarget_RowBg0 = 1, // Set row background color 0 (generally used for background, automatically set when ImGuiTableFlags_RowBg is used) + ImGuiTableBgTarget_RowBg1 = 2, // Set row background color 1 (generally used for selection marking) + ImGuiTableBgTarget_CellBg = 3, // Set cell background color (top-most color) }; // Flags for ImGui::IsWindowFocused() @@ -1313,7 +1313,7 @@ enum ImGuiFocusedFlags_ ImGuiFocusedFlags_AnyWindow = 1 << 2, // Return true if any window is focused. Important: If you are trying to tell how to dispatch your low-level inputs, do NOT use this. Use 'io.WantCaptureMouse' instead! Please read the FAQ! ImGuiFocusedFlags_NoPopupHierarchy = 1 << 3, // Do not consider popup hierarchy (do not treat popup emitter as parent of popup) (when used with _ChildWindows or _RootWindow) ImGuiFocusedFlags_DockHierarchy = 1 << 4, // Consider docking hierarchy (treat dockspace host as parent of docked window) (when used with _ChildWindows or _RootWindow) - ImGuiFocusedFlags_RootAndChildWindows = ImGuiFocusedFlags_RootWindow | ImGuiFocusedFlags_ChildWindows + ImGuiFocusedFlags_RootAndChildWindows = ImGuiFocusedFlags_RootWindow | ImGuiFocusedFlags_ChildWindows, }; // Flags for ImGui::IsItemHovered(), ImGui::IsWindowHovered() @@ -1334,7 +1334,12 @@ enum ImGuiHoveredFlags_ ImGuiHoveredFlags_AllowWhenDisabled = 1 << 9, // IsItemHovered() only: Return true even if the item is disabled ImGuiHoveredFlags_NoNavOverride = 1 << 10, // Disable using gamepad/keyboard navigation state when active, always query mouse. ImGuiHoveredFlags_RectOnly = ImGuiHoveredFlags_AllowWhenBlockedByPopup | ImGuiHoveredFlags_AllowWhenBlockedByActiveItem | ImGuiHoveredFlags_AllowWhenOverlapped, - ImGuiHoveredFlags_RootAndChildWindows = ImGuiHoveredFlags_RootWindow | ImGuiHoveredFlags_ChildWindows + ImGuiHoveredFlags_RootAndChildWindows = ImGuiHoveredFlags_RootWindow | ImGuiHoveredFlags_ChildWindows, + + // Hovering delays (for tooltips) + ImGuiHoveredFlags_DelayNormal = 1 << 11, // Return true after io.HoverDelayNormal elapsed (~0.30 sec) + ImGuiHoveredFlags_DelayShort = 1 << 12, // Return true after io.HoverDelayShort elapsed (~0.10 sec) + ImGuiHoveredFlags_NoSharedDelay = 1 << 13, // Disable shared delay system where moving from one item to the next keeps the previous timer for a short time (standard for tooltips with long delays) }; // Flags for ImGui::DockSpace(), shared/inherited by child nodes. @@ -1350,7 +1355,7 @@ enum ImGuiDockNodeFlags_ ImGuiDockNodeFlags_NoSplit = 1 << 4, // Shared/Local // Disable splitting the node into smaller nodes. Useful e.g. when embedding dockspaces into a main root one (the root one may have splitting disabled to reduce confusion). Note: when turned off, existing splits will be preserved. ImGuiDockNodeFlags_NoResize = 1 << 5, // Shared/Local // Disable resizing node using the splitter/separators. Useful with programmatically setup dockspaces. ImGuiDockNodeFlags_AutoHideTabBar = 1 << 6, // Shared/Local // Tab bar will automatically hide when there is a single window in the dock node. - ImGuiDockNodeFlags_NoMove = 1 << 7 // Shared/Local // Disable moving node + ImGuiDockNodeFlags_NoMove = 1 << 7, // Shared/Local // Disable moving node }; // Flags for ImGui::BeginDragDropSource(), ImGui::AcceptDragDropPayload() @@ -1358,8 +1363,8 @@ enum ImGuiDragDropFlags_ { ImGuiDragDropFlags_None = 0, // BeginDragDropSource() flags - ImGuiDragDropFlags_SourceNoPreviewTooltip = 1 << 0, // By default, a successful call to BeginDragDropSource opens a tooltip so you can display a preview or description of the source contents. This flag disable this behavior. - ImGuiDragDropFlags_SourceNoDisableHover = 1 << 1, // By default, when dragging we clear data so that IsItemHovered() will return false, to avoid subsequent user code submitting tooltips. This flag disable this behavior so you can still call IsItemHovered() on the source item. + ImGuiDragDropFlags_SourceNoPreviewTooltip = 1 << 0, // Disable preview tooltip. By default, a successful call to BeginDragDropSource opens a tooltip so you can display a preview or description of the source contents. This flag disables this behavior. + ImGuiDragDropFlags_SourceNoDisableHover = 1 << 1, // By default, when dragging we clear data so that IsItemHovered() will return false, to avoid subsequent user code submitting tooltips. This flag disables this behavior so you can still call IsItemHovered() on the source item. ImGuiDragDropFlags_SourceNoHoldToOpenOthers = 1 << 2, // Disable the behavior that allows to open tree nodes and collapsing header by holding over them while dragging a source item. ImGuiDragDropFlags_SourceAllowNullID = 1 << 3, // Allow items such as Text(), Image() that have no unique identifier to be used as drag source, by manufacturing a temporary identifier based on their window-relative position. This is extremely unusual within the dear imgui ecosystem and so we made it explicit. ImGuiDragDropFlags_SourceExtern = 1 << 4, // External source (from outside of dear imgui), won't attempt to read current item/window info. Will always return true. Only one Extern source can be active simultaneously. @@ -1368,7 +1373,7 @@ enum ImGuiDragDropFlags_ ImGuiDragDropFlags_AcceptBeforeDelivery = 1 << 10, // AcceptDragDropPayload() will returns true even before the mouse button is released. You can then call IsDelivery() to test if the payload needs to be delivered. ImGuiDragDropFlags_AcceptNoDrawDefaultRect = 1 << 11, // Do not draw the default highlight rectangle when hovering over target. ImGuiDragDropFlags_AcceptNoPreviewTooltip = 1 << 12, // Request hiding the BeginDragDropSource tooltip from the BeginDragDropTarget site. - ImGuiDragDropFlags_AcceptPeekOnly = ImGuiDragDropFlags_AcceptBeforeDelivery | ImGuiDragDropFlags_AcceptNoDrawDefaultRect // For peeking ahead and inspecting the payload before delivery. + ImGuiDragDropFlags_AcceptPeekOnly = ImGuiDragDropFlags_AcceptBeforeDelivery | ImGuiDragDropFlags_AcceptNoDrawDefaultRect, // For peeking ahead and inspecting the payload before delivery. }; // Standard Drag and Drop payload types. You can define you own payload types using short strings. Types starting with '_' are defined by Dear ImGui. @@ -1410,7 +1415,12 @@ enum ImGuiSortDirection_ ImGuiSortDirection_Descending = 2 // Descending = 9->0, Z->A etc. }; -enum ImGuiKey_ +// A key identifier (ImGuiKey_XXX or ImGuiMod_XXX value): can represent Keyboard, Mouse and Gamepad values. +// All our named keys are >= 512. Keys value 0 to 511 are left unused as legacy native/opaque key values (< 1.87). +// Since >= 1.89 we increased typing (went from int to enum), some legacy code may need a cast to ImGuiKey. +// Read details about the 1.87 and 1.89 transition : https://github.com/ocornut/imgui/issues/4921 +// Note that "Keys" related to physical keys and are not the same concept as input "Characters", the later are submitted via io.AddInputCharacter(). +enum ImGuiKey : int { // Keyboard ImGuiKey_None = 0, @@ -1464,112 +1474,95 @@ enum ImGuiKey_ ImGuiKey_KeypadEnter, ImGuiKey_KeypadEqual, - // Gamepad (some of those are analog values, 0.0f to 1.0f) // NAVIGATION action - ImGuiKey_GamepadStart, // Menu (Xbox) + (Switch) Start/Options (PS) // -- - ImGuiKey_GamepadBack, // View (Xbox) - (Switch) Share (PS) // -- - ImGuiKey_GamepadFaceUp, // Y (Xbox) X (Switch) Triangle (PS) // -> ImGuiNavInput_Input - ImGuiKey_GamepadFaceDown, // A (Xbox) B (Switch) Cross (PS) // -> ImGuiNavInput_Activate - ImGuiKey_GamepadFaceLeft, // X (Xbox) Y (Switch) Square (PS) // -> ImGuiNavInput_Menu - ImGuiKey_GamepadFaceRight, // B (Xbox) A (Switch) Circle (PS) // -> ImGuiNavInput_Cancel - ImGuiKey_GamepadDpadUp, // D-pad Up // -> ImGuiNavInput_DpadUp - ImGuiKey_GamepadDpadDown, // D-pad Down // -> ImGuiNavInput_DpadDown - ImGuiKey_GamepadDpadLeft, // D-pad Left // -> ImGuiNavInput_DpadLeft - ImGuiKey_GamepadDpadRight, // D-pad Right // -> ImGuiNavInput_DpadRight - ImGuiKey_GamepadL1, // L Bumper (Xbox) L (Switch) L1 (PS) // -> ImGuiNavInput_FocusPrev + ImGuiNavInput_TweakSlow - ImGuiKey_GamepadR1, // R Bumper (Xbox) R (Switch) R1 (PS) // -> ImGuiNavInput_FocusNext + ImGuiNavInput_TweakFast - ImGuiKey_GamepadL2, // L Trigger (Xbox) ZL (Switch) L2 (PS) [Analog] - ImGuiKey_GamepadR2, // R Trigger (Xbox) ZR (Switch) R2 (PS) [Analog] - ImGuiKey_GamepadL3, // L Thumbstick (Xbox) L3 (Switch) L3 (PS) - ImGuiKey_GamepadR3, // R Thumbstick (Xbox) R3 (Switch) R3 (PS) - ImGuiKey_GamepadLStickUp, // [Analog] // -> ImGuiNavInput_LStickUp - ImGuiKey_GamepadLStickDown, // [Analog] // -> ImGuiNavInput_LStickDown - ImGuiKey_GamepadLStickLeft, // [Analog] // -> ImGuiNavInput_LStickLeft - ImGuiKey_GamepadLStickRight, // [Analog] // -> ImGuiNavInput_LStickRight - ImGuiKey_GamepadRStickUp, // [Analog] - ImGuiKey_GamepadRStickDown, // [Analog] + // Gamepad (some of those are analog values, 0.0f to 1.0f) // NAVIGATION ACTION + // (download controller mapping PNG/PSD at http://dearimgui.com/controls_sheets) + ImGuiKey_GamepadStart, // Menu (Xbox) + (Switch) Start/Options (PS) + ImGuiKey_GamepadBack, // View (Xbox) - (Switch) Share (PS) + ImGuiKey_GamepadFaceLeft, // X (Xbox) Y (Switch) Square (PS) // Tap: Toggle Menu. Hold: Windowing mode (Focus/Move/Resize windows) + ImGuiKey_GamepadFaceRight, // B (Xbox) A (Switch) Circle (PS) // Cancel / Close / Exit + ImGuiKey_GamepadFaceUp, // Y (Xbox) X (Switch) Triangle (PS) // Text Input / On-screen Keyboard + ImGuiKey_GamepadFaceDown, // A (Xbox) B (Switch) Cross (PS) // Activate / Open / Toggle / Tweak + ImGuiKey_GamepadDpadLeft, // D-pad Left // Move / Tweak / Resize Window (in Windowing mode) + ImGuiKey_GamepadDpadRight, // D-pad Right // Move / Tweak / Resize Window (in Windowing mode) + ImGuiKey_GamepadDpadUp, // D-pad Up // Move / Tweak / Resize Window (in Windowing mode) + ImGuiKey_GamepadDpadDown, // D-pad Down // Move / Tweak / Resize Window (in Windowing mode) + ImGuiKey_GamepadL1, // L Bumper (Xbox) L (Switch) L1 (PS) // Tweak Slower / Focus Previous (in Windowing mode) + ImGuiKey_GamepadR1, // R Bumper (Xbox) R (Switch) R1 (PS) // Tweak Faster / Focus Next (in Windowing mode) + ImGuiKey_GamepadL2, // L Trig. (Xbox) ZL (Switch) L2 (PS) [Analog] + ImGuiKey_GamepadR2, // R Trig. (Xbox) ZR (Switch) R2 (PS) [Analog] + ImGuiKey_GamepadL3, // L Stick (Xbox) L3 (Switch) L3 (PS) + ImGuiKey_GamepadR3, // R Stick (Xbox) R3 (Switch) R3 (PS) + ImGuiKey_GamepadLStickLeft, // [Analog] // Move Window (in Windowing mode) + ImGuiKey_GamepadLStickRight, // [Analog] // Move Window (in Windowing mode) + ImGuiKey_GamepadLStickUp, // [Analog] // Move Window (in Windowing mode) + ImGuiKey_GamepadLStickDown, // [Analog] // Move Window (in Windowing mode) ImGuiKey_GamepadRStickLeft, // [Analog] ImGuiKey_GamepadRStickRight, // [Analog] + ImGuiKey_GamepadRStickUp, // [Analog] + ImGuiKey_GamepadRStickDown, // [Analog] + + // Aliases: Mouse Buttons (auto-submitted from AddMouseButtonEvent() calls) + // - This is mirroring the data also written to io.MouseDown[], io.MouseWheel, in a format allowing them to be accessed via standard key API. + ImGuiKey_MouseLeft, ImGuiKey_MouseRight, ImGuiKey_MouseMiddle, ImGuiKey_MouseX1, ImGuiKey_MouseX2, ImGuiKey_MouseWheelX, ImGuiKey_MouseWheelY, + + // [Internal] Reserved for mod storage + ImGuiKey_ReservedForModCtrl, ImGuiKey_ReservedForModShift, ImGuiKey_ReservedForModAlt, ImGuiKey_ReservedForModSuper, + ImGuiKey_COUNT, // Keyboard Modifiers (explicitly submitted by backend via AddKeyEvent() calls) // - This is mirroring the data also written to io.KeyCtrl, io.KeyShift, io.KeyAlt, io.KeySuper, in a format allowing // them to be accessed via standard key API, allowing calls such as IsKeyPressed(), IsKeyReleased(), querying duration etc. - // - Code polling every keys (e.g. an interface to detect a key press for input mapping) might want to ignore those - // and prefer using the real keys (e.g. ImGuiKey_LeftCtrl, ImGuiKey_RightCtrl instead of ImGuiKey_ModCtrl). + // - Code polling every key (e.g. an interface to detect a key press for input mapping) might want to ignore those + // and prefer using the real keys (e.g. ImGuiKey_LeftCtrl, ImGuiKey_RightCtrl instead of ImGuiMod_Ctrl). // - In theory the value of keyboard modifiers should be roughly equivalent to a logical or of the equivalent left/right keys. // In practice: it's complicated; mods are often provided from different sources. Keyboard layout, IME, sticky keys and // backends tend to interfere and break that equivalence. The safer decision is to relay that ambiguity down to the end-user... - ImGuiKey_ModCtrl, ImGuiKey_ModShift, ImGuiKey_ModAlt, ImGuiKey_ModSuper, + ImGuiMod_None = 0, + ImGuiMod_Ctrl = 1 << 12, // Ctrl + ImGuiMod_Shift = 1 << 13, // Shift + ImGuiMod_Alt = 1 << 14, // Option/Menu + ImGuiMod_Super = 1 << 15, // Cmd/Super/Windows + ImGuiMod_Shortcut = 1 << 11, // Alias for Ctrl (non-macOS) _or_ Super (macOS). + ImGuiMod_Mask_ = 0xF800, // 5-bits - // End of list - ImGuiKey_COUNT, // No valid ImGuiKey is ever greater than this value - - // [Internal] Prior to 1.87 we required user to fill io.KeysDown[512] using their own native index + a io.KeyMap[] array. + // [Internal] Prior to 1.87 we required user to fill io.KeysDown[512] using their own native index + the io.KeyMap[] array. // We are ditching this method but keeping a legacy path for user code doing e.g. IsKeyPressed(MY_NATIVE_KEY_CODE) + // If you need to iterate all keys (for e.g. an input mapper) you may use ImGuiKey_NamedKey_BEGIN..ImGuiKey_NamedKey_END. ImGuiKey_NamedKey_BEGIN = 512, ImGuiKey_NamedKey_END = ImGuiKey_COUNT, ImGuiKey_NamedKey_COUNT = ImGuiKey_NamedKey_END - ImGuiKey_NamedKey_BEGIN, #ifdef IMGUI_DISABLE_OBSOLETE_KEYIO - ImGuiKey_KeysData_SIZE = ImGuiKey_NamedKey_COUNT, // Size of KeysData[]: only hold named keys - ImGuiKey_KeysData_OFFSET = ImGuiKey_NamedKey_BEGIN // First key stored in KeysData[0] + ImGuiKey_KeysData_SIZE = ImGuiKey_NamedKey_COUNT, // Size of KeysData[]: only hold named keys + ImGuiKey_KeysData_OFFSET = ImGuiKey_NamedKey_BEGIN, // Accesses to io.KeysData[] must use (key - ImGuiKey_KeysData_OFFSET) index. #else - ImGuiKey_KeysData_SIZE = ImGuiKey_COUNT, // Size of KeysData[]: hold legacy 0..512 keycodes + named keys - ImGuiKey_KeysData_OFFSET = 0 // First key stored in KeysData[0] + ImGuiKey_KeysData_SIZE = ImGuiKey_COUNT, // Size of KeysData[]: hold legacy 0..512 keycodes + named keys + ImGuiKey_KeysData_OFFSET = 0, // Accesses to io.KeysData[] must use (key - ImGuiKey_KeysData_OFFSET) index. #endif #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS - , ImGuiKey_KeyPadEnter = ImGuiKey_KeypadEnter // Renamed in 1.87 + ImGuiKey_ModCtrl = ImGuiMod_Ctrl, ImGuiKey_ModShift = ImGuiMod_Shift, ImGuiKey_ModAlt = ImGuiMod_Alt, ImGuiKey_ModSuper = ImGuiMod_Super, // Renamed in 1.89 + ImGuiKey_KeyPadEnter = ImGuiKey_KeypadEnter, // Renamed in 1.87 #endif }; -// Helper "flags" version of key-mods to store and compare multiple key-mods easily. Sometimes used for storage (e.g. io.KeyMods) but otherwise not much used in public API. -enum ImGuiModFlags_ +#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO +// OBSOLETED in 1.88 (from July 2022): ImGuiNavInput and io.NavInputs[]. +// Official backends between 1.60 and 1.86: will keep working and feed gamepad inputs as long as IMGUI_DISABLE_OBSOLETE_KEYIO is not set. +// Custom backends: feed gamepad inputs via io.AddKeyEvent() and ImGuiKey_GamepadXXX enums. +enum ImGuiNavInput { - ImGuiModFlags_None = 0, - ImGuiModFlags_Ctrl = 1 << 0, - ImGuiModFlags_Shift = 1 << 1, - ImGuiModFlags_Alt = 1 << 2, // Menu - ImGuiModFlags_Super = 1 << 3 // Cmd/Super/Windows key -}; - -// Gamepad/Keyboard navigation -// Keyboard: Set io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard to enable. NewFrame() will automatically fill io.NavInputs[] based on your io.AddKeyEvent() calls. -// Gamepad: Set io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad to enable. Backend: set ImGuiBackendFlags_HasGamepad and fill the io.NavInputs[] fields before calling NewFrame(). Note that io.NavInputs[] is cleared by EndFrame(). -// Read instructions in imgui.cpp for more details. Download PNG/PSD at http://dearimgui.org/controls_sheets. -enum ImGuiNavInput_ -{ - // Gamepad Mapping - ImGuiNavInput_Activate, // Activate / Open / Toggle / Tweak value // e.g. Cross (PS4), A (Xbox), A (Switch), Space (Keyboard) - ImGuiNavInput_Cancel, // Cancel / Close / Exit // e.g. Circle (PS4), B (Xbox), B (Switch), Escape (Keyboard) - ImGuiNavInput_Input, // Text input / On-Screen keyboard // e.g. Triang.(PS4), Y (Xbox), X (Switch), Return (Keyboard) - ImGuiNavInput_Menu, // Tap: Toggle menu / Hold: Focus, Move, Resize // e.g. Square (PS4), X (Xbox), Y (Switch), Alt (Keyboard) - ImGuiNavInput_DpadLeft, // Move / Tweak / Resize window (w/ PadMenu) // e.g. D-pad Left/Right/Up/Down (Gamepads), Arrow keys (Keyboard) - ImGuiNavInput_DpadRight, // - ImGuiNavInput_DpadUp, // - ImGuiNavInput_DpadDown, // - ImGuiNavInput_LStickLeft, // Scroll / Move window (w/ PadMenu) // e.g. Left Analog Stick Left/Right/Up/Down - ImGuiNavInput_LStickRight, // - ImGuiNavInput_LStickUp, // - ImGuiNavInput_LStickDown, // - ImGuiNavInput_FocusPrev, // Focus Next window (w/ PadMenu) // e.g. L1 or L2 (PS4), LB or LT (Xbox), L or ZL (Switch) - ImGuiNavInput_FocusNext, // Focus Prev window (w/ PadMenu) // e.g. R1 or R2 (PS4), RB or RT (Xbox), R or ZL (Switch) - ImGuiNavInput_TweakSlow, // Slower tweaks // e.g. L1 or L2 (PS4), LB or LT (Xbox), L or ZL (Switch) - ImGuiNavInput_TweakFast, // Faster tweaks // e.g. R1 or R2 (PS4), RB or RT (Xbox), R or ZL (Switch) - - // [Internal] Don't use directly! This is used internally to differentiate keyboard from gamepad inputs for behaviors that require to differentiate them. - // Keyboard behavior that have no corresponding gamepad mapping (e.g. CTRL+TAB) will be directly reading from keyboard keys instead of io.NavInputs[]. - ImGuiNavInput_KeyLeft_, // Move left // = Arrow keys - ImGuiNavInput_KeyRight_, // Move right - ImGuiNavInput_KeyUp_, // Move up - ImGuiNavInput_KeyDown_, // Move down - ImGuiNavInput_COUNT + ImGuiNavInput_Activate, ImGuiNavInput_Cancel, ImGuiNavInput_Input, ImGuiNavInput_Menu, ImGuiNavInput_DpadLeft, ImGuiNavInput_DpadRight, ImGuiNavInput_DpadUp, ImGuiNavInput_DpadDown, + ImGuiNavInput_LStickLeft, ImGuiNavInput_LStickRight, ImGuiNavInput_LStickUp, ImGuiNavInput_LStickDown, ImGuiNavInput_FocusPrev, ImGuiNavInput_FocusNext, ImGuiNavInput_TweakSlow, ImGuiNavInput_TweakFast, + ImGuiNavInput_COUNT, }; +#endif // Configuration flags stored in io.ConfigFlags. Set by user/application. enum ImGuiConfigFlags_ { ImGuiConfigFlags_None = 0, - ImGuiConfigFlags_NavEnableKeyboard = 1 << 0, // Master keyboard navigation enable flag. NewFrame() will automatically fill io.NavInputs[] based on io.AddKeyEvent() calls - ImGuiConfigFlags_NavEnableGamepad = 1 << 1, // Master gamepad navigation enable flag. This is mostly to instruct your imgui backend to fill io.NavInputs[]. Backend also needs to set ImGuiBackendFlags_HasGamepad. + ImGuiConfigFlags_NavEnableKeyboard = 1 << 0, // Master keyboard navigation enable flag. Enable full Tabbing + directional arrows + space/enter to activate. + ImGuiConfigFlags_NavEnableGamepad = 1 << 1, // Master gamepad navigation enable flag. Backend also needs to set ImGuiBackendFlags_HasGamepad. ImGuiConfigFlags_NavEnableSetMousePos = 1 << 2, // Instruct navigation to move the mouse cursor. May be useful on TV/console systems where moving a virtual mouse is awkward. Will update io.MousePos and set io.WantSetMousePos=true. If enabled you MUST honor io.WantSetMousePos requests in your backend, otherwise ImGui will react as if the mouse is jumping around back and forth. ImGuiConfigFlags_NavNoCaptureKeyboard = 1 << 3, // Instruct navigation to not set the io.WantCaptureKeyboard flag when io.NavActive is set. ImGuiConfigFlags_NoMouse = 1 << 4, // Instruct imgui to clear mouse position/buttons in NewFrame(). This allows ignoring the mouse information set by the backend. @@ -1588,9 +1581,9 @@ enum ImGuiConfigFlags_ ImGuiConfigFlags_DpiEnableScaleViewports= 1 << 14, // [BETA: Don't use] FIXME-DPI: Reposition and resize imgui windows when the DpiScale of a viewport changed (mostly useful for the main viewport hosting other window). Note that resizing the main window itself is up to your application. ImGuiConfigFlags_DpiEnableScaleFonts = 1 << 15, // [BETA: Don't use] FIXME-DPI: Request bitmap-scaled fonts to match DpiScale. This is a very low-quality workaround. The correct way to handle DPI is _currently_ to replace the atlas and/or fonts in the Platform_OnChangedViewport callback, but this is all early work in progress. - // User storage (to allow your backend/engine to communicate to code that may be shared between multiple projects. Those flags are not used by core Dear ImGui) + // User storage (to allow your backend/engine to communicate to code that may be shared between multiple projects. Those flags are NOT used by core Dear ImGui) ImGuiConfigFlags_IsSRGB = 1 << 20, // Application is SRGB-aware. - ImGuiConfigFlags_IsTouchScreen = 1 << 21 // Application is using a touch screen instead of a mouse. + ImGuiConfigFlags_IsTouchScreen = 1 << 21, // Application is using a touch screen instead of a mouse. }; // Backend capabilities flags stored in io.BackendFlags. Set by imgui_impl_xxx or custom backend. @@ -1605,7 +1598,7 @@ enum ImGuiBackendFlags_ // [BETA] Viewports ImGuiBackendFlags_PlatformHasViewports = 1 << 10, // Backend Platform supports multiple viewports. ImGuiBackendFlags_HasMouseHoveredViewport=1 << 11, // Backend Platform supports calling io.AddMouseViewportEvent() with the viewport under the mouse. IF POSSIBLE, ignore viewports with the ImGuiViewportFlags_NoInputs flag (Win32 backend, GLFW 3.30+ backend can do this, SDL backend cannot). If this cannot be done, Dear ImGui needs to use a flawed heuristic to find the viewport under. - ImGuiBackendFlags_RendererHasViewports = 1 << 12 // Backend Renderer supports multiple viewports. + ImGuiBackendFlags_RendererHasViewports = 1 << 12, // Backend Renderer supports multiple viewports. }; // Enumeration for PushStyleColor() / PopStyleColor() @@ -1641,10 +1634,10 @@ enum ImGuiCol_ ImGuiCol_Separator, ImGuiCol_SeparatorHovered, ImGuiCol_SeparatorActive, - ImGuiCol_ResizeGrip, + ImGuiCol_ResizeGrip, // Resize grip in lower-right and lower-left corners of windows. ImGuiCol_ResizeGripHovered, ImGuiCol_ResizeGripActive, - ImGuiCol_Tab, + ImGuiCol_Tab, // TabItem in a TabBar ImGuiCol_TabHovered, ImGuiCol_TabActive, ImGuiCol_TabUnfocused, @@ -1661,7 +1654,7 @@ enum ImGuiCol_ ImGuiCol_TableRowBg, // Table row background (even rows) ImGuiCol_TableRowBgAlt, // Table row background (odd rows) ImGuiCol_TextSelectedBg, - ImGuiCol_DragDropTarget, + ImGuiCol_DragDropTarget, // Rectangle highlighting a drop target ImGuiCol_NavHighlight, // Gamepad/keyboard: current highlighted item ImGuiCol_NavWindowingHighlight, // Highlight window when using CTRL+TAB ImGuiCol_NavWindowingDimBg, // Darken/colorize entire screen behind the CTRL+TAB window list, when active @@ -1705,6 +1698,9 @@ enum ImGuiStyleVar_ ImGuiStyleVar_TabRounding, // float TabRounding ImGuiStyleVar_ButtonTextAlign, // ImVec2 ButtonTextAlign ImGuiStyleVar_SelectableTextAlign, // ImVec2 SelectableTextAlign + ImGuiStyleVar_SeparatorTextBorderSize,// float SeparatorTextBorderSize + ImGuiStyleVar_SeparatorTextAlign, // ImVec2 SeparatorTextAlign + ImGuiStyleVar_SeparatorTextPadding,// ImVec2 SeparatorTextPadding ImGuiStyleVar_COUNT }; @@ -1718,7 +1714,7 @@ enum ImGuiButtonFlags_ // [Internal] ImGuiButtonFlags_MouseButtonMask_ = ImGuiButtonFlags_MouseButtonLeft | ImGuiButtonFlags_MouseButtonRight | ImGuiButtonFlags_MouseButtonMiddle, - ImGuiButtonFlags_MouseButtonDefault_ = ImGuiButtonFlags_MouseButtonLeft + ImGuiButtonFlags_MouseButtonDefault_ = ImGuiButtonFlags_MouseButtonLeft, }; // Flags for ColorEdit3() / ColorEdit4() / ColorPicker3() / ColorPicker4() / ColorButton() @@ -1759,14 +1755,15 @@ enum ImGuiColorEditFlags_ ImGuiColorEditFlags_DisplayMask_ = ImGuiColorEditFlags_DisplayRGB | ImGuiColorEditFlags_DisplayHSV | ImGuiColorEditFlags_DisplayHex, ImGuiColorEditFlags_DataTypeMask_ = ImGuiColorEditFlags_Uint8 | ImGuiColorEditFlags_Float, ImGuiColorEditFlags_PickerMask_ = ImGuiColorEditFlags_PickerHueWheel | ImGuiColorEditFlags_PickerHueBar, - ImGuiColorEditFlags_InputMask_ = ImGuiColorEditFlags_InputRGB | ImGuiColorEditFlags_InputHSV + ImGuiColorEditFlags_InputMask_ = ImGuiColorEditFlags_InputRGB | ImGuiColorEditFlags_InputHSV, - // Obsolete names (will be removed) - // ImGuiColorEditFlags_RGB = ImGuiColorEditFlags_DisplayRGB, ImGuiColorEditFlags_HSV = ImGuiColorEditFlags_DisplayHSV, ImGuiColorEditFlags_HEX = ImGuiColorEditFlags_DisplayHex // [renamed in 1.69] + // Obsolete names + //ImGuiColorEditFlags_RGB = ImGuiColorEditFlags_DisplayRGB, ImGuiColorEditFlags_HSV = ImGuiColorEditFlags_DisplayHSV, ImGuiColorEditFlags_HEX = ImGuiColorEditFlags_DisplayHex // [renamed in 1.69] }; // Flags for DragFloat(), DragInt(), SliderFloat(), SliderInt() etc. // We use the same sets of flags for DragXXX() and SliderXXX() functions as the features are the same and it makes it easier to swap them. +// (Those are per-item flags. There are shared flags in ImGuiIO: io.ConfigDragClickToInputText) enum ImGuiSliderFlags_ { ImGuiSliderFlags_None = 0, @@ -1774,12 +1771,10 @@ enum ImGuiSliderFlags_ ImGuiSliderFlags_Logarithmic = 1 << 5, // Make the widget logarithmic (linear otherwise). Consider using ImGuiSliderFlags_NoRoundToFormat with this if using a format-string with small amount of digits. ImGuiSliderFlags_NoRoundToFormat = 1 << 6, // Disable rounding underlying value to match precision of the display format string (e.g. %.3f values are rounded to those 3 digits) ImGuiSliderFlags_NoInput = 1 << 7, // Disable CTRL+Click or Enter key allowing to input text directly into the widget - ImGuiSliderFlags_InvalidMask_ = 0x7000000F // [Internal] We treat using those bits as being potentially a 'float power' argument from the previous API that has got miscast to this enum, and will trigger an assert if needed. + ImGuiSliderFlags_InvalidMask_ = 0x7000000F, // [Internal] We treat using those bits as being potentially a 'float power' argument from the previous API that has got miscast to this enum, and will trigger an assert if needed. - // Obsolete names (will be removed) -#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS - , ImGuiSliderFlags_ClampOnInput = ImGuiSliderFlags_AlwaysClamp // [renamed in 1.79] -#endif + // Obsolete names + //ImGuiSliderFlags_ClampOnInput = ImGuiSliderFlags_AlwaysClamp, // [renamed in 1.79] }; // Identify a mouse button. @@ -1800,7 +1795,7 @@ enum ImGuiMouseCursor_ ImGuiMouseCursor_Arrow = 0, ImGuiMouseCursor_TextInput, // When hovering over InputText, etc. ImGuiMouseCursor_ResizeAll, // (Unused by Dear ImGui functions) - ImGuiMouseCursor_ResizeNS, // When hovering over an horizontal border + ImGuiMouseCursor_ResizeNS, // When hovering over a horizontal border ImGuiMouseCursor_ResizeEW, // When hovering over a vertical border or a column ImGuiMouseCursor_ResizeNESW, // When hovering over the bottom-left corner of a window ImGuiMouseCursor_ResizeNWSE, // When hovering over the bottom-right corner of a window @@ -1809,16 +1804,28 @@ enum ImGuiMouseCursor_ ImGuiMouseCursor_COUNT }; +// Enumeration for AddMouseSourceEvent() actual source of Mouse Input data. +// Historically we use "Mouse" terminology everywhere to indicate pointer data, e.g. MousePos, IsMousePressed(), io.AddMousePosEvent() +// But that "Mouse" data can come from different source which occasionally may be useful for application to know about. +// You can submit a change of pointer type using io.AddMouseSourceEvent(). +enum ImGuiMouseSource : int +{ + ImGuiMouseSource_Mouse = 0, // Input is coming from an actual mouse. + ImGuiMouseSource_TouchScreen, // Input is coming from a touch screen (no hovering prior to initial press, less precise initial press aiming, dual-axis wheeling possible). + ImGuiMouseSource_Pen, // Input is coming from a pressure/magnetic pen (often used in conjunction with high-sampling rates). + ImGuiMouseSource_COUNT +}; + // Enumeration for ImGui::SetWindow***(), SetNextWindow***(), SetNextItem***() functions // Represent a condition. // Important: Treat as a regular enum! Do NOT combine multiple values using binary operators! All the functions above treat 0 as a shortcut to ImGuiCond_Always. enum ImGuiCond_ { ImGuiCond_None = 0, // No condition (always set the variable), same as _Always - ImGuiCond_Always = 1 << 0, // No condition (always set the variable) + ImGuiCond_Always = 1 << 0, // No condition (always set the variable), same as _None ImGuiCond_Once = 1 << 1, // Set the variable once per runtime session (only the first call will succeed) ImGuiCond_FirstUseEver = 1 << 2, // Set the variable if the object/window has no persistently saved data (no entry in .ini file) - ImGuiCond_Appearing = 1 << 3 // Set the variable if the object/window is appearing after being hidden/inactive (or the first time) + ImGuiCond_Appearing = 1 << 3, // Set the variable if the object/window is appearing after being hidden/inactive (or the first time) }; //----------------------------------------------------------------------------- @@ -1867,7 +1874,7 @@ struct ImVector // Constructors, destructor inline ImVector() { Size = Capacity = 0; Data = NULL; } inline ImVector(const ImVector& src) { Size = Capacity = 0; Data = NULL; operator=(src); } - inline ImVector& operator=(const ImVector& src) { clear(); resize(src.Size); memcpy(Data, src.Data, (size_t)Size * sizeof(T)); return *this; } + inline ImVector& operator=(const ImVector& src) { clear(); resize(src.Size); if (src.Data) memcpy(Data, src.Data, (size_t)Size * sizeof(T)); return *this; } inline ~ImVector() { if (Data) IM_FREE(Data); } // Important: does not destruct anything inline void clear() { if (Data) { Size = Capacity = 0; IM_FREE(Data); Data = NULL; } } // Important: does not destruct anything @@ -1898,6 +1905,7 @@ struct ImVector inline void resize(int new_size, const T& v) { if (new_size > Capacity) reserve(_grow_capacity(new_size)); if (new_size > Size) for (int n = Size; n < new_size; n++) memcpy(&Data[n], &v, sizeof(v)); Size = new_size; } inline void shrink(int new_size) { IM_ASSERT(new_size <= Size); Size = new_size; } // Resize a vector to a smaller size, guaranteed not to cause a reallocation inline void reserve(int new_capacity) { if (new_capacity <= Capacity) return; T* new_data = (T*)IM_ALLOC((size_t)new_capacity * sizeof(T)); if (Data) { memcpy(new_data, Data, (size_t)Size * sizeof(T)); IM_FREE(Data); } Data = new_data; Capacity = new_capacity; } + inline void reserve_discard(int new_capacity) { if (new_capacity <= Capacity) return; if (Data) IM_FREE(Data); Data = (T*)IM_ALLOC((size_t)new_capacity * sizeof(T)); Capacity = new_capacity; } // NB: It is illegal to call push_back/push_front/insert with a reference pointing inside the ImVector data itself! e.g. v.push_back(v[10]) is forbidden. inline void push_back(const T& v) { if (Size == Capacity) reserve(_grow_capacity(Size + 1)); memcpy(&Data[Size], &v, sizeof(v)); Size++; } @@ -1931,7 +1939,7 @@ struct ImGuiStyle ImVec2 WindowPadding; // Padding within a window. float WindowRounding; // Radius of window corners rounding. Set to 0.0f to have rectangular windows. Large values tend to lead to variety of artifacts and are not recommended. float WindowBorderSize; // Thickness of border around windows. Generally set to 0.0f or 1.0f. (Other values are not well tested and more CPU/GPU costly). - ImVec2 WindowMinSize; // Minimum window size. This is a global setting. If you want to constraint individual windows, use SetNextWindowSizeConstraints(). + ImVec2 WindowMinSize; // Minimum window size. This is a global setting. If you want to constrain individual windows, use SetNextWindowSizeConstraints(). ImVec2 WindowTitleAlign; // Alignment for title bar text. Defaults to (0.0f,0.5f) for left-aligned,vertically centered. ImGuiDir WindowMenuButtonPosition; // Side of the collapsing/docking button in the title bar (None/Left/Right). Defaults to ImGuiDir_Left. float ChildRounding; // Radius of child window corners rounding. Set to 0.0f to have rectangular windows. @@ -1955,10 +1963,13 @@ struct ImGuiStyle float LogSliderDeadzone; // The size in pixels of the dead-zone around zero on logarithmic sliders that cross zero. float TabRounding; // Radius of upper corners of a tab. Set to 0.0f to have rectangular tabs. float TabBorderSize; // Thickness of border around tabs. - float TabMinWidthForCloseButton; // Minimum width for close button to appears on an unselected tab when hovered. Set to 0.0f to always show when hovering, set to FLT_MAX to never show close button unless selected. + float TabMinWidthForCloseButton; // Minimum width for close button to appear on an unselected tab when hovered. Set to 0.0f to always show when hovering, set to FLT_MAX to never show close button unless selected. ImGuiDir ColorButtonPosition; // Side of the color button in the ColorEdit4 widget (left/right). Defaults to ImGuiDir_Right. ImVec2 ButtonTextAlign; // Alignment of button text when button is larger than text. Defaults to (0.5f, 0.5f) (centered). ImVec2 SelectableTextAlign; // Alignment of selectable text. Defaults to (0.0f, 0.0f) (top-left aligned). It's generally important to keep this left-aligned if you want to lay multiple items on a same line. + float SeparatorTextBorderSize; // Thickkness of border in SeparatorText() + ImVec2 SeparatorTextAlign; // Alignment of text within the separator. Defaults to (0.0f, 0.5f) (left aligned, center). + ImVec2 SeparatorTextPadding; // Horizontal offset of text from each edge of the separator + spacing on other axis. Generally small values. .y is recommended to be == FramePadding.y. ImVec2 DisplayWindowPadding; // Window position are clamped to be visible within the display area or monitors by at least this amount. Only applies to regular windows. ImVec2 DisplaySafeAreaPadding; // If you cannot see the edges of your screen (e.g. on a TV) increase the safe area padding. Apply to popups/tooltips as well regular windows. NB: Prefer configuring your TV sets correctly! float MouseCursorScale; // Scale software rendered mouse cursor (when io.MouseDrawCursor is enabled). We apply per-monitor DPI scaling over this scale. May be removed later. @@ -1981,7 +1992,7 @@ struct ImGuiStyle //----------------------------------------------------------------------------- // [Internal] Storage used by IsKeyDown(), IsKeyPressed() etc functions. -// If prior to 1.87 you used io.KeysDownDuration[] (which was marked as internal), you should use GetKeyData(key)->DownDuration and not io.KeysData[key]->DownDuration. +// If prior to 1.87 you used io.KeysDownDuration[] (which was marked as internal), you should use GetKeyData(key)->DownDuration and *NOT* io.KeysData[key]->DownDuration. struct ImGuiKeyData { bool Down; // True for if key is down @@ -2006,9 +2017,11 @@ struct ImGuiIO float MouseDoubleClickTime; // = 0.30f // Time for a double-click, in seconds. float MouseDoubleClickMaxDist; // = 6.0f // Distance threshold to stay in to validate a double-click, in pixels. float MouseDragThreshold; // = 6.0f // Distance threshold before considering we are dragging. - float KeyRepeatDelay; // = 0.250f // When holding a key/button, time before it starts repeating, in seconds (for buttons in Repeat mode, etc.). + float KeyRepeatDelay; // = 0.275f // When holding a key/button, time before it starts repeating, in seconds (for buttons in Repeat mode, etc.). float KeyRepeatRate; // = 0.050f // When holding a key/button, rate at which it repeats, in seconds. - void* UserData; // = NULL // Store your own data for retrieval by callbacks. + float HoverDelayNormal; // = 0.30 sec // Delay on hovering before IsItemHovered(ImGuiHoveredFlags_DelayNormal) returns true. + float HoverDelayShort; // = 0.10 sec // Delay on hovering before IsItemHovered(ImGuiHoveredFlags_DelayShort) returns true. + void* UserData; // = NULL // Store your own data. ImFontAtlas*Fonts; // // Font atlas: load, rasterize and pack one or more fonts into a single texture. float FontGlobalScale; // = 1.0f // Global scale all fonts @@ -2036,11 +2049,24 @@ struct ImGuiIO bool ConfigMacOSXBehaviors; // = defined(__APPLE__) // OS X style: Text editing cursor movement using Alt instead of Ctrl, Shortcuts using Cmd/Super instead of Ctrl, Line/Text Start and End using Cmd+Arrows instead of Home/End, Double click selects by word instead of selecting whole text, Multi-selection in lists uses Cmd/Super instead of Ctrl. bool ConfigInputTrickleEventQueue; // = true // Enable input queue trickling: some types of events submitted during the same frame (e.g. button down + up) will be spread over multiple frames, improving interactions with low framerates. bool ConfigInputTextCursorBlink; // = true // Enable blinking cursor (optional as some users consider it to be distracting). + bool ConfigInputTextEnterKeepActive; // = false // [BETA] Pressing Enter will keep item active and select contents (single-line only). bool ConfigDragClickToInputText; // = false // [BETA] Enable turning DragXXX widgets into text input with a simple mouse click-release (without moving). Not desirable on devices without a keyboard. bool ConfigWindowsResizeFromEdges; // = true // Enable resizing of windows from their edges and from the lower-left corner. This requires (io.BackendFlags & ImGuiBackendFlags_HasMouseCursors) because it needs mouse cursor feedback. (This used to be a per-window ImGuiWindowFlags_ResizeFromAnySide flag) bool ConfigWindowsMoveFromTitleBarOnly; // = false // Enable allowing to move windows only when clicking on their title bar. Does not apply to windows without a title bar. float ConfigMemoryCompactTimer; // = 60.0f // Timer (in seconds) to free transient windows/tables memory buffers when unused. Set to -1.0f to disable. + // Debug options + // - tools to test correct Begin/End and BeginChild/EndChild behaviors. + // - presently Begin()/End() and BeginChild()/EndChild() needs to ALWAYS be called in tandem, regardless of return value of BeginXXX() + // this is inconsistent with other BeginXXX functions and create confusion for many users. + // - we expect to update the API eventually. In the meanwhile we provide tools to facilitate checking user-code behavior. + bool ConfigDebugBeginReturnValueOnce;// = false // First-time calls to Begin()/BeginChild() will return false. NEEDS TO BE SET AT APPLICATION BOOT TIME if you don't want to miss windows. + bool ConfigDebugBeginReturnValueLoop;// = false // Some calls to Begin()/BeginChild() will return false. Will cycle through window depths then repeat. Suggested use: add "io.ConfigDebugBeginReturnValue = io.KeyShift" in your main loop then occasionally press SHIFT. Windows should be flickering while running. + // - option to deactivate io.AddFocusEvent(false) handling. May facilitate interactions with a debugger when focus loss leads to clearing inputs data. + // - backends may have other side-effects on focus loss, so this will reduce side-effects but not necessary remove all of them. + // - consider using e.g. Win32's IsDebuggerPresent() as an additional filter (or see ImOsIsDebuggerPresent() in imgui_test_engine/imgui_te_utils.cpp for a Unix compatible version). + bool ConfigDebugIgnoreFocusLoss; // = false // Ignore io.AddFocusEvent(false), consequently not calling io.ClearInputKeys() in input processing. + //------------------------------------------------------------------ // Platform Functions // (the imgui_impl_xxxx backend files are setting those up for you) @@ -2077,16 +2103,18 @@ struct ImGuiIO IMGUI_API void AddKeyAnalogEvent(ImGuiKey key, bool down, float v); // Queue a new key down/up event for analog values (e.g. ImGuiKey_Gamepad_ values). Dead-zones should be handled by the backend. IMGUI_API void AddMousePosEvent(float x, float y); // Queue a mouse position update. Use -FLT_MAX,-FLT_MAX to signify no mouse (e.g. app not focused and not hovered) IMGUI_API void AddMouseButtonEvent(int button, bool down); // Queue a mouse button change - IMGUI_API void AddMouseWheelEvent(float wh_x, float wh_y); // Queue a mouse wheel update + IMGUI_API void AddMouseWheelEvent(float wheel_x, float wheel_y); // Queue a mouse wheel update. wheel_y<0: scroll down, wheel_y>0: scroll up, wheel_x<0: scroll right, wheel_x>0: scroll left. + IMGUI_API void AddMouseSourceEvent(ImGuiMouseSource source); // Queue a mouse source change (Mouse/TouchScreen/Pen) IMGUI_API void AddMouseViewportEvent(ImGuiID id); // Queue a mouse hovered viewport. Requires backend to set ImGuiBackendFlags_HasMouseHoveredViewport to call this (for multi-viewport support). IMGUI_API void AddFocusEvent(bool focused); // Queue a gain/loss of focus for the application (generally based on OS/platform focus of your window) IMGUI_API void AddInputCharacter(unsigned int c); // Queue a new character input - IMGUI_API void AddInputCharacterUTF16(ImWchar16 c); // Queue a new character input from an UTF-16 character, it can be a surrogate - IMGUI_API void AddInputCharactersUTF8(const char* str); // Queue a new characters input from an UTF-8 string + IMGUI_API void AddInputCharacterUTF16(ImWchar16 c); // Queue a new character input from a UTF-16 character, it can be a surrogate + IMGUI_API void AddInputCharactersUTF8(const char* str); // Queue a new characters input from a UTF-8 string + IMGUI_API void SetKeyEventNativeData(ImGuiKey key, int native_keycode, int native_scancode, int native_legacy_index = -1); // [Optional] Specify index for legacy <1.87 IsKeyXXX() functions with native indices + specify native keycode, scancode. + IMGUI_API void SetAppAcceptingEvents(bool accepting_events); // Set master flag for accepting key/mouse/text events (default to true). Useful if you have native dialog boxes that are interrupting your application loop/refresh, and you want to disable events being queued while your app is frozen. IMGUI_API void ClearInputCharacters(); // [Internal] Clear the text input buffer manually IMGUI_API void ClearInputKeys(); // [Internal] Release all keys - IMGUI_API void SetKeyEventNativeData(ImGuiKey key, int native_keycode, int native_scancode, int native_legacy_index = -1); // [Optional] Specify index for legacy <1.87 IsKeyXXX() functions with native indices + specify native keycode, scancode. //------------------------------------------------------------------ // Output - Updated by NewFrame() or EndFrame()/Render() @@ -2102,7 +2130,7 @@ struct ImGuiIO bool IsSomethingHappening; // This is set to true when inertial scrolling is happening. bool NavActive; // Keyboard/Gamepad navigation is currently allowed (will handle ImGuiKey_NavXXX events) = a window is focused and it doesn't use the ImGuiWindowFlags_NoNavInputs flag. bool NavVisible; // Keyboard/Gamepad navigation is visible and allowed (will handle ImGuiKey_NavXXX events). - float Framerate; // Rough estimate of application framerate, in frame per second. Solely for convenience. Rolling average estimation based on io.DeltaTime over 120 frames. + float Framerate; // Estimate of application framerate (rolling average over 60 frames, based on io.DeltaTime), in frame per second. Solely for convenience. Slow applications may not want to use a moving average or may want to reset underlying buffers occasionally. int MetricsRenderVertices; // Vertices output during last call to Render() int MetricsRenderIndices; // Indices output during last call to Render() = number of triangles * 3 int MetricsRenderWindows; // Number of visible windows @@ -2114,32 +2142,36 @@ struct ImGuiIO // Legacy: before 1.87, we required backend to fill io.KeyMap[] (imgui->native map) during initialization and io.KeysDown[] (native indices) every frame. // This is still temporarily supported as a legacy feature. However the new preferred scheme is for backend to call io.AddKeyEvent(). + // Old (<1.87): ImGui::IsKeyPressed(ImGui::GetIO().KeyMap[ImGuiKey_Space]) --> New (1.87+) ImGui::IsKeyPressed(ImGuiKey_Space) #ifndef IMGUI_DISABLE_OBSOLETE_KEYIO int KeyMap[ImGuiKey_COUNT]; // [LEGACY] Input: map of indices into the KeysDown[512] entries array which represent your "native" keyboard state. The first 512 are now unused and should be kept zero. Legacy backend will write into KeyMap[] using ImGuiKey_ indices which are always >512. bool KeysDown[ImGuiKey_COUNT]; // [LEGACY] Input: Keyboard keys that are pressed (ideally left in the "native" order your engine has access to keyboard keys, so you can use your own defines/enums for keys). This used to be [512] sized. It is now ImGuiKey_COUNT to allow legacy io.KeysDown[GetKeyIndex(...)] to work without an overflow. + float NavInputs[ImGuiNavInput_COUNT]; // [LEGACY] Since 1.88, NavInputs[] was removed. Backends from 1.60 to 1.86 won't build. Feed gamepad inputs via io.AddKeyEvent() and ImGuiKey_GamepadXXX enums. #endif //------------------------------------------------------------------ // [Internal] Dear ImGui will maintain those fields. Forward compatibility not guaranteed! //------------------------------------------------------------------ + ImGuiContext* Ctx; // Parent UI context (needs to be set explicitly by parent). + // Main Input State // (this block used to be written by backend, since 1.87 it is best to NOT write to those directly, call the AddXXX functions above instead) // (reading from those variables is fair game, as they are extremely unlikely to be moving anywhere) ImVec2 MousePos; // Mouse position, in pixels. Set to ImVec2(-FLT_MAX, -FLT_MAX) if mouse is unavailable (on another screen, etc.) - bool MouseDown[5]; // Mouse buttons: 0=left, 1=right, 2=middle + extras (ImGuiMouseButton_COUNT == 5). Dear ImGui mostly uses left and right buttons. Others buttons allows us to track if the mouse is being used by your application + available to user as a convenience via IsMouse** API. - float MouseWheel; // Mouse wheel Vertical: 1 unit scrolls about 5 lines text. - float MouseWheelH; // Mouse wheel Horizontal. Most users don't have a mouse with an horizontal wheel, may not be filled by all backends. + bool MouseDown[5]; // Mouse buttons: 0=left, 1=right, 2=middle + extras (ImGuiMouseButton_COUNT == 5). Dear ImGui mostly uses left and right buttons. Other buttons allow us to track if the mouse is being used by your application + available to user as a convenience via IsMouse** API. + float MouseWheel; // Mouse wheel Vertical: 1 unit scrolls about 5 lines text. >0 scrolls Up, <0 scrolls Down. Hold SHIFT to turn vertical scroll into horizontal scroll. + float MouseWheelH; // Mouse wheel Horizontal. >0 scrolls Left, <0 scrolls Right. Most users don't have a mouse with a horizontal wheel, may not be filled by all backends. + ImGuiMouseSource MouseSource; // Mouse actual input peripheral (Mouse/TouchScreen/Pen). ImGuiID MouseHoveredViewport; // (Optional) Modify using io.AddMouseViewportEvent(). With multi-viewports: viewport the OS mouse is hovering. If possible _IGNORING_ viewports with the ImGuiViewportFlags_NoInputs flag is much better (few backends can handle that). Set io.BackendFlags |= ImGuiBackendFlags_HasMouseHoveredViewport if you can provide this info. If you don't imgui will infer the value using the rectangles and last focused time of the viewports it knows about (ignoring other OS windows). bool KeyCtrl; // Keyboard modifier down: Control bool KeyShift; // Keyboard modifier down: Shift bool KeyAlt; // Keyboard modifier down: Alt bool KeySuper; // Keyboard modifier down: Cmd/Super/Windows - float NavInputs[ImGuiNavInput_COUNT]; // Gamepad inputs. Cleared back to zero by EndFrame(). Keyboard keys will be auto-mapped and be written here by NewFrame(). // Other state maintained from data above + IO function calls - ImGuiModFlags KeyMods; // Key mods flags (same as io.KeyCtrl/KeyShift/KeyAlt/KeySuper but merged into flags), updated by NewFrame() - ImGuiKeyData KeysData[ImGuiKey_KeysData_SIZE]; // Key state for all known keys. Use IsKeyXXX() functions to access this. + ImGuiKeyChord KeyMods; // Key mods flags (any of ImGuiMod_Ctrl/ImGuiMod_Shift/ImGuiMod_Alt/ImGuiMod_Super flags, same as io.KeyCtrl/KeyShift/KeyAlt/KeySuper but merged into flags. DOES NOT CONTAINS ImGuiMod_Shortcut which is pretranslated). Read-only, updated by NewFrame() + ImGuiKeyData KeysData[ImGuiKey_KeysData_SIZE]; // Key state for all known keys. Use IsKeyXXX() functions to access this. bool WantCaptureMouseUnlessPopupClose; // Alternative to WantCaptureMouse: (WantCaptureMouse == true && WantCaptureMouseUnlessPopupClose == false) when a click over void is expected to close a popup. ImVec2 MousePosPrev; // Previous mouse position (note that MouseDelta is not necessary == MousePos-MousePosPrev, in case either position is invalid) ImVec2 MouseClickedPos[5]; // Position at time of clicking @@ -2151,14 +2183,14 @@ struct ImGuiIO bool MouseReleased[5]; // Mouse button went from Down to !Down bool MouseDownOwned[5]; // Track if button was clicked inside a dear imgui window or over void blocked by a popup. We don't request mouse capture from the application if click started outside ImGui bounds. bool MouseDownOwnedUnlessPopupClose[5]; // Track if button was clicked inside a dear imgui window. + bool MouseWheelRequestAxisSwap; // On a non-Mac system, holding SHIFT requests WheelY to perform the equivalent of a WheelX event. On a Mac system this is already enforced by the system. float MouseDownDuration[5]; // Duration the mouse button has been down (0.0f == just clicked) float MouseDownDurationPrev[5]; // Previous time the mouse button has been down ImVec2 MouseDragMaxDistanceAbs[5]; // Maximum distance, absolute, on each axis, of how much mouse has traveled from the clicking point float MouseDragMaxDistanceSqr[5]; // Squared maximum distance of how much mouse has traveled from the clicking point (used for moving thresholds) - float NavInputsDownDuration[ImGuiNavInput_COUNT]; - float NavInputsDownDurationPrev[ImGuiNavInput_COUNT]; float PenPressure; // Touch/Pen pressure (0.0f to 1.0f, should be >0.0f only when MouseDown[0] == true). Helper storage currently unused by Dear ImGui. - bool AppFocusLost; + bool AppFocusLost; // Only modify via AddFocusEvent() + bool AppAcceptingEvents; // Only modify via SetAppAcceptingEvents() ImS8 BackendUsingLegacyKeyArrays; // -1: unknown, 0: using AddKeyEvent(), 1: using legacy io.KeysDown[] bool BackendUsingLegacyNavInputArray; // 0: using AddKeyAnalogEvent(), 1: writing to legacy io.NavInputs[] directly ImWchar16 InputQueueSurrogate; // For AddInputCharacterUTF16() @@ -2182,6 +2214,7 @@ struct ImGuiIO // - ImGuiInputTextFlags_CallbackResize: Callback on buffer capacity changes request (beyond 'buf_size' parameter value), allowing the string to grow. struct ImGuiInputTextCallbackData { + ImGuiContext* Ctx; // Parent UI context ImGuiInputTextFlags EventFlag; // One ImGuiInputTextFlags_Callback* // Read-only ImGuiInputTextFlags Flags; // What user passed to InputText() // Read-only void* UserData; // What user passed to InputText() // Read-only @@ -2213,7 +2246,7 @@ struct ImGuiInputTextCallbackData // NB: For basic min/max size constraint on each axis you don't need to use the callback! The SetNextWindowSizeConstraints() parameters are enough. struct ImGuiSizeCallbackData { - void* UserData; // Read-only. What user passed to SetNextWindowSizeConstraints() + void* UserData; // Read-only. What user passed to SetNextWindowSizeConstraints(). Generally store an integer or float in here (need reinterpret_cast<>). ImVec2 Pos; // Read-only. Window position, for reference. ImVec2 CurrentSize; // Read-only. Current window size. ImVec2 DesiredSize; // Read-write. Desired size, based on user's mouse position. Write to this field to restrain resizing. @@ -2287,7 +2320,7 @@ struct ImGuiTableSortSpecs }; //----------------------------------------------------------------------------- -// [SECTION] Helpers (ImGuiOnceUponAFrame, ImGuiTextFilter, ImGuiTextBuffer, ImGuiStorage, ImGuiListClipper, ImColor) +// [SECTION] Helpers (ImGuiOnceUponAFrame, ImGuiTextFilter, ImGuiTextBuffer, ImGuiStorage, ImGuiListClipper, Math Operators, ImColor) //----------------------------------------------------------------------------- // Helper: Unicode defines @@ -2298,7 +2331,7 @@ struct ImGuiTableSortSpecs #define IM_UNICODE_CODEPOINT_MAX 0xFFFF // Maximum Unicode code point supported by this build. #endif -// Helper: Execute a block of code at maximum once a frame. Convenient if you want to quickly create an UI within deep-nested code that runs multiple times every frame. +// Helper: Execute a block of code at maximum once a frame. Convenient if you want to quickly create a UI within deep-nested code that runs multiple times every frame. // Usage: static ImGuiOnceUponAFrame oaf; if (oaf) ImGui::Text("This will be called only once per frame"); struct ImGuiOnceUponAFrame { @@ -2406,7 +2439,7 @@ struct ImGuiStorage }; // Helper: Manually clip large list of items. -// If you have lots evenly spaced items and you have a random access to the list, you can perform coarse +// If you have lots evenly spaced items and you have random access to the list, you can perform coarse // clipping based on visibility to only submit items that are in view. // The clipper calculates the range of visible items and advance the cursor to compensate for the non-visible items we have skipped. // (Dear ImGui already clip items based on their bounds but: it needs to first layout the item to do so, and generally @@ -2427,6 +2460,7 @@ struct ImGuiStorage // - The clipper also handles various subtleties related to keyboard/gamepad navigation, wrapping etc. struct ImGuiListClipper { + ImGuiContext* Ctx; // Parent UI context int DisplayStart; // First item to display, updated by each call to Step() int DisplayEnd; // End of items to display (exclusive) int ItemsCount; // [Internal] Number of items @@ -2442,14 +2476,42 @@ struct ImGuiListClipper IMGUI_API void End(); // Automatically called on the last call of Step() that returns false. IMGUI_API bool Step(); // Call until it returns false. The DisplayStart/DisplayEnd fields will be set and you can process/draw those items. - // Call ForceDisplayRangeByIndices() before first call to Step() if you need a range of items to be displayed regardless of visibility. - IMGUI_API void ForceDisplayRangeByIndices(int item_min, int item_max); // item_max is exclusive e.g. use (42, 42+1) to make item 42 always visible BUT due to alignment/padding of certain items it is likely that an extra item may be included on either end of the display range. + // Call IncludeRangeByIndices() *BEFORE* first call to Step() if you need a range of items to not be clipped, regardless of their visibility. + // (Due to alignment / padding of certain items it is possible that an extra item may be included on either end of the display range). + IMGUI_API void IncludeRangeByIndices(int item_begin, int item_end); // item_end is exclusive e.g. use (42, 42+1) to make item 42 never clipped. #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS - inline ImGuiListClipper(int items_count, float items_height = -1.0f) { memset(this, 0, sizeof(*this)); ItemsCount = -1; Begin(items_count, items_height); } // [removed in 1.79] + inline void ForceDisplayRangeByIndices(int item_begin, int item_end) { IncludeRangeByIndices(item_begin, item_end); } // [renamed in 1.89.6] + //inline ImGuiListClipper(int items_count, float items_height = -1.0f) { memset(this, 0, sizeof(*this)); ItemsCount = -1; Begin(items_count, items_height); } // [removed in 1.79] #endif }; +// Helpers: ImVec2/ImVec4 operators +// - It is important that we are keeping those disabled by default so they don't leak in user space. +// - This is in order to allow user enabling implicit cast operators between ImVec2/ImVec4 and their own types (using IM_VEC2_CLASS_EXTRA in imconfig.h) +// - You can use '#define IMGUI_DEFINE_MATH_OPERATORS' to import our operators, provided as a courtesy. +#ifdef IMGUI_DEFINE_MATH_OPERATORS +#define IMGUI_DEFINE_MATH_OPERATORS_IMPLEMENTED +IM_MSVC_RUNTIME_CHECKS_OFF +static inline ImVec2 operator*(const ImVec2& lhs, const float rhs) { return ImVec2(lhs.x * rhs, lhs.y * rhs); } +static inline ImVec2 operator/(const ImVec2& lhs, const float rhs) { return ImVec2(lhs.x / rhs, lhs.y / rhs); } +static inline ImVec2 operator+(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x + rhs.x, lhs.y + rhs.y); } +static inline ImVec2 operator-(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x - rhs.x, lhs.y - rhs.y); } +static inline ImVec2 operator*(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x * rhs.x, lhs.y * rhs.y); } +static inline ImVec2 operator/(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x / rhs.x, lhs.y / rhs.y); } +static inline ImVec2 operator-(const ImVec2& lhs) { return ImVec2(-lhs.x, -lhs.y); } +static inline ImVec2& operator*=(ImVec2& lhs, const float rhs) { lhs.x *= rhs; lhs.y *= rhs; return lhs; } +static inline ImVec2& operator/=(ImVec2& lhs, const float rhs) { lhs.x /= rhs; lhs.y /= rhs; return lhs; } +static inline ImVec2& operator+=(ImVec2& lhs, const ImVec2& rhs) { lhs.x += rhs.x; lhs.y += rhs.y; return lhs; } +static inline ImVec2& operator-=(ImVec2& lhs, const ImVec2& rhs) { lhs.x -= rhs.x; lhs.y -= rhs.y; return lhs; } +static inline ImVec2& operator*=(ImVec2& lhs, const ImVec2& rhs) { lhs.x *= rhs.x; lhs.y *= rhs.y; return lhs; } +static inline ImVec2& operator/=(ImVec2& lhs, const ImVec2& rhs) { lhs.x /= rhs.x; lhs.y /= rhs.y; return lhs; } +static inline ImVec4 operator+(const ImVec4& lhs, const ImVec4& rhs) { return ImVec4(lhs.x + rhs.x, lhs.y + rhs.y, lhs.z + rhs.z, lhs.w + rhs.w); } +static inline ImVec4 operator-(const ImVec4& lhs, const ImVec4& rhs) { return ImVec4(lhs.x - rhs.x, lhs.y - rhs.y, lhs.z - rhs.z, lhs.w - rhs.w); } +static inline ImVec4 operator*(const ImVec4& lhs, const ImVec4& rhs) { return ImVec4(lhs.x * rhs.x, lhs.y * rhs.y, lhs.z * rhs.z, lhs.w * rhs.w); } +IM_MSVC_RUNTIME_CHECKS_RESTORE +#endif + // Helpers macros to generate 32-bit encoded colors // User can declare their own format by #defining the 5 _SHIFT/_MASK macros in their imconfig file. #ifndef IM_COL32_R_SHIFT @@ -2552,7 +2614,7 @@ struct ImDrawVert #else // You can override the vertex format layout by defining IMGUI_OVERRIDE_DRAWVERT_STRUCT_LAYOUT in imconfig.h // The code expect ImVec2 pos (8 bytes), ImVec2 uv (8 bytes), ImU32 col (4 bytes), but you can re-order them or add other fields as needed to simplify integration in your engine. -// The type has to be described within the macro (you can either declare the struct or use a typedef). This is because ImVec2/ImU32 are likely not declared a the time you'd want to set your type up. +// The type has to be described within the macro (you can either declare the struct or use a typedef). This is because ImVec2/ImU32 are likely not declared at the time you'd want to set your type up. // NOTE: IMGUI DOESN'T CLEAR THE STRUCTURE AND DOESN'T CALL A CONSTRUCTOR SO ANY CUSTOM FIELD WILL BE UNINITIALIZED. IF YOU ADD EXTRA FIELDS (SUCH AS A 'Z' COORDINATES) YOU WILL NEED TO CLEAR THEM DURING RENDER OR TO IGNORE THEM. IMGUI_OVERRIDE_DRAWVERT_STRUCT_LAYOUT; #endif @@ -2607,7 +2669,7 @@ enum ImDrawFlags_ ImDrawFlags_RoundCornersRight = ImDrawFlags_RoundCornersBottomRight | ImDrawFlags_RoundCornersTopRight, ImDrawFlags_RoundCornersAll = ImDrawFlags_RoundCornersTopLeft | ImDrawFlags_RoundCornersTopRight | ImDrawFlags_RoundCornersBottomLeft | ImDrawFlags_RoundCornersBottomRight, ImDrawFlags_RoundCornersDefault_ = ImDrawFlags_RoundCornersAll, // Default to ALL corners if none of the _RoundCornersXX flags are specified. - ImDrawFlags_RoundCornersMask_ = ImDrawFlags_RoundCornersAll | ImDrawFlags_RoundCornersNone + ImDrawFlags_RoundCornersMask_ = ImDrawFlags_RoundCornersAll | ImDrawFlags_RoundCornersNone, }; // Flags for ImDrawList instance. Those are set automatically by ImGui:: functions from ImGuiIO settings, and generally not manipulated directly. @@ -2618,7 +2680,7 @@ enum ImDrawListFlags_ ImDrawListFlags_AntiAliasedLines = 1 << 0, // Enable anti-aliased lines/borders (*2 the number of triangles for 1.0f wide line or lines thin enough to be drawn using textures, otherwise *3 the number of triangles) ImDrawListFlags_AntiAliasedLinesUseTex = 1 << 1, // Enable anti-aliased lines/borders using textures when possible. Require backend to render with bilinear filtering (NOT point/nearest filtering). ImDrawListFlags_AntiAliasedFill = 1 << 2, // Enable anti-aliased edge around filled shapes (rounded rectangles, circles). - ImDrawListFlags_AllowVtxOffset = 1 << 3 // Can emit 'VtxOffset > 0' to allow large meshes. Set when 'ImGuiBackendFlags_RendererHasVtxOffset' is enabled. + ImDrawListFlags_AllowVtxOffset = 1 << 3, // Can emit 'VtxOffset > 0' to allow large meshes. Set when 'ImGuiBackendFlags_RendererHasVtxOffset' is enabled. }; // Draw command list @@ -2640,7 +2702,7 @@ struct ImDrawList // [Internal, used while building lists] unsigned int _VtxCurrentIdx; // [Internal] generally == VtxBuffer.Size unless we are past 64K vertices, in which case this gets reset to 0. - const ImDrawListSharedData* _Data; // Pointer to shared draw data (you can use ImGui::GetDrawListSharedData() to get the one from current ImGui context) + ImDrawListSharedData* _Data; // Pointer to shared draw data (you can use ImGui::GetDrawListSharedData() to get the one from current ImGui context) const char* _OwnerName; // Pointer to owner window's name for debugging ImDrawVert* _VtxWritePtr; // [Internal] point within VtxBuffer.Data after each add command (to avoid using the ImVector<> operators too much) ImDrawIdx* _IdxWritePtr; // [Internal] point within IdxBuffer.Data after each add command (to avoid using the ImVector<> operators too much) @@ -2652,7 +2714,7 @@ struct ImDrawList float _FringeScale; // [Internal] anti-alias fringe is scaled by this value, this helps to keep things sharp while zooming at vertex buffer content // If you want to create ImDrawList instances, pass them ImGui::GetDrawListSharedData() or create and use your own ImDrawListSharedData (so you can use ImDrawList without ImGui) - ImDrawList(const ImDrawListSharedData* shared_data) { memset(this, 0, sizeof(*this)); _Data = shared_data; } + ImDrawList(ImDrawListSharedData* shared_data) { memset(this, 0, sizeof(*this)); _Data = shared_data; } ~ImDrawList() { _ClearFreeMemory(); } IMGUI_API void PushClipRect(const ImVec2& clip_rect_min, const ImVec2& clip_rect_max, bool intersect_with_current_clip_rect = false); // Render-level scissoring. This is passed down to your render function but not used for CPU-side coarse clipping. Prefer using higher-level ImGui::PushClipRect() to affect logic (hit-testing and widget culling) @@ -2669,7 +2731,7 @@ struct ImDrawList // - For circle primitives, use "num_segments == 0" to automatically calculate tessellation (preferred). // In older versions (until Dear ImGui 1.77) the AddCircle functions defaulted to num_segments == 12. // In future versions we will use textures to provide cheaper and higher-quality circles. - // Use AddNgon() and AddNgonFilled() functions if you need to guaranteed a specific number of sides. + // Use AddNgon() and AddNgonFilled() functions if you need to guarantee a specific number of sides. IMGUI_API void AddLine(const ImVec2& p1, const ImVec2& p2, ImU32 col, float thickness = 1.0f); IMGUI_API void AddRect(const ImVec2& p_min, const ImVec2& p_max, ImU32 col, float rounding = 0.0f, ImDrawFlags flags = 0, float thickness = 1.0f); // a: upper-left, b: lower-right (== upper-left + size) IMGUI_API void AddRectFilled(const ImVec2& p_min, const ImVec2& p_max, ImU32 col, float rounding = 0.0f, ImDrawFlags flags = 0); // a: upper-left, b: lower-right (== upper-left + size) @@ -2737,10 +2799,9 @@ struct ImDrawList inline void PrimWriteIdx(ImDrawIdx idx) { *_IdxWritePtr = idx; _IdxWritePtr++; } inline void PrimVtx(const ImVec2& pos, const ImVec2& uv, ImU32 col) { PrimWriteIdx((ImDrawIdx)_VtxCurrentIdx); PrimWriteVtx(pos, uv, col); } // Write vertex with unique index -#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS - inline void AddBezierCurve(const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, ImU32 col, float thickness, int num_segments = 0) { AddBezierCubic(p1, p2, p3, p4, col, thickness, num_segments); } // OBSOLETED in 1.80 (Jan 2021) - inline void PathBezierCurveTo(const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, int num_segments = 0) { PathBezierCubicCurveTo(p2, p3, p4, num_segments); } // OBSOLETED in 1.80 (Jan 2021) -#endif + // Obsolete names + //inline void AddBezierCurve(const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, ImU32 col, float thickness, int num_segments = 0) { AddBezierCubic(p1, p2, p3, p4, col, thickness, num_segments); } // OBSOLETED in 1.80 (Jan 2021) + //inline void PathBezierCurveTo(const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, int num_segments = 0) { PathBezierCubicCurveTo(p2, p3, p4, num_segments); } // OBSOLETED in 1.80 (Jan 2021) // [Internal helpers] IMGUI_API void _ResetForNewFrame(); @@ -2793,7 +2854,7 @@ struct ImFontConfig bool PixelSnapH; // false // Align every glyph to pixel boundary. Useful e.g. if you are merging a non-pixel aligned font with the default font. If enabled, you can set OversampleH/V to 1. ImVec2 GlyphExtraSpacing; // 0, 0 // Extra spacing (in pixels) between glyphs. Only X axis is supported for now. ImVec2 GlyphOffset; // 0, 0 // Offset all glyphs from this font input. - const ImWchar* GlyphRanges; // NULL // Pointer to a user-provided list of Unicode range (2 value per range, values are inclusive, zero-terminated list). THE ARRAY DATA NEEDS TO PERSIST AS LONG AS THE FONT IS ALIVE. + const ImWchar* GlyphRanges; // NULL // THE ARRAY DATA NEEDS TO PERSIST AS LONG AS THE FONT IS ALIVE. Pointer to a user-provided list of Unicode range (2 value per range, values are inclusive, zero-terminated list). float GlyphMinAdvanceX; // 0 // Minimum AdvanceX for glyphs, set Min to align font icons, set both Min/Max to enforce mono-space font float GlyphMaxAdvanceX; // FLT_MAX // Maximum AdvanceX for glyphs bool MergeMode; // false // Merge into previous ImFont, so you can combine multiple inputs font into one ImFont (e.g. ASCII font + icons + Japanese glyphs). You may want to use GlyphOffset.y when merge font of different heights. @@ -2855,7 +2916,7 @@ enum ImFontAtlasFlags_ ImFontAtlasFlags_None = 0, ImFontAtlasFlags_NoPowerOfTwoHeight = 1 << 0, // Don't round the height to next power of two ImFontAtlasFlags_NoMouseCursors = 1 << 1, // Don't build software mouse cursors into the atlas (save a little texture memory) - ImFontAtlasFlags_NoBakedLines = 1 << 2 // Don't build thick line textures into the atlas (save a little texture memory, allow support for point/nearest filtering). The AntiAliasedLinesUseTex features uses them, otherwise they will be rendered using polygons (more expensive for CPU/GPU). + ImFontAtlasFlags_NoBakedLines = 1 << 2, // Don't build thick line textures into the atlas (save a little texture memory, allow support for point/nearest filtering). The AntiAliasedLinesUseTex features uses them, otherwise they will be rendered using polygons (more expensive for CPU/GPU). }; // Load and rasterize multiple TTF/OTF fonts into a same texture. The font atlas will build a single texture holding: @@ -2874,7 +2935,7 @@ enum ImFontAtlasFlags_ // - Important: By default, AddFontFromMemoryTTF() takes ownership of the data. Even though we are not writing to it, we will free the pointer on destruction. // You can set font_cfg->FontDataOwnedByAtlas=false to keep ownership of your data and it won't be freed, // - Even though many functions are suffixed with "TTF", OTF data is supported just as well. -// - This is an old API and it is currently awkward for those and and various other reasons! We will address them in the future! +// - This is an old API and it is currently awkward for those and various other reasons! We will address them in the future! struct ImFontAtlas { IMGUI_API ImFontAtlas(); @@ -2898,7 +2959,7 @@ struct ImFontAtlas IMGUI_API bool Build(); // Build pixels data. This is called automatically for you by the GetTexData*** functions. IMGUI_API void GetTexDataAsAlpha8(unsigned char** out_pixels, int* out_width, int* out_height, int* out_bytes_per_pixel = NULL); // 1 byte per-pixel IMGUI_API void GetTexDataAsRGBA32(unsigned char** out_pixels, int* out_width, int* out_height, int* out_bytes_per_pixel = NULL); // 4 bytes-per-pixel - bool IsBuilt() const { return Fonts.Size > 0 && TexReady; } // Bit ambiguous: used to detect when user didn't built texture but effectively we should check TexID != 0 except that would be backend dependent... + bool IsBuilt() const { return Fonts.Size > 0 && TexReady; } // Bit ambiguous: used to detect when user didn't build texture but effectively we should check TexID != 0 except that would be backend dependent... void SetTexID(ImTextureID id) { TexID = id; } //------------------------------------------- @@ -2906,9 +2967,11 @@ struct ImFontAtlas //------------------------------------------- // Helpers to retrieve list of common Unicode ranges (2 value per range, values are inclusive, zero-terminated list) - // NB: Make sure that your string are UTF-8 and NOT in your local code page. In C++11, you can create UTF-8 string literal using the u8"Hello world" syntax. See FAQ for details. + // NB: Make sure that your string are UTF-8 and NOT in your local code page. + // Read https://github.com/ocornut/imgui/blob/master/docs/FONTS.md/#about-utf-8-encoding for details. // NB: Consider using ImFontGlyphRangesBuilder to build glyph ranges from textual data. IMGUI_API const ImWchar* GetGlyphRangesDefault(); // Basic Latin, Extended Latin + IMGUI_API const ImWchar* GetGlyphRangesGreek(); // Default + Greek and Coptic IMGUI_API const ImWchar* GetGlyphRangesKorean(); // Default + Korean characters IMGUI_API const ImWchar* GetGlyphRangesJapanese(); // Default + Hiragana, Katakana, Half-Width, Selection of 2999 Ideographs IMGUI_API const ImWchar* GetGlyphRangesChineseFull(); // Default + Half-Width + Japanese Hiragana/Katakana + full set of about 21000 CJK Unified Ideographs @@ -2945,6 +3008,7 @@ struct ImFontAtlas int TexDesiredWidth; // Texture width desired by user before Build(). Must be a power-of-two. If have many glyphs your graphics API have texture size restrictions you may want to increase texture width to decrease height. int TexGlyphPadding; // Padding between glyphs within texture in pixels. Defaults to 1. If your rendering method doesn't rely on bilinear filtering you may set this to 0 (will also need to set AntiAliasedLinesUseTex = false). bool Locked; // Marked as Locked by ImGui::NewFrame() so attempt to modify the atlas will assert. + void* UserData; // Store your own atlas related user-data (if e.g. you have multiple font atlas). // [Internal] // NB: Access texture data via GetTexData*() calls! Which will setup a default font for you. @@ -2993,8 +3057,10 @@ struct ImFont const ImFontConfig* ConfigData; // 4-8 // in // // Pointer within ContainerAtlas->ConfigData short ConfigDataCount; // 2 // in // ~ 1 // Number of ImFontConfig involved in creating this font. Bigger than 1 when merging multiple font sources into one ImFont. ImWchar FallbackChar; // 2 // out // = FFFD/'?' // Character used if a glyph isn't found. - ImWchar EllipsisChar; // 2 // out // = '...' // Character used for ellipsis rendering. - ImWchar DotChar; // 2 // out // = '.' // Character used for ellipsis rendering (if a single '...' character isn't found) + ImWchar EllipsisChar; // 2 // out // = '...'/'.'// Character used for ellipsis rendering. + short EllipsisCharCount; // 1 // out // 1 or 3 + float EllipsisWidth; // 4 // out // Width + float EllipsisCharStep; // 4 // out // Step between characters when EllipsisCount > 0 bool DirtyLookupTables; // 1 // out // float Scale; // 4 // in // = 1.f // Base font scale, multiplied by the per-window font scale which you can adjust with SetWindowFontScale() float Ascent, Descent; // 4+4 // out // // Ascent: distance from top to bottom of e.g. 'A' [0..FontSize] @@ -3037,17 +3103,20 @@ enum ImGuiViewportFlags_ ImGuiViewportFlags_None = 0, ImGuiViewportFlags_IsPlatformWindow = 1 << 0, // Represent a Platform Window ImGuiViewportFlags_IsPlatformMonitor = 1 << 1, // Represent a Platform Monitor (unused yet) - ImGuiViewportFlags_OwnedByApp = 1 << 2, // Platform Window: is created/managed by the application (rather than a dear imgui backend) + ImGuiViewportFlags_OwnedByApp = 1 << 2, // Platform Window: Was created/managed by the user application? (rather than our backend) ImGuiViewportFlags_NoDecoration = 1 << 3, // Platform Window: Disable platform decorations: title bar, borders, etc. (generally set all windows, but if ImGuiConfigFlags_ViewportsDecoration is set we only set this on popups/tooltips) ImGuiViewportFlags_NoTaskBarIcon = 1 << 4, // Platform Window: Disable platform task bar icon (generally set on popups/tooltips, or all windows if ImGuiConfigFlags_ViewportsNoTaskBarIcon is set) ImGuiViewportFlags_NoFocusOnAppearing = 1 << 5, // Platform Window: Don't take focus when created. ImGuiViewportFlags_NoFocusOnClick = 1 << 6, // Platform Window: Don't take focus when clicked on. ImGuiViewportFlags_NoInputs = 1 << 7, // Platform Window: Make mouse pass through so we can drag this window while peaking behind it. ImGuiViewportFlags_NoRendererClear = 1 << 8, // Platform Window: Renderer doesn't need to clear the framebuffer ahead (because we will fill it entirely). - ImGuiViewportFlags_TopMost = 1 << 9, // Platform Window: Display on top (for tooltips only). - ImGuiViewportFlags_Minimized = 1 << 10, // Platform Window: Window is minimized, can skip render. When minimized we tend to avoid using the viewport pos/size for clipping window or testing if they are contained in the viewport. - ImGuiViewportFlags_NoAutoMerge = 1 << 11, // Platform Window: Avoid merging this window into another host window. This can only be set via ImGuiWindowClass viewport flags override (because we need to now ahead if we are going to create a viewport in the first place!). - ImGuiViewportFlags_CanHostOtherWindows = 1 << 12 // Main viewport: can host multiple imgui windows (secondary viewports are associated to a single window). + ImGuiViewportFlags_NoAutoMerge = 1 << 9, // Platform Window: Avoid merging this window into another host window. This can only be set via ImGuiWindowClass viewport flags override (because we need to now ahead if we are going to create a viewport in the first place!). + ImGuiViewportFlags_TopMost = 1 << 10, // Platform Window: Display on top (for tooltips only). + ImGuiViewportFlags_CanHostOtherWindows = 1 << 11, // Viewport can host multiple imgui windows (secondary viewports are associated to a single window). // FIXME: In practice there's still probably code making the assumption that this is always and only on the MainViewport. Will fix once we add support for "no main viewport". + + // Output status flags (from Platform) + ImGuiViewportFlags_IsMinimized = 1 << 12, // Platform Window: Window is minimized, can skip render. When minimized we tend to avoid using the viewport pos/size for clipping window or testing if they are contained in the viewport. + ImGuiViewportFlags_IsFocused = 1 << 13, // Platform Window: Window is focused (last call to Platform_GetWindowFocus() returned true) }; // - Currently represents the Platform Window created by the application which is hosting our Dear ImGui windows. @@ -3078,6 +3147,7 @@ struct ImGuiViewport void* PlatformUserData; // void* to hold custom data structure for the OS / platform (e.g. windowing info, render context). generally set by your Platform_CreateWindow function. void* PlatformHandle; // void* for FindViewportByPlatformHandle(). (e.g. suggested to use natural platform handle such as HWND, GLFWWindow*, SDL_Window*) void* PlatformHandleRaw; // void* to hold lower-level, platform-native window handle (under Win32 this is expected to be a HWND, unused for other platforms), when using an abstraction layer like GLFW or SDL (where PlatformHandle would be a SDL_Window*) + bool PlatformWindowCreated; // Platform window has been created (Platform_CreateWindow() has been called). This is false during the first frame where a viewport is being created. bool PlatformRequestMove; // Platform window requested move (e.g. window was moved by the OS / host window manager, authoritative position will be OS window position) bool PlatformRequestResize; // Platform window requested resize (e.g. window was resized by the OS / host window manager, authoritative size will be OS window size) bool PlatformRequestClose; // Platform window requested closure (e.g. window was moved by the OS / host window manager, e.g. pressing ALT-F4) @@ -3208,7 +3278,8 @@ struct ImGuiPlatformMonitor ImVec2 MainPos, MainSize; // Coordinates of the area displayed on this monitor (Min = upper left, Max = bottom right) ImVec2 WorkPos, WorkSize; // Coordinates without task bars / side bars / menu bars. Used to avoid positioning popups/tooltips inside this region. If you don't have this info, please copy the value for MainPos/MainSize. float DpiScale; // 1.0f = 96 DPI - ImGuiPlatformMonitor() { MainPos = MainSize = WorkPos = WorkSize = ImVec2(0, 0); DpiScale = 1.0f; } + void* PlatformHandle; // Backend dependant data (e.g. HMONITOR, GLFWmonitor*, SDL Display Index, NSScreen*) + ImGuiPlatformMonitor() { MainPos = MainSize = WorkPos = WorkSize = ImVec2(0, 0); DpiScale = 1.0f; PlatformHandle = NULL; } }; // (Optional) Support for IME (Input Method Editor) via the io.SetPlatformImeDataFn() function. @@ -3230,50 +3301,57 @@ struct ImGuiPlatformImeData namespace ImGui { #ifndef IMGUI_DISABLE_OBSOLETE_KEYIO - IMGUI_API int GetKeyIndex(ImGuiKey key); // map ImGuiKey_* values into legacy native key index. == io.KeyMap[key] + IMGUI_API ImGuiKey GetKeyIndex(ImGuiKey key); // map ImGuiKey_* values into legacy native key index. == io.KeyMap[key] #else - static inline int GetKeyIndex(ImGuiKey key) { IM_ASSERT(key >= ImGuiKey_NamedKey_BEGIN && key < ImGuiKey_NamedKey_END && "ImGuiKey and native_index was merged together and native_index is disabled by IMGUI_DISABLE_OBSOLETE_KEYIO. Please switch to ImGuiKey."); return key; } + static inline ImGuiKey GetKeyIndex(ImGuiKey key) { IM_ASSERT(key >= ImGuiKey_NamedKey_BEGIN && key < ImGuiKey_NamedKey_END && "ImGuiKey and native_index was merged together and native_index is disabled by IMGUI_DISABLE_OBSOLETE_KEYIO. Please switch to ImGuiKey."); return key; } #endif } #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS namespace ImGui { + // OBSOLETED in 1.89.4 (from March 2023) + static inline void PushAllowKeyboardFocus(bool tab_stop) { PushTabStop(tab_stop); } + static inline void PopAllowKeyboardFocus() { PopTabStop(); } + // OBSOLETED in 1.89 (from August 2022) + IMGUI_API bool ImageButton(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0 = ImVec2(0, 0), const ImVec2& uv1 = ImVec2(1, 1), int frame_padding = -1, const ImVec4& bg_col = ImVec4(0, 0, 0, 0), const ImVec4& tint_col = ImVec4(1, 1, 1, 1)); // Use new ImageButton() signature (explicit item id, regular FramePadding) + // OBSOLETED in 1.88 (from May 2022) + static inline void CaptureKeyboardFromApp(bool want_capture_keyboard = true) { SetNextFrameWantCaptureKeyboard(want_capture_keyboard); } // Renamed as name was misleading + removed default value. + static inline void CaptureMouseFromApp(bool want_capture_mouse = true) { SetNextFrameWantCaptureMouse(want_capture_mouse); } // Renamed as name was misleading + removed default value. // OBSOLETED in 1.86 (from November 2021) IMGUI_API void CalcListClipping(int items_count, float items_height, int* out_items_display_start, int* out_items_display_end); // Calculate coarse clipping for large list of evenly sized items. Prefer using ImGuiListClipper. // OBSOLETED in 1.85 (from August 2021) - static inline float GetWindowContentRegionWidth() { return GetWindowContentRegionMax().x - GetWindowContentRegionMin().x; } - // OBSOLETED in 1.81 (from February 2021) - IMGUI_API bool ListBoxHeader(const char* label, int items_count, int height_in_items = -1); // Helper to calculate size from items_count and height_in_items - static inline bool ListBoxHeader(const char* label, const ImVec2& size = ImVec2(0, 0)) { return BeginListBox(label, size); } - static inline void ListBoxFooter() { EndListBox(); } - // OBSOLETED in 1.79 (from August 2020) - static inline void OpenPopupContextItem(const char* str_id = NULL, ImGuiMouseButton mb = 1) { OpenPopupOnItemClick(str_id, mb); } // Bool return value removed. Use IsWindowAppearing() in BeginPopup() instead. Renamed in 1.77, renamed back in 1.79. Sorry! - // OBSOLETED in 1.78 (from June 2020) - // Old drag/sliders functions that took a 'float power = 1.0' argument instead of flags. - // For shared code, you can version check at compile-time with `#if IMGUI_VERSION_NUM >= 17704`. - IMGUI_API bool DragScalar(const char* label, ImGuiDataType data_type, void* p_data, float v_speed, const void* p_min, const void* p_max, const char* format, float power); - IMGUI_API bool DragScalarN(const char* label, ImGuiDataType data_type, void* p_data, int components, float v_speed, const void* p_min, const void* p_max, const char* format, float power); - static inline bool DragFloat(const char* label, float* v, float v_speed, float v_min, float v_max, const char* format, float power) { return DragScalar(label, ImGuiDataType_Float, v, v_speed, &v_min, &v_max, format, power); } - static inline bool DragFloat2(const char* label, float v[2], float v_speed, float v_min, float v_max, const char* format, float power) { return DragScalarN(label, ImGuiDataType_Float, v, 2, v_speed, &v_min, &v_max, format, power); } - static inline bool DragFloat3(const char* label, float v[3], float v_speed, float v_min, float v_max, const char* format, float power) { return DragScalarN(label, ImGuiDataType_Float, v, 3, v_speed, &v_min, &v_max, format, power); } - static inline bool DragFloat4(const char* label, float v[4], float v_speed, float v_min, float v_max, const char* format, float power) { return DragScalarN(label, ImGuiDataType_Float, v, 4, v_speed, &v_min, &v_max, format, power); } - IMGUI_API bool SliderScalar(const char* label, ImGuiDataType data_type, void* p_data, const void* p_min, const void* p_max, const char* format, float power); - IMGUI_API bool SliderScalarN(const char* label, ImGuiDataType data_type, void* p_data, int components, const void* p_min, const void* p_max, const char* format, float power); - static inline bool SliderFloat(const char* label, float* v, float v_min, float v_max, const char* format, float power) { return SliderScalar(label, ImGuiDataType_Float, v, &v_min, &v_max, format, power); } - static inline bool SliderFloat2(const char* label, float v[2], float v_min, float v_max, const char* format, float power) { return SliderScalarN(label, ImGuiDataType_Float, v, 2, &v_min, &v_max, format, power); } - static inline bool SliderFloat3(const char* label, float v[3], float v_min, float v_max, const char* format, float power) { return SliderScalarN(label, ImGuiDataType_Float, v, 3, &v_min, &v_max, format, power); } - static inline bool SliderFloat4(const char* label, float v[4], float v_min, float v_max, const char* format, float power) { return SliderScalarN(label, ImGuiDataType_Float, v, 4, &v_min, &v_max, format, power); } - // OBSOLETED in 1.77 (from June 2020) - static inline bool BeginPopupContextWindow(const char* str_id, ImGuiMouseButton mb, bool over_items) { return BeginPopupContextWindow(str_id, mb | (over_items ? 0 : ImGuiPopupFlags_NoOpenOverItems)); } + static inline float GetWindowContentRegionWidth() { return GetWindowContentRegionMax().x - GetWindowContentRegionMin().x; } // Some of the older obsolete names along with their replacement (commented out so they are not reported in IDE) + //-- OBSOLETED in 1.81 (from February 2021) + //static inline bool ListBoxHeader(const char* label, const ImVec2& size = ImVec2(0, 0)) { return BeginListBox(label, size); } + //static inline bool ListBoxHeader(const char* label, int items_count, int height_in_items = -1) { float height = GetTextLineHeightWithSpacing() * ((height_in_items < 0 ? ImMin(items_count, 7) : height_in_items) + 0.25f) + GetStyle().FramePadding.y * 2.0f; return BeginListBox(label, ImVec2(0.0f, height)); } // Helper to calculate size from items_count and height_in_items + //static inline void ListBoxFooter() { EndListBox(); } + //-- OBSOLETED in 1.79 (from August 2020) + //static inline void OpenPopupContextItem(const char* str_id = NULL, ImGuiMouseButton mb = 1) { OpenPopupOnItemClick(str_id, mb); } // Bool return value removed. Use IsWindowAppearing() in BeginPopup() instead. Renamed in 1.77, renamed back in 1.79. Sorry! + //-- OBSOLETED in 1.78 (from June 2020): Old drag/sliders functions that took a 'float power > 1.0f' argument instead of ImGuiSliderFlags_Logarithmic. See github.com/ocornut/imgui/issues/3361 for details. + //IMGUI_API bool DragScalar(const char* label, ImGuiDataType data_type, void* p_data, float v_speed, const void* p_min, const void* p_max, const char* format, float power = 1.0f) // OBSOLETED in 1.78 (from June 2020) + //IMGUI_API bool DragScalarN(const char* label, ImGuiDataType data_type, void* p_data, int components, float v_speed, const void* p_min, const void* p_max, const char* format, float power = 1.0f); // OBSOLETED in 1.78 (from June 2020) + //IMGUI_API bool SliderScalar(const char* label, ImGuiDataType data_type, void* p_data, const void* p_min, const void* p_max, const char* format, float power = 1.0f); // OBSOLETED in 1.78 (from June 2020) + //IMGUI_API bool SliderScalarN(const char* label, ImGuiDataType data_type, void* p_data, int components, const void* p_min, const void* p_max, const char* format, float power = 1.0f); // OBSOLETED in 1.78 (from June 2020) + //static inline bool DragFloat(const char* label, float* v, float v_speed, float v_min, float v_max, const char* format, float power = 1.0f) { return DragScalar(label, ImGuiDataType_Float, v, v_speed, &v_min, &v_max, format, power); } // OBSOLETED in 1.78 (from June 2020) + //static inline bool DragFloat2(const char* label, float v[2], float v_speed, float v_min, float v_max, const char* format, float power = 1.0f) { return DragScalarN(label, ImGuiDataType_Float, v, 2, v_speed, &v_min, &v_max, format, power); } // OBSOLETED in 1.78 (from June 2020) + //static inline bool DragFloat3(const char* label, float v[3], float v_speed, float v_min, float v_max, const char* format, float power = 1.0f) { return DragScalarN(label, ImGuiDataType_Float, v, 3, v_speed, &v_min, &v_max, format, power); } // OBSOLETED in 1.78 (from June 2020) + //static inline bool DragFloat4(const char* label, float v[4], float v_speed, float v_min, float v_max, const char* format, float power = 1.0f) { return DragScalarN(label, ImGuiDataType_Float, v, 4, v_speed, &v_min, &v_max, format, power); } // OBSOLETED in 1.78 (from June 2020) + //static inline bool SliderFloat(const char* label, float* v, float v_min, float v_max, const char* format, float power = 1.0f) { return SliderScalar(label, ImGuiDataType_Float, v, &v_min, &v_max, format, power); } // OBSOLETED in 1.78 (from June 2020) + //static inline bool SliderFloat2(const char* label, float v[2], float v_min, float v_max, const char* format, float power = 1.0f) { return SliderScalarN(label, ImGuiDataType_Float, v, 2, &v_min, &v_max, format, power); } // OBSOLETED in 1.78 (from June 2020) + //static inline bool SliderFloat3(const char* label, float v[3], float v_min, float v_max, const char* format, float power = 1.0f) { return SliderScalarN(label, ImGuiDataType_Float, v, 3, &v_min, &v_max, format, power); } // OBSOLETED in 1.78 (from June 2020) + //static inline bool SliderFloat4(const char* label, float v[4], float v_min, float v_max, const char* format, float power = 1.0f) { return SliderScalarN(label, ImGuiDataType_Float, v, 4, &v_min, &v_max, format, power); } // OBSOLETED in 1.78 (from June 2020) + //-- OBSOLETED in 1.77 and before + //static inline bool BeginPopupContextWindow(const char* str_id, ImGuiMouseButton mb, bool over_items) { return BeginPopupContextWindow(str_id, mb | (over_items ? 0 : ImGuiPopupFlags_NoOpenOverItems)); } // OBSOLETED in 1.77 (from June 2020) //static inline void TreeAdvanceToLabelPos() { SetCursorPosX(GetCursorPosX() + GetTreeNodeToLabelSpacing()); } // OBSOLETED in 1.72 (from July 2019) //static inline void SetNextTreeNodeOpen(bool open, ImGuiCond cond = 0) { SetNextItemOpen(open, cond); } // OBSOLETED in 1.71 (from June 2019) //static inline float GetContentRegionAvailWidth() { return GetContentRegionAvail().x; } // OBSOLETED in 1.70 (from May 2019) //static inline ImDrawList* GetOverlayDrawList() { return GetForegroundDrawList(); } // OBSOLETED in 1.69 (from Mar 2019) //static inline void SetScrollHere(float ratio = 0.5f) { SetScrollHereY(ratio); } // OBSOLETED in 1.66 (from Nov 2018) //static inline bool IsItemDeactivatedAfterChange() { return IsItemDeactivatedAfterEdit(); } // OBSOLETED in 1.63 (from Aug 2018) + //-- OBSOLETED in 1.60 and before //static inline bool IsAnyWindowFocused() { return IsWindowFocused(ImGuiFocusedFlags_AnyWindow); } // OBSOLETED in 1.60 (from Apr 2018) //static inline bool IsAnyWindowHovered() { return IsWindowHovered(ImGuiHoveredFlags_AnyWindow); } // OBSOLETED in 1.60 (between Dec 2017 and Apr 2018) //static inline void ShowTestWindow() { return ShowDemoWindow(); } // OBSOLETED in 1.53 (between Oct 2017 and Dec 2017) @@ -3281,6 +3359,19 @@ namespace ImGui //static inline bool IsRootWindowOrAnyChildFocused() { return IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows); } // OBSOLETED in 1.53 (between Oct 2017 and Dec 2017) //static inline void SetNextWindowContentWidth(float w) { SetNextWindowContentSize(ImVec2(w, 0.0f)); } // OBSOLETED in 1.53 (between Oct 2017 and Dec 2017) //static inline float GetItemsLineHeightWithSpacing() { return GetFrameHeightWithSpacing(); } // OBSOLETED in 1.53 (between Oct 2017 and Dec 2017) + //IMGUI_API bool Begin(char* name, bool* p_open, ImVec2 size_first_use, float bg_alpha = -1.0f, ImGuiWindowFlags flags=0); // OBSOLETED in 1.52 (between Aug 2017 and Oct 2017): Equivalent of using SetNextWindowSize(size, ImGuiCond_FirstUseEver) and SetNextWindowBgAlpha(). + //static inline bool IsRootWindowOrAnyChildHovered() { return IsWindowHovered(ImGuiHoveredFlags_RootAndChildWindows); } // OBSOLETED in 1.52 (between Aug 2017 and Oct 2017) + //static inline void AlignFirstTextHeightToWidgets() { AlignTextToFramePadding(); } // OBSOLETED in 1.52 (between Aug 2017 and Oct 2017) + //static inline void SetNextWindowPosCenter(ImGuiCond c=0) { SetNextWindowPos(GetMainViewport()->GetCenter(), c, ImVec2(0.5f,0.5f)); } // OBSOLETED in 1.52 (between Aug 2017 and Oct 2017) + //static inline bool IsItemHoveredRect() { return IsItemHovered(ImGuiHoveredFlags_RectOnly); } // OBSOLETED in 1.51 (between Jun 2017 and Aug 2017) + //static inline bool IsPosHoveringAnyWindow(const ImVec2&) { IM_ASSERT(0); return false; } // OBSOLETED in 1.51 (between Jun 2017 and Aug 2017): This was misleading and partly broken. You probably want to use the io.WantCaptureMouse flag instead. + //static inline bool IsMouseHoveringAnyWindow() { return IsWindowHovered(ImGuiHoveredFlags_AnyWindow); } // OBSOLETED in 1.51 (between Jun 2017 and Aug 2017) + //static inline bool IsMouseHoveringWindow() { return IsWindowHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup | ImGuiHoveredFlags_AllowWhenBlockedByActiveItem); } // OBSOLETED in 1.51 (between Jun 2017 and Aug 2017) + //-- OBSOLETED in 1.50 and before + //static inline bool CollapsingHeader(char* label, const char* str_id, bool framed = true, bool default_open = false) { return CollapsingHeader(label, (default_open ? (1 << 5) : 0)); } // OBSOLETED in 1.49 + //static inline ImFont*GetWindowFont() { return GetFont(); } // OBSOLETED in 1.48 + //static inline float GetWindowFontSize() { return GetFontSize(); } // OBSOLETED in 1.48 + //static inline void SetScrollPosHere() { SetScrollHere(); } // OBSOLETED in 1.42 } // OBSOLETED in 1.82 (from Mars 2021): flags for AddRect(), AddRectFilled(), AddImageRounded(), PathRect() @@ -3296,15 +3387,26 @@ enum ImDrawCornerFlags_ ImDrawCornerFlags_Top = ImDrawCornerFlags_TopLeft | ImDrawCornerFlags_TopRight, ImDrawCornerFlags_Bot = ImDrawCornerFlags_BotLeft | ImDrawCornerFlags_BotRight, ImDrawCornerFlags_Left = ImDrawCornerFlags_TopLeft | ImDrawCornerFlags_BotLeft, - ImDrawCornerFlags_Right = ImDrawCornerFlags_TopRight | ImDrawCornerFlags_BotRight + ImDrawCornerFlags_Right = ImDrawCornerFlags_TopRight | ImDrawCornerFlags_BotRight, }; -// RENAMED ImGuiKeyModFlags -> ImGuiModFlags in 1.88 (from April 2022) -typedef int ImGuiKeyModFlags; -enum ImGuiKeyModFlags_ { ImGuiKeyModFlags_None = ImGuiModFlags_None, ImGuiKeyModFlags_Ctrl = ImGuiModFlags_Ctrl, ImGuiKeyModFlags_Shift = ImGuiModFlags_Shift, ImGuiKeyModFlags_Alt = ImGuiModFlags_Alt, ImGuiKeyModFlags_Super = ImGuiModFlags_Super }; +// RENAMED and MERGED both ImGuiKey_ModXXX and ImGuiModFlags_XXX into ImGuiMod_XXX (from September 2022) +// RENAMED ImGuiKeyModFlags -> ImGuiModFlags in 1.88 (from April 2022). Exceptionally commented out ahead of obscolescence schedule to reduce confusion and because they were not meant to be used in the first place. +typedef ImGuiKeyChord ImGuiModFlags; // == int. We generally use ImGuiKeyChord to mean "a ImGuiKey or-ed with any number of ImGuiMod_XXX value", but you may store only mods in there. +enum ImGuiModFlags_ { ImGuiModFlags_None = 0, ImGuiModFlags_Ctrl = ImGuiMod_Ctrl, ImGuiModFlags_Shift = ImGuiMod_Shift, ImGuiModFlags_Alt = ImGuiMod_Alt, ImGuiModFlags_Super = ImGuiMod_Super }; +//typedef ImGuiKeyChord ImGuiKeyModFlags; // == int +//enum ImGuiKeyModFlags_ { ImGuiKeyModFlags_None = 0, ImGuiKeyModFlags_Ctrl = ImGuiMod_Ctrl, ImGuiKeyModFlags_Shift = ImGuiMod_Shift, ImGuiKeyModFlags_Alt = ImGuiMod_Alt, ImGuiKeyModFlags_Super = ImGuiMod_Super }; #endif // #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS +// RENAMED IMGUI_DISABLE_METRICS_WINDOW > IMGUI_DISABLE_DEBUG_TOOLS in 1.88 (from June 2022) +#if defined(IMGUI_DISABLE_METRICS_WINDOW) && !defined(IMGUI_DISABLE_OBSOLETE_FUNCTIONS) && !defined(IMGUI_DISABLE_DEBUG_TOOLS) +#define IMGUI_DISABLE_DEBUG_TOOLS +#endif +#if defined(IMGUI_DISABLE_METRICS_WINDOW) && defined(IMGUI_DISABLE_OBSOLETE_FUNCTIONS) +#error IMGUI_DISABLE_METRICS_WINDOW was renamed to IMGUI_DISABLE_DEBUG_TOOLS, please use new name. +#endif + //----------------------------------------------------------------------------- #if defined(__clang__) diff --git a/extern/imgui_patched/imgui_demo.cpp b/extern/imgui_patched/imgui_demo.cpp index 3e304c63..52abc798 100644 --- a/extern/imgui_patched/imgui_demo.cpp +++ b/extern/imgui_patched/imgui_demo.cpp @@ -1,18 +1,22 @@ -// dear imgui, v1.88 WIP +// dear imgui, v1.89.6 // (demo code) // Help: -// - Read FAQ at http://dearimgui.org/faq +// - Read FAQ at http://dearimgui.com/faq // - Newcomers, read 'Programmer guide' in imgui.cpp for notes on how to setup Dear ImGui in your codebase. // - Call and read ImGui::ShowDemoWindow() in imgui_demo.cpp. All applications in examples/ are doing that. // Read imgui.cpp for more details, documentation and comments. // Get the latest version at https://github.com/ocornut/imgui +// ------------------------------------------------- +// PLEASE DO NOT REMOVE THIS FILE FROM YOUR PROJECT! +// ------------------------------------------------- // Message to the person tempted to delete this file when integrating Dear ImGui into their codebase: -// Do NOT remove this file from your project! Think again! It is the most useful reference code that you and other -// coders will want to refer to and call. Have the ImGui::ShowDemoWindow() function wired in an always-available -// debug menu of your game/app! Removing this file from your project is hindering access to documentation for everyone -// in your team, likely leading you to poorer usage of the library. +// Think again! It is the most useful reference code that you and other coders will want to refer to and call. +// Have the ImGui::ShowDemoWindow() function wired in an always-available debug menu of your game/app! +// Also include Metrics! ItemPicker! DebugLog! and other debug features. +// Removing this file from your project is hindering access to documentation for everyone in your team, +// likely leading you to poorer usage of the library. // Everything in this file will be stripped out by the linker if you don't call ImGui::ShowDemoWindow(). // If you want to link core Dear ImGui in your shipped builds but want a thorough guarantee that the demo will not be // linked, you can setup your imconfig.h with #define IMGUI_DISABLE_DEMO_WINDOWS and those functions will be empty. @@ -34,7 +38,7 @@ // - We try to declare static variables in the local scope, as close as possible to the code using them. // - We never use any of the helpers/facilities used internally by Dear ImGui, unless available in the public API. // - We never use maths operators on ImVec2/ImVec4. For our other sources files we use them, and they are provided -// by imgui_internal.h using the IMGUI_DEFINE_MATH_OPERATORS define. For your own sources file they are optional +// by imgui.h using the IMGUI_DEFINE_MATH_OPERATORS define. For your own sources file they are optional // and require you either enable those, either provide your own via IM_VEC2_CLASS_EXTRA in imconfig.h. // Because we can't assume anything about your support of maths operators, we cannot use them in imgui_demo.cpp. @@ -46,15 +50,18 @@ Index of this file: -// [SECTION] Forward Declarations, Helpers +// [SECTION] Forward Declarations +// [SECTION] Helpers // [SECTION] Demo Window / ShowDemoWindow() +// - ShowDemoWindow() // - sub section: ShowDemoWindowWidgets() // - sub section: ShowDemoWindowLayout() // - sub section: ShowDemoWindowPopups() // - sub section: ShowDemoWindowTables() -// - sub section: ShowDemoWindowMisc() +// - sub section: ShowDemoWindowInputs() // [SECTION] About Window / ShowAboutWindow() // [SECTION] Style Editor / ShowStyleEditor() +// [SECTION] User Guide / ShowUserGuide() // [SECTION] Example App: Main Menu Bar / ShowExampleAppMainMenuBar() // [SECTION] Example App: Debug Console / ShowExampleAppConsole() // [SECTION] Example App: Debug Log / ShowExampleAppLog() @@ -95,7 +102,7 @@ Index of this file: #ifdef _MSC_VER #pragma warning (disable: 4127) // condition expression is constant #pragma warning (disable: 4996) // 'This function or variable may be unsafe': strcpy, strdup, sprintf, vsnprintf, sscanf, fopen -#pragma warning (disable: 26451) // [Static Analyzer] Arithmetic overflow : Using operator 'xxx' on a 4 byte value and then casting the result to a 8 byte value. Cast the value to the wider type before calling operator 'xxx' to avoid overflow(io.2). +#pragma warning (disable: 26451) // [Static Analyzer] Arithmetic overflow : Using operator 'xxx' on a 4 byte value and then casting the result to an 8 byte value. Cast the value to the wider type before calling operator 'xxx' to avoid overflow(io.2). #endif // Clang/GCC warnings with -Weverything @@ -188,14 +195,26 @@ static void ShowExampleAppWindowTitles(bool* p_open); static void ShowExampleAppCustomRendering(bool* p_open); static void ShowExampleMenuFile(); +// We split the contents of the big ShowDemoWindow() function into smaller functions +// (because the link time of very large functions grow non-linearly) +static void ShowDemoWindowWidgets(); +static void ShowDemoWindowLayout(); +static void ShowDemoWindowPopups(); +static void ShowDemoWindowTables(); +static void ShowDemoWindowColumns(); +static void ShowDemoWindowInputs(); + +//----------------------------------------------------------------------------- +// [SECTION] Helpers +//----------------------------------------------------------------------------- + // Helper to display a little (?) mark which shows a tooltip when hovered. // In your own code you may want to display an actual icon if you are using a merged icon fonts (see docs/FONTS.md) static void HelpMarker(const char* desc) { ImGui::TextDisabled("(?)"); - if (ImGui::IsItemHovered()) + if (ImGui::IsItemHovered(ImGuiHoveredFlags_DelayShort) && ImGui::BeginTooltip()) { - ImGui::BeginTooltip(); ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f); ImGui::TextUnformatted(desc); ImGui::PopTextWrapPos(); @@ -213,79 +232,39 @@ static void ShowDockingDisabledMessage() io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; } -// Helper to wire demo markers located in code to a interactive browser +// Helper to wire demo markers located in code to an interactive browser typedef void (*ImGuiDemoMarkerCallback)(const char* file, int line, const char* section, void* user_data); -extern ImGuiDemoMarkerCallback GImGuiDemoMarkerCallback; -extern void* GImGuiDemoMarkerCallbackUserData; -ImGuiDemoMarkerCallback GImGuiDemoMarkerCallback = NULL; -void* GImGuiDemoMarkerCallbackUserData = NULL; +extern ImGuiDemoMarkerCallback GImGuiDemoMarkerCallback; +extern void* GImGuiDemoMarkerCallbackUserData; +ImGuiDemoMarkerCallback GImGuiDemoMarkerCallback = NULL; +void* GImGuiDemoMarkerCallbackUserData = NULL; #define IMGUI_DEMO_MARKER(section) do { if (GImGuiDemoMarkerCallback != NULL) GImGuiDemoMarkerCallback(__FILE__, __LINE__, section, GImGuiDemoMarkerCallbackUserData); } while (0) -// Helper to display basic user controls. -void ImGui::ShowUserGuide() -{ - ImGuiIO& io = ImGui::GetIO(); - ImGui::BulletText("Double-click on title bar to collapse window."); - ImGui::BulletText( - "Click and drag on lower corner to resize window\n" - "(double-click to auto fit window to its contents)."); - ImGui::BulletText("CTRL+Click on a slider or drag box to input value as text."); - ImGui::BulletText("TAB/SHIFT+TAB to cycle through keyboard editable fields."); - ImGui::BulletText("CTRL+Tab to select a window."); - if (io.FontAllowUserScaling) - ImGui::BulletText("CTRL+Mouse Wheel to zoom window contents."); - ImGui::BulletText("While inputing text:\n"); - ImGui::Indent(); - ImGui::BulletText("CTRL+Left/Right to word jump."); - ImGui::BulletText("CTRL+A or double-click to select all."); - ImGui::BulletText("CTRL+X/C/V to use clipboard cut/copy/paste."); - ImGui::BulletText("CTRL+Z,CTRL+Y to undo/redo."); - ImGui::BulletText("ESCAPE to revert."); - ImGui::Unindent(); - ImGui::BulletText("With keyboard navigation enabled:"); - ImGui::Indent(); - ImGui::BulletText("Arrow keys to navigate."); - ImGui::BulletText("Space to activate a widget."); - ImGui::BulletText("Return to input text into a widget."); - ImGui::BulletText("Escape to deactivate a widget, close popup, exit child window."); - ImGui::BulletText("Alt to jump to the menu layer of a window."); - ImGui::Unindent(); -} - //----------------------------------------------------------------------------- // [SECTION] Demo Window / ShowDemoWindow() //----------------------------------------------------------------------------- +// - ShowDemoWindow() // - ShowDemoWindowWidgets() // - ShowDemoWindowLayout() // - ShowDemoWindowPopups() // - ShowDemoWindowTables() // - ShowDemoWindowColumns() -// - ShowDemoWindowMisc() +// - ShowDemoWindowInputs() //----------------------------------------------------------------------------- -// We split the contents of the big ShowDemoWindow() function into smaller functions -// (because the link time of very large functions grow non-linearly) -static void ShowDemoWindowWidgets(); -static void ShowDemoWindowLayout(); -static void ShowDemoWindowPopups(); -static void ShowDemoWindowTables(); -static void ShowDemoWindowColumns(); -static void ShowDemoWindowMisc(); - // Demonstrate most Dear ImGui features (this is big function!) // You may execute this function to experiment with the UI and understand what it does. // You may then search for keywords in the code when you are interested by a specific feature. void ImGui::ShowDemoWindow(bool* p_open) { // Exceptionally add an extra assert here for people confused about initial Dear ImGui setup - // Most ImGui functions would normally just crash if the context is missing. + // Most functions would normally just crash if the context is missing. IM_ASSERT(ImGui::GetCurrentContext() != NULL && "Missing dear imgui context. Refer to examples app!"); // Examples Apps (accessible from the "Examples" menu) static bool show_app_main_menu_bar = false; static bool show_app_dockspace = false; static bool show_app_documents = false; - static bool show_app_console = false; static bool show_app_log = false; static bool show_app_layout = false; @@ -301,7 +280,6 @@ void ImGui::ShowDemoWindow(bool* p_open) if (show_app_main_menu_bar) ShowExampleAppMainMenuBar(); if (show_app_dockspace) ShowExampleAppDockSpace(&show_app_dockspace); // Process the Docking app first, as explicit DockSpace() nodes needs to be submitted early (read comments near the DockSpace function) if (show_app_documents) ShowExampleAppDocuments(&show_app_documents); // Process the Document app next, as it may also use a DockSpace() - if (show_app_console) ShowExampleAppConsole(&show_app_console); if (show_app_log) ShowExampleAppLog(&show_app_log); if (show_app_layout) ShowExampleAppLayout(&show_app_layout); @@ -314,15 +292,21 @@ void ImGui::ShowDemoWindow(bool* p_open) if (show_app_window_titles) ShowExampleAppWindowTitles(&show_app_window_titles); if (show_app_custom_rendering) ShowExampleAppCustomRendering(&show_app_custom_rendering); - // Dear ImGui Apps (accessible from the "Tools" menu) + // Dear ImGui Tools/Apps (accessible from the "Tools" menu) static bool show_app_metrics = false; + static bool show_app_debug_log = false; static bool show_app_stack_tool = false; - static bool show_app_style_editor = false; static bool show_app_about = false; + static bool show_app_style_editor = false; - if (show_app_metrics) { ImGui::ShowMetricsWindow(&show_app_metrics); } - if (show_app_stack_tool) { ImGui::ShowStackToolWindow(&show_app_stack_tool); } - if (show_app_about) { ImGui::ShowAboutWindow(&show_app_about); } + if (show_app_metrics) + ImGui::ShowMetricsWindow(&show_app_metrics); + if (show_app_debug_log) + ImGui::ShowDebugLogWindow(&show_app_debug_log); + if (show_app_stack_tool) + ImGui::ShowStackToolWindow(&show_app_stack_tool); + if (show_app_about) + ImGui::ShowAboutWindow(&show_app_about); if (show_app_style_editor) { ImGui::Begin("Dear ImGui Style Editor", &show_app_style_editor); @@ -373,10 +357,8 @@ void ImGui::ShowDemoWindow(bool* p_open) } // Most "big" widgets share a common width settings by default. See 'Demo->Layout->Widgets Width' for details. - // e.g. Use 2/3 of the space for widgets and 1/3 for labels (right align) //ImGui::PushItemWidth(-ImGui::GetWindowWidth() * 0.35f); - // e.g. Leave a fixed amount of width for labels (by passing a negative value), the rest goes to widgets. ImGui::PushItemWidth(ImGui::GetFontSize() * -12); @@ -412,10 +394,14 @@ void ImGui::ShowDemoWindow(bool* p_open) if (ImGui::BeginMenu("Tools")) { IMGUI_DEMO_MARKER("Menu/Tools"); -#ifndef IMGUI_DISABLE_METRICS_WINDOW - ImGui::MenuItem("Metrics/Debugger", NULL, &show_app_metrics); - ImGui::MenuItem("Stack Tool", NULL, &show_app_stack_tool); +#ifndef IMGUI_DISABLE_DEBUG_TOOLS + const bool has_debug_tools = true; +#else + const bool has_debug_tools = false; #endif + ImGui::MenuItem("Metrics/Debugger", NULL, &show_app_metrics, has_debug_tools); + ImGui::MenuItem("Debug Log", NULL, &show_app_debug_log, has_debug_tools); + ImGui::MenuItem("Stack Tool", NULL, &show_app_stack_tool, has_debug_tools); ImGui::MenuItem("Style Editor", NULL, &show_app_style_editor); ImGui::MenuItem("About Dear ImGui", NULL, &show_app_about); ImGui::EndMenu(); @@ -423,29 +409,27 @@ void ImGui::ShowDemoWindow(bool* p_open) ImGui::EndMenuBar(); } - ImGui::Text("dear imgui says hello. (%s)", IMGUI_VERSION); + ImGui::Text("dear imgui says hello! (%s) (%d)", IMGUI_VERSION, IMGUI_VERSION_NUM); ImGui::Spacing(); IMGUI_DEMO_MARKER("Help"); if (ImGui::CollapsingHeader("Help")) { - ImGui::Text("ABOUT THIS DEMO:"); + ImGui::SeparatorText("ABOUT THIS DEMO:"); ImGui::BulletText("Sections below are demonstrating many aspects of the library."); ImGui::BulletText("The \"Examples\" menu above leads to more demo contents."); ImGui::BulletText("The \"Tools\" menu above gives access to: About Box, Style Editor,\n" "and Metrics/Debugger (general purpose Dear ImGui debugging tool)."); - ImGui::Separator(); - ImGui::Text("PROGRAMMER GUIDE:"); + ImGui::SeparatorText("PROGRAMMER GUIDE:"); ImGui::BulletText("See the ShowDemoWindow() code in imgui_demo.cpp. <- you are here!"); ImGui::BulletText("See comments in imgui.cpp."); ImGui::BulletText("See example applications in the examples/ folder."); - ImGui::BulletText("Read the FAQ at http://www.dearimgui.org/faq/"); + ImGui::BulletText("Read the FAQ at http://www.dearimgui.com/faq/"); ImGui::BulletText("Set 'io.ConfigFlags |= NavEnableKeyboard' for keyboard controls."); ImGui::BulletText("Set 'io.ConfigFlags |= NavEnableGamepad' for gamepad controls."); - ImGui::Separator(); - ImGui::Text("USER GUIDE:"); + ImGui::SeparatorText("USER GUIDE:"); ImGui::ShowUserGuide(); } @@ -456,6 +440,7 @@ void ImGui::ShowDemoWindow(bool* p_open) if (ImGui::TreeNode("Configuration##2")) { + ImGui::SeparatorText("General"); ImGui::CheckboxFlags("io.ConfigFlags: NavEnableKeyboard", &io.ConfigFlags, ImGuiConfigFlags_NavEnableKeyboard); ImGui::SameLine(); HelpMarker("Enable keyboard controls."); ImGui::CheckboxFlags("io.ConfigFlags: NavEnableGamepad", &io.ConfigFlags, ImGuiConfigFlags_NavEnableGamepad); @@ -515,18 +500,34 @@ void ImGui::ShowDemoWindow(bool* p_open) ImGui::Checkbox("io.ConfigInputTrickleEventQueue", &io.ConfigInputTrickleEventQueue); ImGui::SameLine(); HelpMarker("Enable input queue trickling: some types of events submitted during the same frame (e.g. button down + up) will be spread over multiple frames, improving interactions with low framerates."); + ImGui::Checkbox("io.MouseDrawCursor", &io.MouseDrawCursor); + ImGui::SameLine(); HelpMarker("Instruct Dear ImGui to render a mouse cursor itself. Note that a mouse cursor rendered via your application GPU rendering path will feel more laggy than hardware cursor, but will be more in sync with your other visuals.\n\nSome desktop applications may use both kinds of cursors (e.g. enable software cursor only when resizing/dragging something)."); + + ImGui::SeparatorText("Widgets"); ImGui::Checkbox("io.ConfigInputTextCursorBlink", &io.ConfigInputTextCursorBlink); ImGui::SameLine(); HelpMarker("Enable blinking cursor (optional as some users consider it to be distracting)."); + ImGui::Checkbox("io.ConfigInputTextEnterKeepActive", &io.ConfigInputTextEnterKeepActive); + ImGui::SameLine(); HelpMarker("Pressing Enter will keep item active and select contents (single-line only)."); ImGui::Checkbox("io.ConfigDragClickToInputText", &io.ConfigDragClickToInputText); ImGui::SameLine(); HelpMarker("Enable turning DragXXX widgets into text input with a simple mouse click-release (without moving)."); ImGui::Checkbox("io.ConfigWindowsResizeFromEdges", &io.ConfigWindowsResizeFromEdges); ImGui::SameLine(); HelpMarker("Enable resizing of windows from their edges and from the lower-left corner.\nThis requires (io.BackendFlags & ImGuiBackendFlags_HasMouseCursors) because it needs mouse cursor feedback."); ImGui::Checkbox("io.ConfigWindowsMoveFromTitleBarOnly", &io.ConfigWindowsMoveFromTitleBarOnly); - ImGui::Checkbox("io.MouseDrawCursor", &io.MouseDrawCursor); - ImGui::SameLine(); HelpMarker("Instruct Dear ImGui to render a mouse cursor itself. Note that a mouse cursor rendered via your application GPU rendering path will feel more laggy than hardware cursor, but will be more in sync with your other visuals.\n\nSome desktop applications may use both kinds of cursors (e.g. enable software cursor only when resizing/dragging something)."); + ImGui::Checkbox("io.ConfigMacOSXBehaviors", &io.ConfigMacOSXBehaviors); ImGui::Text("Also see Style->Rendering for rendering options."); + + ImGui::SeparatorText("Debug"); + ImGui::BeginDisabled(); + ImGui::Checkbox("io.ConfigDebugBeginReturnValueOnce", &io.ConfigDebugBeginReturnValueOnce); // . + ImGui::EndDisabled(); + ImGui::SameLine(); HelpMarker("First calls to Begin()/BeginChild() will return false.\n\nTHIS OPTION IS DISABLED because it needs to be set at application boot-time to make sense. Showing the disabled option is a way to make this feature easier to discover"); + ImGui::Checkbox("io.ConfigDebugBeginReturnValueLoop", &io.ConfigDebugBeginReturnValueLoop); + ImGui::SameLine(); HelpMarker("Some calls to Begin()/BeginChild() will return false.\n\nWill cycle through window depths then repeat. Windows should be flickering while running."); + ImGui::Checkbox("io.ConfigDebugIgnoreFocusLoss", &io.ConfigDebugIgnoreFocusLoss); + ImGui::SameLine(); HelpMarker("Option to deactivate io.AddFocusEvent(false) handling. May facilitate interactions with a debugger when focus loss leads to clearing inputs data."); + ImGui::TreePop(); - ImGui::Separator(); + ImGui::Spacing(); } IMGUI_DEMO_MARKER("Configuration/Backend Flags"); @@ -537,17 +538,18 @@ void ImGui::ShowDemoWindow(bool* p_open) "Here we expose them as read-only fields to avoid breaking interactions with your backend."); // Make a local copy to avoid modifying actual backend flags. - // FIXME: We don't use BeginDisabled() to keep label bright, maybe we need a BeginReadonly() equivalent.. - ImGuiBackendFlags backend_flags = io.BackendFlags; - ImGui::CheckboxFlags("io.BackendFlags: HasGamepad", &backend_flags, ImGuiBackendFlags_HasGamepad); - ImGui::CheckboxFlags("io.BackendFlags: HasMouseCursors", &backend_flags, ImGuiBackendFlags_HasMouseCursors); - ImGui::CheckboxFlags("io.BackendFlags: HasSetMousePos", &backend_flags, ImGuiBackendFlags_HasSetMousePos); - ImGui::CheckboxFlags("io.BackendFlags: PlatformHasViewports", &backend_flags, ImGuiBackendFlags_PlatformHasViewports); - ImGui::CheckboxFlags("io.BackendFlags: HasMouseHoveredViewport",&backend_flags, ImGuiBackendFlags_HasMouseHoveredViewport); - ImGui::CheckboxFlags("io.BackendFlags: RendererHasVtxOffset", &backend_flags, ImGuiBackendFlags_RendererHasVtxOffset); - ImGui::CheckboxFlags("io.BackendFlags: RendererHasViewports", &backend_flags, ImGuiBackendFlags_RendererHasViewports); + // FIXME: Maybe we need a BeginReadonly() equivalent to keep label bright? + ImGui::BeginDisabled(); + ImGui::CheckboxFlags("io.BackendFlags: HasGamepad", &io.BackendFlags, ImGuiBackendFlags_HasGamepad); + ImGui::CheckboxFlags("io.BackendFlags: HasMouseCursors", &io.BackendFlags, ImGuiBackendFlags_HasMouseCursors); + ImGui::CheckboxFlags("io.BackendFlags: HasSetMousePos", &io.BackendFlags, ImGuiBackendFlags_HasSetMousePos); + ImGui::CheckboxFlags("io.BackendFlags: PlatformHasViewports", &io.BackendFlags, ImGuiBackendFlags_PlatformHasViewports); + ImGui::CheckboxFlags("io.BackendFlags: HasMouseHoveredViewport",&io.BackendFlags, ImGuiBackendFlags_HasMouseHoveredViewport); + ImGui::CheckboxFlags("io.BackendFlags: RendererHasVtxOffset", &io.BackendFlags, ImGuiBackendFlags_RendererHasVtxOffset); + ImGui::CheckboxFlags("io.BackendFlags: RendererHasViewports", &io.BackendFlags, ImGuiBackendFlags_RendererHasViewports); + ImGui::EndDisabled(); ImGui::TreePop(); - ImGui::Separator(); + ImGui::Spacing(); } IMGUI_DEMO_MARKER("Configuration/Style"); @@ -556,7 +558,7 @@ void ImGui::ShowDemoWindow(bool* p_open) HelpMarker("The same contents can be accessed in 'Tools->Style Editor' or by calling the ShowStyleEditor() function."); ImGui::ShowStyleEditor(); ImGui::TreePop(); - ImGui::Separator(); + ImGui::Spacing(); } IMGUI_DEMO_MARKER("Configuration/Capture, Logging"); @@ -605,7 +607,7 @@ void ImGui::ShowDemoWindow(bool* p_open) ShowDemoWindowLayout(); ShowDemoWindowPopups(); ShowDemoWindowTables(); - ShowDemoWindowMisc(); + ShowDemoWindowInputs(); // End of ShowDemoWindow() ImGui::PopItemWidth(); @@ -625,6 +627,8 @@ static void ShowDemoWindowWidgets() IMGUI_DEMO_MARKER("Widgets/Basic"); if (ImGui::TreeNode("Basic")) { + ImGui::SeparatorText("General"); + IMGUI_DEMO_MARKER("Widgets/Basic/Button"); static int clicked = 0; if (ImGui::Button("Button")) @@ -679,35 +683,41 @@ static void ShowDemoWindowWidgets() ImGui::SameLine(); ImGui::Text("%d", counter); - IMGUI_DEMO_MARKER("Widgets/Basic/Tooltips"); - ImGui::Text("Hover over me"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("I am a tooltip"); - - ImGui::SameLine(); - ImGui::Text("- or me"); - if (ImGui::IsItemHovered()) { - ImGui::BeginTooltip(); - ImGui::Text("I am a fancy tooltip"); - static float arr[] = { 0.6f, 0.1f, 1.0f, 0.5f, 0.92f, 0.1f, 0.2f }; - ImGui::PlotLines("Curve", arr, IM_ARRAYSIZE(arr)); - ImGui::EndTooltip(); + // Tooltips + IMGUI_DEMO_MARKER("Widgets/Basic/Tooltips"); + //ImGui::AlignTextToFramePadding(); + ImGui::Text("Tooltips:"); + + ImGui::SameLine(); + ImGui::SmallButton("Basic"); + if (ImGui::IsItemHovered()) + ImGui::SetTooltip("I am a tooltip"); + + ImGui::SameLine(); + ImGui::SmallButton("Fancy"); + if (ImGui::IsItemHovered() && ImGui::BeginTooltip()) + { + ImGui::Text("I am a fancy tooltip"); + static float arr[] = { 0.6f, 0.1f, 1.0f, 0.5f, 0.92f, 0.1f, 0.2f }; + ImGui::PlotLines("Curve", arr, IM_ARRAYSIZE(arr)); + ImGui::Text("Sin(time) = %f", sinf((float)ImGui::GetTime())); + ImGui::EndTooltip(); + } + + ImGui::SameLine(); + ImGui::SmallButton("Delayed"); + if (ImGui::IsItemHovered(ImGuiHoveredFlags_DelayNormal)) // With a delay + ImGui::SetTooltip("I am a tooltip with a delay."); + + ImGui::SameLine(); + HelpMarker( + "Tooltip are created by using the IsItemHovered() function over any kind of item."); } - ImGui::Separator(); ImGui::LabelText("label", "Value"); - { - // Using the _simplified_ one-liner Combo() api here - // See "Combo" section for examples of how to use the more flexible BeginCombo()/EndCombo() api. - IMGUI_DEMO_MARKER("Widgets/Basic/Combo"); - const char* items[] = { "AAAA", "BBBB", "CCCC", "DDDD", "EEEE", "FFFF", "GGGG", "HHHH", "IIIIIII", "JJJJ", "KKKKKKK" }; - static int item_current = 0; - ImGui::Combo("combo", &item_current, items, IM_ARRAYSIZE(items)); - ImGui::SameLine(); HelpMarker( - "Using the simplified one-liner Combo API here.\nRefer to the \"Combo\" section below for an explanation of how to use the more flexible and general BeginCombo/EndCombo API."); - } + ImGui::SeparatorText("Inputs"); { // To wire InputText() with std::string or any other custom string type, @@ -719,7 +729,7 @@ static void ShowDemoWindowWidgets() "USER:\n" "Hold SHIFT or use mouse to select text.\n" "CTRL+Left/Right to word jump.\n" - "CTRL+A or double-click to select all.\n" + "CTRL+A or Double-Click to select all.\n" "CTRL+X,CTRL+C,CTRL+V clipboard.\n" "CTRL+Z,CTRL+Y undo/redo.\n" "ESCAPE to revert.\n\n" @@ -751,6 +761,8 @@ static void ShowDemoWindowWidgets() ImGui::InputFloat3("input float3", vec4a); } + ImGui::SeparatorText("Drags"); + { IMGUI_DEMO_MARKER("Widgets/Basic/DragInt, DragFloat"); static int i1 = 50, i2 = 42; @@ -767,6 +779,8 @@ static void ShowDemoWindowWidgets() ImGui::DragFloat("drag small float", &f2, 0.0001f, 0.0f, 0.0f, "%.06f ns"); } + ImGui::SeparatorText("Sliders"); + { IMGUI_DEMO_MARKER("Widgets/Basic/SliderInt, SliderFloat"); static int i1 = 0; @@ -789,10 +803,12 @@ static void ShowDemoWindowWidgets() static int elem = Element_Fire; const char* elems_names[Element_COUNT] = { "Fire", "Earth", "Air", "Water" }; const char* elem_name = (elem >= 0 && elem < Element_COUNT) ? elems_names[elem] : "Unknown"; - ImGui::SliderInt("slider enum", &elem, 0, Element_COUNT - 1, elem_name); + ImGui::SliderInt("slider enum", &elem, 0, Element_COUNT - 1, elem_name); // Use ImGuiSliderFlags_NoInput flag to disable CTRL+Click here. ImGui::SameLine(); HelpMarker("Using the format string parameter to display a name instead of the underlying integer."); } + ImGui::SeparatorText("Selectors/Pickers"); + { IMGUI_DEMO_MARKER("Widgets/Basic/ColorEdit3, ColorEdit4"); static float col1[3] = { 1.0f, 0.0f, 0.2f }; @@ -807,6 +823,17 @@ static void ShowDemoWindowWidgets() ImGui::ColorEdit4("color 2", col2); } + { + // Using the _simplified_ one-liner Combo() api here + // See "Combo" section for examples of how to use the more flexible BeginCombo()/EndCombo() api. + IMGUI_DEMO_MARKER("Widgets/Basic/Combo"); + const char* items[] = { "AAAA", "BBBB", "CCCC", "DDDD", "EEEE", "FFFF", "GGGG", "HHHH", "IIIIIII", "JJJJ", "KKKKKKK" }; + static int item_current = 0; + ImGui::Combo("combo", &item_current, items, IM_ARRAYSIZE(items)); + ImGui::SameLine(); HelpMarker( + "Using the simplified one-liner Combo API here.\nRefer to the \"Combo\" section below for an explanation of how to use the more flexible and general BeginCombo/EndCombo API."); + } + { // Using the _simplified_ one-liner ListBox() api here // See "List boxes" section for examples of how to use the more flexible BeginListBox()/EndListBox() api. @@ -1036,7 +1063,7 @@ static void ShowDemoWindowWidgets() // Note that characters values are preserved even by InputText() if the font cannot be displayed, // so you can safely copy & paste garbled characters into another application. ImGui::TextWrapped( - "CJK text will only appears if the font was loaded with the appropriate CJK character ranges. " + "CJK text will only appear if the font was loaded with the appropriate CJK character ranges. " "Call io.Fonts->AddFontFromFileTTF() manually to load extra character ranges. " "Read docs/FONTS.md for details."); ImGui::Text("Hiragana: \xe3\x81\x8b\xe3\x81\x8d\xe3\x81\x8f\xe3\x81\x91\xe3\x81\x93 (kakikukeko)"); // Normally we would use u8"blah blah" with the proper characters directly in the string. @@ -1077,16 +1104,17 @@ static void ShowDemoWindowWidgets() float my_tex_w = (float)io.Fonts->TexWidth; float my_tex_h = (float)io.Fonts->TexHeight; { + static bool use_text_color_for_tint = false; + ImGui::Checkbox("Use Text Color for Tint", &use_text_color_for_tint); ImGui::Text("%.0fx%.0f", my_tex_w, my_tex_h); ImVec2 pos = ImGui::GetCursorScreenPos(); ImVec2 uv_min = ImVec2(0.0f, 0.0f); // Top-left ImVec2 uv_max = ImVec2(1.0f, 1.0f); // Lower-right - ImVec4 tint_col = ImVec4(1.0f, 1.0f, 1.0f, 1.0f); // No tint - ImVec4 border_col = ImVec4(1.0f, 1.0f, 1.0f, 0.5f); // 50% opaque white + ImVec4 tint_col = use_text_color_for_tint ? ImGui::GetStyleColorVec4(ImGuiCol_Text) : ImVec4(1.0f, 1.0f, 1.0f, 1.0f); // No tint + ImVec4 border_col = ImGui::GetStyleColorVec4(ImGuiCol_Border); ImGui::Image(my_tex_id, ImVec2(my_tex_w, my_tex_h), uv_min, uv_max, tint_col, border_col); - if (ImGui::IsItemHovered()) + if (ImGui::IsItemHovered() && ImGui::BeginTooltip()) { - ImGui::BeginTooltip(); float region_sz = 32.0f; float region_x = io.MousePos.x - pos.x - region_sz * 0.5f; float region_y = io.MousePos.y - pos.y - region_sz * 0.5f; @@ -1109,15 +1137,21 @@ static void ShowDemoWindowWidgets() static int pressed_count = 0; for (int i = 0; i < 8; i++) { + // UV coordinates are often (0.0f, 0.0f) and (1.0f, 1.0f) to display an entire textures. + // Here are trying to display only a 32x32 pixels area of the texture, hence the UV computation. + // Read about UV coordinates here: https://github.com/ocornut/imgui/wiki/Image-Loading-and-Displaying-Examples ImGui::PushID(i); - int frame_padding = -1 + i; // -1 == uses default padding (style.FramePadding) - ImVec2 size = ImVec2(32.0f, 32.0f); // Size of the image we want to make visible - ImVec2 uv0 = ImVec2(0.0f, 0.0f); // UV coordinates for lower-left - ImVec2 uv1 = ImVec2(32.0f / my_tex_w, 32.0f / my_tex_h);// UV coordinates for (32,32) in our texture - ImVec4 bg_col = ImVec4(0.0f, 0.0f, 0.0f, 1.0f); // Black background - ImVec4 tint_col = ImVec4(1.0f, 1.0f, 1.0f, 1.0f); // No tint - if (ImGui::ImageButton(my_tex_id, size, uv0, uv1, frame_padding, bg_col, tint_col)) + if (i > 0) + ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(i - 1.0f, i - 1.0f)); + ImVec2 size = ImVec2(32.0f, 32.0f); // Size of the image we want to make visible + ImVec2 uv0 = ImVec2(0.0f, 0.0f); // UV coordinates for lower-left + ImVec2 uv1 = ImVec2(32.0f / my_tex_w, 32.0f / my_tex_h); // UV coordinates for (32,32) in our texture + ImVec4 bg_col = ImVec4(0.0f, 0.0f, 0.0f, 1.0f); // Black background + ImVec4 tint_col = ImVec4(1.0f, 1.0f, 1.0f, 1.0f); // No tint + if (ImGui::ImageButton("", my_tex_id, size, uv0, uv1, bg_col, tint_col)) pressed_count += 1; + if (i > 0) + ImGui::PopStyleVar(); ImGui::PopID(); ImGui::SameLine(); } @@ -1129,6 +1163,7 @@ static void ShowDemoWindowWidgets() IMGUI_DEMO_MARKER("Widgets/Combo"); if (ImGui::TreeNode("Combo")) { + // Combo Boxes are also called "Dropdown" in other systems // Expose flags as checkbox for the demo static ImGuiComboFlags flags = 0; ImGui::CheckboxFlags("ImGuiComboFlags_PopupAlignLeft", &flags, ImGuiComboFlags_PopupAlignLeft); @@ -1414,7 +1449,15 @@ static void ShowDemoWindowWidgets() { struct TextFilters { - // Return 0 (pass) if the character is 'i' or 'm' or 'g' or 'u' or 'i' + // Modify character input by altering 'data->Eventchar' (ImGuiInputTextFlags_CallbackCharFilter callback) + static int FilterCasingSwap(ImGuiInputTextCallbackData* data) + { + if (data->EventChar >= 'a' && data->EventChar <= 'z') { data->EventChar = data->EventChar - 'A' - 'a'; } // Lowercase becomes uppercase + else if (data->EventChar >= 'A' && data->EventChar <= 'Z') { data->EventChar = data->EventChar + 'a' - 'A'; } // Uppercase becomes lowercase + return 0; + } + + // Return 0 (pass) if the character is 'i' or 'm' or 'g' or 'u' or 'i', otherwise return 1 (filter out) static int FilterImGuiLetters(ImGuiInputTextCallbackData* data) { if (data->EventChar < 256 && strchr("imgui", (char)data->EventChar)) @@ -1423,12 +1466,13 @@ static void ShowDemoWindowWidgets() } }; - static char buf1[64] = ""; ImGui::InputText("default", buf1, 64); - static char buf2[64] = ""; ImGui::InputText("decimal", buf2, 64, ImGuiInputTextFlags_CharsDecimal); - static char buf3[64] = ""; ImGui::InputText("hexadecimal", buf3, 64, ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsUppercase); - static char buf4[64] = ""; ImGui::InputText("uppercase", buf4, 64, ImGuiInputTextFlags_CharsUppercase); - static char buf5[64] = ""; ImGui::InputText("no blank", buf5, 64, ImGuiInputTextFlags_CharsNoBlank); - static char buf6[64] = ""; ImGui::InputText("\"imgui\" letters", buf6, 64, ImGuiInputTextFlags_CallbackCharFilter, TextFilters::FilterImGuiLetters); + static char buf1[32] = ""; ImGui::InputText("default", buf1, 32); + static char buf2[32] = ""; ImGui::InputText("decimal", buf2, 32, ImGuiInputTextFlags_CharsDecimal); + static char buf3[32] = ""; ImGui::InputText("hexadecimal", buf3, 32, ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsUppercase); + static char buf4[32] = ""; ImGui::InputText("uppercase", buf4, 32, ImGuiInputTextFlags_CharsUppercase); + static char buf5[32] = ""; ImGui::InputText("no blank", buf5, 32, ImGuiInputTextFlags_CharsNoBlank); + static char buf6[32] = ""; ImGui::InputText("casing swap", buf6, 32, ImGuiInputTextFlags_CallbackCharFilter, TextFilters::FilterCasingSwap); // Use CharFilter callback to replace characters. + static char buf7[32] = ""; ImGui::InputText("\"imgui\"", buf7, 32, ImGuiInputTextFlags_CallbackCharFilter, TextFilters::FilterImGuiLetters); // Use CharFilter callback to disable some characters. ImGui::TreePop(); } @@ -1493,7 +1537,7 @@ static void ShowDemoWindowWidgets() static char buf3[64]; static int edit_count = 0; ImGui::InputText("Edit", buf3, 64, ImGuiInputTextFlags_CallbackEdit, Funcs::MyCallback, (void*)&edit_count); - ImGui::SameLine(); HelpMarker("Here we toggle the casing of the first character on every edits + count edits."); + ImGui::SameLine(); HelpMarker("Here we toggle the casing of the first character on every edit + count edits."); ImGui::SameLine(); ImGui::Text("(%d)", edit_count); ImGui::TreePop(); @@ -1733,7 +1777,7 @@ static void ShowDemoWindowWidgets() } // Use functions to generate output - // FIXME: This is rather awkward because current plot API only pass in indices. + // FIXME: This is actually VERY awkward because current plot API only pass in indices. // We probably want an API passing floats and user provide sample rate/count. struct Funcs { @@ -1741,7 +1785,7 @@ static void ShowDemoWindowWidgets() static float Saw(void*, int i) { return (i & 1) ? 1.0f : -1.0f; } }; static int func_type = 0, display_count = 70; - ImGui::Separator(); + ImGui::SeparatorText("Functions"); ImGui::SetNextItemWidth(ImGui::GetFontSize() * 8); ImGui::Combo("func", &func_type, "Sin\0Saw\0"); ImGui::SameLine(); @@ -1784,6 +1828,7 @@ static void ShowDemoWindowWidgets() static bool drag_and_drop = true; static bool options_menu = true; static bool hdr = false; + ImGui::SeparatorText("Options"); ImGui::Checkbox("With Alpha Preview", &alpha_preview); ImGui::Checkbox("With Half Alpha Preview", &alpha_half_preview); ImGui::Checkbox("With Drag and Drop", &drag_and_drop); @@ -1792,6 +1837,7 @@ static void ShowDemoWindowWidgets() ImGuiColorEditFlags misc_flags = (hdr ? ImGuiColorEditFlags_HDR : 0) | (drag_and_drop ? 0 : ImGuiColorEditFlags_NoDragDrop) | (alpha_half_preview ? ImGuiColorEditFlags_AlphaPreviewHalf : (alpha_preview ? ImGuiColorEditFlags_AlphaPreview : 0)) | (options_menu ? 0 : ImGuiColorEditFlags_NoOptions); IMGUI_DEMO_MARKER("Widgets/Color/ColorEdit"); + ImGui::SeparatorText("Inline color editor"); ImGui::Text("Color widget:"); ImGui::SameLine(); HelpMarker( "Click on the color square to open a color picker.\n" @@ -1889,7 +1935,7 @@ static void ShowDemoWindowWidgets() ImGui::ColorButton("MyColor##3c", *(ImVec4*)&color, misc_flags | (no_border ? ImGuiColorEditFlags_NoBorder : 0), ImVec2(80, 80)); IMGUI_DEMO_MARKER("Widgets/Color/ColorPicker"); - ImGui::Text("Color picker:"); + ImGui::SeparatorText("Color picker"); static bool alpha = true; static bool alpha_bar = true; static bool side_preview = true; @@ -2018,7 +2064,7 @@ static void ShowDemoWindowWidgets() // - integer/float/double // To avoid polluting the public API with all possible combinations, we use the ImGuiDataType enum // to pass the type, and passing all arguments by pointer. - // This is the reason the test code below creates local variables to hold "zero" "one" etc. for each types. + // This is the reason the test code below creates local variables to hold "zero" "one" etc. for each type. // In practice, if you frequently use a given type that is not covered by the normal API entry points, // you can wrap it yourself inside a 1 line function which can take typed argument as value instead of void*, // and then pass their address to the generic function. For example: @@ -2060,10 +2106,10 @@ static void ShowDemoWindowWidgets() const float drag_speed = 0.2f; static bool drag_clamp = false; IMGUI_DEMO_MARKER("Widgets/Data Types/Drags"); - ImGui::Text("Drags:"); + ImGui::SeparatorText("Drags"); ImGui::Checkbox("Clamp integers to 0..50", &drag_clamp); ImGui::SameLine(); HelpMarker( - "As with every widgets in dear imgui, we never modify values unless there is a user interaction.\n" + "As with every widget in dear imgui, we never modify values unless there is a user interaction.\n" "You can override the clamping limits by using CTRL+Click to input a value."); ImGui::DragScalar("drag s8", ImGuiDataType_S8, &s8_v, drag_speed, drag_clamp ? &s8_zero : NULL, drag_clamp ? &s8_fifty : NULL); ImGui::DragScalar("drag u8", ImGuiDataType_U8, &u8_v, drag_speed, drag_clamp ? &u8_zero : NULL, drag_clamp ? &u8_fifty : NULL, "%u ms"); @@ -2080,7 +2126,7 @@ static void ShowDemoWindowWidgets() ImGui::DragScalar("drag double log",ImGuiDataType_Double, &f64_v, 0.0005f, &f64_zero, &f64_one, "0 < %.10f < 1", ImGuiSliderFlags_Logarithmic); IMGUI_DEMO_MARKER("Widgets/Data Types/Sliders"); - ImGui::Text("Sliders"); + ImGui::SeparatorText("Sliders"); ImGui::SliderScalar("slider s8 full", ImGuiDataType_S8, &s8_v, &s8_min, &s8_max, "%d"); ImGui::SliderScalar("slider u8 full", ImGuiDataType_U8, &u8_v, &u8_min, &u8_max, "%u"); ImGui::SliderScalar("slider s16 full", ImGuiDataType_S16, &s16_v, &s16_min, &s16_max, "%d"); @@ -2105,7 +2151,7 @@ static void ShowDemoWindowWidgets() ImGui::SliderScalar("slider double low log",ImGuiDataType_Double, &f64_v, &f64_zero, &f64_one, "%.10f", ImGuiSliderFlags_Logarithmic); ImGui::SliderScalar("slider double high", ImGuiDataType_Double, &f64_v, &f64_lo_a, &f64_hi_a, "%e grams"); - ImGui::Text("Sliders (reverse)"); + ImGui::SeparatorText("Sliders (reverse)"); ImGui::SliderScalar("slider s8 reverse", ImGuiDataType_S8, &s8_v, &s8_max, &s8_min, "%d"); ImGui::SliderScalar("slider u8 reverse", ImGuiDataType_U8, &u8_v, &u8_max, &u8_min, "%u"); ImGui::SliderScalar("slider s32 reverse", ImGuiDataType_S32, &s32_v, &s32_fifty, &s32_zero, "%d"); @@ -2115,7 +2161,7 @@ static void ShowDemoWindowWidgets() IMGUI_DEMO_MARKER("Widgets/Data Types/Inputs"); static bool inputs_step = true; - ImGui::Text("Inputs"); + ImGui::SeparatorText("Inputs"); ImGui::Checkbox("Show step buttons", &inputs_step); ImGui::InputScalar("input s8", ImGuiDataType_S8, &s8_v, inputs_step ? &s8_one : NULL, NULL, "%d"); ImGui::InputScalar("input u8", ImGuiDataType_U8, &u8_v, inputs_step ? &u8_one : NULL, NULL, "%u"); @@ -2139,22 +2185,23 @@ static void ShowDemoWindowWidgets() static float vec4f[4] = { 0.10f, 0.20f, 0.30f, 0.44f }; static int vec4i[4] = { 1, 5, 100, 255 }; + ImGui::SeparatorText("2-wide"); ImGui::InputFloat2("input float2", vec4f); ImGui::DragFloat2("drag float2", vec4f, 0.01f, 0.0f, 1.0f); ImGui::SliderFloat2("slider float2", vec4f, 0.0f, 1.0f); ImGui::InputInt2("input int2", vec4i); ImGui::DragInt2("drag int2", vec4i, 1, 0, 255); ImGui::SliderInt2("slider int2", vec4i, 0, 255); - ImGui::Spacing(); + ImGui::SeparatorText("3-wide"); ImGui::InputFloat3("input float3", vec4f); ImGui::DragFloat3("drag float3", vec4f, 0.01f, 0.0f, 1.0f); ImGui::SliderFloat3("slider float3", vec4f, 0.0f, 1.0f); ImGui::InputInt3("input int3", vec4i); ImGui::DragInt3("drag int3", vec4i, 1, 0, 255); ImGui::SliderInt3("slider int3", vec4i, 0, 255); - ImGui::Spacing(); + ImGui::SeparatorText("4-wide"); ImGui::InputFloat4("input float4", vec4f); ImGui::DragFloat4("drag float4", vec4f, 0.01f, 0.0f, 1.0f); ImGui::SliderFloat4("slider float4", vec4f, 0.0f, 1.0f); @@ -2362,7 +2409,7 @@ static void ShowDemoWindowWidgets() HelpMarker("Testing how various types of items are interacting with the IsItemXXX functions. Note that the bool return value of most ImGui function is generally equivalent to calling ImGui::IsItemHovered()."); ImGui::Checkbox("Item Disabled", &item_disabled); - // Submit selected item item so we can query their status in the code following it. + // Submit selected items so we can query their status in the code following it. bool ret = false; static bool b = false; static float col4f[4] = { 1.0f, 0.5, 0.0f, 1.0f }; @@ -2386,6 +2433,10 @@ static void ShowDemoWindowWidgets() if (item_type == 14){ const char* items[] = { "Apple", "Banana", "Cherry", "Kiwi" }; static int current = 1; ret = ImGui::Combo("ITEM: Combo", ¤t, items, IM_ARRAYSIZE(items)); } if (item_type == 15){ const char* items[] = { "Apple", "Banana", "Cherry", "Kiwi" }; static int current = 1; ret = ImGui::ListBox("ITEM: ListBox", ¤t, items, IM_ARRAYSIZE(items), IM_ARRAYSIZE(items)); } + bool hovered_delay_none = ImGui::IsItemHovered(); + bool hovered_delay_short = ImGui::IsItemHovered(ImGuiHoveredFlags_DelayShort); + bool hovered_delay_normal = ImGui::IsItemHovered(ImGuiHoveredFlags_DelayNormal); + // Display the values of IsItemHovered() and other common item state functions. // Note that the ImGuiHoveredFlags_XXX flags can be combined. // Because BulletText is an item itself and that would affect the output of IsItemXXX functions, @@ -2430,6 +2481,8 @@ static void ShowDemoWindowWidgets() ImGui::GetItemRectMax().x, ImGui::GetItemRectMax().y, ImGui::GetItemRectSize().x, ImGui::GetItemRectSize().y ); + ImGui::BulletText( + "w/ Hovering Delay: None = %d, Fast %d, Normal = %d", hovered_delay_none, hovered_delay_short, hovered_delay_normal); if (item_disabled) ImGui::EndDisabled(); @@ -2549,6 +2602,26 @@ static void ShowDemoWindowWidgets() ImGui::SameLine(); HelpMarker("Demonstrate using BeginDisabled()/EndDisabled() across this section."); ImGui::TreePop(); } + + IMGUI_DEMO_MARKER("Widgets/Text Filter"); + if (ImGui::TreeNode("Text Filter")) + { + // Helper class to easy setup a text filter. + // You may want to implement a more feature-full filtering scheme in your own application. + HelpMarker("Not a widget per-se, but ImGuiTextFilter is a helper to perform simple filtering on text strings."); + static ImGuiTextFilter filter; + ImGui::Text("Filter usage:\n" + " \"\" display all lines\n" + " \"xxx\" display lines containing \"xxx\"\n" + " \"xxx,yyy\" display lines containing \"xxx\" or \"yyy\"\n" + " \"-xxx\" hide lines containing \"xxx\""); + filter.Draw(); + const char* lines[] = { "aaa1.c", "bbb1.c", "ccc1.c", "aaa2.cpp", "bbb2.cpp", "ccc2.cpp", "abc.h", "hello, world" }; + for (int i = 0; i < IM_ARRAYSIZE(lines); i++) + if (filter.PassFilter(lines[i])) + ImGui::BulletText("%s", lines[i]); + ImGui::TreePop(); + } } static void ShowDemoWindowLayout() @@ -2560,6 +2633,8 @@ static void ShowDemoWindowLayout() IMGUI_DEMO_MARKER("Layout/Child windows"); if (ImGui::TreeNode("Child windows")) { + ImGui::SeparatorText("Child windows"); + HelpMarker("Use child windows to begin into a self-contained independent scrolling/clipping regions within a host window."); static bool disable_mouse_wheel = false; static bool disable_menu = false; @@ -2612,7 +2687,7 @@ static void ShowDemoWindowLayout() ImGui::PopStyleVar(); } - ImGui::Separator(); + ImGui::SeparatorText("Misc/Advanced"); // Demonstrate a few extra things // - Changing ImGuiCol_ChildBg (which is transparent black in default styles) @@ -3275,59 +3350,58 @@ static void ShowDemoWindowLayout() ImGui::DragFloat2("size", (float*)&size, 0.5f, 1.0f, 200.0f, "%.0f"); ImGui::TextWrapped("(Click and drag to scroll)"); + HelpMarker( + "(Left) Using ImGui::PushClipRect():\n" + "Will alter ImGui hit-testing logic + ImDrawList rendering.\n" + "(use this if you want your clipping rectangle to affect interactions)\n\n" + "(Center) Using ImDrawList::PushClipRect():\n" + "Will alter ImDrawList rendering only.\n" + "(use this as a shortcut if you are only using ImDrawList calls)\n\n" + "(Right) Using ImDrawList::AddText() with a fine ClipRect:\n" + "Will alter only this specific ImDrawList::AddText() rendering.\n" + "This is often used internally to avoid altering the clipping rectangle and minimize draw calls."); + for (int n = 0; n < 3; n++) { if (n > 0) ImGui::SameLine(); - ImGui::PushID(n); - ImGui::BeginGroup(); // Lock X position - ImGui::InvisibleButton("##empty", size); + ImGui::PushID(n); + ImGui::InvisibleButton("##canvas", size); if (ImGui::IsItemActive() && ImGui::IsMouseDragging(ImGuiMouseButton_Left)) { offset.x += ImGui::GetIO().MouseDelta.x; offset.y += ImGui::GetIO().MouseDelta.y; } + ImGui::PopID(); + if (!ImGui::IsItemVisible()) // Skip rendering as ImDrawList elements are not clipped. + continue; + const ImVec2 p0 = ImGui::GetItemRectMin(); const ImVec2 p1 = ImGui::GetItemRectMax(); const char* text_str = "Line 1 hello\nLine 2 clip me!"; const ImVec2 text_pos = ImVec2(p0.x + offset.x, p0.y + offset.y); ImDrawList* draw_list = ImGui::GetWindowDrawList(); - switch (n) { case 0: - HelpMarker( - "Using ImGui::PushClipRect():\n" - "Will alter ImGui hit-testing logic + ImDrawList rendering.\n" - "(use this if you want your clipping rectangle to affect interactions)"); ImGui::PushClipRect(p0, p1, true); draw_list->AddRectFilled(p0, p1, IM_COL32(90, 90, 120, 255)); draw_list->AddText(text_pos, IM_COL32_WHITE, text_str); ImGui::PopClipRect(); break; case 1: - HelpMarker( - "Using ImDrawList::PushClipRect():\n" - "Will alter ImDrawList rendering only.\n" - "(use this as a shortcut if you are only using ImDrawList calls)"); draw_list->PushClipRect(p0, p1, true); draw_list->AddRectFilled(p0, p1, IM_COL32(90, 90, 120, 255)); draw_list->AddText(text_pos, IM_COL32_WHITE, text_str); draw_list->PopClipRect(); break; case 2: - HelpMarker( - "Using ImDrawList::AddText() with a fine ClipRect:\n" - "Will alter only this specific ImDrawList::AddText() rendering.\n" - "(this is often used internally to avoid altering the clipping rectangle and minimize draw calls)"); ImVec4 clip_rect(p0.x, p0.y, p1.x, p1.y); // AddText() takes a ImVec4* here so let's convert. draw_list->AddRectFilled(p0, p1, IM_COL32(90, 90, 120, 255)); draw_list->AddText(ImGui::GetFont(), ImGui::GetFontSize(), text_pos, IM_COL32_WHITE, text_str, NULL, 0.0f, &clip_rect); break; } - ImGui::EndGroup(); - ImGui::PopID(); } ImGui::TreePop(); @@ -3377,8 +3451,7 @@ static void ShowDemoWindowPopups() ImGui::TextUnformatted(selected_fish == -1 ? "" : names[selected_fish]); if (ImGui::BeginPopup("my_select_popup")) { - ImGui::Text("Aquarium"); - ImGui::Separator(); + ImGui::SeparatorText("Aquarium"); for (int i = 0; i < IM_ARRAYSIZE(names); i++) if (ImGui::Selectable(names[i])) selected_fish = i; @@ -3464,7 +3537,7 @@ static void ShowDemoWindowPopups() // if (IsItemHovered() && IsMouseReleased(ImGuiMouseButton_Right)) // OpenPopup(id); // return BeginPopup(id); - // For advanced advanced uses you may want to replicate and customize this code. + // For advanced uses you may want to replicate and customize this code. // See more details in BeginPopupContextItem(). // Example 1 @@ -3472,11 +3545,14 @@ static void ShowDemoWindowPopups() // and BeginPopupContextItem() will use the last item ID as the popup ID. { const char* names[5] = { "Label1", "Label2", "Label3", "Label4", "Label5" }; + static int selected = -1; for (int n = 0; n < 5; n++) { - ImGui::Selectable(names[n]); + if (ImGui::Selectable(names[n], selected == n)) + selected = n; if (ImGui::BeginPopupContextItem()) // <-- use last item id as popup id { + selected = n; ImGui::Text("This a popup for \"%s\"!", names[n]); if (ImGui::Button("Close")) ImGui::CloseCurrentPopup(); @@ -3552,7 +3628,7 @@ static void ShowDemoWindowPopups() if (ImGui::BeginPopupModal("Delete?", NULL, ImGuiWindowFlags_AlwaysAutoResize)) { - ImGui::Text("All those beautiful files will be deleted.\nThis operation cannot be undone!\n\n"); + ImGui::Text("All those beautiful files will be deleted.\nThis operation cannot be undone!"); ImGui::Separator(); //static int unused_i = 0; @@ -3620,26 +3696,19 @@ static void ShowDemoWindowPopups() ImGui::TextWrapped("Below we are testing adding menu items to a regular window. It's rather unusual but should work!"); ImGui::Separator(); - // Note: As a quirk in this very specific example, we want to differentiate the parent of this menu from the - // parent of the various popup menus above. To do so we are encloding the items in a PushID()/PopID() block - // to make them two different menusets. If we don't, opening any popup above and hovering our menu here would - // open it. This is because once a menu is active, we allow to switch to a sibling menu by just hovering on it, - // which is the desired behavior for regular menus. - ImGui::PushID("foo"); ImGui::MenuItem("Menu item", "CTRL+M"); if (ImGui::BeginMenu("Menu inside a regular window")) { ShowExampleMenuFile(); ImGui::EndMenu(); } - ImGui::PopID(); ImGui::Separator(); ImGui::TreePop(); } } // Dummy data structure that we use for the Table demo. -// (pre-C++11 doesn't allow us to instantiate ImVector template if this structure if defined inside the demo function) +// (pre-C++11 doesn't allow us to instantiate ImVector template if this structure is defined inside the demo function) namespace { // We are passing our own identifier to TableSetupColumn() to facilitate identifying columns in the sorting code. @@ -3742,9 +3811,8 @@ static void EditTableSizingFlags(ImGuiTableFlags* p_flags) } ImGui::SameLine(); ImGui::TextDisabled("(?)"); - if (ImGui::IsItemHovered()) + if (ImGui::IsItemHovered() && ImGui::BeginTooltip()) { - ImGui::BeginTooltip(); ImGui::PushTextWrapPos(ImGui::GetFontSize() * 50.0f); for (int m = 0; m < IM_ARRAYSIZE(policies); m++) { @@ -3858,7 +3926,7 @@ static void ShowDemoWindowTables() } // [Method 2] Using TableNextColumn() called multiple times, instead of using a for loop + TableSetColumnIndex(). - // This is generally more convenient when you have code manually submitting the contents of each columns. + // This is generally more convenient when you have code manually submitting the contents of each column. HelpMarker("Using TableNextRow() + calling TableNextColumn() _before_ each cell, manually."); if (ImGui::BeginTable("table2", 3)) { @@ -3876,10 +3944,10 @@ static void ShowDemoWindowTables() } // [Method 3] We call TableNextColumn() _before_ each cell. We never call TableNextRow(), - // as TableNextColumn() will automatically wrap around and create new roes as needed. + // as TableNextColumn() will automatically wrap around and create new rows as needed. // This is generally more convenient when your cells all contains the same type of data. HelpMarker( - "Only using TableNextColumn(), which tends to be convenient for tables where every cells contains the same type of contents.\n" + "Only using TableNextColumn(), which tends to be convenient for tables where every cell contains the same type of contents.\n" "This is also more similar to the old NextColumn() function of the Columns API, and provided to facilitate the Columns->Tables API transition."); if (ImGui::BeginTable("table3", 3)) { @@ -3931,7 +3999,7 @@ static void ShowDemoWindowTables() ImGui::SameLine(); ImGui::RadioButton("Text", &contents_type, CT_Text); ImGui::SameLine(); ImGui::RadioButton("FillButton", &contents_type, CT_FillButton); ImGui::Checkbox("Display headers", &display_headers); - ImGui::CheckboxFlags("ImGuiTableFlags_NoBordersInBody", &flags, ImGuiTableFlags_NoBordersInBody); ImGui::SameLine(); HelpMarker("Disable vertical borders in columns Body (borders will always appears in Headers"); + ImGui::CheckboxFlags("ImGuiTableFlags_NoBordersInBody", &flags, ImGuiTableFlags_NoBordersInBody); ImGui::SameLine(); HelpMarker("Disable vertical borders in columns Body (borders will always appear in Headers"); PopStyleCompact(); if (ImGui::BeginTable("table1", 3, flags)) @@ -3970,8 +4038,8 @@ static void ShowDemoWindowTables() IMGUI_DEMO_MARKER("Tables/Resizable, stretch"); if (ImGui::TreeNode("Resizable, stretch")) { - // By default, if we don't enable ScrollX the sizing policy for each columns is "Stretch" - // Each columns maintain a sizing weight, and they will occupy all available width. + // By default, if we don't enable ScrollX the sizing policy for each column is "Stretch" + // All columns maintain a sizing weight, and they will occupy all available width. static ImGuiTableFlags flags = ImGuiTableFlags_SizingStretchSame | ImGuiTableFlags_Resizable | ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersV | ImGuiTableFlags_ContextMenuInBody; PushStyleCompact(); ImGui::CheckboxFlags("ImGuiTableFlags_Resizable", &flags, ImGuiTableFlags_Resizable); @@ -4093,7 +4161,7 @@ static void ShowDemoWindowTables() ImGui::CheckboxFlags("ImGuiTableFlags_Reorderable", &flags, ImGuiTableFlags_Reorderable); ImGui::CheckboxFlags("ImGuiTableFlags_Hideable", &flags, ImGuiTableFlags_Hideable); ImGui::CheckboxFlags("ImGuiTableFlags_NoBordersInBody", &flags, ImGuiTableFlags_NoBordersInBody); - ImGui::CheckboxFlags("ImGuiTableFlags_NoBordersInBodyUntilResize", &flags, ImGuiTableFlags_NoBordersInBodyUntilResize); ImGui::SameLine(); HelpMarker("Disable vertical borders in columns Body until hovered for resize (borders will always appears in Headers)"); + ImGui::CheckboxFlags("ImGuiTableFlags_NoBordersInBodyUntilResize", &flags, ImGuiTableFlags_NoBordersInBodyUntilResize); ImGui::SameLine(); HelpMarker("Disable vertical borders in columns Body until hovered for resize (borders will always appear in Headers)"); PopStyleCompact(); if (ImGui::BeginTable("table1", 3, flags)) @@ -4151,7 +4219,7 @@ static void ShowDemoWindowTables() "- any form of row selection\n" "Because of this, activating BorderOuterV sets the default to PadOuterX. Using PadOuterX or NoPadOuterX you can override the default.\n\n" "Actual padding values are using style.CellPadding.\n\n" - "In this demo we don't show horizontal borders to emphasis how they don't affect default horizontal padding."); + "In this demo we don't show horizontal borders to emphasize how they don't affect default horizontal padding."); static ImGuiTableFlags flags1 = ImGuiTableFlags_BordersV; PushStyleCompact(); @@ -4620,7 +4688,7 @@ static void ShowDemoWindowTables() IMGUI_DEMO_MARKER("Tables/Nested tables"); if (ImGui::TreeNode("Nested tables")) { - HelpMarker("This demonstrate embedding a table into another table cell."); + HelpMarker("This demonstrates embedding a table into another table cell."); if (ImGui::BeginTable("table_nested1", 2, ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable)) { @@ -4665,7 +4733,7 @@ static void ShowDemoWindowTables() IMGUI_DEMO_MARKER("Tables/Row height"); if (ImGui::TreeNode("Row height")) { - HelpMarker("You can pass a 'min_row_height' to TableNextRow().\n\nRows are padded with 'style.CellPadding.y' on top and bottom, so effectively the minimum row height will always be >= 'style.CellPadding.y * 2.0f'.\n\nWe cannot honor a _maximum_ row height as that would requires a unique clipping rectangle per row."); + HelpMarker("You can pass a 'min_row_height' to TableNextRow().\n\nRows are padded with 'style.CellPadding.y' on top and bottom, so effectively the minimum row height will always be >= 'style.CellPadding.y * 2.0f'.\n\nWe cannot honor a _maximum_ row height as that would require a unique clipping rectangle per row."); if (ImGui::BeginTable("table_row_height", 1, ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersInnerV)) { for (int row = 0; row < 10; row++) @@ -4914,7 +4982,7 @@ static void ShowDemoWindowTables() ImGui::TableSetColumnIndex(1); ImGui::SliderFloat("float1", &dummy_f, 0.0f, 1.0f); ImGui::TableSetColumnIndex(2); - ImGui::SliderFloat("float2", &dummy_f, 0.0f, 1.0f); + ImGui::SliderFloat("##float2", &dummy_f, 0.0f, 1.0f); // No visible label since right-aligned ImGui::PopID(); } ImGui::EndTable(); @@ -5084,18 +5152,23 @@ static void ShowDemoWindowTables() if (ImGui::TreeNode("Synced instances")) { HelpMarker("Multiple tables with the same identifier will share their settings, width, visibility, order etc."); + + static ImGuiTableFlags flags = ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable | ImGuiTableFlags_Borders | ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_NoSavedSettings; + ImGui::CheckboxFlags("ImGuiTableFlags_ScrollY", &flags, ImGuiTableFlags_ScrollY); + ImGui::CheckboxFlags("ImGuiTableFlags_SizingFixedFit", &flags, ImGuiTableFlags_SizingFixedFit); for (int n = 0; n < 3; n++) { char buf[32]; sprintf(buf, "Synced Table %d", n); bool open = ImGui::CollapsingHeader(buf, ImGuiTreeNodeFlags_DefaultOpen); - if (open && ImGui::BeginTable("Table", 3, ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable | ImGuiTableFlags_Borders | ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_NoSavedSettings)) + if (open && ImGui::BeginTable("Table", 3, flags, ImVec2(0.0f, ImGui::GetTextLineHeightWithSpacing() * 5))) { ImGui::TableSetupColumn("One"); ImGui::TableSetupColumn("Two"); ImGui::TableSetupColumn("Three"); ImGui::TableHeadersRow(); - for (int cell = 0; cell < 9; cell++) + const int cell_count = (n == 1) ? 27 : 9; // Make second table have a scrollbar to verify that additional decoration is not affecting column positions. + for (int cell = 0; cell < cell_count; cell++) { ImGui::TableNextColumn(); ImGui::Text("this cell %d", cell); @@ -5227,7 +5300,7 @@ static void ShowDemoWindowTables() static bool show_headers = true; static bool show_wrapped_text = false; //static ImGuiTextFilter filter; - //ImGui::SetNextItemOpen(true, ImGuiCond_Once); // FIXME-TABLE: Enabling this results in initial clipped first pass on table which tend to affects column sizing + //ImGui::SetNextItemOpen(true, ImGuiCond_Once); // FIXME-TABLE: Enabling this results in initial clipped first pass on table which tend to affect column sizing if (ImGui::TreeNode("Options")) { // Make the UI compact because there are so many fields @@ -5254,8 +5327,8 @@ static void ShowDemoWindowTables() ImGui::CheckboxFlags("ImGuiTableFlags_BordersH", &flags, ImGuiTableFlags_BordersH); ImGui::CheckboxFlags("ImGuiTableFlags_BordersOuterH", &flags, ImGuiTableFlags_BordersOuterH); ImGui::CheckboxFlags("ImGuiTableFlags_BordersInnerH", &flags, ImGuiTableFlags_BordersInnerH); - ImGui::CheckboxFlags("ImGuiTableFlags_NoBordersInBody", &flags, ImGuiTableFlags_NoBordersInBody); ImGui::SameLine(); HelpMarker("Disable vertical borders in columns Body (borders will always appears in Headers"); - ImGui::CheckboxFlags("ImGuiTableFlags_NoBordersInBodyUntilResize", &flags, ImGuiTableFlags_NoBordersInBodyUntilResize); ImGui::SameLine(); HelpMarker("Disable vertical borders in columns Body until hovered for resize (borders will always appears in Headers)"); + ImGui::CheckboxFlags("ImGuiTableFlags_NoBordersInBody", &flags, ImGuiTableFlags_NoBordersInBody); ImGui::SameLine(); HelpMarker("Disable vertical borders in columns Body (borders will always appear in Headers"); + ImGui::CheckboxFlags("ImGuiTableFlags_NoBordersInBodyUntilResize", &flags, ImGuiTableFlags_NoBordersInBodyUntilResize); ImGui::SameLine(); HelpMarker("Disable vertical borders in columns Body until hovered for resize (borders will always appear in Headers)"); ImGui::TreePop(); } @@ -5318,7 +5391,7 @@ static void ShowDemoWindowTables() HelpMarker("If scrolling is disabled (ScrollX and ScrollY not set):\n" "- The table is output directly in the parent window.\n" "- OuterSize.x < 0.0f will right-align the table.\n" - "- OuterSize.x = 0.0f will narrow fit the table unless there are any Stretch column.\n" + "- OuterSize.x = 0.0f will narrow fit the table unless there are any Stretch columns.\n" "- OuterSize.y then becomes the minimum size for the table, which will extend vertically if there are more rows (unless NoHostExtendY is set)."); // From a user point of view we will tend to use 'inner_width' differently depending on whether our table is embedding scrolling. @@ -5723,148 +5796,121 @@ static void ShowDemoWindowColumns() ImGui::TreePop(); } -namespace ImGui { extern ImGuiKeyData* GetKeyData(ImGuiKey key); } - -static void ShowDemoWindowMisc() +static void ShowDemoWindowInputs() { - IMGUI_DEMO_MARKER("Filtering"); - if (ImGui::CollapsingHeader("Filtering")) - { - // Helper class to easy setup a text filter. - // You may want to implement a more feature-full filtering scheme in your own application. - static ImGuiTextFilter filter; - ImGui::Text("Filter usage:\n" - " \"\" display all lines\n" - " \"xxx\" display lines containing \"xxx\"\n" - " \"xxx,yyy\" display lines containing \"xxx\" or \"yyy\"\n" - " \"-xxx\" hide lines containing \"xxx\""); - filter.Draw(); - const char* lines[] = { "aaa1.c", "bbb1.c", "ccc1.c", "aaa2.cpp", "bbb2.cpp", "ccc2.cpp", "abc.h", "hello, world" }; - for (int i = 0; i < IM_ARRAYSIZE(lines); i++) - if (filter.PassFilter(lines[i])) - ImGui::BulletText("%s", lines[i]); - } - - IMGUI_DEMO_MARKER("Inputs, Navigation & Focus"); - if (ImGui::CollapsingHeader("Inputs, Navigation & Focus")) + IMGUI_DEMO_MARKER("Inputs & Focus"); + if (ImGui::CollapsingHeader("Inputs & Focus")) { ImGuiIO& io = ImGui::GetIO(); - // Display ImGuiIO output flags - IMGUI_DEMO_MARKER("Inputs, Navigation & Focus/Output"); + // Display inputs submitted to ImGuiIO + IMGUI_DEMO_MARKER("Inputs & Focus/Inputs"); ImGui::SetNextItemOpen(true, ImGuiCond_Once); - if (ImGui::TreeNode("Output")) + if (ImGui::TreeNode("Inputs")) { + HelpMarker( + "This is a simplified view. See more detailed input state:\n" + "- in 'Tools->Metrics/Debugger->Inputs'.\n" + "- in 'Tools->Debug Log->IO'."); + if (ImGui::IsMousePosValid()) + ImGui::Text("Mouse pos: (%g, %g)", io.MousePos.x, io.MousePos.y); + else + ImGui::Text("Mouse pos: "); + ImGui::Text("Mouse delta: (%g, %g)", io.MouseDelta.x, io.MouseDelta.y); + ImGui::Text("Mouse down:"); + for (int i = 0; i < IM_ARRAYSIZE(io.MouseDown); i++) if (ImGui::IsMouseDown(i)) { ImGui::SameLine(); ImGui::Text("b%d (%.02f secs)", i, io.MouseDownDuration[i]); } + ImGui::Text("Mouse wheel: %.1f", io.MouseWheel); + + // We iterate both legacy native range and named ImGuiKey ranges, which is a little odd but this allows displaying the data for old/new backends. + // User code should never have to go through such hoops! You can generally iterate between ImGuiKey_NamedKey_BEGIN and ImGuiKey_NamedKey_END. +#ifdef IMGUI_DISABLE_OBSOLETE_KEYIO + struct funcs { static bool IsLegacyNativeDupe(ImGuiKey) { return false; } }; + ImGuiKey start_key = ImGuiKey_NamedKey_BEGIN; +#else + struct funcs { static bool IsLegacyNativeDupe(ImGuiKey key) { return key < 512 && ImGui::GetIO().KeyMap[key] != -1; } }; // Hide Native<>ImGuiKey duplicates when both exists in the array + ImGuiKey start_key = (ImGuiKey)0; +#endif + ImGui::Text("Keys down:"); for (ImGuiKey key = start_key; key < ImGuiKey_NamedKey_END; key = (ImGuiKey)(key + 1)) { if (funcs::IsLegacyNativeDupe(key) || !ImGui::IsKeyDown(key)) continue; ImGui::SameLine(); ImGui::Text((key < ImGuiKey_NamedKey_BEGIN) ? "\"%s\"" : "\"%s\" %d", ImGui::GetKeyName(key), key); } + ImGui::Text("Keys mods: %s%s%s%s", io.KeyCtrl ? "CTRL " : "", io.KeyShift ? "SHIFT " : "", io.KeyAlt ? "ALT " : "", io.KeySuper ? "SUPER " : ""); + ImGui::Text("Chars queue:"); for (int i = 0; i < io.InputQueueCharacters.Size; i++) { ImWchar c = io.InputQueueCharacters[i]; ImGui::SameLine(); ImGui::Text("\'%c\' (0x%04X)", (c > ' ' && c <= 255) ? (char)c : '?', c); } // FIXME: We should convert 'c' to UTF-8 here but the functions are not public. + + ImGui::TreePop(); + } + + // Display ImGuiIO output flags + IMGUI_DEMO_MARKER("Inputs & Focus/Outputs"); + ImGui::SetNextItemOpen(true, ImGuiCond_Once); + if (ImGui::TreeNode("Outputs")) + { + HelpMarker( + "The value of io.WantCaptureMouse and io.WantCaptureKeyboard are normally set by Dear ImGui " + "to instruct your application of how to route inputs. Typically, when a value is true, it means " + "Dear ImGui wants the corresponding inputs and we expect the underlying application to ignore them.\n\n" + "The most typical case is: when hovering a window, Dear ImGui set io.WantCaptureMouse to true, " + "and underlying application should ignore mouse inputs (in practice there are many and more subtle " + "rules leading to how those flags are set)."); ImGui::Text("io.WantCaptureMouse: %d", io.WantCaptureMouse); ImGui::Text("io.WantCaptureMouseUnlessPopupClose: %d", io.WantCaptureMouseUnlessPopupClose); ImGui::Text("io.WantCaptureKeyboard: %d", io.WantCaptureKeyboard); ImGui::Text("io.WantTextInput: %d", io.WantTextInput); ImGui::Text("io.WantSetMousePos: %d", io.WantSetMousePos); ImGui::Text("io.NavActive: %d, io.NavVisible: %d", io.NavActive, io.NavVisible); - ImGui::TreePop(); - } - // Display Mouse state - IMGUI_DEMO_MARKER("Inputs, Navigation & Focus/Mouse State"); - if (ImGui::TreeNode("Mouse State")) - { - if (ImGui::IsMousePosValid()) - ImGui::Text("Mouse pos: (%g, %g)", io.MousePos.x, io.MousePos.y); - else - ImGui::Text("Mouse pos: "); - ImGui::Text("Mouse delta: (%g, %g)", io.MouseDelta.x, io.MouseDelta.y); - - int count = IM_ARRAYSIZE(io.MouseDown); - ImGui::Text("Mouse down:"); for (int i = 0; i < count; i++) if (ImGui::IsMouseDown(i)) { ImGui::SameLine(); ImGui::Text("b%d (%.02f secs)", i, io.MouseDownDuration[i]); } - ImGui::Text("Mouse clicked:"); for (int i = 0; i < count; i++) if (ImGui::IsMouseClicked(i)) { ImGui::SameLine(); ImGui::Text("b%d (%d)", i, ImGui::GetMouseClickedCount(i)); } - ImGui::Text("Mouse released:"); for (int i = 0; i < count; i++) if (ImGui::IsMouseReleased(i)) { ImGui::SameLine(); ImGui::Text("b%d", i); } - ImGui::Text("Mouse wheel: %.1f", io.MouseWheel); - ImGui::Text("Pen Pressure: %.1f", io.PenPressure); // Note: currently unused - ImGui::TreePop(); - } - - // Display Keyboard/Mouse state - IMGUI_DEMO_MARKER("Inputs, Navigation & Focus/Keyboard, Gamepad & Navigation State"); - if (ImGui::TreeNode("Keyboard, Gamepad & Navigation State")) - { - // We iterate both legacy native range and named ImGuiKey ranges, which is a little odd but this allow displaying the data for old/new backends. - // User code should never have to go through such hoops: old code may use native keycodes, new code may use ImGuiKey codes. -#ifdef IMGUI_DISABLE_OBSOLETE_KEYIO - struct funcs { static bool IsLegacyNativeDupe(ImGuiKey) { return false; } }; - const ImGuiKey key_first = ImGuiKey_NamedKey_BEGIN; -#else - struct funcs { static bool IsLegacyNativeDupe(ImGuiKey key) { return key < 512 && ImGui::GetIO().KeyMap[key] != -1; } }; // Hide Native<>ImGuiKey duplicates when both exists in the array - const ImGuiKey key_first = 0; - //ImGui::Text("Legacy raw:"); for (ImGuiKey key = key_first; key < ImGuiKey_COUNT; key++) { if (io.KeysDown[key]) { ImGui::SameLine(); ImGui::Text("\"%s\" %d", ImGui::GetKeyName(key), key); } } -#endif - ImGui::Text("Keys down:"); for (ImGuiKey key = key_first; key < ImGuiKey_COUNT; key++) { if (funcs::IsLegacyNativeDupe(key)) continue; if (ImGui::IsKeyDown(key)) { ImGui::SameLine(); ImGui::Text("\"%s\" %d (%.02f secs)", ImGui::GetKeyName(key), key, ImGui::GetKeyData(key)->DownDuration); } } - ImGui::Text("Keys pressed:"); for (ImGuiKey key = key_first; key < ImGuiKey_COUNT; key++) { if (funcs::IsLegacyNativeDupe(key)) continue; if (ImGui::IsKeyPressed(key)) { ImGui::SameLine(); ImGui::Text("\"%s\" %d", ImGui::GetKeyName(key), key); } } - ImGui::Text("Keys released:"); for (ImGuiKey key = key_first; key < ImGuiKey_COUNT; key++) { if (funcs::IsLegacyNativeDupe(key)) continue; if (ImGui::IsKeyReleased(key)) { ImGui::SameLine(); ImGui::Text("\"%s\" %d", ImGui::GetKeyName(key), key); } } - ImGui::Text("Keys mods: %s%s%s%s", io.KeyCtrl ? "CTRL " : "", io.KeyShift ? "SHIFT " : "", io.KeyAlt ? "ALT " : "", io.KeySuper ? "SUPER " : ""); - ImGui::Text("Chars queue:"); for (int i = 0; i < io.InputQueueCharacters.Size; i++) { ImWchar c = io.InputQueueCharacters[i]; ImGui::SameLine(); ImGui::Text("\'%c\' (0x%04X)", (c > ' ' && c <= 255) ? (char)c : '?', c); } // FIXME: We should convert 'c' to UTF-8 here but the functions are not public. - ImGui::Text("NavInputs down:"); for (int i = 0; i < IM_ARRAYSIZE(io.NavInputs); i++) if (io.NavInputs[i] > 0.0f) { ImGui::SameLine(); ImGui::Text("[%d] %.2f (%.02f secs)", i, io.NavInputs[i], io.NavInputsDownDuration[i]); } - ImGui::Text("NavInputs pressed:"); for (int i = 0; i < IM_ARRAYSIZE(io.NavInputs); i++) if (io.NavInputsDownDuration[i] == 0.0f) { ImGui::SameLine(); ImGui::Text("[%d]", i); } - - // Draw an arbitrary US keyboard layout to visualize translated keys + IMGUI_DEMO_MARKER("Inputs & Focus/Outputs/WantCapture override"); + if (ImGui::TreeNode("WantCapture override")) { - const ImVec2 key_size = ImVec2(35.0f, 35.0f); - const float key_rounding = 3.0f; - const ImVec2 key_face_size = ImVec2(25.0f, 25.0f); - const ImVec2 key_face_pos = ImVec2(5.0f, 3.0f); - const float key_face_rounding = 2.0f; - const ImVec2 key_label_pos = ImVec2(7.0f, 4.0f); - const ImVec2 key_step = ImVec2(key_size.x - 1.0f, key_size.y - 1.0f); - const float key_row_offset = 9.0f; + HelpMarker( + "Hovering the colored canvas will override io.WantCaptureXXX fields.\n" + "Notice how normally (when set to none), the value of io.WantCaptureKeyboard would be false when hovering and true when clicking."); + static int capture_override_mouse = -1; + static int capture_override_keyboard = -1; + const char* capture_override_desc[] = { "None", "Set to false", "Set to true" }; + ImGui::SetNextItemWidth(ImGui::GetFontSize() * 15); + ImGui::SliderInt("SetNextFrameWantCaptureMouse() on hover", &capture_override_mouse, -1, +1, capture_override_desc[capture_override_mouse + 1], ImGuiSliderFlags_AlwaysClamp); + ImGui::SetNextItemWidth(ImGui::GetFontSize() * 15); + ImGui::SliderInt("SetNextFrameWantCaptureKeyboard() on hover", &capture_override_keyboard, -1, +1, capture_override_desc[capture_override_keyboard + 1], ImGuiSliderFlags_AlwaysClamp); - ImVec2 board_min = ImGui::GetCursorScreenPos(); - ImVec2 board_max = ImVec2(board_min.x + 3 * key_step.x + 2 * key_row_offset + 10.0f, board_min.y + 3 * key_step.y + 10.0f); - ImVec2 start_pos = ImVec2(board_min.x + 5.0f - key_step.x, board_min.y); + ImGui::ColorButton("##panel", ImVec4(0.7f, 0.1f, 0.7f, 1.0f), ImGuiColorEditFlags_NoTooltip | ImGuiColorEditFlags_NoDragDrop, ImVec2(128.0f, 96.0f)); // Dummy item + if (ImGui::IsItemHovered() && capture_override_mouse != -1) + ImGui::SetNextFrameWantCaptureMouse(capture_override_mouse == 1); + if (ImGui::IsItemHovered() && capture_override_keyboard != -1) + ImGui::SetNextFrameWantCaptureKeyboard(capture_override_keyboard == 1); - struct KeyLayoutData { int Row, Col; const char* Label; ImGuiKey Key; }; - const KeyLayoutData keys_to_display[] = - { - { 0, 0, "", ImGuiKey_Tab }, { 0, 1, "Q", ImGuiKey_Q }, { 0, 2, "W", ImGuiKey_W }, { 0, 3, "E", ImGuiKey_E }, { 0, 4, "R", ImGuiKey_R }, - { 1, 0, "", ImGuiKey_CapsLock }, { 1, 1, "A", ImGuiKey_A }, { 1, 2, "S", ImGuiKey_S }, { 1, 3, "D", ImGuiKey_D }, { 1, 4, "F", ImGuiKey_F }, - { 2, 0, "", ImGuiKey_LeftShift },{ 2, 1, "Z", ImGuiKey_Z }, { 2, 2, "X", ImGuiKey_X }, { 2, 3, "C", ImGuiKey_C }, { 2, 4, "V", ImGuiKey_V } - }; - - ImDrawList* draw_list = ImGui::GetWindowDrawList(); - draw_list->PushClipRect(board_min, board_max, true); - for (int n = 0; n < IM_ARRAYSIZE(keys_to_display); n++) - { - const KeyLayoutData* key_data = &keys_to_display[n]; - ImVec2 key_min = ImVec2(start_pos.x + key_data->Col * key_step.x + key_data->Row * key_row_offset, start_pos.y + key_data->Row * key_step.y); - ImVec2 key_max = ImVec2(key_min.x + key_size.x, key_min.y + key_size.y); - draw_list->AddRectFilled(key_min, key_max, IM_COL32(204, 204, 204, 255), key_rounding); - draw_list->AddRect(key_min, key_max, IM_COL32(24, 24, 24, 255), key_rounding); - ImVec2 face_min = ImVec2(key_min.x + key_face_pos.x, key_min.y + key_face_pos.y); - ImVec2 face_max = ImVec2(face_min.x + key_face_size.x, face_min.y + key_face_size.y); - draw_list->AddRect(face_min, face_max, IM_COL32(193, 193, 193, 255), key_face_rounding, ImDrawFlags_None, 2.0f); - draw_list->AddRectFilled(face_min, face_max, IM_COL32(252, 252, 252, 255), key_face_rounding); - ImVec2 label_min = ImVec2(key_min.x + key_label_pos.x, key_min.y + key_label_pos.y); - draw_list->AddText(label_min, IM_COL32(64, 64, 64, 255), key_data->Label); - if (ImGui::IsKeyDown(key_data->Key)) - draw_list->AddRectFilled(key_min, key_max, IM_COL32(255, 0, 0, 128), key_rounding); - } - draw_list->PopClipRect(); - ImGui::Dummy(ImVec2(board_max.x - board_min.x, board_max.y - board_min.y)); + ImGui::TreePop(); } ImGui::TreePop(); } - if (ImGui::TreeNode("Capture override")) + // Display mouse cursors + IMGUI_DEMO_MARKER("Inputs & Focus/Mouse Cursors"); + if (ImGui::TreeNode("Mouse Cursors")) { - ImGui::Button("Hovering me sets the\nkeyboard capture flag"); - if (ImGui::IsItemHovered()) - ImGui::CaptureKeyboardFromApp(true); - ImGui::SameLine(); - ImGui::Button("Holding me clears the\nthe keyboard capture flag"); - if (ImGui::IsItemActive()) - ImGui::CaptureKeyboardFromApp(false); + const char* mouse_cursors_names[] = { "Arrow", "TextInput", "ResizeAll", "ResizeNS", "ResizeEW", "ResizeNESW", "ResizeNWSE", "Hand", "NotAllowed" }; + IM_ASSERT(IM_ARRAYSIZE(mouse_cursors_names) == ImGuiMouseCursor_COUNT); + + ImGuiMouseCursor current = ImGui::GetMouseCursor(); + ImGui::Text("Current mouse cursor = %d: %s", current, mouse_cursors_names[current]); + ImGui::BeginDisabled(true); + ImGui::CheckboxFlags("io.BackendFlags: HasMouseCursors", &io.BackendFlags, ImGuiBackendFlags_HasMouseCursors); + ImGui::EndDisabled(); + + ImGui::Text("Hover to see mouse cursors:"); + ImGui::SameLine(); HelpMarker( + "Your application can render a different mouse cursor based on what ImGui::GetMouseCursor() returns. " + "If software cursor rendering (io.MouseDrawCursor) is set ImGui will draw the right cursor for you, " + "otherwise your backend needs to handle it."); + for (int i = 0; i < ImGuiMouseCursor_COUNT; i++) + { + char label[32]; + sprintf(label, "Mouse cursor %d: %s", i, mouse_cursors_names[i]); + ImGui::Bullet(); ImGui::Selectable(label, false); + if (ImGui::IsItemHovered()) + ImGui::SetMouseCursor(i); + } ImGui::TreePop(); } - IMGUI_DEMO_MARKER("Inputs, Navigation & Focus/Tabbing"); + IMGUI_DEMO_MARKER("Inputs & Focus/Tabbing"); if (ImGui::TreeNode("Tabbing")) { ImGui::Text("Use TAB/SHIFT+TAB to cycle through keyboard editable fields."); @@ -5872,15 +5918,15 @@ static void ShowDemoWindowMisc() ImGui::InputText("1", buf, IM_ARRAYSIZE(buf)); ImGui::InputText("2", buf, IM_ARRAYSIZE(buf)); ImGui::InputText("3", buf, IM_ARRAYSIZE(buf)); - ImGui::PushAllowKeyboardFocus(false); + ImGui::PushTabStop(false); ImGui::InputText("4 (tab skip)", buf, IM_ARRAYSIZE(buf)); ImGui::SameLine(); HelpMarker("Item won't be cycled through when using TAB or Shift+Tab."); - ImGui::PopAllowKeyboardFocus(); + ImGui::PopTabStop(); ImGui::InputText("5", buf, IM_ARRAYSIZE(buf)); ImGui::TreePop(); } - IMGUI_DEMO_MARKER("Inputs, Navigation & Focus/Focus from code"); + IMGUI_DEMO_MARKER("Inputs & Focus/Focus from code"); if (ImGui::TreeNode("Focus from code")) { bool focus_1 = ImGui::Button("Focus on 1"); ImGui::SameLine(); @@ -5897,12 +5943,12 @@ static void ShowDemoWindowMisc() ImGui::InputText("2", buf, IM_ARRAYSIZE(buf)); if (ImGui::IsItemActive()) has_focus = 2; - ImGui::PushAllowKeyboardFocus(false); + ImGui::PushTabStop(false); if (focus_3) ImGui::SetKeyboardFocusHere(); ImGui::InputText("3 (tab skip)", buf, IM_ARRAYSIZE(buf)); if (ImGui::IsItemActive()) has_focus = 3; ImGui::SameLine(); HelpMarker("Item won't be cycled through when using TAB or Shift+Tab."); - ImGui::PopAllowKeyboardFocus(); + ImGui::PopTabStop(); if (has_focus) ImGui::Text("Item with focus: %d", has_focus); @@ -5922,7 +5968,7 @@ static void ShowDemoWindowMisc() ImGui::TreePop(); } - IMGUI_DEMO_MARKER("Inputs, Navigation & Focus/Dragging"); + IMGUI_DEMO_MARKER("Inputs & Focus/Dragging"); if (ImGui::TreeNode("Dragging")) { ImGui::TextWrapped("You can use ImGui::GetMouseDragDelta(0) to query for the dragged amount on any widget."); @@ -5950,30 +5996,6 @@ static void ShowDemoWindowMisc() ImGui::Text("io.MouseDelta: (%.1f, %.1f)", mouse_delta.x, mouse_delta.y); ImGui::TreePop(); } - - IMGUI_DEMO_MARKER("Inputs, Navigation & Focus/Mouse cursors"); - if (ImGui::TreeNode("Mouse cursors")) - { - const char* mouse_cursors_names[] = { "Arrow", "TextInput", "ResizeAll", "ResizeNS", "ResizeEW", "ResizeNESW", "ResizeNWSE", "Hand", "NotAllowed" }; - IM_ASSERT(IM_ARRAYSIZE(mouse_cursors_names) == ImGuiMouseCursor_COUNT); - - ImGuiMouseCursor current = ImGui::GetMouseCursor(); - ImGui::Text("Current mouse cursor = %d: %s", current, mouse_cursors_names[current]); - ImGui::Text("Hover to see mouse cursors:"); - ImGui::SameLine(); HelpMarker( - "Your application can render a different mouse cursor based on what ImGui::GetMouseCursor() returns. " - "If software cursor rendering (io.MouseDrawCursor) is set ImGui will draw the right cursor for you, " - "otherwise your backend needs to handle it."); - for (int i = 0; i < ImGuiMouseCursor_COUNT; i++) - { - char label[32]; - sprintf(label, "Mouse cursor %d: %s", i, mouse_cursors_names[i]); - ImGui::Bullet(); ImGui::Selectable(label, false); - if (ImGui::IsItemHovered()) - ImGui::SetMouseCursor(i); - } - ImGui::TreePop(); - } } } @@ -6078,6 +6100,9 @@ void ImGui::ShowAboutWindow(bool* p_open) #ifdef __clang_version__ ImGui::Text("define: __clang_version__=%s", __clang_version__); #endif +#ifdef __EMSCRIPTEN__ + ImGui::Text("define: __EMSCRIPTEN__"); +#endif #ifdef IMGUI_HAS_VIEWPORT ImGui::Text("define: IMGUI_HAS_VIEWPORT"); #endif @@ -6247,7 +6272,7 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref) { if (ImGui::BeginTabItem("Sizes")) { - ImGui::Text("Main"); + ImGui::SeparatorText("Main"); ImGui::SliderFloat2("WindowPadding", (float*)&style.WindowPadding, 0.0f, 20.0f, "%.0f"); ImGui::SliderFloat2("FramePadding", (float*)&style.FramePadding, 0.0f, 20.0f, "%.0f"); ImGui::SliderFloat2("CellPadding", (float*)&style.CellPadding, 0.0f, 20.0f, "%.0f"); @@ -6257,22 +6282,24 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref) ImGui::SliderFloat("IndentSpacing", &style.IndentSpacing, 0.0f, 30.0f, "%.0f"); ImGui::SliderFloat("ScrollbarSize", &style.ScrollbarSize, 1.0f, 20.0f, "%.0f"); ImGui::SliderFloat("GrabMinSize", &style.GrabMinSize, 1.0f, 20.0f, "%.0f"); - ImGui::Text("Borders"); + + ImGui::SeparatorText("Borders"); ImGui::SliderFloat("WindowBorderSize", &style.WindowBorderSize, 0.0f, 1.0f, "%.0f"); ImGui::SliderFloat("ChildBorderSize", &style.ChildBorderSize, 0.0f, 1.0f, "%.0f"); ImGui::SliderFloat("PopupBorderSize", &style.PopupBorderSize, 0.0f, 1.0f, "%.0f"); ImGui::SliderFloat("FrameBorderSize", &style.FrameBorderSize, 0.0f, 1.0f, "%.0f"); ImGui::SliderFloat("TabBorderSize", &style.TabBorderSize, 0.0f, 1.0f, "%.0f"); - ImGui::Text("Rounding"); + + ImGui::SeparatorText("Rounding"); ImGui::SliderFloat("WindowRounding", &style.WindowRounding, 0.0f, 12.0f, "%.0f"); ImGui::SliderFloat("ChildRounding", &style.ChildRounding, 0.0f, 12.0f, "%.0f"); ImGui::SliderFloat("FrameRounding", &style.FrameRounding, 0.0f, 12.0f, "%.0f"); ImGui::SliderFloat("PopupRounding", &style.PopupRounding, 0.0f, 12.0f, "%.0f"); ImGui::SliderFloat("ScrollbarRounding", &style.ScrollbarRounding, 0.0f, 12.0f, "%.0f"); ImGui::SliderFloat("GrabRounding", &style.GrabRounding, 0.0f, 12.0f, "%.0f"); - ImGui::SliderFloat("LogSliderDeadzone", &style.LogSliderDeadzone, 0.0f, 12.0f, "%.0f"); ImGui::SliderFloat("TabRounding", &style.TabRounding, 0.0f, 12.0f, "%.0f"); - ImGui::Text("Alignment"); + + ImGui::SeparatorText("Widgets"); ImGui::SliderFloat2("WindowTitleAlign", (float*)&style.WindowTitleAlign, 0.0f, 1.0f, "%.2f"); int window_menu_button_position = style.WindowMenuButtonPosition + 1; if (ImGui::Combo("WindowMenuButtonPosition", (int*)&window_menu_button_position, "None\0Left\0Right\0")) @@ -6282,9 +6309,13 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref) ImGui::SameLine(); HelpMarker("Alignment applies when a button is larger than its text content."); ImGui::SliderFloat2("SelectableTextAlign", (float*)&style.SelectableTextAlign, 0.0f, 1.0f, "%.2f"); ImGui::SameLine(); HelpMarker("Alignment applies when a selectable is larger than its text content."); - ImGui::Text("Safe Area Padding"); - ImGui::SameLine(); HelpMarker("Adjust if you cannot see the edges of your screen (e.g. on a TV where scaling has not been configured)."); - ImGui::SliderFloat2("DisplaySafeAreaPadding", (float*)&style.DisplaySafeAreaPadding, 0.0f, 30.0f, "%.0f"); + ImGui::SliderFloat("SeparatorTextBorderSize", &style.SeparatorTextBorderSize, 0.0f, 10.0f, "%.0f"); + ImGui::SliderFloat2("SeparatorTextAlign", (float*)&style.SeparatorTextAlign, 0.0f, 1.0f, "%.2f"); + ImGui::SliderFloat2("SeparatorTextPadding", (float*)&style.SeparatorTextPadding, 0.0f, 40.0f, "%0.f"); + ImGui::SliderFloat("LogSliderDeadzone", &style.LogSliderDeadzone, 0.0f, 12.0f, "%.0f"); + + ImGui::SeparatorText("Misc"); + ImGui::SliderFloat2("DisplaySafeAreaPadding", (float*)&style.DisplaySafeAreaPadding, 0.0f, 30.0f, "%.0f"); ImGui::SameLine(); HelpMarker("Adjust if you cannot see the edges of your screen (e.g. on a TV where scaling has not been configured)."); ImGui::EndTabItem(); } @@ -6394,10 +6425,11 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref) // When editing the "Circle Segment Max Error" value, draw a preview of its effect on auto-tessellated circles. ImGui::DragFloat("Circle Tessellation Max Error", &style.CircleTessellationMaxError , 0.005f, 0.10f, 5.0f, "%.2f", ImGuiSliderFlags_AlwaysClamp); - if (ImGui::IsItemActive()) - { + const bool show_samples = ImGui::IsItemActive(); + if (show_samples) ImGui::SetNextWindowPos(ImGui::GetCursorScreenPos()); - ImGui::BeginTooltip(); + if (show_samples && ImGui::BeginTooltip()) + { ImGui::TextUnformatted("(R = radius, N = number of segments)"); ImGui::Spacing(); ImDrawList* draw_list = ImGui::GetWindowDrawList(); @@ -6447,6 +6479,40 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref) ImGui::PopItemWidth(); } +//----------------------------------------------------------------------------- +// [SECTION] User Guide / ShowUserGuide() +//----------------------------------------------------------------------------- + +void ImGui::ShowUserGuide() +{ + ImGuiIO& io = ImGui::GetIO(); + ImGui::BulletText("Double-click on title bar to collapse window."); + ImGui::BulletText( + "Click and drag on lower corner to resize window\n" + "(double-click to auto fit window to its contents)."); + ImGui::BulletText("CTRL+Click on a slider or drag box to input value as text."); + ImGui::BulletText("TAB/SHIFT+TAB to cycle through keyboard editable fields."); + ImGui::BulletText("CTRL+Tab to select a window."); + if (io.FontAllowUserScaling) + ImGui::BulletText("CTRL+Mouse Wheel to zoom window contents."); + ImGui::BulletText("While inputing text:\n"); + ImGui::Indent(); + ImGui::BulletText("CTRL+Left/Right to word jump."); + ImGui::BulletText("CTRL+A or double-click to select all."); + ImGui::BulletText("CTRL+X/C/V to use clipboard cut/copy/paste."); + ImGui::BulletText("CTRL+Z,CTRL+Y to undo/redo."); + ImGui::BulletText("ESCAPE to revert."); + ImGui::Unindent(); + ImGui::BulletText("With keyboard navigation enabled:"); + ImGui::Indent(); + ImGui::BulletText("Arrow keys to navigate."); + ImGui::BulletText("Space to activate a widget."); + ImGui::BulletText("Return to input text into a widget."); + ImGui::BulletText("Escape to deactivate a widget, close popup, exit child window."); + ImGui::BulletText("Alt to jump to the menu layer of a window."); + ImGui::Unindent(); +} + //----------------------------------------------------------------------------- // [SECTION] Example App: Main Menu Bar / ShowExampleAppMainMenuBar() //----------------------------------------------------------------------------- @@ -6560,6 +6626,7 @@ static void ShowExampleMenuFile() IM_ASSERT(0); } if (ImGui::MenuItem("Checked", NULL, true)) {} + ImGui::Separator(); if (ImGui::MenuItem("Quit", "Alt+F4")) {} } @@ -6681,72 +6748,76 @@ struct ExampleAppConsole // Reserve enough left-over height for 1 separator + 1 input text const float footer_height_to_reserve = ImGui::GetStyle().ItemSpacing.y + ImGui::GetFrameHeightWithSpacing(); - ImGui::BeginChild("ScrollingRegion", ImVec2(0, -footer_height_to_reserve), false, ImGuiWindowFlags_HorizontalScrollbar); - if (ImGui::BeginPopupContextWindow()) + if (ImGui::BeginChild("ScrollingRegion", ImVec2(0, -footer_height_to_reserve), false, ImGuiWindowFlags_HorizontalScrollbar)) { - if (ImGui::Selectable("Clear")) ClearLog(); - ImGui::EndPopup(); + if (ImGui::BeginPopupContextWindow()) + { + if (ImGui::Selectable("Clear")) ClearLog(); + ImGui::EndPopup(); + } + + // Display every line as a separate entry so we can change their color or add custom widgets. + // If you only want raw text you can use ImGui::TextUnformatted(log.begin(), log.end()); + // NB- if you have thousands of entries this approach may be too inefficient and may require user-side clipping + // to only process visible items. The clipper will automatically measure the height of your first item and then + // "seek" to display only items in the visible area. + // To use the clipper we can replace your standard loop: + // for (int i = 0; i < Items.Size; i++) + // With: + // ImGuiListClipper clipper; + // clipper.Begin(Items.Size); + // while (clipper.Step()) + // for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) + // - That your items are evenly spaced (same height) + // - That you have cheap random access to your elements (you can access them given their index, + // without processing all the ones before) + // You cannot this code as-is if a filter is active because it breaks the 'cheap random-access' property. + // We would need random-access on the post-filtered list. + // A typical application wanting coarse clipping and filtering may want to pre-compute an array of indices + // or offsets of items that passed the filtering test, recomputing this array when user changes the filter, + // and appending newly elements as they are inserted. This is left as a task to the user until we can manage + // to improve this example code! + // If your items are of variable height: + // - Split them into same height items would be simpler and facilitate random-seeking into your list. + // - Consider using manual call to IsRectVisible() and skipping extraneous decoration from your items. + ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(4, 1)); // Tighten spacing + if (copy_to_clipboard) + ImGui::LogToClipboard(); + for (int i = 0; i < Items.Size; i++) + { + const char* item = Items[i]; + if (!Filter.PassFilter(item)) + continue; + + // Normally you would store more information in your item than just a string. + // (e.g. make Items[] an array of structure, store color/type etc.) + ImVec4 color; + bool has_color = false; + if (strstr(item, "[error]")) { color = ImVec4(1.0f, 0.4f, 0.4f, 1.0f); has_color = true; } + else if (strncmp(item, "# ", 2) == 0) { color = ImVec4(1.0f, 0.8f, 0.6f, 1.0f); has_color = true; } + if (has_color) + ImGui::PushStyleColor(ImGuiCol_Text, color); + ImGui::TextUnformatted(item); + if (has_color) + ImGui::PopStyleColor(); + } + if (copy_to_clipboard) + ImGui::LogFinish(); + + // Keep up at the bottom of the scroll region if we were already at the bottom at the beginning of the frame. + // Using a scrollbar or mouse-wheel will take away from the bottom edge. + if (ScrollToBottom || (AutoScroll && ImGui::GetScrollY() >= ImGui::GetScrollMaxY())) + ImGui::SetScrollHereY(1.0f); + ScrollToBottom = false; + + ImGui::PopStyleVar(); } - - // Display every line as a separate entry so we can change their color or add custom widgets. - // If you only want raw text you can use ImGui::TextUnformatted(log.begin(), log.end()); - // NB- if you have thousands of entries this approach may be too inefficient and may require user-side clipping - // to only process visible items. The clipper will automatically measure the height of your first item and then - // "seek" to display only items in the visible area. - // To use the clipper we can replace your standard loop: - // for (int i = 0; i < Items.Size; i++) - // With: - // ImGuiListClipper clipper; - // clipper.Begin(Items.Size); - // while (clipper.Step()) - // for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) - // - That your items are evenly spaced (same height) - // - That you have cheap random access to your elements (you can access them given their index, - // without processing all the ones before) - // You cannot this code as-is if a filter is active because it breaks the 'cheap random-access' property. - // We would need random-access on the post-filtered list. - // A typical application wanting coarse clipping and filtering may want to pre-compute an array of indices - // or offsets of items that passed the filtering test, recomputing this array when user changes the filter, - // and appending newly elements as they are inserted. This is left as a task to the user until we can manage - // to improve this example code! - // If your items are of variable height: - // - Split them into same height items would be simpler and facilitate random-seeking into your list. - // - Consider using manual call to IsRectVisible() and skipping extraneous decoration from your items. - ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(4, 1)); // Tighten spacing - if (copy_to_clipboard) - ImGui::LogToClipboard(); - for (int i = 0; i < Items.Size; i++) - { - const char* item = Items[i]; - if (!Filter.PassFilter(item)) - continue; - - // Normally you would store more information in your item than just a string. - // (e.g. make Items[] an array of structure, store color/type etc.) - ImVec4 color; - bool has_color = false; - if (strstr(item, "[error]")) { color = ImVec4(1.0f, 0.4f, 0.4f, 1.0f); has_color = true; } - else if (strncmp(item, "# ", 2) == 0) { color = ImVec4(1.0f, 0.8f, 0.6f, 1.0f); has_color = true; } - if (has_color) - ImGui::PushStyleColor(ImGuiCol_Text, color); - ImGui::TextUnformatted(item); - if (has_color) - ImGui::PopStyleColor(); - } - if (copy_to_clipboard) - ImGui::LogFinish(); - - if (ScrollToBottom || (AutoScroll && ImGui::GetScrollY() >= ImGui::GetScrollMaxY())) - ImGui::SetScrollHereY(1.0f); - ScrollToBottom = false; - - ImGui::PopStyleVar(); ImGui::EndChild(); ImGui::Separator(); // Command-line bool reclaim_focus = false; - ImGuiInputTextFlags input_text_flags = ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_CallbackCompletion | ImGuiInputTextFlags_CallbackHistory; + ImGuiInputTextFlags input_text_flags = ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_EscapeClearsAll | ImGuiInputTextFlags_CallbackCompletion | ImGuiInputTextFlags_CallbackHistory; if (ImGui::InputText("Input", InputBuf, IM_ARRAYSIZE(InputBuf), input_text_flags, &TextEditCallbackStub, (void*)this)) { char* s = InputBuf; @@ -6988,63 +7059,66 @@ struct ExampleAppLog Filter.Draw("Filter", -100.0f); ImGui::Separator(); - ImGui::BeginChild("scrolling", ImVec2(0, 0), false, ImGuiWindowFlags_HorizontalScrollbar); - if (clear) - Clear(); - if (copy) - ImGui::LogToClipboard(); + if (ImGui::BeginChild("scrolling", ImVec2(0, 0), false, ImGuiWindowFlags_HorizontalScrollbar)) + { + if (clear) + Clear(); + if (copy) + ImGui::LogToClipboard(); - ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0)); - const char* buf = Buf.begin(); - const char* buf_end = Buf.end(); - if (Filter.IsActive()) - { - // In this example we don't use the clipper when Filter is enabled. - // This is because we don't have a random access on the result on our filter. - // A real application processing logs with ten of thousands of entries may want to store the result of - // search/filter.. especially if the filtering function is not trivial (e.g. reg-exp). - for (int line_no = 0; line_no < LineOffsets.Size; line_no++) + ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0)); + const char* buf = Buf.begin(); + const char* buf_end = Buf.end(); + if (Filter.IsActive()) { - const char* line_start = buf + LineOffsets[line_no]; - const char* line_end = (line_no + 1 < LineOffsets.Size) ? (buf + LineOffsets[line_no + 1] - 1) : buf_end; - if (Filter.PassFilter(line_start, line_end)) - ImGui::TextUnformatted(line_start, line_end); - } - } - else - { - // The simplest and easy way to display the entire buffer: - // ImGui::TextUnformatted(buf_begin, buf_end); - // And it'll just work. TextUnformatted() has specialization for large blob of text and will fast-forward - // to skip non-visible lines. Here we instead demonstrate using the clipper to only process lines that are - // within the visible area. - // If you have tens of thousands of items and their processing cost is non-negligible, coarse clipping them - // on your side is recommended. Using ImGuiListClipper requires - // - A) random access into your data - // - B) items all being the same height, - // both of which we can handle since we an array pointing to the beginning of each line of text. - // When using the filter (in the block of code above) we don't have random access into the data to display - // anymore, which is why we don't use the clipper. Storing or skimming through the search result would make - // it possible (and would be recommended if you want to search through tens of thousands of entries). - ImGuiListClipper clipper; - clipper.Begin(LineOffsets.Size); - while (clipper.Step()) - { - for (int line_no = clipper.DisplayStart; line_no < clipper.DisplayEnd; line_no++) + // In this example we don't use the clipper when Filter is enabled. + // This is because we don't have random access to the result of our filter. + // A real application processing logs with ten of thousands of entries may want to store the result of + // search/filter.. especially if the filtering function is not trivial (e.g. reg-exp). + for (int line_no = 0; line_no < LineOffsets.Size; line_no++) { const char* line_start = buf + LineOffsets[line_no]; const char* line_end = (line_no + 1 < LineOffsets.Size) ? (buf + LineOffsets[line_no + 1] - 1) : buf_end; - ImGui::TextUnformatted(line_start, line_end); + if (Filter.PassFilter(line_start, line_end)) + ImGui::TextUnformatted(line_start, line_end); } } - clipper.End(); + else + { + // The simplest and easy way to display the entire buffer: + // ImGui::TextUnformatted(buf_begin, buf_end); + // And it'll just work. TextUnformatted() has specialization for large blob of text and will fast-forward + // to skip non-visible lines. Here we instead demonstrate using the clipper to only process lines that are + // within the visible area. + // If you have tens of thousands of items and their processing cost is non-negligible, coarse clipping them + // on your side is recommended. Using ImGuiListClipper requires + // - A) random access into your data + // - B) items all being the same height, + // both of which we can handle since we have an array pointing to the beginning of each line of text. + // When using the filter (in the block of code above) we don't have random access into the data to display + // anymore, which is why we don't use the clipper. Storing or skimming through the search result would make + // it possible (and would be recommended if you want to search through tens of thousands of entries). + ImGuiListClipper clipper; + clipper.Begin(LineOffsets.Size); + while (clipper.Step()) + { + for (int line_no = clipper.DisplayStart; line_no < clipper.DisplayEnd; line_no++) + { + const char* line_start = buf + LineOffsets[line_no]; + const char* line_end = (line_no + 1 < LineOffsets.Size) ? (buf + LineOffsets[line_no + 1] - 1) : buf_end; + ImGui::TextUnformatted(line_start, line_end); + } + } + clipper.End(); + } + ImGui::PopStyleVar(); + + // Keep up at the bottom of the scroll region if we were already at the bottom at the beginning of the frame. + // Using a scrollbar or mouse-wheel will take away from the bottom edge. + if (AutoScroll && ImGui::GetScrollY() >= ImGui::GetScrollMaxY()) + ImGui::SetScrollHereY(1.0f); } - ImGui::PopStyleVar(); - - if (AutoScroll && ImGui::GetScrollY() >= ImGui::GetScrollMaxY()) - ImGui::SetScrollHereY(1.0f); - ImGui::EndChild(); ImGui::End(); } @@ -7096,7 +7170,7 @@ static void ShowExampleAppLayout(bool* p_open) { if (ImGui::BeginMenu("File")) { - if (ImGui::MenuItem("Close")) *p_open = false; + if (ImGui::MenuItem("Close", "Ctrl+W")) { *p_open = false; } ImGui::EndMenu(); } ImGui::EndMenuBar(); @@ -7324,53 +7398,84 @@ static void ShowExampleAppAutoResize(bool* p_open) //----------------------------------------------------------------------------- // Demonstrate creating a window with custom resize constraints. +// Note that size constraints currently don't work on a docked window (when in 'docking' branch) static void ShowExampleAppConstrainedResize(bool* p_open) { struct CustomConstraints { // Helper functions to demonstrate programmatic constraints - static void Square(ImGuiSizeCallbackData* data) { data->DesiredSize.x = data->DesiredSize.y = IM_MAX(data->DesiredSize.x, data->DesiredSize.y); } - static void Step(ImGuiSizeCallbackData* data) { float step = (float)(int)(intptr_t)data->UserData; data->DesiredSize = ImVec2((int)(data->DesiredSize.x / step + 0.5f) * step, (int)(data->DesiredSize.y / step + 0.5f) * step); } + // FIXME: This doesn't take account of decoration size (e.g. title bar), library should make this easier. + static void AspectRatio(ImGuiSizeCallbackData* data) { float aspect_ratio = *(float*)data->UserData; data->DesiredSize.x = IM_MAX(data->CurrentSize.x, data->CurrentSize.y); data->DesiredSize.y = (float)(int)(data->DesiredSize.x / aspect_ratio); } + static void Square(ImGuiSizeCallbackData* data) { data->DesiredSize.x = data->DesiredSize.y = IM_MAX(data->CurrentSize.x, data->CurrentSize.y); } + static void Step(ImGuiSizeCallbackData* data) { float step = *(float*)data->UserData; data->DesiredSize = ImVec2((int)(data->CurrentSize.x / step + 0.5f) * step, (int)(data->CurrentSize.y / step + 0.5f) * step); } }; const char* test_desc[] = { + "Between 100x100 and 500x500", + "At least 100x100", "Resize vertical only", "Resize horizontal only", - "Width > 100, Height > 100", - "Width 400-500", - "Height 400-500", + "Width Between 400 and 500", + "Custom: Aspect Ratio 16:9", "Custom: Always Square", "Custom: Fixed Steps (100)", }; + // Options static bool auto_resize = false; - static int type = 0; + static bool window_padding = true; + static int type = 5; // Aspect Ratio static int display_lines = 10; - if (type == 0) ImGui::SetNextWindowSizeConstraints(ImVec2(-1, 0), ImVec2(-1, FLT_MAX)); // Vertical only - if (type == 1) ImGui::SetNextWindowSizeConstraints(ImVec2(0, -1), ImVec2(FLT_MAX, -1)); // Horizontal only - if (type == 2) ImGui::SetNextWindowSizeConstraints(ImVec2(100, 100), ImVec2(FLT_MAX, FLT_MAX)); // Width > 100, Height > 100 - if (type == 3) ImGui::SetNextWindowSizeConstraints(ImVec2(400, -1), ImVec2(500, -1)); // Width 400-500 - if (type == 4) ImGui::SetNextWindowSizeConstraints(ImVec2(-1, 400), ImVec2(-1, 500)); // Height 400-500 - if (type == 5) ImGui::SetNextWindowSizeConstraints(ImVec2(0, 0), ImVec2(FLT_MAX, FLT_MAX), CustomConstraints::Square); // Always Square - if (type == 6) ImGui::SetNextWindowSizeConstraints(ImVec2(0, 0), ImVec2(FLT_MAX, FLT_MAX), CustomConstraints::Step, (void*)(intptr_t)100); // Fixed Step - ImGuiWindowFlags flags = auto_resize ? ImGuiWindowFlags_AlwaysAutoResize : 0; - if (ImGui::Begin("Example: Constrained Resize", p_open, flags)) + // Submit constraint + float aspect_ratio = 16.0f / 9.0f; + float fixed_step = 100.0f; + if (type == 0) ImGui::SetNextWindowSizeConstraints(ImVec2(100, 100), ImVec2(500, 500)); // Between 100x100 and 500x500 + if (type == 1) ImGui::SetNextWindowSizeConstraints(ImVec2(100, 100), ImVec2(FLT_MAX, FLT_MAX)); // Width > 100, Height > 100 + if (type == 2) ImGui::SetNextWindowSizeConstraints(ImVec2(-1, 0), ImVec2(-1, FLT_MAX)); // Vertical only + if (type == 3) ImGui::SetNextWindowSizeConstraints(ImVec2(0, -1), ImVec2(FLT_MAX, -1)); // Horizontal only + if (type == 4) ImGui::SetNextWindowSizeConstraints(ImVec2(400, -1), ImVec2(500, -1)); // Width Between and 400 and 500 + if (type == 5) ImGui::SetNextWindowSizeConstraints(ImVec2(0, 0), ImVec2(FLT_MAX, FLT_MAX), CustomConstraints::AspectRatio, (void*)&aspect_ratio); // Aspect ratio + if (type == 6) ImGui::SetNextWindowSizeConstraints(ImVec2(0, 0), ImVec2(FLT_MAX, FLT_MAX), CustomConstraints::Square); // Always Square + if (type == 7) ImGui::SetNextWindowSizeConstraints(ImVec2(0, 0), ImVec2(FLT_MAX, FLT_MAX), CustomConstraints::Step, (void*)&fixed_step); // Fixed Step + + // Submit window + if (!window_padding) + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f)); + const ImGuiWindowFlags window_flags = auto_resize ? ImGuiWindowFlags_AlwaysAutoResize : 0; + const bool window_open = ImGui::Begin("Example: Constrained Resize", p_open, window_flags); + if (!window_padding) + ImGui::PopStyleVar(); + if (window_open) { IMGUI_DEMO_MARKER("Examples/Constrained Resizing window"); - if (ImGui::IsWindowDocked()) - ImGui::Text("Warning: Sizing Constraints won't work if the window is docked!"); - if (ImGui::Button("200x200")) { ImGui::SetWindowSize(ImVec2(200, 200)); } ImGui::SameLine(); - if (ImGui::Button("500x500")) { ImGui::SetWindowSize(ImVec2(500, 500)); } ImGui::SameLine(); - if (ImGui::Button("800x200")) { ImGui::SetWindowSize(ImVec2(800, 200)); } - ImGui::SetNextItemWidth(200); - ImGui::Combo("Constraint", &type, test_desc, IM_ARRAYSIZE(test_desc)); - ImGui::SetNextItemWidth(200); - ImGui::DragInt("Lines", &display_lines, 0.2f, 1, 100); - ImGui::Checkbox("Auto-resize", &auto_resize); - for (int i = 0; i < display_lines; i++) - ImGui::Text("%*sHello, sailor! Making this line long enough for the example.", i * 4, ""); + if (ImGui::GetIO().KeyShift) + { + // Display a dummy viewport (in your real app you would likely use ImageButton() to display a texture. + ImVec2 avail_size = ImGui::GetContentRegionAvail(); + ImVec2 pos = ImGui::GetCursorScreenPos(); + ImGui::ColorButton("viewport", ImVec4(0.5f, 0.2f, 0.5f, 1.0f), ImGuiColorEditFlags_NoTooltip | ImGuiColorEditFlags_NoDragDrop, avail_size); + ImGui::SetCursorScreenPos(ImVec2(pos.x + 10, pos.y + 10)); + ImGui::Text("%.2f x %.2f", avail_size.x, avail_size.y); + } + else + { + ImGui::Text("(Hold SHIFT to display a dummy viewport)"); + if (ImGui::IsWindowDocked()) + ImGui::Text("Warning: Sizing Constraints won't work if the window is docked!"); + if (ImGui::Button("Set 200x200")) { ImGui::SetWindowSize(ImVec2(200, 200)); } ImGui::SameLine(); + if (ImGui::Button("Set 500x500")) { ImGui::SetWindowSize(ImVec2(500, 500)); } ImGui::SameLine(); + if (ImGui::Button("Set 800x200")) { ImGui::SetWindowSize(ImVec2(800, 200)); } + ImGui::SetNextItemWidth(ImGui::GetFontSize() * 20); + ImGui::Combo("Constraint", &type, test_desc, IM_ARRAYSIZE(test_desc)); + ImGui::SetNextItemWidth(ImGui::GetFontSize() * 20); + ImGui::DragInt("Lines", &display_lines, 0.2f, 1, 100); + ImGui::Checkbox("Auto-resize", &auto_resize); + ImGui::Checkbox("Window padding", &window_padding); + for (int i = 0; i < display_lines; i++) + ImGui::Text("%*sHello, sailor! Making this line long enough for the example.", i * 4, ""); + } } ImGui::End(); } @@ -7383,29 +7488,35 @@ static void ShowExampleAppConstrainedResize(bool* p_open) // + a context-menu to choose which corner of the screen to use. static void ShowExampleAppSimpleOverlay(bool* p_open) { - static int corner = 0; + static int location = 0; ImGuiIO& io = ImGui::GetIO(); ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav; - if (corner != -1) + if (location >= 0) { const float PAD = 10.0f; const ImGuiViewport* viewport = ImGui::GetMainViewport(); ImVec2 work_pos = viewport->WorkPos; // Use work area to avoid menu-bar/task-bar, if any! ImVec2 work_size = viewport->WorkSize; ImVec2 window_pos, window_pos_pivot; - window_pos.x = (corner & 1) ? (work_pos.x + work_size.x - PAD) : (work_pos.x + PAD); - window_pos.y = (corner & 2) ? (work_pos.y + work_size.y - PAD) : (work_pos.y + PAD); - window_pos_pivot.x = (corner & 1) ? 1.0f : 0.0f; - window_pos_pivot.y = (corner & 2) ? 1.0f : 0.0f; + window_pos.x = (location & 1) ? (work_pos.x + work_size.x - PAD) : (work_pos.x + PAD); + window_pos.y = (location & 2) ? (work_pos.y + work_size.y - PAD) : (work_pos.y + PAD); + window_pos_pivot.x = (location & 1) ? 1.0f : 0.0f; + window_pos_pivot.y = (location & 2) ? 1.0f : 0.0f; ImGui::SetNextWindowPos(window_pos, ImGuiCond_Always, window_pos_pivot); ImGui::SetNextWindowViewport(viewport->ID); window_flags |= ImGuiWindowFlags_NoMove; } + else if (location == -2) + { + // Center window + ImGui::SetNextWindowPos(ImGui::GetMainViewport()->GetCenter(), ImGuiCond_Always, ImVec2(0.5f, 0.5f)); + window_flags |= ImGuiWindowFlags_NoMove; + } ImGui::SetNextWindowBgAlpha(0.35f); // Transparent background if (ImGui::Begin("Example: Simple overlay", p_open, window_flags)) { IMGUI_DEMO_MARKER("Examples/Simple Overlay"); - ImGui::Text("Simple overlay\n" "in the corner of the screen.\n" "(right-click to change position)"); + ImGui::Text("Simple overlay\n" "(right-click to change position)"); ImGui::Separator(); if (ImGui::IsMousePosValid()) ImGui::Text("Mouse Position: (%.1f,%.1f)", io.MousePos.x, io.MousePos.y); @@ -7413,11 +7524,12 @@ static void ShowExampleAppSimpleOverlay(bool* p_open) ImGui::Text("Mouse Position: "); if (ImGui::BeginPopupContextWindow()) { - if (ImGui::MenuItem("Custom", NULL, corner == -1)) corner = -1; - if (ImGui::MenuItem("Top-left", NULL, corner == 0)) corner = 0; - if (ImGui::MenuItem("Top-right", NULL, corner == 1)) corner = 1; - if (ImGui::MenuItem("Bottom-left", NULL, corner == 2)) corner = 2; - if (ImGui::MenuItem("Bottom-right", NULL, corner == 3)) corner = 3; + if (ImGui::MenuItem("Custom", NULL, location == -1)) location = -1; + if (ImGui::MenuItem("Center", NULL, location == -2)) location = -2; + if (ImGui::MenuItem("Top-left", NULL, location == 0)) location = 0; + if (ImGui::MenuItem("Top-right", NULL, location == 1)) location = 1; + if (ImGui::MenuItem("Bottom-left", NULL, location == 2)) location = 2; + if (ImGui::MenuItem("Bottom-right", NULL, location == 3)) location = 3; if (p_open && ImGui::MenuItem("Close")) *p_open = false; ImGui::EndPopup(); } @@ -7433,10 +7545,10 @@ static void ShowExampleAppSimpleOverlay(bool* p_open) static void ShowExampleAppFullscreen(bool* p_open) { static bool use_work_area = true; - static ImGuiWindowFlags flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoSavedSettings; + static ImGuiWindowFlags flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings; // We demonstrate using the full viewport area or the work area (without menu-bars, task-bars etc.) - // Based on your use case you may want one of the other. + // Based on your use case you may want one or the other. const ImGuiViewport* viewport = ImGui::GetMainViewport(); ImGui::SetNextWindowPos(use_work_area ? viewport->WorkPos : viewport->Pos); ImGui::SetNextWindowSize(use_work_area ? viewport->WorkSize : viewport->Size); @@ -7465,8 +7577,8 @@ static void ShowExampleAppFullscreen(bool* p_open) // [SECTION] Example App: Manipulating Window Titles / ShowExampleAppWindowTitles() //----------------------------------------------------------------------------- -// Demonstrate using "##" and "###" in identifiers to manipulate ID generation. -// This apply to all regular items as well. +// Demonstrate the use of "##" and "###" in identifiers to manipulate ID generation. +// This applies to all regular items as well. // Read FAQ section "How can I have multiple widgets with the same label?" for details. static void ShowExampleAppWindowTitles(bool*) { @@ -8010,7 +8122,8 @@ void ShowExampleAppDocuments(bool* p_open) if (ImGui::MenuItem("Close All Documents", NULL, false, open_count > 0)) for (int doc_n = 0; doc_n < app.Documents.Size; doc_n++) app.Documents[doc_n].DoQueueClose(); - if (ImGui::MenuItem("Exit", "Alt+F4")) {} + if (ImGui::MenuItem("Exit", "Ctrl+F4") && p_open) + *p_open = false; ImGui::EndMenu(); } ImGui::EndMenuBar(); diff --git a/extern/imgui_patched/imgui_draw.cpp b/extern/imgui_patched/imgui_draw.cpp index e73bce28..db56f7e3 100644 --- a/extern/imgui_patched/imgui_draw.cpp +++ b/extern/imgui_patched/imgui_draw.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.88 WIP +// dear imgui, v1.89.6 // (drawing and font code) /* @@ -26,38 +26,24 @@ Index of this file: #define _CRT_SECURE_NO_WARNINGS #endif -#include "imgui.h" -#ifndef IMGUI_DISABLE - #ifndef IMGUI_DEFINE_MATH_OPERATORS #define IMGUI_DEFINE_MATH_OPERATORS #endif +#include "imgui.h" +#ifndef IMGUI_DISABLE #include "imgui_internal.h" #ifdef IMGUI_ENABLE_FREETYPE #include "misc/freetype/imgui_freetype.h" #endif #include // vsnprintf, sscanf, printf -#if !defined(alloca) -#if defined(__GLIBC__) || defined(__sun) || defined(__APPLE__) || defined(__NEWLIB__) -#include // alloca (glibc uses . Note that Cygwin may have _WIN32 defined, so the order matters here) -#elif defined(_WIN32) -#include // alloca -#if !defined(alloca) -#define alloca _alloca // for clang with MS Codegen -#endif -#else -#include // alloca -#endif -#endif // Visual Studio warnings #ifdef _MSC_VER #pragma warning (disable: 4127) // condition expression is constant #pragma warning (disable: 4505) // unreferenced local function has been removed (stb stuff) #pragma warning (disable: 4996) // 'This function or variable may be unsafe': strcpy, strdup, sprintf, vsnprintf, sscanf, fopen -#pragma warning (disable: 6255) // [Static Analyzer] _alloca indicates failure by raising a stack overflow exception. Consider using _malloca instead. #pragma warning (disable: 26451) // [Static Analyzer] Arithmetic overflow : Using operator 'xxx' on a 4 byte value and then casting the result to a 8 byte value. Cast the value to the wider type before calling operator 'xxx' to avoid overflow(io.2). #pragma warning (disable: 26812) // [Static Analyzer] The enum type 'xxx' is unscoped. Prefer 'enum class' over 'enum' (Enum.3). [MSVC Static Analyzer) #endif @@ -67,9 +53,6 @@ Index of this file: #if __has_warning("-Wunknown-warning-option") #pragma clang diagnostic ignored "-Wunknown-warning-option" // warning: unknown warning group 'xxx' // not all warnings are known by all Clang versions and they tend to be rename-happy.. so ignoring warnings triggers new warnings on some configuration. Great! #endif -#if __has_warning("-Walloca") -#pragma clang diagnostic ignored "-Walloca" // warning: use of function '__builtin_alloca' is discouraged -#endif #pragma clang diagnostic ignored "-Wunknown-pragmas" // warning: unknown warning group 'xxx' #pragma clang diagnostic ignored "-Wold-style-cast" // warning: use of old-style cast // yes, they are more terse. #pragma clang diagnostic ignored "-Wfloat-equal" // warning: comparing floating point with == or != is unsafe // storing and comparing against same constants ok. @@ -471,11 +454,13 @@ void ImDrawList::AddDrawCmd() // Note that this leaves the ImDrawList in a state unfit for further commands, as most code assume that CmdBuffer.Size > 0 && CmdBuffer.back().UserCallback == NULL void ImDrawList::_PopUnusedDrawCmd() { - if (CmdBuffer.Size == 0) - return; - ImDrawCmd* curr_cmd = &CmdBuffer.Data[CmdBuffer.Size - 1]; - if (curr_cmd->ElemCount == 0 && curr_cmd->UserCallback == NULL) + while (CmdBuffer.Size > 0) + { + ImDrawCmd* curr_cmd = &CmdBuffer.Data[CmdBuffer.Size - 1]; + if (curr_cmd->ElemCount != 0 || curr_cmd->UserCallback != NULL) + return;// break; CmdBuffer.pop_back(); + } } void ImDrawList::AddCallback(ImDrawCallback callback, void* callback_data) @@ -728,7 +713,7 @@ void ImDrawList::PrimQuadUV(const ImVec2& a, const ImVec2& b, const ImVec2& c, c // We avoid using the ImVec2 math operators here to reduce cost to a minimum for debug/non-inlined builds. void ImDrawList::AddPolyline(const ImVec2* points, const int points_count, ImU32 col, ImDrawFlags flags, float thickness) { - if (points_count < 2) + if (points_count < 2 || (col & IM_COL32_A_MASK) == 0) return; const bool closed = (flags & ImDrawFlags_Closed) != 0; @@ -761,7 +746,8 @@ void ImDrawList::AddPolyline(const ImVec2* points, const int points_count, ImU32 // Temporary buffer // The first items are normals at each line point, then after that there are either 2 or 4 temp points for each line point - ImVec2* temp_normals = (ImVec2*)alloca(points_count * ((use_texture || !thick_line) ? 3 : 5) * sizeof(ImVec2)); //-V630 + _Data->TempBuffer.reserve_discard(points_count * ((use_texture || !thick_line) ? 3 : 5)); + ImVec2* temp_normals = _Data->TempBuffer.Data; ImVec2* temp_points = temp_normals + points_count; // Calculate normals (tangents) for each line segment @@ -985,7 +971,7 @@ void ImDrawList::AddPolyline(const ImVec2* points, const int points_count, ImU32 // - Filled shapes must always use clockwise winding order. The anti-aliasing fringe depends on it. Counter-clockwise shapes will have "inward" anti-aliasing. void ImDrawList::AddConvexPolyFilled(const ImVec2* points, const int points_count, ImU32 col) { - if (points_count < 3) + if (points_count < 3 || (col & IM_COL32_A_MASK) == 0) return; const ImVec2 uv = _Data->TexUvWhitePixel; @@ -1009,7 +995,8 @@ void ImDrawList::AddConvexPolyFilled(const ImVec2* points, const int points_coun } // Compute normals - ImVec2* temp_normals = (ImVec2*)alloca(points_count * sizeof(ImVec2)); //-V630 + _Data->TempBuffer.reserve_discard(points_count); + ImVec2* temp_normals = _Data->TempBuffer.Data; for (int i0 = points_count - 1, i1 = 0; i1 < points_count; i0 = i1++) { const ImVec2& p0 = points[i0]; @@ -1303,6 +1290,7 @@ void ImDrawList::PathBezierCubicCurveTo(const ImVec2& p2, const ImVec2& p3, cons ImVec2 p1 = _Path.back(); if (num_segments == 0) { + IM_ASSERT(_Data->CurveTessellationTol > 0.0f); PathBezierCubicCurveToCasteljau(&_Path, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y, p4.x, p4.y, _Data->CurveTessellationTol, 0); // Auto-tessellated } else @@ -1318,6 +1306,7 @@ void ImDrawList::PathBezierQuadraticCurveTo(const ImVec2& p2, const ImVec2& p3, ImVec2 p1 = _Path.back(); if (num_segments == 0) { + IM_ASSERT(_Data->CurveTessellationTol > 0.0f); PathBezierQuadraticCurveToCasteljau(&_Path, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y, _Data->CurveTessellationTol, 0);// Auto-tessellated } else @@ -1332,6 +1321,7 @@ IM_STATIC_ASSERT(ImDrawFlags_RoundCornersTopLeft == (1 << 4)); static inline ImDrawFlags FixRectCornerFlags(ImDrawFlags flags) { #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS + // Obsoleted in 1.82 (from February 2021) // Legacy Support for hard coded ~0 (used to be a suggested equivalent to ImDrawCornerFlags_All) // ~0 --> ImDrawFlags_RoundCornersAll or 0 if (flags == ~0) @@ -2353,10 +2343,11 @@ void ImFontAtlasBuildMultiplyCalcLookupTable(unsigned char out_table[256], fl void ImFontAtlasBuildMultiplyRectAlpha8(const unsigned char table[256], unsigned char* pixels, int x, int y, int w, int h, int stride) { + IM_ASSERT_PARANOID(w <= stride); unsigned char* data = pixels + x + y * stride; - for (int j = h; j > 0; j--, data += stride) - for (int i = 0; i < w; i++) - data[i] = table[data[i]]; + for (int j = h; j > 0; j--, data += stride - w) + for (int i = w; i > 0; i--, data++) + *data = table[*data]; } #ifdef IMGUI_ENABLE_STB_TRUETYPE @@ -2373,7 +2364,7 @@ struct ImFontBuildSrcData int GlyphsHighest; // Highest requested codepoint int GlyphsCount; // Glyph count (excluding missing glyphs and glyphs already set by an earlier source font) ImBitVector GlyphsSet; // Glyph bit map (random access, 1-bit per codepoint. This will be a maximum of 8KB) - ImVector GlyphsList; // Glyph codepoints list (flattened version of GlyphsMap) + ImVector GlyphsList; // Glyph codepoints list (flattened version of GlyphsSet) }; // Temporary data for one destination ImFont* (multiple source fonts can be merged into one destination ImFont) @@ -2445,7 +2436,12 @@ static bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas) ImFontBuildDstData& dst_tmp = dst_tmp_array[src_tmp.DstIndex]; src_tmp.SrcRanges = cfg.GlyphRanges ? cfg.GlyphRanges : atlas->GetGlyphRangesDefault(); for (const ImWchar* src_range = src_tmp.SrcRanges; src_range[0] && src_range[1]; src_range += 2) + { + // Check for valid range. This may also help detect *some* dangling pointers, because a common + // user error is to setup ImFontConfig::GlyphRanges with a pointer to data that isn't persistent. + IM_ASSERT(src_range[0] <= src_range[1]); src_tmp.GlyphsHighest = ImMax(src_tmp.GlyphsHighest, (int)src_range[1]); + } dst_tmp.SrcCount++; dst_tmp.GlyphsHighest = ImMax(dst_tmp.GlyphsHighest, src_tmp.GlyphsHighest); } @@ -2610,13 +2606,10 @@ static bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas) // 9. Setup ImFont and glyphs for runtime for (int src_i = 0; src_i < src_tmp_array.Size; src_i++) { - ImFontBuildSrcData& src_tmp = src_tmp_array[src_i]; - if (src_tmp.GlyphsCount == 0) - continue; - // When merging fonts with MergeMode=true: // - We can have multiple input fonts writing into a same destination font. // - dst_font->ConfigData is != from cfg which is our source configuration. + ImFontBuildSrcData& src_tmp = src_tmp_array[src_i]; ImFontConfig& cfg = atlas->ConfigData[src_i]; ImFont* dst_font = cfg.DstFont; @@ -2680,6 +2673,9 @@ void ImFontAtlasBuildPackCustomRects(ImFontAtlas* atlas, void* stbrp_context_opa ImVector& user_rects = atlas->CustomRects; IM_ASSERT(user_rects.Size >= 1); // We expect at least the default custom rects to be registered, else something went wrong. +#ifdef __GNUC__ + if (user_rects.Size < 1) { __builtin_unreachable(); } // Workaround for GCC bug if IM_ASSERT() is defined to conditionally throw (see #5343) +#endif ImVector pack_rects; pack_rects.resize(user_rects.Size); @@ -2873,6 +2869,17 @@ const ImWchar* ImFontAtlas::GetGlyphRangesDefault() return &ranges[0]; } +const ImWchar* ImFontAtlas::GetGlyphRangesGreek() +{ + static const ImWchar ranges[] = + { + 0x0020, 0x00FF, // Basic Latin + Latin Supplement + 0x0370, 0x03FF, // Greek and Coptic + 0, + }; + return &ranges[0]; +} + const ImWchar* ImFontAtlas::GetGlyphRangesKorean() { static const ImWchar ranges[] = @@ -2989,19 +2996,19 @@ const ImWchar* ImFontAtlas::GetGlyphRangesJapanese() // 2999 ideograms code points for Japanese // - 2136 Joyo (meaning "for regular use" or "for common use") Kanji code points // - 863 Jinmeiyo (meaning "for personal name") Kanji code points - // - Sourced from the character information database of the Information-technology Promotion Agency, Japan - // - https://mojikiban.ipa.go.jp/mji/ - // - Available under the terms of the Creative Commons Attribution-ShareAlike 2.1 Japan (CC BY-SA 2.1 JP). - // - https://creativecommons.org/licenses/by-sa/2.1/jp/deed.en - // - https://creativecommons.org/licenses/by-sa/2.1/jp/legalcode - // - You can generate this code by the script at: - // - https://github.com/vaiorabbit/everyday_use_kanji + // - Sourced from official information provided by the government agencies of Japan: + // - List of Joyo Kanji by the Agency for Cultural Affairs + // - https://www.bunka.go.jp/kokugo_nihongo/sisaku/joho/joho/kijun/naikaku/kanji/ + // - List of Jinmeiyo Kanji by the Ministry of Justice + // - http://www.moj.go.jp/MINJI/minji86.html + // - Available under the terms of the Creative Commons Attribution 4.0 International (CC BY 4.0). + // - https://creativecommons.org/licenses/by/4.0/legalcode + // - You can generate this code by the script at: + // - https://github.com/vaiorabbit/everyday_use_kanji // - References: // - List of Joyo Kanji - // - (Official list by the Agency for Cultural Affairs) https://www.bunka.go.jp/kokugo_nihongo/sisaku/joho/joho/kakuki/14/tosin02/index.html // - (Wikipedia) https://en.wikipedia.org/wiki/List_of_j%C5%8Dy%C5%8D_kanji // - List of Jinmeiyo Kanji - // - (Official list by the Ministry of Justice) http://www.moj.go.jp/MINJI/minji86.html // - (Wikipedia) https://en.wikipedia.org/wiki/Jinmeiy%C5%8D_kanji // - Missing 1 Joyo Kanji: U+20B9F (Kun'yomi: Shikaru, On'yomi: Shitsu,shichi), see https://github.com/ocornut/imgui/pull/3627 for details. // You can use ImFontGlyphRangesBuilder to create your own ranges derived from this, by merging existing ranges or adding new characters. @@ -3164,7 +3171,8 @@ ImFont::ImFont() FallbackAdvanceX = 0.0f; FallbackChar = (ImWchar)-1; EllipsisChar = (ImWchar)-1; - DotChar = (ImWchar)-1; + EllipsisWidth = EllipsisCharStep = 0.0f; + EllipsisCharCount = 0; FallbackGlyph = NULL; ContainerAtlas = NULL; ConfigData = NULL; @@ -3245,17 +3253,7 @@ void ImFont::BuildLookupTable() SetGlyphVisible((ImWchar)' ', false); SetGlyphVisible((ImWchar)'\t', false); - // Ellipsis character is required for rendering elided text. We prefer using U+2026 (horizontal ellipsis). - // However some old fonts may contain ellipsis at U+0085. Here we auto-detect most suitable ellipsis character. - // FIXME: Note that 0x2026 is rarely included in our font ranges. Because of this we are more likely to use three individual dots. - const ImWchar ellipsis_chars[] = { (ImWchar)0x2026, (ImWchar)0x0085 }; - const ImWchar dots_chars[] = { (ImWchar)'.', (ImWchar)0xFF0E }; - if (EllipsisChar == (ImWchar)-1) - EllipsisChar = FindFirstExistingGlyph(this, ellipsis_chars, IM_ARRAYSIZE(ellipsis_chars)); - if (DotChar == (ImWchar)-1) - DotChar = FindFirstExistingGlyph(this, dots_chars, IM_ARRAYSIZE(dots_chars)); - - // Setup fallback character + // Setup Fallback character const ImWchar fallback_chars[] = { (ImWchar)IM_UNICODE_CODEPOINT_INVALID, (ImWchar)'?', (ImWchar)' ' }; FallbackGlyph = FindGlyphNoFallback(FallbackChar); if (FallbackGlyph == NULL) @@ -3268,11 +3266,32 @@ void ImFont::BuildLookupTable() FallbackChar = (ImWchar)FallbackGlyph->Codepoint; } } - FallbackAdvanceX = FallbackGlyph->AdvanceX; for (int i = 0; i < max_codepoint + 1; i++) if (IndexAdvanceX[i] < 0.0f) IndexAdvanceX[i] = FallbackAdvanceX; + + // Setup Ellipsis character. It is required for rendering elided text. We prefer using U+2026 (horizontal ellipsis). + // However some old fonts may contain ellipsis at U+0085. Here we auto-detect most suitable ellipsis character. + // FIXME: Note that 0x2026 is rarely included in our font ranges. Because of this we are more likely to use three individual dots. + const ImWchar ellipsis_chars[] = { (ImWchar)0x2026, (ImWchar)0x0085 }; + const ImWchar dots_chars[] = { (ImWchar)'.', (ImWchar)0xFF0E }; + if (EllipsisChar == (ImWchar)-1) + EllipsisChar = FindFirstExistingGlyph(this, ellipsis_chars, IM_ARRAYSIZE(ellipsis_chars)); + const ImWchar dot_char = FindFirstExistingGlyph(this, dots_chars, IM_ARRAYSIZE(dots_chars)); + if (EllipsisChar != (ImWchar)-1) + { + EllipsisCharCount = 1; + EllipsisWidth = EllipsisCharStep = FindGlyph(EllipsisChar)->X1; + } + else if (dot_char != (ImWchar)-1) + { + const ImFontGlyph* glyph = FindGlyph(dot_char); + EllipsisChar = dot_char; + EllipsisCharCount = 3; + EllipsisCharStep = (glyph->X1 - glyph->X0) + 1.0f; + EllipsisWidth = EllipsisCharStep * 3.0f - 1.0f; + } } // API is designed this way to avoid exposing the 4K page size @@ -3385,11 +3404,21 @@ const ImFontGlyph* ImFont::FindGlyphNoFallback(ImWchar c) const return &Glyphs.Data[i]; } +// Wrapping skips upcoming blanks +static inline const char* CalcWordWrapNextLineStartA(const char* text, const char* text_end) +{ + while (text < text_end && ImCharIsBlankA(*text)) + text++; + if (*text == '\n') + text++; + return text; +} + +// Simple word-wrapping for English, not full-featured. Please submit failing cases! +// This will return the next location to wrap from. If no wrapping if necessary, this will fast-forward to e.g. text_end. +// FIXME: Much possible improvements (don't cut things like "word !", "word!!!" but cut within "word,,,,", more sensible support for punctuations, support for Unicode punctuations, etc.) const char* ImFont::CalcWordWrapPositionA(float scale, const char* text, const char* text_end, float wrap_width) const { - // Simple word-wrapping for English, not full-featured. Please submit failing cases! - // FIXME: Much possible improvements (don't cut things like "word !", "word!!!" but cut within "word,,,,", more sensible support for punctuations, support for Unicode punctuations, etc.) - // For references, possible wrap point marked with ^ // "aaa bbb, ccc,ddd. eee fff. ggg!" // ^ ^ ^ ^ ^__ ^ ^ @@ -3401,7 +3430,6 @@ const char* ImFont::CalcWordWrapPositionA(float scale, const char* text, const c // Cut words that cannot possibly fit within one line. // e.g.: "The tropical fish" with ~5 characters worth of width --> "The tr" "opical" "fish" - float line_width = 0.0f; float word_width = 0.0f; float blank_width = 0.0f; @@ -3412,6 +3440,7 @@ const char* ImFont::CalcWordWrapPositionA(float scale, const char* text, const c bool inside_word = true; const char* s = text; + IM_ASSERT(text_end != NULL); while (s < text_end) { unsigned int c = (unsigned int)*s; @@ -3420,8 +3449,6 @@ const char* ImFont::CalcWordWrapPositionA(float scale, const char* text, const c next_s = s + 1; else next_s = s + ImTextCharFromUtf8(&c, s, text_end); - if (c == 0) - break; if (c < 32) { @@ -3481,6 +3508,10 @@ const char* ImFont::CalcWordWrapPositionA(float scale, const char* text, const c s = next_s; } + // Wrap_width is too small to fit anything. Force displaying 1 character to minimize the height discontinuity. + // +1 may not be a character start point in UTF-8 but it's ok because caller loops use (text >= word_wrap_eol). + if (s == text && text < text_end) + return s + 1; return s; } @@ -3505,11 +3536,7 @@ ImVec2 ImFont::CalcTextSizeA(float size, float max_width, float wrap_width, cons { // Calculate how far we can render. Requires two passes on the string data but keeps the code simple and not intrusive for what's essentially an uncommon feature. if (!word_wrap_eol) - { word_wrap_eol = CalcWordWrapPositionA(scale, s, text_end, wrap_width - line_width); - if (word_wrap_eol == s) // Wrap_width is too small to fit anything. Force displaying 1 character to minimize the height discontinuity. - word_wrap_eol++; // +1 may not be a character start point in UTF-8 but it's ok because we use s >= word_wrap_eol below - } if (s >= word_wrap_eol) { @@ -3518,13 +3545,7 @@ ImVec2 ImFont::CalcTextSizeA(float size, float max_width, float wrap_width, cons text_size.y += line_height; line_width = 0.0f; word_wrap_eol = NULL; - - // Wrapping skips upcoming blanks - while (s < text_end) - { - const char c = *s; - if (ImCharIsBlankA(c)) { s++; } else if (c == '\n') { s++; break; } else { break; } - } + s = CalcWordWrapNextLineStartA(s, text_end); // Wrapping skips upcoming blanks continue; } } @@ -3533,15 +3554,9 @@ ImVec2 ImFont::CalcTextSizeA(float size, float max_width, float wrap_width, cons const char* prev_s = s; unsigned int c = (unsigned int)*s; if (c < 0x80) - { s += 1; - } else - { s += ImTextCharFromUtf8(&c, s, text_end); - if (c == 0) // Malformed UTF-8? - break; - } if (c < 32) { @@ -3609,15 +3624,25 @@ void ImFont::RenderText(ImDrawList* draw_list, float size, const ImVec2& pos, Im const float scale = size / FontSize; const float line_height = FontSize * scale; const bool word_wrap_enabled = (wrap_width > 0.0f); - const char* word_wrap_eol = NULL; // Fast-forward to first visible line const char* s = text_begin; - if (y + line_height < clip_rect.y && !word_wrap_enabled) + if (y + line_height < clip_rect.y) while (y + line_height < clip_rect.y && s < text_end) { - s = (const char*)memchr(s, '\n', text_end - s); - s = s ? s + 1 : text_end; + const char* line_end = (const char*)memchr(s, '\n', text_end - s); + if (word_wrap_enabled) + { + // FIXME-OPT: This is not optimal as do first do a search for \n before calling CalcWordWrapPositionA(). + // If the specs for CalcWordWrapPositionA() were reworked to optionally return on \n we could combine both. + // However it is still better than nothing performing the fast-forward! + s = CalcWordWrapPositionA(scale, s, line_end ? line_end : text_end, wrap_width); + s = CalcWordWrapNextLineStartA(s, text_end); + } + else + { + s = line_end ? line_end + 1 : text_end; + } y += line_height; } @@ -3643,12 +3668,12 @@ void ImFont::RenderText(ImDrawList* draw_list, float size, const ImVec2& pos, Im const int idx_count_max = (int)(text_end - s) * 6; const int idx_expected_size = draw_list->IdxBuffer.Size + idx_count_max; draw_list->PrimReserve(idx_count_max, vtx_count_max); - - ImDrawVert* vtx_write = draw_list->_VtxWritePtr; - ImDrawIdx* idx_write = draw_list->_IdxWritePtr; - unsigned int vtx_current_idx = draw_list->_VtxCurrentIdx; + ImDrawVert* vtx_write = draw_list->_VtxWritePtr; + ImDrawIdx* idx_write = draw_list->_IdxWritePtr; + unsigned int vtx_index = draw_list->_VtxCurrentIdx; const ImU32 col_untinted = col | ~IM_COL32_A_MASK; + const char* word_wrap_eol = NULL; while (s < text_end) { @@ -3656,24 +3681,14 @@ void ImFont::RenderText(ImDrawList* draw_list, float size, const ImVec2& pos, Im { // Calculate how far we can render. Requires two passes on the string data but keeps the code simple and not intrusive for what's essentially an uncommon feature. if (!word_wrap_eol) - { word_wrap_eol = CalcWordWrapPositionA(scale, s, text_end, wrap_width - (x - start_x)); - if (word_wrap_eol == s) // Wrap_width is too small to fit anything. Force displaying 1 character to minimize the height discontinuity. - word_wrap_eol++; // +1 may not be a character start point in UTF-8 but it's ok because we use s >= word_wrap_eol below - } if (s >= word_wrap_eol) { x = start_x; y += line_height; word_wrap_eol = NULL; - - // Wrapping skips upcoming blanks - while (s < text_end) - { - const char c = *s; - if (ImCharIsBlankA(c)) { s++; } else if (c == '\n') { s++; break; } else { break; } - } + s = CalcWordWrapNextLineStartA(s, text_end); // Wrapping skips upcoming blanks continue; } } @@ -3681,15 +3696,9 @@ void ImFont::RenderText(ImDrawList* draw_list, float size, const ImVec2& pos, Im // Decode and advance source unsigned int c = (unsigned int)*s; if (c < 0x80) - { s += 1; - } else - { s += ImTextCharFromUtf8(&c, s, text_end); - if (c == 0) // Malformed UTF-8? - break; - } if (c < 32) { @@ -3760,14 +3769,14 @@ void ImFont::RenderText(ImDrawList* draw_list, float size, const ImVec2& pos, Im // We are NOT calling PrimRectUV() here because non-inlined causes too much overhead in a debug builds. Inlined here: { - idx_write[0] = (ImDrawIdx)(vtx_current_idx); idx_write[1] = (ImDrawIdx)(vtx_current_idx+1); idx_write[2] = (ImDrawIdx)(vtx_current_idx+2); - idx_write[3] = (ImDrawIdx)(vtx_current_idx); idx_write[4] = (ImDrawIdx)(vtx_current_idx+2); idx_write[5] = (ImDrawIdx)(vtx_current_idx+3); vtx_write[0].pos.x = x1; vtx_write[0].pos.y = y1; vtx_write[0].col = glyph_col; vtx_write[0].uv.x = u1; vtx_write[0].uv.y = v1; vtx_write[1].pos.x = x2; vtx_write[1].pos.y = y1; vtx_write[1].col = glyph_col; vtx_write[1].uv.x = u2; vtx_write[1].uv.y = v1; vtx_write[2].pos.x = x2; vtx_write[2].pos.y = y2; vtx_write[2].col = glyph_col; vtx_write[2].uv.x = u2; vtx_write[2].uv.y = v2; vtx_write[3].pos.x = x1; vtx_write[3].pos.y = y2; vtx_write[3].col = glyph_col; vtx_write[3].uv.x = u1; vtx_write[3].uv.y = v2; + idx_write[0] = (ImDrawIdx)(vtx_index); idx_write[1] = (ImDrawIdx)(vtx_index + 1); idx_write[2] = (ImDrawIdx)(vtx_index + 2); + idx_write[3] = (ImDrawIdx)(vtx_index); idx_write[4] = (ImDrawIdx)(vtx_index + 2); idx_write[5] = (ImDrawIdx)(vtx_index + 3); vtx_write += 4; - vtx_current_idx += 4; + vtx_index += 4; idx_write += 6; } } @@ -3781,7 +3790,7 @@ void ImFont::RenderText(ImDrawList* draw_list, float size, const ImVec2& pos, Im draw_list->CmdBuffer[draw_list->CmdBuffer.Size - 1].ElemCount -= (idx_expected_size - draw_list->IdxBuffer.Size); draw_list->_VtxWritePtr = vtx_write; draw_list->_IdxWritePtr = idx_write; - draw_list->_VtxCurrentIdx = vtx_current_idx; + draw_list->_VtxCurrentIdx = vtx_index; } //----------------------------------------------------------------------------- @@ -3834,6 +3843,7 @@ void ImGui::RenderArrow(ImDrawList* draw_list, ImVec2 pos, ImU32 col, ImGuiDir d void ImGui::RenderBullet(ImDrawList* draw_list, ImVec2 pos, ImU32 col) { + // FIXME-OPT: This should be baked in font. draw_list->AddCircleFilled(pos, draw_list->_Data->FontSize * 0.20f, col, 8); } diff --git a/extern/imgui_patched/imgui_impl_sdlrenderer.h b/extern/imgui_patched/imgui_impl_sdlrenderer.h deleted file mode 100644 index 379265de..00000000 --- a/extern/imgui_patched/imgui_impl_sdlrenderer.h +++ /dev/null @@ -1,31 +0,0 @@ -// dear imgui: Renderer Backend for SDL_Renderer -// (Requires: SDL 2.0.17+) - -// Important to understand: SDL_Renderer is an _optional_ component of SDL. -// For a multi-platform app consider using e.g. SDL+DirectX on Windows and SDL+OpenGL on Linux/OSX. -// If your application will want to render any non trivial amount of graphics other than UI, -// please be aware that SDL_Renderer offers a limited graphic API to the end-user and it might -// be difficult to step out of those boundaries. -// However, we understand it is a convenient choice to get an app started easily. - -// Implemented features: -// [X] Renderer: User texture binding. Use 'SDL_Texture*' as ImTextureID. Read the FAQ about ImTextureID! -// [X] Renderer: Support for large meshes (64k+ vertices) with 16-bit indices. -// Missing features: -// [ ] Renderer: Multi-viewport support (multiple windows). - -#pragma once -#include "imgui.h" // IMGUI_IMPL_API - -struct SDL_Renderer; - -IMGUI_IMPL_API bool ImGui_ImplSDLRenderer_Init(SDL_Renderer* renderer); -IMGUI_IMPL_API void ImGui_ImplSDLRenderer_Shutdown(); -IMGUI_IMPL_API bool ImGui_ImplSDLRenderer_NewFrame(); -IMGUI_IMPL_API void ImGui_ImplSDLRenderer_RenderDrawData(ImDrawData* draw_data); - -// Called by Init/NewFrame/Shutdown -IMGUI_IMPL_API bool ImGui_ImplSDLRenderer_CreateFontsTexture(); -IMGUI_IMPL_API void ImGui_ImplSDLRenderer_DestroyFontsTexture(); -IMGUI_IMPL_API bool ImGui_ImplSDLRenderer_CreateDeviceObjects(); -IMGUI_IMPL_API void ImGui_ImplSDLRenderer_DestroyDeviceObjects(); diff --git a/extern/imgui_patched/imgui_internal.h b/extern/imgui_patched/imgui_internal.h index c2e15764..6fa0dc58 100644 --- a/extern/imgui_patched/imgui_internal.h +++ b/extern/imgui_patched/imgui_internal.h @@ -1,10 +1,12 @@ -// dear imgui, v1.88 WIP +// dear imgui, v1.89.6 // (internal structures/api) -// You may use this file to debug, understand or extend ImGui features but we don't provide any guarantee of forward compatibility! -// Set: -// #define IMGUI_DEFINE_MATH_OPERATORS -// To implement maths operators for ImVec2 (disabled by default to not collide with using IM_VEC2_CLASS_EXTRA along with your own math types+operators) +// You may use this file to debug, understand or extend Dear ImGui features but we don't provide any guarantee of forward compatibility. +// To implement maths operators for ImVec2 (disabled by default to not conflict with using IM_VEC2_CLASS_EXTRA with your own math types+operators), use: +/* +#define IMGUI_DEFINE_MATH_OPERATORS +#include "imgui_internal.h" +*/ /* @@ -26,6 +28,7 @@ Index of this file: // [SECTION] Docking support // [SECTION] Viewport support // [SECTION] Settings support +// [SECTION] Localization support // [SECTION] Metrics, Debug tools // [SECTION] Generic context hooks // [SECTION] ImGuiContext (main imgui context) @@ -55,7 +58,7 @@ Index of this file: #include // INT_MIN, INT_MAX // Enable SSE intrinsics if available -#if (defined __SSE__ || defined __x86_64__ || defined _M_X64) && !defined(IMGUI_DISABLE_SSE) +#if (defined __SSE__ || defined __x86_64__ || defined _M_X64 || (defined(_M_IX86_FP) && (_M_IX86_FP >= 1))) && !defined(IMGUI_DISABLE_SSE) #define IMGUI_ENABLE_SSE #include #endif @@ -92,6 +95,12 @@ Index of this file: #pragma GCC diagnostic ignored "-Wclass-memaccess" // [__GNUC__ >= 8] warning: 'memset/memcpy' clearing/writing an object of type 'xxxx' with no trivial copy-assignment; use assignment or value-initialization instead #endif +// In 1.89.4, we moved the implementation of "courtesy maths operators" from imgui_internal.h in imgui.h +// As they are frequently requested, we do not want to encourage to many people using imgui_internal.h +#if defined(IMGUI_DEFINE_MATH_OPERATORS) && !defined(IMGUI_DEFINE_MATH_OPERATORS_IMPLEMENTED) +#error Please '#define IMGUI_DEFINE_MATH_OPERATORS' _BEFORE_ including imgui.h! +#endif + // Legacy defines #ifdef IMGUI_DISABLE_FORMAT_STRING_FUNCTIONS // Renamed in 1.74 #error Use IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS @@ -117,6 +126,7 @@ struct ImDrawListSharedData; // Data shared between all ImDrawList instan struct ImGuiColorMod; // Stacked color modifier, backup of modified data so we can restore it struct ImGuiContext; // Main Dear ImGui context struct ImGuiContextHook; // Hook for extensions like ImGuiTestEngine +struct ImGuiDataVarInfo; // Variable information (e.g. to avoid style variables from an enum) struct ImGuiDataTypeInfo; // Type information associated to a ImGuiDataType enum struct ImGuiDockContext; // Docking system context struct ImGuiDockRequest; // Docking system dock/undock queued request @@ -124,7 +134,9 @@ struct ImGuiDockNode; // Docking system node (hold a list of Windo struct ImGuiDockNodeSettings; // Storage for a dock node in .ini file (we preserve those even if the associated dock node isn't active during the session) struct ImGuiGroupData; // Stacked storage data for BeginGroup()/EndGroup() struct ImGuiInputTextState; // Internal state of the currently focused/edited text input box +struct ImGuiInputTextDeactivateData;// Short term storage to backup text of a deactivating InputText() while another is stealing active id struct ImGuiLastItemData; // Status storage for last submitted items +struct ImGuiLocEntry; // A localization entry. struct ImGuiMenuColumns; // Simple column measurement, currently used for MenuItem() only struct ImGuiNavItemData; // Result of a gamepad/keyboard directional navigation move query result struct ImGuiMetricsConfig; // Storage for ShowMetricsWindow() and DebugNodeXXX() functions @@ -148,15 +160,21 @@ struct ImGuiWindow; // Storage for one window struct ImGuiWindowTempData; // Temporary storage for one window (that's the data which in theory we could ditch at the end of the frame, in practice we currently keep it for each window) struct ImGuiWindowSettings; // Storage for a window .ini settings (we keep one of those even if the actual window wasn't instanced during this session) +// Enumerations // Use your programming IDE "Go to definition" facility on the names of the center columns to find the actual flags/enum lists. +enum ImGuiLocKey : int; // -> enum ImGuiLocKey // Enum: a localization entry for translation. typedef int ImGuiDataAuthority; // -> enum ImGuiDataAuthority_ // Enum: for storing the source authority (dock node vs window) of a field typedef int ImGuiLayoutType; // -> enum ImGuiLayoutType_ // Enum: Horizontal or vertical + +// Flags typedef int ImGuiActivateFlags; // -> enum ImGuiActivateFlags_ // Flags: for navigation/focus function (will be for ActivateItem() later) -typedef int ImGuiItemFlags; // -> enum ImGuiItemFlags_ // Flags: for PushItemFlag() -typedef int ImGuiItemStatusFlags; // -> enum ImGuiItemStatusFlags_ // Flags: for DC.LastItemStatusFlags +typedef int ImGuiDebugLogFlags; // -> enum ImGuiDebugLogFlags_ // Flags: for ShowDebugLogWindow(), g.DebugLogFlags +typedef int ImGuiFocusRequestFlags; // -> enum ImGuiFocusRequestFlags_ // Flags: for FocusWindow(); +typedef int ImGuiInputFlags; // -> enum ImGuiInputFlags_ // Flags: for IsKeyPressed(), IsMouseClicked(), SetKeyOwner(), SetItemKeyOwner() etc. +typedef int ImGuiItemFlags; // -> enum ImGuiItemFlags_ // Flags: for PushItemFlag(), g.LastItemData.InFlags +typedef int ImGuiItemStatusFlags; // -> enum ImGuiItemStatusFlags_ // Flags: for g.LastItemData.StatusFlags typedef int ImGuiOldColumnFlags; // -> enum ImGuiOldColumnFlags_ // Flags: for BeginColumns() typedef int ImGuiNavHighlightFlags; // -> enum ImGuiNavHighlightFlags_ // Flags: for RenderNavHighlight() -typedef int ImGuiNavDirSourceFlags; // -> enum ImGuiNavDirSourceFlags_ // Flags: for GetNavInputAmount2d() typedef int ImGuiNavMoveFlags; // -> enum ImGuiNavMoveFlags_ // Flags: for navigation requests typedef int ImGuiNextItemDataFlags; // -> enum ImGuiNextItemDataFlags_ // Flags: for SetNextItemXXX() functions typedef int ImGuiNextWindowDataFlags; // -> enum ImGuiNextWindowDataFlags_// Flags: for SetNextWindowXXX() functions @@ -201,22 +219,31 @@ namespace ImStb // Internal Drag and Drop payload types. String starting with '_' are reserved for Dear ImGui. #define IMGUI_PAYLOAD_TYPE_WINDOW "_IMWINDOW" // Payload == ImGuiWindow* -// Debug Logging -#ifndef IMGUI_DEBUG_LOG -#define IMGUI_DEBUG_LOG(_FMT,...) printf("[%05d] " _FMT, GImGui->FrameCount, __VA_ARGS__) +// Debug Printing Into TTY +// (since IMGUI_VERSION_NUM >= 18729: IMGUI_DEBUG_LOG was reworked into IMGUI_DEBUG_PRINTF (and removed framecount from it). If you were using a #define IMGUI_DEBUG_LOG please rename) +#ifndef IMGUI_DEBUG_PRINTF +#ifndef IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS +#define IMGUI_DEBUG_PRINTF(_FMT,...) printf(_FMT, __VA_ARGS__) +#else +#define IMGUI_DEBUG_PRINTF(_FMT,...) ((void)0) +#endif #endif -// Debug Logging for selected systems. Remove the '((void)0) //' to enable. -//#define IMGUI_DEBUG_LOG_POPUP IMGUI_DEBUG_LOG // Enable log -//#define IMGUI_DEBUG_LOG_NAV IMGUI_DEBUG_LOG // Enable log -//#define IMGUI_DEBUG_LOG_IO IMGUI_DEBUG_LOG // Enable log -//#define IMGUI_DEBUG_LOG_VIEWPORT IMGUI_DEBUG_LOG // Enable log -//#define IMGUI_DEBUG_LOG_DOCKING IMGUI_DEBUG_LOG // Enable log -#define IMGUI_DEBUG_LOG_POPUP(...) ((void)0) // Disable log -#define IMGUI_DEBUG_LOG_NAV(...) ((void)0) // Disable log -#define IMGUI_DEBUG_LOG_IO(...) ((void)0) // Disable log -#define IMGUI_DEBUG_LOG_VIEWPORT(...) ((void)0) // Disable log -#define IMGUI_DEBUG_LOG_DOCKING(...) ((void)0) // Disable log +// Debug Logging for ShowDebugLogWindow(). This is designed for relatively rare events so please don't spam. +#ifndef IMGUI_DISABLE_DEBUG_TOOLS +#define IMGUI_DEBUG_LOG(...) ImGui::DebugLog(__VA_ARGS__) +#else +#define IMGUI_DEBUG_LOG(...) ((void)0) +#endif +#define IMGUI_DEBUG_LOG_ACTIVEID(...) do { if (g.DebugLogFlags & ImGuiDebugLogFlags_EventActiveId) IMGUI_DEBUG_LOG(__VA_ARGS__); } while (0) +#define IMGUI_DEBUG_LOG_FOCUS(...) do { if (g.DebugLogFlags & ImGuiDebugLogFlags_EventFocus) IMGUI_DEBUG_LOG(__VA_ARGS__); } while (0) +#define IMGUI_DEBUG_LOG_POPUP(...) do { if (g.DebugLogFlags & ImGuiDebugLogFlags_EventPopup) IMGUI_DEBUG_LOG(__VA_ARGS__); } while (0) +#define IMGUI_DEBUG_LOG_NAV(...) do { if (g.DebugLogFlags & ImGuiDebugLogFlags_EventNav) IMGUI_DEBUG_LOG(__VA_ARGS__); } while (0) +#define IMGUI_DEBUG_LOG_SELECTION(...) do { if (g.DebugLogFlags & ImGuiDebugLogFlags_EventSelection)IMGUI_DEBUG_LOG(__VA_ARGS__); } while (0) +#define IMGUI_DEBUG_LOG_CLIPPER(...) do { if (g.DebugLogFlags & ImGuiDebugLogFlags_EventClipper) IMGUI_DEBUG_LOG(__VA_ARGS__); } while (0) +#define IMGUI_DEBUG_LOG_IO(...) do { if (g.DebugLogFlags & ImGuiDebugLogFlags_EventIO) IMGUI_DEBUG_LOG(__VA_ARGS__); } while (0) +#define IMGUI_DEBUG_LOG_DOCKING(...) do { if (g.DebugLogFlags & ImGuiDebugLogFlags_EventDocking) IMGUI_DEBUG_LOG(__VA_ARGS__); } while (0) +#define IMGUI_DEBUG_LOG_VIEWPORT(...) do { if (g.DebugLogFlags & ImGuiDebugLogFlags_EventViewport) IMGUI_DEBUG_LOG(__VA_ARGS__); } while (0) // Static Asserts #define IM_STATIC_ASSERT(_COND) static_assert(_COND, "") @@ -243,7 +270,9 @@ namespace ImStb #else #define IM_NEWLINE "\n" #endif +#ifndef IM_TABSIZE // Until we move this to runtime and/or add proper tab support, at least allow users to compile-time override #define IM_TABSIZE (4) +#endif #define IM_MEMALIGN(_OFF,_ALIGN) (((_OFF) + ((_ALIGN) - 1)) & ~((_ALIGN) - 1)) // Memory align e.g. IM_ALIGN(0,4)=0, IM_ALIGN(1,4)=4, IM_ALIGN(4,4)=4, IM_ALIGN(5,4)=8 #define IM_F32_TO_INT8_UNBOUND(_VAL) ((int)((_VAL) * 255.0f + ((_VAL)>=0 ? 0.5f : -0.5f))) // Unsaturated, for display purpose #define IM_F32_TO_INT8_SAT(_VAL) ((int)(ImSaturate(_VAL) * 255.0f + 0.5f)) // Saturated, always output 0..255 @@ -305,11 +334,12 @@ namespace ImStb // - Helper: ImSpan<>, ImSpanAllocator<> // - Helper: ImPool<> // - Helper: ImChunkStream<> +// - Helper: ImGuiTextIndex //----------------------------------------------------------------------------- // Helpers: Hashing -IMGUI_API ImGuiID ImHashData(const void* data, size_t data_size, ImU32 seed = 0); -IMGUI_API ImGuiID ImHashStr(const char* data, size_t data_size = 0, ImU32 seed = 0); +IMGUI_API ImGuiID ImHashData(const void* data, size_t data_size, ImGuiID seed = 0); +IMGUI_API ImGuiID ImHashStr(const char* data, size_t data_size = 0, ImGuiID seed = 0); // Helpers: Sorting #ifndef ImQsort @@ -337,12 +367,17 @@ IMGUI_API const ImWchar*ImStrbolW(const ImWchar* buf_mid_line, const ImWchar* bu IMGUI_API const char* ImStristr(const char* haystack, const char* haystack_end, const char* needle, const char* needle_end); IMGUI_API void ImStrTrimBlanks(char* str); IMGUI_API const char* ImStrSkipBlank(const char* str); +IM_MSVC_RUNTIME_CHECKS_OFF +static inline char ImToUpper(char c) { return (c >= 'a' && c <= 'z') ? c &= ~32 : c; } static inline bool ImCharIsBlankA(char c) { return c == ' ' || c == '\t'; } static inline bool ImCharIsBlankW(unsigned int c) { return c == ' ' || c == '\t' || c == 0x3000; } +IM_MSVC_RUNTIME_CHECKS_RESTORE // Helpers: Formatting IMGUI_API int ImFormatString(char* buf, size_t buf_size, const char* fmt, ...) IM_FMTARGS(3); IMGUI_API int ImFormatStringV(char* buf, size_t buf_size, const char* fmt, va_list args) IM_FMTLIST(3); +IMGUI_API void ImFormatStringToTempBuffer(const char** out_buf, const char** out_buf_end, const char* fmt, ...) IM_FMTARGS(3); +IMGUI_API void ImFormatStringToTempBufferV(const char** out_buf, const char** out_buf_end, const char* fmt, va_list args) IM_FMTLIST(3); IMGUI_API const char* ImParseFormatFindStart(const char* format); IMGUI_API const char* ImParseFormatFindEnd(const char* format); IMGUI_API const char* ImParseFormatTrimDecorations(const char* format, char* buf, size_t buf_size); @@ -359,29 +394,6 @@ IMGUI_API int ImTextCountCharsFromUtf8(const char* in_text, const char IMGUI_API int ImTextCountUtf8BytesFromChar(const char* in_text, const char* in_text_end); // return number of bytes to express one char in UTF-8 IMGUI_API int ImTextCountUtf8BytesFromStr(const ImWchar* in_text, const ImWchar* in_text_end); // return number of bytes to express string in UTF-8 -// Helpers: ImVec2/ImVec4 operators -// We are keeping those disabled by default so they don't leak in user space, to allow user enabling implicit cast operators between ImVec2 and their own types (using IM_VEC2_CLASS_EXTRA etc.) -// We unfortunately don't have a unary- operator for ImVec2 because this would needs to be defined inside the class itself. -#ifdef IMGUI_DEFINE_MATH_OPERATORS -IM_MSVC_RUNTIME_CHECKS_OFF -static inline ImVec2 operator*(const ImVec2& lhs, const float rhs) { return ImVec2(lhs.x * rhs, lhs.y * rhs); } -static inline ImVec2 operator/(const ImVec2& lhs, const float rhs) { return ImVec2(lhs.x / rhs, lhs.y / rhs); } -static inline ImVec2 operator+(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x + rhs.x, lhs.y + rhs.y); } -static inline ImVec2 operator-(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x - rhs.x, lhs.y - rhs.y); } -static inline ImVec2 operator*(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x * rhs.x, lhs.y * rhs.y); } -static inline ImVec2 operator/(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x / rhs.x, lhs.y / rhs.y); } -static inline ImVec2& operator*=(ImVec2& lhs, const float rhs) { lhs.x *= rhs; lhs.y *= rhs; return lhs; } -static inline ImVec2& operator/=(ImVec2& lhs, const float rhs) { lhs.x /= rhs; lhs.y /= rhs; return lhs; } -static inline ImVec2& operator+=(ImVec2& lhs, const ImVec2& rhs) { lhs.x += rhs.x; lhs.y += rhs.y; return lhs; } -static inline ImVec2& operator-=(ImVec2& lhs, const ImVec2& rhs) { lhs.x -= rhs.x; lhs.y -= rhs.y; return lhs; } -static inline ImVec2& operator*=(ImVec2& lhs, const ImVec2& rhs) { lhs.x *= rhs.x; lhs.y *= rhs.y; return lhs; } -static inline ImVec2& operator/=(ImVec2& lhs, const ImVec2& rhs) { lhs.x /= rhs.x; lhs.y /= rhs.y; return lhs; } -static inline ImVec4 operator+(const ImVec4& lhs, const ImVec4& rhs) { return ImVec4(lhs.x + rhs.x, lhs.y + rhs.y, lhs.z + rhs.z, lhs.w + rhs.w); } -static inline ImVec4 operator-(const ImVec4& lhs, const ImVec4& rhs) { return ImVec4(lhs.x - rhs.x, lhs.y - rhs.y, lhs.z - rhs.z, lhs.w - rhs.w); } -static inline ImVec4 operator*(const ImVec4& lhs, const ImVec4& rhs) { return ImVec4(lhs.x * rhs.x, lhs.y * rhs.y, lhs.z * rhs.z, lhs.w * rhs.w); } -IM_MSVC_RUNTIME_CHECKS_RESTORE -#endif - // Helpers: File System #ifdef IMGUI_DISABLE_FILE_FUNCTIONS #define IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS @@ -464,6 +476,7 @@ static inline ImVec2 ImRotate(const ImVec2& v, float cos_a, float sin_a) static inline float ImLinearSweep(float current, float target, float speed) { if (current < target) return ImMin(current + speed, target); if (current > target) return ImMax(current - speed, target); return current; } static inline ImVec2 ImMul(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x * rhs.x, lhs.y * rhs.y); } static inline bool ImIsFloatAboveGuaranteedIntegerPrecision(float f) { return f <= -16777216 || f >= 16777216; } +static inline float ImExponentialMovingAverage(float avg, float sample, int n) { avg -= avg / n; avg += sample / n; return avg; } IM_MSVC_RUNTIME_CHECKS_RESTORE // Helpers: Geometry @@ -476,7 +489,6 @@ IMGUI_API bool ImTriangleContainsPoint(const ImVec2& a, const ImVec2& b, c IMGUI_API ImVec2 ImTriangleClosestPoint(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& p); IMGUI_API void ImTriangleBarycentricCoords(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& p, float& out_u, float& out_v, float& out_w); inline float ImTriangleArea(const ImVec2& a, const ImVec2& b, const ImVec2& c) { return ImFabs((a.x * (b.y - c.y)) + (b.x * (c.y - a.y)) + (c.x * (a.y - b.y))) * 0.5f; } -IMGUI_API ImGuiDir ImGetDirQuadrantFromDelta(float dx, float dy); // Helper: ImVec1 (1D vector) // (this odd construct is used to facilitate the transition between 1D and 2D, and the maintenance of some branches/patches) @@ -534,9 +546,12 @@ struct IMGUI_API ImRect bool IsInverted() const { return Min.x > Max.x || Min.y > Max.y; } ImVec4 ToVec4() const { return ImVec4(Min.x, Min.y, Max.x, Max.y); } }; -IM_MSVC_RUNTIME_CHECKS_RESTORE // Helper: ImBitArray +#define IM_BITARRAY_TESTBIT(_ARRAY, _N) ((_ARRAY[(_N) >> 5] & ((ImU32)1 << ((_N) & 31))) != 0) // Macro version of ImBitArrayTestBit(): ensure args have side-effect or are costly! +#define IM_BITARRAY_CLEARBIT(_ARRAY, _N) ((_ARRAY[(_N) >> 5] &= ~((ImU32)1 << ((_N) & 31)))) // Macro version of ImBitArrayClearBit(): ensure args have side-effect or are costly! +inline size_t ImBitArrayGetStorageSizeInBytes(int bitcount) { return (size_t)((bitcount + 31) >> 5) << 2; } +inline void ImBitArrayClearAllBits(ImU32* arr, int bitcount){ memset(arr, 0, ImBitArrayGetStorageSizeInBytes(bitcount)); } inline bool ImBitArrayTestBit(const ImU32* arr, int n) { ImU32 mask = (ImU32)1 << (n & 31); return (arr[n >> 5] & mask) != 0; } inline void ImBitArrayClearBit(ImU32* arr, int n) { ImU32 mask = (ImU32)1 << (n & 31); arr[n >> 5] &= ~mask; } inline void ImBitArraySetBit(ImU32* arr, int n) { ImU32 mask = (ImU32)1 << (n & 31); arr[n >> 5] |= mask; } @@ -553,49 +568,22 @@ inline void ImBitArraySetBitRange(ImU32* arr, int n, int n2) // Works on ran } } +typedef ImU32* ImBitArrayPtr; // Name for use in structs + // Helper: ImBitArray class (wrapper over ImBitArray functions) // Store 1-bit per value. template struct ImBitArray { ImU32 Storage[(BITCOUNT + 31) >> 5]; - ImBitArray() { ClearAllBits(); } - void ClearAllBits() { memset(Storage, 0, sizeof(Storage)); } - void SetAllBits() { memset(Storage, 255, sizeof(Storage)); } - bool TestBit(int n) const { n += OFFSET; IM_ASSERT(n >= 0 && n < BITCOUNT); return ImBitArrayTestBit(Storage, n); } - void SetBit(int n) { n += OFFSET; IM_ASSERT(n >= 0 && n < BITCOUNT); ImBitArraySetBit(Storage, n); } - void ClearBit(int n) { n += OFFSET; IM_ASSERT(n >= 0 && n < BITCOUNT); ImBitArrayClearBit(Storage, n); } - void SetBitRange(int n, int n2) { n += OFFSET; n2 += OFFSET; IM_ASSERT(n >= 0 && n < BITCOUNT && n2 > n && n2 <= BITCOUNT); ImBitArraySetBitRange(Storage, n, n2); } // Works on range [n..n2) - bool operator[](int n) const { return TestBit(n); } - bool operator&(int n) const { return TestBit(n); } - bool operator==(ImBitArray const &a) const - { - for (int i = 0; i < ((BITCOUNT + 31) >> 5); ++i) - if (Storage[i] != a.Storage[i]) - return false; - return true; - } - bool operator!=(ImBitArray const &a) const - { - for (int i = 0; i < ((BITCOUNT + 31) >> 5); ++i) - if (Storage[i] == a.Storage[i]) - return false; - return true; - } - template bool operator==(ImBitArray const &a) const - { - for (int i = 0; i < ImMin((DSTBITCOUNT + 31) >> 5, (BITCOUNT + 31) >> 5); ++i) - if (Storage[i] != a.Storage[i]) - return false; - return true; - } - template bool operator!=(ImBitArray const &a) const - { - for (int i = 0; i < ImMin((DSTBITCOUNT + 31) >> 5, (BITCOUNT + 31) >> 5); ++i) - if (Storage[i] == a.Storage[i]) - return false; - return true; - } + ImBitArray() { ClearAllBits(); } + void ClearAllBits() { memset(Storage, 0, sizeof(Storage)); } + void SetAllBits() { memset(Storage, 255, sizeof(Storage)); } + bool TestBit(int n) const { n += OFFSET; IM_ASSERT(n >= 0 && n < BITCOUNT); return IM_BITARRAY_TESTBIT(Storage, n); } + void SetBit(int n) { n += OFFSET; IM_ASSERT(n >= 0 && n < BITCOUNT); ImBitArraySetBit(Storage, n); } + void ClearBit(int n) { n += OFFSET; IM_ASSERT(n >= 0 && n < BITCOUNT); ImBitArrayClearBit(Storage, n); } + void SetBitRange(int n, int n2) { n += OFFSET; n2 += OFFSET; IM_ASSERT(n >= 0 && n < BITCOUNT && n2 > n && n2 <= BITCOUNT); ImBitArraySetBitRange(Storage, n, n2); } // Works on range [n..n2) + bool operator[](int n) const { n += OFFSET; IM_ASSERT(n >= 0 && n < BITCOUNT); return IM_BITARRAY_TESTBIT(Storage, n); } }; // Helper: ImBitVector @@ -603,28 +591,13 @@ struct ImBitArray struct IMGUI_API ImBitVector { ImVector Storage; - int BitCount = 0; - ImBitVector(int sz = 0) { if (sz > 0) { Create(sz); } } - void Create(int sz) { BitCount = sz; Storage.resize((sz + 31) >> 5); Storage.fill(0); } - void Clear() { Storage.clear(); } - void ClearAllBits() { Storage.fill(0); } - void SetAllBits() { Storage.fill(~0); } - bool TestBit(int n) const { IM_ASSERT(n >= 0 && n < BitCount); return ImBitArrayTestBit(Storage.Data, n); } - void SetBit(int n) { IM_ASSERT(n >= 0 && n < BitCount); ImBitArraySetBit(Storage.Data, n); } - void SetBitRange(int n, int n2) { IM_ASSERT(n >= 0 && n < BitCount && n2 > n && n2 <= BitCount); ImBitArraySetBitRange(Storage.Data, n, n2); } // Works on range [n..n2) - void ClearBit(int n) { IM_ASSERT(n >= 0 && n < BitCount); ImBitArrayClearBit(Storage.Data, n); } - bool CheckEqual(ImBitVector const &a) const - { - for (int i = 0; i < ImMin((a.BitCount + 31) >> 5, (BitCount + 31) >> 5); ++i) - if (Storage[i] != a.Storage[i]) - return false; - return true; - } - bool operator[](int n) const { return TestBit(n); } - bool operator&(int n) const { return TestBit(n); } - bool operator==(ImBitVector const &a) const { return CheckEqual(a); } - bool operator!=(ImBitVector const &a) const { return !CheckEqual(a); } + void Create(int sz) { Storage.resize((sz + 31) >> 5); memset(Storage.Data, 0, (size_t)Storage.Size * sizeof(Storage.Data[0])); } + void Clear() { Storage.clear(); } + bool TestBit(int n) const { IM_ASSERT(n < (Storage.Size << 5)); return IM_BITARRAY_TESTBIT(Storage.Data, n); } + void SetBit(int n) { IM_ASSERT(n < (Storage.Size << 5)); ImBitArraySetBit(Storage.Data, n); } + void ClearBit(int n) { IM_ASSERT(n < (Storage.Size << 5)); ImBitArrayClearBit(Storage.Data, n); } }; +IM_MSVC_RUNTIME_CHECKS_RESTORE // Helper: ImSpan<> // Pointing to a span of data we don't own. @@ -737,6 +710,20 @@ struct ImChunkStream }; +// Helper: ImGuiTextIndex<> +// Maintain a line index for a text buffer. This is a strong candidate to be moved into the public API. +struct ImGuiTextIndex +{ + ImVector LineOffsets; + int EndOffset = 0; // Because we don't own text buffer we need to maintain EndOffset (may bake in LineOffsets?) + + void clear() { LineOffsets.clear(); EndOffset = 0; } + int size() { return LineOffsets.Size; } + const char* get_line_begin(const char* base, int n) { return base + LineOffsets[n]; } + const char* get_line_end(const char* base, int n) { return base + (n + 1 < LineOffsets.Size ? (LineOffsets[n + 1] - 1) : EndOffset); } + void append(const char* base, int old_size, int new_size); +}; + //----------------------------------------------------------------------------- // [SECTION] ImDrawList support //----------------------------------------------------------------------------- @@ -778,6 +765,9 @@ struct IMGUI_API ImDrawListSharedData ImVec4 ClipRectFullscreen; // Value for PushClipRectFullscreen() ImDrawListFlags InitialFlags; // Initial flags at the beginning of the frame (it is possible to alter flags on a per-drawlist basis afterwards) + // [Internal] Temp write buffer + ImVector TempBuffer; + // [Internal] Lookup tables ImVec2 ArcFastVtx[IM_DRAWLIST_ARCFAST_TABLE_SIZE]; // Sample points on the quarter of the circle. float ArcFastRadiusCutoff; // Cutoff radius after which arc drawing will fallback to slower PathArcTo() @@ -802,24 +792,32 @@ struct ImDrawDataBuilder // [SECTION] Widgets support: flags, enums, data structures //----------------------------------------------------------------------------- -// Transient per-window flags, reset at the beginning of the frame. For child window, inherited from parent on first Begin(). +// Flags used by upcoming items +// - input: PushItemFlag() manipulates g.CurrentItemFlags, ItemAdd() calls may add extra flags. +// - output: stored in g.LastItemData.InFlags +// Current window shared by all windows. // This is going to be exposed in imgui.h when stabilized enough. enum ImGuiItemFlags_ { + // Controlled by user ImGuiItemFlags_None = 0, - ImGuiItemFlags_NoTabStop = 1 << 0, // false // Disable keyboard tabbing (FIXME: should merge with _NoNav) + ImGuiItemFlags_NoTabStop = 1 << 0, // false // Disable keyboard tabbing. This is a "lighter" version of ImGuiItemFlags_NoNav. ImGuiItemFlags_ButtonRepeat = 1 << 1, // false // Button() will return true multiple times based on io.KeyRepeatDelay and io.KeyRepeatRate settings. ImGuiItemFlags_Disabled = 1 << 2, // false // Disable interactions but doesn't affect visuals. See BeginDisabled()/EndDisabled(). See github.com/ocornut/imgui/issues/211 - ImGuiItemFlags_NoNav = 1 << 3, // false // Disable keyboard/gamepad directional navigation (FIXME: should merge with _NoTabStop) + ImGuiItemFlags_NoNav = 1 << 3, // false // Disable any form of focusing (keyboard/gamepad directional navigation and SetKeyboardFocusHere() calls) ImGuiItemFlags_NoNavDefaultFocus = 1 << 4, // false // Disable item being a candidate for default focus (e.g. used by title bar items) ImGuiItemFlags_SelectableDontClosePopup = 1 << 5, // false // Disable MenuItem/Selectable() automatically closing their popup window ImGuiItemFlags_MixedValue = 1 << 6, // false // [BETA] Represent a mixed/indeterminate value, generally multi-selection where values differ. Currently only supported by Checkbox() (later should support all sorts of widgets) ImGuiItemFlags_ReadOnly = 1 << 7, // false // [ALPHA] Allow hovering interactions but underlying value is not changed. - ImGuiItemFlags_Inputable = 1 << 8, // false // [WIP] Auto-activate input mode when tab focused. Currently only used and supported by a few items before it becomes a generic feature. - ImGuiItemFlags_NoInertialScroll = 1 << 9 // false // Disable inertial scroll when activated + ImGuiItemFlags_NoWindowHoverableCheck = 1 << 8, // false // Disable hoverable check in ItemHoverable() + + // Controlled by widget code + ImGuiItemFlags_Inputable = 1 << 10, // false // [WIP] Auto-activate input mode when tab focused. Currently only used and supported by a few items before it becomes a generic feature. + ImGuiItemFlags_NoInertialScroll = 1 << 11, // false // Disable inertial scroll when activated }; -// Storage for LastItem data +// Status flags for an already submitted item +// - output: stored in g.LastItemData.StatusFlags enum ImGuiItemStatusFlags_ { ImGuiItemStatusFlags_None = 0, @@ -831,14 +829,16 @@ enum ImGuiItemStatusFlags_ ImGuiItemStatusFlags_HasDeactivated = 1 << 5, // Set if the widget/group is able to provide data for the ImGuiItemStatusFlags_Deactivated flag. ImGuiItemStatusFlags_Deactivated = 1 << 6, // Only valid if ImGuiItemStatusFlags_HasDeactivated is set. ImGuiItemStatusFlags_HoveredWindow = 1 << 7, // Override the HoveredWindow test to allow cross-window hover testing. - ImGuiItemStatusFlags_FocusedByTabbing = 1 << 8 // Set when the Focusable item just got focused by Tabbing (FIXME: to be removed soon) + ImGuiItemStatusFlags_FocusedByTabbing = 1 << 8, // Set when the Focusable item just got focused by Tabbing (FIXME: to be removed soon) + ImGuiItemStatusFlags_Visible = 1 << 9, // [WIP] Set when item is overlapping the current clipping rectangle (Used internally. Please don't use yet: API/system will change as we refactor Itemadd()). + // Additional status + semantic for ImGuiTestEngine #ifdef IMGUI_ENABLE_TEST_ENGINE - , // [imgui_tests only] ImGuiItemStatusFlags_Openable = 1 << 20, // Item is an openable (e.g. TreeNode) - ImGuiItemStatusFlags_Opened = 1 << 21, // + ImGuiItemStatusFlags_Opened = 1 << 21, // Opened status ImGuiItemStatusFlags_Checkable = 1 << 22, // Item is a checkable (e.g. CheckBox, MenuItem) - ImGuiItemStatusFlags_Checked = 1 << 23 // + ImGuiItemStatusFlags_Checked = 1 << 23, // Checked status + ImGuiItemStatusFlags_Inputable = 1 << 24, // Item is a text-inputable (e.g. InputText, SliderXXX, DragXXX) #endif }; @@ -848,7 +848,7 @@ enum ImGuiInputTextFlagsPrivate_ // [Internal] ImGuiInputTextFlags_Multiline = 1 << 26, // For internal use by InputTextMultiline() ImGuiInputTextFlags_NoMarkEdited = 1 << 27, // For internal use by functions using InputText() before reformatting data - ImGuiInputTextFlags_MergedItem = 1 << 28 // For internal use by TempInputText(), will skip calling ItemAdd(). Require bounding-box to strictly match. + ImGuiInputTextFlags_MergedItem = 1 << 28, // For internal use by TempInputText(), will skip calling ItemAdd(). Require bounding-box to strictly match. }; // Extend ImGuiButtonFlags_ @@ -868,23 +868,25 @@ enum ImGuiButtonFlagsPrivate_ ImGuiButtonFlags_AlignTextBaseLine = 1 << 15, // vertically align button to match text baseline - ButtonEx() only // FIXME: Should be removed and handled by SmallButton(), not possible currently because of DC.CursorPosPrevLine ImGuiButtonFlags_NoKeyModifiers = 1 << 16, // disable mouse interaction if a key modifier is held ImGuiButtonFlags_NoHoldingActiveId = 1 << 17, // don't set ActiveId while holding the mouse (ImGuiButtonFlags_PressedOnClick only) - ImGuiButtonFlags_NoNavFocus = 1 << 18, // don't override navigation focus when activated + ImGuiButtonFlags_NoNavFocus = 1 << 18, // don't override navigation focus when activated (FIXME: this is essentially used everytime an item uses ImGuiItemFlags_NoNav, but because legacy specs don't requires LastItemData to be set ButtonBehavior(), we can't poll g.LastItemData.InFlags) ImGuiButtonFlags_NoHoveredOnFocus = 1 << 19, // don't report as hovered when nav focus is on this item + ImGuiButtonFlags_NoSetKeyOwner = 1 << 20, // don't set key/input owner on the initial click (note: mouse buttons are keys! often, the key in question will be ImGuiKey_MouseLeft!) + ImGuiButtonFlags_NoTestKeyOwner = 1 << 21, // don't test key/input owner when polling the key (note: mouse buttons are keys! often, the key in question will be ImGuiKey_MouseLeft!) ImGuiButtonFlags_PressedOnMask_ = ImGuiButtonFlags_PressedOnClick | ImGuiButtonFlags_PressedOnClickRelease | ImGuiButtonFlags_PressedOnClickReleaseAnywhere | ImGuiButtonFlags_PressedOnRelease | ImGuiButtonFlags_PressedOnDoubleClick | ImGuiButtonFlags_PressedOnDragDropHold, - ImGuiButtonFlags_PressedOnDefault_ = ImGuiButtonFlags_PressedOnClickRelease + ImGuiButtonFlags_PressedOnDefault_ = ImGuiButtonFlags_PressedOnClickRelease, }; // Extend ImGuiComboFlags_ enum ImGuiComboFlagsPrivate_ { - ImGuiComboFlags_CustomPreview = 1 << 20 // enable BeginComboPreview() + ImGuiComboFlags_CustomPreview = 1 << 20, // enable BeginComboPreview() }; // Extend ImGuiSliderFlags_ enum ImGuiSliderFlagsPrivate_ { ImGuiSliderFlags_Vertical = 1 << 20, // Should this slider be orientated vertically? - ImGuiSliderFlags_ReadOnly = 1 << 21 + ImGuiSliderFlags_ReadOnly = 1 << 21, }; // Extend ImGuiSelectableFlags_ @@ -896,35 +898,45 @@ enum ImGuiSelectableFlagsPrivate_ ImGuiSelectableFlags_SelectOnClick = 1 << 22, // Override button behavior to react on Click (default is Click+Release) ImGuiSelectableFlags_SelectOnRelease = 1 << 23, // Override button behavior to react on Release (default is Click+Release) ImGuiSelectableFlags_SpanAvailWidth = 1 << 24, // Span all avail width even if we declared less for layout purpose. FIXME: We may be able to remove this (added in 6251d379, 2bcafc86 for menus) - ImGuiSelectableFlags_DrawHoveredWhenHeld = 1 << 25, // Always show active when held, even is not hovered. This concept could probably be renamed/formalized somehow. - ImGuiSelectableFlags_SetNavIdOnHover = 1 << 26, // Set Nav/Focus ID on mouse hover (used by MenuItem) - ImGuiSelectableFlags_NoPadWithHalfSpacing = 1 << 27 // Disable padding each side with ItemSpacing * 0.5f + ImGuiSelectableFlags_SetNavIdOnHover = 1 << 25, // Set Nav/Focus ID on mouse hover (used by MenuItem) + ImGuiSelectableFlags_NoPadWithHalfSpacing = 1 << 26, // Disable padding each side with ItemSpacing * 0.5f + ImGuiSelectableFlags_NoSetKeyOwner = 1 << 27, // Don't set key/input owner on the initial click (note: mouse buttons are keys! often, the key in question will be ImGuiKey_MouseLeft!) }; // Extend ImGuiTreeNodeFlags_ enum ImGuiTreeNodeFlagsPrivate_ { - ImGuiTreeNodeFlags_ClipLabelForTrailingButton = 1 << 20 + ImGuiTreeNodeFlags_ClipLabelForTrailingButton = 1 << 20, }; enum ImGuiSeparatorFlags_ { - ImGuiSeparatorFlags_None = 0, - ImGuiSeparatorFlags_Horizontal = 1 << 0, // Axis default to current layout type, so generally Horizontal unless e.g. in a menu bar - ImGuiSeparatorFlags_Vertical = 1 << 1, - ImGuiSeparatorFlags_SpanAllColumns = 1 << 2 + ImGuiSeparatorFlags_None = 0, + ImGuiSeparatorFlags_Horizontal = 1 << 0, // Axis default to current layout type, so generally Horizontal unless e.g. in a menu bar + ImGuiSeparatorFlags_Vertical = 1 << 1, + ImGuiSeparatorFlags_SpanAllColumns = 1 << 2, // Make separator cover all columns of a legacy Columns() set. +}; + +// Flags for FocusWindow(). This is not called ImGuiFocusFlags to avoid confusion with public-facing ImGuiFocusedFlags. +// FIXME: Once we finishing replacing more uses of GetTopMostPopupModal()+IsWindowWithinBeginStackOf() +// and FindBlockingModal() with this, we may want to change the flag to be opt-out instead of opt-in. +enum ImGuiFocusRequestFlags_ +{ + ImGuiFocusRequestFlags_None = 0, + ImGuiFocusRequestFlags_RestoreFocusedChild = 1 << 0, // Find last focused child (if any) and focus it instead. + ImGuiFocusRequestFlags_UnlessBelowModal = 1 << 1, // Do not set focus if the window is below a modal. }; enum ImGuiTextFlags_ { - ImGuiTextFlags_None = 0, - ImGuiTextFlags_NoWidthForLargeClippedText = 1 << 0 + ImGuiTextFlags_None = 0, + ImGuiTextFlags_NoWidthForLargeClippedText = 1 << 0, }; enum ImGuiTooltipFlags_ { - ImGuiTooltipFlags_None = 0, - ImGuiTooltipFlags_OverridePreviousTooltip = 1 << 0 // Override will clear/ignore previously submitted tooltip (defaults to append) + ImGuiTooltipFlags_None = 0, + ImGuiTooltipFlags_OverridePreviousTooltip = 1 << 0, // Override will clear/ignore previously submitted tooltip (defaults to append) }; // FIXME: this is in development, not exposed/functional as a generic feature yet. @@ -941,7 +953,7 @@ enum ImGuiLogType ImGuiLogType_TTY, ImGuiLogType_File, ImGuiLogType_Buffer, - ImGuiLogType_Clipboard + ImGuiLogType_Clipboard, }; // X/Y enums are fixed to 0/1 so they may be used to index ImVec2 @@ -955,14 +967,22 @@ enum ImGuiAxis enum ImGuiPlotType { ImGuiPlotType_Lines, - ImGuiPlotType_Histogram + ImGuiPlotType_Histogram, }; enum ImGuiPopupPositionPolicy { ImGuiPopupPositionPolicy_Default, ImGuiPopupPositionPolicy_ComboBox, - ImGuiPopupPositionPolicy_Tooltip + ImGuiPopupPositionPolicy_Tooltip, +}; + +struct ImGuiDataVarInfo +{ + ImGuiDataType Type; + ImU32 Count; // 1+ + ImU32 Offset; // Offset in parent structure + void* GetVarPtr(void* parent) const { return (void*)((unsigned char*)parent + Offset); } }; struct ImGuiDataTypeTempStorage @@ -984,7 +1004,7 @@ enum ImGuiDataTypePrivate_ { ImGuiDataType_String = ImGuiDataType_COUNT + 1, ImGuiDataType_Pointer, - ImGuiDataType_ID + ImGuiDataType_ID, }; // Stacked color modifier, backup of modified data so we can restore it @@ -1051,10 +1071,20 @@ struct IMGUI_API ImGuiMenuColumns void CalcNextTotalWidth(bool update_offsets); }; +// Internal temporary state for deactivating InputText() instances. +struct IMGUI_API ImGuiInputTextDeactivatedState +{ + ImGuiID ID; // widget id owning the text state (which just got deactivated) + ImVector TextA; // text buffer + + ImGuiInputTextDeactivatedState() { memset(this, 0, sizeof(*this)); } + void ClearFreeMemory() { ID = 0; TextA.clear(); } +}; // Internal state of the currently focused/edited text input box // For a given item ID, access with ImGui::GetInputTextState() struct IMGUI_API ImGuiInputTextState { + ImGuiContext* Ctx; // parent UI context (needs to be set explicitly by parent). ImGuiID ID; // widget id owning the text state int CurLenW, CurLenA; // we need to maintain our buffer length in both UTF-8 and wchar format. UTF-8 length is valid even if TextA is not. ImVector TextW; // edit buffer, we need to persist but can't guarantee the persistence of the user-provided buffer. so we copy into own buffer. @@ -1068,7 +1098,7 @@ struct IMGUI_API ImGuiInputTextState bool CursorFollow; // set when we want scrolling to follow the current cursor position (not always!) bool SelectedAllMouseLock; // after a double-click to select all, we ignore further mouse drags to update selection bool Edited; // edited this frame - ImGuiInputTextFlags Flags; // copy of InputText() flags + ImGuiInputTextFlags Flags; // copy of InputText() flags. may be used to check if e.g. ImGuiInputTextFlags_Password is set. ImGuiInputTextState() { memset(this, 0, sizeof(*this)); } void ClearText() { CurLenW = CurLenA = 0; TextW[0] = 0; TextA[0] = 0; CursorClamp(); } @@ -1093,13 +1123,14 @@ struct ImGuiPopupData { ImGuiID PopupId; // Set on OpenPopup() ImGuiWindow* Window; // Resolved on BeginPopup() - may stay unresolved if user never calls OpenPopup() - ImGuiWindow* SourceWindow; // Set on OpenPopup() copy of NavWindow at the time of opening the popup + ImGuiWindow* BackupNavWindow;// Set on OpenPopup(), a NavWindow that will be restored on popup close + int ParentNavLayer; // Resolved on BeginPopup(). Actually a ImGuiNavLayer type (declared down below), initialized to -1 which is not part of an enum, but serves well-enough as "not any of layers" value int OpenFrameCount; // Set on OpenPopup() ImGuiID OpenParentId; // Set on OpenPopup(), we need this to differentiate multiple menu sets from each others (e.g. inside menu bar vs loose menu items) ImVec2 OpenPopupPos; // Set on OpenPopup(), preferred popup position (typically == OpenMousePos when using mouse) ImVec2 OpenMousePos; // Set on OpenPopup(), copy of mouse position at the time of opening popup - ImGuiPopupData() { memset(this, 0, sizeof(*this)); OpenFrameCount = -1; } + ImGuiPopupData() { memset(this, 0, sizeof(*this)); ParentNavLayer = OpenFrameCount = -1; } }; enum ImGuiNextWindowDataFlags_ @@ -1115,7 +1146,7 @@ enum ImGuiNextWindowDataFlags_ ImGuiNextWindowDataFlags_HasScroll = 1 << 7, ImGuiNextWindowDataFlags_HasViewport = 1 << 8, ImGuiNextWindowDataFlags_HasDock = 1 << 9, - ImGuiNextWindowDataFlags_HasWindowClass = 1 << 10 + ImGuiNextWindowDataFlags_HasWindowClass = 1 << 10, }; // Storage for SetNexWindow** functions @@ -1150,7 +1181,7 @@ enum ImGuiNextItemDataFlags_ { ImGuiNextItemDataFlags_None = 0, ImGuiNextItemDataFlags_HasWidth = 1 << 0, - ImGuiNextItemDataFlags_HasOpen = 1 << 1 + ImGuiNextItemDataFlags_HasOpen = 1 << 1, }; struct ImGuiNextItemData @@ -1191,8 +1222,8 @@ struct IMGUI_API ImGuiStackSizes short SizeOfDisabledStack; ImGuiStackSizes() { memset(this, 0, sizeof(*this)); } - void SetToCurrentState(); - void CompareWithCurrentState(); + void SetToContextState(ImGuiContext* ctx); + void CompareWithContextState(ImGuiContext* ctx); }; // Data saved for each window pushed into the stack @@ -1207,6 +1238,7 @@ struct ImGuiShrinkWidthItem { int Index; float Width; + float InitialWidth; }; struct ImGuiPtrOrIndex @@ -1222,15 +1254,30 @@ struct ImGuiPtrOrIndex // [SECTION] Inputs support //----------------------------------------------------------------------------- +// Bit array for named keys typedef ImBitArray ImBitArrayForNamedKeys; -enum ImGuiKeyPrivate_ -{ - ImGuiKey_LegacyNativeKey_BEGIN = 0, - ImGuiKey_LegacyNativeKey_END = 512, - ImGuiKey_Gamepad_BEGIN = ImGuiKey_GamepadStart, - ImGuiKey_Gamepad_END = ImGuiKey_GamepadRStickRight + 1 -}; +// [Internal] Key ranges +#define ImGuiKey_LegacyNativeKey_BEGIN 0 +#define ImGuiKey_LegacyNativeKey_END 512 +#define ImGuiKey_Keyboard_BEGIN (ImGuiKey_NamedKey_BEGIN) +#define ImGuiKey_Keyboard_END (ImGuiKey_GamepadStart) +#define ImGuiKey_Gamepad_BEGIN (ImGuiKey_GamepadStart) +#define ImGuiKey_Gamepad_END (ImGuiKey_GamepadRStickDown + 1) +#define ImGuiKey_Mouse_BEGIN (ImGuiKey_MouseLeft) +#define ImGuiKey_Mouse_END (ImGuiKey_MouseWheelY + 1) +#define ImGuiKey_Aliases_BEGIN (ImGuiKey_Mouse_BEGIN) +#define ImGuiKey_Aliases_END (ImGuiKey_Mouse_END) + +// [Internal] Named shortcuts for Navigation +#define ImGuiKey_NavKeyboardTweakSlow ImGuiMod_Ctrl +#define ImGuiKey_NavKeyboardTweakFast ImGuiMod_Shift +#define ImGuiKey_NavGamepadTweakSlow ImGuiKey_GamepadL1 +#define ImGuiKey_NavGamepadTweakFast ImGuiKey_GamepadR1 +#define ImGuiKey_NavGamepadActivate ImGuiKey_GamepadFaceDown +#define ImGuiKey_NavGamepadCancel ImGuiKey_GamepadFaceRight +#define ImGuiKey_NavGamepadMenu ImGuiKey_GamepadFaceLeft +#define ImGuiKey_NavGamepadInput ImGuiKey_GamepadFaceUp enum ImGuiInputEventType { @@ -1248,19 +1295,18 @@ enum ImGuiInputEventType enum ImGuiInputSource { ImGuiInputSource_None = 0, - ImGuiInputSource_Mouse, + ImGuiInputSource_Mouse, // Note: may be Mouse or TouchScreen or Pen. See io.MouseSource to distinguish them. ImGuiInputSource_Keyboard, ImGuiInputSource_Gamepad, ImGuiInputSource_Clipboard, // Currently only used by InputText() - ImGuiInputSource_Nav, // Stored in g.ActiveIdSource only ImGuiInputSource_COUNT }; // FIXME: Structures in the union below need to be declared as anonymous unions appears to be an extension? // Using ImVec2() would fail on Clang 'union member 'MousePos' has a non-trivial default constructor' -struct ImGuiInputEventMousePos { float PosX, PosY; }; -struct ImGuiInputEventMouseWheel { float WheelX, WheelY; }; -struct ImGuiInputEventMouseButton { int Button; bool Down; }; +struct ImGuiInputEventMousePos { float PosX, PosY; ImGuiMouseSource MouseSource; }; +struct ImGuiInputEventMouseWheel { float WheelX, WheelY; ImGuiMouseSource MouseSource; }; +struct ImGuiInputEventMouseButton { int Button; bool Down; ImGuiMouseSource MouseSource; }; struct ImGuiInputEventMouseViewport { ImGuiID HoveredViewportID; }; struct ImGuiInputEventKey { ImGuiKey Key; bool Down; float AnalogValue; }; struct ImGuiInputEventText { unsigned int Char; }; @@ -1270,6 +1316,7 @@ struct ImGuiInputEvent { ImGuiInputEventType Type; ImGuiInputSource Source; + ImU32 EventId; // Unique, sequential increasing integer to identify an event (if you need to correlate them to other data). union { ImGuiInputEventMousePos MousePos; // if Type == ImGuiInputEventType_MousePos @@ -1285,21 +1332,101 @@ struct ImGuiInputEvent ImGuiInputEvent() { memset(this, 0, sizeof(*this)); } }; -// FIXME-NAV: Clarify/expose various repeat delay/rate -enum ImGuiNavReadMode +// Input function taking an 'ImGuiID owner_id' argument defaults to (ImGuiKeyOwner_Any == 0) aka don't test ownership, which matches legacy behavior. +#define ImGuiKeyOwner_Any ((ImGuiID)0) // Accept key that have an owner, UNLESS a call to SetKeyOwner() explicitly used ImGuiInputFlags_LockThisFrame or ImGuiInputFlags_LockUntilRelease. +#define ImGuiKeyOwner_None ((ImGuiID)-1) // Require key to have no owner. + +typedef ImS16 ImGuiKeyRoutingIndex; + +// Routing table entry (sizeof() == 16 bytes) +struct ImGuiKeyRoutingData { - ImGuiNavReadMode_Down, - ImGuiNavReadMode_Pressed, - ImGuiNavReadMode_Released, - ImGuiNavReadMode_Repeat, - ImGuiNavReadMode_RepeatSlow, - ImGuiNavReadMode_RepeatFast + ImGuiKeyRoutingIndex NextEntryIndex; + ImU16 Mods; // Technically we'd only need 4-bits but for simplify we store ImGuiMod_ values which need 16-bits. ImGuiMod_Shortcut is already translated to Ctrl/Super. + ImU8 RoutingNextScore; // Lower is better (0: perfect score) + ImGuiID RoutingCurr; + ImGuiID RoutingNext; + + ImGuiKeyRoutingData() { NextEntryIndex = -1; Mods = 0; RoutingNextScore = 255; RoutingCurr = RoutingNext = ImGuiKeyOwner_None; } +}; + +// Routing table: maintain a desired owner for each possible key-chord (key + mods), and setup owner in NewFrame() when mods are matching. +// Stored in main context (1 instance) +struct ImGuiKeyRoutingTable +{ + ImGuiKeyRoutingIndex Index[ImGuiKey_NamedKey_COUNT]; // Index of first entry in Entries[] + ImVector Entries; + ImVector EntriesNext; // Double-buffer to avoid reallocation (could use a shared buffer) + + ImGuiKeyRoutingTable() { Clear(); } + void Clear() { for (int n = 0; n < IM_ARRAYSIZE(Index); n++) Index[n] = -1; Entries.clear(); EntriesNext.clear(); } +}; + +// This extends ImGuiKeyData but only for named keys (legacy keys don't support the new features) +// Stored in main context (1 per named key). In the future it might be merged into ImGuiKeyData. +struct ImGuiKeyOwnerData +{ + ImGuiID OwnerCurr; + ImGuiID OwnerNext; + bool LockThisFrame; // Reading this key requires explicit owner id (until end of frame). Set by ImGuiInputFlags_LockThisFrame. + bool LockUntilRelease; // Reading this key requires explicit owner id (until key is released). Set by ImGuiInputFlags_LockUntilRelease. When this is true LockThisFrame is always true as well. + + ImGuiKeyOwnerData() { OwnerCurr = OwnerNext = ImGuiKeyOwner_None; LockThisFrame = LockUntilRelease = false; } +}; + +// Flags for extended versions of IsKeyPressed(), IsMouseClicked(), Shortcut(), SetKeyOwner(), SetItemKeyOwner() +// Don't mistake with ImGuiInputTextFlags! (for ImGui::InputText() function) +enum ImGuiInputFlags_ +{ + // Flags for IsKeyPressed(), IsMouseClicked(), Shortcut() + ImGuiInputFlags_None = 0, + ImGuiInputFlags_Repeat = 1 << 0, // Return true on successive repeats. Default for legacy IsKeyPressed(). NOT Default for legacy IsMouseClicked(). MUST BE == 1. + ImGuiInputFlags_RepeatRateDefault = 1 << 1, // Repeat rate: Regular (default) + ImGuiInputFlags_RepeatRateNavMove = 1 << 2, // Repeat rate: Fast + ImGuiInputFlags_RepeatRateNavTweak = 1 << 3, // Repeat rate: Faster + ImGuiInputFlags_RepeatRateMask_ = ImGuiInputFlags_RepeatRateDefault | ImGuiInputFlags_RepeatRateNavMove | ImGuiInputFlags_RepeatRateNavTweak, + + // Flags for SetItemKeyOwner() + ImGuiInputFlags_CondHovered = 1 << 4, // Only set if item is hovered (default to both) + ImGuiInputFlags_CondActive = 1 << 5, // Only set if item is active (default to both) + ImGuiInputFlags_CondDefault_ = ImGuiInputFlags_CondHovered | ImGuiInputFlags_CondActive, + ImGuiInputFlags_CondMask_ = ImGuiInputFlags_CondHovered | ImGuiInputFlags_CondActive, + + // Flags for SetKeyOwner(), SetItemKeyOwner() + ImGuiInputFlags_LockThisFrame = 1 << 6, // Access to key data will require EXPLICIT owner ID (ImGuiKeyOwner_Any/0 will NOT accepted for polling). Cleared at end of frame. This is useful to make input-owner-aware code steal keys from non-input-owner-aware code. + ImGuiInputFlags_LockUntilRelease = 1 << 7, // Access to key data will require EXPLICIT owner ID (ImGuiKeyOwner_Any/0 will NOT accepted for polling). Cleared when the key is released or at end of each frame if key is released. This is useful to make input-owner-aware code steal keys from non-input-owner-aware code. + + // Routing policies for Shortcut() + low-level SetShortcutRouting() + // - The general idea is that several callers register interest in a shortcut, and only one owner gets it. + // - When a policy (other than _RouteAlways) is set, Shortcut() will register itself with SetShortcutRouting(), + // allowing the system to decide where to route the input among other route-aware calls. + // - Shortcut() uses ImGuiInputFlags_RouteFocused by default: meaning that a simple Shortcut() poll + // will register a route and only succeed when parent window is in the focus stack and if no-one + // with a higher priority is claiming the shortcut. + // - Using ImGuiInputFlags_RouteAlways is roughly equivalent to doing e.g. IsKeyPressed(key) + testing mods. + // - Priorities: GlobalHigh > Focused (when owner is active item) > Global > Focused (when focused window) > GlobalLow. + // - Can select only 1 policy among all available. + ImGuiInputFlags_RouteFocused = 1 << 8, // (Default) Register focused route: Accept inputs if window is in focus stack. Deep-most focused window takes inputs. ActiveId takes inputs over deep-most focused window. + ImGuiInputFlags_RouteGlobalLow = 1 << 9, // Register route globally (lowest priority: unless a focused window or active item registered the route) -> recommended Global priority. + ImGuiInputFlags_RouteGlobal = 1 << 10, // Register route globally (medium priority: unless an active item registered the route, e.g. CTRL+A registered by InputText). + ImGuiInputFlags_RouteGlobalHigh = 1 << 11, // Register route globally (highest priority: unlikely you need to use that: will interfere with every active items) + ImGuiInputFlags_RouteMask_ = ImGuiInputFlags_RouteFocused | ImGuiInputFlags_RouteGlobal | ImGuiInputFlags_RouteGlobalLow | ImGuiInputFlags_RouteGlobalHigh, // _Always not part of this! + ImGuiInputFlags_RouteAlways = 1 << 12, // Do not register route, poll keys directly. + ImGuiInputFlags_RouteUnlessBgFocused= 1 << 13, // Global routes will not be applied if underlying background/void is focused (== no Dear ImGui windows are focused). Useful for overlay applications. + ImGuiInputFlags_RouteExtraMask_ = ImGuiInputFlags_RouteAlways | ImGuiInputFlags_RouteUnlessBgFocused, + + // [Internal] Mask of which function support which flags + ImGuiInputFlags_SupportedByIsKeyPressed = ImGuiInputFlags_Repeat | ImGuiInputFlags_RepeatRateMask_, + ImGuiInputFlags_SupportedByShortcut = ImGuiInputFlags_Repeat | ImGuiInputFlags_RepeatRateMask_ | ImGuiInputFlags_RouteMask_ | ImGuiInputFlags_RouteExtraMask_, + ImGuiInputFlags_SupportedBySetKeyOwner = ImGuiInputFlags_LockThisFrame | ImGuiInputFlags_LockUntilRelease, + ImGuiInputFlags_SupportedBySetItemKeyOwner = ImGuiInputFlags_SupportedBySetKeyOwner | ImGuiInputFlags_CondMask_, }; //----------------------------------------------------------------------------- // [SECTION] Clipper support //----------------------------------------------------------------------------- +// Note that Max is exclusive, so perhaps should be using a Begin/End convention. struct ImGuiListClipperRange { int Min; @@ -1332,9 +1459,9 @@ struct ImGuiListClipperData enum ImGuiActivateFlags_ { ImGuiActivateFlags_None = 0, - ImGuiActivateFlags_PreferInput = 1 << 0, // Favor activation that requires keyboard text input (e.g. for Slider/Drag). Default if keyboard is available. - ImGuiActivateFlags_PreferTweak = 1 << 1, // Favor activation for tweaking with arrows or gamepad (e.g. for Slider/Drag). Default if keyboard is not available. - ImGuiActivateFlags_TryToPreserveState = 1 << 2 // Request widget to preserve state if it can (e.g. InputText will try to preserve cursor/selection) + ImGuiActivateFlags_PreferInput = 1 << 0, // Favor activation that requires keyboard text input (e.g. for Slider/Drag). Default for Enter key. + ImGuiActivateFlags_PreferTweak = 1 << 1, // Favor activation for tweaking with arrows or gamepad (e.g. for Slider/Drag). Default for Space key and if keyboard is not used. + ImGuiActivateFlags_TryToPreserveState = 1 << 2, // Request widget to preserve state if it can (e.g. InputText will try to preserve cursor/selection) }; // Early work-in-progress API for ScrollToItem() @@ -1349,7 +1476,7 @@ enum ImGuiScrollFlags_ ImGuiScrollFlags_AlwaysCenterY = 1 << 5, // Always center the result item on Y axis [default for Y axis for appearing window) ImGuiScrollFlags_NoScrollParent = 1 << 6, // Disable forwarding scrolling to parent window if required to keep item/rect visible (only scroll window the function was applied to). ImGuiScrollFlags_MaskX_ = ImGuiScrollFlags_KeepVisibleEdgeX | ImGuiScrollFlags_KeepVisibleCenterX | ImGuiScrollFlags_AlwaysCenterX, - ImGuiScrollFlags_MaskY_ = ImGuiScrollFlags_KeepVisibleEdgeY | ImGuiScrollFlags_KeepVisibleCenterY | ImGuiScrollFlags_AlwaysCenterY + ImGuiScrollFlags_MaskY_ = ImGuiScrollFlags_KeepVisibleEdgeY | ImGuiScrollFlags_KeepVisibleCenterY | ImGuiScrollFlags_AlwaysCenterY, }; enum ImGuiNavHighlightFlags_ @@ -1358,16 +1485,7 @@ enum ImGuiNavHighlightFlags_ ImGuiNavHighlightFlags_TypeDefault = 1 << 0, ImGuiNavHighlightFlags_TypeThin = 1 << 1, ImGuiNavHighlightFlags_AlwaysDraw = 1 << 2, // Draw rectangular highlight if (g.NavId == id) _even_ when using the mouse. - ImGuiNavHighlightFlags_NoRounding = 1 << 3 -}; - -enum ImGuiNavDirSourceFlags_ -{ - ImGuiNavDirSourceFlags_None = 0, - ImGuiNavDirSourceFlags_RawKeyboard = 1 << 0, // Raw keyboard (not pulled from nav), facilitate use of some functions before we can unify nav and keys - ImGuiNavDirSourceFlags_Keyboard = 1 << 1, - ImGuiNavDirSourceFlags_PadDPad = 1 << 2, - ImGuiNavDirSourceFlags_PadLStick = 1 << 3 + ImGuiNavHighlightFlags_NoRounding = 1 << 3, }; enum ImGuiNavMoveFlags_ @@ -1377,6 +1495,7 @@ enum ImGuiNavMoveFlags_ ImGuiNavMoveFlags_LoopY = 1 << 1, ImGuiNavMoveFlags_WrapX = 1 << 2, // On failed request, request from opposite side one line down (when NavDir==right) or one line up (when NavDir==left) ImGuiNavMoveFlags_WrapY = 1 << 3, // This is not super useful but provided for completeness + ImGuiNavMoveFlags_WrapMask_ = ImGuiNavMoveFlags_LoopX | ImGuiNavMoveFlags_LoopY | ImGuiNavMoveFlags_WrapX | ImGuiNavMoveFlags_WrapY, ImGuiNavMoveFlags_AllowCurrentNavId = 1 << 4, // Allow scoring and considering the current NavId as a move target candidate. This is used when the move source is offset (e.g. pressing PageDown actually needs to send a Up move request, if we are pressing PageDown from the bottom-most item we need to stay in place) ImGuiNavMoveFlags_AlsoScoreVisibleSet = 1 << 5, // Store alternate result in NavMoveResultLocalVisible that only comprise elements that are already fully visible (used by PageUp/PageDown) ImGuiNavMoveFlags_ScrollToEdgeY = 1 << 6, // Force scrolling to min/max (used by Home/End) // FIXME-NAV: Aim to remove or reword, probably unnecessary @@ -1385,13 +1504,13 @@ enum ImGuiNavMoveFlags_ ImGuiNavMoveFlags_FocusApi = 1 << 9, ImGuiNavMoveFlags_Tabbing = 1 << 10, // == Focus + Activate if item is Inputable + DontChangeNavHighlight ImGuiNavMoveFlags_Activate = 1 << 11, - ImGuiNavMoveFlags_DontSetNavHighlight = 1 << 12 // Do not alter the visible state of keyboard vs mouse nav highlight + ImGuiNavMoveFlags_DontSetNavHighlight = 1 << 12, // Do not alter the visible state of keyboard vs mouse nav highlight }; enum ImGuiNavLayer { ImGuiNavLayer_Main = 0, // Main scrolling layer - ImGuiNavLayer_Menu = 1, // Menu layer (access with Alt/ImGuiNavInput_Menu) + ImGuiNavLayer_Menu = 1, // Menu layer (access with Alt) ImGuiNavLayer_COUNT }; @@ -1422,24 +1541,24 @@ enum ImGuiOldColumnFlags_ ImGuiOldColumnFlags_NoResize = 1 << 1, // Disable resizing columns when clicking on the dividers ImGuiOldColumnFlags_NoPreserveWidths = 1 << 2, // Disable column width preservation when adjusting columns ImGuiOldColumnFlags_NoForceWithinWindow = 1 << 3, // Disable forcing columns to fit within window - ImGuiOldColumnFlags_GrowParentContentsSize = 1 << 4 // (WIP) Restore pre-1.51 behavior of extending the parent window contents size but _without affecting the columns width at all_. Will eventually remove. + ImGuiOldColumnFlags_GrowParentContentsSize = 1 << 4, // (WIP) Restore pre-1.51 behavior of extending the parent window contents size but _without affecting the columns width at all_. Will eventually remove. // Obsolete names (will be removed) #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS - , ImGuiColumnsFlags_None = ImGuiOldColumnFlags_None, + ImGuiColumnsFlags_None = ImGuiOldColumnFlags_None, ImGuiColumnsFlags_NoBorder = ImGuiOldColumnFlags_NoBorder, ImGuiColumnsFlags_NoResize = ImGuiOldColumnFlags_NoResize, ImGuiColumnsFlags_NoPreserveWidths = ImGuiOldColumnFlags_NoPreserveWidths, ImGuiColumnsFlags_NoForceWithinWindow = ImGuiOldColumnFlags_NoForceWithinWindow, - ImGuiColumnsFlags_GrowParentContentsSize = ImGuiOldColumnFlags_GrowParentContentsSize + ImGuiColumnsFlags_GrowParentContentsSize = ImGuiOldColumnFlags_GrowParentContentsSize, #endif }; struct ImGuiOldColumnData { - float OffsetNorm; // Column start offset, normalized 0.0 (far left) -> 1.0 (far right) + float OffsetNorm; // Column start offset, normalized 0.0 (far left) -> 1.0 (far right) float OffsetNormBeforeResize; - ImGuiOldColumnFlags Flags; // Not exposed + ImGuiOldColumnFlags Flags; // Not exposed ImRect ClipRect; ImGuiOldColumnData() { memset(this, 0, sizeof(*this)); } @@ -1478,6 +1597,9 @@ struct ImGuiOldColumns // [SECTION] Docking support //----------------------------------------------------------------------------- +#define DOCKING_HOST_DRAW_CHANNEL_BG 0 // Dock host: background fill +#define DOCKING_HOST_DRAW_CHANNEL_FG 1 // Dock host: decorations and contents + #ifdef IMGUI_HAS_DOCK // Extend ImGuiDockNodeFlags_ @@ -1510,7 +1632,7 @@ enum ImGuiDataAuthority_ { ImGuiDataAuthority_Auto, ImGuiDataAuthority_DockNode, - ImGuiDataAuthority_Window + ImGuiDataAuthority_Window, }; enum ImGuiDockNodeState @@ -1518,7 +1640,7 @@ enum ImGuiDockNodeState ImGuiDockNodeState_Unknown, ImGuiDockNodeState_HostWindowHiddenBecauseSingleWindow, ImGuiDockNodeState_HostWindowHiddenBecauseWindowsAreResizing, - ImGuiDockNodeState_HostWindowVisible + ImGuiDockNodeState_HostWindowVisible, }; // sizeof() 156~192 @@ -1623,16 +1745,16 @@ struct ImGuiDockContext // Every instance of ImGuiViewport is in fact a ImGuiViewportP. struct ImGuiViewportP : public ImGuiViewport { + ImGuiWindow* Window; // Set when the viewport is owned by a window (and ImGuiViewportFlags_CanHostOtherWindows is NOT set) int Idx; int LastFrameActive; // Last frame number this viewport was activated by a window - int LastFrontMostStampCount;// Last stamp number from when a window hosted by this viewport was made front-most (by comparing this value between two viewport we have an implicit viewport z-order + int LastFocusedStampCount; // Last stamp number from when a window hosted by this viewport was focused (by comparing this value between two viewport we have an implicit viewport z-order we use as fallback) ImGuiID LastNameHash; ImVec2 LastPos; float Alpha; // Window opacity (when dragging dockable windows/viewports we make them transparent) float LastAlpha; + bool LastFocusedHadNavWindow;// Instead of maintaining a LastFocusedWindow (which may harder to correctly maintain), we merely store weither NavWindow != NULL last time the viewport was focused. short PlatformMonitor; - bool PlatformWindowCreated; - ImGuiWindow* Window; // Set when the viewport is owned by a window (and ImGuiViewportFlags_CanHostOtherWindows is NOT set) int DrawListsLastFrame[2]; // Last frame number the background (0) and foreground (1) draw lists were used ImDrawList* DrawLists[2]; // Convenience background (0) and foreground (1) draw lists. We use them to draw software mouser cursor when io.MouseDrawCursor is set and to draw most debug overlays. ImDrawData DrawDataP; @@ -1645,7 +1767,7 @@ struct ImGuiViewportP : public ImGuiViewport ImVec2 BuildWorkOffsetMin; // Work Area: Offset being built during current frame. Generally >= 0.0f. ImVec2 BuildWorkOffsetMax; // Work Area: Offset being built during current frame. Generally <= 0.0f. - ImGuiViewportP() { Idx = -1; LastFrameActive = DrawListsLastFrame[0] = DrawListsLastFrame[1] = LastFrontMostStampCount = -1; LastNameHash = 0; Alpha = LastAlpha = 1.0f; PlatformMonitor = -1; PlatformWindowCreated = false; Window = NULL; DrawLists[0] = DrawLists[1] = NULL; LastPlatformPos = LastPlatformSize = LastRendererSize = ImVec2(FLT_MAX, FLT_MAX); } + ImGuiViewportP() { Window = NULL; Idx = -1; LastFrameActive = DrawListsLastFrame[0] = DrawListsLastFrame[1] = LastFocusedStampCount = -1; LastNameHash = 0; Alpha = LastAlpha = 1.0f; LastFocusedHadNavWindow = false; PlatformMonitor = -1; DrawLists[0] = DrawLists[1] = NULL; LastPlatformPos = LastPlatformSize = LastRendererSize = ImVec2(FLT_MAX, FLT_MAX); } ~ImGuiViewportP() { if (DrawLists[0]) IM_DELETE(DrawLists[0]); if (DrawLists[1]) IM_DELETE(DrawLists[1]); } void ClearRequestFlags() { PlatformRequestClose = PlatformRequestMove = PlatformRequestResize = false; } @@ -1679,6 +1801,7 @@ struct ImGuiWindowSettings short DockOrder; // Order of the last time the window was visible within its DockNode. This is used to reorder windows that are reappearing on the same frame. Same value between windows that were active and windows that were none are possible. bool Collapsed; bool WantApply; // Set when loaded from .ini data (to enable merging/loading .ini data into an already running context) + bool WantDelete; // Set to invalidate/delete the settings entry ImGuiWindowSettings() { memset(this, 0, sizeof(*this)); DockOrder = -1; } char* GetName() { return (char*)(this + 1); } @@ -1699,34 +1822,65 @@ struct ImGuiSettingsHandler ImGuiSettingsHandler() { memset(this, 0, sizeof(*this)); } }; +//----------------------------------------------------------------------------- +// [SECTION] Localization support +//----------------------------------------------------------------------------- + +// This is experimental and not officially supported, it'll probably fall short of features, if/when it does we may backtrack. +enum ImGuiLocKey : int +{ + ImGuiLocKey_TableSizeOne, + ImGuiLocKey_TableSizeAllFit, + ImGuiLocKey_TableSizeAllDefault, + ImGuiLocKey_TableResetOrder, + ImGuiLocKey_WindowingMainMenuBar, + ImGuiLocKey_WindowingPopup, + ImGuiLocKey_WindowingUntitled, + ImGuiLocKey_DockingHideTabBar, + ImGuiLocKey_COUNT +}; + +struct ImGuiLocEntry +{ + ImGuiLocKey Key; + const char* Text; +}; + + //----------------------------------------------------------------------------- // [SECTION] Metrics, Debug Tools //----------------------------------------------------------------------------- +enum ImGuiDebugLogFlags_ +{ + // Event types + ImGuiDebugLogFlags_None = 0, + ImGuiDebugLogFlags_EventActiveId = 1 << 0, + ImGuiDebugLogFlags_EventFocus = 1 << 1, + ImGuiDebugLogFlags_EventPopup = 1 << 2, + ImGuiDebugLogFlags_EventNav = 1 << 3, + ImGuiDebugLogFlags_EventClipper = 1 << 4, + ImGuiDebugLogFlags_EventSelection = 1 << 5, + ImGuiDebugLogFlags_EventIO = 1 << 6, + ImGuiDebugLogFlags_EventDocking = 1 << 7, + ImGuiDebugLogFlags_EventViewport = 1 << 8, + ImGuiDebugLogFlags_EventMask_ = ImGuiDebugLogFlags_EventActiveId | ImGuiDebugLogFlags_EventFocus | ImGuiDebugLogFlags_EventPopup | ImGuiDebugLogFlags_EventNav | ImGuiDebugLogFlags_EventClipper | ImGuiDebugLogFlags_EventSelection | ImGuiDebugLogFlags_EventIO | ImGuiDebugLogFlags_EventDocking | ImGuiDebugLogFlags_EventViewport, + ImGuiDebugLogFlags_OutputToTTY = 1 << 10, // Also send output to TTY +}; + struct ImGuiMetricsConfig { - bool ShowStackTool; - bool ShowWindowsRects; - bool ShowWindowsBeginOrder; - bool ShowTablesRects; - bool ShowDrawCmdMesh; - bool ShowDrawCmdBoundingBoxes; - bool ShowDockingNodes; - int ShowWindowsRectsType; - int ShowTablesRectsType; - - ImGuiMetricsConfig() - { - ShowStackTool = false; - ShowWindowsRects = false; - ShowWindowsBeginOrder = false; - ShowTablesRects = false; - ShowDrawCmdMesh = true; - ShowDrawCmdBoundingBoxes = true; - ShowDockingNodes = false; - ShowWindowsRectsType = -1; - ShowTablesRectsType = -1; - } + bool ShowDebugLog = false; + bool ShowStackTool = false; + bool ShowWindowsRects = false; + bool ShowWindowsBeginOrder = false; + bool ShowTablesRects = false; + bool ShowDrawCmdMesh = true; + bool ShowDrawCmdBoundingBoxes = true; + bool ShowAtlasTintedWithTextColor = false; + bool ShowDockingNodes = false; + int ShowWindowsRectsType = -1; + int ShowTablesRectsType = -1; }; struct ImGuiStackLevelInfo @@ -1781,8 +1935,6 @@ struct ImGuiContext bool FontAtlasOwnedByContext; // IO.Fonts-> is owned by the ImGuiContext and will be destructed along with it. ImGuiIO IO; ImGuiPlatformIO PlatformIO; - ImVector InputEventsQueue; // Input events which will be tricked/written into IO structure. - ImVector InputEventsTrail; // Past input events processed in NewFrame(). This is to allow domain-specific application to access e.g mouse/pen trail. ImGuiStyle Style; ImGuiConfigFlags ConfigFlagsCurrFrame; // = g.IO.ConfigFlags at the time of NewFrame() ImGuiConfigFlags ConfigFlagsLastFrame; @@ -1802,6 +1954,12 @@ struct ImGuiContext bool TestEngineHookItems; // Will call test engine hooks: ImGuiTestEngineHook_ItemAdd(), ImGuiTestEngineHook_ItemInfo(), ImGuiTestEngineHook_Log() void* TestEngine; // Test engine user data + // Inputs + ImVector InputEventsQueue; // Input events which will be trickled/written into IO structure. + ImVector InputEventsTrail; // Past input events processed in NewFrame(). This is to allow domain-specific application to access e.g mouse/pen trail. + ImGuiMouseSource InputEventsNextMouseSource; + ImU32 InputEventsNextEventId; + // Windows state ImVector Windows; // Windows, sorted in display order, back to front ImVector WindowsFocusOrder; // Root windows, sorted in focus order, back to front. @@ -1813,19 +1971,19 @@ struct ImGuiContext ImGuiWindow* CurrentWindow; // Window being drawn into ImGuiWindow* HoveredWindow; // Window the mouse is hovering. Will typically catch mouse inputs. ImGuiWindow* HoveredWindowUnderMovingWindow; // Hovered window ignoring MovingWindow. Only set if MovingWindow is set. - ImGuiDockNode* HoveredDockNode; // [Debug] Hovered dock node. ImGuiWindow* MovingWindow; // Track the window we clicked on (in order to preserve focus). The actual window that is moved is generally MovingWindow->RootWindowDockTree. ImGuiWindow* WheelingWindow; // Track the window we started mouse-wheeling on. Until a timer elapse or mouse has moved, generally keep scrolling the same window even if during the course of scrolling the mouse ends up hovering a child window. ImVec2 WheelingWindowRefMousePos; - float WheelingWindowTimer; + int WheelingWindowStartFrame; // This may be set one frame before WheelingWindow is != NULL + float WheelingWindowReleaseTimer; + ImVec2 WheelingWindowWheelRemainder; + ImVec2 WheelingAxisAvg; // Item/widgets state and tracking information ImGuiID DebugHookIdInfo; // Will call core hooks: DebugHookIdInfo() from GetID functions, used by Stack Tool [next HoveredId/ActiveId to not pull in an extra cache-line] ImGuiID HoveredId; // Hovered widget, filled during the frame ImGuiID HoveredIdPreviousFrame; bool HoveredIdAllowOverlap; - bool HoveredIdUsingMouseWheel; // Hovered widget will use mouse wheel. Blocks scrolling the underlying window. - bool HoveredIdPreviousFrameUsingMouseWheel; bool HoveredIdDisabled; // At least one widget passed the rect test, but has been discarded by disabled flag or popup inhibit. May be true even if HoveredId == 0. float HoveredIdTimer; // Measure contiguous hovering time float HoveredIdNotActiveTimer; // Measure contiguous hovering time where the item has not been active @@ -1840,7 +1998,7 @@ struct ImGuiContext bool ActiveIdHasBeenEditedThisFrame; ImVec2 ActiveIdClickOffset; // Clicked offset from upper-left corner, if applicable (currently only set by ButtonBehavior) ImGuiWindow* ActiveIdWindow; - ImGuiInputSource ActiveIdSource; // Activating with mouse or nav (gamepad/keyboard) + ImGuiInputSource ActiveIdSource; // Activating source: ImGuiInputSource_Mouse OR ImGuiInputSource_Keyboard OR ImGuiInputSource_Gamepad int ActiveIdMouseButton; ImGuiID ActiveIdPreviousFrame; bool ActiveIdPreviousFrameIsAlive; @@ -1849,14 +2007,22 @@ struct ImGuiContext ImGuiID LastActiveId; // Store the last non-zero ActiveId, useful for animation. float LastActiveIdTimer; // Store the last non-zero ActiveId timer since the beginning of activation, useful for animation. - // Input Ownership - bool ActiveIdUsingMouseWheel; // Active widget will want to read mouse wheel. Blocks scrolling the underlying window. + // [EXPERIMENTAL] Key/Input Ownership + Shortcut Routing system + // - The idea is that instead of "eating" a given key, we can link to an owner. + // - Input query can then read input by specifying ImGuiKeyOwner_Any (== 0), ImGuiKeyOwner_None (== -1) or a custom ID. + // - Routing is requested ahead of time for a given chord (Key + Mods) and granted in NewFrame(). + ImGuiKeyOwnerData KeysOwnerData[ImGuiKey_NamedKey_COUNT]; + ImGuiKeyRoutingTable KeysRoutingTable; ImU32 ActiveIdUsingNavDirMask; // Active widget will want to read those nav move requests (e.g. can activate a button and move away from it) - ImU32 ActiveIdUsingNavInputMask; // Active widget will want to read those nav inputs. - ImBitArrayForNamedKeys ActiveIdUsingKeyInputMask; // Active widget will want to read those key inputs. When we grow the ImGuiKey enum we'll need to either to order the enum to make useful keys come first, either redesign this into e.g. a small array. + bool ActiveIdUsingAllKeyboardKeys; // Active widget will want to read all keyboard keys inputs. (FIXME: This is a shortcut for not taking ownership of 100+ keys but perhaps best to not have the inconsistency) +#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO + ImU32 ActiveIdUsingNavInputMask; // If you used this. Since (IMGUI_VERSION_NUM >= 18804) : 'g.ActiveIdUsingNavInputMask |= (1 << ImGuiNavInput_Cancel);' becomes 'SetKeyOwner(ImGuiKey_Escape, g.ActiveId) and/or SetKeyOwner(ImGuiKey_NavGamepadCancel, g.ActiveId);' +#endif // Next window/item data - ImGuiItemFlags CurrentItemFlags; // == g.ItemFlagsStack.back() + ImGuiID CurrentFocusScopeId; // == g.FocusScopeStack.back() + ImGuiItemFlags CurrentItemFlags; // == g.ItemFlagsStack.back() + ImGuiID DebugLocateId; // Storage for DebugLocateItemOnHover() feature: this is read by ItemAdd() so we keep it in a hot/cached location ImGuiNextItemData NextItemData; // Storage for SetNextItem** functions ImGuiLastItemData LastItemData; // Storage for last submitted item (setup by ItemAdd) ImGuiNextWindowData NextWindowData; // Storage for SetNextWindow** functions @@ -1865,7 +2031,7 @@ struct ImGuiContext ImVector ColorStack; // Stack for PushStyleColor()/PopStyleColor() - inherited by Begin() ImVector StyleVarStack; // Stack for PushStyleVar()/PopStyleVar() - inherited by Begin() ImVector FontStack; // Stack for PushFont()/PopFont() - inherited by Begin() - ImVector FocusScopeStack; // Stack for PushFocusScope()/PopFocusScope() - not inherited by Begin(), unless child window + ImVector FocusScopeStack; // Stack for PushFocusScope()/PopFocusScope() - inherited by BeginChild(), pushed into by Begin() ImVectorItemFlagsStack; // Stack for PushItemFlag()/PopItemFlag() - inherited by Begin() ImVectorGroupStack; // Stack for BeginGroup()/EndGroup() - not inherited by Begin() ImVectorOpenPopupStack; // Which popups are open (persistent) @@ -1880,23 +2046,22 @@ struct ImGuiContext ImGuiViewportP* MouseLastHoveredViewport; // Last known viewport that was hovered by mouse (even if we are not hovering any viewport any more) + honoring the _NoInputs flag. ImGuiID PlatformLastFocusedViewportId; ImGuiPlatformMonitor FallbackMonitor; // Virtual monitor used as fallback if backend doesn't provide monitor information. - int ViewportFrontMostStampCount; // Every time the front-most window changes, we stamp its viewport with an incrementing counter + int ViewportFocusedStampCount; // Every time the front-most window changes, we stamp its viewport with an incrementing counter // Gamepad/keyboard Navigation ImGuiWindow* NavWindow; // Focused window for navigation. Could be called 'FocusedWindow' ImGuiID NavId; // Focused item for navigation ImGuiID NavFocusScopeId; // Identify a selection scope (selection code often wants to "clear other items" when landing on an item of the selection set) - ImGuiID NavActivateId; // ~~ (g.ActiveId == 0) && IsNavInputPressed(ImGuiNavInput_Activate) ? NavId : 0, also set when calling ActivateItem() - ImGuiID NavActivateDownId; // ~~ IsNavInputDown(ImGuiNavInput_Activate) ? NavId : 0 - ImGuiID NavActivatePressedId; // ~~ IsNavInputPressed(ImGuiNavInput_Activate) ? NavId : 0 - ImGuiID NavActivateInputId; // ~~ IsNavInputPressed(ImGuiNavInput_Input) ? NavId : 0; ImGuiActivateFlags_PreferInput will be set and NavActivateId will be 0. + ImGuiID NavActivateId; // ~~ (g.ActiveId == 0) && (IsKeyPressed(ImGuiKey_Space) || IsKeyDown(ImGuiKey_Enter) || IsKeyPressed(ImGuiKey_NavGamepadActivate)) ? NavId : 0, also set when calling ActivateItem() + ImGuiID NavActivateDownId; // ~~ IsKeyDown(ImGuiKey_Space) || IsKeyDown(ImGuiKey_Enter) || IsKeyDown(ImGuiKey_NavGamepadActivate) ? NavId : 0 + ImGuiID NavActivatePressedId; // ~~ IsKeyPressed(ImGuiKey_Space) || IsKeyPressed(ImGuiKey_Enter) || IsKeyPressed(ImGuiKey_NavGamepadActivate) ? NavId : 0 (no repeat) ImGuiActivateFlags NavActivateFlags; ImGuiID NavJustMovedToId; // Just navigated to this id (result of a successfully MoveRequest). ImGuiID NavJustMovedToFocusScopeId; // Just navigated to this focus scope id (result of a successfully MoveRequest). - ImGuiModFlags NavJustMovedToKeyMods; + ImGuiKeyChord NavJustMovedToKeyMods; ImGuiID NavNextActivateId; // Set by ActivateItem(), queued until next frame. ImGuiActivateFlags NavNextActivateFlags; - ImGuiInputSource NavInputSource; // Keyboard or Gamepad mode? THIS WILL ONLY BE None or NavGamepad or NavKeyboard. + ImGuiInputSource NavInputSource; // Keyboard or Gamepad mode? THIS CAN ONLY BE ImGuiInputSource_Keyboard or ImGuiInputSource_Mouse ImGuiNavLayer NavLayer; // Layer we are navigating on. For now the system is hard-coded for 0=main contents and 1=menu/title bar, may expose layers later. bool NavIdIsAlive; // Nav widget has been seen this frame ~~ NavRectRel is valid bool NavMousePosDirty; // When set we will update mouse position if (io.ConfigFlags & ImGuiConfigFlags_NavEnableSetMousePos) if set (NB: this not enabled by default) @@ -1907,14 +2072,13 @@ struct ImGuiContext bool NavAnyRequest; // ~~ NavMoveRequest || NavInitRequest this is to perform early out in ItemAdd() bool NavInitRequest; // Init request for appearing window to select first item bool NavInitRequestFromMove; - ImGuiID NavInitResultId; // Init request result (first item of the window, or one for which SetItemDefaultFocus() was called) - ImRect NavInitResultRectRel; // Init request result rectangle (relative to parent window) + ImGuiNavItemData NavInitResult; // Init request result (first item of the window, or one for which SetItemDefaultFocus() was called) bool NavMoveSubmitted; // Move request submitted, will process result on next NewFrame() bool NavMoveScoringItems; // Move request submitted, still scoring incoming items bool NavMoveForwardToNextFrame; ImGuiNavMoveFlags NavMoveFlags; ImGuiScrollFlags NavMoveScrollFlags; - ImGuiModFlags NavMoveKeyMods; + ImGuiKeyChord NavMoveKeyMods; ImGuiDir NavMoveDir; // Direction of the move request (left/right/up/down) ImGuiDir NavMoveDirForDebug; ImGuiDir NavMoveClipDir; // FIXME-NAV: Describe the purpose of this better. Might want to rename? @@ -1929,12 +2093,16 @@ struct ImGuiContext ImGuiNavItemData NavTabbingResultFirst; // First tabbing request candidate within NavWindow and flattened hierarchy // Navigation: Windowing (CTRL+TAB for list, or Menu button + keys or directional pads to move/resize) + ImGuiKeyChord ConfigNavWindowingKeyNext; // = ImGuiMod_Ctrl | ImGuiKey_Tab, for reconfiguration (see #4828) + ImGuiKeyChord ConfigNavWindowingKeyPrev; // = ImGuiMod_Ctrl | ImGuiMod_Shift | ImGuiKey_Tab ImGuiWindow* NavWindowingTarget; // Target window when doing CTRL+Tab (or Pad Menu + FocusPrev/Next), this window is temporarily displayed top-most! ImGuiWindow* NavWindowingTargetAnim; // Record of last valid NavWindowingTarget until DimBgRatio and NavWindowingHighlightAlpha becomes 0.0f, so the fade-out can stay on it. ImGuiWindow* NavWindowingListWindow; // Internal window actually listing the CTRL+Tab contents float NavWindowingTimer; float NavWindowingHighlightAlpha; bool NavWindowingToggleLayer; + ImVec2 NavWindowingAccumDeltaPos; + ImVec2 NavWindowingAccumDeltaSize; // Inertial scroll bool InertialScrollInhibited; // Is inertial scroll inhibited? (e.g. by ImGuiItemFlags_NoInertialScroll) @@ -1982,17 +2150,27 @@ struct ImGuiContext ImVector CurrentTabBarStack; ImVector ShrinkWidthBuffer; + // Hover Delay system + ImGuiID HoverDelayId; + ImGuiID HoverDelayIdPreviousFrame; + float HoverDelayTimer; // Currently used IsItemHovered(), generally inferred from g.HoveredIdTimer but kept uncleared until clear timer elapse. + float HoverDelayClearTimer; // Currently used IsItemHovered(): grace time before g.TooltipHoverTimer gets cleared. + // Widget state ImVec2 MouseLastValidPos; ImGuiInputTextState InputTextState; + ImGuiInputTextDeactivatedState InputTextDeactivatedState; ImFont InputTextPasswordFont; ImGuiID TempInputId; // Temporary text input when CTRL+clicking on a slider, etc. ImGuiColorEditFlags ColorEditOptions; // Store user options for color edit widgets - float ColorEditLastHue; // Backup of last Hue associated to LastColor, so we can restore Hue in lossy RGB<>HSV round trips - float ColorEditLastSat; // Backup of last Saturation associated to LastColor, so we can restore Saturation in lossy RGB<>HSV round trips - ImU32 ColorEditLastColor; // RGB value with alpha set to 0. + ImGuiID ColorEditCurrentID; // Set temporarily while inside of the parent-most ColorEdit4/ColorPicker4 (because they call each others). + ImGuiID ColorEditSavedID; // ID we are saving/restoring HS for + float ColorEditSavedHue; // Backup of last Hue associated to LastColor, so we can restore Hue in lossy RGB<>HSV round trips + float ColorEditSavedSat; // Backup of last Saturation associated to LastColor, so we can restore Saturation in lossy RGB<>HSV round trips + ImU32 ColorEditSavedColor; // RGB value with alpha set to 0. ImVec4 ColorPickerRef; // Initial/reference color at the time of opening the color picker. ImGuiComboPreviewData ComboPreviewData; + float SliderGrabClickOffset; float SliderCurrentAccum; // Accumulated slider delta when using navigation controls. bool SliderCurrentAccumDirty; // Has the accumulated slider delta changed since last time we tried to apply it? bool DragCurrentAccumDirty; @@ -2002,7 +2180,6 @@ struct ImGuiContext float DisabledAlphaBackup; // Backup for style.Alpha for BeginDisabled() short DisabledStackSize; short TooltipOverrideCount; - float TooltipSlowDelay; // Time before slow tooltips appears (FIXME: This is temporary until we merge in tooltip timer+priority work) ImVector ClipboardHandlerData; // If no custom clipboard handler is defined ImVector MenusIdSubmittedThisFrame; // A list of menu IDs that were rendered at least once @@ -2015,6 +2192,7 @@ struct ImGuiContext // Extensions // FIXME: We could provide an API to register one slot in an array held in ImGuiContext? ImGuiDockContext DockContext; + void (*DockNodeWindowMenuHandler)(ImGuiContext* ctx, ImGuiDockNode* node, ImGuiTabBar* tab_bar); // Settings bool SettingsLoaded; @@ -2026,6 +2204,9 @@ struct ImGuiContext ImVector Hooks; // Hooks for extensions (e.g. test engine) ImGuiID HookIdNext; // Next available HookId + // Localization + const char* LocalizationTable[ImGuiLocKey_COUNT]; + // Capture/Logging bool LogEnabled; // Currently capturing ImGuiLogType LogType; // Capture target @@ -2040,23 +2221,34 @@ struct ImGuiContext int LogDepthToExpandDefault; // Default/stored value for LogDepthMaxExpand if not specified in the LogXXX function call. // Debug Tools + ImGuiDebugLogFlags DebugLogFlags; + ImGuiTextBuffer DebugLogBuf; + ImGuiTextIndex DebugLogIndex; + ImU8 DebugLogClipperAutoDisableFrames; + ImU8 DebugLocateFrames; // For DebugLocateItemOnHover(). This is used together with DebugLocateId which is in a hot/cached spot above. + ImS8 DebugBeginReturnValueCullDepth; // Cycle between 0..9 then wrap around. bool DebugItemPickerActive; // Item picker is active (started with DebugStartItemPicker()) + ImU8 DebugItemPickerMouseButton; ImGuiID DebugItemPickerBreakId; // Will call IM_DEBUG_BREAK() when encountering this ID ImGuiMetricsConfig DebugMetricsConfig; ImGuiStackTool DebugStackTool; + ImGuiDockNode* DebugHoveredDockNode; // Hovered dock node. // Misc - float FramerateSecPerFrame[120]; // Calculate estimate of framerate for user over the last 2 seconds. + float FramerateSecPerFrame[60]; // Calculate estimate of framerate for user over the last 60 frames.. int FramerateSecPerFrameIdx; int FramerateSecPerFrameCount; float FramerateSecPerFrameAccum; - int WantCaptureMouseNextFrame; // Explicit capture via CaptureKeyboardFromApp()/CaptureMouseFromApp() sets those flags - int WantCaptureKeyboardNextFrame; + int WantCaptureMouseNextFrame; // Explicit capture override via SetNextFrameWantCaptureMouse()/SetNextFrameWantCaptureKeyboard(). Default to -1. + int WantCaptureKeyboardNextFrame; // " int WantTextInputNextFrame; - char TempBuffer[1024 * 3 + 1]; // Temporary text buffer + ImVector TempBuffer; // Temporary text buffer ImGuiContext(ImFontAtlas* shared_font_atlas) { + IO.Ctx = this; + InputTextState.Ctx = this; + Initialized = false; ConfigFlagsCurrFrame = ConfigFlagsLastFrame = ImGuiConfigFlags_None; FontAtlasOwnedByContext = shared_font_atlas ? false : true; @@ -2071,19 +2263,21 @@ struct ImGuiContext TestEngineHookItems = false; TestEngine = NULL; + InputEventsNextMouseSource = ImGuiMouseSource_Mouse; + InputEventsNextEventId = 1; + WindowsActiveCount = 0; CurrentWindow = NULL; HoveredWindow = NULL; HoveredWindowUnderMovingWindow = NULL; - HoveredDockNode = NULL; MovingWindow = NULL; WheelingWindow = NULL; - WheelingWindowTimer = 0.0f; + WheelingWindowStartFrame = -1; + WheelingWindowReleaseTimer = 0.0f; DebugHookIdInfo = 0; HoveredId = HoveredIdPreviousFrame = 0; HoveredIdAllowOverlap = false; - HoveredIdUsingMouseWheel = HoveredIdPreviousFrameUsingMouseWheel = false; HoveredIdDisabled = false; HoveredIdTimer = HoveredIdNotActiveTimer = 0.0f; ActiveId = 0; @@ -2106,11 +2300,13 @@ struct ImGuiContext LastActiveId = 0; LastActiveIdTimer = 0.0f; - ActiveIdUsingMouseWheel = false; ActiveIdUsingNavDirMask = 0x00; + ActiveIdUsingAllKeyboardKeys = false; +#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO ActiveIdUsingNavInputMask = 0x00; - ActiveIdUsingKeyInputMask.ClearAllBits(); +#endif + CurrentFocusScopeId = 0; CurrentItemFlags = ImGuiItemFlags_None; BeginMenuCount = 0; @@ -2118,14 +2314,14 @@ struct ImGuiContext CurrentViewport = NULL; MouseViewport = MouseLastHoveredViewport = NULL; PlatformLastFocusedViewportId = 0; - ViewportFrontMostStampCount = 0; + ViewportFocusedStampCount = 0; NavWindow = NULL; - NavId = NavFocusScopeId = NavActivateId = NavActivateDownId = NavActivatePressedId = NavActivateInputId = 0; + NavId = NavFocusScopeId = NavActivateId = NavActivateDownId = NavActivatePressedId = 0; NavJustMovedToId = NavJustMovedToFocusScopeId = NavNextActivateId = 0; NavActivateFlags = NavNextActivateFlags = ImGuiActivateFlags_None; - NavJustMovedToKeyMods = ImGuiModFlags_None; - NavInputSource = ImGuiInputSource_None; + NavJustMovedToKeyMods = ImGuiMod_None; + NavInputSource = ImGuiInputSource_Keyboard; NavLayer = ImGuiNavLayer_Main; NavIdIsAlive = false; NavMousePosDirty = false; @@ -2134,18 +2330,19 @@ struct ImGuiContext NavAnyRequest = false; NavInitRequest = false; NavInitRequestFromMove = false; - NavInitResultId = 0; NavMoveSubmitted = false; NavMoveScoringItems = false; NavMoveForwardToNextFrame = false; NavMoveFlags = ImGuiNavMoveFlags_None; NavMoveScrollFlags = ImGuiScrollFlags_None; - NavMoveKeyMods = ImGuiModFlags_None; + NavMoveKeyMods = ImGuiMod_None; NavMoveDir = NavMoveDirForDebug = NavMoveClipDir = ImGuiDir_None; NavScoringDebugCount = 0; NavTabbingDir = 0; NavTabbingCounter = 0; + ConfigNavWindowingKeyNext = ImGuiMod_Ctrl | ImGuiKey_Tab; + ConfigNavWindowingKeyPrev = ImGuiMod_Ctrl | ImGuiMod_Shift | ImGuiKey_Tab; NavWindowingTarget = NavWindowingTargetAnim = NavWindowingListWindow = NULL; NavWindowingTimer = NavWindowingHighlightAlpha = 0.0f; NavWindowingToggleLayer = false; @@ -2173,30 +2370,38 @@ struct ImGuiContext TablesTempDataStacked = 0; CurrentTabBar = NULL; + HoverDelayId = HoverDelayIdPreviousFrame = 0; + HoverDelayTimer = HoverDelayClearTimer = 0.0f; + TempInputId = 0; ColorEditOptions = ImGuiColorEditFlags_DefaultOptions_; - ColorEditLastHue = ColorEditLastSat = 0.0f; - ColorEditLastColor = 0; + ColorEditCurrentID = ColorEditSavedID = 0; + ColorEditSavedHue = ColorEditSavedSat = 0.0f; + ColorEditSavedColor = 0; + SliderGrabClickOffset = 0.0f; SliderCurrentAccum = 0.0f; SliderCurrentAccumDirty = false; DragCurrentAccumDirty = false; DragCurrentAccum = 0.0f; DragSpeedDefaultRatio = 1.0f / 100.0f; + ScrollbarClickDeltaToGrabCenter = 0.0f; DisabledAlphaBackup = 0.0f; DisabledStackSize = 0; - ScrollbarClickDeltaToGrabCenter = 0.0f; TooltipOverrideCount = 0; - TooltipSlowDelay = 0.50f; PlatformImeData.InputPos = ImVec2(0.0f, 0.0f); PlatformImeDataPrev.InputPos = ImVec2(-1.0f, -1.0f); // Different to ensure initial submission PlatformImeViewport = 0; PlatformLocaleDecimalPoint = '.'; + DockNodeWindowMenuHandler = NULL; + SettingsLoaded = false; SettingsDirtyTimer = 0.0f; HookIdNext = 0; + memset(LocalizationTable, 0, sizeof(LocalizationTable)); + LogEnabled = false; LogType = ImGuiLogType_None; LogNextPrefix = LogNextSuffix = NULL; @@ -2206,14 +2411,20 @@ struct ImGuiContext LogDepthRef = 0; LogDepthToExpand = LogDepthToExpandDefault = 2; + DebugLogFlags = ImGuiDebugLogFlags_OutputToTTY; + DebugLocateId = 0; + DebugLogClipperAutoDisableFrames = 0; + DebugLocateFrames = 0; + DebugBeginReturnValueCullDepth = -1; DebugItemPickerActive = false; + DebugItemPickerMouseButton = ImGuiMouseButton_Left; DebugItemPickerBreakId = 0; + DebugHoveredDockNode = NULL; memset(FramerateSecPerFrame, 0, sizeof(FramerateSecPerFrame)); FramerateSecPerFrameIdx = FramerateSecPerFrameCount = 0; FramerateSecPerFrameAccum = 0.0f; WantCaptureMouseNextFrame = WantCaptureKeyboardNextFrame = WantTextInputNextFrame = -1; - memset(TempBuffer, 0, sizeof(TempBuffer)); } }; @@ -2237,18 +2448,19 @@ struct IMGUI_API ImGuiWindowTempData float CurrLineTextBaseOffset; // Baseline offset (0.0f by default on a new line, generally == style.FramePadding.y when a framed item has been added). float PrevLineTextBaseOffset; bool IsSameLine; + bool IsSetPos; ImVec1 Indent; // Indentation / start position from left of window (increased by TreePush/TreePop, etc.) ImVec1 ColumnsOffset; // Offset to the current column (if ColumnsCurrent > 0). FIXME: This and the above should be a stack to allow use cases like Tree->Column->Tree. Need revamp columns API. ImVec1 GroupOffset; - ImVec2 CursorStartPosLossyness;// Record the loss of precision of CursorStartPos due to really large scrolling amount. This is used by clipper to compensentate and fix the most common use case of large scroll area. + ImVec2 CursorStartPosLossyness;// Record the loss of precision of CursorStartPos due to really large scrolling amount. This is used by clipper to compensate and fix the most common use case of large scroll area. // Keyboard/Gamepad navigation ImGuiNavLayer NavLayerCurrent; // Current layer, 0..31 (we currently only use 0..1) short NavLayersActiveMask; // Which layers have been written to (result from previous frame) short NavLayersActiveMaskNext;// Which layers have been written to (accumulator for current frame) - ImGuiID NavFocusScopeIdCurrent; // Current focus scope ID while appending + bool NavIsScrollPushableX; // Set when current work location may be scrolled horizontally when moving left / right. This is generally always true UNLESS within a column. bool NavHideHighlightOneFrame; - bool NavHasScroll; // Set when scrolling can be used (ScrollMax > 0.0f) + bool NavWindowHasScrollY; // Set per window when scrolling can be used (== ScrollMax.y > 0.0f) // Miscellaneous bool MenuBarAppending; // FIXME: Remove this @@ -2274,6 +2486,7 @@ struct IMGUI_API ImGuiWindowTempData // Storage for one window struct IMGUI_API ImGuiWindow { + ImGuiContext* Ctx; // Parent UI context (needs to be set explicitly by parent). char* Name; // Window name, owned by the window. ImGuiID ID; // == ImHashStr(Name) ImGuiWindowFlags Flags, FlagsPreviousFrame; // See enum ImGuiWindowFlags_ @@ -2291,6 +2504,9 @@ struct IMGUI_API ImGuiWindow ImVec2 WindowPadding; // Window padding at the time of Begin(). float WindowRounding; // Window rounding at the time of Begin(). May be clamped lower to avoid rendering artifacts with title bar, menu bar etc. float WindowBorderSize; // Window border size at the time of Begin(). + float DecoOuterSizeX1, DecoOuterSizeY1; // Left/Up offsets. Sum of non-scrolling outer decorations (X1 generally == 0.0f. Y1 generally = TitleBarHeight + MenuBarHeight). Locked during Begin(). + float DecoOuterSizeX2, DecoOuterSizeY2; // Right/Down offsets (X2 generally == ScrollbarSize.x, Y2 == ScrollbarSizes.y). + float DecoInnerSizeX1, DecoInnerSizeY1; // Applied AFTER/OVER InnerRect. Specialized for Tables as they use specialized form of clipping and frozen rows/columns are inside InnerRect (and not part of regular decoration sizes). int NameBufLen; // Size of buffer storing Name. May be larger than strlen(Name)! ImGuiID MoveId; // == window->GetID("#MOVE") ImGuiID TabId; // == window->GetID("#TAB") @@ -2318,6 +2534,7 @@ struct IMGUI_API ImGuiWindow bool InertialScroll; // Set when inertial scrolling is active signed char ResizeBorderHeld; // Current border being held for resize (-1: none, otherwise 0-3) short BeginCount; // Number of Begin() during the current frame (generally 0 or 1, 1+ if appending via multiple Begin/End pairs) + short BeginCountPreviousFrame; // Number of Begin() during the previous frame short BeginOrderWithinParent; // Begin() order within immediate parent window, if we are a child window. Otherwise 0. short BeginOrderWithinContext; // Begin() order within entire imgui context. This is mostly used for debugging submission order related issues. short FocusOrder; // Order within WindowsFocusOrder[], altered when windows are focused. @@ -2375,6 +2592,8 @@ struct IMGUI_API ImGuiWindow ImGuiWindow* NavLastChildNavWindow; // When going to the menu bar, we remember the child window we came from. (This could probably be made implicit if we kept g.Windows sorted by last focused including child window.) ImGuiID NavLastIds[ImGuiNavLayer_COUNT]; // Last known NavId for this window, per layer (0/1) ImRect NavRectRel[ImGuiNavLayer_COUNT]; // Reference rectangle, in window relative space + ImVec2 NavPreferredScoringPosRel[ImGuiNavLayer_COUNT]; // Preferred X/Y position updated when moving on a given axis, reset to FLT_MAX. + ImGuiID NavRootFocusScopeId; // Focus Scope ID at the time of Begin() int MemoryDrawListIdxCapacity; // Backup of last idx/vtx count, so when waking up the window we can preallocate and avoid iterative alloc/copy int MemoryDrawListVtxCapacity; @@ -2402,12 +2621,12 @@ public: ImGuiID GetID(int n); ImGuiID GetIDFromRectangle(const ImRect& r_abs); - // We don't use g.FontSize because the window may be != g.CurrentWidow. + // We don't use g.FontSize because the window may be != g.CurrentWindow. ImRect Rect() const { return ImRect(Pos.x, Pos.y, Pos.x + Size.x, Pos.y + Size.y); } - float CalcFontSize() const { ImGuiContext& g = *GImGui; float scale = g.FontBaseSize * FontWindowScale * FontDpiScale; if (ParentWindow) scale *= ParentWindow->FontWindowScale; return scale; } - float TitleBarHeight() const { ImGuiContext& g = *GImGui; return (Flags & ImGuiWindowFlags_NoTitleBar) ? 0.0f : CalcFontSize() + g.Style.FramePadding.y * 2.0f; } + float CalcFontSize() const { ImGuiContext& g = *Ctx; float scale = g.FontBaseSize * FontWindowScale * FontDpiScale; if (ParentWindow) scale *= ParentWindow->FontWindowScale; return scale; } + float TitleBarHeight() const { ImGuiContext& g = *Ctx; return (Flags & ImGuiWindowFlags_NoTitleBar) ? 0.0f : CalcFontSize() + g.Style.FramePadding.y * 2.0f; } ImRect TitleBarRect() const { return ImRect(Pos, ImVec2(Pos.x + SizeFull.x, Pos.y + TitleBarHeight())); } - float MenuBarHeight() const { ImGuiContext& g = *GImGui; return (Flags & ImGuiWindowFlags_MenuBar) ? DC.MenuBarOffset.y + CalcFontSize() + g.Style.FramePadding.y * 2.0f : 0.0f; } + float MenuBarHeight() const { ImGuiContext& g = *Ctx; return (Flags & ImGuiWindowFlags_MenuBar) ? DC.MenuBarOffset.y + CalcFontSize() + g.Style.FramePadding.y * 2.0f : 0.0f; } ImRect MenuBarRect() const { float y1 = Pos.y + TitleBarHeight(); return ImRect(Pos.x, y1, Pos.x + SizeFull.x, y1 + MenuBarHeight()); } }; @@ -2420,7 +2639,7 @@ enum ImGuiTabBarFlagsPrivate_ { ImGuiTabBarFlags_DockNode = 1 << 20, // Part of a dock node [we don't use this in the master branch but it facilitate branch syncing to keep this around] ImGuiTabBarFlags_IsFocused = 1 << 21, - ImGuiTabBarFlags_SaveSettings = 1 << 22 // FIXME: Settings are handled by the docking system, this only request the tab bar to mark settings dirty when reordering tabs + ImGuiTabBarFlags_SaveSettings = 1 << 22, // FIXME: Settings are handled by the docking system, this only request the tab bar to mark settings dirty when reordering tabs }; // Extend ImGuiTabItemFlags_ @@ -2430,7 +2649,7 @@ enum ImGuiTabItemFlagsPrivate_ ImGuiTabItemFlags_NoCloseButton = 1 << 20, // Track whether p_open was set or not (we'll need this info on the next frame to recompute ContentWidth during layout) ImGuiTabItemFlags_Button = 1 << 21, // Used by TabItemButton, change the tab item behavior to mimic a button ImGuiTabItemFlags_Unsorted = 1 << 22, // [Docking] Trailing tabs with the _Unsorted flag will be sorted based on the DockOrder of their Window. - ImGuiTabItemFlags_Preview = 1 << 23 // [Docking] Display tab shape for docking preview (height is adjusted slightly to compensate for the yet missing tab bar) + ImGuiTabItemFlags_Preview = 1 << 23, // [Docking] Display tab shape for docking preview (height is adjusted slightly to compensate for the yet missing tab bar) }; // Storage for one active tab item (sizeof() 48 bytes) @@ -2444,12 +2663,13 @@ struct ImGuiTabItem float Offset; // Position relative to beginning of tab float Width; // Width currently displayed float ContentWidth; // Width of label, stored during BeginTabItem() call + float RequestedWidth; // Width optionally requested by caller, -1.0f is unused ImS32 NameOffset; // When Window==NULL, offset to name within parent ImGuiTabBar::TabsNames ImS16 BeginOrder; // BeginTabItem() order, used to re-order tabs after toggling ImGuiTabBarFlags_Reorderable - ImS16 IndexDuringLayout; // Index only used during TabBarLayout() + ImS16 IndexDuringLayout; // Index only used during TabBarLayout(). Tabs gets reordered so 'Tabs[n].IndexDuringLayout == n' but may mismatch during additions. bool WantClose; // Marked as closed by SetTabItemClosed() - ImGuiTabItem() { memset(this, 0, sizeof(*this)); LastFrameVisible = LastFrameSelected = -1; NameOffset = -1; BeginOrder = IndexDuringLayout = -1; } + ImGuiTabItem() { memset(this, 0, sizeof(*this)); LastFrameVisible = LastFrameSelected = -1; RequestedWidth = -1.0f; NameOffset = -1; BeginOrder = IndexDuringLayout = -1; } }; // Storage for a tab bar (sizeof() 152 bytes) @@ -2488,28 +2708,20 @@ struct IMGUI_API ImGuiTabBar ImGuiTextBuffer TabsNames; // For non-docking tab bar we re-append names in a contiguous buffer. ImGuiTabBar(); - int GetTabOrder(const ImGuiTabItem* tab) const { return Tabs.index_from_ptr(tab); } - const char* GetTabName(const ImGuiTabItem* tab) const - { - if (tab->Window) - return tab->Window->Name; - IM_ASSERT(tab->NameOffset != -1 && tab->NameOffset < TabsNames.Buf.Size); - return TabsNames.Buf.Data + tab->NameOffset; - } }; //----------------------------------------------------------------------------- // [SECTION] Table support //----------------------------------------------------------------------------- -#define IM_COL32_DISABLE IM_COL32(0,0,0,1) // Special sentinel code which cannot be used as a regular color. -#define IMGUI_TABLE_DRAW_CHANNELS(c) (4 + (c) * 2) // See TableSetupDrawChannels() +#define IM_COL32_DISABLE IM_COL32(0,0,0,1) // Special sentinel code which cannot be used as a regular color. +#define IMGUI_TABLE_MAX_COLUMNS 512 // May be further lifted -// Our current column maximum is IMGUI_TABLE_MAX_COLUMNS but we may raise that in the future. +// Our current column maximum is 64 but we may raise that in the future. typedef ImS16 ImGuiTableColumnIdx; typedef ImU16 ImGuiTableDrawChannelIdx; -// [Internal] sizeof() ~ 104 +// [Internal] sizeof() ~ 112 // We use the terminology "Enabled" to refer to a column that is not Hidden by user/api. // We use the terminology "Clipped" to refer to a column that is out of sight because of scrolling/clipping. // This is in contrast with some user-facing api such as IsItemVisible() / IsRectVisible() which use "Visible" to mean "not clipped". @@ -2555,7 +2767,7 @@ struct ImGuiTableColumn ImU8 SortDirection : 2; // ImGuiSortDirection_Ascending or ImGuiSortDirection_Descending ImU8 SortDirectionsAvailCount : 2; // Number of available sort directions (0 to 3) ImU8 SortDirectionsAvailMask : 4; // Mask of available sort directions (1-bit each) - ImU8 SortDirectionsAvailList; // Ordered of available sort directions (2-bits each) + ImU8 SortDirectionsAvailList; // Ordered list of available sort directions (2-bits each, total 8-bits) ImGuiTableColumn() { @@ -2566,7 +2778,7 @@ struct ImGuiTableColumn PrevEnabledColumn = NextEnabledColumn = -1; SortOrder = -1; SortDirection = ImGuiSortDirection_None; - DrawChannelCurrent = DrawChannelFrozen = DrawChannelUnfrozen = (ImU16)-1; + DrawChannelCurrent = DrawChannelFrozen = DrawChannelUnfrozen = (ImU8)-1; } }; @@ -2578,16 +2790,19 @@ struct ImGuiTableCellData ImGuiTableColumnIdx Column; // Column number }; -// Per-instance data that needs preserving across frames (seemingly most others do not need to be preserved aside from debug needs, does that needs they could be moved to ImGuiTableTempData ?) +// Per-instance data that needs preserving across frames (seemingly most others do not need to be preserved aside from debug needs. Does that means they could be moved to ImGuiTableTempData?) struct ImGuiTableInstanceData { - float LastOuterHeight; // Outer height from last frame // FIXME: multi-instance issue (#3955) - float LastFirstRowHeight; // Height of first row from last frame // FIXME: possible multi-instance issue? + ImGuiID TableInstanceID; + float LastOuterHeight; // Outer height from last frame + float LastFirstRowHeight; // Height of first row from last frame (FIXME: this is used as "header height" and may be reworked) + float LastFrozenHeight; // Height of frozen section from last frame - ImGuiTableInstanceData() { LastOuterHeight = LastFirstRowHeight = 0.0f; } + ImGuiTableInstanceData() { TableInstanceID = 0; LastOuterHeight = LastFirstRowHeight = LastFrozenHeight = 0.0f; } }; -// FIXME-TABLE: more transient data could be stored in a per-stacked table structure: DrawSplitter, SortSpecs, incoming RowData +// FIXME-TABLE: more transient data could be stored in a stacked ImGuiTableTempData: e.g. SortSpecs, incoming RowData +// sizeof() ~ 580 bytes + heap allocs described in TableBeginInitMemory() struct IMGUI_API ImGuiTable { ImGuiID ID; @@ -2597,10 +2812,9 @@ struct IMGUI_API ImGuiTable ImSpan Columns; // Point within RawData[] ImSpan DisplayOrderToIndex; // Point within RawData[]. Store display order of columns (when not reordered, the values are 0...Count-1) ImSpan RowCellData; // Point within RawData[]. Store cells background requests for current row. - ImBitVector EnabledMaskByDisplayOrder; // Column DisplayOrder -> IsEnabled map - ImBitVector EnabledMaskByIndex; // Column Index -> IsEnabled map (== not hidden by user/api) in a format adequate for iterating column without touching cold data - ImBitVector VisibleMaskByIndex; // Column Index -> IsVisibleX|IsVisibleY map (== not hidden by user/api && not hidden by scrolling/cliprect) - ImBitVector RequestOutputMaskByIndex; // Column Index -> IsVisible || AutoFit (== expect user to submit items) + ImBitArrayPtr EnabledMaskByDisplayOrder; // Column DisplayOrder -> IsEnabled map + ImBitArrayPtr EnabledMaskByIndex; // Column Index -> IsEnabled map (== not hidden by user/api) in a format adequate for iterating column without touching cold data + ImBitArrayPtr VisibleMaskByIndex; // Column Index -> IsVisibleX|IsVisibleY map (== not hidden by user/api && not hidden by scrolling/cliprect) ImGuiTableFlags SettingsLoadedFlags; // Which data were loaded from the .ini file (e.g. when order is not altered we won't save order) int SettingsOffset; // Offset in g.SettingsTables int LastFrameActive; @@ -2692,6 +2906,8 @@ struct IMGUI_API ImGuiTable bool IsResetDisplayOrderRequest; bool IsUnfrozenRows; // Set when we got past the frozen row. bool IsDefaultSizingPolicy; // Set if user didn't explicitly set a sizing policy in BeginTable() + bool HasScrollbarYCurr; // Whether ANY instance of this table had a vertical scrollbar during the current frame. + bool HasScrollbarYPrev; // Whether ANY instance of this table had a vertical scrollbar during the previous. bool MemoryCompacted; bool HostSkipItems; // Backup of InnerWindow->SkipItem at the end of BeginTable(), because we will overwrite InnerWindow->SkipItem on a per-column basis @@ -2702,6 +2918,7 @@ struct IMGUI_API ImGuiTable // Transient data that are only needed between BeginTable() and EndTable(), those buffers are shared (1 per level of stacked table). // - Accessing those requires chasing an extra pointer so for very frequently used data we leave them in the main table structure. // - We also leave out of this structure data that tend to be particularly useful for debugging/metrics. +// sizeof() ~ 112 bytes. struct IMGUI_API ImGuiTableTempData { int TableIndex; // Index in g.Tables.Buf[] pool @@ -2786,12 +3003,14 @@ namespace ImGui IMGUI_API void SetWindowSize(ImGuiWindow* window, const ImVec2& size, ImGuiCond cond = 0); IMGUI_API void SetWindowCollapsed(ImGuiWindow* window, bool collapsed, ImGuiCond cond = 0); IMGUI_API void SetWindowHitTestHole(ImGuiWindow* window, const ImVec2& pos, const ImVec2& size); + IMGUI_API void SetWindowHiddendAndSkipItemsForCurrentFrame(ImGuiWindow* window); inline ImRect WindowRectAbsToRel(ImGuiWindow* window, const ImRect& r) { ImVec2 off = window->DC.CursorStartPos; return ImRect(r.Min.x - off.x, r.Min.y - off.y, r.Max.x - off.x, r.Max.y - off.y); } inline ImRect WindowRectRelToAbs(ImGuiWindow* window, const ImRect& r) { ImVec2 off = window->DC.CursorStartPos; return ImRect(r.Min.x + off.x, r.Min.y + off.y, r.Max.x + off.x, r.Max.y + off.y); } + inline ImVec2 WindowPosRelToAbs(ImGuiWindow* window, const ImVec2& p) { ImVec2 off = window->DC.CursorStartPos; return ImVec2(p.x + off.x, p.y + off.y); } // Windows: Display Order and Focus Order - IMGUI_API void FocusWindow(ImGuiWindow* window); - IMGUI_API void FocusTopMostWindowUnderOne(ImGuiWindow* under_this_window, ImGuiWindow* ignore_window); + IMGUI_API void FocusWindow(ImGuiWindow* window, ImGuiFocusRequestFlags flags = 0); + IMGUI_API void FocusTopMostWindowUnderOne(ImGuiWindow* under_this_window, ImGuiWindow* ignore_window, ImGuiViewport* filter_viewport, ImGuiFocusRequestFlags flags); IMGUI_API void BringWindowToFocusFront(ImGuiWindow* window); IMGUI_API void BringWindowToDisplayFront(ImGuiWindow* window); IMGUI_API void BringWindowToDisplayBack(ImGuiWindow* window); @@ -2834,15 +3053,21 @@ namespace ImGui IMGUI_API void MarkIniSettingsDirty(); IMGUI_API void MarkIniSettingsDirty(ImGuiWindow* window); IMGUI_API void ClearIniSettings(); - IMGUI_API ImGuiWindowSettings* CreateNewWindowSettings(const char* name); - IMGUI_API ImGuiWindowSettings* FindWindowSettings(ImGuiID id); - IMGUI_API ImGuiWindowSettings* FindOrCreateWindowSettings(const char* name); IMGUI_API void AddSettingsHandler(const ImGuiSettingsHandler* handler); IMGUI_API void RemoveSettingsHandler(const char* type_name); IMGUI_API ImGuiSettingsHandler* FindSettingsHandler(const char* type_name); + // Settings - Windows + IMGUI_API ImGuiWindowSettings* CreateNewWindowSettings(const char* name); + IMGUI_API ImGuiWindowSettings* FindWindowSettingsByID(ImGuiID id); + IMGUI_API ImGuiWindowSettings* FindWindowSettingsByWindow(ImGuiWindow* window); + IMGUI_API void ClearWindowSettings(const char* name); + + // Localization + IMGUI_API void LocalizeRegisterEntries(const ImGuiLocEntry* entries, int count); + inline const char* LocalizeGetMsg(ImGuiLocKey key) { ImGuiContext& g = *GImGui; const char* msg = g.LocalizationTable[key]; return msg ? msg : "*Missing Text*"; } + // Scrolling - IMGUI_API void SetNextWindowScroll(const ImVec2& scroll); // Use -1.0f on one axis to leave as-is IMGUI_API void SetScrollX(ImGuiWindow* window, float scroll_x); IMGUI_API void SetScrollY(ImGuiWindow* window, float scroll_y); IMGUI_API void SetScrollFromPosX(ImGuiWindow* window, float local_x, float center_x_ratio); @@ -2857,7 +3082,6 @@ namespace ImGui //#endif // Basic Accessors - inline ImGuiID GetItemID() { ImGuiContext& g = *GImGui; return g.LastItemData.ID; } // Get ID of last item (~~ often same ImGui::GetID(label) beforehand) inline ImGuiItemStatusFlags GetItemStatusFlags(){ ImGuiContext& g = *GImGui; return g.LastItemData.StatusFlags; } inline ImGuiItemFlags GetItemFlags() { ImGuiContext& g = *GImGui; return g.LastItemData.InFlags; } inline ImGuiID GetActiveID() { ImGuiContext& g = *GImGui; return g.ActiveId; } @@ -2871,12 +3095,14 @@ namespace ImGui IMGUI_API void MarkItemEdited(ImGuiID id); // Mark data associated to given item as "edited", used by IsItemDeactivatedAfterEdit() function. IMGUI_API void PushOverrideID(ImGuiID id); // Push given value as-is at the top of the ID stack (whereas PushID combines old and new hashes) IMGUI_API ImGuiID GetIDWithSeed(const char* str_id_begin, const char* str_id_end, ImGuiID seed); + IMGUI_API ImGuiID GetIDWithSeed(int n, ImGuiID seed); // Basic Helpers for widget code IMGUI_API void ItemSize(const ImVec2& size, float text_baseline_y = -1.0f); inline void ItemSize(const ImRect& bb, float text_baseline_y = -1.0f) { ItemSize(bb.GetSize(), text_baseline_y); } // FIXME: This is a misleading API since we expect CursorPos to be bb.Min. IMGUI_API bool ItemAdd(const ImRect& bb, ImGuiID id, const ImRect* nav_bb = NULL, ImGuiItemFlags extra_flags = 0); IMGUI_API bool ItemHoverable(const ImRect& bb, ImGuiID id); + IMGUI_API bool IsWindowContentHoverable(ImGuiWindow* window, ImGuiHoveredFlags flags = 0); IMGUI_API bool IsClippedEx(const ImRect& bb, ImGuiID id); IMGUI_API void SetLastItemData(ImGuiID item_id, ImGuiItemFlags in_flags, ImGuiItemStatusFlags status_flags, const ImRect& item_rect); IMGUI_API ImVec2 CalcItemSize(ImVec2 size, float default_w, float default_h); @@ -2886,20 +3112,10 @@ namespace ImGui IMGUI_API ImVec2 GetContentRegionMaxAbs(); IMGUI_API void ShrinkWidths(ImGuiShrinkWidthItem* items, int count, float width_excess); - // Parameter stacks + // Parameter stacks (shared) IMGUI_API void PushItemFlag(ImGuiItemFlags option, bool enabled); IMGUI_API void PopItemFlag(); - -#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS - // Currently refactoring focus/nav/tabbing system - // If you have old/custom copy-and-pasted widgets that used FocusableItemRegister(): - // (Old) IMGUI_VERSION_NUM < 18209: using 'ItemAdd(....)' and 'bool tab_focused = FocusableItemRegister(...)' - // (Old) IMGUI_VERSION_NUM >= 18209: using 'ItemAdd(..., ImGuiItemAddFlags_Focusable)' and 'bool tab_focused = (GetItemStatusFlags() & ImGuiItemStatusFlags_Focused) != 0' - // (New) IMGUI_VERSION_NUM >= 18413: using 'ItemAdd(..., ImGuiItemFlags_Inputable)' and 'bool tab_focused = (GetItemStatusFlags() & ImGuiItemStatusFlags_FocusedTabbing) != 0 || g.NavActivateInputId == id' (WIP) - // Widget code are simplified as there's no need to call FocusableItemUnregister() while managing the transition from regular widget to TempInputText() - inline bool FocusableItemRegister(ImGuiWindow* window, ImGuiID id) { IM_ASSERT(0); IM_UNUSED(window); IM_UNUSED(id); return false; } // -> pass ImGuiItemAddFlags_Inputable flag to ItemAdd() - inline void FocusableItemUnregister(ImGuiWindow* window) { IM_ASSERT(0); IM_UNUSED(window); } // -> unnecessary: TempInputText() uses ImGuiInputTextFlags_MergedItem -#endif + IMGUI_API const ImGuiDataVarInfo* GetStyleVarInfo(ImGuiStyleVar idx); // Logging/Capture IMGUI_API void LogBegin(ImGuiLogType type, int auto_open_depth); // -> BeginCapture() when we design v2 api, for now stay under the radar by using the old name. @@ -2915,10 +3131,11 @@ namespace ImGui IMGUI_API void ClosePopupsExceptModals(); IMGUI_API bool IsPopupOpen(ImGuiID id, ImGuiPopupFlags popup_flags); IMGUI_API bool BeginPopupEx(ImGuiID id, ImGuiWindowFlags extra_flags); - IMGUI_API void BeginTooltipEx(ImGuiTooltipFlags tooltip_flags, ImGuiWindowFlags extra_window_flags); + IMGUI_API bool BeginTooltipEx(ImGuiTooltipFlags tooltip_flags, ImGuiWindowFlags extra_window_flags); IMGUI_API ImRect GetPopupAllowedExtentRect(ImGuiWindow* window); IMGUI_API ImGuiWindow* GetTopMostPopupModal(); IMGUI_API ImGuiWindow* GetTopMostAndVisiblePopupModal(); + IMGUI_API ImGuiWindow* FindBlockingModal(ImGuiWindow* window); IMGUI_API ImVec2 FindBestWindowPosForPopup(ImGuiWindow* window); IMGUI_API ImVec2 FindBestWindowPosForPopupEx(const ImVec2& ref_pos, const ImVec2& size, ImGuiDir* last_dir, const ImRect& r_outer, const ImRect& r_avoid, ImGuiPopupPositionPolicy policy); @@ -2942,40 +3159,90 @@ namespace ImGui IMGUI_API void NavMoveRequestCancel(); IMGUI_API void NavMoveRequestApplyResult(); IMGUI_API void NavMoveRequestTryWrapping(ImGuiWindow* window, ImGuiNavMoveFlags move_flags); - IMGUI_API const char* GetNavInputName(ImGuiNavInput n); - IMGUI_API float GetNavInputAmount(ImGuiNavInput n, ImGuiNavReadMode mode); - IMGUI_API ImVec2 GetNavInputAmount2d(ImGuiNavDirSourceFlags dir_sources, ImGuiNavReadMode mode, float slow_factor = 0.0f, float fast_factor = 0.0f); - IMGUI_API int CalcTypematicRepeatAmount(float t0, float t1, float repeat_delay, float repeat_rate); + IMGUI_API void NavClearPreferredPosForAxis(ImGuiAxis axis); + IMGUI_API void NavUpdateCurrentWindowIsScrollPushableX(); IMGUI_API void ActivateItem(ImGuiID id); // Remotely activate a button, checkbox, tree node etc. given its unique ID. activation is queued and processed on the next frame when the item is encountered again. + IMGUI_API void SetNavWindow(ImGuiWindow* window); IMGUI_API void SetNavID(ImGuiID id, ImGuiNavLayer nav_layer, ImGuiID focus_scope_id, const ImRect& rect_rel); - // Focus Scope (WIP) - // This is generally used to identify a selection set (multiple of which may be in the same window), as selection - // patterns generally need to react (e.g. clear selection) when landing on an item of the set. - IMGUI_API void PushFocusScope(ImGuiID id); - IMGUI_API void PopFocusScope(); - inline ImGuiID GetFocusedFocusScope() { ImGuiContext& g = *GImGui; return g.NavFocusScopeId; } // Focus scope which is actually active - inline ImGuiID GetFocusScope() { ImGuiContext& g = *GImGui; return g.CurrentWindow->DC.NavFocusScopeIdCurrent; } // Focus scope we are outputting into, set by PushFocusScope() - // Inputs // FIXME: Eventually we should aim to move e.g. IsActiveIdUsingKey() into IsKeyXXX functions. inline bool IsNamedKey(ImGuiKey key) { return key >= ImGuiKey_NamedKey_BEGIN && key < ImGuiKey_NamedKey_END; } + inline bool IsNamedKeyOrModKey(ImGuiKey key) { return (key >= ImGuiKey_NamedKey_BEGIN && key < ImGuiKey_NamedKey_END) || key == ImGuiMod_Ctrl || key == ImGuiMod_Shift || key == ImGuiMod_Alt || key == ImGuiMod_Super || key == ImGuiMod_Shortcut; } inline bool IsLegacyKey(ImGuiKey key) { return key >= ImGuiKey_LegacyNativeKey_BEGIN && key < ImGuiKey_LegacyNativeKey_END; } + inline bool IsKeyboardKey(ImGuiKey key) { return key >= ImGuiKey_Keyboard_BEGIN && key < ImGuiKey_Keyboard_END; } inline bool IsGamepadKey(ImGuiKey key) { return key >= ImGuiKey_Gamepad_BEGIN && key < ImGuiKey_Gamepad_END; } - IMGUI_API ImGuiKeyData* GetKeyData(ImGuiKey key); - IMGUI_API void SetItemUsingMouseWheel(); - IMGUI_API void SetActiveIdUsingNavAndKeys(); - inline bool IsActiveIdUsingNavDir(ImGuiDir dir) { ImGuiContext& g = *GImGui; return (g.ActiveIdUsingNavDirMask & (1 << dir)) != 0; } - inline bool IsActiveIdUsingNavInput(ImGuiNavInput input) { ImGuiContext& g = *GImGui; return (g.ActiveIdUsingNavInputMask & (1 << input)) != 0; } - inline bool IsActiveIdUsingKey(ImGuiKey key) { ImGuiContext& g = *GImGui; return g.ActiveIdUsingKeyInputMask[key]; } - inline void SetActiveIdUsingKey(ImGuiKey key) { ImGuiContext& g = *GImGui; g.ActiveIdUsingKeyInputMask.SetBit(key); } + inline bool IsMouseKey(ImGuiKey key) { return key >= ImGuiKey_Mouse_BEGIN && key < ImGuiKey_Mouse_END; } + inline bool IsAliasKey(ImGuiKey key) { return key >= ImGuiKey_Aliases_BEGIN && key < ImGuiKey_Aliases_END; } + inline ImGuiKeyChord ConvertShortcutMod(ImGuiKeyChord key_chord) { ImGuiContext& g = *GImGui; IM_ASSERT_PARANOID(key_chord & ImGuiMod_Shortcut); return (key_chord & ~ImGuiMod_Shortcut) | (g.IO.ConfigMacOSXBehaviors ? ImGuiMod_Super : ImGuiMod_Ctrl); } + inline ImGuiKey ConvertSingleModFlagToKey(ImGuiContext* ctx, ImGuiKey key) + { + ImGuiContext& g = *ctx; + if (key == ImGuiMod_Ctrl) return ImGuiKey_ReservedForModCtrl; + if (key == ImGuiMod_Shift) return ImGuiKey_ReservedForModShift; + if (key == ImGuiMod_Alt) return ImGuiKey_ReservedForModAlt; + if (key == ImGuiMod_Super) return ImGuiKey_ReservedForModSuper; + if (key == ImGuiMod_Shortcut) return (g.IO.ConfigMacOSXBehaviors ? ImGuiKey_ReservedForModSuper : ImGuiKey_ReservedForModCtrl); + return key; + } + + IMGUI_API ImGuiKeyData* GetKeyData(ImGuiContext* ctx, ImGuiKey key); + inline ImGuiKeyData* GetKeyData(ImGuiKey key) { ImGuiContext& g = *GImGui; return GetKeyData(&g, key); } + IMGUI_API void GetKeyChordName(ImGuiKeyChord key_chord, char* out_buf, int out_buf_size); + inline ImGuiKey MouseButtonToKey(ImGuiMouseButton button) { IM_ASSERT(button >= 0 && button < ImGuiMouseButton_COUNT); return (ImGuiKey)(ImGuiKey_MouseLeft + button); } IMGUI_API bool IsMouseDragPastThreshold(ImGuiMouseButton button, float lock_threshold = -1.0f); - inline bool IsNavInputDown(ImGuiNavInput n) { ImGuiContext& g = *GImGui; return g.IO.NavInputs[n] > 0.0f; } - inline bool IsNavInputTest(ImGuiNavInput n, ImGuiNavReadMode rm) { return (GetNavInputAmount(n, rm) > 0.0f); } - IMGUI_API ImGuiModFlags GetMergedModFlags(); -#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO - inline bool IsKeyPressedMap(ImGuiKey key, bool repeat = true) { IM_ASSERT(IsNamedKey(key)); return IsKeyPressed(key, repeat); } // [removed in 1.87] -#endif + IMGUI_API ImVec2 GetKeyMagnitude2d(ImGuiKey key_left, ImGuiKey key_right, ImGuiKey key_up, ImGuiKey key_down); + IMGUI_API float GetNavTweakPressedAmount(ImGuiAxis axis); + IMGUI_API int CalcTypematicRepeatAmount(float t0, float t1, float repeat_delay, float repeat_rate); + IMGUI_API void GetTypematicRepeatRate(ImGuiInputFlags flags, float* repeat_delay, float* repeat_rate); + IMGUI_API void SetActiveIdUsingAllKeyboardKeys(); + inline bool IsActiveIdUsingNavDir(ImGuiDir dir) { ImGuiContext& g = *GImGui; return (g.ActiveIdUsingNavDirMask & (1 << dir)) != 0; } + + // [EXPERIMENTAL] Low-Level: Key/Input Ownership + // - The idea is that instead of "eating" a given input, we can link to an owner id. + // - Ownership is most often claimed as a result of reacting to a press/down event (but occasionally may be claimed ahead). + // - Input queries can then read input by specifying ImGuiKeyOwner_Any (== 0), ImGuiKeyOwner_None (== -1) or a custom ID. + // - Legacy input queries (without specifying an owner or _Any or _None) are equivalent to using ImGuiKeyOwner_Any (== 0). + // - Input ownership is automatically released on the frame after a key is released. Therefore: + // - for ownership registration happening as a result of a down/press event, the SetKeyOwner() call may be done once (common case). + // - for ownership registration happening ahead of a down/press event, the SetKeyOwner() call needs to be made every frame (happens if e.g. claiming ownership on hover). + // - SetItemKeyOwner() is a shortcut for common simple case. A custom widget will probably want to call SetKeyOwner() multiple times directly based on its interaction state. + // - This is marked experimental because not all widgets are fully honoring the Set/Test idioms. We will need to move forward step by step. + // Please open a GitHub Issue to submit your usage scenario or if there's a use case you need solved. + IMGUI_API ImGuiID GetKeyOwner(ImGuiKey key); + IMGUI_API void SetKeyOwner(ImGuiKey key, ImGuiID owner_id, ImGuiInputFlags flags = 0); + IMGUI_API void SetKeyOwnersForKeyChord(ImGuiKeyChord key, ImGuiID owner_id, ImGuiInputFlags flags = 0); + IMGUI_API void SetItemKeyOwner(ImGuiKey key, ImGuiInputFlags flags = 0); // Set key owner to last item if it is hovered or active. Equivalent to 'if (IsItemHovered() || IsItemActive()) { SetKeyOwner(key, GetItemID());'. + IMGUI_API bool TestKeyOwner(ImGuiKey key, ImGuiID owner_id); // Test that key is either not owned, either owned by 'owner_id' + inline ImGuiKeyOwnerData* GetKeyOwnerData(ImGuiContext* ctx, ImGuiKey key) { if (key & ImGuiMod_Mask_) key = ConvertSingleModFlagToKey(ctx, key); IM_ASSERT(IsNamedKey(key)); return &ctx->KeysOwnerData[key - ImGuiKey_NamedKey_BEGIN]; } + + // [EXPERIMENTAL] High-Level: Input Access functions w/ support for Key/Input Ownership + // - Important: legacy IsKeyPressed(ImGuiKey, bool repeat=true) _DEFAULTS_ to repeat, new IsKeyPressed() requires _EXPLICIT_ ImGuiInputFlags_Repeat flag. + // - Expected to be later promoted to public API, the prototypes are designed to replace existing ones (since owner_id can default to Any == 0) + // - Specifying a value for 'ImGuiID owner' will test that EITHER the key is NOT owned (UNLESS locked), EITHER the key is owned by 'owner'. + // Legacy functions use ImGuiKeyOwner_Any meaning that they typically ignore ownership, unless a call to SetKeyOwner() explicitly used ImGuiInputFlags_LockThisFrame or ImGuiInputFlags_LockUntilRelease. + // - Binding generators may want to ignore those for now, or suffix them with Ex() until we decide if this gets moved into public API. + IMGUI_API bool IsKeyDown(ImGuiKey key, ImGuiID owner_id); + IMGUI_API bool IsKeyPressed(ImGuiKey key, ImGuiID owner_id, ImGuiInputFlags flags = 0); // Important: when transitioning from old to new IsKeyPressed(): old API has "bool repeat = true", so would default to repeat. New API requiress explicit ImGuiInputFlags_Repeat. + IMGUI_API bool IsKeyReleased(ImGuiKey key, ImGuiID owner_id); + IMGUI_API bool IsMouseDown(ImGuiMouseButton button, ImGuiID owner_id); + IMGUI_API bool IsMouseClicked(ImGuiMouseButton button, ImGuiID owner_id, ImGuiInputFlags flags = 0); + IMGUI_API bool IsMouseReleased(ImGuiMouseButton button, ImGuiID owner_id); + + // [EXPERIMENTAL] Shortcut Routing + // - ImGuiKeyChord = a ImGuiKey optionally OR-red with ImGuiMod_Alt/ImGuiMod_Ctrl/ImGuiMod_Shift/ImGuiMod_Super. + // ImGuiKey_C (accepted by functions taking ImGuiKey or ImGuiKeyChord) + // ImGuiKey_C | ImGuiMod_Ctrl (accepted by functions taking ImGuiKeyChord) + // ONLY ImGuiMod_XXX values are legal to 'OR' with an ImGuiKey. You CANNOT 'OR' two ImGuiKey values. + // - When using one of the routing flags (e.g. ImGuiInputFlags_RouteFocused): routes requested ahead of time given a chord (key + modifiers) and a routing policy. + // - Routes are resolved during NewFrame(): if keyboard modifiers are matching current ones: SetKeyOwner() is called + route is granted for the frame. + // - Route is granted to a single owner. When multiple requests are made we have policies to select the winning route. + // - Multiple read sites may use the same owner id and will all get the granted route. + // - For routing: when owner_id is 0 we use the current Focus Scope ID as a default owner in order to identify our location. + IMGUI_API bool Shortcut(ImGuiKeyChord key_chord, ImGuiID owner_id = 0, ImGuiInputFlags flags = 0); + IMGUI_API bool SetShortcutRouting(ImGuiKeyChord key_chord, ImGuiID owner_id = 0, ImGuiInputFlags flags = 0); + IMGUI_API bool TestShortcutRouting(ImGuiKeyChord key_chord, ImGuiID owner_id); + IMGUI_API ImGuiKeyRoutingData* GetShortcutRoutingData(ImGuiKeyChord key_chord); // Docking // (some functions are only declared in imgui.cpp, see Docking section) @@ -2990,7 +3257,11 @@ namespace ImGui IMGUI_API void DockContextQueueDock(ImGuiContext* ctx, ImGuiWindow* target, ImGuiDockNode* target_node, ImGuiWindow* payload, ImGuiDir split_dir, float split_ratio, bool split_outer); IMGUI_API void DockContextQueueUndockWindow(ImGuiContext* ctx, ImGuiWindow* window); IMGUI_API void DockContextQueueUndockNode(ImGuiContext* ctx, ImGuiDockNode* node); - IMGUI_API bool DockContextCalcDropPosForDocking(ImGuiWindow* target, ImGuiDockNode* target_node, ImGuiWindow* payload, ImGuiDir split_dir, bool split_outer, ImVec2* out_pos); + IMGUI_API void DockContextProcessUndockWindow(ImGuiContext* ctx, ImGuiWindow* window, bool clear_persistent_docking_ref = true); + IMGUI_API void DockContextProcessUndockNode(ImGuiContext* ctx, ImGuiDockNode* node); + IMGUI_API bool DockContextCalcDropPosForDocking(ImGuiWindow* target, ImGuiDockNode* target_node, ImGuiWindow* payload_window, ImGuiDockNode* payload_node, ImGuiDir split_dir, bool split_outer, ImVec2* out_pos); + IMGUI_API ImGuiDockNode*DockContextFindNodeByID(ImGuiContext* ctx, ImGuiID id); + IMGUI_API void DockNodeWindowMenuHandler_Default(ImGuiContext* ctx, ImGuiDockNode* node, ImGuiTabBar* tab_bar); IMGUI_API bool DockNodeBeginAmendTabBar(ImGuiDockNode* node); IMGUI_API void DockNodeEndAmendTabBar(); inline ImGuiDockNode* DockNodeGetRootNode(ImGuiDockNode* node) { while (node->ParentNode) node = node->ParentNode; return node; } @@ -3028,10 +3299,24 @@ namespace ImGui IMGUI_API void DockBuilderCopyWindowSettings(const char* src_name, const char* dst_name); IMGUI_API void DockBuilderFinish(ImGuiID node_id); + // [EXPERIMENTAL] Focus Scope + // This is generally used to identify a unique input location (for e.g. a selection set) + // There is one per window (automatically set in Begin), but: + // - Selection patterns generally need to react (e.g. clear a selection) when landing on one item of the set. + // So in order to identify a set multiple lists in same window may each need a focus scope. + // If you imagine an hypothetical BeginSelectionGroup()/EndSelectionGroup() api, it would likely call PushFocusScope()/EndFocusScope() + // - Shortcut routing also use focus scope as a default location identifier if an owner is not provided. + // We don't use the ID Stack for this as it is common to want them separate. + IMGUI_API void PushFocusScope(ImGuiID id); + IMGUI_API void PopFocusScope(); + inline ImGuiID GetCurrentFocusScope() { ImGuiContext& g = *GImGui; return g.CurrentFocusScopeId; } // Focus scope we are outputting into, set by PushFocusScope() + // Drag and Drop + IMGUI_API bool IsDragDropActive(); IMGUI_API bool BeginDragDropTargetCustom(const ImRect& bb, ImGuiID id); IMGUI_API void ClearDragDrop(); IMGUI_API bool IsDragDropPayloadBeingAccepted(); + IMGUI_API void RenderDragDropTargetRect(const ImRect& bb); // Internal Columns API (this is not exposed because we will encourage transitioning to the Tables API) IMGUI_API void SetWindowClipRectBeforeSetChannel(ImGuiWindow* window, const ImRect& clip_rect); @@ -3066,8 +3351,10 @@ namespace ImGui IMGUI_API void TableUpdateColumnsWeightFromWidth(ImGuiTable* table); IMGUI_API void TableDrawBorders(ImGuiTable* table); IMGUI_API void TableDrawContextMenu(ImGuiTable* table); + IMGUI_API bool TableBeginContextMenuPopup(ImGuiTable* table); IMGUI_API void TableMergeDrawChannels(ImGuiTable* table); - inline ImGuiTableInstanceData* TableGetInstanceData(ImGuiTable* table, int instance_no) { if (instance_no == 0) return &table->InstanceDataFirst; return &table->InstanceDataExtra[instance_no - 1]; } + inline ImGuiTableInstanceData* TableGetInstanceData(ImGuiTable* table, int instance_no) { if (instance_no == 0) return &table->InstanceDataFirst; return &table->InstanceDataExtra[instance_no - 1]; } + inline ImGuiID TableGetInstanceID(ImGuiTable* table, int instance_no) { return TableGetInstanceData(table, instance_no)->TableInstanceID; } IMGUI_API void TableSortSpecsSanitize(ImGuiTable* table); IMGUI_API void TableSortSpecsBuild(ImGuiTable* table); IMGUI_API ImGuiSortDirection TableGetColumnNextSortDirection(ImGuiTableColumn* column); @@ -3079,7 +3366,7 @@ namespace ImGui IMGUI_API void TableEndCell(ImGuiTable* table); IMGUI_API ImRect TableGetCellBgRect(const ImGuiTable* table, int column_n); IMGUI_API const char* TableGetColumnName(const ImGuiTable* table, int column_n); - IMGUI_API ImGuiID TableGetColumnResizeID(const ImGuiTable* table, int column_n, int instance_no = 0); + IMGUI_API ImGuiID TableGetColumnResizeID(ImGuiTable* table, int column_n, int instance_no = 0); IMGUI_API float TableGetMaxColumnWidth(const ImGuiTable* table, int column_n); IMGUI_API void TableSetColumnWidthAutoSingle(ImGuiTable* table, int column_n); IMGUI_API void TableSetColumnWidthAutoAll(ImGuiTable* table); @@ -3098,17 +3385,24 @@ namespace ImGui IMGUI_API ImGuiTableSettings* TableSettingsFindByID(ImGuiID id); // Tab Bars + inline ImGuiTabBar* GetCurrentTabBar() { ImGuiContext& g = *GImGui; return g.CurrentTabBar; } IMGUI_API bool BeginTabBarEx(ImGuiTabBar* tab_bar, const ImRect& bb, ImGuiTabBarFlags flags, ImGuiDockNode* dock_node); IMGUI_API ImGuiTabItem* TabBarFindTabByID(ImGuiTabBar* tab_bar, ImGuiID tab_id); + IMGUI_API ImGuiTabItem* TabBarFindTabByOrder(ImGuiTabBar* tab_bar, int order); IMGUI_API ImGuiTabItem* TabBarFindMostRecentlySelectedTabForActiveWindow(ImGuiTabBar* tab_bar); + IMGUI_API ImGuiTabItem* TabBarGetCurrentTab(ImGuiTabBar* tab_bar); + inline int TabBarGetTabOrder(ImGuiTabBar* tab_bar, ImGuiTabItem* tab) { return tab_bar->Tabs.index_from_ptr(tab); } + IMGUI_API const char* TabBarGetTabName(ImGuiTabBar* tab_bar, ImGuiTabItem* tab); IMGUI_API void TabBarAddTab(ImGuiTabBar* tab_bar, ImGuiTabItemFlags tab_flags, ImGuiWindow* window); IMGUI_API void TabBarRemoveTab(ImGuiTabBar* tab_bar, ImGuiID tab_id); IMGUI_API void TabBarCloseTab(ImGuiTabBar* tab_bar, ImGuiTabItem* tab); - IMGUI_API void TabBarQueueReorder(ImGuiTabBar* tab_bar, const ImGuiTabItem* tab, int offset); - IMGUI_API void TabBarQueueReorderFromMousePos(ImGuiTabBar* tab_bar, const ImGuiTabItem* tab, ImVec2 mouse_pos); + IMGUI_API void TabBarQueueFocus(ImGuiTabBar* tab_bar, ImGuiTabItem* tab); + IMGUI_API void TabBarQueueReorder(ImGuiTabBar* tab_bar, ImGuiTabItem* tab, int offset); + IMGUI_API void TabBarQueueReorderFromMousePos(ImGuiTabBar* tab_bar, ImGuiTabItem* tab, ImVec2 mouse_pos); IMGUI_API bool TabBarProcessReorder(ImGuiTabBar* tab_bar); IMGUI_API bool TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open, ImGuiTabItemFlags flags, ImGuiWindow* docked_window); - IMGUI_API ImVec2 TabItemCalcSize(const char* label, bool has_close_button); + IMGUI_API ImVec2 TabItemCalcSize(const char* label, bool has_close_button_or_unsaved_marker); + IMGUI_API ImVec2 TabItemCalcSize(ImGuiWindow* window); IMGUI_API void TabItemBackground(ImDrawList* draw_list, const ImRect& bb, ImGuiTabItemFlags flags, ImU32 col); IMGUI_API void TabItemLabelAndCloseButton(ImDrawList* draw_list, const ImRect& bb, ImGuiTabItemFlags flags, ImVec2 frame_padding, const char* label, ImGuiID tab_id, ImGuiID close_button_id, bool is_contents_visible, bool* out_just_closed, bool* out_text_clipped); @@ -3140,19 +3434,22 @@ namespace ImGui // Widgets IMGUI_API void TextEx(const char* text, const char* text_end = NULL, ImGuiTextFlags flags = 0); IMGUI_API bool ButtonEx(const char* label, const ImVec2& size_arg = ImVec2(0, 0), ImGuiButtonFlags flags = 0); + IMGUI_API bool ArrowButtonEx(const char* str_id, ImGuiDir dir, ImVec2 size_arg, ImGuiButtonFlags flags = 0); + IMGUI_API bool ImageButtonEx(ImGuiID id, ImTextureID texture_id, const ImVec2& size, const ImVec2& uv0, const ImVec2& uv1, const ImVec4& bg_col, const ImVec4& tint_col, ImGuiButtonFlags flags = 0); + IMGUI_API void SeparatorEx(ImGuiSeparatorFlags flags, float thickness = 1.0f); + IMGUI_API void SeparatorTextEx(ImGuiID id, const char* label, const char* label_end, float extra_width); + IMGUI_API bool CheckboxFlags(const char* label, ImS64* flags, ImS64 flags_value); + IMGUI_API bool CheckboxFlags(const char* label, ImU64* flags, ImU64 flags_value); + + // Widgets: Window Decorations IMGUI_API bool CloseButton(ImGuiID id, const ImVec2& pos); IMGUI_API bool CollapseButton(ImGuiID id, const ImVec2& pos, ImGuiDockNode* dock_node); - IMGUI_API bool ArrowButtonEx(const char* str_id, ImGuiDir dir, ImVec2 size_arg, ImGuiButtonFlags flags = 0); IMGUI_API void Scrollbar(ImGuiAxis axis); IMGUI_API bool ScrollbarEx(const ImRect& bb, ImGuiID id, ImGuiAxis axis, ImS64* p_scroll_v, ImS64 avail_v, ImS64 contents_v, ImDrawFlags flags); - IMGUI_API bool ImageButtonEx(ImGuiID id, ImTextureID texture_id, const ImVec2& size, const ImVec2& uv0, const ImVec2& uv1, const ImVec2& padding, const ImVec4& bg_col, const ImVec4& tint_col); IMGUI_API ImRect GetWindowScrollbarRect(ImGuiWindow* window, ImGuiAxis axis); IMGUI_API ImGuiID GetWindowScrollbarID(ImGuiWindow* window, ImGuiAxis axis); IMGUI_API ImGuiID GetWindowResizeCornerID(ImGuiWindow* window, int n); // 0..3: corners IMGUI_API ImGuiID GetWindowResizeBorderID(ImGuiWindow* window, ImGuiDir dir); - IMGUI_API void SeparatorEx(ImGuiSeparatorFlags flags); - IMGUI_API bool CheckboxFlags(const char* label, ImS64* flags, ImS64 flags_value); - IMGUI_API bool CheckboxFlags(const char* label, ImU64* flags, ImU64 flags_value); // Widgets low-level behaviors IMGUI_API bool ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool* out_held, ImGuiButtonFlags flags = 0); @@ -3160,8 +3457,9 @@ namespace ImGui IMGUI_API bool SliderBehavior(const ImRect& bb, ImGuiID id, ImGuiDataType data_type, void* p_v, const void* p_min, const void* p_max, const char* format, ImGuiSliderFlags flags, ImRect* out_grab_bb); IMGUI_API bool SplitterBehavior(const ImRect& bb, ImGuiID id, ImGuiAxis axis, float* size1, float* size2, float min_size1, float min_size2, float hover_extend = 0.0f, float hover_visibility_delay = 0.0f, ImU32 bg_col = 0); IMGUI_API bool TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* label, const char* label_end = NULL); - IMGUI_API bool TreeNodeBehaviorIsOpen(ImGuiID id, ImGuiTreeNodeFlags flags = 0); // Consume previous SetNextItemOpen() data, if any. May return true when logging IMGUI_API void TreePushOverrideID(ImGuiID id); + IMGUI_API void TreeNodeSetOpen(ImGuiID id, bool open); + IMGUI_API bool TreeNodeUpdateNextOpen(ImGuiID id, ImGuiTreeNodeFlags flags); // Return open state. Consume previous SetNextItemOpen() data, if any. May return true when logging. // Template functions are instantiated in imgui_widgets.cpp for a finite number of types. // To use them externally (for custom widget) you may need an "extern template" statement in your code in order to link to existing instances and silence Clang warnings (see #2036). @@ -3183,10 +3481,11 @@ namespace ImGui // InputText IMGUI_API bool InputTextEx(const char* label, const char* hint, char* buf, int buf_size, const ImVec2& size_arg, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback = NULL, void* user_data = NULL); + IMGUI_API void InputTextDeactivateHook(ImGuiID id); IMGUI_API bool TempInputText(const ImRect& bb, ImGuiID id, const char* label, char* buf, int buf_size, ImGuiInputTextFlags flags); IMGUI_API bool TempInputScalar(const ImRect& bb, ImGuiID id, const char* label, ImGuiDataType data_type, void* p_data, const char* format, const void* p_clamp_min = NULL, const void* p_clamp_max = NULL); inline bool TempInputIsActive(ImGuiID id) { ImGuiContext& g = *GImGui; return (g.ActiveId == id && g.TempInputId == id); } - inline ImGuiInputTextState* GetInputTextState(ImGuiID id) { ImGuiContext& g = *GImGui; return (g.InputTextState.ID == id) ? &g.InputTextState : NULL; } // Get input text state if active + inline ImGuiInputTextState* GetInputTextState(ImGuiID id) { ImGuiContext& g = *GImGui; return (id != 0 && g.InputTextState.ID == id) ? &g.InputTextState : NULL; } // Get input text state if active // Color IMGUI_API void ColorTooltip(const char* text, const float* col, ImGuiColorEditFlags flags); @@ -3194,7 +3493,7 @@ namespace ImGui IMGUI_API void ColorPickerOptionsPopup(const float* ref_col, ImGuiColorEditFlags flags); // Plot - IMGUI_API int PlotEx(ImGuiPlotType plot_type, const char* label, float (*values_getter)(void* data, int idx), void* data, int values_count, int values_offset, const char* overlay_text, float scale_min, float scale_max, ImVec2 frame_size); + IMGUI_API int PlotEx(ImGuiPlotType plot_type, const char* label, float (*values_getter)(void* data, int idx), void* data, int values_count, int values_offset, const char* overlay_text, float scale_min, float scale_max, const ImVec2& size_arg); // Shade functions (write over already created vertices) IMGUI_API void ShadeVertsLinearColorGradientKeepAlpha(ImDrawList* draw_list, int vert_start_idx, int vert_end_idx, ImVec2 gradient_p0, ImVec2 gradient_p1, ImU32 col0, ImU32 col1); @@ -3205,12 +3504,19 @@ namespace ImGui IMGUI_API void GcCompactTransientWindowBuffers(ImGuiWindow* window); IMGUI_API void GcAwakeTransientWindowBuffers(ImGuiWindow* window); + // Debug Log + IMGUI_API void DebugLog(const char* fmt, ...) IM_FMTARGS(1); + IMGUI_API void DebugLogV(const char* fmt, va_list args) IM_FMTLIST(1); + // Debug Tools IMGUI_API void ErrorCheckEndFrameRecover(ImGuiErrorLogCallback log_callback, void* user_data = NULL); IMGUI_API void ErrorCheckEndWindowRecover(ImGuiErrorLogCallback log_callback, void* user_data = NULL); + IMGUI_API void ErrorCheckUsingSetCursorPosToExtendParentBoundaries(); + IMGUI_API void DebugLocateItem(ImGuiID target_id); // Call sparingly: only 1 at the same time! + IMGUI_API void DebugLocateItemOnHover(ImGuiID target_id); // Only call on reaction to a mouse Hover: because only 1 at the same time! + IMGUI_API void DebugLocateItemResolveWithLastItem(); inline void DebugDrawItemRect(ImU32 col = IM_COL32(255,0,0,255)) { ImGuiContext& g = *GImGui; ImGuiWindow* window = g.CurrentWindow; GetForegroundDrawList(window)->AddRect(g.LastItemData.Rect.Min, g.LastItemData.Rect.Max, col); } inline void DebugStartItemPicker() { ImGuiContext& g = *GImGui; g.DebugItemPickerActive = true; } - IMGUI_API void ShowFontAtlas(ImFontAtlas* atlas); IMGUI_API void DebugHookIdInfo(ImGuiID id, ImGuiDataType data_type, const void* data_id, const void* data_id_end); IMGUI_API void DebugNodeColumns(ImGuiOldColumns* columns); @@ -3223,13 +3529,32 @@ namespace ImGui IMGUI_API void DebugNodeTabBar(ImGuiTabBar* tab_bar, const char* label); IMGUI_API void DebugNodeTable(ImGuiTable* table); IMGUI_API void DebugNodeTableSettings(ImGuiTableSettings* settings); + IMGUI_API void DebugNodeInputTextState(ImGuiInputTextState* state); IMGUI_API void DebugNodeWindow(ImGuiWindow* window, const char* label); IMGUI_API void DebugNodeWindowSettings(ImGuiWindowSettings* settings); IMGUI_API void DebugNodeWindowsList(ImVector* windows, const char* label); IMGUI_API void DebugNodeWindowsListByBeginStackParent(ImGuiWindow** windows, int windows_size, ImGuiWindow* parent_in_begin_stack); IMGUI_API void DebugNodeViewport(ImGuiViewportP* viewport); + IMGUI_API void DebugRenderKeyboardPreview(ImDrawList* draw_list); IMGUI_API void DebugRenderViewportThumbnail(ImDrawList* draw_list, ImGuiViewportP* viewport, const ImRect& bb); + // Obsolete functions +#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS + inline void SetItemUsingMouseWheel() { SetItemKeyOwner(ImGuiKey_MouseWheelY); } // Changed in 1.89 + inline bool TreeNodeBehaviorIsOpen(ImGuiID id, ImGuiTreeNodeFlags flags = 0) { return TreeNodeUpdateNextOpen(id, flags); } // Renamed in 1.89 + + // Refactored focus/nav/tabbing system in 1.82 and 1.84. If you have old/custom copy-and-pasted widgets that used FocusableItemRegister(): + // (Old) IMGUI_VERSION_NUM < 18209: using 'ItemAdd(....)' and 'bool tab_focused = FocusableItemRegister(...)' + // (Old) IMGUI_VERSION_NUM >= 18209: using 'ItemAdd(..., ImGuiItemAddFlags_Focusable)' and 'bool tab_focused = (GetItemStatusFlags() & ImGuiItemStatusFlags_Focused) != 0' + // (New) IMGUI_VERSION_NUM >= 18413: using 'ItemAdd(..., ImGuiItemFlags_Inputable)' and 'bool tab_focused = (GetItemStatusFlags() & ImGuiItemStatusFlags_FocusedTabbing) != 0 || (g.NavActivateId == id && (g.NavActivateFlags & ImGuiActivateFlags_PreferInput))' (WIP) + // Widget code are simplified as there's no need to call FocusableItemUnregister() while managing the transition from regular widget to TempInputText() + inline bool FocusableItemRegister(ImGuiWindow* window, ImGuiID id) { IM_ASSERT(0); IM_UNUSED(window); IM_UNUSED(id); return false; } // -> pass ImGuiItemAddFlags_Inputable flag to ItemAdd() + inline void FocusableItemUnregister(ImGuiWindow* window) { IM_ASSERT(0); IM_UNUSED(window); } // -> unnecessary: TempInputText() uses ImGuiInputTextFlags_MergedItem +#endif +#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO + inline bool IsKeyPressedMap(ImGuiKey key, bool repeat = true) { IM_ASSERT(IsNamedKey(key)); return IsKeyPressed(key, repeat); } // Removed in 1.87: Mapping from named key is always identity! +#endif + } // namespace ImGui @@ -3261,14 +3586,15 @@ IMGUI_API void ImFontAtlasBuildMultiplyRectAlpha8(const unsigned char table //----------------------------------------------------------------------------- #ifdef IMGUI_ENABLE_TEST_ENGINE -extern void ImGuiTestEngineHook_ItemAdd(ImGuiContext* ctx, const ImRect& bb, ImGuiID id); +extern void ImGuiTestEngineHook_ItemAdd(ImGuiContext* ctx, ImGuiID id, const ImRect& bb, const ImGuiLastItemData* item_data); // item_data may be NULL extern void ImGuiTestEngineHook_ItemInfo(ImGuiContext* ctx, ImGuiID id, const char* label, ImGuiItemStatusFlags flags); extern void ImGuiTestEngineHook_Log(ImGuiContext* ctx, const char* fmt, ...); extern const char* ImGuiTestEngine_FindItemDebugLabel(ImGuiContext* ctx, ImGuiID id); -#define IMGUI_TEST_ENGINE_ITEM_ADD(_BB,_ID) if (g.TestEngineHookItems) ImGuiTestEngineHook_ItemAdd(&g, _BB, _ID) // Register item bounding box -#define IMGUI_TEST_ENGINE_ITEM_INFO(_ID,_LABEL,_FLAGS) if (g.TestEngineHookItems) ImGuiTestEngineHook_ItemInfo(&g, _ID, _LABEL, _FLAGS) // Register item label and status flags (optional) -#define IMGUI_TEST_ENGINE_LOG(_FMT,...) if (g.TestEngineHookItems) ImGuiTestEngineHook_Log(&g, _FMT, __VA_ARGS__) // Custom log entry from user land into test log +// In IMGUI_VERSION_NUM >= 18934: changed IMGUI_TEST_ENGINE_ITEM_ADD(bb,id) to IMGUI_TEST_ENGINE_ITEM_ADD(id,bb,item_data); +#define IMGUI_TEST_ENGINE_ITEM_ADD(_ID,_BB,_ITEM_DATA) if (g.TestEngineHookItems) ImGuiTestEngineHook_ItemAdd(&g, _ID, _BB, _ITEM_DATA) // Register item bounding box +#define IMGUI_TEST_ENGINE_ITEM_INFO(_ID,_LABEL,_FLAGS) if (g.TestEngineHookItems) ImGuiTestEngineHook_ItemInfo(&g, _ID, _LABEL, _FLAGS) // Register item label and status flags (optional) +#define IMGUI_TEST_ENGINE_LOG(_FMT,...) if (g.TestEngineHookItems) ImGuiTestEngineHook_Log(&g, _FMT, __VA_ARGS__) // Custom log entry from user land into test log #else #define IMGUI_TEST_ENGINE_ITEM_ADD(_BB,_ID) ((void)0) #define IMGUI_TEST_ENGINE_ITEM_INFO(_ID,_LABEL,_FLAGS) ((void)g) diff --git a/extern/imgui_patched/imgui_tables.cpp b/extern/imgui_patched/imgui_tables.cpp index 46bf0b13..8850094d 100644 --- a/extern/imgui_patched/imgui_tables.cpp +++ b/extern/imgui_patched/imgui_tables.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.88 WIP +// dear imgui, v1.89.6 // (tables and columns code) /* @@ -80,20 +80,20 @@ Index of this file: // - outer_size.x <= 0.0f -> Right-align from window/work-rect right-most edge. With -FLT_MIN or 0.0f will align exactly on right-most edge. // - outer_size.x > 0.0f -> Set Fixed width. // Y with ScrollX/ScrollY disabled: we output table directly in current window -// - outer_size.y < 0.0f -> Bottom-align (but will auto extend, unless _NoHostExtendY is set). Not meaningful is parent window can vertically scroll. +// - outer_size.y < 0.0f -> Bottom-align (but will auto extend, unless _NoHostExtendY is set). Not meaningful if parent window can vertically scroll. // - outer_size.y = 0.0f -> No minimum height (but will auto extend, unless _NoHostExtendY is set) // - outer_size.y > 0.0f -> Set Minimum height (but will auto extend, unless _NoHostExtenY is set) // Y with ScrollX/ScrollY enabled: using a child window for scrolling -// - outer_size.y < 0.0f -> Bottom-align. Not meaningful is parent window can vertically scroll. +// - outer_size.y < 0.0f -> Bottom-align. Not meaningful if parent window can vertically scroll. // - outer_size.y = 0.0f -> Bottom-align, consistent with BeginChild(). Not recommended unless table is last item in parent window. // - outer_size.y > 0.0f -> Set Exact height. Recommended when using Scrolling on any axis. //----------------------------------------------------------------------------- // Outer size is also affected by the NoHostExtendX/NoHostExtendY flags. -// Important to that note how the two flags have slightly different behaviors! +// Important to note how the two flags have slightly different behaviors! // - ImGuiTableFlags_NoHostExtendX -> Make outer width auto-fit to columns (overriding outer_size.x value). Only available when ScrollX/ScrollY are disabled and Stretch columns are not used. // - ImGuiTableFlags_NoHostExtendY -> Make outer height stop exactly at outer_size.y (prevent auto-extending table past the limit). Only available when ScrollX/ScrollY is disabled. Data below the limit will be clipped and not visible. // In theory ImGuiTableFlags_NoHostExtendY could be the default and any non-scrolling tables with outer_size.y != 0.0f would use exact height. -// This would be consistent but perhaps less useful and more confusing (as vertically clipped items are not easily noticeable) +// This would be consistent but perhaps less useful and more confusing (as vertically clipped items are not useful and not easily noticeable). //----------------------------------------------------------------------------- // About 'inner_width': // With ScrollX disabled: @@ -112,15 +112,16 @@ Index of this file: //----------------------------------------------------------------------------- // COLUMNS SIZING POLICIES +// (Reference: ImGuiTableFlags_SizingXXX flags and ImGuiTableColumnFlags_WidthXXX flags) //----------------------------------------------------------------------------- // About overriding column sizing policy and width/weight with TableSetupColumn(): -// We use a default parameter of 'init_width_or_weight == -1'. +// We use a default parameter of -1 for 'init_width'/'init_weight'. // - with ImGuiTableColumnFlags_WidthFixed, init_width <= 0 (default) --> width is automatic // - with ImGuiTableColumnFlags_WidthFixed, init_width > 0 (explicit) --> width is custom // - with ImGuiTableColumnFlags_WidthStretch, init_weight <= 0 (default) --> weight is 1.0f // - with ImGuiTableColumnFlags_WidthStretch, init_weight > 0 (explicit) --> weight is custom // Widths are specified _without_ CellPadding. If you specify a width of 100.0f, the column will be cover (100.0f + Padding * 2.0f) -// and you can fit a 100.0f wide item in it without clipping and with full padding. +// and you can fit a 100.0f wide item in it without clipping and with padding honored. //----------------------------------------------------------------------------- // About default sizing policy (if you don't specify a ImGuiTableColumnFlags_WidthXXXX flag) // - with Table policy ImGuiTableFlags_SizingFixedFit --> default Column policy is ImGuiTableColumnFlags_WidthFixed, default Width is equal to contents width @@ -134,10 +135,10 @@ Index of this file: // - using mixed policies with ScrollX does not make much sense, as using Stretch columns with ScrollX does not make much sense in the first place! // that is, unless 'inner_width' is passed to BeginTable() to explicitly provide a total width to layout columns in. // - when using ImGuiTableFlags_SizingFixedSame with mixed columns, only the Fixed/Auto columns will match their widths to the width of the maximum contents. -// - when using ImGuiTableFlags_SizingStretchSame with mixed columns, only the Stretch columns will match their weight/widths. +// - when using ImGuiTableFlags_SizingStretchSame with mixed columns, only the Stretch columns will match their weights/widths. //----------------------------------------------------------------------------- // About using column width: -// If a column is manual resizable or has a width specified with TableSetupColumn(): +// If a column is manually resizable or has a width specified with TableSetupColumn(): // - you may use GetContentRegionAvail().x to query the width available in a given column. // - right-side alignment features such as SetNextItemWidth(-x) or PushItemWidth(-x) will rely on this width. // If the column is not resizable and has no width specified with TableSetupColumn(): @@ -151,7 +152,7 @@ Index of this file: // TABLES CLIPPING/CULLING //----------------------------------------------------------------------------- // About clipping/culling of Rows in Tables: -// - For large numbers of rows, it is recommended you use ImGuiListClipper to only submit visible rows. +// - For large numbers of rows, it is recommended you use ImGuiListClipper to submit only visible rows. // ImGuiListClipper is reliant on the fact that rows are of equal height. // See 'Demo->Tables->Vertical Scrolling' or 'Demo->Tables->Advanced' for a demo of using the clipper. // - Note that auto-resizing columns don't play well with using the clipper. @@ -168,7 +169,7 @@ Index of this file: // - Case C: column is hidden explicitly by the user (e.g. via the context menu, or _DefaultHide column flag, etc.). // // [A] [B] [C] -// TableNextColumn(): true false false -> [userland] when TableNextColumn() / TableSetColumnIndex() return false, user can skip submitting items but only if the column doesn't contribute to row height. +// TableNextColumn(): true false false -> [userland] when TableNextColumn() / TableSetColumnIndex() returns false, user can skip submitting items but only if the column doesn't contribute to row height. // SkipItems: false false true -> [internal] when SkipItems is true, most widgets will early out if submitted, resulting is no layout output. // ClipRect: normal zero-width zero-width -> [internal] when ClipRect is zero, ItemAdd() will return false and most widgets will early out mid-way. // ImDrawList output: normal dummy dummy -> [internal] when using the dummy channel, ImDrawList submissions (if any) will be wasted (because cliprect is zero-width anyway). @@ -188,12 +189,12 @@ Index of this file: #define _CRT_SECURE_NO_WARNINGS #endif -#include "imgui.h" -#ifndef IMGUI_DISABLE - #ifndef IMGUI_DEFINE_MATH_OPERATORS #define IMGUI_DEFINE_MATH_OPERATORS #endif + +#include "imgui.h" +#ifndef IMGUI_DISABLE #include "imgui_internal.h" // System includes @@ -315,11 +316,11 @@ bool ImGui::BeginTableEx(const char* name, ImGuiID id, int columns_count, ImG return false; // Sanity checks - IM_ASSERT(columns_count > 0 && "Only 1..64 columns allowed!"); + IM_ASSERT(columns_count > 0 && columns_count < IMGUI_TABLE_MAX_COLUMNS); if (flags & ImGuiTableFlags_ScrollX) IM_ASSERT(inner_width >= 0.0f); - // If an outer size is specified ahead we will be able to early out when not visible. Exact clipping rules may evolve. + // If an outer size is specified ahead we will be able to early out when not visible. Exact clipping criteria may evolve. const bool use_child_window = (flags & (ImGuiTableFlags_ScrollX | ImGuiTableFlags_ScrollY)) != 0; const ImVec2 avail_size = GetContentRegionAvail(); ImVec2 actual_outer_size = CalcItemSize(outer_size, ImMax(avail_size.x, 1.0f), use_child_window ? ImMax(avail_size.y, 1.0f) : 0.0f); @@ -332,11 +333,7 @@ bool ImGui::BeginTableEx(const char* name, ImGuiID id, int columns_count, ImG // Acquire storage for the table ImGuiTable* table = g.Tables.GetOrAddByKey(id); - const int instance_no = (table->LastFrameActive != g.FrameCount) ? 0 : table->InstanceCurrent + 1; - const ImGuiID instance_id = id + instance_no; const ImGuiTableFlags table_last_flags = table->Flags; - if (instance_no > 0) - IM_ASSERT(table->ColumnsCount == columns_count && "BeginTable(): Cannot change columns count mid-frame while preserving same ID"); // Acquire temporary buffers const int table_idx = g.Tables.GetIndex(table); @@ -352,27 +349,32 @@ bool ImGui::BeginTableEx(const char* name, ImGuiID id, int columns_count, ImG flags = TableFixFlags(flags, outer_window); // Initialize + const int instance_no = (table->LastFrameActive != g.FrameCount) ? 0 : table->InstanceCurrent + 1; table->ID = id; table->Flags = flags; - table->InstanceCurrent = (ImS16)instance_no; table->LastFrameActive = g.FrameCount; table->OuterWindow = table->InnerWindow = outer_window; table->ColumnsCount = columns_count; - if (table->EnabledMaskByDisplayOrder.BitCount < columns_count || - table->EnabledMaskByIndex.BitCount < columns_count || - table->VisibleMaskByIndex.BitCount < columns_count || - table->RequestOutputMaskByIndex.BitCount < columns_count) - { - table->EnabledMaskByDisplayOrder.Create(columns_count); - table->EnabledMaskByIndex.Create(columns_count); - table->VisibleMaskByIndex.Create(columns_count); - table->RequestOutputMaskByIndex.Create(columns_count); - } table->IsLayoutLocked = false; table->InnerWidth = inner_width; temp_data->UserOuterSize = outer_size; - if (instance_no > 0 && table->InstanceDataExtra.Size < instance_no) - table->InstanceDataExtra.push_back(ImGuiTableInstanceData()); + + // Instance data (for instance 0, TableID == TableInstanceID) + ImGuiID instance_id; + table->InstanceCurrent = (ImS16)instance_no; + if (instance_no > 0) + { + IM_ASSERT(table->ColumnsCount == columns_count && "BeginTable(): Cannot change columns count mid-frame while preserving same ID"); + if (table->InstanceDataExtra.Size < instance_no) + table->InstanceDataExtra.push_back(ImGuiTableInstanceData()); + instance_id = GetIDWithSeed(instance_no, GetIDWithSeed("##Instances", NULL, id)); // Push "##Instances" followed by (int)instance_no in ID stack. + } + else + { + instance_id = id; + } + ImGuiTableInstanceData* table_instance = TableGetInstanceData(table, table->InstanceCurrent); + table_instance->TableInstanceID = instance_id; // When not using a child window, WorkRect.Max will grow as we append contents. if (use_child_window) @@ -405,6 +407,14 @@ bool ImGui::BeginTableEx(const char* name, ImGuiID id, int columns_count, ImG table->OuterRect = table->InnerWindow->Rect(); table->InnerRect = table->InnerWindow->InnerRect; IM_ASSERT(table->InnerWindow->WindowPadding.x == 0.0f && table->InnerWindow->WindowPadding.y == 0.0f && table->InnerWindow->WindowBorderSize == 0.0f); + + // When using multiple instances, ensure they have the same amount of horizontal decorations (aka vertical scrollbar) so stretched columns can be aligned) + if (instance_no == 0) + { + table->HasScrollbarYPrev = table->HasScrollbarYCurr; + table->HasScrollbarYCurr = false; + } + table->HasScrollbarYCurr |= (table->InnerWindow->ScrollMax.y > 0.0f); } else { @@ -414,7 +424,9 @@ bool ImGui::BeginTableEx(const char* name, ImGuiID id, int columns_count, ImG } // Push a standardized ID for both child-using and not-child-using tables - PushOverrideID(instance_id); + PushOverrideID(id); + if (instance_no > 0) + PushOverrideID(instance_id); // FIXME: Somehow this is not resolved by stack-tool, even tho GetIDWithSeed() submitted the symbol. // Backup a copy of host window members we will modify ImGuiWindow* inner_window = table->InnerWindow; @@ -466,12 +478,13 @@ bool ImGui::BeginTableEx(const char* name, ImGuiID id, int columns_count, ImG table->IsUnfrozenRows = true; table->DeclColumnsCount = 0; - // Using opaque colors facilitate overlapping elements of the grid + // Using opaque colors facilitate overlapping lines of the grid, otherwise we'd need to improve TableDrawBorders() table->BorderColorStrong = GetColorU32(ImGuiCol_TableBorderStrong); table->BorderColorLight = GetColorU32(ImGuiCol_TableBorderLight); // Make table current g.CurrentTable = table; + outer_window->DC.NavIsScrollPushableX = false; // Shortcut for NavUpdateCurrentWindowIsScrollPushableX(); outer_window->DC.CurrentTableIdx = table_idx; if (inner_window != outer_window) // So EndChild() within the inner window can restore the table properly. inner_window->DC.CurrentTableIdx = table_idx; @@ -479,7 +492,7 @@ bool ImGui::BeginTableEx(const char* name, ImGuiID id, int columns_count, ImG if ((table_last_flags & ImGuiTableFlags_Reorderable) && (flags & ImGuiTableFlags_Reorderable) == 0) table->IsResetDisplayOrderRequest = true; - // Mark as used + // Mark as used to avoid GC if (table_idx >= g.TablesLastTimeActive.Size) g.TablesLastTimeActive.resize(table_idx + 1, -1.0f); g.TablesLastTimeActive[table_idx] = (float)g.Time; @@ -549,7 +562,7 @@ bool ImGui::BeginTableEx(const char* name, ImGuiID id, int columns_count, ImG if (table->RefScale != 0.0f && table->RefScale != new_ref_scale_unit) { const float scale_factor = new_ref_scale_unit / table->RefScale; - //IMGUI_DEBUG_LOG("[table] %08X RefScaleUnit %.3f -> %.3f, scaling width by %.3f\n", table->ID, table->RefScaleUnit, new_ref_scale_unit, scale_factor); + //IMGUI_DEBUG_PRINT("[table] %08X RefScaleUnit %.3f -> %.3f, scaling width by %.3f\n", table->ID, table->RefScaleUnit, new_ref_scale_unit, scale_factor); for (int n = 0; n < columns_count; n++) table->Columns[n].WidthRequest = table->Columns[n].WidthRequest * scale_factor; } @@ -572,34 +585,40 @@ bool ImGui::BeginTableEx(const char* name, ImGuiID id, int columns_count, ImG } // For reference, the average total _allocation count_ for a table is: -// + 0 (for ImGuiTable instance, we are pooling allocations in g.Tables) +// + 0 (for ImGuiTable instance, we are pooling allocations in g.Tables[]) // + 1 (for table->RawData allocated below) // + 1 (for table->ColumnsNames, if names are used) -// Shared allocations per number of nested tables +// Shared allocations for the maximum number of simultaneously nested tables (generally a very small number) // + 1 (for table->Splitter._Channels) // + 2 * active_channels_count (for ImDrawCmd and ImDrawIdx buffers inside channels) -// Where active_channels_count is variable but often == columns_count or columns_count + 1, see TableSetupDrawChannels() for details. +// Where active_channels_count is variable but often == columns_count or == columns_count + 1, see TableSetupDrawChannels() for details. // Unused channels don't perform their +2 allocations. void ImGui::TableBeginInitMemory(ImGuiTable* table, int columns_count) { // Allocate single buffer for our arrays - ImSpanAllocator<3> span_allocator; + const int columns_bit_array_size = (int)ImBitArrayGetStorageSizeInBytes(columns_count); + ImSpanAllocator<6> span_allocator; span_allocator.Reserve(0, columns_count * sizeof(ImGuiTableColumn)); span_allocator.Reserve(1, columns_count * sizeof(ImGuiTableColumnIdx)); span_allocator.Reserve(2, columns_count * sizeof(ImGuiTableCellData), 4); + for (int n = 3; n < 6; n++) + span_allocator.Reserve(n, columns_bit_array_size); table->RawData = IM_ALLOC(span_allocator.GetArenaSizeInBytes()); memset(table->RawData, 0, span_allocator.GetArenaSizeInBytes()); span_allocator.SetArenaBasePtr(table->RawData); span_allocator.GetSpan(0, &table->Columns); span_allocator.GetSpan(1, &table->DisplayOrderToIndex); span_allocator.GetSpan(2, &table->RowCellData); + table->EnabledMaskByDisplayOrder = (ImU32*)span_allocator.GetSpanPtrBegin(3); + table->EnabledMaskByIndex = (ImU32*)span_allocator.GetSpanPtrBegin(4); + table->VisibleMaskByIndex = (ImU32*)span_allocator.GetSpanPtrBegin(5); } // Apply queued resizing/reordering/hiding requests void ImGui::TableBeginApplyRequests(ImGuiTable* table) { // Handle resizing request - // (We process this at the first TableBegin of the frame) + // (We process this in the TableBegin() of the first instance of each table) // FIXME-TABLE: Contains columns if our work area doesn't allow for scrolling? if (table->InstanceCurrent == 0) { @@ -644,8 +663,7 @@ void ImGui::TableBeginApplyRequests(ImGuiTable* table) table->Columns[table->DisplayOrderToIndex[order_n]].DisplayOrder -= (ImGuiTableColumnIdx)reorder_dir; IM_ASSERT(dst_column->DisplayOrder == dst_order - reorder_dir); - // Display order is stored in both columns->IndexDisplayOrder and table->DisplayOrder[], - // rebuild the later from the former. + // Display order is stored in both columns->IndexDisplayOrder and table->DisplayOrder[]. Rebuild later from the former. for (int column_n = 0; column_n < table->ColumnsCount; column_n++) table->DisplayOrderToIndex[table->Columns[column_n].DisplayOrder] = (ImGuiTableColumnIdx)column_n; table->ReorderColumnDir = 0; @@ -719,8 +737,8 @@ static void TableSetupColumnFlags(ImGuiTable* table, ImGuiTableColumn* column, I } } -// Layout columns for the frame. This is in essence the followup to BeginTable(). -// Runs on the first call to TableNextRow(), to give a chance for TableSetupColumn() to be called first. +// Layout columns for the frame. This is in essence the followup to BeginTable() and this is our largest function. +// Runs on the first call to TableNextRow(), to give a chance for TableSetupColumn() and other TableSetupXXXXX() functions to be called first. // FIXME-TABLE: Our width (and therefore our WorkRect) will be minimal in the first frame for _WidthAuto columns. // Increase feedback side-effect with widgets relying on WorkRect.Max.x... Maybe provide a default distribution for _WidthAuto columns? void ImGui::TableUpdateLayout(ImGuiTable* table) @@ -731,8 +749,8 @@ void ImGui::TableUpdateLayout(ImGuiTable* table) const ImGuiTableFlags table_sizing_policy = (table->Flags & ImGuiTableFlags_SizingMask_); table->IsDefaultDisplayOrder = true; table->ColumnsEnabledCount = 0; - table->EnabledMaskByIndex.ClearAllBits(); - table->EnabledMaskByDisplayOrder.ClearAllBits(); + ImBitArrayClearAllBits(table->EnabledMaskByIndex, table->ColumnsCount); + ImBitArrayClearAllBits(table->EnabledMaskByDisplayOrder, table->ColumnsCount); table->LeftMostEnabledColumn = -1; table->MinColumnWidth = ImMax(1.0f, g.Style.FramePadding.x * 1.0f); // g.Style.ColumnsMinSpacing; // FIXME-TABLE @@ -797,8 +815,8 @@ void ImGui::TableUpdateLayout(ImGuiTable* table) else table->LeftMostEnabledColumn = (ImGuiTableColumnIdx)column_n; column->IndexWithinEnabledSet = table->ColumnsEnabledCount++; - table->EnabledMaskByIndex.SetBit(column_n); - table->EnabledMaskByDisplayOrder.SetBit(column->DisplayOrder); + ImBitArraySetBit(table->EnabledMaskByIndex, column_n); + ImBitArraySetBit(table->EnabledMaskByDisplayOrder, column->DisplayOrder); prev_visible_column_idx = column_n; IM_ASSERT(column->IndexWithinEnabledSet <= column->DisplayOrder); @@ -841,12 +859,12 @@ void ImGui::TableUpdateLayout(ImGuiTable* table) table->IsSettingsDirty = true; // [Part 3] Fix column flags and record a few extra information. - float sum_width_requests = 0.0f; // Sum of all width for fixed and auto-resize columns, excluding width contributed by Stretch columns but including spacing/padding. - float stretch_sum_weights = 0.0f; // Sum of all weights for stretch columns. + float sum_width_requests = 0.0f; // Sum of all width for fixed and auto-resize columns, excluding width contributed by Stretch columns but including spacing/padding. + float stretch_sum_weights = 0.0f; // Sum of all weights for stretch columns. table->LeftMostStretchedColumn = table->RightMostStretchedColumn = -1; for (int column_n = 0; column_n < table->ColumnsCount; column_n++) { - if (!table->EnabledMaskByIndex.TestBit(column_n)) + if (!IM_BITARRAY_TESTBIT(table->EnabledMaskByIndex, column_n)) continue; ImGuiTableColumn* column = &table->Columns[column_n]; @@ -862,7 +880,7 @@ void ImGui::TableUpdateLayout(ImGuiTable* table) // Latch initial size for fixed columns and update it constantly for auto-resizing column (unless clipped!) if (column->AutoFitQueue != 0x00) column->WidthRequest = width_auto; - else if ((column->Flags & ImGuiTableColumnFlags_WidthFixed) && !column_is_resizable && (table->RequestOutputMaskByIndex.TestBit(column_n))) + else if ((column->Flags & ImGuiTableColumnFlags_WidthFixed) && !column_is_resizable && column->IsRequestOutput) column->WidthRequest = width_auto; // FIXME-TABLE: Increase minimum size during init frame to avoid biasing auto-fitting widgets @@ -903,13 +921,14 @@ void ImGui::TableUpdateLayout(ImGuiTable* table) // [Part 4] Apply final widths based on requested widths const ImRect work_rect = table->WorkRect; const float width_spacings = (table->OuterPaddingX * 2.0f) + (table->CellSpacingX1 + table->CellSpacingX2) * (table->ColumnsEnabledCount - 1); - const float width_avail = ((table->Flags & ImGuiTableFlags_ScrollX) && table->InnerWidth == 0.0f) ? table->InnerClipRect.GetWidth() : work_rect.GetWidth(); + const float width_removed = (table->HasScrollbarYPrev && !table->InnerWindow->ScrollbarY) ? g.Style.ScrollbarSize : 0.0f; // To synchronize decoration width of synched tables with mismatching scrollbar state (#5920) + const float width_avail = ImMax(1.0f, (((table->Flags & ImGuiTableFlags_ScrollX) && table->InnerWidth == 0.0f) ? table->InnerClipRect.GetWidth() : work_rect.GetWidth()) - width_removed); const float width_avail_for_stretched_columns = width_avail - width_spacings - sum_width_requests; float width_remaining_for_stretched_columns = width_avail_for_stretched_columns; table->ColumnsGivenWidth = width_spacings + (table->CellPaddingX * 2.0f) * table->ColumnsEnabledCount; for (int column_n = 0; column_n < table->ColumnsCount; column_n++) { - if (!table->EnabledMaskByIndex.TestBit(column_n)) + if (!IM_BITARRAY_TESTBIT(table->EnabledMaskByIndex, column_n)) continue; ImGuiTableColumn* column = &table->Columns[column_n]; @@ -936,7 +955,7 @@ void ImGui::TableUpdateLayout(ImGuiTable* table) if (width_remaining_for_stretched_columns >= 1.0f && !(table->Flags & ImGuiTableFlags_PreciseWidths)) for (int order_n = table->ColumnsCount - 1; stretch_sum_weights > 0.0f && width_remaining_for_stretched_columns >= 1.0f && order_n >= 0; order_n--) { - if (!table->EnabledMaskByDisplayOrder.TestBit(order_n)) + if (!IM_BITARRAY_TESTBIT(table->EnabledMaskByDisplayOrder, order_n)) continue; ImGuiTableColumn* column = &table->Columns[table->DisplayOrderToIndex[order_n]]; if (!(column->Flags & ImGuiTableColumnFlags_WidthStretch)) @@ -946,11 +965,19 @@ void ImGui::TableUpdateLayout(ImGuiTable* table) width_remaining_for_stretched_columns -= 1.0f; } + // Determine if table is hovered which will be used to flag columns as hovered. + // - In principle we'd like to use the equivalent of IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem), + // but because our item is partially submitted at this point we use ItemHoverable() and a workaround (temporarily + // clear ActiveId, which is equivalent to the change provided by _AllowWhenBLockedByActiveItem). + // - This allows columns to be marked as hovered when e.g. clicking a button inside the column, or using drag and drop. ImGuiTableInstanceData* table_instance = TableGetInstanceData(table, table->InstanceCurrent); table->HoveredColumnBody = -1; table->HoveredColumnBorder = -1; const ImRect mouse_hit_rect(table->OuterRect.Min.x, table->OuterRect.Min.y, table->OuterRect.Max.x, ImMax(table->OuterRect.Max.y, table->OuterRect.Min.y + table_instance->LastOuterHeight)); + const ImGuiID backup_active_id = g.ActiveId; + g.ActiveId = 0; const bool is_hovering_table = ItemHoverable(mouse_hit_rect, 0); + g.ActiveId = backup_active_id; // [Part 6] Setup final position, offset, skip/clip states and clipping rectangles, detect hovered column // Process columns in their visible orders as we are comparing the visible order and adjusting host_clip_rect while looping. @@ -959,14 +986,13 @@ void ImGui::TableUpdateLayout(ImGuiTable* table) float offset_x = ((table->FreezeColumnsCount > 0) ? table->OuterRect.Min.x : work_rect.Min.x) + table->OuterPaddingX - table->CellSpacingX1; ImRect host_clip_rect = table->InnerClipRect; //host_clip_rect.Max.x += table->CellPaddingX + table->CellSpacingX2; - table->VisibleMaskByIndex.ClearAllBits(); - table->RequestOutputMaskByIndex.ClearAllBits(); + ImBitArrayClearAllBits(table->VisibleMaskByIndex, table->ColumnsCount); for (int order_n = 0; order_n < table->ColumnsCount; order_n++) { const int column_n = table->DisplayOrderToIndex[order_n]; ImGuiTableColumn* column = &table->Columns[column_n]; - column->NavLayerCurrent = (ImS8)((table->FreezeRowsCount > 0 || column_n < table->FreezeColumnsCount) ? ImGuiNavLayer_Menu : ImGuiNavLayer_Main); + column->NavLayerCurrent = (ImS8)(table->FreezeRowsCount > 0 ? ImGuiNavLayer_Menu : ImGuiNavLayer_Main); // Use Count NOT request so Header line changes layer when frozen if (offset_x_frozen && table->FreezeColumnsCount == visible_n) { @@ -977,7 +1003,7 @@ void ImGui::TableUpdateLayout(ImGuiTable* table) // Clear status flags column->Flags &= ~ImGuiTableColumnFlags_StatusMask_; - if (!table->EnabledMaskByDisplayOrder.TestBit(order_n)) + if (!IM_BITARRAY_TESTBIT(table->EnabledMaskByDisplayOrder, order_n)) { // Hidden column: clear a few fields and we are done with it for the remainder of the function. // We set a zero-width clip rect but set Min.y/Max.y properly to not interfere with the clipper. @@ -1030,12 +1056,10 @@ void ImGui::TableUpdateLayout(ImGuiTable* table) column->IsVisibleY = true; // (column->ClipRect.Max.y > column->ClipRect.Min.y); const bool is_visible = column->IsVisibleX; //&& column->IsVisibleY; if (is_visible) - table->VisibleMaskByIndex.SetBit(column_n); + ImBitArraySetBit(table->VisibleMaskByIndex, column_n); // Mark column as requesting output from user. Note that fixed + non-resizable sets are auto-fitting at all times and therefore always request output. column->IsRequestOutput = is_visible || column->AutoFitQueue != 0 || column->CannotSkipItemsQueue != 0; - if (column->IsRequestOutput) - table->RequestOutputMaskByIndex.SetBit(column_n); // Mark column as SkipItems (ignoring all items/layout) column->IsSkipItems = !column->IsEnabled || table->HostSkipItems; @@ -1115,25 +1139,24 @@ void ImGui::TableUpdateLayout(ImGuiTable* table) table->IsUsingHeaders = false; // [Part 11] Context menu - if (table->IsContextPopupOpen && table->InstanceCurrent == table->InstanceInteracted) + if (TableBeginContextMenuPopup(table)) { - const ImGuiID context_menu_id = ImHashStr("##ContextMenu", 0, table->ID); - if (BeginPopupEx(context_menu_id, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoSavedSettings)) - { - TableDrawContextMenu(table); - EndPopup(); - } - else - { - table->IsContextPopupOpen = false; - } + TableDrawContextMenu(table); + EndPopup(); } - // [Part 13] Sanitize and build sort specs before we have a change to use them for display. + // [Part 12] Sanitize and build sort specs before we have a chance to use them for display. // This path will only be exercised when sort specs are modified before header rows (e.g. init or visibility change) if (table->IsSortSpecsDirty && (table->Flags & ImGuiTableFlags_Sortable)) TableSortSpecsBuild(table); + // [Part 13] Setup inner window decoration size (for scrolling / nav tracking to properly take account of frozen rows/columns) + if (table->FreezeColumnsRequest > 0) + table->InnerWindow->DecoInnerSizeX1 = table->Columns[table->DisplayOrderToIndex[table->FreezeColumnsRequest - 1]].MaxX - table->OuterRect.Min.x; + if (table->FreezeRowsRequest > 0) + table->InnerWindow->DecoInnerSizeY1 = table_instance->LastFrozenHeight; + table_instance->LastFrozenHeight = 0.0f; + // Initial state ImGuiWindow* inner_window = table->InnerWindow; if (table->Flags & ImGuiTableFlags_NoClip) @@ -1143,9 +1166,9 @@ void ImGui::TableUpdateLayout(ImGuiTable* table) } // Process hit-testing on resizing borders. Actual size change will be applied in EndTable() -// - Set table->HoveredColumnBorder with a short delay/timer to reduce feedback noise -// - Submit ahead of table contents and header, use ImGuiButtonFlags_AllowItemOverlap to prioritize widgets -// overlapping the same area. +// - Set table->HoveredColumnBorder with a short delay/timer to reduce visual feedback noise. +// - Submit ahead of table contents and header, use ImGuiButtonFlags_AllowItemOverlap to prioritize +// widgets overlapping the same area. void ImGui::TableUpdateBorders(ImGuiTable* table) { ImGuiContext& g = *GImGui; @@ -1163,7 +1186,7 @@ void ImGui::TableUpdateBorders(ImGuiTable* table) for (int order_n = 0; order_n < table->ColumnsCount; order_n++) { - if (!table->EnabledMaskByDisplayOrder.TestBit(order_n)) + if (!IM_BITARRAY_TESTBIT(table->EnabledMaskByDisplayOrder, order_n)) continue; const int column_n = table->DisplayOrderToIndex[order_n]; @@ -1181,8 +1204,8 @@ void ImGui::TableUpdateBorders(ImGuiTable* table) ImGuiID column_id = TableGetColumnResizeID(table, column_n, table->InstanceCurrent); ImRect hit_rect(column->MaxX - hit_half_width, hit_y1, column->MaxX + hit_half_width, border_y2_hit); + ItemAdd(hit_rect, column_id, NULL, ImGuiItemFlags_NoNav); //GetForegroundDrawList()->AddRect(hit_rect.Min, hit_rect.Max, IM_COL32(255, 0, 0, 100)); - KeepAliveID(column_id); bool hovered = false, held = false; bool pressed = ButtonBehavior(hit_rect, column_id, &hovered, &held, ImGuiButtonFlags_FlattenChildren | ImGuiButtonFlags_AllowItemOverlap | ImGuiButtonFlags_PressedOnClick | ImGuiButtonFlags_PressedOnDoubleClick | ImGuiButtonFlags_NoNavFocus); @@ -1299,7 +1322,7 @@ void ImGui::EndTable() float auto_fit_width_for_stretched = 0.0f; float auto_fit_width_for_stretched_min = 0.0f; for (int column_n = 0; column_n < table->ColumnsCount; column_n++) - if (table->EnabledMaskByIndex.TestBit(column_n)) + if (IM_BITARRAY_TESTBIT(table->EnabledMaskByIndex, column_n)) { ImGuiTableColumn* column = &table->Columns[column_n]; float column_width_request = ((column->Flags & ImGuiTableColumnFlags_WidthFixed) && !(column->Flags & ImGuiTableColumnFlags_NoResize)) ? column->WidthRequest : TableGetColumnWidthAuto(table, column); @@ -1339,8 +1362,10 @@ void ImGui::EndTable() } // Pop from id stack - IM_ASSERT_USER_ERROR(inner_window->IDStack.back() == table->ID + table->InstanceCurrent, "Mismatching PushID/PopID!"); + IM_ASSERT_USER_ERROR(inner_window->IDStack.back() == table_instance->TableInstanceID, "Mismatching PushID/PopID!"); IM_ASSERT_USER_ERROR(outer_window->DC.ItemWidthStack.Size >= temp_data->HostBackupItemWidthStackSize, "Too many PopItemWidth!"); + if (table->InstanceCurrent > 0) + PopID(); PopID(); // Restore window data that we modified @@ -1412,6 +1437,7 @@ void ImGui::EndTable() g.CurrentTable->DrawSplitter = &temp_data->DrawSplitter; } outer_window->DC.CurrentTableIdx = g.CurrentTable ? g.Tables.GetIndex(g.CurrentTable) : -1; + NavUpdateCurrentWindowIsScrollPushableX(); } // See "COLUMN SIZING POLICIES" comments at the top of this file @@ -1490,7 +1516,7 @@ void ImGui::TableSetupScrollFreeze(int columns, int rows) ImGuiTable* table = g.CurrentTable; IM_ASSERT(table != NULL && "Need to call TableSetupColumn() after BeginTable()!"); IM_ASSERT(table->IsLayoutLocked == false && "Need to call TableSetupColumn() before first row!"); - IM_ASSERT(columns >= 0); + IM_ASSERT(columns >= 0 && columns < IMGUI_TABLE_MAX_COLUMNS); IM_ASSERT(rows >= 0 && rows < 128); // Arbitrary limit table->FreezeColumnsRequest = (table->Flags & ImGuiTableFlags_ScrollX) ? (ImGuiTableColumnIdx)ImMin(columns, table->ColumnsCount) : 0; @@ -1610,14 +1636,14 @@ ImRect ImGui::TableGetCellBgRect(const ImGuiTable* table, int column_n) } // Return the resizing ID for the right-side of the given column. -ImGuiID ImGui::TableGetColumnResizeID(const ImGuiTable* table, int column_n, int instance_no) +ImGuiID ImGui::TableGetColumnResizeID(ImGuiTable* table, int column_n, int instance_no) { IM_ASSERT(column_n >= 0 && column_n < table->ColumnsCount); - ImGuiID id = table->ID + 1 + (instance_no * table->ColumnsCount) + column_n; - return id; + ImGuiID instance_id = TableGetInstanceID(table, instance_no); + return instance_id + 1 + column_n; // FIXME: #6140: still not ideal } -// Return -1 when table is not hovered. return columns_count if the unused space at the right of visible columns is hovered. +// Return -1 when table is not hovered. return columns_count if hovering the unused space at the right of the right-most visible column. int ImGui::TableGetHoveredColumn() { ImGuiContext& g = *GImGui; @@ -1645,7 +1671,7 @@ void ImGui::TableSetBgColor(ImGuiTableBgTarget target, ImU32 color, int column_n return; if (column_n == -1) column_n = table->CurrentColumn; - if (!table->VisibleMaskByIndex.TestBit(column_n)) + if (!IM_BITARRAY_TESTBIT(table->VisibleMaskByIndex, column_n)) return; if (table->RowCellDataCurrent < 0 || table->RowCellData[table->RowCellDataCurrent].Column != column_n) table->RowCellDataCurrent++; @@ -1735,6 +1761,8 @@ void ImGui::TableBeginRow(ImGuiTable* table) table->RowTextBaseline = 0.0f; table->RowIndentOffsetX = window->DC.Indent.x - table->HostIndentX; // Lock indent window->DC.PrevLineTextBaseOffset = 0.0f; + window->DC.CurrLineSize = ImVec2(0.0f, 0.0f); + window->DC.IsSameLine = window->DC.IsSetPos = false; window->DC.CursorMaxPos.y = next_y1; // Making the header BG color non-transparent will allow us to overlay it multiple times when handling smooth dragging. @@ -1847,17 +1875,15 @@ void ImGui::TableEndRow(ImGuiTable* table) // get the new cursor position. if (unfreeze_rows_request) for (int column_n = 0; column_n < table->ColumnsCount; column_n++) - { - ImGuiTableColumn* column = &table->Columns[column_n]; - column->NavLayerCurrent = (ImS8)((column_n < table->FreezeColumnsCount) ? ImGuiNavLayer_Menu : ImGuiNavLayer_Main); - } + table->Columns[column_n].NavLayerCurrent = ImGuiNavLayer_Main; if (unfreeze_rows_actual) { IM_ASSERT(table->IsUnfrozenRows == false); + const float y0 = ImMax(table->RowPosY2 + 1, window->InnerClipRect.Min.y); table->IsUnfrozenRows = true; + TableGetInstanceData(table, table->InstanceCurrent)->LastFrozenHeight = y0 - table->OuterRect.Min.y; // BgClipRect starts as table->InnerClipRect, reduce it now and make BgClipRectForDrawCmd == BgClipRect - float y0 = ImMax(table->RowPosY2 + 1, window->InnerClipRect.Min.y); table->BgClipRect.Min.y = table->Bg2ClipRectForDrawCmd.Min.y = ImMin(y0, window->InnerClipRect.Max.y); table->BgClipRect.Max.y = table->Bg2ClipRectForDrawCmd.Max.y = window->InnerClipRect.Max.y; table->Bg2DrawChannelCurrent = table->Bg2DrawChannelUnfrozen; @@ -1920,7 +1946,7 @@ bool ImGui::TableSetColumnIndex(int column_n) // Return whether the column is visible. User may choose to skip submitting items based on this return value, // however they shouldn't skip submitting for columns that may have the tallest contribution to row height. - return table->RequestOutputMaskByIndex.TestBit(column_n); + return table->Columns[column_n].IsRequestOutput; } // [Public] Append into the next column, wrap and create a new row when already on last column @@ -1945,8 +1971,7 @@ bool ImGui::TableNextColumn() // Return whether the column is visible. User may choose to skip submitting items based on this return value, // however they shouldn't skip submitting for columns that may have the tallest contribution to row height. - int column_n = table->CurrentColumn; - return table->RequestOutputMaskByIndex.TestBit(column_n); + return table->Columns[table->CurrentColumn].IsRequestOutput; } @@ -1955,6 +1980,7 @@ bool ImGui::TableNextColumn() // FIXME-TABLE FIXME-OPT: Could probably shortcut some things for non-active or clipped columns. void ImGui::TableBeginCell(ImGuiTable* table, int column_n) { + ImGuiContext& g = *GImGui; ImGuiTableColumn* column = &table->Columns[column_n]; ImGuiWindow* window = table->InnerWindow; table->CurrentColumn = column_n; @@ -1976,14 +2002,9 @@ void ImGui::TableBeginCell(ImGuiTable* table, int column_n) window->WorkRect.Max.x = column->WorkMaxX; window->DC.ItemWidth = column->ItemWidth; - // To allow ImGuiListClipper to function we propagate our row height - if (!column->IsEnabled) - window->DC.CursorPos.y = ImMax(window->DC.CursorPos.y, table->RowPosY2); - window->SkipItems = column->IsSkipItems; if (column->IsSkipItems) { - ImGuiContext& g = *GImGui; g.LastItemData.ID = 0; g.LastItemData.StatusFlags = 0; } @@ -2002,7 +2023,6 @@ void ImGui::TableBeginCell(ImGuiTable* table, int column_n) } // Logging - ImGuiContext& g = *GImGui; if (g.LogEnabled && !column->IsSkipItems) { LogRenderedText(&window->DC.CursorPos, "|"); @@ -2016,6 +2036,9 @@ void ImGui::TableEndCell(ImGuiTable* table) ImGuiTableColumn* column = &table->Columns[table->CurrentColumn]; ImGuiWindow* window = table->InnerWindow; + if (window->DC.IsSetPos) + ErrorCheckUsingSetCursorPosToExtendParentBoundaries(); + // Report maximum position so we can infer content size per column. float* p_max_pos_x; if (table->RowFlags & ImGuiTableRowFlags_Headers) @@ -2023,7 +2046,8 @@ void ImGui::TableEndCell(ImGuiTable* table) else p_max_pos_x = table->IsUnfrozenRows ? &column->ContentMaxXUnfrozen : &column->ContentMaxXFrozen; *p_max_pos_x = ImMax(*p_max_pos_x, window->DC.CursorMaxPos.x); - table->RowPosY2 = ImMax(table->RowPosY2, window->DC.CursorMaxPos.y + table->CellPaddingY); + if (column->IsEnabled) + table->RowPosY2 = ImMax(table->RowPosY2, window->DC.CursorMaxPos.y + table->CellPaddingY); column->ItemWidth = window->DC.ItemWidth; // Propagate text baseline for the entire row @@ -2110,7 +2134,7 @@ void ImGui::TableSetColumnWidth(int column_n, float width) if (column_0->WidthGiven == column_0_width || column_0->WidthRequest == column_0_width) return; - //IMGUI_DEBUG_LOG("TableSetColumnWidth(%d, %.1f->%.1f)\n", column_0_idx, column_0->WidthGiven, column_0_width); + //IMGUI_DEBUG_PRINT("TableSetColumnWidth(%d, %.1f->%.1f)\n", column_0_idx, column_0->WidthGiven, column_0_width); ImGuiTableColumn* column_1 = (column_0->NextEnabledColumn != -1) ? &table->Columns[column_0->NextEnabledColumn] : NULL; // In this surprisingly not simple because of how we support mixing Fixed and multiple Stretch columns. @@ -2118,7 +2142,7 @@ void ImGui::TableSetColumnWidth(int column_n, float width) // - All stretch: easy. // - One or more fixed + one stretch: easy. // - One or more fixed + more than one stretch: tricky. - // Qt when manual resize is enabled only support a single _trailing_ stretch column. + // Qt when manual resize is enabled only supports a single _trailing_ stretch column, we support more cases here. // When forwarding resize from Wn| to Fn+1| we need to be considerate of the _NoResize flag on Fn+1. // FIXME-TABLE: Find a way to rewrite all of this so interactions feel more consistent for the user. @@ -2201,7 +2225,7 @@ void ImGui::TableUpdateColumnsWeightFromWidth(ImGuiTable* table) { IM_ASSERT(table->LeftMostStretchedColumn != -1 && table->RightMostStretchedColumn != -1); - // Measure existing quantity + // Measure existing quantities float visible_weight = 0.0f; float visible_width = 0.0f; for (int column_n = 0; column_n < table->ColumnsCount; column_n++) @@ -2283,7 +2307,7 @@ void ImGui::TableSetupDrawChannels(ImGuiTable* table) const int freeze_row_multiplier = (table->FreezeRowsCount > 0) ? 2 : 1; const int channels_for_row = (table->Flags & ImGuiTableFlags_NoClip) ? 1 : table->ColumnsEnabledCount; const int channels_for_bg = 1 + 1 * freeze_row_multiplier; - const int channels_for_dummy = (table->ColumnsEnabledCount < table->ColumnsCount || table->VisibleMaskByIndex != table->EnabledMaskByIndex) ? +1 : 0; + const int channels_for_dummy = (table->ColumnsEnabledCount < table->ColumnsCount || (memcmp(table->VisibleMaskByIndex, table->EnabledMaskByIndex, ImBitArrayGetStorageSizeInBytes(table->ColumnsCount)) != 0)) ? +1 : 0; const int channels_total = channels_for_bg + (channels_for_row * freeze_row_multiplier) + channels_for_dummy; table->DrawSplitter->Split(table->InnerWindow->DrawList, channels_total); table->DummyDrawChannel = (ImGuiTableDrawChannelIdx)((channels_for_dummy > 0) ? channels_total - 1 : -1); @@ -2357,25 +2381,26 @@ void ImGui::TableMergeDrawChannels(ImGuiTable* table) // Track which groups we are going to attempt to merge, and which channels goes into each group. struct MergeGroup { - ImRect ClipRect; - int ChannelsCount; - ImBitVector ChannelsMask; - - MergeGroup(int sz) : ChannelsMask(sz) { ChannelsCount = 0; } + ImRect ClipRect; + int ChannelsCount = 0; + ImBitArrayPtr ChannelsMask = NULL; }; int merge_group_mask = 0x00; - int merge_group_bitlen = IMGUI_TABLE_DRAW_CHANNELS(table->ColumnsCount); - MergeGroup merge_groups[4]{ - merge_group_bitlen, - merge_group_bitlen, - merge_group_bitlen, - merge_group_bitlen - }; + MergeGroup merge_groups[4]; + + // Use a reusable temp buffer for the merge masks as they are dynamically sized. + const int max_draw_channels = (4 + table->ColumnsCount * 2); + const int size_for_masks_bitarrays_one = (int)ImBitArrayGetStorageSizeInBytes(max_draw_channels); + g.TempBuffer.reserve(size_for_masks_bitarrays_one * 5); + memset(g.TempBuffer.Data, 0, size_for_masks_bitarrays_one * 5); + for (int n = 0; n < IM_ARRAYSIZE(merge_groups); n++) + merge_groups[n].ChannelsMask = (ImBitArrayPtr)(void*)(g.TempBuffer.Data + (size_for_masks_bitarrays_one * n)); + ImBitArrayPtr remaining_mask = (ImBitArrayPtr)(void*)(g.TempBuffer.Data + (size_for_masks_bitarrays_one * 4)); // 1. Scan channels and take note of those which can be merged for (int column_n = 0; column_n < table->ColumnsCount; column_n++) { - if (!table->VisibleMaskByIndex.TestBit(column_n)) + if (!IM_BITARRAY_TESTBIT(table->VisibleMaskByIndex, column_n)) continue; ImGuiTableColumn* column = &table->Columns[column_n]; @@ -2386,7 +2411,7 @@ void ImGui::TableMergeDrawChannels(ImGuiTable* table) // Don't attempt to merge if there are multiple draw calls within the column ImDrawChannel* src_channel = &splitter->_Channels[channel_no]; - if (src_channel->_CmdBuffer.Size > 0 && src_channel->_CmdBuffer.back().ElemCount == 0 && src_channel->_CmdBuffer.back().UserCallback != NULL) // Equivalent of PopUnusedDrawCmd() + if (src_channel->_CmdBuffer.Size > 0 && src_channel->_CmdBuffer.back().ElemCount == 0 && src_channel->_CmdBuffer.back().UserCallback == NULL) // Equivalent of PopUnusedDrawCmd() src_channel->_CmdBuffer.pop_back(); if (src_channel->_CmdBuffer.Size != 1) continue; @@ -2407,11 +2432,11 @@ void ImGui::TableMergeDrawChannels(ImGuiTable* table) } const int merge_group_n = (has_freeze_h && column_n < table->FreezeColumnsCount ? 0 : 1) + (has_freeze_v && merge_group_sub_n == 0 ? 0 : 2); - IM_ASSERT(channel_no < merge_group_bitlen); + IM_ASSERT(channel_no < max_draw_channels); MergeGroup* merge_group = &merge_groups[merge_group_n]; if (merge_group->ChannelsCount == 0) merge_group->ClipRect = ImRect(+FLT_MAX, +FLT_MAX, -FLT_MAX, -FLT_MAX); - merge_group->ChannelsMask.SetBit(channel_no); + ImBitArraySetBit(merge_group->ChannelsMask, channel_no); merge_group->ChannelsCount++; merge_group->ClipRect.Add(src_channel->_CmdBuffer[0].ClipRect); merge_group_mask |= (1 << merge_group_n); @@ -2447,9 +2472,8 @@ void ImGui::TableMergeDrawChannels(ImGuiTable* table) const int LEADING_DRAW_CHANNELS = 2; g.DrawChannelsTempMergeBuffer.resize(splitter->_Count - LEADING_DRAW_CHANNELS); // Use shared temporary storage so the allocation gets amortized ImDrawChannel* dst_tmp = g.DrawChannelsTempMergeBuffer.Data; - ImBitVector remaining_mask(merge_group_bitlen); // We need 132-bit of storage - remaining_mask.SetBitRange(LEADING_DRAW_CHANNELS, splitter->_Count); - remaining_mask.ClearBit(table->Bg2DrawChannelUnfrozen); + ImBitArraySetBitRange(remaining_mask, LEADING_DRAW_CHANNELS, splitter->_Count); + ImBitArrayClearBit(remaining_mask, table->Bg2DrawChannelUnfrozen); IM_ASSERT(has_freeze_v == false || table->Bg2DrawChannelUnfrozen != TABLE_DRAW_CHANNEL_BG2_FROZEN); int remaining_count = splitter->_Count - (has_freeze_v ? LEADING_DRAW_CHANNELS + 1 : LEADING_DRAW_CHANNELS); //ImRect host_rect = (table->InnerWindow == table->OuterWindow) ? table->InnerClipRect : table->HostClipRect; @@ -2476,20 +2500,18 @@ void ImGui::TableMergeDrawChannels(ImGuiTable* table) merge_clip_rect.Max.x = ImMax(merge_clip_rect.Max.x, host_rect.Max.x); if ((merge_group_n & 2) != 0 && (table->Flags & ImGuiTableFlags_NoHostExtendY) == 0) merge_clip_rect.Max.y = ImMax(merge_clip_rect.Max.y, host_rect.Max.y); -#if 0 - GetOverlayDrawList()->AddRect(merge_group->ClipRect.Min, merge_group->ClipRect.Max, IM_COL32(255, 0, 0, 200), 0.0f, 0, 1.0f); - GetOverlayDrawList()->AddLine(merge_group->ClipRect.Min, merge_clip_rect.Min, IM_COL32(255, 100, 0, 200)); - GetOverlayDrawList()->AddLine(merge_group->ClipRect.Max, merge_clip_rect.Max, IM_COL32(255, 100, 0, 200)); -#endif + //GetForegroundDrawList()->AddRect(merge_group->ClipRect.Min, merge_group->ClipRect.Max, IM_COL32(255, 0, 0, 200), 0.0f, 0, 1.0f); // [DEBUG] + //GetForegroundDrawList()->AddLine(merge_group->ClipRect.Min, merge_clip_rect.Min, IM_COL32(255, 100, 0, 200)); + //GetForegroundDrawList()->AddLine(merge_group->ClipRect.Max, merge_clip_rect.Max, IM_COL32(255, 100, 0, 200)); remaining_count -= merge_group->ChannelsCount; - for (int n = 0; n < remaining_mask.Storage.size(); n++) - remaining_mask.Storage[n] &= ~merge_group->ChannelsMask.Storage[n]; + for (int n = 0; n < (size_for_masks_bitarrays_one >> 2); n++) + remaining_mask[n] &= ~merge_group->ChannelsMask[n]; for (int n = 0; n < splitter->_Count && merge_channels_count != 0; n++) { // Copy + overwrite new clip rect - if (!merge_group->ChannelsMask.TestBit(n)) + if (!IM_BITARRAY_TESTBIT(merge_group->ChannelsMask, n)) continue; - merge_group->ChannelsMask.ClearBit(n); + IM_BITARRAY_CLEARBIT(merge_group->ChannelsMask, n); merge_channels_count--; ImDrawChannel* channel = &splitter->_Channels[n]; @@ -2507,7 +2529,7 @@ void ImGui::TableMergeDrawChannels(ImGuiTable* table) // Append unmergeable channels that we didn't reorder at the end of the list for (int n = 0; n < splitter->_Count && remaining_count != 0; n++) { - if (!remaining_mask.TestBit(n)) + if (!IM_BITARRAY_TESTBIT(remaining_mask, n)) continue; ImDrawChannel* channel = &splitter->_Channels[n]; memcpy(dst_tmp++, channel, sizeof(ImDrawChannel)); @@ -2532,14 +2554,14 @@ void ImGui::TableDrawBorders(ImGuiTable* table) // Draw inner border and resizing feedback ImGuiTableInstanceData* table_instance = TableGetInstanceData(table, table->InstanceCurrent); const float border_size = TABLE_BORDER_SIZE; - const float draw_y1 = table->InnerRect.Min.y + ((table->Flags & ImGuiTableFlags_NoBordersInFrozenArea)?table_instance->LastFirstRowHeight:0.0f); + const float draw_y1 = table->InnerRect.Min.y; const float draw_y2_body = table->InnerRect.Max.y; const float draw_y2_head = table->IsUsingHeaders ? ImMin(table->InnerRect.Max.y, (table->FreezeRowsCount >= 1 ? table->InnerRect.Min.y : table->WorkRect.Min.y) + table_instance->LastFirstRowHeight) : draw_y1; if (table->Flags & ImGuiTableFlags_BordersInnerV) { for (int order_n = 0; order_n < table->ColumnsCount; order_n++) { - if (!table->EnabledMaskByDisplayOrder.TestBit(order_n)) + if (!IM_BITARRAY_TESTBIT(table->EnabledMaskByDisplayOrder, order_n)) continue; const int column_n = table->DisplayOrderToIndex[order_n]; @@ -2644,7 +2666,6 @@ ImGuiTableSortSpecs* ImGui::TableGetSortSpecs() TableUpdateLayout(table); TableSortSpecsBuild(table); - return &table->SortSpecs; } @@ -2763,7 +2784,7 @@ void ImGui::TableSortSpecsSanitize(ImGuiTable* table) } } - // Fallback default sort order (if no column had the ImGuiTableColumnFlags_DefaultSort flag) + // Fallback default sort order (if no column with the ImGuiTableColumnFlags_DefaultSort flag) if (sort_order_count == 0 && !(table->Flags & ImGuiTableFlags_SortTristate)) for (int column_n = 0; column_n < table->ColumnsCount; column_n++) { @@ -2867,10 +2888,9 @@ void ImGui::TableHeadersRow() continue; // Push an id to allow unnamed labels (generally accidental, but let's behave nicely with them) - // - in your own code you may omit the PushID/PopID all-together, provided you know they won't collide - // - table->InstanceCurrent is only >0 when we use multiple BeginTable/EndTable calls with same identifier. + // In your own code you may omit the PushID/PopID all-together, provided you know they won't collide. const char* name = (TableGetColumnFlags(column_n) & ImGuiTableColumnFlags_NoHeaderLabel) ? "" : TableGetColumnName(column_n); - PushID(table->InstanceCurrent * table->ColumnsCount + column_n); + PushID(column_n); TableHeader(name); PopID(); } @@ -2985,7 +3005,7 @@ void ImGui::TableHeader(const char* label) } // Sort order arrow - const float ellipsis_max = cell_r.Max.x - w_arrow - w_sort_text; + const float ellipsis_max = ImMax(cell_r.Max.x - w_arrow - w_sort_text, label_pos.x); if ((table->Flags & ImGuiTableFlags_Sortable) && !(column->Flags & ImGuiTableColumnFlags_NoSort)) { if (column->SortOrder != -1) @@ -3016,7 +3036,7 @@ void ImGui::TableHeader(const char* label) RenderTextEllipsis(window->DrawList, label_pos, ImVec2(ellipsis_max, label_pos.y + label_height + g.Style.FramePadding.y), ellipsis_max, ellipsis_max, label, label_end, &label_size); const bool text_clipped = label_size.x > (ellipsis_max - label_pos.x); - if (text_clipped && hovered && g.HoveredIdNotActiveTimer > g.TooltipSlowDelay) + if (text_clipped && hovered && g.ActiveId == 0 && IsItemHovered(ImGuiHoveredFlags_DelayNormal)) SetTooltip("%.*s", (int)(label_end - label), label); // We don't use BeginPopupContextItem() because we want the popup to stay up even after the column is hidden @@ -3051,6 +3071,17 @@ void ImGui::TableOpenContextMenu(int column_n) } } +bool ImGui::TableBeginContextMenuPopup(ImGuiTable* table) +{ + if (!table->IsContextPopupOpen || table->InstanceCurrent != table->InstanceInteracted) + return false; + const ImGuiID context_menu_id = ImHashStr("##ContextMenu", 0, table->ID); + if (BeginPopupEx(context_menu_id, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoSavedSettings)) + return true; + table->IsContextPopupOpen = false; + return false; +} + // Output context menu into current window (generally a popup) // FIXME-TABLE: Ideally this should be writable by the user. Full programmatic access to that data? void ImGui::TableDrawContextMenu(ImGuiTable* table) @@ -3070,15 +3101,15 @@ void ImGui::TableDrawContextMenu(ImGuiTable* table) if (column != NULL) { const bool can_resize = !(column->Flags & ImGuiTableColumnFlags_NoResize) && column->IsEnabled; - if (MenuItem("Size column to fit###SizeOne", NULL, false, can_resize)) + if (MenuItem(LocalizeGetMsg(ImGuiLocKey_TableSizeOne), NULL, false, can_resize)) // "###SizeOne" TableSetColumnWidthAutoSingle(table, column_n); } const char* size_all_desc; if (table->ColumnsEnabledFixedCount == table->ColumnsEnabledCount && (table->Flags & ImGuiTableFlags_SizingMask_) != ImGuiTableFlags_SizingFixedSame) - size_all_desc = "Size all columns to fit###SizeAll"; // All fixed + size_all_desc = LocalizeGetMsg(ImGuiLocKey_TableSizeAllFit); // "###SizeAll" All fixed else - size_all_desc = "Size all columns to default###SizeAll"; // All stretch or mixed + size_all_desc = LocalizeGetMsg(ImGuiLocKey_TableSizeAllDefault); // "###SizeAll" All stretch or mixed if (MenuItem(size_all_desc, NULL)) TableSetColumnWidthAutoAll(table); want_separator = true; @@ -3087,7 +3118,7 @@ void ImGui::TableDrawContextMenu(ImGuiTable* table) // Ordering if (table->Flags & ImGuiTableFlags_Reorderable) { - if (MenuItem("Reset order", NULL, false, !table->IsDefaultDisplayOrder)) + if (MenuItem(LocalizeGetMsg(ImGuiLocKey_TableResetOrder), NULL, false, !table->IsDefaultDisplayOrder)) table->IsResetDisplayOrderRequest = true; want_separator = true; } @@ -3444,12 +3475,12 @@ static void TableSettingsHandler_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandle if (!save_column) continue; buf->appendf("Column %-2d", column_n); - if (column->UserID != 0) buf->appendf(" UserID=%08X", column->UserID); - if (save_size && column->IsStretch) buf->appendf(" Weight=%.4f", column->WidthOrWeight); - if (save_size && !column->IsStretch) buf->appendf(" Width=%d", (int)column->WidthOrWeight); - if (save_visible) buf->appendf(" Visible=%d", column->IsEnabled); - if (save_order) buf->appendf(" Order=%d", column->DisplayOrder); - if (save_sort && column->SortOrder != -1) buf->appendf(" Sort=%d%c", column->SortOrder, (column->SortDirection == ImGuiSortDirection_Ascending) ? 'v' : '^'); + if (column->UserID != 0) { buf->appendf(" UserID=%08X", column->UserID); } + if (save_size && column->IsStretch) { buf->appendf(" Weight=%.4f", column->WidthOrWeight); } + if (save_size && !column->IsStretch) { buf->appendf(" Width=%d", (int)column->WidthOrWeight); } + if (save_visible) { buf->appendf(" Visible=%d", column->IsEnabled); } + if (save_order) { buf->appendf(" Order=%d", column->DisplayOrder); } + if (save_sort && column->SortOrder != -1) { buf->appendf(" Sort=%d%c", column->SortOrder, (column->SortDirection == ImGuiSortDirection_Ascending) ? 'v' : '^'); } buf->append("\n"); } buf->append("\n"); @@ -3480,7 +3511,7 @@ void ImGui::TableSettingsAddSettingsHandler() // Remove Table (currently only used by TestEngine) void ImGui::TableRemove(ImGuiTable* table) { - //IMGUI_DEBUG_LOG("TableRemove() id=0x%08X\n", table->ID); + //IMGUI_DEBUG_PRINT("TableRemove() id=0x%08X\n", table->ID); ImGuiContext& g = *GImGui; int table_idx = g.Tables.GetIndex(table); //memset(table->RawData.Data, 0, table->RawData.size_in_bytes()); @@ -3492,12 +3523,12 @@ void ImGui::TableRemove(ImGuiTable* table) // Free up/compact internal Table buffers for when it gets unused void ImGui::TableGcCompactTransientBuffers(ImGuiTable* table) { - //IMGUI_DEBUG_LOG("TableGcCompactTransientBuffers() id=0x%08X\n", table->ID); + //IMGUI_DEBUG_PRINT("TableGcCompactTransientBuffers() id=0x%08X\n", table->ID); ImGuiContext& g = *GImGui; IM_ASSERT(table->MemoryCompacted == false); table->SortSpecs.Specs = NULL; table->SortSpecsMulti.clear(); - table->IsSortSpecsDirty = true; // FIXME: shouldn't have to leak into user performing a sort + table->IsSortSpecsDirty = true; // FIXME: In theory shouldn't have to leak into user performing a sort on resume. table->ColumnsNames.clear(); table->MemoryCompacted = true; for (int n = 0; n < table->ColumnsCount; n++) @@ -3536,7 +3567,7 @@ void ImGui::TableGcCompactSettings() // - DebugNodeTable() [Internal] //------------------------------------------------------------------------- -#ifndef IMGUI_DISABLE_METRICS_WINDOW +#ifndef IMGUI_DISABLE_DEBUG_TOOLS static const char* DebugNodeTableGetSizingPolicyDesc(ImGuiTableFlags sizing_policy) { @@ -3550,13 +3581,9 @@ static const char* DebugNodeTableGetSizingPolicyDesc(ImGuiTableFlags sizing_poli void ImGui::DebugNodeTable(ImGuiTable* table) { - char buf[512]; - char* p = buf; - const char* buf_end = buf + IM_ARRAYSIZE(buf); - const bool is_active = (table->LastFrameActive >= ImGui::GetFrameCount() - 2); // Note that fully clipped early out scrolling tables will appear as inactive here. - ImFormatString(p, buf_end - p, "Table 0x%08X (%d columns, in '%s')%s", table->ID, table->ColumnsCount, table->OuterWindow->Name, is_active ? "" : " *Inactive*"); + const bool is_active = (table->LastFrameActive >= GetFrameCount() - 2); // Note that fully clipped early out scrolling tables will appear as inactive here. if (!is_active) { PushStyleColor(ImGuiCol_Text, GetStyleColorVec4(ImGuiCol_TextDisabled)); } - bool open = TreeNode(table, "%s", buf); + bool open = TreeNode(table, "Table 0x%08X (%d columns, in '%s')%s", table->ID, table->ColumnsCount, table->OuterWindow->Name, is_active ? "" : " *Inactive*"); if (!is_active) { PopStyleColor(); } if (IsItemHovered()) GetForegroundDrawList()->AddRect(table->OuterRect.Min, table->OuterRect.Max, IM_COL32(255, 255, 0, 255)); @@ -3565,7 +3592,7 @@ void ImGui::DebugNodeTable(ImGuiTable* table) if (!open) return; if (table->InstanceCurrent > 0) - ImGui::Text("** %d instances of same table! Some data below will refer to last instance.", table->InstanceCurrent + 1); + Text("** %d instances of same table! Some data below will refer to last instance.", table->InstanceCurrent + 1); bool clear_settings = SmallButton("Clear settings"); BulletText("OuterRect: Pos: (%.1f,%.1f) Size: (%.1f,%.1f) Sizing: '%s'", table->OuterRect.Min.x, table->OuterRect.Min.y, table->OuterRect.GetWidth(), table->OuterRect.GetHeight(), DebugNodeTableGetSizingPolicyDesc(table->Flags)); BulletText("ColumnsGivenWidth: %.1f, ColumnsAutoFitWidth: %.1f, InnerWidth: %.1f%s", table->ColumnsGivenWidth, table->ColumnsAutoFitWidth, table->InnerWidth, table->InnerWidth == 0.0f ? " (auto)" : ""); @@ -3581,6 +3608,7 @@ void ImGui::DebugNodeTable(ImGuiTable* table) { ImGuiTableColumn* column = &table->Columns[n]; const char* name = TableGetColumnName(table, n); + char buf[512]; ImFormatString(buf, IM_ARRAYSIZE(buf), "Column %d order %d '%s': offset %+.2f to %+.2f%s\n" "Enabled: %d, VisibleX/Y: %d/%d, RequestOutput: %d, SkipItems: %d, DrawChannels: %d,%d\n" @@ -3630,7 +3658,7 @@ void ImGui::DebugNodeTableSettings(ImGuiTableSettings* settings) TreePop(); } -#else // #ifndef IMGUI_DISABLE_METRICS_WINDOW +#else // #ifndef IMGUI_DISABLE_DEBUG_TOOLS void ImGui::DebugNodeTable(ImGuiTable*) {} void ImGui::DebugNodeTableSettings(ImGuiTableSettings*) {} @@ -3869,6 +3897,7 @@ void ImGui::BeginColumns(const char* str_id, int columns_count, ImGuiOldColumnFl columns->Count = columns_count; columns->Flags = flags; window->DC.CurrentColumns = columns; + window->DC.NavIsScrollPushableX = false; // Shortcut for NavUpdateCurrentWindowIsScrollPushableX(); columns->HostCursorPosY = window->DC.CursorPos.y; columns->HostCursorMaxPosX = window->DC.CursorMaxPos.x; @@ -3970,6 +3999,7 @@ void ImGui::NextColumn() { // New row/line: column 0 honor IndentX. window->DC.ColumnsOffset.x = ImMax(column_padding - window->WindowPadding.x, 0.0f); + window->DC.IsSameLine = false; columns->LineMinY = columns->LineMaxY; } window->DC.CursorPos.x = IM_FLOOR(window->Pos.x + window->DC.Indent.x + window->DC.ColumnsOffset.x); @@ -4021,8 +4051,7 @@ void ImGui::EndColumns() const ImGuiID column_id = columns->ID + ImGuiID(n); const float column_hit_hw = COLUMNS_HIT_RECT_HALF_WIDTH; const ImRect column_hit_rect(ImVec2(x - column_hit_hw, y1), ImVec2(x + column_hit_hw, y2)); - KeepAliveID(column_id); - if (IsClippedEx(column_hit_rect, column_id)) // FIXME: Can be removed or replaced with a lower-level test + if (!ItemAdd(column_hit_rect, column_id, NULL, ImGuiItemFlags_NoNav)) continue; bool hovered = false, held = false; @@ -4059,6 +4088,7 @@ void ImGui::EndColumns() window->DC.CurrentColumns = NULL; window->DC.ColumnsOffset.x = 0.0f; window->DC.CursorPos.x = IM_FLOOR(window->Pos.x + window->DC.Indent.x + window->DC.ColumnsOffset.x); + NavUpdateCurrentWindowIsScrollPushableX(); } void ImGui::Columns(int columns_count, const char* id, bool border) diff --git a/extern/imgui_patched/imgui_widgets.cpp b/extern/imgui_patched/imgui_widgets.cpp index 45bfd82c..b99e546e 100644 --- a/extern/imgui_patched/imgui_widgets.cpp +++ b/extern/imgui_patched/imgui_widgets.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.88 WIP +// dear imgui, v1.89.6 // (widgets code) /* @@ -32,16 +32,15 @@ Index of this file: #define _CRT_SECURE_NO_WARNINGS #endif -#include "imgui.h" -#ifndef IMGUI_DISABLE - #ifndef IMGUI_DEFINE_MATH_OPERATORS #define IMGUI_DEFINE_MATH_OPERATORS #endif + +#include "imgui.h" +#ifndef IMGUI_DISABLE #include "imgui_internal.h" // System includes -#include // toupper #if defined(_MSC_VER) && _MSC_VER <= 1500 // MSVC 2008 or earlier #include // intptr_t #else @@ -127,7 +126,7 @@ static const ImU64 IM_U64_MAX = (2ULL * 9223372036854775807LL + 1); // For InputTextEx() static bool InputTextFilterCharacter(unsigned int* p_char, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, void* user_data, ImGuiInputSource input_source); static int InputTextCalcTextLenAndLineCount(const char* text_begin, const char** out_text_end); -static ImVec2 InputTextCalcTextSizeW(const ImWchar* text_begin, const ImWchar* text_end, const ImWchar** remaining = NULL, ImVec2* out_offset = NULL, bool stop_on_new_line = false); +static ImVec2 InputTextCalcTextSizeW(ImGuiContext* ctx, const ImWchar* text_begin, const ImWchar* text_end, const ImWchar** remaining = NULL, ImVec2* out_offset = NULL, bool stop_on_new_line = false); //------------------------------------------------------------------------- // [SECTION] Widgets: Text, etc. @@ -275,10 +274,9 @@ void ImGui::TextV(const char* fmt, va_list args) if (window->SkipItems) return; - // FIXME-OPT: Handle the %s shortcut? - ImGuiContext& g = *GImGui; - const char* text_end = g.TempBuffer + ImFormatStringV(g.TempBuffer, IM_ARRAYSIZE(g.TempBuffer), fmt, args); - TextEx(g.TempBuffer, text_end, ImGuiTextFlags_NoWidthForLargeClippedText); + const char* text, *text_end; + ImFormatStringToTempBufferV(&text, &text_end, fmt, args); + TextEx(text, text_end, ImGuiTextFlags_NoWidthForLargeClippedText); } void ImGui::TextColored(const ImVec4& col, const char* fmt, ...) @@ -292,10 +290,7 @@ void ImGui::TextColored(const ImVec4& col, const char* fmt, ...) void ImGui::TextColoredV(const ImVec4& col, const char* fmt, va_list args) { PushStyleColor(ImGuiCol_Text, col); - if (fmt[0] == '%' && fmt[1] == 's' && fmt[2] == 0) - TextEx(va_arg(args, const char*), NULL, ImGuiTextFlags_NoWidthForLargeClippedText); // Skip formatting - else - TextV(fmt, args); + TextV(fmt, args); PopStyleColor(); } @@ -311,10 +306,7 @@ void ImGui::TextDisabledV(const char* fmt, va_list args) { ImGuiContext& g = *GImGui; PushStyleColor(ImGuiCol_Text, g.Style.Colors[ImGuiCol_TextDisabled]); - if (fmt[0] == '%' && fmt[1] == 's' && fmt[2] == 0) - TextEx(va_arg(args, const char*), NULL, ImGuiTextFlags_NoWidthForLargeClippedText); // Skip formatting - else - TextV(fmt, args); + TextV(fmt, args); PopStyleColor(); } @@ -329,13 +321,10 @@ void ImGui::TextWrapped(const char* fmt, ...) void ImGui::TextWrappedV(const char* fmt, va_list args) { ImGuiContext& g = *GImGui; - bool need_backup = (g.CurrentWindow->DC.TextWrapPos < 0.0f); // Keep existing wrap position if one is already set + const bool need_backup = (g.CurrentWindow->DC.TextWrapPos < 0.0f); // Keep existing wrap position if one is already set if (need_backup) PushTextWrapPos(0.0f); - if (fmt[0] == '%' && fmt[1] == 's' && fmt[2] == 0) - TextEx(va_arg(args, const char*), NULL, ImGuiTextFlags_NoWidthForLargeClippedText); // Skip formatting - else - TextV(fmt, args); + TextV(fmt, args); if (need_backup) PopTextWrapPos(); } @@ -359,8 +348,8 @@ void ImGui::LabelTextV(const char* label, const char* fmt, va_list args) const ImGuiStyle& style = g.Style; const float w = CalcItemWidth(); - const char* value_text_begin = &g.TempBuffer[0]; - const char* value_text_end = value_text_begin + ImFormatStringV(g.TempBuffer, IM_ARRAYSIZE(g.TempBuffer), fmt, args); + const char* value_text_begin, *value_text_end; + ImFormatStringToTempBufferV(&value_text_begin, &value_text_end, fmt, args); const ImVec2 value_size = CalcTextSize(value_text_begin, value_text_end, false); const ImVec2 label_size = CalcTextSize(label, NULL, true); @@ -395,8 +384,8 @@ void ImGui::BulletTextV(const char* fmt, va_list args) ImGuiContext& g = *GImGui; const ImGuiStyle& style = g.Style; - const char* text_begin = g.TempBuffer; - const char* text_end = text_begin + ImFormatStringV(g.TempBuffer, IM_ARRAYSIZE(g.TempBuffer), fmt, args); + const char* text_begin, *text_end; + ImFormatStringToTempBufferV(&text_begin, &text_end, fmt, args); const ImVec2 label_size = CalcTextSize(text_begin, text_end, false); const ImVec2 total_size = ImVec2(g.FontSize + (label_size.x > 0.0f ? (label_size.x + style.FramePadding.x * 2) : 0.0f), label_size.y); // Empty text doesn't add padding ImVec2 pos = window->DC.CursorPos; @@ -509,8 +498,9 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool g.HoveredWindow = window; #ifdef IMGUI_ENABLE_TEST_ENGINE + // Alternate registration spot, for when caller didn't use ItemAdd() if (id != 0 && g.LastItemData.ID != id) - IMGUI_TEST_ENGINE_ITEM_ADD(bb, id); + IMGUI_TEST_ENGINE_ITEM_ADD(id, bb, NULL); #endif bool pressed = false; @@ -542,18 +532,28 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool hovered = false; // Mouse handling + const ImGuiID test_owner_id = (flags & ImGuiButtonFlags_NoTestKeyOwner) ? ImGuiKeyOwner_Any : id; if (hovered) { + // Poll mouse buttons + // - 'mouse_button_clicked' is generally carried into ActiveIdMouseButton when setting ActiveId. + // - Technically we only need some values in one code path, but since this is gated by hovered test this is fine. + int mouse_button_clicked = -1; + int mouse_button_released = -1; + for (int button = 0; button < 3; button++) + if (flags & (ImGuiButtonFlags_MouseButtonLeft << button)) // Handle ImGuiButtonFlags_MouseButtonRight and ImGuiButtonFlags_MouseButtonMiddle here. + { + if (IsMouseClicked(button, test_owner_id) && mouse_button_clicked == -1) { mouse_button_clicked = button; } + if (IsMouseReleased(button, test_owner_id) && mouse_button_released == -1) { mouse_button_released = button; } + } + + // Process initial action if (!(flags & ImGuiButtonFlags_NoKeyModifiers) || (!g.IO.KeyCtrl && !g.IO.KeyShift && !g.IO.KeyAlt)) { - // Poll buttons - int mouse_button_clicked = -1; - if ((flags & ImGuiButtonFlags_MouseButtonLeft) && g.IO.MouseClicked[0]) { mouse_button_clicked = 0; } - else if ((flags & ImGuiButtonFlags_MouseButtonRight) && g.IO.MouseClicked[1]) { mouse_button_clicked = 1; } - else if ((flags & ImGuiButtonFlags_MouseButtonMiddle) && g.IO.MouseClicked[2]) { mouse_button_clicked = 2; } - if (mouse_button_clicked != -1 && g.ActiveId != id) { + if (!(flags & ImGuiButtonFlags_NoSetKeyOwner)) + SetKeyOwner(MouseButtonToKey(mouse_button_clicked), id); if (flags & (ImGuiButtonFlags_PressedOnClickRelease | ImGuiButtonFlags_PressedOnClickReleaseAnywhere)) { SetActiveID(id, window); @@ -577,10 +577,6 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool } if (flags & ImGuiButtonFlags_PressedOnRelease) { - int mouse_button_released = -1; - if ((flags & ImGuiButtonFlags_MouseButtonLeft) && g.IO.MouseReleased[0]) { mouse_button_released = 0; } - else if ((flags & ImGuiButtonFlags_MouseButtonRight) && g.IO.MouseReleased[1]) { mouse_button_released = 1; } - else if ((flags & ImGuiButtonFlags_MouseButtonMiddle) && g.IO.MouseReleased[2]) { mouse_button_released = 2; } if (mouse_button_released != -1) { const bool has_repeated_at_least_once = (flags & ImGuiButtonFlags_Repeat) && g.IO.MouseDownDurationPrev[mouse_button_released] >= g.IO.KeyRepeatDelay; // Repeat mode trumps on release behavior @@ -595,7 +591,7 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool // 'Repeat' mode acts when held regardless of _PressedOn flags (see table above). // Relies on repeat logic of IsMouseClicked() but we may as well do it ourselves if we end up exposing finer RepeatDelay/RepeatRate settings. if (g.ActiveId == id && (flags & ImGuiButtonFlags_Repeat)) - if (g.IO.MouseDownDuration[g.ActiveIdMouseButton] > 0.0f && IsMouseClicked(g.ActiveIdMouseButton, true)) + if (g.IO.MouseDownDuration[g.ActiveIdMouseButton] > 0.0f && IsMouseClicked(g.ActiveIdMouseButton, test_owner_id, ImGuiInputFlags_Repeat)) pressed = true; } @@ -611,13 +607,22 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool if (g.NavActivateDownId == id) { bool nav_activated_by_code = (g.NavActivateId == id); - bool nav_activated_by_inputs = IsNavInputTest(ImGuiNavInput_Activate, (flags & ImGuiButtonFlags_Repeat) ? ImGuiNavReadMode_Repeat : ImGuiNavReadMode_Pressed); + bool nav_activated_by_inputs = (g.NavActivatePressedId == id); + if (!nav_activated_by_inputs && (flags & ImGuiButtonFlags_Repeat)) + { + // Avoid pressing multiple keys from triggering excessive amount of repeat events + const ImGuiKeyData* key1 = GetKeyData(ImGuiKey_Space); + const ImGuiKeyData* key2 = GetKeyData(ImGuiKey_Enter); + const ImGuiKeyData* key3 = GetKeyData(ImGuiKey_NavGamepadActivate); + const float t1 = ImMax(ImMax(key1->DownDuration, key2->DownDuration), key3->DownDuration); + nav_activated_by_inputs = CalcTypematicRepeatAmount(t1 - g.IO.DeltaTime, t1, g.IO.KeyRepeatDelay, g.IO.KeyRepeatRate) > 0; + } if (nav_activated_by_code || nav_activated_by_inputs) { // Set active id so it can be queried by user via IsItemActive(), equivalent of holding the mouse button. pressed = true; SetActiveID(id, window); - g.ActiveIdSource = ImGuiInputSource_Nav; + g.ActiveIdSource = g.NavInputSource; if (!(flags & ImGuiButtonFlags_NoNavFocus)) SetFocusID(id, window); } @@ -633,8 +638,12 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool g.ActiveIdClickOffset = g.IO.MousePos - bb.Min; const int mouse_button = g.ActiveIdMouseButton; - IM_ASSERT(mouse_button >= 0 && mouse_button < ImGuiMouseButton_COUNT); - if (g.IO.MouseDown[mouse_button]) + if (mouse_button == -1) + { + // Fallback for the rare situation were g.ActiveId was set programmatically or from another widget (e.g. #6304). + ClearActiveID(); + } + else if (IsMouseDown(mouse_button, test_owner_id)) { held = true; } @@ -647,7 +656,8 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool // Report as pressed when releasing the mouse (this is the most common path) bool is_double_click_release = (flags & ImGuiButtonFlags_PressedOnDoubleClick) && g.IO.MouseReleased[mouse_button] && g.IO.MouseClickedLastCount[mouse_button] == 2; bool is_repeating_already = (flags & ImGuiButtonFlags_Repeat) && g.IO.MouseDownDurationPrev[mouse_button] >= g.IO.KeyRepeatDelay; // Repeat mode trumps - if (!is_double_click_release && !is_repeating_already) + bool is_button_avail_or_owned = TestKeyOwner(MouseButtonToKey(mouse_button), test_owner_id); + if (!is_double_click_release && !is_repeating_already && is_button_avail_or_owned) pressed = true; } ClearActiveID(); @@ -655,7 +665,7 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool if (!(flags & ImGuiButtonFlags_NoNavFocus)) g.NavDisableHighlight = true; } - else if (g.ActiveIdSource == ImGuiInputSource_Nav) + else if (g.ActiveIdSource == ImGuiInputSource_Keyboard || g.ActiveIdSource == ImGuiInputSource_Gamepad) { // When activated using Nav, we hold on the ActiveID until activation button is released if (g.NavActivateDownId != id) @@ -822,7 +832,7 @@ bool ImGui::CloseButton(ImGuiID id, const ImVec2& pos) ImU32 col = GetColorU32(held ? ImGuiCol_ButtonActive : ImGuiCol_ButtonHovered); ImVec2 center = bb.GetCenter(); if (hovered) - window->DrawList->AddCircleFilled(center, ImMax(2.0f, g.FontSize * 0.5f + 1.0f), col, 12); + window->DrawList->AddCircleFilled(center, ImMax(2.0f, g.FontSize * 0.5f + 1.0f), col); float cross_extent = g.FontSize * 0.5f * 0.7071f - 1.0f; ImU32 cross_col = GetColorU32(ImGuiCol_Text); @@ -849,7 +859,7 @@ bool ImGui::CollapseButton(ImGuiID id, const ImVec2& pos, ImGuiDockNode* dock_no ImU32 bg_col = GetColorU32((held && hovered) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button); ImU32 text_col = GetColorU32(ImGuiCol_Text); if (hovered || held) - window->DrawList->AddCircleFilled(bb.GetCenter() + ImVec2(0,-0.5f), g.FontSize * 0.5f + 1.0f, bg_col, 12); + window->DrawList->AddCircleFilled(bb.GetCenter() + ImVec2(0,-0.5f), g.FontSize * 0.5f + 1.0f, bg_col); if (dock_node) RenderArrowDockMenu(window->DrawList, bb.Min + g.Style.FramePadding, g.FontSize, text_col); @@ -886,9 +896,7 @@ void ImGui::Scrollbar(ImGuiAxis axis) { ImGuiContext& g = *GImGui; ImGuiWindow* window = g.CurrentWindow; - const ImGuiID id = GetWindowScrollbarID(window, axis); - KeepAliveID(id); // Calculate scrollbar bounding box ImRect bb = GetWindowScrollbarRect(window, axis); @@ -957,6 +965,7 @@ bool ImGui::ScrollbarEx(const ImRect& bb_frame, ImGuiID id, ImGuiAxis axis, ImS6 // Handle input right away. None of the code of Begin() is relying on scrolling position before calling Scrollbar(). bool held = false; bool hovered = false; + ItemAdd(bb_frame, id, NULL, ImGuiItemFlags_NoNav); ButtonBehavior(bb, id, &hovered, &held, ImGuiButtonFlags_NoNavFocus); const ImS64 scroll_max = ImMax((ImS64)1, size_contents_v - size_avail_v); @@ -1036,20 +1045,21 @@ void ImGui::Image(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& // ImageButton() is flawed as 'id' is always derived from 'texture_id' (see #2464 #1390) // We provide this internal helper to write your own variant while we figure out how to redesign the public ImageButton() API. -bool ImGui::ImageButtonEx(ImGuiID id, ImTextureID texture_id, const ImVec2& size, const ImVec2& uv0, const ImVec2& uv1, const ImVec2& padding, const ImVec4& bg_col, const ImVec4& tint_col) +bool ImGui::ImageButtonEx(ImGuiID id, ImTextureID texture_id, const ImVec2& size, const ImVec2& uv0, const ImVec2& uv1, const ImVec4& bg_col, const ImVec4& tint_col, ImGuiButtonFlags flags) { ImGuiContext& g = *GImGui; ImGuiWindow* window = GetCurrentWindow(); if (window->SkipItems) return false; - const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + size + padding * 2); + const ImVec2 padding = g.Style.FramePadding; + const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + size + padding * 2.0f); ItemSize(bb); if (!ItemAdd(bb, id)) return false; bool hovered, held; - bool pressed = ButtonBehavior(bb, id, &hovered, &held); + bool pressed = ButtonBehavior(bb, id, &hovered, &held, flags); // Render const ImU32 col = GetColorU32((held && hovered) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button); @@ -1062,9 +1072,21 @@ bool ImGui::ImageButtonEx(ImGuiID id, ImTextureID texture_id, const ImVec2& size return pressed; } -// frame_padding < 0: uses FramePadding from style (default) -// frame_padding = 0: no framing -// frame_padding > 0: set framing size +bool ImGui::ImageButton(const char* str_id, ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0, const ImVec2& uv1, const ImVec4& bg_col, const ImVec4& tint_col) +{ + ImGuiContext& g = *GImGui; + ImGuiWindow* window = g.CurrentWindow; + if (window->SkipItems) + return false; + + return ImageButtonEx(window->GetID(str_id), user_texture_id, size, uv0, uv1, bg_col, tint_col); +} + +#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS +// Legacy API obsoleted in 1.89. Two differences with new ImageButton() +// - new ImageButton() requires an explicit 'const char* str_id' Old ImageButton() used opaque imTextureId (created issue with: multiple buttons with same image, transient texture id values, opaque computation of ID) +// - new ImageButton() always use style.FramePadding Old ImageButton() had an override argument. +// If you need to change padding with new ImageButton() you can use PushStyleVar(ImGuiStyleVar_FramePadding, value), consistent with other Button functions. bool ImGui::ImageButton(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0, const ImVec2& uv1, int frame_padding, const ImVec4& bg_col, const ImVec4& tint_col) { ImGuiContext& g = *GImGui; @@ -1077,9 +1099,14 @@ bool ImGui::ImageButton(ImTextureID user_texture_id, const ImVec2& size, const I const ImGuiID id = window->GetID("#image"); PopID(); - const ImVec2 padding = (frame_padding >= 0) ? ImVec2((float)frame_padding, (float)frame_padding) : g.Style.FramePadding; - return ImageButtonEx(id, user_texture_id, size, uv0, uv1, padding, bg_col, tint_col); + if (frame_padding >= 0) + PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2((float)frame_padding, (float)frame_padding)); + bool ret = ImageButtonEx(id, user_texture_id, size, uv0, uv1, bg_col, tint_col); + if (frame_padding >= 0) + PopStyleVar(); + return ret; } +#endif // #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS bool ImGui::Checkbox(const char* label, bool* v) { @@ -1217,17 +1244,18 @@ bool ImGui::RadioButton(const char* label, bool active) MarkItemEdited(id); RenderNavHighlight(total_bb, id); - window->DrawList->AddCircleFilled(center, radius, GetColorU32((held && hovered) ? ImGuiCol_FrameBgActive : hovered ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg), 16); + const int num_segment = window->DrawList->_CalcCircleAutoSegmentCount(radius); + window->DrawList->AddCircleFilled(center, radius, GetColorU32((held && hovered) ? ImGuiCol_FrameBgActive : hovered ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg), num_segment); if (active) { const float pad = ImMax(1.0f, IM_FLOOR(square_sz / 6.0f)); - window->DrawList->AddCircleFilled(center, radius - pad, GetColorU32(ImGuiCol_CheckMark), 16); + window->DrawList->AddCircleFilled(center, radius - pad, GetColorU32(ImGuiCol_CheckMark)); } if (style.FrameBorderSize > 0.0f) { - window->DrawList->AddCircle(center + ImVec2(1, 1), radius, GetColorU32(ImGuiCol_BorderShadow), 16, style.FrameBorderSize); - window->DrawList->AddCircle(center, radius, GetColorU32(ImGuiCol_Border), 16, style.FrameBorderSize); + window->DrawList->AddCircle(center + ImVec2(1, 1), radius, GetColorU32(ImGuiCol_BorderShadow), num_segment, style.FrameBorderSize); + window->DrawList->AddCircle(center, radius, GetColorU32(ImGuiCol_Border), num_segment, style.FrameBorderSize); } ImVec2 label_pos = ImVec2(check_bb.Max.x + style.ItemInnerSpacing.x, check_bb.Min.y + style.FramePadding.y); @@ -1370,7 +1398,9 @@ void ImGui::AlignTextToFramePadding() } // Horizontal/vertical separating line -void ImGui::SeparatorEx(ImGuiSeparatorFlags flags) +// FIXME: Surprisingly, this seemingly trivial widget is a victim of many different legacy/tricky layout issues. +// Note how thickness == 1.0f is handled specifically as not moving CursorPos by 'thickness', but other values are. +void ImGui::SeparatorEx(ImGuiSeparatorFlags flags, float thickness) { ImGuiWindow* window = GetCurrentWindow(); if (window->SkipItems) @@ -1378,21 +1408,20 @@ void ImGui::SeparatorEx(ImGuiSeparatorFlags flags) ImGuiContext& g = *GImGui; IM_ASSERT(ImIsPowerOfTwo(flags & (ImGuiSeparatorFlags_Horizontal | ImGuiSeparatorFlags_Vertical))); // Check that only 1 option is selected + IM_ASSERT(thickness > 0.0f); - float thickness_draw = 1.0f; - float thickness_layout = 0.0f; if (flags & ImGuiSeparatorFlags_Vertical) { - // Vertical separator, for menu bars (use current line height). Not exposed because it is misleading and it doesn't have an effect on regular layout. + // Vertical separator, for menu bars (use current line height). float y1 = window->DC.CursorPos.y; float y2 = window->DC.CursorPos.y + window->DC.CurrLineSize.y; - const ImRect bb(ImVec2(window->DC.CursorPos.x, y1), ImVec2(window->DC.CursorPos.x + thickness_draw, y2)); - ItemSize(ImVec2(thickness_layout, 0.0f)); + const ImRect bb(ImVec2(window->DC.CursorPos.x, y1), ImVec2(window->DC.CursorPos.x + thickness, y2)); + ItemSize(ImVec2(thickness, 0.0f)); if (!ItemAdd(bb, 0)) return; // Draw - window->DrawList->AddLine(ImVec2(bb.Min.x, bb.Min.y), ImVec2(bb.Min.x, bb.Max.y), GetColorU32(ImGuiCol_Separator)); + window->DrawList->AddRectFilled(bb.Min, bb.Max, GetColorU32(ImGuiCol_Separator)); if (g.LogEnabled) LogText(" |"); } @@ -1414,19 +1443,22 @@ void ImGui::SeparatorEx(ImGuiSeparatorFlags flags) x2 = table->Columns[table->CurrentColumn].MaxX; } + // Before Tables API happened, we relied on Separator() to span all columns of a Columns() set. + // We currently don't need to provide the same feature for tables because tables naturally have border features. ImGuiOldColumns* columns = (flags & ImGuiSeparatorFlags_SpanAllColumns) ? window->DC.CurrentColumns : NULL; if (columns) PushColumnsBackground(); // We don't provide our width to the layout so that it doesn't get feed back into AutoFit // FIXME: This prevents ->CursorMaxPos based bounding box evaluation from working (e.g. TableEndCell) - const ImRect bb(ImVec2(x1, window->DC.CursorPos.y), ImVec2(x2, window->DC.CursorPos.y + thickness_draw)); - ItemSize(ImVec2(0.0f, thickness_layout)); - const bool item_visible = ItemAdd(bb, 0); - if (item_visible) + const float thickness_for_layout = (thickness == 1.0f) ? 0.0f : thickness; // FIXME: See 1.70/1.71 Separator() change: makes legacy 1-px separator not affect layout yet. Should change. + const ImRect bb(ImVec2(x1, window->DC.CursorPos.y), ImVec2(x2, window->DC.CursorPos.y + thickness)); + ItemSize(ImVec2(0.0f, thickness_for_layout)); + + if (ItemAdd(bb, 0)) { // Draw - window->DrawList->AddLine(bb.Min, ImVec2(bb.Max.x, bb.Min.y), GetColorU32(ImGuiCol_Separator)); + window->DrawList->AddRectFilled(bb.Min, bb.Max, GetColorU32(ImGuiCol_Separator)); if (g.LogEnabled) LogRenderedText(&bb.Min, "--------------------------------\n"); @@ -1446,10 +1478,76 @@ void ImGui::Separator() if (window->SkipItems) return; - // Those flags should eventually be overridable by the user + // Those flags should eventually be configurable by the user + // FIXME: We cannot g.Style.SeparatorTextBorderSize for thickness as it relates to SeparatorText() which is a decorated separator, not defaulting to 1.0f. ImGuiSeparatorFlags flags = (window->DC.LayoutType == ImGuiLayoutType_Horizontal) ? ImGuiSeparatorFlags_Vertical : ImGuiSeparatorFlags_Horizontal; flags |= ImGuiSeparatorFlags_SpanAllColumns; // NB: this only applies to legacy Columns() api as they relied on Separator() a lot. - SeparatorEx(flags); + SeparatorEx(flags, 1.0f); +} + +void ImGui::SeparatorTextEx(ImGuiID id, const char* label, const char* label_end, float extra_w) +{ + ImGuiContext& g = *GImGui; + ImGuiWindow* window = g.CurrentWindow; + ImGuiStyle& style = g.Style; + + const ImVec2 label_size = CalcTextSize(label, label_end, false); + const ImVec2 pos = window->DC.CursorPos; + const ImVec2 padding = style.SeparatorTextPadding; + + const float separator_thickness = style.SeparatorTextBorderSize; + const ImVec2 min_size(label_size.x + extra_w + padding.x * 2.0f, ImMax(label_size.y + padding.y * 2.0f, separator_thickness)); + const ImRect bb(pos, ImVec2(window->WorkRect.Max.x, pos.y + min_size.y)); + const float text_baseline_y = ImFloor((bb.GetHeight() - label_size.y) * style.SeparatorTextAlign.y + 0.99999f); //ImMax(padding.y, ImFloor((style.SeparatorTextSize - label_size.y) * 0.5f)); + ItemSize(min_size, text_baseline_y); + if (!ItemAdd(bb, id)) + return; + + const float sep1_x1 = pos.x; + const float sep2_x2 = bb.Max.x; + const float seps_y = ImFloor((bb.Min.y + bb.Max.y) * 0.5f + 0.99999f); + + const float label_avail_w = ImMax(0.0f, sep2_x2 - sep1_x1 - padding.x * 2.0f); + const ImVec2 label_pos(pos.x + padding.x + ImMax(0.0f, (label_avail_w - label_size.x - extra_w) * style.SeparatorTextAlign.x), pos.y + text_baseline_y); // FIXME-ALIGN + + // This allows using SameLine() to position something in the 'extra_w' + window->DC.CursorPosPrevLine.x = label_pos.x + label_size.x; + + const ImU32 separator_col = GetColorU32(ImGuiCol_Separator); + if (label_size.x > 0.0f) + { + const float sep1_x2 = label_pos.x - style.ItemSpacing.x; + const float sep2_x1 = label_pos.x + label_size.x + extra_w + style.ItemSpacing.x; + if (sep1_x2 > sep1_x1 && separator_thickness > 0.0f) + window->DrawList->AddLine(ImVec2(sep1_x1, seps_y), ImVec2(sep1_x2, seps_y), separator_col, separator_thickness); + if (sep2_x2 > sep2_x1 && separator_thickness > 0.0f) + window->DrawList->AddLine(ImVec2(sep2_x1, seps_y), ImVec2(sep2_x2, seps_y), separator_col, separator_thickness); + if (g.LogEnabled) + LogSetNextTextDecoration("---", NULL); + RenderTextEllipsis(window->DrawList, label_pos, ImVec2(bb.Max.x, bb.Max.y + style.ItemSpacing.y), bb.Max.x, bb.Max.x, label, label_end, &label_size); + } + else + { + if (g.LogEnabled) + LogText("---"); + if (separator_thickness > 0.0f) + window->DrawList->AddLine(ImVec2(sep1_x1, seps_y), ImVec2(sep2_x2, seps_y), separator_col, separator_thickness); + } +} + +void ImGui::SeparatorText(const char* label) +{ + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return; + + // The SeparatorText() vs SeparatorTextEx() distinction is designed to be considerate that we may want: + // - allow separator-text to be draggable items (would require a stable ID + a noticeable highlight) + // - this high-level entry point to allow formatting? (which in turns may require ID separate from formatted string) + // - because of this we probably can't turn 'const char* label' into 'const char* fmt, ...' + // Otherwise, we can decide that users wanting to drag this would layout a dedicated drag-item, + // and then we can turn this into a format function. + SeparatorTextEx(0, label, FindRenderedTextEnd(label), 0.0f); } // Using 'hover_visibility_delay' allows us to hide the highlight and mouse cursor for a short time, which can be convenient to reduce visual noise. @@ -1458,11 +1556,7 @@ bool ImGui::SplitterBehavior(const ImRect& bb, ImGuiID id, ImGuiAxis axis, float ImGuiContext& g = *GImGui; ImGuiWindow* window = g.CurrentWindow; - const ImGuiItemFlags item_flags_backup = g.CurrentItemFlags; - g.CurrentItemFlags |= ImGuiItemFlags_NoNav | ImGuiItemFlags_NoNavDefaultFocus; - bool item_add = ItemAdd(bb, id); - g.CurrentItemFlags = item_flags_backup; - if (!item_add) + if (!ItemAdd(bb, id, NULL, ImGuiItemFlags_NoNav)) return false; bool hovered, held; @@ -1548,7 +1642,7 @@ void ImGui::ShrinkWidths(ImGuiShrinkWidthItem* items, int count, float width_exc width_excess -= width_to_remove_per_item * count_same_width; } - // Round width and redistribute remainder left-to-right (could make it an option of the function?) + // Round width and redistribute remainder // Ensure that e.g. the right-most tab of a shrunk tab-bar always reaches exactly at the same distance from the right-most edge of the tab bar separator. width_excess = 0.0f; for (int n = 0; n < count; n++) @@ -1557,10 +1651,13 @@ void ImGui::ShrinkWidths(ImGuiShrinkWidthItem* items, int count, float width_exc width_excess += items[n].Width - width_rounded; items[n].Width = width_rounded; } - if (width_excess > 0.0f) - for (int n = 0; n < count; n++) - if (items[n].Index < (int)(width_excess + 0.01f)) - items[n].Width += 1.0f; + while (width_excess > 0.0f) + for (int n = 0; n < count && width_excess > 0.0f; n++) + { + float width_to_add = ImMin(items[n].InitialWidth - items[n].Width, 1.0f); + items[n].Width += width_to_add; + width_excess -= width_to_add; + } } //------------------------------------------------------------------------- @@ -1682,7 +1779,12 @@ bool ImGui::BeginComboPopup(ImGuiID popup_id, const ImRect& bb, ImGuiComboFlags if (flags & ImGuiComboFlags_HeightRegular) popup_max_height_in_items = 8; else if (flags & ImGuiComboFlags_HeightSmall) popup_max_height_in_items = 4; else if (flags & ImGuiComboFlags_HeightLarge) popup_max_height_in_items = 20; - SetNextWindowSizeConstraints(ImVec2(w, 0.0f), ImVec2(FLT_MAX, CalcMaxPopupHeightFromItemCount(popup_max_height_in_items))); + ImVec2 constraint_min(0.0f, 0.0f), constraint_max(FLT_MAX, FLT_MAX); + if ((g.NextWindowData.Flags & ImGuiNextWindowDataFlags_HasSize) == 0 || g.NextWindowData.SizeVal.x <= 0.0f) // Don't apply constraints if user specified a size + constraint_min.x = w; + if ((g.NextWindowData.Flags & ImGuiNextWindowDataFlags_HasSize) == 0 || g.NextWindowData.SizeVal.y <= 0.0f) + constraint_max.y = CalcMaxPopupHeightFromItemCount(popup_max_height_in_items); + SetNextWindowSizeConstraints(constraint_min, constraint_max); } // This is essentially a specialized version of BeginPopupEx() @@ -1730,7 +1832,7 @@ bool ImGui::BeginComboPreview() ImGuiWindow* window = g.CurrentWindow; ImGuiComboPreviewData* preview_data = &g.ComboPreviewData; - if (window->SkipItems || !window->ClipRect.Overlaps(g.LastItemData.Rect)) // FIXME: Because we don't have a ImGuiItemStatusFlags_Visible flag to test last ItemAdd() result + if (window->SkipItems || !(g.LastItemData.StatusFlags & ImGuiItemStatusFlags_Visible)) return false; IM_ASSERT(g.LastItemData.Rect.Min.x == preview_data->PreviewRect.Min.x && g.LastItemData.Rect.Min.y == preview_data->PreviewRect.Min.y); // Didn't call after BeginCombo/EndCombo block or forgot to pass ImGuiComboFlags_CustomPreview flag? if (!window->ClipRect.Contains(preview_data->PreviewRect)) // Narrower test (optional) @@ -1874,11 +1976,11 @@ bool ImGui::Combo(const char* label, int* current_item, const char* items_separa //------------------------------------------------------------------------- // [SECTION] Data Type and Data Formatting Helpers [Internal] //------------------------------------------------------------------------- -// - PatchFormatStringFloatToInt() // - DataTypeGetInfo() // - DataTypeFormatString() // - DataTypeApplyOp() // - DataTypeApplyOpFromText() +// - DataTypeCompare() // - DataTypeClamp() // - GetMinimumStepAtDecimalPrecision // - RoundScalarWithFormat<>() @@ -1904,30 +2006,6 @@ static const ImGuiDataTypeInfo GDataTypeInfo[] = }; IM_STATIC_ASSERT(IM_ARRAYSIZE(GDataTypeInfo) == ImGuiDataType_COUNT); -// FIXME-LEGACY: Prior to 1.61 our DragInt() function internally used floats and because of this the compile-time default value for format was "%.0f". -// Even though we changed the compile-time default, we expect users to have carried %f around, which would break the display of DragInt() calls. -// To honor backward compatibility we are rewriting the format string, unless IMGUI_DISABLE_OBSOLETE_FUNCTIONS is enabled. What could possibly go wrong?! -static const char* PatchFormatStringFloatToInt(const char* fmt) -{ - if (fmt[0] == '%' && fmt[1] == '.' && fmt[2] == '0' && fmt[3] == 'f' && fmt[4] == 0) // Fast legacy path for "%.0f" which is expected to be the most common case. - return "%d"; - const char* fmt_start = ImParseFormatFindStart(fmt); // Find % (if any, and ignore %%) - const char* fmt_end = ImParseFormatFindEnd(fmt_start); // Find end of format specifier, which itself is an exercise of confidence/recklessness (because snprintf is dependent on libc or user). - if (fmt_end > fmt_start && fmt_end[-1] == 'f') - { -#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS - if (fmt_start == fmt && fmt_end[0] == 0) - return "%d"; - ImGuiContext& g = *GImGui; - ImFormatString(g.TempBuffer, IM_ARRAYSIZE(g.TempBuffer), "%.*s%%d%s", (int)(fmt_start - fmt), fmt, fmt_end); // Honor leading and trailing decorations, but lose alignment/precision. - return g.TempBuffer; -#else - IM_ASSERT(0 && "DragInt(): Invalid format string!"); // Old versions used a default parameter of "%.0f", please replace with e.g. "%d" -#endif - } - return fmt; -} - const ImGuiDataTypeInfo* ImGui::DataTypeGetInfo(ImGuiDataType data_type) { IM_ASSERT(data_type >= 0 && data_type < ImGuiDataType_COUNT); @@ -2022,7 +2100,8 @@ bool ImGui::DataTypeApplyFromText(const char* buf, ImGuiDataType data_type, void memcpy(&data_backup, p_data, type_info->Size); // Sanitize format - // For float/double we have to ignore format with precision (e.g. "%.2f") because sscanf doesn't take them in, so force them into %f and %lf + // - For float/double we have to ignore format with precision (e.g. "%.2f") because sscanf doesn't take them in, so force them into %f and %lf + // - In theory could treat empty format as using default, but this would only cover rare/bizarre case of using InputScalar() + integer + format string without %. char format_sanitized[32]; if (data_type == ImGuiDataType_Float || data_type == ImGuiDataType_Double) format = type_info->ScanFmt; @@ -2183,10 +2262,13 @@ bool ImGui::DragBehaviorT(ImGuiDataType data_type, TYPE* v, float v_speed, const if (g.IO.KeyShift) adjust_delta *= 10.0f; } - else if (g.ActiveIdSource == ImGuiInputSource_Nav) + else if (g.ActiveIdSource == ImGuiInputSource_Keyboard || g.ActiveIdSource == ImGuiInputSource_Gamepad) { const int decimal_precision = is_floating_point ? ImParseFormatPrecision(format, 3) : 0; - adjust_delta = GetNavInputAmount2d(ImGuiNavDirSourceFlags_Keyboard | ImGuiNavDirSourceFlags_PadDPad, ImGuiNavReadMode_RepeatFast, 1.0f / 10.0f, 10.0f)[axis]; + const bool tweak_slow = IsKeyDown((g.NavInputSource == ImGuiInputSource_Gamepad) ? ImGuiKey_NavGamepadTweakSlow : ImGuiKey_NavKeyboardTweakSlow); + const bool tweak_fast = IsKeyDown((g.NavInputSource == ImGuiInputSource_Gamepad) ? ImGuiKey_NavGamepadTweakFast : ImGuiKey_NavKeyboardTweakFast); + const float tweak_factor = tweak_slow ? 1.0f / 1.0f : tweak_fast ? 10.0f : 1.0f; + adjust_delta = GetNavTweakPressedAmount(axis) * tweak_factor; v_speed = ImMax(v_speed, GetMinimumStepAtDecimalPrecision(decimal_precision)); } adjust_delta *= v_speed; @@ -2284,9 +2366,10 @@ bool ImGui::DragBehavior(ImGuiID id, ImGuiDataType data_type, void* p_v, float v ImGuiContext& g = *GImGui; if (g.ActiveId == id) { + // Those are the things we can do easily outside the DragBehaviorT<> template, saves code generation. if (g.ActiveIdSource == ImGuiInputSource_Mouse && !g.IO.MouseDown[0]) ClearActiveID(); - else if (g.ActiveIdSource == ImGuiInputSource_Nav && g.NavActivatePressedId == id && !g.ActiveIdIsJustActivated) + else if ((g.ActiveIdSource == ImGuiInputSource_Keyboard || g.ActiveIdSource == ImGuiInputSource_Gamepad) && g.NavActivatePressedId == id && !g.ActiveIdIsJustActivated) ClearActiveID(); } if (g.ActiveId != id) @@ -2337,36 +2420,38 @@ bool ImGui::DragScalar(const char* label, ImGuiDataType data_type, void* p_data, // Default format string when passing NULL if (format == NULL) format = DataTypeGetInfo(data_type)->PrintFmt; - else if (data_type == ImGuiDataType_S32 && strcmp(format, "%d") != 0) // (FIXME-LEGACY: Patch old "%.0f" format string to use "%d", read function more details.) - format = PatchFormatStringFloatToInt(format); - // Tabbing or CTRL-clicking on Drag turns it into an InputText const bool hovered = ItemHoverable(frame_bb, id); bool temp_input_is_active = temp_input_allowed && TempInputIsActive(id); if (!temp_input_is_active) { + // Tabbing or CTRL-clicking on Drag turns it into an InputText const bool input_requested_by_tabbing = temp_input_allowed && (g.LastItemData.StatusFlags & ImGuiItemStatusFlags_FocusedByTabbing) != 0; - const bool clicked = (hovered && g.IO.MouseClicked[0]); - const bool double_clicked = (hovered && g.IO.MouseClickedCount[0] == 2); - if (input_requested_by_tabbing || clicked || double_clicked || g.NavActivateId == id || g.NavActivateInputId == id) + const bool clicked = hovered && IsMouseClicked(0, id); + const bool double_clicked = (hovered && g.IO.MouseClickedCount[0] == 2 && TestKeyOwner(ImGuiKey_MouseLeft, id)); + const bool make_active = (input_requested_by_tabbing || clicked || double_clicked || g.NavActivateId == id); + if (make_active && (clicked || double_clicked)) + SetKeyOwner(ImGuiKey_MouseLeft, id); + if (make_active && temp_input_allowed) + if (input_requested_by_tabbing || (clicked && g.IO.KeyCtrl) || double_clicked || (g.NavActivateId == id && (g.NavActivateFlags & ImGuiActivateFlags_PreferInput))) + temp_input_is_active = true; + + // (Optional) simple click (without moving) turns Drag into an InputText + if (g.IO.ConfigDragClickToInputText && temp_input_allowed && !temp_input_is_active) + if (g.ActiveId == id && hovered && g.IO.MouseReleased[0] && !IsMouseDragPastThreshold(0, g.IO.MouseDragThreshold * DRAG_MOUSE_THRESHOLD_FACTOR)) + { + g.NavActivateId = id; + g.NavActivateFlags = ImGuiActivateFlags_PreferInput; + temp_input_is_active = true; + } + + if (make_active && !temp_input_is_active) { SetActiveID(id, window); SetFocusID(id, window); FocusWindow(window); g.ActiveIdUsingNavDirMask = (1 << ImGuiDir_Left) | (1 << ImGuiDir_Right); - if (temp_input_allowed) - if (input_requested_by_tabbing || (clicked && g.IO.KeyCtrl) || double_clicked || g.NavActivateInputId == id) - temp_input_is_active = true; } - - // Experimental: simple click (without moving) turns Drag into an InputText - if (g.IO.ConfigDragClickToInputText && temp_input_allowed && !temp_input_is_active) - if (g.ActiveId == id && hovered && g.IO.MouseReleased[0] && !IsMouseDragPastThreshold(0, g.IO.MouseDragThreshold * DRAG_MOUSE_THRESHOLD_FACTOR)) - { - g.NavActivateId = g.NavActivateInputId = id; - g.NavActivateFlags = ImGuiActivateFlags_PreferInput; - temp_input_is_active = true; - } } if (temp_input_is_active) @@ -2396,7 +2481,7 @@ bool ImGui::DragScalar(const char* label, ImGuiDataType data_type, void* p_data, if (label_size.x > 0.0f) RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label); - IMGUI_TEST_ENGINE_ITEM_INFO(id, label, g.LastItemData.StatusFlags); + IMGUI_TEST_ENGINE_ITEM_INFO(id, label, g.LastItemData.StatusFlags | (temp_input_allowed ? ImGuiItemStatusFlags_Inputable : 0)); return value_changed; } @@ -2542,35 +2627,6 @@ bool ImGui::DragIntRange2(const char* label, int* v_current_min, int* v_current_ return value_changed; } -#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS - -// Obsolete versions with power parameter. See https://github.com/ocornut/imgui/issues/3361 for details. -bool ImGui::DragScalar(const char* label, ImGuiDataType data_type, void* p_data, float v_speed, const void* p_min, const void* p_max, const char* format, float power) -{ - ImGuiSliderFlags drag_flags = ImGuiSliderFlags_None; - if (power != 1.0f) - { - IM_ASSERT(power == 1.0f && "Call function with ImGuiSliderFlags_Logarithmic flags instead of using the old 'float power' function!"); - IM_ASSERT(p_min != NULL && p_max != NULL); // When using a power curve the drag needs to have known bounds - drag_flags |= ImGuiSliderFlags_Logarithmic; // Fallback for non-asserting paths - } - return DragScalar(label, data_type, p_data, v_speed, p_min, p_max, format, drag_flags); -} - -bool ImGui::DragScalarN(const char* label, ImGuiDataType data_type, void* p_data, int components, float v_speed, const void* p_min, const void* p_max, const char* format, float power) -{ - ImGuiSliderFlags drag_flags = ImGuiSliderFlags_None; - if (power != 1.0f) - { - IM_ASSERT(power == 1.0f && "Call function with ImGuiSliderFlags_Logarithmic flags instead of using the old 'float power' function!"); - IM_ASSERT(p_min != NULL && p_max != NULL); // When using a power curve the drag needs to have known bounds - drag_flags |= ImGuiSliderFlags_Logarithmic; // Fallback for non-asserting paths - } - return DragScalarN(label, data_type, p_data, components, v_speed, p_min, p_max, format, drag_flags); -} - -#endif // IMGUI_DISABLE_OBSOLETE_FUNCTIONS - //------------------------------------------------------------------------- // [SECTION] Widgets: SliderScalar, SliderFloat, SliderInt, etc. //------------------------------------------------------------------------- @@ -2621,7 +2677,6 @@ float ImGui::ScaleRatioFromValueT(ImGuiDataType data_type, TYPE v, TYPE v_min, T v_max_fudged = -logarithmic_zero_epsilon; float result; - if (v_clamped <= v_min_fudged) result = 0.0f; // Workaround for values that are in-range but below our fudge else if (v_clamped >= v_max_fudged) @@ -2645,91 +2700,81 @@ float ImGui::ScaleRatioFromValueT(ImGuiDataType data_type, TYPE v, TYPE v_min, T return flipped ? (1.0f - result) : result; } - - // Linear slider - return (float)((FLOATTYPE)(SIGNEDTYPE)(v_clamped - v_min) / (FLOATTYPE)(SIGNEDTYPE)(v_max - v_min)); + else + { + // Linear slider + return (float)((FLOATTYPE)(SIGNEDTYPE)(v_clamped - v_min) / (FLOATTYPE)(SIGNEDTYPE)(v_max - v_min)); + } } // Convert a parametric position on a slider into a value v in the output space (the logical opposite of ScaleRatioFromValueT) template TYPE ImGui::ScaleValueFromRatioT(ImGuiDataType data_type, float t, TYPE v_min, TYPE v_max, bool is_logarithmic, float logarithmic_zero_epsilon, float zero_deadzone_halfsize) { - if (v_min == v_max) + // We special-case the extents because otherwise our logarithmic fudging can lead to "mathematically correct" + // but non-intuitive behaviors like a fully-left slider not actually reaching the minimum value. Also generally simpler. + if (t <= 0.0f || v_min == v_max) return v_min; - const bool is_floating_point = (data_type == ImGuiDataType_Float) || (data_type == ImGuiDataType_Double); + if (t >= 1.0f) + return v_max; - TYPE result; + TYPE result = (TYPE)0; if (is_logarithmic) { - // We special-case the extents because otherwise our fudging can lead to "mathematically correct" but non-intuitive behaviors like a fully-left slider not actually reaching the minimum value - if (t <= 0.0f) - result = v_min; - else if (t >= 1.0f) - result = v_max; - else + // Fudge min/max to avoid getting silly results close to zero + FLOATTYPE v_min_fudged = (ImAbs((FLOATTYPE)v_min) < logarithmic_zero_epsilon) ? ((v_min < 0.0f) ? -logarithmic_zero_epsilon : logarithmic_zero_epsilon) : (FLOATTYPE)v_min; + FLOATTYPE v_max_fudged = (ImAbs((FLOATTYPE)v_max) < logarithmic_zero_epsilon) ? ((v_max < 0.0f) ? -logarithmic_zero_epsilon : logarithmic_zero_epsilon) : (FLOATTYPE)v_max; + + const bool flipped = v_max < v_min; // Check if range is "backwards" + if (flipped) + ImSwap(v_min_fudged, v_max_fudged); + + // Awkward special case - we need ranges of the form (-100 .. 0) to convert to (-100 .. -epsilon), not (-100 .. epsilon) + if ((v_max == 0.0f) && (v_min < 0.0f)) + v_max_fudged = -logarithmic_zero_epsilon; + + float t_with_flip = flipped ? (1.0f - t) : t; // t, but flipped if necessary to account for us flipping the range + + if ((v_min * v_max) < 0.0f) // Range crosses zero, so we have to do this in two parts { - bool flipped = v_max < v_min; // Check if range is "backwards" - - // Fudge min/max to avoid getting silly results close to zero - FLOATTYPE v_min_fudged = (ImAbs((FLOATTYPE)v_min) < logarithmic_zero_epsilon) ? ((v_min < 0.0f) ? -logarithmic_zero_epsilon : logarithmic_zero_epsilon) : (FLOATTYPE)v_min; - FLOATTYPE v_max_fudged = (ImAbs((FLOATTYPE)v_max) < logarithmic_zero_epsilon) ? ((v_max < 0.0f) ? -logarithmic_zero_epsilon : logarithmic_zero_epsilon) : (FLOATTYPE)v_max; - - if (flipped) - ImSwap(v_min_fudged, v_max_fudged); - - // Awkward special case - we need ranges of the form (-100 .. 0) to convert to (-100 .. -epsilon), not (-100 .. epsilon) - if ((v_max == 0.0f) && (v_min < 0.0f)) - v_max_fudged = -logarithmic_zero_epsilon; - - float t_with_flip = flipped ? (1.0f - t) : t; // t, but flipped if necessary to account for us flipping the range - - if ((v_min * v_max) < 0.0f) // Range crosses zero, so we have to do this in two parts - { - float zero_point_center = (-(float)ImMin(v_min, v_max)) / ImAbs((float)v_max - (float)v_min); // The zero point in parametric space - float zero_point_snap_L = zero_point_center - zero_deadzone_halfsize; - float zero_point_snap_R = zero_point_center + zero_deadzone_halfsize; - if (t_with_flip >= zero_point_snap_L && t_with_flip <= zero_point_snap_R) - result = (TYPE)0.0f; // Special case to make getting exactly zero possible (the epsilon prevents it otherwise) - else if (t_with_flip < zero_point_center) - result = (TYPE)-(logarithmic_zero_epsilon * ImPow(-v_min_fudged / logarithmic_zero_epsilon, (FLOATTYPE)(1.0f - (t_with_flip / zero_point_snap_L)))); - else - result = (TYPE)(logarithmic_zero_epsilon * ImPow(v_max_fudged / logarithmic_zero_epsilon, (FLOATTYPE)((t_with_flip - zero_point_snap_R) / (1.0f - zero_point_snap_R)))); - } - else if ((v_min < 0.0f) || (v_max < 0.0f)) // Entirely negative slider - result = (TYPE)-(-v_max_fudged * ImPow(-v_min_fudged / -v_max_fudged, (FLOATTYPE)(1.0f - t_with_flip))); + float zero_point_center = (-(float)ImMin(v_min, v_max)) / ImAbs((float)v_max - (float)v_min); // The zero point in parametric space + float zero_point_snap_L = zero_point_center - zero_deadzone_halfsize; + float zero_point_snap_R = zero_point_center + zero_deadzone_halfsize; + if (t_with_flip >= zero_point_snap_L && t_with_flip <= zero_point_snap_R) + result = (TYPE)0.0f; // Special case to make getting exactly zero possible (the epsilon prevents it otherwise) + else if (t_with_flip < zero_point_center) + result = (TYPE)-(logarithmic_zero_epsilon * ImPow(-v_min_fudged / logarithmic_zero_epsilon, (FLOATTYPE)(1.0f - (t_with_flip / zero_point_snap_L)))); else - result = (TYPE)(v_min_fudged * ImPow(v_max_fudged / v_min_fudged, (FLOATTYPE)t_with_flip)); + result = (TYPE)(logarithmic_zero_epsilon * ImPow(v_max_fudged / logarithmic_zero_epsilon, (FLOATTYPE)((t_with_flip - zero_point_snap_R) / (1.0f - zero_point_snap_R)))); } + else if ((v_min < 0.0f) || (v_max < 0.0f)) // Entirely negative slider + result = (TYPE)-(-v_max_fudged * ImPow(-v_min_fudged / -v_max_fudged, (FLOATTYPE)(1.0f - t_with_flip))); + else + result = (TYPE)(v_min_fudged * ImPow(v_max_fudged / v_min_fudged, (FLOATTYPE)t_with_flip)); } else { // Linear slider + const bool is_floating_point = (data_type == ImGuiDataType_Float) || (data_type == ImGuiDataType_Double); if (is_floating_point) { result = ImLerp(v_min, v_max, t); } - else + else if (t < 1.0) { // - For integer values we want the clicking position to match the grab box so we round above // This code is carefully tuned to work with large values (e.g. high ranges of U64) while preserving this property.. // - Not doing a *1.0 multiply at the end of a range as it tends to be lossy. While absolute aiming at a large s64/u64 // range is going to be imprecise anyway, with this check we at least make the edge values matches expected limits. - if (t < 1.0) - { - FLOATTYPE v_new_off_f = (SIGNEDTYPE)(v_max - v_min) * t; - result = (TYPE)((SIGNEDTYPE)v_min + (SIGNEDTYPE)(v_new_off_f + (FLOATTYPE)(v_min > v_max ? -0.5 : 0.5))); - } - else - { - result = v_max; - } + FLOATTYPE v_new_off_f = (SIGNEDTYPE)(v_max - v_min) * t; + result = (TYPE)((SIGNEDTYPE)v_min + (SIGNEDTYPE)(v_new_off_f + (FLOATTYPE)(v_min > v_max ? -0.5 : 0.5))); } } return result; } -// FIXME: Move more of the code into SliderBehavior() +// FIXME: Try to move more of the code into shared SliderBehavior() template bool ImGui::SliderBehaviorT(const ImRect& bb, ImGuiID id, ImGuiDataType data_type, TYPE* v, const TYPE v_min, const TYPE v_max, const char* format, ImGuiSliderFlags flags, ImRect* out_grab_bb) { @@ -2739,13 +2784,14 @@ bool ImGui::SliderBehaviorT(const ImRect& bb, ImGuiID id, ImGuiDataType data_typ const ImGuiAxis axis = (flags & ImGuiSliderFlags_Vertical) ? ImGuiAxis_Y : ImGuiAxis_X; const bool is_logarithmic = (flags & ImGuiSliderFlags_Logarithmic) != 0; const bool is_floating_point = (data_type == ImGuiDataType_Float) || (data_type == ImGuiDataType_Double); + const SIGNEDTYPE v_range = (v_min < v_max ? v_max - v_min : v_min - v_max); - const float grab_padding = 2.0f; + // Calculate bounds + const float grab_padding = 2.0f; // FIXME: Should be part of style. const float slider_sz = (bb.Max[axis] - bb.Min[axis]) - grab_padding * 2.0f; float grab_sz = style.GrabMinSize; - SIGNEDTYPE v_range = (v_min < v_max ? v_max - v_min : v_min - v_max); - if (!is_floating_point && v_range >= 0) // v_range < 0 may happen on integer overflows - grab_sz = ImMax((float)(slider_sz / (v_range + 1)), style.GrabMinSize); // For integer sliders: if possible have the grab size represent 1 unit + if (!is_floating_point && v_range >= 0) // v_range < 0 may happen on integer overflows + grab_sz = ImMax((float)(slider_sz / (v_range + 1)), style.GrabMinSize); // For integer sliders: if possible have the grab size represent 1 unit grab_sz = ImMin(grab_sz, slider_sz); const float slider_usable_sz = slider_sz - grab_sz; const float slider_usable_pos_min = bb.Min[axis] + grab_padding + grab_sz * 0.5f; @@ -2776,13 +2822,23 @@ bool ImGui::SliderBehaviorT(const ImRect& bb, ImGuiID id, ImGuiDataType data_typ else { const float mouse_abs_pos = g.IO.MousePos[axis]; - clicked_t = (slider_usable_sz > 0.0f) ? ImClamp((mouse_abs_pos - slider_usable_pos_min) / slider_usable_sz, 0.0f, 1.0f) : 0.0f; + if (g.ActiveIdIsJustActivated) + { + float grab_t = ScaleRatioFromValueT(data_type, *v, v_min, v_max, is_logarithmic, logarithmic_zero_epsilon, zero_deadzone_halfsize); + if (axis == ImGuiAxis_Y) + grab_t = 1.0f - grab_t; + const float grab_pos = ImLerp(slider_usable_pos_min, slider_usable_pos_max, grab_t); + const bool clicked_around_grab = (mouse_abs_pos >= grab_pos - grab_sz * 0.5f - 1.0f) && (mouse_abs_pos <= grab_pos + grab_sz * 0.5f + 1.0f); // No harm being extra generous here. + g.SliderGrabClickOffset = (clicked_around_grab && is_floating_point) ? mouse_abs_pos - grab_pos : 0.0f; + } + if (slider_usable_sz > 0.0f) + clicked_t = ImSaturate((mouse_abs_pos - g.SliderGrabClickOffset - slider_usable_pos_min) / slider_usable_sz); if (axis == ImGuiAxis_Y) clicked_t = 1.0f - clicked_t; set_new_value = true; } } - else if (g.ActiveIdSource == ImGuiInputSource_Nav) + else if (g.ActiveIdSource == ImGuiInputSource_Keyboard || g.ActiveIdSource == ImGuiInputSource_Gamepad) { if (g.ActiveIdIsJustActivated) { @@ -2790,25 +2846,26 @@ bool ImGui::SliderBehaviorT(const ImRect& bb, ImGuiID id, ImGuiDataType data_typ g.SliderCurrentAccumDirty = false; } - const ImVec2 input_delta2 = GetNavInputAmount2d(ImGuiNavDirSourceFlags_Keyboard | ImGuiNavDirSourceFlags_PadDPad, ImGuiNavReadMode_RepeatFast, 0.0f, 0.0f); - float input_delta = (axis == ImGuiAxis_X) ? input_delta2.x : -input_delta2.y; + float input_delta = (axis == ImGuiAxis_X) ? GetNavTweakPressedAmount(axis) : -GetNavTweakPressedAmount(axis); if (input_delta != 0.0f) { + const bool tweak_slow = IsKeyDown((g.NavInputSource == ImGuiInputSource_Gamepad) ? ImGuiKey_NavGamepadTweakSlow : ImGuiKey_NavKeyboardTweakSlow); + const bool tweak_fast = IsKeyDown((g.NavInputSource == ImGuiInputSource_Gamepad) ? ImGuiKey_NavGamepadTweakFast : ImGuiKey_NavKeyboardTweakFast); const int decimal_precision = is_floating_point ? ImParseFormatPrecision(format, 3) : 0; if (decimal_precision > 0) { input_delta /= 100.0f; // Gamepad/keyboard tweak speeds in % of slider bounds - if (IsNavInputDown(ImGuiNavInput_TweakSlow)) + if (tweak_slow) input_delta /= 10.0f; } else { - if ((v_range >= -100.0f && v_range <= 100.0f) || IsNavInputDown(ImGuiNavInput_TweakSlow)) + if ((v_range >= -100.0f && v_range <= 100.0f) || tweak_slow) input_delta = ((input_delta < 0.0f) ? -1.0f : +1.0f) / (float)v_range; // Gamepad/keyboard tweak speeds in integer steps else input_delta /= 100.0f; } - if (IsNavInputDown(ImGuiNavInput_TweakFast)) + if (tweak_fast) input_delta *= 10.0f; g.SliderCurrentAccum += input_delta; @@ -2896,6 +2953,7 @@ bool ImGui::SliderBehavior(const ImRect& bb, ImGuiID id, ImGuiDataType data_type // Read imgui.cpp "API BREAKING CHANGES" section for 1.78 if you hit this assert. IM_ASSERT((flags == 1 || (flags & ImGuiSliderFlags_InvalidMask_) == 0) && "Invalid ImGuiSliderFlags flag! Has the 'float power' argument been mistakenly cast to flags? Call function with ImGuiSliderFlags_Logarithmic flags instead."); + // Those are the things we can do easily outside the SliderBehaviorT<> template, saves code generation. ImGuiContext& g = *GImGui; if ((g.LastItemData.InFlags & ImGuiItemFlags_ReadOnly) || (flags & ImGuiSliderFlags_ReadOnly)) return false; @@ -2955,24 +3013,27 @@ bool ImGui::SliderScalar(const char* label, ImGuiDataType data_type, void* p_dat // Default format string when passing NULL if (format == NULL) format = DataTypeGetInfo(data_type)->PrintFmt; - else if (data_type == ImGuiDataType_S32 && strcmp(format, "%d") != 0) // (FIXME-LEGACY: Patch old "%.0f" format string to use "%d", read function more details.) - format = PatchFormatStringFloatToInt(format); - // Tabbing or CTRL-clicking on Slider turns it into an input box const bool hovered = ItemHoverable(frame_bb, id); bool temp_input_is_active = temp_input_allowed && TempInputIsActive(id); if (!temp_input_is_active) { + // Tabbing or CTRL-clicking on Slider turns it into an input box const bool input_requested_by_tabbing = temp_input_allowed && (g.LastItemData.StatusFlags & ImGuiItemStatusFlags_FocusedByTabbing) != 0; - const bool clicked = (hovered && g.IO.MouseClicked[0]); - if (input_requested_by_tabbing || clicked || g.NavActivateId == id || g.NavActivateInputId == id) + const bool clicked = hovered && IsMouseClicked(0, id); + const bool make_active = (input_requested_by_tabbing || clicked || g.NavActivateId == id); + if (make_active && clicked) + SetKeyOwner(ImGuiKey_MouseLeft, id); + if (make_active && temp_input_allowed) + if (input_requested_by_tabbing || (clicked && g.IO.KeyCtrl) || (g.NavActivateId == id && (g.NavActivateFlags & ImGuiActivateFlags_PreferInput))) + temp_input_is_active = true; + + if (make_active && !temp_input_is_active) { SetActiveID(id, window); SetFocusID(id, window); FocusWindow(window); g.ActiveIdUsingNavDirMask |= (1 << ImGuiDir_Left) | (1 << ImGuiDir_Right); - if (temp_input_allowed && (input_requested_by_tabbing || (clicked && g.IO.KeyCtrl) || g.NavActivateInputId == id)) - temp_input_is_active = true; } } @@ -3008,7 +3069,7 @@ bool ImGui::SliderScalar(const char* label, ImGuiDataType data_type, void* p_dat if (label_size.x > 0.0f) RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label); - IMGUI_TEST_ENGINE_ITEM_INFO(id, label, g.LastItemData.StatusFlags); + IMGUI_TEST_ENGINE_ITEM_INFO(id, label, g.LastItemData.StatusFlags | (temp_input_allowed ? ImGuiItemStatusFlags_Inputable : 0)); return value_changed; } @@ -3120,24 +3181,27 @@ bool ImGui::VSliderScalar(const char* label, const ImVec2& size, ImGuiDataType d // Default format string when passing NULL if (format == NULL) format = DataTypeGetInfo(data_type)->PrintFmt; - else if (data_type == ImGuiDataType_S32 && strcmp(format, "%d") != 0) // (FIXME-LEGACY: Patch old "%.0f" format string to use "%d", read function more details.) - format = PatchFormatStringFloatToInt(format); - // Tabbing or CTRL-clicking on Slider turns it into an input box const bool hovered = ItemHoverable(frame_bb, id); bool temp_input_is_active = temp_input_allowed && TempInputIsActive(id); if (!temp_input_is_active) { + // Tabbing or CTRL-clicking on Slider turns it into an input box const bool input_requested_by_tabbing = temp_input_allowed && (g.LastItemData.StatusFlags & ImGuiItemStatusFlags_FocusedByTabbing) != 0; - const bool clicked = (hovered && g.IO.MouseClicked[0]); - if (input_requested_by_tabbing || clicked || g.NavActivateId == id || g.NavActivateInputId == id) + const bool clicked = hovered && IsMouseClicked(0, id); + const bool make_active = (input_requested_by_tabbing || clicked || g.NavActivateId == id); + if (make_active && clicked) + SetKeyOwner(ImGuiKey_MouseLeft, id); + if (make_active && temp_input_allowed) + if (input_requested_by_tabbing || (clicked && g.IO.KeyCtrl) || (g.NavActivateId == id && (g.NavActivateFlags & ImGuiActivateFlags_PreferInput))) + temp_input_is_active = true; + + if (make_active && !temp_input_is_active) { SetActiveID(id, window); SetFocusID(id, window); FocusWindow(window); g.ActiveIdUsingNavDirMask |= (1 << ImGuiDir_Up) | (1 << ImGuiDir_Down); - if (temp_input_allowed && (input_requested_by_tabbing || (clicked && g.IO.KeyCtrl) || g.NavActivateInputId == id)) - temp_input_is_active = true; } } @@ -3185,33 +3249,6 @@ bool ImGui::VSliderInt(const char* label, const ImVec2& size, int* v, int v_min, return VSliderScalar(label, size, ImGuiDataType_S32, v, &v_min, &v_max, format, flags); } -#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS - -// Obsolete versions with power parameter. See https://github.com/ocornut/imgui/issues/3361 for details. -bool ImGui::SliderScalar(const char* label, ImGuiDataType data_type, void* p_data, const void* p_min, const void* p_max, const char* format, float power) -{ - ImGuiSliderFlags slider_flags = ImGuiSliderFlags_None; - if (power != 1.0f) - { - IM_ASSERT(power == 1.0f && "Call function with ImGuiSliderFlags_Logarithmic flags instead of using the old 'float power' function!"); - slider_flags |= ImGuiSliderFlags_Logarithmic; // Fallback for non-asserting paths - } - return SliderScalar(label, data_type, p_data, p_min, p_max, format, slider_flags); -} - -bool ImGui::SliderScalarN(const char* label, ImGuiDataType data_type, void* v, int components, const void* v_min, const void* v_max, const char* format, float power) -{ - ImGuiSliderFlags slider_flags = ImGuiSliderFlags_None; - if (power != 1.0f) - { - IM_ASSERT(power == 1.0f && "Call function with ImGuiSliderFlags_Logarithmic flags instead of using the old 'float power' function!"); - slider_flags |= ImGuiSliderFlags_Logarithmic; // Fallback for non-asserting paths - } - return SliderScalarN(label, data_type, v, components, v_min, v_max, format, slider_flags); -} - -#endif // IMGUI_DISABLE_OBSOLETE_FUNCTIONS - //------------------------------------------------------------------------- // [SECTION] Widgets: InputScalar, InputFloat, InputInt, etc. //------------------------------------------------------------------------- @@ -3267,7 +3304,7 @@ const char* ImParseFormatFindEnd(const char* fmt) } // Extract the format out of a format string with leading or trailing decorations -// fmt = "blah blah" -> return fmt +// fmt = "blah blah" -> return "" // fmt = "%.3f" -> return fmt // fmt = "hello %.3f" -> return fmt + 6 // fmt = "%.3f hello" -> return buf written with "%.3f" @@ -3275,7 +3312,7 @@ const char* ImParseFormatTrimDecorations(const char* fmt, char* buf, size_t buf_ { const char* fmt_start = ImParseFormatFindStart(fmt); if (fmt_start[0] != '%') - return fmt; + return ""; const char* fmt_end = ImParseFormatFindEnd(fmt_start); if (fmt_end[0] == 0) // If we only have leading decoration, we don't need to copy the data. return fmt_start; @@ -3300,7 +3337,7 @@ void ImParseFormatSanitizeForPrinting(const char* fmt_in, char* fmt_out, size_t *fmt_out = 0; // Zero-terminate } -// - For scanning we need to remove all width and precision fields "%3.7f" -> "%f". BUT don't strip types like "%I64d" which includes digits. ! "%07I64d" -> "%I64d" +// - For scanning we need to remove all width and precision fields and flags "%+3.7f" -> "%f". BUT don't strip types like "%I64d" which includes digits. ! "%07I64d" -> "%I64d" const char* ImParseFormatSanitizeForScanning(const char* fmt_in, char* fmt_out, size_t fmt_out_size) { const char* fmt_end = ImParseFormatFindEnd(fmt_in); @@ -3311,7 +3348,7 @@ const char* ImParseFormatSanitizeForScanning(const char* fmt_in, char* fmt_out, while (fmt_in < fmt_end) { char c = *fmt_in++; - if (!has_type && ((c >= '0' && c <= '9') || c == '.')) + if (!has_type && ((c >= '0' && c <= '9') || c == '.' || c == '+' || c == '#')) continue; has_type |= ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')); // Stop skipping digits if (c != '\'' && c != '$' && c != '_') // Custom flags provided by stb_sprintf.h. POSIX 2008 also supports '. @@ -3393,9 +3430,14 @@ static inline ImGuiInputTextFlags InputScalar_DefaultCharsFilter(ImGuiDataType d // However this may not be ideal for all uses, as some user code may break on out of bound values. bool ImGui::TempInputScalar(const ImRect& bb, ImGuiID id, const char* label, ImGuiDataType data_type, void* p_data, const char* format, const void* p_clamp_min, const void* p_clamp_max) { + // FIXME: May need to clarify display behavior if format doesn't contain %. + // "%d" -> "%d" / "There are %d items" -> "%d" / "items" -> "%d" (fallback). Also see #6405 + const ImGuiDataTypeInfo* type_info = DataTypeGetInfo(data_type); char fmt_buf[32]; char data_buf[32]; format = ImParseFormatTrimDecorations(format, fmt_buf, IM_ARRAYSIZE(fmt_buf)); + if (format[0] == 0) + format = type_info->PrintFmt; DataTypeFormatString(data_buf, IM_ARRAYSIZE(data_buf), data_type, p_data, format); ImStrTrimBlanks(data_buf); @@ -3406,7 +3448,7 @@ bool ImGui::TempInputScalar(const ImRect& bb, ImGuiID id, const char* label, ImG if (TempInputText(bb, id, label, data_buf, IM_ARRAYSIZE(data_buf), flags)) { // Backup old value - size_t data_type_size = DataTypeGetInfo(data_type)->Size; + size_t data_type_size = type_info->Size; ImGuiDataTypeTempStorage data_backup; memcpy(&data_backup, p_data, data_type_size); @@ -3450,7 +3492,12 @@ bool ImGui::InputScalar(const char* label, ImGuiDataType data_type, void* p_data flags |= ImGuiInputTextFlags_AutoSelectAll | ImGuiInputTextFlags_NoMarkEdited; // We call MarkItemEdited() ourselves by comparing the actual data rather than the string. bool value_changed = false; - if (p_step != NULL) + if (p_step == NULL) + { + if (InputText(label, buf, IM_ARRAYSIZE(buf), flags)) + value_changed = DataTypeApplyFromText(buf, data_type, p_data, format); + } + else { const float button_size = GetFrameHeight(); @@ -3459,6 +3506,7 @@ bool ImGui::InputScalar(const char* label, ImGuiDataType data_type, void* p_data SetNextItemWidth(ImMax(1.0f, CalcItemWidth() - (button_size + style.ItemInnerSpacing.x) * 2)); if (InputText("", buf, IM_ARRAYSIZE(buf), flags)) // PushId(label) + "" gives us the expected ID from outside point of view value_changed = DataTypeApplyFromText(buf, data_type, p_data, format); + IMGUI_TEST_ENGINE_ITEM_INFO(g.LastItemData.ID, label, g.LastItemData.StatusFlags | ImGuiItemStatusFlags_Inputable); // Step buttons const ImVec2 backup_frame_padding = style.FramePadding; @@ -3492,11 +3540,6 @@ bool ImGui::InputScalar(const char* label, ImGuiDataType data_type, void* p_data PopID(); EndGroup(); } - else - { - if (InputText(label, buf, IM_ARRAYSIZE(buf), flags)) - value_changed = DataTypeApplyFromText(buf, data_type, p_data, format); - } if (value_changed) MarkItemEdited(g.LastItemData.ID); @@ -3597,6 +3640,7 @@ bool ImGui::InputDouble(const char* label, double* v, double step, double step_f // - InputTextReindexLines() [Internal] // - InputTextReindexLinesRange() [Internal] // - InputTextEx() [Internal] +// - DebugNodeInputTextState() [Internal] //------------------------------------------------------------------------- bool ImGui::InputText(const char* label, char* buf, size_t buf_size, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, void* user_data) @@ -3612,7 +3656,7 @@ bool ImGui::InputTextMultiline(const char* label, char* buf, size_t buf_size, co bool ImGui::InputTextWithHint(const char* label, const char* hint, char* buf, size_t buf_size, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, void* user_data) { - IM_ASSERT(!(flags & ImGuiInputTextFlags_Multiline)); // call InputTextMultiline() + IM_ASSERT(!(flags & ImGuiInputTextFlags_Multiline)); // call InputTextMultiline() or InputTextEx() manually if you need multi-line + hint. return InputTextEx(label, hint, buf, (int)buf_size, ImVec2(0, 0), flags, callback, user_data); } @@ -3630,9 +3674,9 @@ static int InputTextCalcTextLenAndLineCount(const char* text_begin, const char** return line_count; } -static ImVec2 InputTextCalcTextSizeW(const ImWchar* text_begin, const ImWchar* text_end, const ImWchar** remaining, ImVec2* out_offset, bool stop_on_new_line) +static ImVec2 InputTextCalcTextSizeW(ImGuiContext* ctx, const ImWchar* text_begin, const ImWchar* text_end, const ImWchar** remaining, ImVec2* out_offset, bool stop_on_new_line) { - ImGuiContext& g = *GImGui; + ImGuiContext& g = *ctx; ImFont* font = g.Font; const float line_height = g.FontSize; const float scale = line_height / font->FontSize; @@ -3681,14 +3725,14 @@ namespace ImStb static int STB_TEXTEDIT_STRINGLEN(const ImGuiInputTextState* obj) { return obj->CurLenW; } static ImWchar STB_TEXTEDIT_GETCHAR(const ImGuiInputTextState* obj, int idx) { return obj->TextW[idx]; } -static float STB_TEXTEDIT_GETWIDTH(ImGuiInputTextState* obj, int line_start_idx, int char_idx) { ImWchar c = obj->TextW[line_start_idx + char_idx]; if (c == '\n') return STB_TEXTEDIT_GETWIDTH_NEWLINE; ImGuiContext& g = *GImGui; return g.Font->GetCharAdvance(c) * (g.FontSize / g.Font->FontSize); } +static float STB_TEXTEDIT_GETWIDTH(ImGuiInputTextState* obj, int line_start_idx, int char_idx) { ImWchar c = obj->TextW[line_start_idx + char_idx]; if (c == '\n') return STB_TEXTEDIT_GETWIDTH_NEWLINE; ImGuiContext& g = *obj->Ctx; return g.Font->GetCharAdvance(c) * (g.FontSize / g.Font->FontSize); } static int STB_TEXTEDIT_KEYTOTEXT(int key) { return key >= 0x200000 ? 0 : key; } static ImWchar STB_TEXTEDIT_NEWLINE = '\n'; static void STB_TEXTEDIT_LAYOUTROW(StbTexteditRow* r, ImGuiInputTextState* obj, int line_start_idx) { const ImWchar* text = obj->TextW.Data; const ImWchar* text_remaining = NULL; - const ImVec2 size = InputTextCalcTextSizeW(text + line_start_idx, text + obj->CurLenW, &text_remaining, NULL, true); + const ImVec2 size = InputTextCalcTextSizeW(obj->Ctx, text + line_start_idx, text + obj->CurLenW, &text_remaining, NULL, true); r->x0 = 0.0f; r->x1 = size.x; r->baseline_y_delta = size.y; @@ -3697,19 +3741,40 @@ static void STB_TEXTEDIT_LAYOUTROW(StbTexteditRow* r, ImGuiInputTextState* ob r->num_chars = (int)(text_remaining - (text + line_start_idx)); } -// When ImGuiInputTextFlags_Password is set, we don't want actions such as CTRL+Arrow to leak the fact that underlying data are blanks or separators. -static bool is_separator(unsigned int c) { return ImCharIsBlankW(c) || c==',' || c==';' || c=='(' || c==')' || c=='{' || c=='}' || c=='[' || c==']' || c=='|' || c=='\n' || c=='\r'; } -static int is_word_boundary_from_right(ImGuiInputTextState* obj, int idx) { if (obj->Flags & ImGuiInputTextFlags_Password) return 0; return idx > 0 ? (is_separator(obj->TextW[idx - 1]) && !is_separator(obj->TextW[idx]) ) : 1; } -static int is_word_boundary_from_left(ImGuiInputTextState* obj, int idx) { if (obj->Flags & ImGuiInputTextFlags_Password) return 0; return idx > 0 ? (!is_separator(obj->TextW[idx - 1]) && is_separator(obj->TextW[idx])) : 1; } +static bool is_separator(unsigned int c) +{ + return c==',' || c==';' || c=='(' || c==')' || c=='{' || c=='}' || c=='[' || c==']' || c=='|' || c=='\n' || c=='\r' || c=='.' || c=='!'; +} + +static int is_word_boundary_from_right(ImGuiInputTextState* obj, int idx) +{ + // When ImGuiInputTextFlags_Password is set, we don't want actions such as CTRL+Arrow to leak the fact that underlying data are blanks or separators. + if ((obj->Flags & ImGuiInputTextFlags_Password) || idx <= 0) + return 0; + + bool prev_white = ImCharIsBlankW(obj->TextW[idx - 1]); + bool prev_separ = is_separator(obj->TextW[idx - 1]); + bool curr_white = ImCharIsBlankW(obj->TextW[idx]); + bool curr_separ = is_separator(obj->TextW[idx]); + return ((prev_white || prev_separ) && !(curr_separ || curr_white)) || (curr_separ && !prev_separ); +} +static int is_word_boundary_from_left(ImGuiInputTextState* obj, int idx) +{ + if ((obj->Flags & ImGuiInputTextFlags_Password) || idx <= 0) + return 0; + + bool prev_white = ImCharIsBlankW(obj->TextW[idx]); + bool prev_separ = is_separator(obj->TextW[idx]); + bool curr_white = ImCharIsBlankW(obj->TextW[idx - 1]); + bool curr_separ = is_separator(obj->TextW[idx - 1]); + return ((prev_white) && !(curr_separ || curr_white)) || (curr_separ && !prev_separ); +} static int STB_TEXTEDIT_MOVEWORDLEFT_IMPL(ImGuiInputTextState* obj, int idx) { idx--; while (idx >= 0 && !is_word_boundary_from_right(obj, idx)) idx--; return idx < 0 ? 0 : idx; } static int STB_TEXTEDIT_MOVEWORDRIGHT_MAC(ImGuiInputTextState* obj, int idx) { idx++; int len = obj->CurLenW; while (idx < len && !is_word_boundary_from_left(obj, idx)) idx++; return idx > len ? len : idx; } -#define STB_TEXTEDIT_MOVEWORDLEFT STB_TEXTEDIT_MOVEWORDLEFT_IMPL // They need to be #define for stb_textedit.h -#ifdef __APPLE__ // FIXME: Move setting to IO structure -#define STB_TEXTEDIT_MOVEWORDRIGHT STB_TEXTEDIT_MOVEWORDRIGHT_MAC -#else static int STB_TEXTEDIT_MOVEWORDRIGHT_WIN(ImGuiInputTextState* obj, int idx) { idx++; int len = obj->CurLenW; while (idx < len && !is_word_boundary_from_right(obj, idx)) idx++; return idx > len ? len : idx; } -#define STB_TEXTEDIT_MOVEWORDRIGHT STB_TEXTEDIT_MOVEWORDRIGHT_WIN -#endif +static int STB_TEXTEDIT_MOVEWORDRIGHT_IMPL(ImGuiInputTextState* obj, int idx) { ImGuiContext& g = *obj->Ctx; if (g.IO.ConfigMacOSXBehaviors) return STB_TEXTEDIT_MOVEWORDRIGHT_MAC(obj, idx); else return STB_TEXTEDIT_MOVEWORDRIGHT_WIN(obj, idx); } +#define STB_TEXTEDIT_MOVEWORDLEFT STB_TEXTEDIT_MOVEWORDLEFT_IMPL // They need to be #define for stb_textedit.h +#define STB_TEXTEDIT_MOVEWORDRIGHT STB_TEXTEDIT_MOVEWORDRIGHT_IMPL static void STB_TEXTEDIT_DELETECHARS(ImGuiInputTextState* obj, int pos, int n) { @@ -3792,11 +3857,12 @@ static void stb_textedit_replace(ImGuiInputTextState* str, STB_TexteditState* st { stb_text_makeundo_replace(str, state, 0, str->CurLenW, text_len); ImStb::STB_TEXTEDIT_DELETECHARS(str, 0, str->CurLenW); + state->cursor = state->select_start = state->select_end = 0; if (text_len <= 0) return; if (ImStb::STB_TEXTEDIT_INSERTCHARS(str, 0, text, text_len)) { - state->cursor = text_len; + state->cursor = state->select_start = state->select_end = text_len; state->has_preferred_x = 0; return; } else { @@ -3851,7 +3917,7 @@ void ImGuiInputTextCallbackData::InsertChars(int pos, const char* new_text, cons return; // Contrary to STB_TEXTEDIT_INSERTCHARS() this is working in the UTF8 buffer, hence the mildly similar code (until we remove the U16 buffer altogether!) - ImGuiContext& g = *GImGui; + ImGuiContext& g = *Ctx; ImGuiInputTextState* edit_state = &g.InputTextState; IM_ASSERT(edit_state->ID != 0 && g.ActiveId == edit_state->ID); IM_ASSERT(Buf == edit_state->TextA.Data); @@ -3918,6 +3984,13 @@ static bool InputTextFilterCharacter(unsigned int* p_char, ImGuiInputTextFlags f ImGuiContext& g = *GImGui; const unsigned c_decimal_point = (unsigned int)g.PlatformLocaleDecimalPoint; + // Full-width -> half-width conversion for numeric fields (https://en.wikipedia.org/wiki/Halfwidth_and_Fullwidth_Forms_(Unicode_block) + // While this is mostly convenient, this has the side-effect for uninformed users accidentally inputting full-width characters that they may + // scratch their head as to why it works in numerical fields vs in generic text fields it would require support in the font. + if (flags & (ImGuiInputTextFlags_CharsDecimal | ImGuiInputTextFlags_CharsScientific | ImGuiInputTextFlags_CharsHexadecimal)) + if (c >= 0xFF01 && c <= 0xFF5E) + c = c - 0xFF01 + 0x21; + // Allow 0-9 . - + * / if (flags & ImGuiInputTextFlags_CharsDecimal) if (!(c >= '0' && c <= '9') && (c != c_decimal_point) && (c != '-') && (c != '+') && (c != '*') && (c != '/')) @@ -3936,18 +4009,21 @@ static bool InputTextFilterCharacter(unsigned int* p_char, ImGuiInputTextFlags f // Turn a-z into A-Z if (flags & ImGuiInputTextFlags_CharsUppercase) if (c >= 'a' && c <= 'z') - *p_char = (c += (unsigned int)('A' - 'a')); + c += (unsigned int)('A' - 'a'); if (flags & ImGuiInputTextFlags_CharsNoBlank) if (ImCharIsBlankW(c)) return false; + + *p_char = c; } // Custom callback filter if (flags & ImGuiInputTextFlags_CallbackCharFilter) { + ImGuiContext& g = *GImGui; ImGuiInputTextCallbackData callback_data; - memset(&callback_data, 0, sizeof(ImGuiInputTextCallbackData)); + callback_data.Ctx = &g; callback_data.EventFlag = ImGuiInputTextFlags_CallbackCharFilter; callback_data.EventChar = (ImWchar)c; callback_data.Flags = flags; @@ -3962,6 +4038,56 @@ static bool InputTextFilterCharacter(unsigned int* p_char, ImGuiInputTextFlags f return true; } +// Find the shortest single replacement we can make to get the new text from the old text. +// Important: needs to be run before TextW is rewritten with the new characters because calling STB_TEXTEDIT_GETCHAR() at the end. +// FIXME: Ideally we should transition toward (1) making InsertChars()/DeleteChars() update undo-stack (2) discourage (and keep reconcile) or obsolete (and remove reconcile) accessing buffer directly. +static void InputTextReconcileUndoStateAfterUserCallback(ImGuiInputTextState* state, const char* new_buf_a, int new_length_a) +{ + ImGuiContext& g = *GImGui; + const ImWchar* old_buf = state->TextW.Data; + const int old_length = state->CurLenW; + const int new_length = ImTextCountCharsFromUtf8(new_buf_a, new_buf_a + new_length_a); + g.TempBuffer.reserve_discard((new_length + 1) * sizeof(ImWchar)); + ImWchar* new_buf = (ImWchar*)(void*)g.TempBuffer.Data; + ImTextStrFromUtf8(new_buf, new_length + 1, new_buf_a, new_buf_a + new_length_a); + + const int shorter_length = ImMin(old_length, new_length); + int first_diff; + for (first_diff = 0; first_diff < shorter_length; first_diff++) + if (old_buf[first_diff] != new_buf[first_diff]) + break; + if (first_diff == old_length && first_diff == new_length) + return; + + int old_last_diff = old_length - 1; + int new_last_diff = new_length - 1; + for (; old_last_diff >= first_diff && new_last_diff >= first_diff; old_last_diff--, new_last_diff--) + if (old_buf[old_last_diff] != new_buf[new_last_diff]) + break; + + const int insert_len = new_last_diff - first_diff + 1; + const int delete_len = old_last_diff - first_diff + 1; + if (insert_len > 0 || delete_len > 0) + if (STB_TEXTEDIT_CHARTYPE* p = stb_text_createundo(&state->Stb.undostate, first_diff, delete_len, insert_len)) + for (int i = 0; i < delete_len; i++) + p[i] = ImStb::STB_TEXTEDIT_GETCHAR(state, first_diff + i); +} + +// As InputText() retain textual data and we currently provide a path for user to not retain it (via local variables) +// we need some form of hook to reapply data back to user buffer on deactivation frame. (#4714) +// It would be more desirable that we discourage users from taking advantage of the "user not retaining data" trick, +// but that more likely be attractive when we do have _NoLiveEdit flag available. +void ImGui::InputTextDeactivateHook(ImGuiID id) +{ + ImGuiContext& g = *GImGui; + ImGuiInputTextState* state = &g.InputTextState; + if (id == 0 || state->ID != id) + return; + g.InputTextDeactivatedState.ID = state->ID; + g.InputTextDeactivatedState.TextA.resize(state->CurLenA + 1); + memcpy(g.InputTextDeactivatedState.TextA.Data, state->TextA.Data ? state->TextA.Data : "", state->CurLenA + 1); +} + // Edit a string of text // - buf_size account for the zero-terminator, so a buf_size of 6 can hold "Hello" but not "Hello!". // This is so we can easily call InputText() on static arrays using ARRAYSIZE() and to match @@ -4057,7 +4183,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ ImGuiInputTextState* state = GetInputTextState(id); const bool input_requested_by_tabbing = (item_status_flags & ImGuiItemStatusFlags_FocusedByTabbing) != 0; - const bool input_requested_by_nav = (g.ActiveId != id) && ((g.NavActivateInputId == id) || (g.NavActivateId == id && g.NavInputSource == ImGuiInputSource_Keyboard)); + const bool input_requested_by_nav = (g.ActiveId != id) && ((g.NavActivateId == id) && ((g.NavActivateFlags & ImGuiActivateFlags_PreferInput) || (g.NavInputSource == ImGuiInputSource_Keyboard))); const bool user_clicked = hovered && io.MouseClicked[0]; const bool user_scroll_finish = is_multiline && state != NULL && g.ActiveId == 0 && g.ActiveIdPreviousFrame == GetWindowScrollbarID(draw_window, ImGuiAxis_Y); @@ -4067,7 +4193,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ float scroll_y = is_multiline ? draw_window->Scroll.y : FLT_MAX; - const bool init_changed_specs = (state != NULL && state->Stb.single_line != !is_multiline); + const bool init_changed_specs = (state != NULL && state->Stb.single_line != !is_multiline); // state != NULL means its our state. const bool init_make_active = (user_clicked || user_scroll_finish || input_requested_by_nav || input_requested_by_tabbing); const bool init_state = (init_make_active || user_scroll_active); if ((init_state && g.ActiveId != id) || init_changed_specs) @@ -4076,23 +4202,30 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ state = &g.InputTextState; state->CursorAnimReset(); + // Backup state of deactivating item so they'll have a chance to do a write to output buffer on the same frame they report IsItemDeactivatedAfterEdit (#4714) + InputTextDeactivateHook(state->ID); + // Take a copy of the initial buffer value (both in original UTF-8 format and converted to wchar) // From the moment we focused we are ignoring the content of 'buf' (unless we are in read-only mode) const int buf_len = (int)strlen(buf); state->InitialTextA.resize(buf_len + 1); // UTF-8. we use +1 to make sure that .Data is always pointing to at least an empty string. memcpy(state->InitialTextA.Data, buf, buf_len + 1); + // Preserve cursor position and undo/redo stack if we come back to same widget + // FIXME: Since we reworked this on 2022/06, may want to differenciate recycle_cursor vs recycle_undostate? + bool recycle_state = (state->ID == id && !init_changed_specs); + if (recycle_state && (state->CurLenA != buf_len || (state->TextAIsValid && strncmp(state->TextA.Data, buf, buf_len) != 0))) + recycle_state = false; + // Start edition const char* buf_end = NULL; + state->ID = id; state->TextW.resize(buf_size + 1); // wchar count <= UTF-8 count. we use +1 to make sure that .Data is always pointing to at least an empty string. state->TextA.resize(0); state->TextAIsValid = false; // TextA is not valid yet (we will display buf until then) state->CurLenW = ImTextStrFromUtf8(state->TextW.Data, buf_size, buf, NULL, &buf_end); state->CurLenA = (int)(buf_end - buf); // We can't get the result from ImStrncpy() above because it is not UTF-8 aware. Here we'll cut off malformed UTF-8. - // Preserve cursor position and undo/redo stack if we come back to same widget - // FIXME: For non-readonly widgets we might be able to require that TextAIsValid && TextA == buf ? (untested) and discard undo stack if user buffer has changed. - const bool recycle_state = (state->ID == id && !init_changed_specs); if (recycle_state) { // Recycle existing cursor/selection/undo stack but clamp position @@ -4101,7 +4234,6 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ } else { - state->ID = id; state->ScrollX = 0.0f; stb_textedit_initialize_state(&state->Stb, !is_multiline); } @@ -4120,30 +4252,33 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ state->Stb.insert_mode = 1; // stb field name is indeed incorrect (see #2863) } + const bool is_osx = io.ConfigMacOSXBehaviors; if (g.ActiveId != id && init_make_active) { IM_ASSERT(state && state->ID == id); SetActiveID(id, window); SetFocusID(id, window); FocusWindow(window); - - // Declare our inputs - IM_ASSERT(ImGuiNavInput_COUNT < 32); + } + if (g.ActiveId == id) + { + // Declare some inputs, the other are registered and polled via Shortcut() routing system. + if (user_clicked) + SetKeyOwner(ImGuiKey_MouseLeft, id); g.ActiveIdUsingNavDirMask |= (1 << ImGuiDir_Left) | (1 << ImGuiDir_Right); if (is_multiline || (flags & ImGuiInputTextFlags_CallbackHistory)) g.ActiveIdUsingNavDirMask |= (1 << ImGuiDir_Up) | (1 << ImGuiDir_Down); - g.ActiveIdUsingNavInputMask |= (1 << ImGuiNavInput_Cancel); - SetActiveIdUsingKey(ImGuiKey_Home); - SetActiveIdUsingKey(ImGuiKey_End); + SetKeyOwner(ImGuiKey_Home, id); + SetKeyOwner(ImGuiKey_End, id); if (is_multiline) { - SetActiveIdUsingKey(ImGuiKey_PageUp); - SetActiveIdUsingKey(ImGuiKey_PageDown); + SetKeyOwner(ImGuiKey_PageUp, id); + SetKeyOwner(ImGuiKey_PageDown, id); } + if (is_osx) + SetKeyOwner(ImGuiMod_Alt, id); if (flags & (ImGuiInputTextFlags_CallbackCompletion | ImGuiInputTextFlags_AllowTabInput)) // Disable keyboard tabbing out as we will use the \t character. - { - SetActiveIdUsingKey(ImGuiKey_Tab); - } + SetShortcutRouting(ImGuiKey_Tab, id); } // We have an edge case if ActiveId was set through another widget (e.g. widget being swapped), clear id immediately (don't wait until the end of the function) @@ -4155,10 +4290,10 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ clear_active_id = true; // Lock the decision of whether we are going to take the path displaying the cursor or selection - const bool render_cursor = (g.ActiveId == id) || (state && user_scroll_active); + bool render_cursor = (g.ActiveId == id) || (state && user_scroll_active); bool render_selection = state && (state->HasSelection() || select_all) && (RENDER_SELECTION_WHEN_INACTIVE || render_cursor); bool value_changed = false; - bool enter_pressed = false; + bool validated = false; // When read-only we always use the live data passed to the function // FIXME-OPT: Because our selection/cursor code currently needs the wide text we need to convert it when active, which is not ideal :( @@ -4205,13 +4340,11 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ // Although we are active we don't prevent mouse from hovering other elements unless we are interacting right now with the widget. // Down the line we should have a cleaner library-wide concept of Selected vs Active. g.ActiveIdAllowOverlap = !io.MouseDown[0]; - g.WantTextInputNextFrame = 1; // Edit in progress const float mouse_x = (io.MousePos.x - frame_bb.Min.x - style.FramePadding.x) + state->ScrollX; const float mouse_y = (is_multiline ? (io.MousePos.y - draw_window->DC.CursorPos.y) : (g.FontSize * 0.5f)); - const bool is_osx = io.ConfigMacOSXBehaviors; if (select_all) { state->SelectAll(); @@ -4254,10 +4387,12 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ } else if (io.MouseClicked[0] && !state->SelectedAllMouseLock) { - // FIXME: unselect on late click could be done release? if (hovered) { - stb_textedit_click(state, &state->Stb, mouse_x, mouse_y); + if (io.KeyShift) + stb_textedit_drag(state, &state->Stb, mouse_x, mouse_y); + else + stb_textedit_click(state, &state->Stb, mouse_x, mouse_y); state->CursorAnimReset(); } } @@ -4270,10 +4405,9 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ if (state->SelectedAllMouseLock && !io.MouseDown[0]) state->SelectedAllMouseLock = false; - // We except backends to emit a Tab key but some also emit a Tab character which we ignore (#2467, #1336) + // We expect backends to emit a Tab key but some also emit a Tab character which we ignore (#2467, #1336) // (For Tab and Enter: Win32/SFML/Allegro are sending both keys and chars, GLFW and SDL are only sending keys. For Space they all send all threes) - const bool ignore_char_inputs = (io.KeyCtrl && !io.KeyAlt) || (is_osx && io.KeySuper); - if ((flags & ImGuiInputTextFlags_AllowTabInput) && IsKeyPressed(ImGuiKey_Tab) && !ignore_char_inputs && !io.KeyShift && !is_readonly) + if ((flags & ImGuiInputTextFlags_AllowTabInput) && Shortcut(ImGuiKey_Tab, id) && !is_readonly) { unsigned int c = '\t'; // Insert TAB if (InputTextFilterCharacter(&c, flags, callback, callback_user_data, ImGuiInputSource_Keyboard)) @@ -4282,6 +4416,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ // Process regular text input (before we check for Return because using some IME will effectively send a Return?) // We ignore CTRL inputs, but need to allow ALT+CTRL as some keyboards (e.g. German) use AltGR (which _is_ Alt+Ctrl) to input certain characters. + const bool ignore_char_inputs = (io.KeyCtrl && !io.KeyAlt) || (is_osx && io.KeySuper); if (io.InputQueueCharacters.Size > 0) { if (!ignore_char_inputs && !is_readonly && !input_requested_by_nav) @@ -4301,7 +4436,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ } // Process other shortcuts/key-presses - bool cancel_edit = false; + bool revert_edit = false; if (g.ActiveId == id && !g.ActiveIdIsJustActivated && !clear_active_id) { IM_ASSERT(state != NULL); @@ -4310,25 +4445,26 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ state->Stb.row_count_per_page = row_count_per_page; const int k_mask = (io.KeyShift ? STB_TEXTEDIT_K_SHIFT : 0); - const bool is_osx = io.ConfigMacOSXBehaviors; - const bool is_osx_shift_shortcut = is_osx && (io.KeyMods == (ImGuiModFlags_Super | ImGuiModFlags_Shift)); const bool is_wordmove_key_down = is_osx ? io.KeyAlt : io.KeyCtrl; // OS X style: Text editing cursor movement using Alt instead of Ctrl const bool is_startend_key_down = is_osx && io.KeySuper && !io.KeyCtrl && !io.KeyAlt; // OS X style: Line/Text Start and End using Cmd+Arrows instead of Home/End - const bool is_ctrl_key_only = (io.KeyMods == ImGuiModFlags_Ctrl); - const bool is_shift_key_only = (io.KeyMods == ImGuiModFlags_Shift); - const bool is_shortcut_key = g.IO.ConfigMacOSXBehaviors ? (io.KeyMods == ImGuiModFlags_Super) : (io.KeyMods == ImGuiModFlags_Ctrl); - const bool is_cut = ((is_shortcut_key && IsKeyPressed(ImGuiKey_X)) || (is_shift_key_only && IsKeyPressed(ImGuiKey_Delete))) && !is_readonly && !is_password && (!is_multiline || state->HasSelection()); - const bool is_copy = ((is_shortcut_key && IsKeyPressed(ImGuiKey_C)) || (is_ctrl_key_only && IsKeyPressed(ImGuiKey_Insert))) && !is_password && (!is_multiline || state->HasSelection()); - const bool is_paste = ((is_shortcut_key && IsKeyPressed(ImGuiKey_V)) || (is_shift_key_only && IsKeyPressed(ImGuiKey_Insert))) && !is_readonly; - const bool is_undo = ((is_shortcut_key && IsKeyPressed(ImGuiKey_Z)) && !is_readonly && is_undoable); - const bool is_redo = ((is_shortcut_key && IsKeyPressed(ImGuiKey_Y)) || (is_osx_shift_shortcut && IsKeyPressed(ImGuiKey_Z))) && !is_readonly && is_undoable; + // Using Shortcut() with ImGuiInputFlags_RouteFocused (default policy) to allow routing operations for other code (e.g. calling window trying to use CTRL+A and CTRL+B: formet would be handled by InputText) + // Otherwise we could simply assume that we own the keys as we are active. + const ImGuiInputFlags f_repeat = ImGuiInputFlags_Repeat; + const bool is_cut = (Shortcut(ImGuiMod_Shortcut | ImGuiKey_X, id, f_repeat) || Shortcut(ImGuiMod_Shift | ImGuiKey_Delete, id, f_repeat)) && !is_readonly && !is_password && (!is_multiline || state->HasSelection()); + const bool is_copy = (Shortcut(ImGuiMod_Shortcut | ImGuiKey_C, id) || Shortcut(ImGuiMod_Ctrl | ImGuiKey_Insert, id)) && !is_password && (!is_multiline || state->HasSelection()); + const bool is_paste = (Shortcut(ImGuiMod_Shortcut | ImGuiKey_V, id, f_repeat) || Shortcut(ImGuiMod_Shift | ImGuiKey_Insert, id, f_repeat)) && !is_readonly; + const bool is_undo = (Shortcut(ImGuiMod_Shortcut | ImGuiKey_Z, id, f_repeat)) && !is_readonly && is_undoable; + const bool is_redo = (Shortcut(ImGuiMod_Shortcut | ImGuiKey_Y, id, f_repeat) || (is_osx && Shortcut(ImGuiMod_Shortcut | ImGuiMod_Shift | ImGuiKey_Z, id, f_repeat))) && !is_readonly && is_undoable; + const bool is_select_all = Shortcut(ImGuiMod_Shortcut | ImGuiKey_A, id); // We allow validate/cancel with Nav source (gamepad) to makes it easier to undo an accidental NavInput press with no keyboard wired, but otherwise it isn't very useful. - const bool is_validate_enter = IsKeyPressed(ImGuiKey_Enter) || IsKeyPressed(ImGuiKey_KeypadEnter); - const bool is_validate_nav = (IsNavInputTest(ImGuiNavInput_Activate, ImGuiNavReadMode_Pressed) && !IsKeyPressed(ImGuiKey_Space)) || IsNavInputTest(ImGuiNavInput_Input, ImGuiNavReadMode_Pressed); - const bool is_cancel = IsKeyPressed(ImGuiKey_Escape) || IsNavInputTest(ImGuiNavInput_Cancel, ImGuiNavReadMode_Pressed); + const bool nav_gamepad_active = (io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) != 0 && (io.BackendFlags & ImGuiBackendFlags_HasGamepad) != 0; + const bool is_enter_pressed = IsKeyPressed(ImGuiKey_Enter, true) || IsKeyPressed(ImGuiKey_KeypadEnter, true); + const bool is_gamepad_validate = nav_gamepad_active && (IsKeyPressed(ImGuiKey_NavGamepadActivate, false) || IsKeyPressed(ImGuiKey_NavGamepadInput, false)); + const bool is_cancel = Shortcut(ImGuiKey_Escape, id, f_repeat) || (nav_gamepad_active && Shortcut(ImGuiKey_NavGamepadCancel, id, f_repeat)); + // FIXME: Should use more Shortcut() and reduce IsKeyPressed()+SetKeyOwner(), but requires modifiers combination to be taken account of. if (IsKeyPressed(ImGuiKey_LeftArrow)) { state->OnKeyPressed((is_startend_key_down ? STB_TEXTEDIT_K_LINESTART : is_wordmove_key_down ? STB_TEXTEDIT_K_WORDLEFT : STB_TEXTEDIT_K_LEFT) | k_mask); } else if (IsKeyPressed(ImGuiKey_RightArrow)) { state->OnKeyPressed((is_startend_key_down ? STB_TEXTEDIT_K_LINEEND : is_wordmove_key_down ? STB_TEXTEDIT_K_WORDRIGHT : STB_TEXTEDIT_K_RIGHT) | k_mask); } else if (IsKeyPressed(ImGuiKey_UpArrow) && is_multiline) { if (io.KeyCtrl) SetScrollY(draw_window, ImMax(draw_window->Scroll.y - g.FontSize, 0.0f)); else state->OnKeyPressed((is_startend_key_down ? STB_TEXTEDIT_K_TEXTSTART : STB_TEXTEDIT_K_UP) | k_mask); } @@ -4337,7 +4473,16 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ else if (IsKeyPressed(ImGuiKey_PageDown) && is_multiline) { state->OnKeyPressed(STB_TEXTEDIT_K_PGDOWN | k_mask); scroll_y += row_count_per_page * g.FontSize; } else if (IsKeyPressed(ImGuiKey_Home)) { state->OnKeyPressed(io.KeyCtrl ? STB_TEXTEDIT_K_TEXTSTART | k_mask : STB_TEXTEDIT_K_LINESTART | k_mask); } else if (IsKeyPressed(ImGuiKey_End)) { state->OnKeyPressed(io.KeyCtrl ? STB_TEXTEDIT_K_TEXTEND | k_mask : STB_TEXTEDIT_K_LINEEND | k_mask); } - else if (IsKeyPressed(ImGuiKey_Delete) && !is_readonly && !is_cut) { state->OnKeyPressed(STB_TEXTEDIT_K_DELETE | k_mask); } + else if (IsKeyPressed(ImGuiKey_Delete) && !is_readonly && !is_cut) + { + if (!state->HasSelection()) + { + // OSX doesn't seem to have Super+Delete to delete until end-of-line, so we don't emulate that (as opposed to Super+Backspace) + if (is_wordmove_key_down) + state->OnKeyPressed(STB_TEXTEDIT_K_WORDRIGHT | STB_TEXTEDIT_K_SHIFT); + } + state->OnKeyPressed(STB_TEXTEDIT_K_DELETE | k_mask); + } else if (IsKeyPressed(ImGuiKey_Backspace) && !is_readonly) { if (!state->HasSelection()) @@ -4349,12 +4494,17 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ } state->OnKeyPressed(STB_TEXTEDIT_K_BACKSPACE | k_mask); } - else if (is_validate_enter) + else if (is_enter_pressed || is_gamepad_validate) { + // Determine if we turn Enter into a \n character bool ctrl_enter_for_new_line = (flags & ImGuiInputTextFlags_CtrlEnterForNewLine) != 0; - if (!is_multiline || (ctrl_enter_for_new_line && !io.KeyCtrl) || (!ctrl_enter_for_new_line && io.KeyCtrl)) + if (!is_multiline || is_gamepad_validate || (ctrl_enter_for_new_line && !io.KeyCtrl) || (!ctrl_enter_for_new_line && io.KeyCtrl)) { - enter_pressed = clear_active_id = true; + validated = true; + if (io.ConfigInputTextEnterKeepActive && !is_multiline) + state->SelectAll(); // No need to scroll + else + clear_active_id = true; } else if (!is_readonly) { @@ -4363,21 +4513,32 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ state->OnKeyPressed((int)c); } } - else if (is_validate_nav) - { - IM_ASSERT(!is_validate_enter); - enter_pressed = clear_active_id = true; - } else if (is_cancel) { - clear_active_id = cancel_edit = true; + if (flags & ImGuiInputTextFlags_EscapeClearsAll) + { + if (state->CurLenA > 0) + { + revert_edit = true; + } + else + { + render_cursor = render_selection = false; + clear_active_id = true; + } + } + else + { + clear_active_id = revert_edit = true; + render_cursor = render_selection = false; + } } else if (is_undo || is_redo) { state->OnKeyPressed(is_undo ? STB_TEXTEDIT_K_UNDO : STB_TEXTEDIT_K_REDO); state->ClearSelection(); } - else if (is_shortcut_key && IsKeyPressed(ImGuiKey_A)) + else if (is_select_all) { state->SelectAll(); state->CursorFollow = true; @@ -4411,12 +4572,10 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ const int clipboard_len = (int)strlen(clipboard); ImWchar* clipboard_filtered = (ImWchar*)IM_ALLOC((clipboard_len + 1) * sizeof(ImWchar)); int clipboard_filtered_len = 0; - for (const char* s = clipboard; *s; ) + for (const char* s = clipboard; *s != 0; ) { unsigned int c; s += ImTextCharFromUtf8(&c, s, NULL); - if (c == 0) - break; if (!InputTextFilterCharacter(&c, flags, callback, callback_user_data, ImGuiInputSource_Clipboard)) continue; clipboard_filtered[clipboard_filtered_len++] = (ImWchar)c; @@ -4441,14 +4600,23 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ if (g.ActiveId == id) { IM_ASSERT(state != NULL); - if (cancel_edit) + if (revert_edit && !is_readonly) { - // Restore initial value. Only return true if restoring to the initial value changes the current buffer contents. - if (!is_readonly && strcmp(buf, state->InitialTextA.Data) != 0) + if (flags & ImGuiInputTextFlags_EscapeClearsAll) { + // Clear input + apply_new_text = ""; + apply_new_text_length = 0; + STB_TEXTEDIT_CHARTYPE empty_string; + stb_textedit_replace(state, &state->Stb, &empty_string, 0); + } + else if (strcmp(buf, state->InitialTextA.Data) != 0) + { + // Restore initial value. Only return true if restoring to the initial value changes the current buffer contents. // Push records into the undo stack so we can CTRL+Z the revert operation itself apply_new_text = state->InitialTextA.Data; apply_new_text_length = state->InitialTextA.Size - 1; + value_changed = true; ImVector w_text; if (apply_new_text_length > 0) { @@ -4459,22 +4627,24 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ } } + // Apply ASCII value + if (!is_readonly) + { + state->TextAIsValid = true; + state->TextA.resize(state->TextW.Size * 4 + 1); + ImTextStrToUtf8(state->TextA.Data, state->TextA.Size, state->TextW.Data, NULL); + } + // When using 'ImGuiInputTextFlags_EnterReturnsTrue' as a special case we reapply the live buffer back to the input buffer before clearing ActiveId, even though strictly speaking it wasn't modified on this frame. // If we didn't do that, code like InputInt() with ImGuiInputTextFlags_EnterReturnsTrue would fail. // This also allows the user to use InputText() with ImGuiInputTextFlags_EnterReturnsTrue without maintaining any user-side storage (please note that if you use this property along ImGuiInputTextFlags_CallbackResize you can end up with your temporary string object unnecessarily allocating once a frame, either store your string data, either if you don't then don't use ImGuiInputTextFlags_CallbackResize). - bool apply_edit_back_to_user_buffer = !cancel_edit || (enter_pressed && (flags & ImGuiInputTextFlags_EnterReturnsTrue) != 0); + const bool apply_edit_back_to_user_buffer = !revert_edit || (validated && (flags & ImGuiInputTextFlags_EnterReturnsTrue) != 0); if (apply_edit_back_to_user_buffer) { // Apply new value immediately - copy modified buffer back // Note that as soon as the input box is active, the in-widget value gets priority over any underlying modification of the input buffer // FIXME: We actually always render 'buf' when calling DrawList->AddText, making the comment above incorrect. // FIXME-OPT: CPU waste to do this every time the widget is active, should mark dirty state from the stb_textedit callbacks. - if (!is_readonly) - { - state->TextAIsValid = true; - state->TextA.resize(state->TextW.Size * 4 + 1); - ImTextStrToUtf8(state->TextA.Data, state->TextA.Size, state->TextW.Data, NULL); - } // User callback if ((flags & (ImGuiInputTextFlags_CallbackCompletion | ImGuiInputTextFlags_CallbackHistory | ImGuiInputTextFlags_CallbackEdit | ImGuiInputTextFlags_CallbackAlways)) != 0) @@ -4484,7 +4654,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ // The reason we specify the usage semantic (Completion/History) is that Completion needs to disable keyboard TABBING at the moment. ImGuiInputTextFlags event_flag = 0; ImGuiKey event_key = ImGuiKey_None; - if ((flags & ImGuiInputTextFlags_CallbackCompletion) != 0 && IsKeyPressed(ImGuiKey_Tab)) + if ((flags & ImGuiInputTextFlags_CallbackCompletion) != 0 && Shortcut(ImGuiKey_Tab, id)) { event_flag = ImGuiInputTextFlags_CallbackCompletion; event_key = ImGuiKey_Tab; @@ -4511,7 +4681,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ if (event_flag) { ImGuiInputTextCallbackData callback_data; - memset(&callback_data, 0, sizeof(ImGuiInputTextCallbackData)); + callback_data.Ctx = &g; callback_data.EventFlag = event_flag; callback_data.Flags = flags; callback_data.UserData = callback_user_data; @@ -4543,9 +4713,11 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ if (callback_data.SelectionEnd != utf8_selection_end || buf_dirty) { state->Stb.select_end = (callback_data.SelectionEnd == callback_data.SelectionStart) ? state->Stb.select_start : ImTextCountCharsFromUtf8(callback_data.Buf, callback_data.Buf + callback_data.SelectionEnd); } if (buf_dirty) { + IM_ASSERT((flags & ImGuiInputTextFlags_ReadOnly) == 0); IM_ASSERT(callback_data.BufTextLen == (int)strlen(callback_data.Buf)); // You need to maintain BufTextLen if you change the text! + InputTextReconcileUndoStateAfterUserCallback(state, callback_data.Buf, callback_data.BufTextLen); // FIXME: Move the rest of this block inside function and rename to InputTextReconcileStateAfterUserCallback() ? if (callback_data.BufTextLen > backup_current_text_length && is_resizable) - state->TextW.resize(state->TextW.Size + (callback_data.BufTextLen - backup_current_text_length)); + state->TextW.resize(state->TextW.Size + (callback_data.BufTextLen - backup_current_text_length)); // Worse case scenario resize state->CurLenW = ImTextStrFromUtf8(state->TextW.Data, state->TextW.Size, callback_data.Buf, NULL); state->CurLenA = callback_data.BufTextLen; // Assume correct length and valid UTF-8 from user, saves us an extra strlen() state->CursorAnimReset(); @@ -4558,11 +4730,22 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ { apply_new_text = state->TextA.Data; apply_new_text_length = state->CurLenA; + value_changed = true; } } + } - // Clear temporary user storage - state->Flags = ImGuiInputTextFlags_None; + // Handle reapplying final data on deactivation (see InputTextDeactivateHook() for details) + if (g.InputTextDeactivatedState.ID == id) + { + if (g.ActiveId != id && IsItemDeactivatedAfterEdit() && !is_readonly) + { + apply_new_text = g.InputTextDeactivatedState.TextA.Data; + apply_new_text_length = g.InputTextDeactivatedState.TextA.Size - 1; + value_changed |= (strcmp(g.InputTextDeactivatedState.TextA.Data, buf) != 0); + //IMGUI_DEBUG_LOG("InputText(): apply Deactivated data for 0x%08X: \"%.*s\".\n", id, apply_new_text_length, apply_new_text); + } + g.InputTextDeactivatedState.ID = 0; } // Copy result to user buffer. This can currently only happen when (g.ActiveId == id) @@ -4577,6 +4760,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ if (is_resizable) { ImGuiInputTextCallbackData callback_data; + callback_data.Ctx = &g; callback_data.EventFlag = ImGuiInputTextFlags_CallbackResize; callback_data.Flags = flags; callback_data.Buf = buf; @@ -4589,16 +4773,16 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ apply_new_text_length = ImMin(callback_data.BufTextLen, buf_size - 1); IM_ASSERT(apply_new_text_length <= buf_size); } - //IMGUI_DEBUG_LOG("InputText(\"%s\"): apply_new_text length %d\n", label, apply_new_text_length); + //IMGUI_DEBUG_PRINT("InputText(\"%s\"): apply_new_text length %d\n", label, apply_new_text_length); // If the underlying buffer resize was denied or not carried to the next frame, apply_new_text_length+1 may be >= buf_size. ImStrncpy(buf, apply_new_text, ImMin(apply_new_text_length + 1, buf_size)); - value_changed = true; } else { printf("invalid buffer!\n"); if (is_resizable) { ImGuiInputTextCallbackData callback_data; + callback_data.Ctx = &g; callback_data.EventFlag = ImGuiInputTextFlags_CallbackResize; callback_data.Flags = flags; callback_data.Buf = buf; @@ -4611,17 +4795,19 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ apply_new_text_length = 0; IM_ASSERT(apply_new_text_length <= buf_size); } - //IMGUI_DEBUG_LOG("InputText(\"%s\"): apply_new_text length %d\n", label, apply_new_text_length); + //IMGUI_DEBUG_PRINT("InputText(\"%s\"): apply_new_text length %d\n", label, apply_new_text_length); // clear the buffer ImStrncpy(buf, "", 1); - value_changed = true; } } // Release active ID at the end of the function (so e.g. pressing Return still does a final application of the value) - if (clear_active_id && g.ActiveId == id) + // Otherwise request text input ahead for next frame. + if (g.ActiveId == id && clear_active_id) ClearActiveID(); + else if (g.ActiveId == id) + g.WantTextInputNextFrame = 1; // Render frame if (!is_multiline) @@ -4701,11 +4887,11 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ searches_result_line_no[1] = line_count; // Calculate 2d position by finding the beginning of the line and measuring distance - cursor_offset.x = InputTextCalcTextSizeW(ImStrbolW(searches_input_ptr[0], text_begin), searches_input_ptr[0]).x; + cursor_offset.x = InputTextCalcTextSizeW(&g, ImStrbolW(searches_input_ptr[0], text_begin), searches_input_ptr[0]).x; cursor_offset.y = searches_result_line_no[0] * g.FontSize; if (searches_result_line_no[1] >= 0) { - select_start_offset.x = InputTextCalcTextSizeW(ImStrbolW(searches_input_ptr[1], text_begin), searches_input_ptr[1]).x; + select_start_offset.x = InputTextCalcTextSizeW(&g, ImStrbolW(searches_input_ptr[1], text_begin), searches_input_ptr[1]).x; select_start_offset.y = searches_result_line_no[1] * g.FontSize; } @@ -4774,7 +4960,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ } else { - ImVec2 rect_size = InputTextCalcTextSizeW(p, text_selected_end, &p, NULL, true); + ImVec2 rect_size = InputTextCalcTextSizeW(&g, p, text_selected_end, &p, NULL, true); if (rect_size.x <= 0.0f) rect_size.x = IM_FLOOR(g.Font->GetCharAdvance((ImWchar)' ') * 0.50f); // So we can see selected empty lines ImRect rect(rect_pos + ImVec2(0.0f, bg_offy_up - g.FontSize), rect_pos + ImVec2(rect_size.x, bg_offy_dn)); rect.ClipWith(clip_rect); @@ -4867,13 +5053,49 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ if (value_changed && !(flags & ImGuiInputTextFlags_NoMarkEdited)) MarkItemEdited(id); - IMGUI_TEST_ENGINE_ITEM_INFO(id, label, g.LastItemData.StatusFlags); + IMGUI_TEST_ENGINE_ITEM_INFO(id, label, g.LastItemData.StatusFlags | ImGuiItemStatusFlags_Inputable); if ((flags & ImGuiInputTextFlags_EnterReturnsTrue) != 0) - return enter_pressed; + return validated; else return value_changed; } +void ImGui::DebugNodeInputTextState(ImGuiInputTextState* state) +{ +#ifndef IMGUI_DISABLE_DEBUG_TOOLS + ImGuiContext& g = *GImGui; + ImStb::STB_TexteditState* stb_state = &state->Stb; + ImStb::StbUndoState* undo_state = &stb_state->undostate; + Text("ID: 0x%08X, ActiveID: 0x%08X", state->ID, g.ActiveId); + DebugLocateItemOnHover(state->ID); + Text("CurLenW: %d, CurLenA: %d, Cursor: %d, Selection: %d..%d", state->CurLenW, state->CurLenA, stb_state->cursor, stb_state->select_start, stb_state->select_end); + Text("has_preferred_x: %d (%.2f)", stb_state->has_preferred_x, stb_state->preferred_x); + Text("undo_point: %d, redo_point: %d, undo_char_point: %d, redo_char_point: %d", undo_state->undo_point, undo_state->redo_point, undo_state->undo_char_point, undo_state->redo_char_point); + if (BeginChild("undopoints", ImVec2(0.0f, GetTextLineHeight() * 15), true)) // Visualize undo state + { + PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0)); + for (int n = 0; n < STB_TEXTEDIT_UNDOSTATECOUNT; n++) + { + ImStb::StbUndoRecord* undo_rec = &undo_state->undo_rec[n]; + const char undo_rec_type = (n < undo_state->undo_point) ? 'u' : (n >= undo_state->redo_point) ? 'r' : ' '; + if (undo_rec_type == ' ') + BeginDisabled(); + char buf[64] = ""; + if (undo_rec_type != ' ' && undo_rec->char_storage != -1) + ImTextStrToUtf8(buf, IM_ARRAYSIZE(buf), undo_state->undo_char + undo_rec->char_storage, undo_state->undo_char + undo_rec->char_storage + undo_rec->insert_length); + Text("%c [%02d] where %03d, insert %03d, delete %03d, char_storage %03d \"%s\"", + undo_rec_type, n, undo_rec->where, undo_rec->insert_length, undo_rec->delete_length, undo_rec->char_storage, buf); + if (undo_rec_type == ' ') + EndDisabled(); + } + PopStyleVar(); + } + EndChild(); +#else + IM_UNUSED(state); +#endif +} + //------------------------------------------------------------------------- // [SECTION] Widgets: ColorEdit, ColorPicker, ColorButton, etc. //------------------------------------------------------------------------- @@ -4894,28 +5116,32 @@ bool ImGui::ColorEdit3(const char* label, float col[3], ImGuiColorEditFlags flag return ColorEdit4(label, col, flags | ImGuiColorEditFlags_NoAlpha); } +static void ColorEditRestoreH(const float* col, float* H) +{ + ImGuiContext& g = *GImGui; + IM_ASSERT(g.ColorEditCurrentID != 0); + if (g.ColorEditSavedID != g.ColorEditCurrentID || g.ColorEditSavedColor != ImGui::ColorConvertFloat4ToU32(ImVec4(col[0], col[1], col[2], 0))) + return; + *H = g.ColorEditSavedHue; +} + // ColorEdit supports RGB and HSV inputs. In case of RGB input resulting color may have undefined hue and/or saturation. // Since widget displays both RGB and HSV values we must preserve hue and saturation to prevent these values resetting. static void ColorEditRestoreHS(const float* col, float* H, float* S, float* V) { - // This check is optional. Suppose we have two color widgets side by side, both widgets display different colors, but both colors have hue and/or saturation undefined. - // With color check: hue/saturation is preserved in one widget. Editing color in one widget would reset hue/saturation in another one. - // Without color check: common hue/saturation would be displayed in all widgets that have hue/saturation undefined. - // g.ColorEditLastColor is stored as ImU32 RGB value: this essentially gives us color equality check with reduced precision. - // Tiny external color changes would not be detected and this check would still pass. This is OK, since we only restore hue/saturation _only_ if they are undefined, - // therefore this change flipping hue/saturation from undefined to a very tiny value would still be represented in color picker. ImGuiContext& g = *GImGui; - if (g.ColorEditLastColor != ImGui::ColorConvertFloat4ToU32(ImVec4(col[0], col[1], col[2], 0))) + IM_ASSERT(g.ColorEditCurrentID != 0); + if (g.ColorEditSavedID != g.ColorEditCurrentID || g.ColorEditSavedColor != ImGui::ColorConvertFloat4ToU32(ImVec4(col[0], col[1], col[2], 0))) return; // When S == 0, H is undefined. // When H == 1 it wraps around to 0. - if (*S == 0.0f || (*H == 0.0f && g.ColorEditLastHue == 1)) - *H = g.ColorEditLastHue; + if (*S == 0.0f || (*H == 0.0f && g.ColorEditSavedHue == 1)) + *H = g.ColorEditSavedHue; // When V == 0, S is undefined. if (*V == 0.0f) - *S = g.ColorEditLastSat; + *S = g.ColorEditSavedSat; } // Edit colors components (each component in 0.0f..1.0f range). @@ -4938,6 +5164,9 @@ bool ImGui::ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flag BeginGroup(); PushID(label); + const bool set_current_color_edit_id = (g.ColorEditCurrentID == 0); + if (set_current_color_edit_id) + g.ColorEditCurrentID = window->IDStack.back(); // If we're not showing any slider there's no point in doing any HSV conversions const ImGuiColorEditFlags flags_untouched = flags; @@ -4971,7 +5200,7 @@ bool ImGui::ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flag ColorConvertHSVtoRGB(f[0], f[1], f[2], f[0], f[1], f[2]); else if ((flags & ImGuiColorEditFlags_InputRGB) && (flags & ImGuiColorEditFlags_DisplayHSV)) { - // Hue is lost when converting from greyscale rgb (saturation=0). Restore it. + // Hue is lost when converting from grayscale rgb (saturation=0). Restore it. ColorConvertRGBtoHSV(f[0], f[1], f[2], f[0], f[1], f[2]); ColorEditRestoreHS(col, &f[0], &f[1], &f[2]); } @@ -5076,23 +5305,29 @@ bool ImGui::ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flag if (BeginPopup("picker")) { - picker_active_window = g.CurrentWindow; - if (label != label_display_end) + if (g.CurrentWindow->BeginCount == 1) { - TextEx(label, label_display_end); - Spacing(); + picker_active_window = g.CurrentWindow; + if (label != label_display_end) + { + TextEx(label, label_display_end); + Spacing(); + } + ImGuiColorEditFlags picker_flags_to_forward = ImGuiColorEditFlags_DataTypeMask_ | ImGuiColorEditFlags_PickerMask_ | ImGuiColorEditFlags_InputMask_ | ImGuiColorEditFlags_HDR | ImGuiColorEditFlags_NoAlpha | ImGuiColorEditFlags_AlphaBar; + ImGuiColorEditFlags picker_flags = (flags_untouched & picker_flags_to_forward) | ImGuiColorEditFlags_DisplayMask_ | ImGuiColorEditFlags_NoLabel | ImGuiColorEditFlags_AlphaPreviewHalf; + SetNextItemWidth(square_sz * 12.0f); // Use 256 + bar sizes? + value_changed |= ColorPicker4("##picker", col, picker_flags, &g.ColorPickerRef.x); } - ImGuiColorEditFlags picker_flags_to_forward = ImGuiColorEditFlags_DataTypeMask_ | ImGuiColorEditFlags_PickerMask_ | ImGuiColorEditFlags_InputMask_ | ImGuiColorEditFlags_HDR | ImGuiColorEditFlags_NoAlpha | ImGuiColorEditFlags_AlphaBar; - ImGuiColorEditFlags picker_flags = (flags_untouched & picker_flags_to_forward) | ImGuiColorEditFlags_DisplayMask_ | ImGuiColorEditFlags_NoLabel | ImGuiColorEditFlags_AlphaPreviewHalf; - SetNextItemWidth(square_sz * 12.0f); // Use 256 + bar sizes? - value_changed |= ColorPicker4("##picker", col, picker_flags, &g.ColorPickerRef.x); EndPopup(); } } if (label != label_display_end && !(flags & ImGuiColorEditFlags_NoLabel)) { + // Position not necessarily next to last submitted button (e.g. if style.ColorButtonPosition == ImGuiDir_Left), + // but we need to use SameLine() to setup baseline correctly. Might want to refactor SameLine() to simplify this. SameLine(0.0f, style.ItemInnerSpacing.x); + window->DC.CursorPos.x = pos.x + ((flags & ImGuiColorEditFlags_NoInputs) ? w_button : w_full + style.ItemInnerSpacing.x); TextEx(label, label_display_end); } @@ -5104,10 +5339,11 @@ bool ImGui::ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flag f[n] = i[n] / 255.0f; if ((flags & ImGuiColorEditFlags_DisplayHSV) && (flags & ImGuiColorEditFlags_InputRGB)) { - g.ColorEditLastHue = f[0]; - g.ColorEditLastSat = f[1]; + g.ColorEditSavedHue = f[0]; + g.ColorEditSavedSat = f[1]; ColorConvertHSVtoRGB(f[0], f[1], f[2], f[0], f[1], f[2]); - g.ColorEditLastColor = ColorConvertFloat4ToU32(ImVec4(f[0], f[1], f[2], 0)); + g.ColorEditSavedID = g.ColorEditCurrentID; + g.ColorEditSavedColor = ColorConvertFloat4ToU32(ImVec4(f[0], f[1], f[2], 0)); } if ((flags & ImGuiColorEditFlags_DisplayRGB) && (flags & ImGuiColorEditFlags_InputHSV)) ColorConvertRGBtoHSV(f[0], f[1], f[2], f[0], f[1], f[2]); @@ -5119,6 +5355,8 @@ bool ImGui::ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flag col[3] = f[3]; } + if (set_current_color_edit_id) + g.ColorEditCurrentID = 0; PopID(); EndGroup(); @@ -5129,7 +5367,7 @@ bool ImGui::ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flag bool accepted_drag_drop = false; if (const ImGuiPayload* payload = AcceptDragDropPayload(IMGUI_PAYLOAD_TYPE_COLOR_3F)) { - memcpy((float*)col, payload->Data, sizeof(float) * 3); // Preserve alpha if any //-V512 + memcpy((float*)col, payload->Data, sizeof(float) * 3); // Preserve alpha if any //-V512 //-V1086 value_changed = accepted_drag_drop = true; } if (const ImGuiPayload* payload = AcceptDragDropPayload(IMGUI_PAYLOAD_TYPE_COLOR_4F)) @@ -5148,7 +5386,7 @@ bool ImGui::ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flag if (picker_active_window && g.ActiveId != 0 && g.ActiveIdWindow == picker_active_window) g.LastItemData.ID = g.ActiveId; - if (value_changed) + if (value_changed && g.LastItemData.ID != 0) // In case of ID collision, the second EndGroup() won't catch g.ActiveId MarkItemEdited(g.LastItemData.ID); return value_changed; @@ -5192,6 +5430,9 @@ bool ImGui::ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags fl g.NextItemData.ClearFlags(); PushID(label); + const bool set_current_color_edit_id = (g.ColorEditCurrentID == 0); + if (set_current_color_edit_id) + g.ColorEditCurrentID = window->IDStack.back(); BeginGroup(); if (!(flags & ImGuiColorEditFlags_NoSidePreview)) @@ -5240,7 +5481,7 @@ bool ImGui::ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags fl float R = col[0], G = col[1], B = col[2]; if (flags & ImGuiColorEditFlags_InputRGB) { - // Hue is lost when converting from greyscale rgb (saturation=0). Restore it. + // Hue is lost when converting from grayscale rgb (saturation=0). Restore it. ColorConvertRGBtoHSV(R, G, B, H, S, V); ColorEditRestoreHS(col, &H, &S, &V); } @@ -5295,10 +5536,7 @@ bool ImGui::ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags fl { S = ImSaturate((io.MousePos.x - picker_pos.x) / (sv_picker_size - 1)); V = 1.0f - ImSaturate((io.MousePos.y - picker_pos.y) / (sv_picker_size - 1)); - - // Greatly reduces hue jitter and reset to 0 when hue == 255 and color is rapidly modified using SV square. - if (g.ColorEditLastColor == ColorConvertFloat4ToU32(ImVec4(col[0], col[1], col[2], 0))) - H = g.ColorEditLastHue; + ColorEditRestoreH(col, &H); // Greatly reduces hue jitter and reset to 0 when hue == 255 and color is rapidly modified using SV square. value_changed = value_changed_sv = true; } if (!(flags & ImGuiColorEditFlags_NoOptions)) @@ -5373,9 +5611,10 @@ bool ImGui::ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags fl if (flags & ImGuiColorEditFlags_InputRGB) { ColorConvertHSVtoRGB(H, S, V, col[0], col[1], col[2]); - g.ColorEditLastHue = H; - g.ColorEditLastSat = S; - g.ColorEditLastColor = ColorConvertFloat4ToU32(ImVec4(col[0], col[1], col[2], 0)); + g.ColorEditSavedHue = H; + g.ColorEditSavedSat = S; + g.ColorEditSavedID = g.ColorEditCurrentID; + g.ColorEditSavedColor = ColorConvertFloat4ToU32(ImVec4(col[0], col[1], col[2], 0)); } else if (flags & ImGuiColorEditFlags_InputHSV) { @@ -5477,7 +5716,7 @@ bool ImGui::ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags fl float sin_hue_angle = ImSin(H * 2.0f * IM_PI); ImVec2 hue_cursor_pos(wheel_center.x + cos_hue_angle * (wheel_r_inner + wheel_r_outer) * 0.5f, wheel_center.y + sin_hue_angle * (wheel_r_inner + wheel_r_outer) * 0.5f); float hue_cursor_rad = value_changed_h ? wheel_thickness * 0.65f : wheel_thickness * 0.55f; - int hue_cursor_segments = ImClamp((int)(hue_cursor_rad / 1.4f), 9, 32); + int hue_cursor_segments = draw_list->_CalcCircleAutoSegmentCount(hue_cursor_rad); // Lock segment count so the +1 one matches others. draw_list->AddCircleFilled(hue_cursor_pos, hue_cursor_rad, hue_color32, hue_cursor_segments); draw_list->AddCircle(hue_cursor_pos, hue_cursor_rad + 1, col_midgrey, hue_cursor_segments); draw_list->AddCircle(hue_cursor_pos, hue_cursor_rad, col_white, hue_cursor_segments); @@ -5487,13 +5726,10 @@ bool ImGui::ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags fl ImVec2 trb = wheel_center + ImRotate(triangle_pb, cos_hue_angle, sin_hue_angle); ImVec2 trc = wheel_center + ImRotate(triangle_pc, cos_hue_angle, sin_hue_angle); ImVec2 uv_white = GetFontTexUvWhitePixel(); - draw_list->PrimReserve(6, 6); + draw_list->PrimReserve(3, 3); draw_list->PrimVtx(tra, uv_white, hue_color32); - draw_list->PrimVtx(trb, uv_white, hue_color32); - draw_list->PrimVtx(trc, uv_white, col_white); - draw_list->PrimVtx(tra, uv_white, 0); draw_list->PrimVtx(trb, uv_white, col_black); - draw_list->PrimVtx(trc, uv_white, 0); + draw_list->PrimVtx(trc, uv_white, col_white); draw_list->AddTriangle(tra, trb, trc, col_midgrey, 1.5f); sv_cursor_pos = ImLerp(ImLerp(trc, tra, ImSaturate(S)), trb, ImSaturate(1 - V)); } @@ -5516,9 +5752,10 @@ bool ImGui::ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags fl // Render cursor/preview circle (clamp S/V within 0..1 range because floating points colors may lead HSV values to be out of range) float sv_cursor_rad = value_changed_sv ? 10.0f : 6.0f; - draw_list->AddCircleFilled(sv_cursor_pos, sv_cursor_rad, user_col32_striped_of_alpha, 12); - draw_list->AddCircle(sv_cursor_pos, sv_cursor_rad + 1, col_midgrey, 12); - draw_list->AddCircle(sv_cursor_pos, sv_cursor_rad, col_white, 12); + int sv_cursor_segments = draw_list->_CalcCircleAutoSegmentCount(sv_cursor_rad); // Lock segment count so the +1 one matches others. + draw_list->AddCircleFilled(sv_cursor_pos, sv_cursor_rad, user_col32_striped_of_alpha, sv_cursor_segments); + draw_list->AddCircle(sv_cursor_pos, sv_cursor_rad + 1, col_midgrey, sv_cursor_segments); + draw_list->AddCircle(sv_cursor_pos, sv_cursor_rad, col_white, sv_cursor_segments); // Render alpha bar if (alpha_bar) @@ -5536,9 +5773,11 @@ bool ImGui::ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags fl if (value_changed && memcmp(backup_initial_col, col, components * sizeof(float)) == 0) value_changed = false; - if (value_changed) + if (value_changed && g.LastItemData.ID != 0) // In case of ID collision, the second EndGroup() won't catch g.ActiveId MarkItemEdited(g.LastItemData.ID); + if (set_current_color_edit_id) + g.ColorEditCurrentID = 0; PopID(); return value_changed; @@ -5652,7 +5891,8 @@ void ImGui::ColorTooltip(const char* text, const float* col, ImGuiColorEditFlags { ImGuiContext& g = *GImGui; - BeginTooltipEx(ImGuiTooltipFlags_OverridePreviousTooltip, ImGuiWindowFlags_None); + if (!BeginTooltipEx(ImGuiTooltipFlags_OverridePreviousTooltip, ImGuiWindowFlags_None)) + return; const char* text_end = text ? FindRenderedTextEnd(text, NULL) : text; if (text_end > text) { @@ -5855,9 +6095,9 @@ bool ImGui::TreeNodeExV(const char* str_id, ImGuiTreeNodeFlags flags, const char if (window->SkipItems) return false; - ImGuiContext& g = *GImGui; - const char* label_end = g.TempBuffer + ImFormatStringV(g.TempBuffer, IM_ARRAYSIZE(g.TempBuffer), fmt, args); - return TreeNodeBehavior(window->GetID(str_id), flags, g.TempBuffer, label_end); + const char* label, *label_end; + ImFormatStringToTempBufferV(&label, &label_end, fmt, args); + return TreeNodeBehavior(window->GetID(str_id), flags, label, label_end); } bool ImGui::TreeNodeExV(const void* ptr_id, ImGuiTreeNodeFlags flags, const char* fmt, va_list args) @@ -5866,12 +6106,19 @@ bool ImGui::TreeNodeExV(const void* ptr_id, ImGuiTreeNodeFlags flags, const char if (window->SkipItems) return false; - ImGuiContext& g = *GImGui; - const char* label_end = g.TempBuffer + ImFormatStringV(g.TempBuffer, IM_ARRAYSIZE(g.TempBuffer), fmt, args); - return TreeNodeBehavior(window->GetID(ptr_id), flags, g.TempBuffer, label_end); + const char* label, *label_end; + ImFormatStringToTempBufferV(&label, &label_end, fmt, args); + return TreeNodeBehavior(window->GetID(ptr_id), flags, label, label_end); } -bool ImGui::TreeNodeBehaviorIsOpen(ImGuiID id, ImGuiTreeNodeFlags flags) +void ImGui::TreeNodeSetOpen(ImGuiID id, bool open) +{ + ImGuiContext& g = *GImGui; + ImGuiStorage* storage = g.CurrentWindow->DC.StateStorage; + storage->SetInt(id, open ? 1 : 0); +} + +bool ImGui::TreeNodeUpdateNextOpen(ImGuiID id, ImGuiTreeNodeFlags flags) { if (flags & ImGuiTreeNodeFlags_Leaf) return true; @@ -5887,7 +6134,7 @@ bool ImGui::TreeNodeBehaviorIsOpen(ImGuiID id, ImGuiTreeNodeFlags flags) if (g.NextItemData.OpenCond & ImGuiCond_Always) { is_open = g.NextItemData.OpenVal; - storage->SetInt(id, is_open); + TreeNodeSetOpen(id, is_open); } else { @@ -5896,7 +6143,7 @@ bool ImGui::TreeNodeBehaviorIsOpen(ImGuiID id, ImGuiTreeNodeFlags flags) if (stored_value == -1) { is_open = g.NextItemData.OpenVal; - storage->SetInt(id, is_open); + TreeNodeSetOpen(id, is_open); } else { @@ -5962,7 +6209,7 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l // For this purpose we essentially compare if g.NavIdIsAlive went from 0 to 1 between TreeNode() and TreePop(). // This is currently only support 32 level deep and we are fine with (1 << Depth) overflowing into a zero. const bool is_leaf = (flags & ImGuiTreeNodeFlags_Leaf) != 0; - bool is_open = TreeNodeBehaviorIsOpen(id, flags); + bool is_open = TreeNodeUpdateNextOpen(id, flags); if (is_open && !g.NavIdIsAlive && (flags & ImGuiTreeNodeFlags_NavLeftJumpsBackHere) && !(flags & ImGuiTreeNodeFlags_NoTreePushOnOpen)) window->DC.TreeJumpToParentOnPopMask |= (1 << window->DC.TreeDepth); @@ -6036,11 +6283,13 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l if (g.NavId == id && g.NavMoveDir == ImGuiDir_Left && is_open) { toggled = true; + NavClearPreferredPosForAxis(ImGuiAxis_X); NavMoveRequestCancel(); } if (g.NavId == id && g.NavMoveDir == ImGuiDir_Right && !is_open) // If there's something upcoming on the line we may want to give it the priority? { toggled = true; + NavClearPreferredPosForAxis(ImGuiAxis_X); NavMoveRequestCancel(); } @@ -6305,6 +6554,7 @@ bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags fl // We use NoHoldingActiveID on menus so user can click and _hold_ on a menu then drag to browse child entries ImGuiButtonFlags button_flags = 0; if (flags & ImGuiSelectableFlags_NoHoldingActiveID) { button_flags |= ImGuiButtonFlags_NoHoldingActiveId; } + if (flags & ImGuiSelectableFlags_NoSetKeyOwner) { button_flags |= ImGuiButtonFlags_NoSetKeyOwner; } if (flags & ImGuiSelectableFlags_SelectOnClick) { button_flags |= ImGuiButtonFlags_PressedOnClick; } if (flags & ImGuiSelectableFlags_SelectOnRelease) { button_flags |= ImGuiButtonFlags_PressedOnRelease; } if (flags & ImGuiSelectableFlags_AllowDoubleClick) { button_flags |= ImGuiButtonFlags_PressedOnClickRelease | ImGuiButtonFlags_PressedOnDoubleClick; } @@ -6321,7 +6571,7 @@ bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags fl // - (1) it would require focus scope to be set, need exposing PushFocusScope() or equivalent (e.g. BeginSelection() calling PushFocusScope()) // - (2) usage will fail with clipped items // The multi-select API aim to fix those issues, e.g. may be replaced with a BeginSelection() API. - if ((flags & ImGuiSelectableFlags_SelectOnNav) && g.NavJustMovedToId != 0 && g.NavJustMovedToFocusScopeId == window->DC.NavFocusScopeIdCurrent) + if ((flags & ImGuiSelectableFlags_SelectOnNav) && g.NavJustMovedToId != 0 && g.NavJustMovedToFocusScopeId == g.CurrentFocusScopeId) if (g.NavJustMovedToId == id) selected = pressed = true; @@ -6330,7 +6580,7 @@ bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags fl { if (!g.NavDisableMouseHover && g.NavWindow == window && g.NavLayer == window->DC.NavLayerCurrent) { - SetNavID(id, window->DC.NavLayerCurrent, window->DC.NavFocusScopeIdCurrent, WindowRectAbsToRel(window, bb)); // (bb == NavRect) + SetNavID(id, window->DC.NavLayerCurrent, g.CurrentFocusScopeId, WindowRectAbsToRel(window, bb)); // (bb == NavRect) g.NavDisableHighlight = true; } } @@ -6345,8 +6595,6 @@ bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags fl g.LastItemData.StatusFlags |= ImGuiItemStatusFlags_ToggledSelection; // Render - if (held && (flags & ImGuiSelectableFlags_DrawHoveredWhenHeld)) - hovered = true; if ((hovered && !(g.IO.ConfigFlags&ImGuiConfigFlags_NoHoverColors)) || selected) { const ImU32 col = GetColorU32((held && hovered) ? ImGuiCol_HeaderActive : (hovered && !(g.IO.ConfigFlags&ImGuiConfigFlags_NoHoverColors)) ? ImGuiCol_HeaderHovered : ImGuiCol_Header); @@ -6431,20 +6679,6 @@ bool ImGui::BeginListBox(const char* label, const ImVec2& size_arg) return true; } -#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS -// OBSOLETED in 1.81 (from February 2021) -bool ImGui::ListBoxHeader(const char* label, int items_count, int height_in_items) -{ - // If height_in_items == -1, default height is maximum 7. - ImGuiContext& g = *GImGui; - float height_in_items_f = (height_in_items < 0 ? ImMin(items_count, 7) : height_in_items) + 0.25f; - ImVec2 size; - size.x = 0.0f; - size.y = GetTextLineHeightWithSpacing() * height_in_items_f + g.Style.FramePadding.y * 2.0f; - return BeginListBox(label, size); -} -#endif - void ImGui::EndListBox() { ImGuiContext& g = *GImGui; @@ -6521,7 +6755,7 @@ bool ImGui::ListBox(const char* label, int* current_item, bool (*items_getter)(v // - others https://github.com/ocornut/imgui/wiki/Useful-Extensions //------------------------------------------------------------------------- -int ImGui::PlotEx(ImGuiPlotType plot_type, const char* label, float (*values_getter)(void* data, int idx), void* data, int values_count, int values_offset, const char* overlay_text, float scale_min, float scale_max, ImVec2 frame_size) +int ImGui::PlotEx(ImGuiPlotType plot_type, const char* label, float (*values_getter)(void* data, int idx), void* data, int values_count, int values_offset, const char* overlay_text, float scale_min, float scale_max, const ImVec2& size_arg) { ImGuiContext& g = *GImGui; ImGuiWindow* window = GetCurrentWindow(); @@ -6532,10 +6766,7 @@ int ImGui::PlotEx(ImGuiPlotType plot_type, const char* label, float (*values_get const ImGuiID id = window->GetID(label); const ImVec2 label_size = CalcTextSize(label, NULL, true); - if (frame_size.x == 0.0f) - frame_size.x = CalcItemWidth(); - if (frame_size.y == 0.0f) - frame_size.y = label_size.y + (style.FramePadding.y * 2); + const ImVec2 frame_size = CalcItemSize(size_arg, CalcItemWidth(), label_size.y + style.FramePadding.y * 2.0f); const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + frame_size); const ImRect inner_bb(frame_bb.Min + style.FramePadding, frame_bb.Max - style.FramePadding); @@ -6821,7 +7052,7 @@ void ImGui::EndMenuBar() // To do so we claim focus back, restore NavId and then process the movement request for yet another frame. // This involve a one-frame delay which isn't very problematic in this situation. We could remove it by scoring in advance for multiple window (probably not worth bothering) const ImGuiNavLayer layer = ImGuiNavLayer_Menu; - IM_ASSERT(window->DC.NavLayersActiveMaskNext & (1 << layer)); // Sanity check + IM_ASSERT(window->DC.NavLayersActiveMaskNext & (1 << layer)); // Sanity check (FIXME: Seems unnecessary) FocusWindow(window); SetNavID(window->NavLastIds[layer], layer, 0, window->NavRectRel[layer]); g.NavDisableHighlight = true; // Hide highlight for the current frame so we don't see the intermediary selection. @@ -6915,7 +7146,7 @@ void ImGui::EndMainMenuBar() // FIXME: With this strategy we won't be able to restore a NULL focus. ImGuiContext& g = *GImGui; if (g.CurrentWindow == g.NavWindow && g.NavLayer == ImGuiNavLayer_Main && !g.NavAnyRequest) - FocusTopMostWindowUnderOne(g.NavWindow, NULL); + FocusTopMostWindowUnderOne(g.NavWindow, NULL, NULL, ImGuiFocusRequestFlags_UnlessBelowModal | ImGuiFocusRequestFlags_RestoreFocusedChild); End(); } @@ -6927,14 +7158,21 @@ static bool IsRootOfOpenMenuSet() if ((g.OpenPopupStack.Size <= g.BeginPopupStack.Size) || (window->Flags & ImGuiWindowFlags_ChildMenu)) return false; - // Initially we used 'OpenParentId' to differentiate multiple menu sets from each others (e.g. inside menu bar vs loose menu items) based on parent ID. - // This would however prevent the use of e.g. PuhsID() user code submitting menus. + // Initially we used 'upper_popup->OpenParentId == window->IDStack.back()' to differentiate multiple menu sets from each others + // (e.g. inside menu bar vs loose menu items) based on parent ID. + // This would however prevent the use of e.g. PushID() user code submitting menus. // Previously this worked between popup and a first child menu because the first child menu always had the _ChildWindow flag, - // making hovering on parent popup possible while first child menu was focused - but this was generally a bug with other side effects. + // making hovering on parent popup possible while first child menu was focused - but this was generally a bug with other side effects. // Instead we don't treat Popup specifically (in order to consistently support menu features in them), maybe the first child menu of a Popup - // doesn't have the _ChildWindow flag, and we rely on this IsRootOfOpenMenuSet() check to allow hovering between root window/popup and first chilld menu. + // doesn't have the _ChildWindow flag, and we rely on this IsRootOfOpenMenuSet() check to allow hovering between root window/popup and first child menu. + // In the end, lack of ID check made it so we could no longer differentiate between separate menu sets. To compensate for that, we at least check parent window nav layer. + // This fixes the most common case of menu opening on hover when moving between window content and menu bar. Multiple different menu sets in same nav layer would still + // open on hover, but that should be a lesser problem, because if such menus are close in proximity in window content then it won't feel weird and if they are far apart + // it likely won't be a problem anyone runs into. const ImGuiPopupData* upper_popup = &g.OpenPopupStack[g.BeginPopupStack.Size]; - return (/*upper_popup->OpenParentId == window->IDStack.back() &&*/ upper_popup->Window && (upper_popup->Window->Flags & ImGuiWindowFlags_ChildMenu)); + if (window->DC.NavLayerCurrent != upper_popup->ParentNavLayer) + return false; + return upper_popup->Window && (upper_popup->Window->Flags & ImGuiWindowFlags_ChildMenu) && ImGui::IsWindowChildOf(upper_popup->Window, window, true, false); } bool ImGui::BeginMenuEx(const char* label, const char* icon, bool enabled) @@ -6949,10 +7187,10 @@ bool ImGui::BeginMenuEx(const char* label, const char* icon, bool enabled) bool menu_is_open = IsPopupOpen(id, ImGuiPopupFlags_None); // Sub-menus are ChildWindow so that mouse can be hovering across them (otherwise top-most popup menu would steal focus and not allow hovering on parent menu) - // The first menu in a hierarchy isn't so hovering doesn't get accross (otherwise e.g. resizing borders with ImGuiButtonFlags_FlattenChildren would react), but top-most BeginMenu() will bypass that limitation. - ImGuiWindowFlags flags = ImGuiWindowFlags_ChildMenu | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoNavFocus; + // The first menu in a hierarchy isn't so hovering doesn't get across (otherwise e.g. resizing borders with ImGuiButtonFlags_FlattenChildren would react), but top-most BeginMenu() will bypass that limitation. + ImGuiWindowFlags window_flags = ImGuiWindowFlags_ChildMenu | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoNavFocus; if (window->Flags & ImGuiWindowFlags_ChildMenu) - flags |= ImGuiWindowFlags_ChildWindow; + window_flags |= ImGuiWindowFlags_ChildWindow; // If a menu with same the ID was already submitted, we will append to it, matching the behavior of Begin(). // We are relying on a O(N) search - so O(N log N) over the frame - which seems like the most efficient for the expected small amount of BeginMenu() calls per frame. @@ -6960,7 +7198,7 @@ bool ImGui::BeginMenuEx(const char* label, const char* icon, bool enabled) if (g.MenusIdSubmittedThisFrame.contains(id)) { if (menu_is_open) - menu_is_open = BeginPopupEx(id, flags); // menu_is_open can be 'false' when the popup is completely clipped (e.g. zero size display) + menu_is_open = BeginPopupEx(id, window_flags); // menu_is_open can be 'false' when the popup is completely clipped (e.g. zero size display) else g.NextWindowData.ClearFlags(); // we behave like Begin() and need to consume those values return menu_is_open; @@ -6972,10 +7210,10 @@ bool ImGui::BeginMenuEx(const char* label, const char* icon, bool enabled) ImVec2 label_size = CalcTextSize(label, NULL, true); // Odd hack to allow hovering across menus of a same menu-set (otherwise we wouldn't be able to hover parent without always being a Child window) + // This is only done for items for the menu set and not the full parent window. const bool menuset_is_open = IsRootOfOpenMenuSet(); - ImGuiWindow* backed_nav_window = g.NavWindow; if (menuset_is_open) - g.NavWindow = window; + PushItemFlag(ImGuiItemFlags_NoWindowHoverableCheck, true); // The reference position stored in popup_pos will be used by Begin() to find a suitable position for the child menu, // However the final position is going to be different! It is chosen by FindBestWindowPosForPopup(). @@ -6986,7 +7224,9 @@ bool ImGui::BeginMenuEx(const char* label, const char* icon, bool enabled) BeginDisabled(); const ImGuiMenuColumns* offsets = &window->DC.MenuColumns; bool pressed; - const ImGuiSelectableFlags selectable_flags = ImGuiSelectableFlags_NoHoldingActiveID | ImGuiSelectableFlags_SelectOnClick | ImGuiSelectableFlags_DontClosePopups; + + // We use ImGuiSelectableFlags_NoSetKeyOwner to allow down on one menu item, move, up on another. + const ImGuiSelectableFlags selectable_flags = ImGuiSelectableFlags_NoHoldingActiveID | ImGuiSelectableFlags_NoSetKeyOwner | ImGuiSelectableFlags_SelectOnClick | ImGuiSelectableFlags_DontClosePopups; if (window->DC.LayoutType == ImGuiLayoutType_Horizontal) { // Menu inside an horizontal menu bar @@ -6997,7 +7237,7 @@ bool ImGui::BeginMenuEx(const char* label, const char* icon, bool enabled) PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(style.ItemSpacing.x * 2.0f, style.ItemSpacing.y)); float w = label_size.x; ImVec2 text_pos(window->DC.CursorPos.x + offsets->OffsetLabel, window->DC.CursorPos.y + window->DC.CurrLineTextBaseOffset); - pressed = Selectable("", menu_is_open, selectable_flags, ImVec2(w, 0.0f)); + pressed = Selectable("", menu_is_open, selectable_flags, ImVec2(w, label_size.y)); RenderText(text_pos, label); PopStyleVar(); window->DC.CursorPos.x += IM_FLOOR(style.ItemSpacing.x * (-1.0f + 0.5f)); // -1 spacing to compensate the spacing added when Selectable() did a SameLine(). It would also work to call SameLine() ourselves after the PopStyleVar(). @@ -7013,7 +7253,7 @@ bool ImGui::BeginMenuEx(const char* label, const char* icon, bool enabled) float min_w = window->DC.MenuColumns.DeclColumns(icon_w, label_size.x, 0.0f, checkmark_w); // Feedback to next frame float extra_w = ImMax(0.0f, GetContentRegionAvail().x - min_w); ImVec2 text_pos(window->DC.CursorPos.x + offsets->OffsetLabel, window->DC.CursorPos.y + window->DC.CurrLineTextBaseOffset); - pressed = Selectable("", menu_is_open, selectable_flags | ImGuiSelectableFlags_SpanAvailWidth, ImVec2(min_w, 0.0f)); + pressed = Selectable("", menu_is_open, selectable_flags | ImGuiSelectableFlags_SpanAvailWidth, ImVec2(min_w, label_size.y)); RenderText(text_pos, label); if (icon_w > 0.0f) RenderText(pos + ImVec2(offsets->OffsetIcon, 0.0f), icon); @@ -7024,7 +7264,7 @@ bool ImGui::BeginMenuEx(const char* label, const char* icon, bool enabled) const bool hovered = (g.HoveredId == id) && enabled && !g.NavDisableMouseHover; if (menuset_is_open) - g.NavWindow = backed_nav_window; + PopItemFlag(); bool want_open = false; bool want_close = false; @@ -7033,26 +7273,30 @@ bool ImGui::BeginMenuEx(const char* label, const char* icon, bool enabled) // Close menu when not hovering it anymore unless we are moving roughly in the direction of the menu // Implement http://bjk5.com/post/44698559168/breaking-down-amazons-mega-dropdown to avoid using timers, so menus feels more reactive. bool moving_toward_child_menu = false; - ImGuiWindow* child_menu_window = (g.BeginPopupStack.Size < g.OpenPopupStack.Size && g.OpenPopupStack[g.BeginPopupStack.Size].SourceWindow == window) ? g.OpenPopupStack[g.BeginPopupStack.Size].Window : NULL; - if (g.HoveredWindow == window && child_menu_window != NULL && !(window->Flags & ImGuiWindowFlags_MenuBar)) + ImGuiPopupData* child_popup = (g.BeginPopupStack.Size < g.OpenPopupStack.Size) ? &g.OpenPopupStack[g.BeginPopupStack.Size] : NULL; // Popup candidate (testing below) + ImGuiWindow* child_menu_window = (child_popup && child_popup->Window && child_popup->Window->ParentWindow == window) ? child_popup->Window : NULL; + if (g.HoveredWindow == window && child_menu_window != NULL) { float ref_unit = g.FontSize; // FIXME-DPI + float child_dir = (window->Pos.x < child_menu_window->Pos.x) ? 1.0f : -1.0f; ImRect next_window_rect = child_menu_window->Rect(); ImVec2 ta = (g.IO.MousePos - g.IO.MouseDelta); - ImVec2 tb = (window->Pos.x < child_menu_window->Pos.x) ? next_window_rect.GetTL() : next_window_rect.GetTR(); - ImVec2 tc = (window->Pos.x < child_menu_window->Pos.x) ? next_window_rect.GetBL() : next_window_rect.GetBR(); + ImVec2 tb = (child_dir > 0.0f) ? next_window_rect.GetTL() : next_window_rect.GetTR(); + ImVec2 tc = (child_dir > 0.0f) ? next_window_rect.GetBL() : next_window_rect.GetBR(); float extra = ImClamp(ImFabs(ta.x - tb.x) * 0.30f, ref_unit * 0.5f, ref_unit * 2.5f); // add a bit of extra slack. - ta.x += (window->Pos.x < child_menu_window->Pos.x) ? -0.5f : +0.5f; // to avoid numerical issues (FIXME: ??) + ta.x += child_dir * -0.5f; + tb.x += child_dir * ref_unit; + tc.x += child_dir * ref_unit; tb.y = ta.y + ImMax((tb.y - extra) - ta.y, -ref_unit * 8.0f); // triangle has maximum height to limit the slope and the bias toward large sub-menus tc.y = ta.y + ImMin((tc.y + extra) - ta.y, +ref_unit * 8.0f); moving_toward_child_menu = ImTriangleContainsPoint(ta, tb, tc, g.IO.MousePos); - //GetForegroundDrawList()->AddTriangleFilled(ta, tb, tc, moving_toward_other_child_menu ? IM_COL32(0,128,0,128) : IM_COL32(128,0,0,128)); // [DEBUG] + //GetForegroundDrawList()->AddTriangleFilled(ta, tb, tc, moving_toward_child_menu ? IM_COL32(0,128,0,128) : IM_COL32(128,0,0,128)); // [DEBUG] } // The 'HovereWindow == window' check creates an inconsistency (e.g. moving away from menu slowly tends to hit same window, whereas moving away fast does not) // But we also need to not close the top-menu menu when moving over void. Perhaps we should extend the triangle check to a larger polygon. // (Remember to test this on BeginPopup("A")->BeginMenu("B") sequence which behaves slightly differently as B isn't a Child of A and hovering isn't shared.) - if (menu_is_open && !hovered && g.HoveredWindow == window && !moving_toward_child_menu) + if (menu_is_open && !hovered && g.HoveredWindow == window && !moving_toward_child_menu && !g.NavDisableMouseHover) want_close = true; // Open @@ -7093,23 +7337,32 @@ bool ImGui::BeginMenuEx(const char* label, const char* icon, bool enabled) IMGUI_TEST_ENGINE_ITEM_INFO(id, label, g.LastItemData.StatusFlags | ImGuiItemStatusFlags_Openable | (menu_is_open ? ImGuiItemStatusFlags_Opened : 0)); PopID(); - if (!menu_is_open && want_open && g.OpenPopupStack.Size > g.BeginPopupStack.Size) + if (want_open && !menu_is_open && g.OpenPopupStack.Size > g.BeginPopupStack.Size) { - // Don't recycle same menu level in the same frame, first close the other menu and yield for a frame. + // Don't reopen/recycle same menu level in the same frame, first close the other menu and yield for a frame. OpenPopup(label); - return false; } - - menu_is_open |= want_open; - if (want_open) + else if (want_open) + { + menu_is_open = true; OpenPopup(label); + } if (menu_is_open) { - SetNextWindowPos(popup_pos, ImGuiCond_Always); // Note: this is super misleading! The value will serve as reference for FindBestWindowPosForPopup(), not actual pos. + ImGuiLastItemData last_item_in_parent = g.LastItemData; + SetNextWindowPos(popup_pos, ImGuiCond_Always); // Note: misleading: the value will serve as reference for FindBestWindowPosForPopup(), not actual pos. PushStyleVar(ImGuiStyleVar_ChildRounding, style.PopupRounding); // First level will use _PopupRounding, subsequent will use _ChildRounding - menu_is_open = BeginPopupEx(id, flags); // menu_is_open can be 'false' when the popup is completely clipped (e.g. zero size display) + menu_is_open = BeginPopupEx(id, window_flags); // menu_is_open can be 'false' when the popup is completely clipped (e.g. zero size display) PopStyleVar(); + if (menu_is_open) + { + // Restore LastItemData so IsItemXXXX functions can work after BeginMenu()/EndMenu() + // (This fixes using IsItemClicked() and IsItemHovered(), but IsItemHovered() also relies on its support for ImGuiItemFlags_NoWindowHoverableCheck) + g.LastItemData = last_item_in_parent; + if (g.HoveredWindow == window) + g.LastItemData.StatusFlags |= ImGuiItemStatusFlags_HoveredWindow; + } } else { @@ -7126,17 +7379,18 @@ bool ImGui::BeginMenu(const char* label, bool enabled) void ImGui::EndMenu() { - // Nav: When a left move request _within our child menu_ failed, close ourselves (the _parent_ menu). - // A menu doesn't close itself because EndMenuBar() wants the catch the last Left<>Right inputs. - // However, it means that with the current code, a BeginMenu() from outside another menu or a menu-bar won't be closable with the Left direction. + // Nav: When a left move request our menu failed, close ourselves. ImGuiContext& g = *GImGui; ImGuiWindow* window = g.CurrentWindow; - if (g.NavMoveDir == ImGuiDir_Left && NavMoveRequestButNoResultYet() && window->DC.LayoutType == ImGuiLayoutType_Vertical) - if (g.NavWindow && (g.NavWindow->RootWindowForNav->Flags & ImGuiWindowFlags_Popup) && g.NavWindow->RootWindowForNav->ParentWindow == window) - { - ClosePopupToLevel(g.BeginPopupStack.Size, true); - NavMoveRequestCancel(); - } + IM_ASSERT(window->Flags & ImGuiWindowFlags_Popup); // Mismatched BeginMenu()/EndMenu() calls + ImGuiWindow* parent_window = window->ParentWindow; // Should always be != NULL is we passed assert. + if (window->BeginCount == window->BeginCountPreviousFrame) + if (g.NavMoveDir == ImGuiDir_Left && NavMoveRequestButNoResultYet()) + if (g.NavWindow && (g.NavWindow->RootWindowForNav == window) && parent_window->DC.LayoutType == ImGuiLayoutType_Vertical) + { + ClosePopupToLevel(g.BeginPopupStack.Size - 1, true); + NavMoveRequestCancel(); + } EndPopup(); } @@ -7152,10 +7406,10 @@ bool ImGui::MenuItemEx(const char* label, const char* icon, const char* shortcut ImVec2 pos = window->DC.CursorPos; ImVec2 label_size = CalcTextSize(label, NULL, true); + // See BeginMenuEx() for comments about this. const bool menuset_is_open = IsRootOfOpenMenuSet(); - ImGuiWindow* backed_nav_window = g.NavWindow; if (menuset_is_open) - g.NavWindow = window; + PushItemFlag(ImGuiItemFlags_NoWindowHoverableCheck, true); // We've been using the equivalent of ImGuiSelectableFlags_SetNavIdOnHover on all Selectable() since early Nav system days (commit 43ee5d73), // but I am unsure whether this should be kept at all. For now moved it to be an opt-in feature used by menus only. @@ -7164,7 +7418,8 @@ bool ImGui::MenuItemEx(const char* label, const char* icon, const char* shortcut if (!enabled) BeginDisabled(); - const ImGuiSelectableFlags selectable_flags = ImGuiSelectableFlags_SelectOnRelease | ImGuiSelectableFlags_SetNavIdOnHover; + // We use ImGuiSelectableFlags_NoSetKeyOwner to allow down on one menu item, move, up on another. + const ImGuiSelectableFlags selectable_flags = ImGuiSelectableFlags_SelectOnRelease | ImGuiSelectableFlags_NoSetKeyOwner | ImGuiSelectableFlags_SetNavIdOnHover; const ImGuiMenuColumns* offsets = &window->DC.MenuColumns; if (window->DC.LayoutType == ImGuiLayoutType_Horizontal) { @@ -7176,7 +7431,8 @@ bool ImGui::MenuItemEx(const char* label, const char* icon, const char* shortcut PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(style.ItemSpacing.x * 2.0f, style.ItemSpacing.y)); pressed = Selectable("", selected, selectable_flags, ImVec2(w, 0.0f)); PopStyleVar(); - RenderText(text_pos, label); + if (g.LastItemData.StatusFlags & ImGuiItemStatusFlags_Visible) + RenderText(text_pos, label); window->DC.CursorPos.x += IM_FLOOR(style.ItemSpacing.x * (-1.0f + 0.5f)); // -1 spacing to compensate the spacing added when Selectable() did a SameLine(). It would also work to call SameLine() ourselves after the PopStyleVar(). } else @@ -7189,25 +7445,28 @@ bool ImGui::MenuItemEx(const char* label, const char* icon, const char* shortcut float checkmark_w = IM_FLOOR(g.FontSize * 1.20f); float min_w = window->DC.MenuColumns.DeclColumns(icon_w, label_size.x, shortcut_w, checkmark_w); // Feedback for next frame float stretch_w = ImMax(0.0f, GetContentRegionAvail().x - min_w); - pressed = Selectable("", false, selectable_flags | ImGuiSelectableFlags_SpanAvailWidth, ImVec2(min_w, 0.0f)); - RenderText(pos + ImVec2(offsets->OffsetLabel, 0.0f), label); - if (icon_w > 0.0f) - RenderText(pos + ImVec2(offsets->OffsetIcon, 0.0f), icon); - if (shortcut_w > 0.0f) + pressed = Selectable("", false, selectable_flags | ImGuiSelectableFlags_SpanAvailWidth, ImVec2(min_w, label_size.y)); + if (g.LastItemData.StatusFlags & ImGuiItemStatusFlags_Visible) { - PushStyleColor(ImGuiCol_Text, style.Colors[ImGuiCol_TextDisabled]); - RenderText(pos + ImVec2(offsets->OffsetShortcut + stretch_w, 0.0f), shortcut, NULL, false); - PopStyleColor(); + RenderText(pos + ImVec2(offsets->OffsetLabel, 0.0f), label); + if (icon_w > 0.0f) + RenderText(pos + ImVec2(offsets->OffsetIcon, 0.0f), icon); + if (shortcut_w > 0.0f) + { + PushStyleColor(ImGuiCol_Text, style.Colors[ImGuiCol_TextDisabled]); + RenderText(pos + ImVec2(offsets->OffsetShortcut + stretch_w, 0.0f), shortcut, NULL, false); + PopStyleColor(); + } + if (selected) + RenderCheckMark(window->DrawList, pos + ImVec2(offsets->OffsetMark + stretch_w + g.FontSize * 0.40f, g.FontSize * 0.134f * 0.5f), GetColorU32(ImGuiCol_Text), g.FontSize * 0.866f); } - if (selected) - RenderCheckMark(window->DrawList, pos + ImVec2(offsets->OffsetMark + stretch_w + g.FontSize * 0.40f, g.FontSize * 0.134f * 0.5f), GetColorU32(ImGuiCol_Text), g.FontSize * 0.866f); } IMGUI_TEST_ENGINE_ITEM_INFO(g.LastItemData.ID, label, g.LastItemData.StatusFlags | ImGuiItemStatusFlags_Checkable | (selected ? ImGuiItemStatusFlags_Checked : 0)); if (!enabled) EndDisabled(); PopID(); if (menuset_is_open) - g.NavWindow = backed_nav_window; + PopItemFlag(); return pressed; } @@ -7238,12 +7497,19 @@ bool ImGui::MenuItem(const char* label, const char* shortcut, bool* p_selected, // - TabBarCalcTabID() [Internal] // - TabBarCalcMaxTabWidth() [Internal] // - TabBarFindTabById() [Internal] +// - TabBarFindTabByOrder() [Internal] +// - TabBarFindMostRecentlySelectedTabForActiveWindow() [Internal] +// - TabBarGetCurrentTab() [Internal] +// - TabBarGetTabName() [Internal] // - TabBarAddTab() [Internal] // - TabBarRemoveTab() [Internal] // - TabBarCloseTab() [Internal] // - TabBarScrollClamp() [Internal] // - TabBarScrollToTab() [Internal] -// - TabBarQueueChangeTabOrder() [Internal] +// - TabBarQueueFocus() [Internal] +// - TabBarQueueReorder() [Internal] +// - TabBarProcessReorderFromMousePos() [Internal] +// - TabBarProcessReorder() [Internal] // - TabBarScrollingButtons() [Internal] // - TabBarTabListPopupButton() [Internal] //------------------------------------------------------------------------- @@ -7369,6 +7635,7 @@ bool ImGui::BeginTabBarEx(ImGuiTabBar* tab_bar, const ImRect& tab_bar_bb, ImG tab_bar->ItemSpacingY = g.Style.ItemSpacing.y; tab_bar->FramePadding = g.Style.FramePadding; tab_bar->TabsActiveCount = 0; + tab_bar->LastTabItemIdx = -1; tab_bar->BeginCount = 1; // Set cursor pos in a way which only be used in the off-chance the user erroneously submits item before BeginTabItem(): items will overlap @@ -7424,6 +7691,7 @@ void ImGui::EndTabBar() if (tab_bar->BeginCount > 1) window->DC.CursorPos = tab_bar->BackupCursorPos; + tab_bar->LastTabItemIdx = -1; if ((tab_bar->Flags & ImGuiTabBarFlags_DockNode) == 0) PopID(); @@ -7431,6 +7699,12 @@ void ImGui::EndTabBar() g.CurrentTabBar = g.CurrentTabBarStack.empty() ? NULL : GetTabBarFromTabBarRef(g.CurrentTabBarStack.back()); } +// Scrolling happens only in the central section (leading/trailing sections are not scrolling) +static float TabBarCalcScrollableWidth(ImGuiTabBar* tab_bar, ImGuiTabBarSection* sections) +{ + return tab_bar->BarRect.GetWidth() - sections[0].Width - sections[2].Width - sections[1].Spacing; +} + // This is called only once a frame before by the first call to ItemTab() // The reason we're not calling it in BeginTabBar() is to leave a chance to the user to call the SetTabItemClosed() functions. static void ImGui::TabBarLayout(ImGuiTabBar* tab_bar) @@ -7533,9 +7807,9 @@ static void ImGui::TabBarLayout(ImGuiTabBar* tab_bar) // Refresh tab width immediately, otherwise changes of style e.g. style.FramePadding.x would noticeably lag in the tab bar. // Additionally, when using TabBarAddTab() to manipulate tab bar order we occasionally insert new tabs that don't have a width yet, // and we cannot wait for the next BeginTabItem() call. We cannot compute this width within TabBarAddTab() because font size depends on the active window. - const char* tab_name = tab_bar->GetTabName(tab); - const bool has_close_button = (tab->Flags & ImGuiTabItemFlags_NoCloseButton) == 0; - tab->ContentWidth = TabItemCalcSize(tab_name, has_close_button).x; + const char* tab_name = TabBarGetTabName(tab_bar, tab); + const bool has_close_button_or_unsaved_marker = (tab->Flags & ImGuiTabItemFlags_NoCloseButton) == 0 || (tab->Flags & ImGuiTabItemFlags_UnsavedDocument); + tab->ContentWidth = (tab->RequestedWidth >= 0.0f) ? tab->RequestedWidth : TabItemCalcSize(tab_name, has_close_button_or_unsaved_marker).x; int section_n = TabItemGetSectionIdx(tab); ImGuiTabBarSection* section = §ions[section_n]; @@ -7544,12 +7818,10 @@ static void ImGui::TabBarLayout(ImGuiTabBar* tab_bar) // Store data so we can build an array sorted by width if we need to shrink tabs down IM_MSVC_WARNING_SUPPRESS(6385); - int shrink_buffer_index = shrink_buffer_indexes[section_n]++; - g.ShrinkWidthBuffer[shrink_buffer_index].Index = tab_n; - g.ShrinkWidthBuffer[shrink_buffer_index].Width = tab->ContentWidth; - - IM_ASSERT(tab->ContentWidth > 0.0f); - tab->Width = tab->ContentWidth; + ImGuiShrinkWidthItem* shrink_width_item = &g.ShrinkWidthBuffer[shrink_buffer_indexes[section_n]++]; + shrink_width_item->Index = tab_n; + shrink_width_item->Width = shrink_width_item->InitialWidth = tab->ContentWidth; + tab->Width = ImMax(tab->ContentWidth, 1.0f); } // Compute total ideal width (used for e.g. auto-resizing a window) @@ -7579,7 +7851,7 @@ static void ImGui::TabBarLayout(ImGuiTabBar* tab_bar) width_excess = (section_0_w + section_2_w) - tab_bar->BarRect.GetWidth(); // Excess used to shrink leading/trailing section // With ImGuiTabBarFlags_FittingPolicyScroll policy, we will only shrink leading/trailing if the central section is not visible anymore - if (width_excess > 0.0f && ((tab_bar->Flags & ImGuiTabBarFlags_FittingPolicyResizeDown) || !central_section_is_visible)) + if (width_excess >= 1.0f && ((tab_bar->Flags & ImGuiTabBarFlags_FittingPolicyResizeDown) || !central_section_is_visible)) { int shrink_data_count = (central_section_is_visible ? sections[1].TabCount : sections[0].TabCount + sections[2].TabCount); int shrink_data_offset = (central_section_is_visible ? sections[0].TabCount + sections[2].TabCount : 0); @@ -7593,6 +7865,7 @@ static void ImGui::TabBarLayout(ImGuiTabBar* tab_bar) if (shrinked_width < 0.0f) continue; + shrinked_width = ImMax(1.0f, shrinked_width); int section_n = TabItemGetSectionIdx(tab); sections[section_n].Width -= (tab->Width - shrinked_width); tab->Width = shrinked_width; @@ -7636,11 +7909,25 @@ static void ImGui::TabBarLayout(ImGuiTabBar* tab_bar) // CTRL+TAB can override visible tab temporarily if (g.NavWindowingTarget != NULL && g.NavWindowingTarget->DockNode && g.NavWindowingTarget->DockNode->TabBar == tab_bar) - tab_bar->VisibleTabId = scroll_to_tab_id = g.NavWindowingTarget->ID; + tab_bar->VisibleTabId = scroll_to_tab_id = g.NavWindowingTarget->TabId; - // Update scrolling + // Apply request requests if (scroll_to_tab_id != 0) TabBarScrollToTab(tab_bar, scroll_to_tab_id, sections); + else if ((tab_bar->Flags & ImGuiTabBarFlags_FittingPolicyScroll) && IsMouseHoveringRect(tab_bar->BarRect.Min, tab_bar->BarRect.Max, true) && IsWindowContentHoverable(g.CurrentWindow)) + { + const float wheel = g.IO.MouseWheelRequestAxisSwap ? g.IO.MouseWheel : g.IO.MouseWheelH; + const ImGuiKey wheel_key = g.IO.MouseWheelRequestAxisSwap ? ImGuiKey_MouseWheelY : ImGuiKey_MouseWheelX; + if (TestKeyOwner(wheel_key, tab_bar->ID) && wheel != 0.0f) + { + const float scroll_step = wheel * TabBarCalcScrollableWidth(tab_bar, sections) / 3.0f; + tab_bar->ScrollingTargetDistToVisibility = 0.0f; + tab_bar->ScrollingTarget = TabBarScrollClamp(tab_bar, tab_bar->ScrollingTarget - scroll_step); + } + SetKeyOwner(wheel_key, tab_bar->ID); + } + + // Update scrolling tab_bar->ScrollingAnim = TabBarScrollClamp(tab_bar, tab_bar->ScrollingAnim); tab_bar->ScrollingTarget = TabBarScrollClamp(tab_bar, tab_bar->ScrollingTarget); if (tab_bar->ScrollingAnim != tab_bar->ScrollingTarget) @@ -7666,7 +7953,7 @@ static void ImGui::TabBarLayout(ImGuiTabBar* tab_bar) window->DC.IdealMaxPos.x = ImMax(window->DC.IdealMaxPos.x, tab_bar->BarRect.Min.x + tab_bar->WidthAllTabsIdeal); } -// Dockable uses Name/ID in the global namespace. Non-dockable items use the ID stack. +// Dockable windows uses Name/ID in the global namespace. Non-dockable items use the ID stack. static ImU32 ImGui::TabBarCalcTabID(ImGuiTabBar* tab_bar, const char* label, ImGuiWindow* docked_window) { if (docked_window != NULL) @@ -7699,6 +7986,14 @@ ImGuiTabItem* ImGui::TabBarFindTabByID(ImGuiTabBar* tab_bar, ImGuiID tab_id) return NULL; } +// Order = visible order, not submission order! (which is tab->BeginOrder) +ImGuiTabItem* ImGui::TabBarFindTabByOrder(ImGuiTabBar* tab_bar, int order) +{ + if (order < 0 || order >= tab_bar->Tabs.Size) + return NULL; + return &tab_bar->Tabs[order]; +} + // FIXME: See references to #2304 in TODO.txt ImGuiTabItem* ImGui::TabBarFindMostRecentlySelectedTabForActiveWindow(ImGuiTabBar* tab_bar) { @@ -7713,6 +8008,23 @@ ImGuiTabItem* ImGui::TabBarFindMostRecentlySelectedTabForActiveWindow(ImGuiTabBa return most_recently_selected_tab; } +ImGuiTabItem* ImGui::TabBarGetCurrentTab(ImGuiTabBar* tab_bar) +{ + if (tab_bar->LastTabItemIdx <= 0 || tab_bar->LastTabItemIdx >= tab_bar->Tabs.Size) + return NULL; + return &tab_bar->Tabs[tab_bar->LastTabItemIdx]; +} + +const char* ImGui::TabBarGetTabName(ImGuiTabBar* tab_bar, ImGuiTabItem* tab) +{ + if (tab->Window) + return tab->Window->Name; + if (tab->NameOffset == -1) + return "N/A"; + IM_ASSERT(tab->NameOffset < tab_bar->TabsNames.Buf.Size); + return tab_bar->TabsNames.Buf.Data + tab->NameOffset; +} + // The purpose of this call is to register tab in advance so we can control their order at the time they appear. // Otherwise calling this is unnecessary as tabs are appending as needed by the BeginTabItem() function. void ImGui::TabBarAddTab(ImGuiTabBar* tab_bar, ImGuiTabItemFlags tab_flags, ImGuiWindow* window) @@ -7734,7 +8046,7 @@ void ImGui::TabBarAddTab(ImGuiTabBar* tab_bar, ImGuiTabItemFlags tab_flags, ImGu tab_bar->Tabs.push_back(new_tab); } -// The *TabId fields be already set by the docking system _before_ the actual TabItem was created, so we clear them regardless. +// The *TabId fields are already set by the docking system _before_ the actual TabItem was created, so we clear them regardless. void ImGui::TabBarRemoveTab(ImGuiTabBar* tab_bar, ImGuiID tab_id) { if (ImGuiTabItem* tab = TabBarFindTabByID(tab_bar, tab_id)) @@ -7747,7 +8059,9 @@ void ImGui::TabBarRemoveTab(ImGuiTabBar* tab_bar, ImGuiID tab_id) // Called on manual closure attempt void ImGui::TabBarCloseTab(ImGuiTabBar* tab_bar, ImGuiTabItem* tab) { - IM_ASSERT(!(tab->Flags & ImGuiTabItemFlags_Button)); + if (tab->Flags & ImGuiTabItemFlags_Button) + return; // A button appended with TabItemButton(). + if (!(tab->Flags & ImGuiTabItemFlags_UnsavedDocument)) { // This will remove a frame of lag for selecting another tab on closure. @@ -7763,7 +8077,7 @@ void ImGui::TabBarCloseTab(ImGuiTabBar* tab_bar, ImGuiTabItem* tab) { // Actually select before expecting closure attempt (on an UnsavedDocument tab user is expect to e.g. show a popup) if (tab_bar->VisibleTabId != tab->ID) - tab_bar->NextSelectedTabId = tab->ID; + TabBarQueueFocus(tab_bar, tab); } } @@ -7784,11 +8098,10 @@ static void ImGui::TabBarScrollToTab(ImGuiTabBar* tab_bar, ImGuiID tab_id, ImGui ImGuiContext& g = *GImGui; float margin = g.FontSize * 1.0f; // When to scroll to make Tab N+1 visible always make a bit of N visible to suggest more scrolling area (since we don't have a scrollbar) - int order = tab_bar->GetTabOrder(tab); + int order = TabBarGetTabOrder(tab_bar, tab); // Scrolling happens only in the central section (leading/trailing sections are not scrolling) - // FIXME: This is all confusing. - float scrollable_width = tab_bar->BarRect.GetWidth() - sections[0].Width - sections[2].Width - sections[1].Spacing; + float scrollable_width = TabBarCalcScrollableWidth(tab_bar, sections); // We make all tabs positions all relative Sections[0].Width to make code simpler float tab_x1 = tab->Offset - sections[0].Width + (order > sections[0].TabCount - 1 ? -margin : 0.0f); @@ -7808,7 +8121,12 @@ static void ImGui::TabBarScrollToTab(ImGuiTabBar* tab_bar, ImGuiID tab_id, ImGui } } -void ImGui::TabBarQueueReorder(ImGuiTabBar* tab_bar, const ImGuiTabItem* tab, int offset) +void ImGui::TabBarQueueFocus(ImGuiTabBar* tab_bar, ImGuiTabItem* tab) +{ + tab_bar->NextSelectedTabId = tab->ID; +} + +void ImGui::TabBarQueueReorder(ImGuiTabBar* tab_bar, ImGuiTabItem* tab, int offset) { IM_ASSERT(offset != 0); IM_ASSERT(tab_bar->ReorderRequestTabId == 0); @@ -7816,7 +8134,7 @@ void ImGui::TabBarQueueReorder(ImGuiTabBar* tab_bar, const ImGuiTabItem* tab, in tab_bar->ReorderRequestOffset = (ImS16)offset; } -void ImGui::TabBarQueueReorderFromMousePos(ImGuiTabBar* tab_bar, const ImGuiTabItem* src_tab, ImVec2 mouse_pos) +void ImGui::TabBarQueueReorderFromMousePos(ImGuiTabBar* tab_bar, ImGuiTabItem* src_tab, ImVec2 mouse_pos) { ImGuiContext& g = *GImGui; IM_ASSERT(tab_bar->ReorderRequestTabId == 0); @@ -7859,7 +8177,7 @@ bool ImGui::TabBarProcessReorder(ImGuiTabBar* tab_bar) return false; //IM_ASSERT(tab_bar->Flags & ImGuiTabBarFlags_Reorderable); // <- this may happen when using debug tools - int tab2_order = tab_bar->GetTabOrder(tab1) + tab_bar->ReorderRequestOffset; + int tab2_order = TabBarGetTabOrder(tab_bar, tab1) + tab_bar->ReorderRequestOffset; if (tab2_order < 0 || tab2_order >= tab_bar->Tabs.Size) return false; @@ -7919,7 +8237,7 @@ static ImGuiTabItem* ImGui::TabBarScrollingButtons(ImGuiTabBar* tab_bar) if (select_dir != 0) if (ImGuiTabItem* tab_item = TabBarFindTabByID(tab_bar, tab_bar->SelectedTabId)) { - int selected_order = tab_bar->GetTabOrder(tab_item); + int selected_order = TabBarGetTabOrder(tab_bar, tab_item); int target_order = selected_order + select_dir; // Skip tab item buttons until another tab item is found or end is reached @@ -7971,7 +8289,7 @@ static ImGuiTabItem* ImGui::TabBarTabListPopupButton(ImGuiTabBar* tab_bar) if (tab->Flags & ImGuiTabItemFlags_Button) continue; - const char* tab_name = tab_bar->GetTabName(tab); + const char* tab_name = TabBarGetTabName(tab_bar, tab); if (Selectable(tab_name, tab_bar->SelectedTabId == tab->ID)) tab_to_select = tab; } @@ -8057,10 +8375,13 @@ bool ImGui::TabItemButton(const char* label, ImGuiTabItemFlags flags) bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open, ImGuiTabItemFlags flags, ImGuiWindow* docked_window) { // Layout whole tab bar if not already done - if (tab_bar->WantLayout) - TabBarLayout(tab_bar); - ImGuiContext& g = *GImGui; + if (tab_bar->WantLayout) + { + ImGuiNextItemData backup_next_item_data = g.NextItemData; + TabBarLayout(tab_bar); + g.NextItemData = backup_next_item_data; + } ImGuiWindow* window = g.CurrentWindow; if (window->SkipItems) return false; @@ -8073,7 +8394,7 @@ bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open, IMGUI_TEST_ENGINE_ITEM_INFO(id, label, g.LastItemData.StatusFlags); if (p_open && !*p_open) { - ItemAdd(ImRect(), id, NULL, ImGuiItemFlags_NoNav | ImGuiItemFlags_NoNavDefaultFocus); + ItemAdd(ImRect(), id, NULL, ImGuiItemFlags_NoNav); return false; } @@ -8086,9 +8407,6 @@ bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open, else if (p_open == NULL) flags |= ImGuiTabItemFlags_NoCloseButton; - // Calculate tab contents size - ImVec2 size = TabItemCalcSize(label, p_open != NULL); - // Acquire tab data ImGuiTabItem* tab = TabBarFindTabByID(tab_bar, id); bool tab_is_new = false; @@ -8097,44 +8415,51 @@ bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open, tab_bar->Tabs.push_back(ImGuiTabItem()); tab = &tab_bar->Tabs.back(); tab->ID = id; - tab->Width = size.x; - tab_bar->TabsAddedNew = true; - tab_is_new = true; + tab_bar->TabsAddedNew = tab_is_new = true; } tab_bar->LastTabItemIdx = (ImS16)tab_bar->Tabs.index_from_ptr(tab); + + // Calculate tab contents size + ImVec2 size = TabItemCalcSize(label, (p_open != NULL) || (flags & ImGuiTabItemFlags_UnsavedDocument)); + tab->RequestedWidth = -1.0f; + if (g.NextItemData.Flags & ImGuiNextItemDataFlags_HasWidth) + size.x = tab->RequestedWidth = g.NextItemData.Width; + if (tab_is_new) + tab->Width = ImMax(1.0f, size.x); tab->ContentWidth = size.x; tab->BeginOrder = tab_bar->TabsActiveCount++; const bool tab_bar_appearing = (tab_bar->PrevFrameVisible + 1 < g.FrameCount); const bool tab_bar_focused = (tab_bar->Flags & ImGuiTabBarFlags_IsFocused) != 0; const bool tab_appearing = (tab->LastFrameVisible + 1 < g.FrameCount); + const bool tab_just_unsaved = (flags & ImGuiTabItemFlags_UnsavedDocument) && !(tab->Flags & ImGuiTabItemFlags_UnsavedDocument); const bool is_tab_button = (flags & ImGuiTabItemFlags_Button) != 0; tab->LastFrameVisible = g.FrameCount; tab->Flags = flags; tab->Window = docked_window; - // Append name with zero-terminator + // Append name _WITH_ the zero-terminator // (regular tabs are permitted in a DockNode tab bar, but window tabs not permitted in a non-DockNode tab bar) - if (tab->Window != NULL) + if (docked_window != NULL) { IM_ASSERT(tab_bar->Flags & ImGuiTabBarFlags_DockNode); tab->NameOffset = -1; } else { - IM_ASSERT(tab->Window == NULL); tab->NameOffset = (ImS32)tab_bar->TabsNames.size(); - tab_bar->TabsNames.append(label, label + strlen(label) + 1); // Append name _with_ the zero-terminator. + tab_bar->TabsNames.append(label, label + strlen(label) + 1); } // Update selected tab - if (tab_appearing && (tab_bar->Flags & ImGuiTabBarFlags_AutoSelectNewTabs) && tab_bar->NextSelectedTabId == 0) - if (!tab_bar_appearing || tab_bar->SelectedTabId == 0) - if (!is_tab_button) - tab_bar->NextSelectedTabId = id; // New tabs gets activated - if ((flags & ImGuiTabItemFlags_SetSelected) && (tab_bar->SelectedTabId != id)) // SetSelected can only be passed on explicit tab bar - if (!is_tab_button) - tab_bar->NextSelectedTabId = id; + if (!is_tab_button) + { + if (tab_appearing && (tab_bar->Flags & ImGuiTabBarFlags_AutoSelectNewTabs) && tab_bar->NextSelectedTabId == 0) + if (!tab_bar_appearing || tab_bar->SelectedTabId == 0) + TabBarQueueFocus(tab_bar, tab); // New tabs gets activated + if ((flags & ImGuiTabItemFlags_SetSelected) && (tab_bar->SelectedTabId != id)) // _SetSelected can only be passed on explicit tab bar + TabBarQueueFocus(tab_bar, tab); + } // Lock visibility // (Note: tab_contents_visible != tab_selected... because CTRL+TAB operations may preview some tabs without selecting them!) @@ -8151,7 +8476,7 @@ bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open, // and then gets submitted again, the tabs will have 'tab_appearing=true' but 'tab_is_new=false'. if (tab_appearing && (!tab_bar_appearing || tab_is_new)) { - ItemAdd(ImRect(), id, NULL, ImGuiItemFlags_NoNav | ImGuiItemFlags_NoNavDefaultFocus); + ItemAdd(ImRect(), id, NULL, ImGuiItemFlags_NoNav); if (is_tab_button) return false; return tab_contents_visible; @@ -8197,7 +8522,7 @@ bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open, bool hovered, held; bool pressed = ButtonBehavior(bb, id, &hovered, &held, button_flags); if (pressed && !is_tab_button) - tab_bar->NextSelectedTabId = id; + TabBarQueueFocus(tab_bar, tab); // Transfer active id window so the active id is not owned by the dock host (as StartMouseMovingWindow() // will only do it on the drag). This allows FocusWindow() to be more conservative in how it clears active id. @@ -8258,7 +8583,7 @@ bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open, if (distance_from_edge_y >= threshold_y) undocking_tab = true; if (drag_distance_from_edge_x > threshold_x) - if ((drag_dir < 0 && tab_bar->GetTabOrder(tab) == 0) || (drag_dir > 0 && tab_bar->GetTabOrder(tab) == tab_bar->Tabs.Size - 1)) + if ((drag_dir < 0 && TabBarGetTabOrder(tab_bar, tab) == 0) || (drag_dir > 0 && TabBarGetTabOrder(tab_bar, tab) == tab_bar->Tabs.Size - 1)) undocking_tab = true; } @@ -8271,7 +8596,7 @@ bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open, SetActiveID(g.MovingWindow->MoveId, g.MovingWindow); g.ActiveIdClickOffset -= g.MovingWindow->Pos - bb.Min; g.ActiveIdNoClearOnFocusLoss = true; - SetActiveIdUsingNavAndKeys(); + SetActiveIdUsingAllKeyboardKeys(); } } } @@ -8294,9 +8619,8 @@ bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open, // Select with right mouse button. This is so the common idiom for context menu automatically highlight the current widget. const bool hovered_unblocked = IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup); - if (hovered_unblocked && (IsMouseClicked(1) || IsMouseReleased(1))) - if (!is_tab_button) - tab_bar->NextSelectedTabId = id; + if (hovered_unblocked && (IsMouseClicked(1) || IsMouseReleased(1)) && !is_tab_button) + TabBarQueueFocus(tab_bar, tab); if (tab_bar->Flags & ImGuiTabBarFlags_NoCloseWithMiddleMouseButton) flags |= ImGuiTabItemFlags_NoCloseWithMiddleMouseButton; @@ -8305,7 +8629,7 @@ bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open, const ImGuiID close_button_id = (p_open && can_undock) ? GetIDWithSeed("#CLOSE", NULL, docked_window ? docked_window->ID : id) : 0; bool just_closed; bool text_clipped; - TabItemLabelAndCloseButton(display_draw_list, bb, flags, tab_bar->FramePadding, label, id, close_button_id, tab_contents_visible, &just_closed, &text_clipped); + TabItemLabelAndCloseButton(display_draw_list, bb, tab_just_unsaved ? (flags & ~ImGuiTabItemFlags_UnsavedDocument) : flags, tab_bar->FramePadding, label, id, close_button_id, tab_contents_visible, &just_closed, &text_clipped); if (just_closed && p_open != NULL) { *p_open = false; @@ -8327,9 +8651,10 @@ bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open, // (We test IsItemHovered() to discard e.g. when another item is active or drag and drop over the tab bar, which g.HoveredId ignores) // FIXME: This is a mess. // FIXME: We may want disabled tab to still display the tooltip? - if (text_clipped && g.HoveredId == id && !held && g.HoveredIdNotActiveTimer > g.TooltipSlowDelay && IsItemHovered()) + if (text_clipped && g.HoveredId == id && !held) if (!(tab_bar->Flags & ImGuiTabBarFlags_NoTooltip) && !(tab->Flags & ImGuiTabItemFlags_NoTooltip)) - SetTooltip("%.*s", (int)(FindRenderedTextEnd(label) - label), label); + if (IsItemHovered(ImGuiHoveredFlags_DelayNormal)) + SetTooltip("%.*s", (int)(FindRenderedTextEnd(label) - label), label); IM_ASSERT(!is_tab_button || !(tab_bar->SelectedTabId == tab->ID && is_tab_button)); // TabItemButton should not be selected if (is_tab_button) @@ -8363,18 +8688,23 @@ void ImGui::SetTabItemClosed(const char* label) } } -ImVec2 ImGui::TabItemCalcSize(const char* label, bool has_close_button) +ImVec2 ImGui::TabItemCalcSize(const char* label, bool has_close_button_or_unsaved_marker) { ImGuiContext& g = *GImGui; ImVec2 label_size = CalcTextSize(label, NULL, true); ImVec2 size = ImVec2(label_size.x + g.Style.FramePadding.x, label_size.y + g.Style.FramePadding.y * 2.0f); - if (has_close_button) + if (has_close_button_or_unsaved_marker) size.x += g.Style.FramePadding.x + (g.Style.ItemInnerSpacing.x + g.FontSize); // We use Y intentionally to fit the close button circle. else size.x += g.Style.FramePadding.x + 1.0f; return ImVec2(ImMin(size.x, TabBarCalcMaxTabWidth()), size.y); } +ImVec2 ImGui::TabItemCalcSize(ImGuiWindow* window) +{ + return TabItemCalcSize(window->Name, window->HasCloseButton || (window->Flags & ImGuiWindowFlags_UnsavedDocument)); +} + void ImGui::TabItemBackground(ImDrawList* draw_list, const ImRect& bb, ImGuiTabItemFlags flags, ImU32 col) { // While rendering tabs, we trim 1 pixel off the top of our bounding box so they can fit within a regular frame height while looking "detached" from it. diff --git a/extern/imgui_patched/imstb_textedit.h b/extern/imgui_patched/imstb_textedit.h index d9364230..360395ce 100644 --- a/extern/imgui_patched/imstb_textedit.h +++ b/extern/imgui_patched/imstb_textedit.h @@ -2,6 +2,7 @@ // This is a slightly modified version of stb_textedit.h 1.14. // Those changes would need to be pushed into nothings/stb: // - Fix in stb_textedit_discard_redo (see https://github.com/nothings/stb/issues/321) +// - Fix in stb_textedit_find_charpos to handle last line (see https://github.com/ocornut/imgui/issues/6000) // Grep for [DEAR IMGUI] to find the changes. // stb_textedit.h - v1.14 - public domain - Sean Barrett @@ -524,29 +525,14 @@ static void stb_textedit_find_charpos(StbFindState *find, STB_TEXTEDIT_STRING *s int z = STB_TEXTEDIT_STRINGLEN(str); int i=0, first; - if (n == z) { - // if it's at the end, then find the last line -- simpler than trying to - // explicitly handle this case in the regular code - if (single_line) { - STB_TEXTEDIT_LAYOUTROW(&r, str, 0); - find->y = 0; - find->first_char = 0; - find->length = z; - find->height = r.ymax - r.ymin; - find->x = r.x1; - } else { - find->y = 0; - find->x = 0; - find->height = 1; - while (i < z) { - STB_TEXTEDIT_LAYOUTROW(&r, str, i); - prev_start = i; - i += r.num_chars; - } - find->first_char = i; - find->length = 0; - find->prev_first = prev_start; - } + if (n == z && single_line) { + // special case if it's at the end (may not be needed?) + STB_TEXTEDIT_LAYOUTROW(&r, str, 0); + find->y = 0; + find->first_char = 0; + find->length = z; + find->height = r.ymax - r.ymin; + find->x = r.x1; return; } @@ -557,9 +543,13 @@ static void stb_textedit_find_charpos(StbFindState *find, STB_TEXTEDIT_STRING *s STB_TEXTEDIT_LAYOUTROW(&r, str, i); if (n < i + r.num_chars) break; + if (i + r.num_chars == z && z > 0 && STB_TEXTEDIT_GETCHAR(str, z - 1) != STB_TEXTEDIT_NEWLINE) // [DEAR IMGUI] special handling for last line + break; // [DEAR IMGUI] prev_start = i; i += r.num_chars; find->y += r.baseline_y_delta; + if (i == z) // [DEAR IMGUI] + break; // [DEAR IMGUI] } find->first_char = first = i; diff --git a/extern/imgui_patched/imstb_truetype.h b/extern/imgui_patched/imstb_truetype.h index 643d3789..35c827e6 100644 --- a/extern/imgui_patched/imstb_truetype.h +++ b/extern/imgui_patched/imstb_truetype.h @@ -2008,7 +2008,7 @@ static stbtt__buf stbtt__cid_get_glyph_subrs(const stbtt_fontinfo *info, int gly start = end; } } - if (fdselector == -1) stbtt__new_buf(NULL, 0); + if (fdselector == -1) return stbtt__new_buf(NULL, 0); // [DEAR IMGUI] fixed, see #6007 and nothings/stb#1422 return stbtt__get_subrs(info->cff, stbtt__cff_index_get(info->fontdicts, fdselector)); } diff --git a/extern/imgui_patched/misc/cpp/README.txt b/extern/imgui_patched/misc/cpp/README.txt index 42915902..17f0a3cd 100644 --- a/extern/imgui_patched/misc/cpp/README.txt +++ b/extern/imgui_patched/misc/cpp/README.txt @@ -9,5 +9,5 @@ imgui_scoped.h Try by merging: https://github.com/ocornut/imgui/pull/2197 Discuss at: https://github.com/ocornut/imgui/issues/2096 -See more C++ related extension on Wiki +See more C++ related extension (fmt, RAII, syntaxis sugar) on Wiki: https://github.com/ocornut/imgui/wiki/Useful-Extensions#cness diff --git a/extern/imgui_patched/misc/cpp/imgui_stdlib.cpp b/extern/imgui_patched/misc/cpp/imgui_stdlib.cpp index dd6bd8a5..c9060e88 100644 --- a/extern/imgui_patched/misc/cpp/imgui_stdlib.cpp +++ b/extern/imgui_patched/misc/cpp/imgui_stdlib.cpp @@ -4,6 +4,9 @@ // Changelog: // - v0.10: Initial version. Added InputText() / InputTextMultiline() calls with std::string +// See more C++ related extension (fmt, RAII, syntaxis sugar) on Wiki: +// https://github.com/ocornut/imgui/wiki/Useful-Extensions#cness + #include "imgui.h" #include "imgui_stdlib.h" diff --git a/extern/imgui_patched/misc/cpp/imgui_stdlib.h b/extern/imgui_patched/misc/cpp/imgui_stdlib.h index 61afc098..835a808f 100644 --- a/extern/imgui_patched/misc/cpp/imgui_stdlib.h +++ b/extern/imgui_patched/misc/cpp/imgui_stdlib.h @@ -4,6 +4,9 @@ // Changelog: // - v0.10: Initial version. Added InputText() / InputTextMultiline() calls with std::string +// See more C++ related extension (fmt, RAII, syntaxis sugar) on Wiki: +// https://github.com/ocornut/imgui/wiki/Useful-Extensions#cness + #pragma once #include @@ -12,7 +15,7 @@ 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); + IMGUI_API bool InputText(const char* label, std::string* str, ImGuiInputTextFlags flags = 0, ImGuiInputTextCallback callback = nullptr, void* user_data = nullptr); + IMGUI_API bool InputTextMultiline(const char* label, std::string* str, const ImVec2& size = ImVec2(0, 0), ImGuiInputTextFlags flags = 0, ImGuiInputTextCallback callback = nullptr, void* user_data = nullptr); + IMGUI_API bool InputTextWithHint(const char* label, const char* hint, std::string* str, ImGuiInputTextFlags flags = 0, ImGuiInputTextCallback callback = nullptr, void* user_data = nullptr); } diff --git a/extern/imgui_patched/misc/debuggers/imgui.natstepfilter b/extern/imgui_patched/misc/debuggers/imgui.natstepfilter index efd1957b..6825c934 100644 --- a/extern/imgui_patched/misc/debuggers/imgui.natstepfilter +++ b/extern/imgui_patched/misc/debuggers/imgui.natstepfilter @@ -3,14 +3,15 @@ .natstepfilter file for Visual Studio debugger. Purpose: instruct debugger to skip some functions when using StepInto (F11) -To enable: +Since Visual Studio 2022 version 17.6 Preview 2 (currently available as a "Preview" build on March 14, 2023) +It is possible to add the .natstepfilter file to your project file and it will automatically be used. +(https://developercommunity.visualstudio.com/t/allow-natstepfilter-and-natjmc-to-be-included-as-p/561718) + +For older Visual Studio version prior to 2022 17.6 Preview 2: * copy in %USERPROFILE%\Documents\Visual Studio XXXX\Visualizers (current user) * or copy in %VsInstallDirectory%\Common7\Packages\Debugger\Visualizers (all users) -If you have multiple VS version installed, the version that matters is the one you are using the IDE/debugger of (not the compiling toolset). -This is supported since Visual Studio 2012. - -Unfortunately, unlike .natvis files, it isn't yet possible to include this file in your project :( -You may upvote this: https://developercommunity.visualstudio.com/t/allow-natstepfilter-and-natjmc-to-be-included-as-p/561718 +If you have multiple VS version installed, the version that matters is the one you are using the IDE/debugger +of (not the compiling toolset). This is supported since Visual Studio 2012. More information at: https://docs.microsoft.com/en-us/visualstudio/debugger/just-my-code?view=vs-2019#BKMK_C___Just_My_Code --> diff --git a/extern/imgui_patched/misc/fonts/binary_to_compressed_c.cpp b/extern/imgui_patched/misc/fonts/binary_to_compressed_c.cpp index 284f039a..f41d20f7 100644 --- a/extern/imgui_patched/misc/fonts/binary_to_compressed_c.cpp +++ b/extern/imgui_patched/misc/fonts/binary_to_compressed_c.cpp @@ -66,7 +66,7 @@ int main(int argc, char** argv) char Encode85Byte(unsigned int x) { x = (x % 85) + 35; - return (x >= '\\') ? x + 1 : x; + return (char)((x >= '\\') ? x + 1 : x); } bool binary_to_compressed_c(const char* filename, const char* symbol, bool use_base85_encoding, bool use_compression, bool use_static) @@ -263,17 +263,17 @@ static int stb_compress_chunk(stb_uchar *history, int best = 2, dist=0; if (q+65536 > end) - match_max = end-q; + match_max = (stb_uint)(end-q); else match_max = 65536; -#define stb__nc(b,d) ((d) <= window && ((b) > 9 || stb_not_crap(b,d))) +#define stb__nc(b,d) ((d) <= window && ((b) > 9 || stb_not_crap((int)(b),(int)(d)))) #define STB__TRY(t,p) /* avoid retrying a match we already tried */ \ - if (p ? dist != q-t : 1) \ + if (p ? dist != (int)(q-t) : 1) \ if ((m = stb_matchlen(t, q, match_max)) > best) \ if (stb__nc(m,q-(t))) \ - best = m, dist = q - (t) + best = m, dist = (int)(q - (t)) // rather than search for all matches, only try 4 candidate locations, // chosen based on 4 different hash functions of different lengths. @@ -299,24 +299,24 @@ static int stb_compress_chunk(stb_uchar *history, if (best < 3) { // fast path literals ++q; } else if (best > 2 && best <= 0x80 && dist <= 0x100) { - outliterals(lit_start, q-lit_start); lit_start = (q += best); + outliterals(lit_start, (int)(q-lit_start)); lit_start = (q += best); stb_out(0x80 + best-1); stb_out(dist-1); } else if (best > 5 && best <= 0x100 && dist <= 0x4000) { - outliterals(lit_start, q-lit_start); lit_start = (q += best); + outliterals(lit_start, (int)(q-lit_start)); lit_start = (q += best); stb_out2(0x4000 + dist-1); stb_out(best-1); } else if (best > 7 && best <= 0x100 && dist <= 0x80000) { - outliterals(lit_start, q-lit_start); lit_start = (q += best); + outliterals(lit_start, (int)(q-lit_start)); lit_start = (q += best); stb_out3(0x180000 + dist-1); stb_out(best-1); } else if (best > 8 && best <= 0x10000 && dist <= 0x80000) { - outliterals(lit_start, q-lit_start); lit_start = (q += best); + outliterals(lit_start, (int)(q-lit_start)); lit_start = (q += best); stb_out3(0x100000 + dist-1); stb_out2(best-1); } else if (best > 9 && dist <= 0x1000000) { if (best > 65536) best = 65536; - outliterals(lit_start, q-lit_start); lit_start = (q += best); + outliterals(lit_start, (int)(q-lit_start)); lit_start = (q += best); if (best <= 0x100) { stb_out(0x06); stb_out3(dist-1); @@ -336,10 +336,10 @@ static int stb_compress_chunk(stb_uchar *history, q = start+length; // the literals are everything from lit_start to q - *pending_literals = (q - lit_start); + *pending_literals = (int)(q - lit_start); - stb__running_adler = stb_adler32(stb__running_adler, start, q - start); - return q - start; + stb__running_adler = stb_adler32(stb__running_adler, start, (stb_uint)(q - start)); + return (int)(q - start); } static int stb_compress_inner(stb_uchar *input, stb_uint length) @@ -349,9 +349,9 @@ static int stb_compress_inner(stb_uchar *input, stb_uint length) stb_uchar **chash; chash = (stb_uchar**) malloc(stb__hashsize * sizeof(stb_uchar*)); - if (chash == NULL) return 0; // failure + if (chash == nullptr) return 0; // failure for (i=0; i < stb__hashsize; ++i) - chash[i] = NULL; + chash[i] = nullptr; // stream signature stb_out(0x57); stb_out(0xbc); @@ -380,9 +380,9 @@ static int stb_compress_inner(stb_uchar *input, stb_uint length) stb_uint stb_compress(stb_uchar *out, stb_uchar *input, stb_uint length) { stb__out = out; - stb__outfile = NULL; + stb__outfile = nullptr; stb_compress_inner(input, length); - return stb__out - out; + return (stb_uint)(stb__out - out); } diff --git a/extern/imgui_patched/misc/freetype/README.md b/extern/imgui_patched/misc/freetype/README.md index 5fcfc2d7..140ae225 100644 --- a/extern/imgui_patched/misc/freetype/README.md +++ b/extern/imgui_patched/misc/freetype/README.md @@ -24,7 +24,7 @@ See https://gist.github.com/ocornut/b3a9ecf13502fd818799a452969649ad - Oversampling settins are ignored but also not so much necessary with the higher quality rendering. -### Comparaison +### Comparison Small, thin anti-aliased fonts typically benefit a lot from FreeType's hinting: ![comparing_font_rasterizers](https://user-images.githubusercontent.com/8225057/107550178-fef87f00-6bd0-11eb-8d09-e2edb2f0ccfc.gif) diff --git a/extern/imgui_patched/misc/freetype/imgui_freetype.cpp b/extern/imgui_patched/misc/freetype/imgui_freetype.cpp index 4066a9a6..503430a6 100644 --- a/extern/imgui_patched/misc/freetype/imgui_freetype.cpp +++ b/extern/imgui_patched/misc/freetype/imgui_freetype.cpp @@ -6,6 +6,7 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) +// 2023/01/04: fixed a packing issue which in some occurrences would prevent large amount of glyphs from being packed correctly. // 2021/08/23: fixed crash when FT_Render_Glyph() fails to render a glyph and returns NULL. // 2021/03/05: added ImGuiFreeTypeBuilderFlags_Bitmap to load bitmap glyphs. // 2021/03/02: set 'atlas->TexPixelsUseColors = true' to help some backends with deciding of a prefered texture format. @@ -42,13 +43,16 @@ #include FT_SYNTHESIS_H // #ifdef _MSC_VER +#pragma warning (push) #pragma warning (disable: 4505) // unreferenced local function has been removed (stb stuff) #pragma warning (disable: 26812) // [Static Analyzer] The enum type 'xxx' is unscoped. Prefer 'enum class' over 'enum' (Enum.3). #endif -#if defined(__GNUC__) +#ifdef __GNUC__ +#pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wpragmas" // warning: unknown option after '#pragma GCC diagnostic' kind #pragma GCC diagnostic ignored "-Wunused-function" // warning: 'xxxx' defined but not used +#pragma GCC diagnostic ignored "-Wsubobject-linkage" // warning: 'xxxx' has a field 'xxxx' whose type uses the anonymous namespace #endif //------------------------------------------------------------------------- @@ -62,7 +66,7 @@ static void ImGuiFreeTypeDefaultFreeFunc(void* ptr, void* user_data) { IM_UNUSE // Current memory allocators static void* (*GImGuiFreeTypeAllocFunc)(size_t size, void* user_data) = ImGuiFreeTypeDefaultAllocFunc; static void (*GImGuiFreeTypeFreeFunc)(void* ptr, void* user_data) = ImGuiFreeTypeDefaultFreeFunc; -static void* GImGuiFreeTypeAllocatorUserData = NULL; +static void* GImGuiFreeTypeAllocatorUserData = nullptr; //------------------------------------------------------------------------- // Code @@ -132,7 +136,7 @@ namespace void SetPixelHeight(int pixel_height); // Change font pixel size. All following calls to RasterizeGlyph() will use this size const FT_Glyph_Metrics* LoadGlyph(uint32_t in_codepoint); const FT_Bitmap* RenderGlyphAndGetInfo(GlyphInfo* out_glyph_info); - void BlitGlyph(const FT_Bitmap* ft_bitmap, uint32_t* dst, uint32_t dst_pitch, unsigned char* multiply_table = NULL); + void BlitGlyph(const FT_Bitmap* ft_bitmap, uint32_t* dst, uint32_t dst_pitch, unsigned char* multiply_table = nullptr); ~FreeTypeFont() { CloseFont(); } // [Internals] @@ -194,7 +198,7 @@ namespace if (Face) { FT_Done_Face(Face); - Face = NULL; + Face = nullptr; } } @@ -225,7 +229,7 @@ namespace { uint32_t glyph_index = FT_Get_Char_Index(Face, codepoint); if (glyph_index == 0) - return NULL; + return nullptr; // If this crash for you: FreeType 2.11.0 has a crash bug on some bitmap/colored fonts. // - https://gitlab.freedesktop.org/freetype/freetype/-/issues/1076 @@ -234,7 +238,7 @@ namespace // You can use FreeType 2.10, or the patched version of 2.11.0 in VcPkg, or probably any upcoming FreeType version. FT_Error error = FT_Load_Glyph(Face, glyph_index, LoadFlags); if (error) - return NULL; + return nullptr; // Need an outline for this to work FT_GlyphSlot slot = Face->glyph; @@ -260,7 +264,7 @@ namespace FT_GlyphSlot slot = Face->glyph; FT_Error error = FT_Render_Glyph(slot, RenderMode); if (error != 0) - return NULL; + return nullptr; FT_Bitmap* ft_bitmap = &Face->glyph->bitmap; out_glyph_info->Width = (int)ft_bitmap->width; @@ -275,7 +279,7 @@ namespace void FreeTypeFont::BlitGlyph(const FT_Bitmap* ft_bitmap, uint32_t* dst, uint32_t dst_pitch, unsigned char* multiply_table) { - IM_ASSERT(ft_bitmap != NULL); + IM_ASSERT(ft_bitmap != nullptr); const uint32_t w = ft_bitmap->width; const uint32_t h = ft_bitmap->rows; const uint8_t* src = ft_bitmap->buffer; @@ -285,7 +289,7 @@ namespace { case FT_PIXEL_MODE_GRAY: // Grayscale image, 1 byte per pixel. { - if (multiply_table == NULL) + if (multiply_table == nullptr) { for (uint32_t y = 0; y < h; y++, src += src_pitch, dst += dst_pitch) for (uint32_t x = 0; x < w; x++) @@ -320,7 +324,7 @@ namespace { // FIXME: Converting pre-multiplied alpha to straight. Doesn't smell good. #define DE_MULTIPLY(color, alpha) (ImU32)(255.0f * (float)color / (float)alpha + 0.5f) - if (multiply_table == NULL) + if (multiply_table == nullptr) { for (uint32_t y = 0; y < h; y++, src += src_pitch, dst += dst_pitch) for (uint32_t x = 0; x < w; x++) @@ -347,7 +351,7 @@ namespace IM_ASSERT(0 && "FreeTypeFont::BlitGlyph(): Unknown bitmap pixel mode!"); } } -} +} // namespace #ifndef STB_RECT_PACK_IMPLEMENTATION // in case the user already have an implementation in the _same_ compilation unit (e.g. unity builds) #ifndef IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION @@ -399,7 +403,7 @@ bool ImFontAtlasBuildWithFreeTypeEx(FT_Library ft_library, ImFontAtlas* atlas, u ImFontAtlasBuildInit(atlas); // Clear atlas - atlas->TexID = (ImTextureID)NULL; + atlas->TexID = (ImTextureID)nullptr; atlas->TexWidth = atlas->TexHeight = 0; atlas->TexUvScale = ImVec2(0.0f, 0.0f); atlas->TexUvWhitePixel = ImVec2(0.0f, 0.0f); @@ -440,7 +444,12 @@ bool ImFontAtlasBuildWithFreeTypeEx(FT_Library ft_library, ImFontAtlas* atlas, u ImFontBuildDstDataFT& dst_tmp = dst_tmp_array[src_tmp.DstIndex]; src_tmp.SrcRanges = cfg.GlyphRanges ? cfg.GlyphRanges : atlas->GetGlyphRangesDefault(); for (const ImWchar* src_range = src_tmp.SrcRanges; src_range[0] && src_range[1]; src_range += 2) + { + // Check for valid range. This may also help detect *some* dangling pointers, because a common + // user error is to setup ImFontConfig::GlyphRanges with a pointer to data that isn't persistent. + IM_ASSERT(src_range[0] <= src_range[1]); src_tmp.GlyphsHighest = ImMax(src_tmp.GlyphsHighest, (int)src_range[1]); + } dst_tmp.SrcCount++; dst_tmp.GlyphsHighest = ImMax(dst_tmp.GlyphsHighest, src_tmp.GlyphsHighest); } @@ -508,7 +517,7 @@ bool ImFontAtlasBuildWithFreeTypeEx(FT_Library ft_library, ImFontAtlas* atlas, u // Allocate temporary rasterization data buffers. // We could not find a way to retrieve accurate glyph size without rendering them. // (e.g. slot->metrics->width not always matching bitmap->width, especially considering the Oblique transform) - // We allocate in chunks of 256 KB to not waste too much extra memory ahead. Hopefully users of FreeType won't find the temporary allocations. + // We allocate in chunks of 256 KB to not waste too much extra memory ahead. Hopefully users of FreeType won't mind the temporary allocations. const int BITMAP_BUFFERS_CHUNK_SIZE = 256 * 1024; int buf_bitmap_current_used_bytes = 0; ImVector buf_bitmap_buffers; @@ -541,12 +550,12 @@ bool ImFontAtlasBuildWithFreeTypeEx(FT_Library ft_library, ImFontAtlas* atlas, u ImFontBuildSrcGlyphFT& src_glyph = src_tmp.GlyphsList[glyph_i]; const FT_Glyph_Metrics* metrics = src_tmp.Font.LoadGlyph(src_glyph.Codepoint); - if (metrics == NULL) + if (metrics == nullptr) continue; // Render glyph into a bitmap (currently held by FreeType) const FT_Bitmap* ft_bitmap = src_tmp.Font.RenderGlyphAndGetInfo(&src_glyph.Info); - if (ft_bitmap == NULL) + if (ft_bitmap == nullptr) continue; // Allocate new temporary chunk if needed @@ -556,11 +565,12 @@ bool ImFontAtlasBuildWithFreeTypeEx(FT_Library ft_library, ImFontAtlas* atlas, u buf_bitmap_current_used_bytes = 0; buf_bitmap_buffers.push_back((unsigned char*)IM_ALLOC(BITMAP_BUFFERS_CHUNK_SIZE)); } + IM_ASSERT(buf_bitmap_current_used_bytes + bitmap_size_in_bytes <= BITMAP_BUFFERS_CHUNK_SIZE); // We could probably allocate custom-sized buffer instead. // Blit rasterized pixels to our temporary buffer and keep a pointer to it. src_glyph.BitmapData = (unsigned int*)(buf_bitmap_buffers.back() + buf_bitmap_current_used_bytes); buf_bitmap_current_used_bytes += bitmap_size_in_bytes; - src_tmp.Font.BlitGlyph(ft_bitmap, src_glyph.BitmapData, src_glyph.Info.Width, multiply_enabled ? multiply_table : NULL); + src_tmp.Font.BlitGlyph(ft_bitmap, src_glyph.BitmapData, src_glyph.Info.Width, multiply_enabled ? multiply_table : nullptr); src_tmp.Rects[glyph_i].w = (stbrp_coord)(src_glyph.Info.Width + padding); src_tmp.Rects[glyph_i].h = (stbrp_coord)(src_glyph.Info.Height + padding); @@ -585,7 +595,7 @@ bool ImFontAtlasBuildWithFreeTypeEx(FT_Library ft_library, ImFontAtlas* atlas, u ImVector pack_nodes; pack_nodes.resize(num_nodes_for_packing_algorithm); stbrp_context pack_context; - stbrp_init_target(&pack_context, atlas->TexWidth, TEX_HEIGHT_MAX, pack_nodes.Data, pack_nodes.Size); + stbrp_init_target(&pack_context, atlas->TexWidth - atlas->TexGlyphPadding, TEX_HEIGHT_MAX - atlas->TexGlyphPadding, pack_nodes.Data, pack_nodes.Size); ImFontAtlasBuildPackCustomRects(atlas, &pack_context); // 6. Pack each source font. No rendering yet, we are working with rectangles in an infinitely tall texture at this point. @@ -676,7 +686,7 @@ bool ImFontAtlasBuildWithFreeTypeEx(FT_Library ft_library, ImFontAtlas* atlas, u size_t blit_src_stride = (size_t)src_glyph.Info.Width; size_t blit_dst_stride = (size_t)atlas->TexWidth; unsigned int* blit_src = src_glyph.BitmapData; - if (atlas->TexPixelsAlpha8 != NULL) + if (atlas->TexPixelsAlpha8 != nullptr) { unsigned char* blit_dst = atlas->TexPixelsAlpha8 + (ty * blit_dst_stride) + tx; for (int y = 0; y < info.Height; y++, blit_dst += blit_dst_stride, blit_src += blit_src_stride) @@ -692,7 +702,7 @@ bool ImFontAtlasBuildWithFreeTypeEx(FT_Library ft_library, ImFontAtlas* atlas, u } } - src_tmp.Rects = NULL; + src_tmp.Rects = nullptr; } atlas->TexPixelsUseColors = tex_use_colors; @@ -720,13 +730,13 @@ static void FreeType_Free(FT_Memory /*memory*/, void* block) static void* FreeType_Realloc(FT_Memory /*memory*/, long cur_size, long new_size, void* block) { // Implement realloc() as we don't ask user to provide it. - if (block == NULL) + if (block == nullptr) return GImGuiFreeTypeAllocFunc((size_t)new_size, GImGuiFreeTypeAllocatorUserData); if (new_size == 0) { GImGuiFreeTypeFreeFunc(block, GImGuiFreeTypeAllocatorUserData); - return NULL; + return nullptr; } if (new_size > cur_size) @@ -744,7 +754,7 @@ static bool ImFontAtlasBuildWithFreeType(ImFontAtlas* atlas) { // FreeType memory management: https://www.freetype.org/freetype2/docs/design/design-4.html FT_MemoryRec_ memory_rec = {}; - memory_rec.user = NULL; + memory_rec.user = nullptr; memory_rec.alloc = &FreeType_Alloc; memory_rec.free = &FreeType_Free; memory_rec.realloc = &FreeType_Realloc; @@ -777,3 +787,11 @@ void ImGuiFreeType::SetAllocatorFunctions(void* (*alloc_func)(size_t sz, void* u GImGuiFreeTypeFreeFunc = free_func; GImGuiFreeTypeAllocatorUserData = user_data; } + +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif + +#ifdef _MSC_VER +#pragma warning (pop) +#endif diff --git a/extern/imgui_patched/misc/freetype/imgui_freetype.h b/extern/imgui_patched/misc/freetype/imgui_freetype.h index 713e4639..80a1f95e 100644 --- a/extern/imgui_patched/misc/freetype/imgui_freetype.h +++ b/extern/imgui_patched/misc/freetype/imgui_freetype.h @@ -40,7 +40,7 @@ namespace ImGuiFreeType // Override allocators. By default ImGuiFreeType will use IM_ALLOC()/IM_FREE() // However, as FreeType does lots of allocations we provide a way for the user to redirect it to a separate memory heap if desired. - IMGUI_API void SetAllocatorFunctions(void* (*alloc_func)(size_t sz, void* user_data), void (*free_func)(void* ptr, void* user_data), void* user_data = NULL); + IMGUI_API void SetAllocatorFunctions(void* (*alloc_func)(size_t sz, void* user_data), void (*free_func)(void* ptr, void* user_data), void* user_data = nullptr); // Obsolete names (will be removed soon) // Prefer using '#define IMGUI_ENABLE_FREETYPE' diff --git a/extern/imgui_patched/misc/single_file/imgui_single_file.h b/extern/imgui_patched/misc/single_file/imgui_single_file.h index 6c1fb369..7ca31e0f 100644 --- a/extern/imgui_patched/misc/single_file/imgui_single_file.h +++ b/extern/imgui_patched/misc/single_file/imgui_single_file.h @@ -7,7 +7,15 @@ // #define IMGUI_IMPLEMENTATION // Before you include this file in *one* C++ file to create the implementation. // Using this in your project will leak the contents of imgui_internal.h and ImVec2 operators in this compilation unit. + +#ifdef IMGUI_IMPLEMENTATION +#define IMGUI_DEFINE_MATH_OPERATORS +#endif + #include "../../imgui.h" +#ifdef IMGUI_ENABLE_FREETYPE +#include "../../misc/freetype/imgui_freetype.h" +#endif #ifdef IMGUI_IMPLEMENTATION #include "../../imgui.cpp" @@ -15,4 +23,7 @@ #include "../../imgui_draw.cpp" #include "../../imgui_tables.cpp" #include "../../imgui_widgets.cpp" +#ifdef IMGUI_ENABLE_FREETYPE +#include "../../misc/freetype/imgui_freetype.cpp" +#endif #endif diff --git a/instruments/FM/drums/OPM Power Snare.fui b/instruments/FM/drums/OPM Power Snare.fui new file mode 100644 index 00000000..58846582 Binary files /dev/null and b/instruments/FM/drums/OPM Power Snare.fui differ diff --git a/instruments/other/AY Heavy Kick and Snare.fui b/instruments/other/AY Heavy Kick and Snare.fui new file mode 100644 index 00000000..2bcb7d95 Binary files /dev/null and b/instruments/other/AY Heavy Kick and Snare.fui differ diff --git a/instruments/other/AY Heavy Kick.fui b/instruments/other/AY Heavy Kick.fui new file mode 100644 index 00000000..3f3de6fc Binary files /dev/null and b/instruments/other/AY Heavy Kick.fui differ diff --git a/papers/doc/1-intro/README.md b/papers/doc/1-intro/README.md deleted file mode 100644 index a550aca1..00000000 --- a/papers/doc/1-intro/README.md +++ /dev/null @@ -1,27 +0,0 @@ -# introduction - -Furnace is a tool which allows you to create music using emulated sound chips from the 8/16-bit era. -For a full list of soundchips that Furnace supports, please see [this list](https://github.com/tildearrow/furnace/tree/master/papers/doc/7-systems). - -It has a music tracker interface. think of a piano roll, or a table that scrolls up and plays the notes. - -Another core feature of Furnace is its windowing system, similar to that of GEMS or Deflemask, but with a few more features. - -## Sound generation - -Furnace generates sound from 3 different main types of sound sources. - - Instruments are the most standard and most used type of sound source in Furnace. -The instrument format is how you can specify parameters and macros for certain channels on certain soundchips, as well as binding samples and wavetables to a format that you can sequence on the note grid. -See [4-instrument](https://github.com/tildearrow/furnace/tree/master/papers/doc/4-instrument) for more details. - - Wavetables are the way that you create custom waveform shapes for the HuC6280, Seta X1-010, WonderSwan, any PCM chip with wavetable synthesizer support, etc. -Wavetables only work in the sequencer if you bind them to an instrument. See [4-instrument](https://github.com/tildearrow/furnace/tree/master/papers/doc/4-instrument) and [5-wave](https://github.com/tildearrow/furnace/tree/master/papers/doc/5-wave) for more details. - - Samples are how you play back raw audio streams (samples) on certain channels, on certain soundchips, and in some cases, in certain modes. -To sequence a sample, you do not need to assign it to an instrument, however, to resample samples (change the speed of a sample), you need to bind it to a Sample instrument. -See [6-sample](https://github.com/tildearrow/furnace/tree/master/papers/doc/6-sample) and [4-instrument](https://github.com/tildearrow/furnace/tree/master/papers/doc/4-instrument) for more details. - -## Interface/other - -Furnace is built to have a user-friendly interface that is intentionally made so that it is quick and easy to get around when working in Furnace. -However, we understand that the interface may not be the easiest to learn, depending on how you learn, so there is documentation on it as well. - -See [2-interface](https://github.com/tildearrow/furnace/tree/master/papers/doc/2-interface) and [3-pattern](https://github.com/tildearrow/furnace/tree/master/papers/doc/3-pattern) to view said documentation. diff --git a/papers/doc/2-interface/README.md b/papers/doc/2-interface/README.md deleted file mode 100644 index c61bf575..00000000 --- a/papers/doc/2-interface/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# interface - -the Furnace user interface is where the job gets done. - -- [UI components](components.md) -- [global keyboard shortcuts](keyboard.md) -- [basic mode](basic-mode.md) diff --git a/papers/doc/3-pattern/channelbar.png b/papers/doc/3-pattern/channelbar.png deleted file mode 100644 index 61a62133..00000000 Binary files a/papers/doc/3-pattern/channelbar.png and /dev/null differ diff --git a/papers/doc/3-pattern/channels.png b/papers/doc/3-pattern/channels.png deleted file mode 100644 index 6f9f04f2..00000000 Binary files a/papers/doc/3-pattern/channels.png and /dev/null differ diff --git a/papers/doc/3-pattern/keyboard.png b/papers/doc/3-pattern/keyboard.png deleted file mode 100644 index 67f0b78d..00000000 Binary files a/papers/doc/3-pattern/keyboard.png and /dev/null differ diff --git a/papers/doc/3-pattern/pattern.png b/papers/doc/3-pattern/pattern.png deleted file mode 100644 index e6abde48..00000000 Binary files a/papers/doc/3-pattern/pattern.png and /dev/null differ diff --git a/papers/doc/4-instrument/8930.md b/papers/doc/4-instrument/8930.md deleted file mode 100644 index d155a511..00000000 --- a/papers/doc/4-instrument/8930.md +++ /dev/null @@ -1,14 +0,0 @@ -# AY8930 instrument editor - -AY8930 instrument editor consists of 10 macros. - -- [Volume] - volume levels sequence -- [Arpeggio]- pitch sequence -- [Noise frequency] - AY8930 noise generator frequency sequence -- [Waveform] - selector of sound type - pulse wave tone, noise or envelope generator -- [Duty cycle] - duty cycle of a pulse wave sequence -- [Envelope] - allows shaping an envelope -- [Auto envelope numerator] - sets the envelope to the channel's frequency multiplied by numerator -- [Auto envelope denominator] - sets the envelope to the channel's frequency multiplied by denominator -- [Noise AND mask] - alters the shape/frequency of the noise generator, allowing to produce various interesting sound effects and even PWM phasing -- [Noise OR mask] - see above diff --git a/papers/doc/4-instrument/README.md b/papers/doc/4-instrument/README.md deleted file mode 100644 index 58d7bac9..00000000 --- a/papers/doc/4-instrument/README.md +++ /dev/null @@ -1,45 +0,0 @@ -# instrument list - -![instrument list](list.png) - -click on an instrument to select it. - -double-click to open the instrument editor. - -# instrument editor - -every instrument can be renamed and have its type changed. - -depending on the instrument type, there are currently 13 different types of an instrument editor: - -- [FM synthesis](fm.md) - for use with YM2612, YM2151 and FM block portion of YM2610. -- [Standard](standard.md) - for use with NES and Sega Master System's PSG sound source and its derivatives. -- [Game Boy](game-boy.md) - for use with Game Boy APU. -- [PC Engine/TurboGrafx-16](pce.md) - for use with PC Engine's wavetable synthesizer. -- [WonderSwan](wonderswan.md) - for use with WonderSwan's wavetable synthesizer. -- [AY8930](8930.md) - for use with Microchip AY8930 E-PSG sound source. -- [Commodore 64](c64.md) - for use with Commodore 64 SID. -- [SAA1099](saa.md) - for use with Philips SAA1099 PSG sound source. -- [TIA](tia.md) - for use with Atari 2600 chip. -- [AY-3-8910](ay8910.md) - for use with AY-3-8910 PSG sound source and SSG portion in YM2610. -- [Amiga/sample](amiga.md) for controlling Amiga and other sample based synthsizers like YM2612's Channel 6 PCM mode, NES channel 5, Sega PCM, X1-010 and PC Engine's sample playback mode. -- [Atari Lynx](lynx.md) - for use with Atari Lynx handheld console. -- [VERA](vera.md) - for use with Commander X16 VERA. -- [Seta/Allumer X1-010](x1_010.md) - for use with Wavetable portion in Seta/Allumer X1-010. -- [Konami SCC/Bubble System WSG](scc.md) - for use with Konami SCC and Wavetable portion in Bubble System's sound hardware. -- [Namco 163](n163.md) - for use with Namco 163. -- [Konami VRC6](vrc6.md) - for use with VRC6's PSG sound source. - -# macros - -one common feature to instruments is macros (also known as sequences). - -these run on every tick and are useful for controlling parameters automatically. - -![macro view](macro.png) - -to change the loop portion/point, click on the bar under the macro. -right click on it to disable macro loop. - -to change the release point, shift-click the bar under the macro. -shift-right click on it to remove the release point. diff --git a/papers/doc/4-instrument/amiga.md b/papers/doc/4-instrument/amiga.md deleted file mode 100644 index 9c9a86ac..00000000 --- a/papers/doc/4-instrument/amiga.md +++ /dev/null @@ -1,13 +0,0 @@ -# Amiga/PCM sound sourceinstrument editor - -PCM instrument editor consists of four macros and sample selector: - -# Amiga/sample - -- [Initial sample] - specifies which sample should be assigned to the instrument, or the first one in the sequence - -# Macros - -- [Volume] - volume sequence WARNING: it works only on Amiga system, as of version 0.5.5!! -- [Arpeggio] - pitch sequence -- [Waveform] - sample sequence diff --git a/papers/doc/4-instrument/ay8910.md b/papers/doc/4-instrument/ay8910.md deleted file mode 100644 index 732d4e5e..00000000 --- a/papers/doc/4-instrument/ay8910.md +++ /dev/null @@ -1,11 +0,0 @@ -# AY-3-8910 instrument editor - -AY-3-8910 instrument editor consists of 7 macros. - -- [Volume] - volume levels sequence -- [Arpeggio]- pitch sequence -- [Noise frequency] - AY-3-8910 noise generator frequency sequence -- [Waveform] - selector of sound type - square wave tone, noise or envelope generator -- [Envelope] - allows shaping an envelope -- [Auto envelope numerator] - sets the envelope to the channel's frequency multiplied by numerator -- [Auto envelope denominator] - ets the envelope to the channel's frequency multiplied by denominator diff --git a/papers/doc/4-instrument/c64.md b/papers/doc/4-instrument/c64.md deleted file mode 100644 index 9d612f47..00000000 --- a/papers/doc/4-instrument/c64.md +++ /dev/null @@ -1,30 +0,0 @@ -# C64 SID instrument editor - -C64 instrument editor consists of two tabs: one controlling various parameters of sound channels and macro tab containing seven macros: - -## C64 -- [Waveform] - allows selecting a waveform. NOTE: more than one waveform can be selected at once, logical AND mix of waves will be produced, with an exception of a noise waveform, it can't be mixed. -- [Attack] - determines the rising time for the sound. The bigger the value, the slower the attack. (0-15 range) -- [Decay]- Determines the diminishing time for the sound. The higher the value, the longer the decay. It's the initial amplitude decay rate. (0-15 range) -- [Sustain] - Determines the diminishing time for the sound. The higher the value, the longer the decay. This is the long "tail" of the sound that continues as long as the key is depressed. (0-15 range) -- [Release] - Determines the rate at which the sound disappears after KEY-OFF. The higher the value, the longer the release. (0-15 range) -- [Ring Modulation] - enables the ring modulation affecting the instrument. -- [Duty] - specifies the width of a pulse wave. (0-4095 range) -- [Oscillator Sync] - enables the oscillator hard sync. As one oscillator finishes a cycle, it resets the period of another oscillator, forcing the latter to have the same base frequency. This can produce a harmonically rich sound, the timbre of which can be altered by varying the synced oscillator's frequency. -- [Enable filter] - enables analogue filter affecting the instrument -- [Initialize filter] - initializes the filter with the specified parameters: -- [Cutoff] - defines the "intensity" of a filter, to put in in layman terms (0-2047 range) -- [Resonance] - defines an additional controlled amplification of that cutoff frequency, creating a secondary peak forms and colors the original pitch. (0-15 range) -- [Filter mode] - determined the filter mode NOTE: SID's filter is muliti-mode, you can mix different modes together (like low and high-pass filters at once) CH3-OFF disables the channel 3, for no reason whatsoever lmao -- [Volume Macrio is a Cutoff macro] - turns a volume macro in a macros tab into a filter cutoff macro. -- [Absolute Cutoff macro] - changes the behaviour of a cutoff macro from the old-style, compatible to much more define-able. -- [Absolute Duty macro] - changes the behaviour of a duty cycle macro from the old-style, compatible to much more define-able. - -## Macros -- [Volume/Cutoff] - volume sequence (WARNING: Volume sequence is global for ALL three channels!!) -- [Arpeggio] - pitch sequence -- [Duty cycle] - pulse duty cycle sequence -- [Waveform] - select the waveform used by instrument -- [Filter mode] - select the filter mode/sequence -- [Resonance] - filter resonance sequence -- [Special] - ring and oscillator sync selector diff --git a/papers/doc/4-instrument/fm.md b/papers/doc/4-instrument/fm.md deleted file mode 100644 index 68c8f32d..00000000 --- a/papers/doc/4-instrument/fm.md +++ /dev/null @@ -1,48 +0,0 @@ -# FM synthesis instrument editor - -FM editor is divided into 7 tabs: - -- [FM] - for controlling the basic parameters of FM sound source. -- [Macros (FM)]- for macros controlling algorithm, feedback and LFO -- [Macros (OP1)] - for macros controlling FM paramets of operator 1 -- [Macros (OP2)] - for macros controlling FM paramets of operator 2 -- [Macros (OP3)] - for macros controlling FM paramets of operator 3 -- [Macros (OP4)] - for macros controlling FM paramets of operator 4 -- [Macros] - for miscellaneous macros controlling volume, argeggio and YM2151 noise generator. - -## FM - -FM synthesizers Furnace supports are for-operator, meaning it takes four oscillators to produce a single sound. Each operator is controlled by a dozen of sliders: - -- [Attack Rate (AR)] - determines the rising time for the sound. The bigger the value, the faster the attack. (0-31 range) -- [Decay Rate (DR)]- Determines the diminishing time for the sound. The higher the value, the shorter the decay. It's the initial amplitude decay rate. (0-31 range) -- [Secondary Decay Rate (DR2)/Sustain Rate (SR)] - Determines the diminishing time for the sound. The higher the value, the shorter the decay. This is the long "tail" of the sound that continues as long as the key is depressed. (0-31 range) -- [Release Rate (RR)] - Determines the rate at which the sound disappears after KEY-OFF. The higher the value, the shorter the release. (0-15 range) -- [Sustain Level(SL)] - Determines the point at which the sound ceases to decay and changes to a sound having a constant level. The sustain level is expressed as a fraction of the maximum level. (0-15 range) -- [Total Level (TL)] - Represents the envelope’s highest amplitude, with 0 being the largest and 127 (decimal) the smallest. A change of one unit is about 0.75 dB. -- [Envelope Scale (KSR)] - A parameter that determines the degree to which the envelope execution speed increases according to the pitch. (0-3 range) -- [Frequency Multiplier (MULT)] - Determines the operator frequency in relation to the pitch. (0-15 range) -- [Fine Detune (DT)] - Shifts the pitch a little (0-7 range) -- [Coarse Detune (DT2)] - Shifts the pitch by tens of cents (0-3 range) WARNING: this parameter affects only YM2151 sound source!!! -- [Hardware Envelope Generator (SSG-EG)] - Executes the built-in envelope, inherited from AY-3-8910 PSG. Speed of execution is controlled via Decay Rate. WARNING: this parameter affects only YM2610/YM2612 sound source!!! -- [Algorithm (AL)] - Determines how operators are connected to each other. (0-7 range) -- [Feedback (FB)] - Determines the amount of signal whick operator 1 returns to itself. (0-7 range) -- [Amplitude Modulation (AM)] - Makes the operator affected by LFO. -- [LFO Frequency Sensitivity] - Determines the amount of LFO frequency changes. (0-7 range) -- [LFO Amplitude Sensitivity (AM)] - Determines the amount of LFO frequency changes. (0-3 range) - -## Macros - -Macros define the sequence of values passed to the given parameter. Via macro, aside previously mentioned parameters, the following can be controlled: - -- LFO Frequency -- LFO waveform selection WARNING: this parameter affects only YM2151 sound source!!! -- Amplitude Modulation Depth WARNING: this parameter affects only YM2151 sound source!!! -- Frequency Modulation Depth WARNING: this parameter affects only YM2151 sound source!!! -- Arpeggio Macro: pitch change sequence in semitones. Two modes are available: -Absolute (default) - Executes the pitch with absolute change based on the pitch of the actual note. -Fixed - Executes at the pitch specified in the sequence regardless of the note pitch. -- Noise Frequency: specifies the noise frequency in noise mode of YM2151's Channel 8 Operator 4 special mode. - -Loop -You can loop the execution of part of a sequence. Left-click anywhere on the Loop line at the bottom of the editor to create a loop. You can move the start and end points of the loop by dragging both ends of the loop. diff --git a/papers/doc/4-instrument/game-boy.md b/papers/doc/4-instrument/game-boy.md deleted file mode 100644 index 69401cb0..00000000 --- a/papers/doc/4-instrument/game-boy.md +++ /dev/null @@ -1,17 +0,0 @@ -# Game Boy instrument editor - -GB instrument editor consists of two tabs: one controlling envelope of sound channels and macro tab containing only four macros: - -## Game Boy - -- [Volume] - this slider affect the channel volume (range 0-15) -- [Envelope length] - this slider specifies the envelope decay/attack (range 0-7) -- [Sound length] - this slider cuts off the sound after specified length, overriding the previous slider's value - -- [UP an DOWN radio buttons] - these buttons alter the behaviour of a second slider. Up makes it specify the envelope attack, down the decay. WARNING: for envelope attack to have any effect, volume should be at the lower rates! - -## Macros -- [Volume] - volume sequence -- [Arpeggio] - pitch sequence -- [Duty cycle] - pulse wave channels duty cycle sequence -- [Waveform] - ch3 wavetable sequence diff --git a/papers/doc/4-instrument/list.png b/papers/doc/4-instrument/list.png deleted file mode 100644 index d85cea62..00000000 Binary files a/papers/doc/4-instrument/list.png and /dev/null differ diff --git a/papers/doc/4-instrument/macro.png b/papers/doc/4-instrument/macro.png deleted file mode 100644 index 42a2a635..00000000 Binary files a/papers/doc/4-instrument/macro.png and /dev/null differ diff --git a/papers/doc/4-instrument/n163.md b/papers/doc/4-instrument/n163.md deleted file mode 100644 index ca4dd2e7..00000000 --- a/papers/doc/4-instrument/n163.md +++ /dev/null @@ -1,23 +0,0 @@ -# Namco 163 instrument editor - -Namco 163 instrument editor consists of two tabs: one controlling various parameters for waveform initialize and macro tab containing 10 macros. - -## Namco 163 -- [Initial Waveform] - Determines the initial waveform for playing. -- [Initial Waveform position in RAM] - Determines the initial waveform position will be load to RAM. -- [Initial Waveform length in RAM] - Determines the initial waveform length will be load to RAM. -- [Load waveform before playback] - Determines the load initial waveform into RAM before playback. -- [Update waveforms into RAM when every waveform changes] - Determines the update every different waveform changes in playback. - - -## Macros -- [Volume] - volume levels sequence -- [Arpeggio]- pitch sequence -- [Waveform pos.] - sets the waveform source address in RAM for playback (single nibble unit) -- [Waveform] - sets waveform source for playback immediately or update later -- [Waveform len.] - sets the waveform source length for playback (4 nibble unit) -- [Waveform update] - sets the waveform update trigger behavior for playback -- [Waveform to load] - sets waveform source for load to RAM immediately or later -- [Wave pos. to load] - sets address of waveform for load to RAM (single nibble unit) -- [Wave len. to load] - sets length of waveform for load to RAM (4 nibble unit) -- [Waveform load] - sets the waveform load trigger behavior diff --git a/papers/doc/4-instrument/pce.md b/papers/doc/4-instrument/pce.md deleted file mode 100644 index ac0a6824..00000000 --- a/papers/doc/4-instrument/pce.md +++ /dev/null @@ -1,9 +0,0 @@ -# NEC PC Engine instrument editor - -PCE instrument editor consists of only three macros, almost like TIA: - -- [Volume] - volume sequence -- [Arpeggio] - pitch sequence -- [Waveform] - spicifies wavetables sequence - -It also has wavetable synthesizer support, but unfortunately, it clicks a lot when in use on the HuC6280. diff --git a/papers/doc/4-instrument/saa.md b/papers/doc/4-instrument/saa.md deleted file mode 100644 index cdfc3557..00000000 --- a/papers/doc/4-instrument/saa.md +++ /dev/null @@ -1,9 +0,0 @@ -# Philips SAA1099 instrument editor - -SAA1099 instrument editor consists of five macros: - -- [Volume] - volume sequence -- [Arpeggio] - pitch sequence -- [Duty cycle/ Noise] - noise generator frequency -- [Waveform] - selector between tone and noise -- [Envelope] - specifies the envelope generator shape diff --git a/papers/doc/4-instrument/scc.md b/papers/doc/4-instrument/scc.md deleted file mode 100644 index 2650e0a3..00000000 --- a/papers/doc/4-instrument/scc.md +++ /dev/null @@ -1,7 +0,0 @@ -# Konami SCC/Bubble System WSG instrument editor - -SCC/Bubble System WSG instrument editor consists of only three macros: - -- [Volume] - volume sequence -- [Arpeggio] - pitch sequence -- [Waveform] - spicifies wavetables sequence diff --git a/papers/doc/4-instrument/standard.md b/papers/doc/4-instrument/standard.md deleted file mode 100644 index 5f116c74..00000000 --- a/papers/doc/4-instrument/standard.md +++ /dev/null @@ -1,7 +0,0 @@ -# Standard instrument editor - -SMS and NES instrument editor consists of only three macros: - -- [Volume] - volume sequence -- [Arpeggio] - pitch sequencr -- [Duty cycle] - spicifies duty cycle and noise mode for NES channels NOTE: it obviously has no effect on Sega Master System diff --git a/papers/doc/4-instrument/tia.md b/papers/doc/4-instrument/tia.md deleted file mode 100644 index 41fffd38..00000000 --- a/papers/doc/4-instrument/tia.md +++ /dev/null @@ -1,7 +0,0 @@ -# Atari TIA instrument editor - -TIA instrument editor consists of only three macros: - -- [Volume] - volume sequence -- [Arpeggio] - pitch sequencr -- [Waveform] - 1-bit polynomial pattern type sequence diff --git a/papers/doc/4-instrument/vera.md b/papers/doc/4-instrument/vera.md deleted file mode 100644 index b577ccd2..00000000 --- a/papers/doc/4-instrument/vera.md +++ /dev/null @@ -1,8 +0,0 @@ -# VERA instrument editor - -VERA instrument editor consists of only four macros: - -- [Volume] - volume sequence -- [Arpeggio] - pitch sequence -- [Duty cycle] - pulse duty cycle sequence -- [Waveform] - select the waveform used by instrument diff --git a/papers/doc/4-instrument/wonderswan.md b/papers/doc/4-instrument/wonderswan.md deleted file mode 100644 index 6ad0e8c9..00000000 --- a/papers/doc/4-instrument/wonderswan.md +++ /dev/null @@ -1,8 +0,0 @@ -# WonderSwan instrument editor - -WS instrument editor consists of only four macros, similar to PCE but with different volume and noise range: - -- [Volume] - volume sequence -- [Arpeggio] - pitch sequencr -- [Noise] - noise LFSR tap sequence -- [Waveform] - spicifies wavetables sequence diff --git a/papers/doc/4-instrument/x1_010.md b/papers/doc/4-instrument/x1_010.md deleted file mode 100644 index c76cbcb5..00000000 --- a/papers/doc/4-instrument/x1_010.md +++ /dev/null @@ -1,11 +0,0 @@ -# X1-010 instrument editor - -X1-010 instrument editor consists of 7 macros. - -- [Volume] - volume levels sequence -- [Arpeggio]- pitch sequence -- [Waveform] - spicifies wavetables sequence -- [Envelope Mode] - allows shaping an envelope -- [Envelope] - spicifies envelope shape sequence, it's also wavetable. -- [Auto envelope numerator] - sets the envelope to the channel's frequency multiplied by numerator -- [Auto envelope denominator] - sets the envelope to the channel's frequency divided by denominator diff --git a/papers/doc/7-systems/ay8910.md b/papers/doc/7-systems/ay8910.md deleted file mode 100644 index 25eb77f7..00000000 --- a/papers/doc/7-systems/ay8910.md +++ /dev/null @@ -1,46 +0,0 @@ -# General Instrument AY-3-8910 - -this chip was used in many home computers (ZX Spectrum, MSX, Amstrad CPC, Atari ST, etc.), video game consoles (Intellivision and Vectrex), arcade boards and even slot machines! - -it is a 3-channel square/noise/envelope sound generator. the chip's powerful sound comes from the envelope... - -the AY-3-8914 variant was used in Intellivision, which is pretty much an AY with 4 level envelope volume per channel and different register format. - -# effects - -- `20xx`: set channel mode. `xx` may be one of the following: - - `00`: square - - `01`: noise - - `02`: square and noise - - `03`: envelope - - `04`: envelope and square - - `05`: envelope and noise - - `06`: envelope and square and noise - - `07`: nothing -- `21xx`: set noise frequency. `xx` is a value between 00 and 1F. -- `22xy`: set envelope mode. - - `x` sets the envelope shape, which may be one of the following: - - `0: \___` decay - - `4: /___` attack once - - `8: \\\\` saw - - `9: \___` decay - - `A: \/\/` inverse obelisco - - `B: \¯¯¯` decay once - - `C: ////` inverse saw - - `D: /¯¯¯` attack - - `E: /\/\` obelisco - - `F: /___` attack once - - if `y` is 1 then the envelope will affect this channel. -- `23xx`: set envelope period low byte. -- `24xx`: set envelope period high byte. -- `25xx`: slide envelope period up. -- `26xx`: slide envelope period down. -- `29xy`: enable auto-envelope mode. - - in this mode the envelope period is set to the channel's notes, multiplied by a fraction. - - `x` is the numerator. - - `y` is the denominator. - - if `x` or `y` are 0 this will disable auto-envelope mode. -- `2Exx`: write to I/O port A. - - this changes the port's mode to "write". make sure you have connected something to it. -- `2Fxx`: write to I/O port B. - - this changes the port's mode to "write". make sure you have connected something to it. diff --git a/papers/doc/7-systems/ay8930.md b/papers/doc/7-systems/ay8930.md deleted file mode 100644 index 0d471bca..00000000 --- a/papers/doc/7-systems/ay8930.md +++ /dev/null @@ -1,55 +0,0 @@ -# Microchip AY8930 - -a backwards-compatible successor to the AY-3-8910, with increased volume resolution, duty cycle control, three envelopes and highly configurable noise generator. - -sadly, this soundchip has only ever observed minimal success, and has remained rather obscure since. -it is best known for being used in the Covox Sound Master, which didn't sell well either. It also observed very minimal success in Merit's CRT-250 machines, but only as a replacement for the AY-3-8910. - -emulation of this chip in Furnace is now complete thanks to community efforts and hardware testing, which an MSX board called Darky has permitted. - -# effects - -- `12xx`: set channel duty cycle. `xx` is a value between 00 and 08. - - `00`: 3.125% - - `01`: 6.25% - - `02`: 12.5% - - `03`: 25% - - `04`: 50% - - `05`: 75% - - `06`: 87.5% - - `07`: 93.75% - - `08`: 96.875% -- `20xx`: set channel mode. `xx` may be one of the following: - - `00`: square - - `01`: noise - - `02`: square and noise - - `03`: envelope - - `04`: envelope and square - - `05`: envelope and noise - - `06`: envelope and square and noise - - `07`: nothing -- `21xx`: set noise frequency. `xx` is a value between 00 and FF. -- `22xy`: set envelope mode. - - `x` sets the envelope shape, which may be one of the following: - - `0: \___` decay - - `4: /___` attack once - - `8: \\\\` saw - - `9: \___` decay - - `A: \/\/` inverse obelisco - - `B: \¯¯¯` decay once - - `C: ////` inverse saw - - `D: /¯¯¯` attack - - `E: /\/\` obelisco - - `F: /___` attack once - - if `y` is 1 then the envelope will affect this channel. -- `23xx`: set envelope period low byte. -- `24xx`: set envelope period high byte. -- `25xx`: slide envelope period up. -- `26xx`: slide envelope period down. -- `27xx`: set noise AND mask. -- `28xx`: set noise OR mask. -- `29xy`: enable auto-envelope mode. - - in this mode the envelope period is set to the channel's notes, multiplied by a fraction. - - `x` is the numerator. - - `y` is the denominator. - - if `x` or `y` are 0 this will disable auto-envelope mode. diff --git a/papers/doc/7-systems/es5506.md b/papers/doc/7-systems/es5506.md deleted file mode 100644 index acdcd0a4..00000000 --- a/papers/doc/7-systems/es5506.md +++ /dev/null @@ -1,41 +0,0 @@ -# Ensoniq ES5506 (OTTO) - -Sample-based synthesis chip used in a bunch of Taito arcade machines and PC sound cards like Soundscape Elite. A variant of it was the heart of the well-known Gravis Ultrasound. - -it supports a whooping 32 channels of 16-bit PCM and: - -- Real time digital filters -- Frequency interpolation -- Loop start and stop positions for each voice (bidirectional and reverse looping) -- Internal volume multiplication and stereo panning -- Hardware support for envelopes - -# effects - -- `10xx`: set waveform. -- `11xx`: set filter mode (0-3) -- `120x`: set pause (bit 0). Pauses the sample until the bit is unset, where it will then resume where it left off. -- `14xx`: set filter coefficient K1 low byte. -- `15xx`: set filter coefficient K1 high byte. -- `16xx`: set filter coefficient K2 low byte. -- `17xx`: set filter coefficient K2 high byte. -- `18xx`: set filter coefficient K1 slide up. -- `19xx`: set filter coefficient K1 slide down. -- `1Axx`: set filter coefficient K2 slide up. -- `1Bxx`: set filter coefficient K2 slide down. -- `20xx`: set envelope count. -- `22xx`: set envelope left volume ramp. -- `23xx`: set envelope right volume ramp. -- `24xx`: set envelope filter coefficient K1 ramp. -- `25xx`: set envelope filter coefficient K1 ramp (slower). -- `26xx`: set envelope filter coefficient K2 ramp. -- `27xx`: set envelope filter coefficient K2 ramp (slower). -- `3xxx`: set coarse filter coefficient K1. -- `4xxx`: set coarse filter coefficient K2. -- `81xx`: set panning (left channel). -- `82xx`: set panning (right channel). -- `88xx`: set panning (rear channels). -- `89xx`: set panning (rear left channel). -- `8Axx`: set panning (rear right channel). -- `9xxx`: set sample offset (x256). -- `DFxx`: set sample playback direction. diff --git a/papers/doc/7-systems/game-boy.md b/papers/doc/7-systems/game-boy.md deleted file mode 100644 index ffc357fb..00000000 --- a/papers/doc/7-systems/game-boy.md +++ /dev/null @@ -1,18 +0,0 @@ -# Game Boy - -the Nintendo Game Boy is one of the most successful portable game systems ever made. - -with stereo sound, two pulse channels, a wave channel and a noise one it packed some serious punch. - -# effects - -- `10xx`: change wave. -- `11xx`: set noise length. `xx` may be one of: - - 0: long - - 1: short -- `12xx`: set duty cycle (from 0 to 3). -- `13xy`: setup sweep (pulse channels only). - - `x` is the time. - - `y` is the shift. - - set to 0 to disable it. -- `14xx`: set sweep direction. 0 is up and 1 is down. diff --git a/papers/doc/7-systems/genesis.md b/papers/doc/7-systems/genesis.md deleted file mode 100644 index 335466d0..00000000 --- a/papers/doc/7-systems/genesis.md +++ /dev/null @@ -1,37 +0,0 @@ -# Sega Genesis/Mega Drive - -a video game console that showed itself as the first true rival to Nintendo's video game market near-monopoly in the US during the '80's. - -this console is powered by two sound chips: the [Yamaha YM2612](ym2612.md) and [a derivative of the SN76489](sms.md). - -# effects - -- `10xy`: set LFO parameters. - - `x` toggles the LFO. - - `y` sets its speed. -- `11xx`: set feedback of channel. -- `12xx`: set operator 1 level. -- `13xx`: set operator 2 level. -- `14xx`: set operator 3 level. -- `15xx`: set operator 4 level. -- `16xy`: set multiplier of operator. - - `x` is the operator (1-4). - - `y` is the multiplier. -- `17xx`: enable PCM channel. - - this only works on channel 6. - - **this effect is there for compatibility reasons** - it is otherwise recommended to use Sample type instruments (which automatically enable PCM mode when used). -- `18xx`: toggle extended channel 3 mode. - - 0 disables it and 1 enables it. - - only in extended channel 3 chip. -- `19xx`: set attack of all operators. -- `1Axx`: set attack of operator 1. -- `1Bxx`: set attack of operator 2. -- `1Cxx`: set attack of operator 3. -- `1Dxx`: set attack of operator 4. -- `20xy`: set PSG noise mode. - - `x` controls whether to inherit frequency from PSG channel 3. - - 0: use one of 3 preset frequencies (C: A-2; C#: A-3; D: A-4). - - 1: use frequency of PSG channel 3. - - `y` controls whether to select noise or thin pulse. - - 0: thin pulse. - - 1: noise. diff --git a/papers/doc/7-systems/msm6295.md b/papers/doc/7-systems/msm6295.md deleted file mode 100644 index 25766927..00000000 --- a/papers/doc/7-systems/msm6295.md +++ /dev/null @@ -1,7 +0,0 @@ -# OKI MSM6295 - -an upgrade from 6258 - it provides 4 ADPCM channels, at max 32 KHz (still no variable pitch though). between late 80s and late 90s, it was one of the most common, if not THE most common soundchip used in arcade machines (Capcom, Toaplan, Kaneko, Atari, Tecmo, the list can go on and on...) - -# effects - -- `20xx`: set chip output rate. diff --git a/papers/doc/7-systems/n163.md b/papers/doc/7-systems/n163.md deleted file mode 100644 index 06f2d0b1..00000000 --- a/papers/doc/7-systems/n163.md +++ /dev/null @@ -1,32 +0,0 @@ -# Namco 163 (also called N163, Namco C163, Namco 106 (sic), Namco 160 or Namco 129) - -this is one of Namco's NES mappers, with up to 8 wavetable channels. - -it has 256 nibbles (128 bytes) of internal RAM which is shared between channel state and waves. - -wavetables are variable in size and may be allocated anywhere in RAM. at least 128 nibbles (64 bytes) can be dedicated to waves, with more available if not all channels are used - waveform RAM area becomes smaller as more channels are activated, since channel registers consume 8 bytes for each channel. - -Namco 163 uses time-division multiplexing for its output. this means that only one channel is output per sample (like OPLL and OPN2). therefore, its sound quality gets worse as more channels are activated. - -Furnace supports loading waveforms into RAM and waveform playback simultaneously, and channel limit is dynamically changeable with effect commands. - -you must load waveform to RAM first for playback, as its load behavior auto-updates when every waveform changes. - -both waveform playback and load command work independently per each channel columns. -(Global) commands don't care about the channel columns for work commands and its load behavior is independent with per-channel column load commands. - -# effects - -- `10xx`: set waveform for playback. -- `11xx`: set waveform position in RAM for playback (single nibble unit). -- `12xx`: set waveform length in RAM for playback (04 to FC, 4 nibble unit). -- `130x`: set playback waveform update behavior (0: off, bit 0: update now, bit 1: update when every waveform is changed). -- `14xx`: set waveform for load to RAM. -- `15xx`: set waveform position for load to RAM (single nibble unit). -- `16xx`: set waveform length for load to RAM (04 to FC, 4 nibble unit). -- `170x`: set waveform load behavior (0: off, bit 0: load now, bit 1: load when every waveform is changed). -- `180x`: set channel limit (0 to 7, x + 1). -- `20xx`: (Global) set waveform for load to RAM. -- `21xx`: (Global) set waveform position for load to RAM (single nibble unit). -- `22xx`: (Global) set waveform length for load to RAM (04 to FC, 4 nibble unit). -- `230x`: (Global) set waveform load behavior (0: off, bit 0: load now, bit 1: load when every waveform is changed). diff --git a/papers/doc/7-systems/nes.md b/papers/doc/7-systems/nes.md deleted file mode 100644 index 8367c589..00000000 --- a/papers/doc/7-systems/nes.md +++ /dev/null @@ -1,110 +0,0 @@ -# NES - -the console from Nintendo that plays Super Mario Bros. and helped revive the agonizing video game market in the US during mid-80s. - -also known as Famicom. it is a five-channel sound generator: first two channels play pulse wave with three different duty cycles, third is a fixed-volume triangle channel, fourth is a noise channel (can work in both pseudo-random and periodic modes) and fifth is a (D)PCM sample channel. - -# effects - -- `11xx`: write to delta modulation counter. - - this may be used to attenuate the triangle and noise channels. - - will not work if a sample is playing. -- `12xx`: set duty cycle or noise mode of channel. - - may be 0-3 for the pulse channels and 0-1 for the noise channel. -- `13xy`: setup sweep up. - - `x` is the time. - - `y` is the shift. - - set to 0 to disable it. -- `14xy`: setup sweep down. - - `x` is the time. - - `y` is the shift. - - set to 0 to disable it. -- `15xx`: set envelope mode. - - `0`: envelope + length counter (volume represents envelope duration). - - `1`: length counter (volume represents output volume). - - `2`: looping envelope (volume represents envelope duration). - - `3`: constant volume (default; volume represents output volume). - - pulse and noise channels only. - - you may need to apply a phase reset (using the macro) to make the envelope effective. -- `16xx`: set length counter. - - see table below for possible values. - - this will trigger phase reset. -- `17xx`: set frame counter mode. - - `0`: 4-step. - - NTSC: 120Hz sweeps and lengths; 240Hz envelope. - - PAL: 100Hz sweeps and lengths; 200Hz envelope. - - Dendy: 118.9Hz sweeps and lengths; 237.8Hz envelope. - - `1`: 5-step. - - NTSC: 96Hz sweeps and lengths; 192Hz envelope. - - PAL: 80Hz sweeps and lengths; 160Hz envelope. - - Dendy: 95.1Hz sweeps and lengths; 190.2Hz envelope. -- `18xx`: set PCM channel mode. - - `00`: PCM (software). - - `01`: DPCM (hardware). - - when in DPCM mode, samples will sound muffled (due to its nature), availables pitches are limited and loop point is ignored. -- `19xx`: set triangle linear counter. - - `00` to `7F` set the counter. - - `80` and higher halt it. -- `20xx`: set DPCM frequency. - - only works in DPCM mode. - - see table below for possible values. - -# DPCM frequency table - -val | NTSC | PAL -----|-----------|----------- - 00 | 4181.7Hz | 4177.4Hz - 01 | 4709.9Hz | 4696.6Hz - 02 | 5264.0Hz | 5261.4Hz - 03 | 5593.0Hz | 5579.2Hz - 04 | 6257.9Hz | 6023.9Hz - 05 | 7046.3Hz | 7044.9Hz - 06 | 7919.3Hz | 7917.2Hz - 07 | 8363.4Hz | 8397.0Hz - 08 | 9419.9Hz | 9446.6Hz - 09 | 11186.1Hz | 11233.8Hz - 0A | 12604.0Hz | 12595.5Hz - 0B | 13982.6Hz | 14089.9Hz - 0C | 16884.6Hz | 16965.4Hz - 0D | 21306.8Hz | 21315.5Hz - 0E | 24858.0Hz | 25191.0Hz - 0F | 33143.9Hz | 33252.1Hz - -# length counter table - -val | raw | NTSC | PAL | Dendy | NTSC 5-step | PAL 5-step | Dendy 5-step -----|-----|-------|-------|-------|-------------|------------|-------------- - 00 | 10 | 83ms | 100ms | 84ms | 104ms | 125ms | 105ms - 01 | 254 | 2.1s | 2.5s | 2.1s | 2.6s | 3.2s | 2.7s - 02 | 20 | 166ms | 200ms | 168ms | 208ms | 250ms | 210ms - 03 | 2 | 17ms | 20ms | 17ms | 21ms | 25ms | 21ms - 04 | 40 | 333ms | 400ms | 336ms | 417ms | 500ms | 421ms - 05 | 4 | 33ms | 40ms | 34ms | 42ms | 50ms | 42ms - 06 | 80 | 667ms | 800ms | 673ms | 833ms | 1.0s | 841ms - 07 | 6 | 50ms | 60ms | 50ms | 63ms | 75ms | 63ms - 08 | 160 | 1.3s | 1.6s | 1.3s | 1.7s | 2.0s | 1.7s - 09 | 8 | 67ms | 80ms | 67ms | 83ms | 100ms | 84ms - 0A | 60 | 500ms | 600ms | 505ms | 625ms | 750ms | 631ms - 0B | 10 | 83ms | 100ms | 84ms | 104ms | 125ms | 105ms - 0C | 14 | 117ms | 140ms | 118ms | 146ms | 175ms | 147ms - 0D | 12 | 100ms | 120ms | 101ms | 125ms | 150ms | 126ms - 0E | 26 | 217ms | 260ms | 219ms | 271ms | 325ms | 273ms - 0F | 14 | 117ms | 140ms | 118ms | 145ms | 175ms | 147ms - 10 | 12 | 100ms | 120ms | 101ms | 125ms | 150ms | 126ms - 11 | 16 | 133ms | 160ms | 135ms | 167ms | 200ms | 168ms - 12 | 24 | 200ms | 240ms | 202ms | 250ms | 300ms | 252ms - 13 | 18 | 150ms | 180ms | 151ms | 188ms | 225ms | 189ms - 14 | 48 | 400ms | 480ms | 404ms | 500ms | 600ms | 505ms - 15 | 20 | 167ms | 200ms | 168ms | 208ms | 250ms | 210ms - 16 | 96 | 800ms | 960ms | 807ms | 1.0s | 1.2s | 1.0s - 17 | 22 | 183ms | 220ms | 185ms | 229ms | 275ms | 231ms - 18 | 192 | 1.6s | 1.9s | 1.6s | 2.0s | 2.4s | 2.0s - 19 | 24 | 200ms | 240ms | 202ms | 250ms | 300ms | 252ms - 1A | 72 | 600ms | 720ms | 606ms | 750ms | 900ms | 757ms - 1B | 26 | 217ms | 260ms | 219ms | 271ms | 325ms | 273ms - 1C | 16 | 133ms | 160ms | 135ms | 167ms | 200ms | 168ms - 1D | 28 | 233ms | 280ms | 235ms | 292ms | 350ms | 294ms - 1E | 32 | 267ms | 320ms | 269ms | 333ms | 400ms | 336ms - 1F | 30 | 250ms | 300ms | 252ms | 313ms | 375ms | 315ms - -reference: [NESdev](https://www.nesdev.org/wiki/APU_Length_Counter) diff --git a/papers/doc/7-systems/opl.md b/papers/doc/7-systems/opl.md deleted file mode 100644 index b4a86e6d..00000000 --- a/papers/doc/7-systems/opl.md +++ /dev/null @@ -1,80 +0,0 @@ -# Yamaha OPL - -a series of FM sound chips which were very popular in DOS land. it was so popular that even Yamaha made a logo for it! - -essentially a downgraded version of Yamaha's other FM chips, with only 2 operators per channel. -however, it also had a drums mode, and later chips in the series added more waveforms (than just the typical sine) and even a 4-operator mode. - -the original OPL (Yamaha YM3526) was present as an expansion for the Commodore 64 and MSX computers (erm, a variant of it). it only had 9 two-operator channels and drums mode. - -its successor, the OPL2 (Yamaha YM3812), added 3 more waveforms and was one of the more popular chips because it was present on the AdLib card for PC. -later Creative would borrow the chip to make the Sound Blaster, and totally destroyed AdLib's dominance. - -the OPL3 (Yamaha YMF262) added 9 more channels, 4 more waveforms, rudimentary 4-operator mode (pairing up to 12 channels to make up to six 4-operator channels), quadraphonic output (sadly Furnace only supports stereo) and some other things. - -afterwards everyone moved to Windows and software mixed PCM streaming... - -# effects - -- 10xx: set AM depth. the following values are accepted: - - 0: 1dB (shallow) - - 1: 4.8dB (deep) - - this effect applies to all channels. -- `11xx`: set feedback of channel. -- `12xx`: set operator 1 level. -- `13xx`: set operator 2 level. -- `14xx`: set operator 3 level. - - only in 4-op mode (OPL3). -- `15xx`: set operator 4 level. - - only in 4-op mode (OPL3). -- `16xy`: set multiplier of operator. - - `x` is the operator (1-4; last 2 operators only in 4-op mode). - - `y` is the multiplier. -- 17xx: set vibrato depth. the following values are accepted: - - 0: normal - - 1: double - - this effect applies to all channels. -- `18xx`: toggle drums mode. - - 0 disables it and 1 enables it. - - only in drums chip. -- `19xx`: set attack of all operators. -- `1Axx`: set attack of operator 1. -- `1Bxx`: set attack of operator 2. -- `1Cxx`: set attack of operator 3. - - only in 4-op mode (OPL3). -- `1Dxx`: set attack of operator 4. - - only in 4-op mode (OPL3). -- `2Axy`: set waveform of operator. - - `x` is the operator (1-4; last 2 operators only in 4-op mode). a value of 0 means "all operators". - - `y` is the value. - - only in OPL2 or higher. -- `30xx`: enable envelope hard reset. - - this works by inserting a quick release and tiny delay before a new note. -- `50xy`: set AM of operator. - - `x` is the operator (1-4; last 2 operators only in 4-op mode). a value of 0 means "all operators". - - `y` determines whether AM is on. -- `51xy` set SL of operator. - - `x` is the operator (1-4; last 2 operators only in 4-op mode). a value of 0 means "all operators". - - `y` is the value. -- `52xy` set RR of operator. - - `x` is the operator (1-4; last 2 operators only in 4-op mode). a value of 0 means "all operators". - - `y` is the value. -- `53xy`: set VIB of operator. - - `x` is the operator (1-4; last 2 operators only in 4-op mode). a value of 0 means "all operators". - - `y` determines whether VIB is on. -- `54xy` set KSL of operator. - - `x` is the operator (1-4; last 2 operators only in 4-op mode). a value of 0 means "all operators". - - `y` is the value. -- `55xy` set SUS of operator. - - `x` is the operator (1-4; last 2 operators only in 4-op mode). a value of 0 means "all operators". - - `y` determines whether SUS is on. -- `56xx`: set DR of all operators. -- `57xx`: set DR of operator 1. -- `58xx`: set DR of operator 2. -- `59xx`: set DR of operator 3. - - only in 4-op mode (OPL3). -- `5Axx`: set DR of operator 4. - - only in 4-op mode (OPL3). -- `5Bxy`: set KSR of operator. - - `x` is the operator (1-4; last 2 operators only in 4-op mode). a value of 0 means "all operators". - - `y` determines whether KSR is on. \ No newline at end of file diff --git a/papers/doc/7-systems/opll.md b/papers/doc/7-systems/opll.md deleted file mode 100644 index 8b16e888..00000000 --- a/papers/doc/7-systems/opll.md +++ /dev/null @@ -1,63 +0,0 @@ -# Yamaha YM2413/OPLL - -the YM2413, otherwise known as OPLL, is a cost-reduced FM synthesis sound chip, based on the Yamaha YM3812 (OPL2). thought OPL was downgraded enough? :p - -OPLL also spawned a few derivative chips, the best known of these is: -- the famous Konami VRC7. used in the Japan-only video game Lagrange Point, it was **another** cost reduction on top of the OPLL! this time just 6 channels... -- Yamaha YM2423, same chip as YM2413, just a different patch set -- Yamaha YMF281, ditto - -# technical specifications - -the YM2413 is equipped with the following features: - -- 9 channels of 2 operator FM synthesis -- A drum/percussion mode, replacing the last 3 voices with 5 rhythm channels -- 1 user-definable patch (this patch can be changed throughout the course of the song) -- 15 pre-defined patches which can all be used at the same time -- Support for ADSR on both the modulator and the carrier -- Sine and half-sine based FM synthesis -- 9 octave note control -- 4096 different frequencies for channels -- 16 unique volume levels (NOTE: Volume 0 is NOT silent.) -- Modulator and carrier key scaling -- Built-in hardware vibrato support - -# effects - -- `11xx`: set feedback of channel. -- `12xx`: set operator 1 level. -- `13xx`: set operator 2 level. -- `16xy`: set multiplier of operator. - - `x` is the operator (1 or 2). - - `y` is the multiplier. -- `18xx`: toggle drums mode. - - 0 disables it and 1 enables it. - - only in drums chip. -- `19xx`: set attack of all operators. -- `1Axx`: set attack of operator 1. -- `1Bxx`: set attack of operator 2. -- `50xy`: set AM of operator. - - `x` is the operator (1-2). a value of 0 means "all operators". - - `y` determines whether AM is on. -- `51xy` set SL of operator. - - `x` is the operator (1-2). a value of 0 means "all operators". - - `y` is the value. -- `52xy` set RR of operator. - - `x` is the operator (1-2). a value of 0 means "all operators". - - `y` is the value. -- `53xy`: set VIB of operator. - - `x` is the operator (1-2). a value of 0 means "all operators". - - `y` determines whether VIB is on. -- `54xy` set KSL of operator. - - `x` is the operator (1-2). a value of 0 means "all operators". - - `y` is the value. -- `55xy` set EGT of operator. - - `x` is the operator (1-2). a value of 0 means "all operators". - - `y` determines whether EGT is on. -- `56xx`: set DR of all operators. -- `57xx`: set DR of operator 1. -- `58xx`: set DR of operator 2. -- `5Bxy`: set KSR of operator. - - `x` is the operator (1-2). a value of 0 means "all operators". - - `y` determines whether KSR is on. \ No newline at end of file diff --git a/papers/doc/7-systems/opz.md b/papers/doc/7-systems/opz.md deleted file mode 100644 index 507e4ab1..00000000 --- a/papers/doc/7-systems/opz.md +++ /dev/null @@ -1,115 +0,0 @@ -# Yamaha OPZ (YM2414) - -**disclaimer: despite the name, this has nothing to do with teenage engineering's OP-Z synth!** - -this is the YM2151's little-known successor, used in the Yamaha TX81Z and a few other Yamaha synthesizers. oh, and the Korg Z3 too. - -it adds these features on top of the YM2151: -- 8 waveforms (but they're different from the OPL ones) -- per-channel (possibly) linear volume control separate from TL -- increased multiplier precision (in 1/16ths) -- 4-step envelope generator shift (minimum TL) -- another LFO -- no per-operator key on/off -- fixed frequency mode per operator (kind of like OPN family's extended channel mode but with a bit less precision and for all 8 channels) -- "reverb" effect (actually extends release) - -unlike the YM2151, this chip is officially undocumented. very few efforts have been made to study the chip and document it... -therefore emulation of this chip in Furnace is incomplete and uncertain. - -no plans have been made for TX81Z MIDI passthrough, because: -- Furnace works with register writes rather than MIDI commands -- the MIDI protocol is slow (would not be enough). -- the TX81Z is very slow to process a note on/off or parameter change event. -- the TL range has been reduced to 0-99, but the chip goes from 0-127. - -# effects - -- `10xx`: set noise frequency of channel 8 operator 4. 00 disables noise while 01 to 20 enables it. -- `11xx`: set feedback of channel. -- `12xx`: set operator 1 level. -- `13xx`: set operator 2 level. -- `14xx`: set operator 3 level. -- `15xx`: set operator 4 level. -- `16xy`: set multiplier of operator. - - `x` is the operator (1-4). - - `y` is the multiplier. -- `17xx`: set LFO speed. -- `18xx`: set LFO waveform. `xx` may be one of the following: - - `00`: saw - - `01`: square - - `02`: triangle - - `03`: noise -- `19xx`: set attack of all operators. -- `1Axx`: set attack of operator 1. -- `1Bxx`: set attack of operator 2. -- `1Cxx`: set attack of operator 3. -- `1Dxx`: set attack of operator 4. -- `1Exx`: set LFO AM depth. -- `1Fxx`: set LFO PM depth. -- `24xx`: set LFO 2 speed. -- `25xx`: set LFO 2 waveform. `xx` may be one of the following: - - `00`: saw - - `01`: square - - `02`: triangle - - `03`: noise -- `26xx`: set LFO 2 AM depth. -- `27xx`: set LFO 2 PM depth. -- `28xy`: set reverb of operator. - - `x` is the operator (1-4). a value of 0 means "all operators". - - `y` is the value. -- `2Axy`: set waveform of operator. - - `x` is the operator (1-4). a value of 0 means "all operators". - - `y` is the value. -- `2Bxy`: set EG shift of operator. - - `x` is the operator (1-4). a value of 0 means "all operators". - - `y` is the value. -- `2Cxy` set fine multiplier of operator. - - `x` is the operator (1-4). a value of 0 means "all operators". - - `y` is the value. -- `2Fxx`: enable envelope hard reset. - - this works by inserting a quick release and tiny delay before a new note. -- `3xyy`: set fixed frequency of operator 1/2. - - `x` is the block (0-7 for operator 1; 8-F for operator 2). - - `y` is the frequency. fixed frequency mode will be disabled if this is less than 8. - - the actual frequency is: `y*(2^x)`. -- `4xyy`: set fixed frequency of operator 3/4. - - `x` is the block (0-7 for operator 3; 8-F for operator 4). - - `y` is the frequency. fixed frequency mode will be disabled if this is less than 8. - - the actual frequency is: `y*(2^x)`. -- `50xy`: set AM of operator. - - `x` is the operator (1-4). a value of 0 means "all operators". - - `y` determines whether AM is on. -- `51xy` set SL of operator. - - `x` is the operator (1-4). a value of 0 means "all operators". - - `y` is the value. -- `52xy` set RR of operator. - - `x` is the operator (1-4). a value of 0 means "all operators". - - `y` is the value. -- `53xy` set DT of operator. - - `x` is the operator (1-4). a value of 0 means "all operators". - - `y` is the value: - - 0: +0 - - 1: +1 - - 2: +2 - - 3: +3 - - 4: -0 - - 5: -3 - - 6: -2 - - 7: -1 -- `54xy` set RS of operator. - - `x` is the operator (1-4). a value of 0 means "all operators". - - `y` is the value. -- `55xy` set DT2 of operator. - - `x` is the operator (1-4). a value of 0 means "all operators". - - `y` is the value. -- `56xx`: set DR of all operators. -- `57xx`: set DR of operator 1. -- `58xx`: set DR of operator 2. -- `59xx`: set DR of operator 3. -- `5Axx`: set DR of operator 4. -- `5Bxx`: set D2R/SR of all operators. -- `5Cxx`: set D2R/SR of operator 1. -- `5Dxx`: set D2R/SR of operator 2. -- `5Exx`: set D2R/SR of operator 3. -- `5Fxx`: set D2R/SR of operator 4. diff --git a/papers/doc/7-systems/pce.md b/papers/doc/7-systems/pce.md deleted file mode 100644 index 2405ac4f..00000000 --- a/papers/doc/7-systems/pce.md +++ /dev/null @@ -1,22 +0,0 @@ -# PC Engine/TurboGrafx-16 - -a console from NEC that, depending on a region: - attempted to enter the fierce battle between Nintendo and Sega, but because its capabilities are a mix of third and fourth generation, it failed to last long. (US and Europe) - was Nintendo's most fearsome rival, completely defeating Sega Mega Drive and defending itself against Super Famicom (Japan) - -it has 6 wavetable channels and the last two ones also double as noise channels. -furthermore, it has some PCM and LFO! - -# effects - -- `10xx`: change wave. -- `11xx`: toggle noise mode. only available in the last two channels. -- `12xx`: setup LFO. the following values are accepted: - - `00`: LFO disabled. - - `01`: LFO enabled, shift 0. - - `02`: LFO enabled, shift 4. - - `03`: LFO enabled, shift 8. - - when LFO is enabled, channel 2 is muted and its output is passed to channel 1's frequency. -- `13xx`: set LFO speed. -- `17xx`: toggle PCM mode. - - **this effect is there for compatibility reasons** - it is otherwise recommended to use Sample type instruments (which automatically enable PCM mode when used). diff --git a/papers/doc/7-systems/sm8521.md b/papers/doc/7-systems/sm8521.md deleted file mode 100644 index e6846198..00000000 --- a/papers/doc/7-systems/sm8521.md +++ /dev/null @@ -1,23 +0,0 @@ -# Sharp SM8521 - -The SM8521 is the CPU and sound chip of the Game.com, a handheld console released in 1997 as a competitor to the infamous Nintendo Virtual Boy. - -Ultimately, most of the games for the Game.com ended up being failures in the eyes of reviewers, thus giving the Game.com a pretty bad reputation. This was one of the reasons that the Game.com only ended up selling at least 300,000 units. For these reasons and more, the Game.com ended up being discontinued in 2000. - -However, for its time, it was a pretty competitively priced system. The Gameboy Color was to be released in a year for $79.95, while the Game.com was released for $69.99, and its later model, the Pocket Pro, was released in mid-1999 for $29.99 due to the Game.com's apparent significant decrease in value. - -In fact, most games never used the wavetable/noise mode of the chip. Sonic Jam, for example, uses a sine wave with a software-controlled volume envelope on the DAC channel (see below for more information on the DAC channel). - -The sound-related features and quirks of the SM8521 are as follows: -- 2 4-bit wavetable channels -- a noise channel (which can go up to a very high pitch, creating an almost periodic noise sound) -- 5-bit volume -- A low bit-depth output (which means it distorts a lot). -- It phase resets when you switch waves -- 12-bit pitch with a wide frequency range -- A software-controlled D/A register that (potentially) requires all other registers to be stopped to play. Due to this, it is currently, it is not implemented in Furnace as of version 0.6pre4. - -## effect commands - -- `10xx` Set waveform - - `xx` is a value between 0 and 255, that sets the waveform of the channel you place it on. diff --git a/papers/doc/7-systems/sms.md b/papers/doc/7-systems/sms.md deleted file mode 100644 index 37097ccd..00000000 --- a/papers/doc/7-systems/sms.md +++ /dev/null @@ -1,17 +0,0 @@ -# TI SN76489 (e.g. Sega Master System) - -a relatively simple sound chip made by Texas Instruments. a derivative of it is used in Sega's Master System, the predecessor to Genesis. - -the original iteration of the SN76489 used in the TI-99/4A computers was clocked at 447 KHz, being able to play as low as 13.670 Hz (A -1). consequently, pitch accuracy for higher notes is compromised. - -on the other hand, the chip was clocked at a much higher speed on Master System and Genesis, which makes it rather poor in the bass range. - -# effects - -- `20xy`: set noise mode. - - `x` controls whether to inherit frequency from channel 3. - - 0: use one of 3 preset frequencies (C: A-2; C#: A-3; D: A-4). - - 1: use frequency of channel 3. - - `y` controls whether to select noise or thin pulse. - - 0: thin pulse. - - 1: noise. diff --git a/papers/doc/7-systems/snes.md b/papers/doc/7-systems/snes.md deleted file mode 100644 index 61b30635..00000000 --- a/papers/doc/7-systems/snes.md +++ /dev/null @@ -1,81 +0,0 @@ -# Super Nintendo Entertainment System (SNES)/Super Famicom - -the successor to NES to compete with Genesis, packing superior graphics and sample-based audio. - -its audio system, developed by Sony, features a DSP chip, SPC700 CPU and 64KB of dedicated SRAM used by both. -this whole system itself is pretty much a separate computer that the main CPU needs to upload its program and samples to. - -Furnace communicates with the DSP directly and provides a full 64KB of memory. this memory might be reduced excessively on ROM export to make up for playback engine and pattern data. you can go to window > statistics to see how much memory your samples are using. - -some notable features of the DSP are: -- pitch modulation, meaning that you can use 2 channels to make a basic FM synth without eating up too much memory. -- a built in noise generator, useful for hi-hats, cymbals, rides, effects, among other things. -- per-channel echo, which unfortunately eats up a lot of memory but can be used to save channels in songs. -- an 8-tap FIR filter for the echo, which is basically a procedural low-pass filter that you can edit however you want. -- sample loop, but the loop points have to be multiples of 16. -- left/right channel invert for surround sound. -- ADSR and gain envelope modes. -- 7-bit volume per channel. -- sample interpolation, which is basically a low-pass filter that gets affected by the pitch of the channel. - -Furnace also allows the SNES to use wavetables (and the wavetable synthesizer) in order to create more 'animated' sounds, using less memory than regular samples. this however is not a hardware feature, and might be difficult to implement on real hardware. - -# effects - -- `10xx`: set waveform. -- `11xx`: toggle noise mode. -- `12xx`: toggle echo on this channel. -- `13xx`: toggle pitch modulation. -- `14xy`: toggle inverting the left or right channels (x: left, y: right). -- `15xx`: set envelope mode. - - 0: ADSR. - - 1: gain (direct). - - 2: linear decrement. - - 3: exponential decrement. - - 4: linear increment. - - 5: bent line (inverse log) increment. -- `16xx`: set gain (00 to 7F if direct, 00 to 1F otherwise). -- `18xx`: enable echo buffer. -- `19xx`: set echo delay - - goes from 0 to F. -- `1Axx`: set left echo channel volume. - - this is a signed number. - - 00 to 7F for 0 to 127. - - 80 to FF for -128 to -1. - - setting this to -128 is not recommended as it may cause echo output to overflow and therefore click. -- `1Bxx`: set right echo channel volume. - - this is a signed number. - - 00 to 7F for 0 to 127. - - 80 to FF for -128 to -1. - - setting this to -128 is not recommended as it may cause echo output to overflow and therefore click. -- `1Cxx`: set echo feedback. - - this is a signed number. - - 00 to 7F for 0 to 127. - - 80 to FF for -128 to -1. - - setting this to -128 is not recommended as it may cause echo output to overflow and therefore click. -- `1Dxx`: set noise generator frequency (00 to 1F). -- `1Exx`: set left dry/global volume. - - this does not affect echo. -- `1Fxx`: set right dry/global volume. - - this does not affect echo. -- `20xx`: set attack (0 to F). - - only in ADSR envelope mode. -- `21xx`: set decay (0 to 7). - - only in ADSR envelope mode. -- `22xx`: set sustain (0 to 7). - - only in ADSR envelope mode. -- `23xx`: set release (00 to 1F). - - only in ADSR envelope mode. -- `30xx`: set echo filter coefficient 0. -- `31xx`: set echo filter coefficient 1. -- `32xx`: set echo filter coefficient 2. -- `33xx`: set echo filter coefficient 3. -- `34xx`: set echo filter coefficient 4. -- `35xx`: set echo filter coefficient 5. -- `36xx`: set echo filter coefficient 6. -- `37xx`: set echo filter coefficient 7. - - all of these are signed numbers. - - 00 to 7F for 0 to 127. - - 80 to FF for -128 to -1. - - make sure the sum of these is between -128 or 127. - - failure to comply may result in overflow and therefore clicking. diff --git a/papers/doc/7-systems/soundunit.md b/papers/doc/7-systems/soundunit.md deleted file mode 100644 index 4f123461..00000000 --- a/papers/doc/7-systems/soundunit.md +++ /dev/null @@ -1,56 +0,0 @@ -# tildearrow Sound Unit - -a fantasy sound chip, used in the specs2 fantasy computer designed by tildearrow. - -it has the following capabilities: -- 8 channels of either waveform or sample -- stereo sound -- 8 waveforms (pulse, saw, sine, triangle, noise, periodic noise, XOR sine and XOR triangle) -- 128 widths for the pulse wave -- per-channel resonant filter -- ring modulation -- volume, frequency and cutoff sweep units (per-channel) -- phase reset timer (per-channel) - -# effects - -- `10xx`: set waveform - - 0: pulse wave - - 1: sawtooth - - 2: sine wave - - 3: triangle wave - - 4: noise - - 5: periodic noise - - 6: XOR sine - - 7: XOR triangle -- `12xx`: set pulse width (0 to 7F) -- `13xx`: set resonance of filter (0 to FF) - - despite what the internal effects list says (0 to F), you can use a resonance value from 0 to FF (255) -- `14xx`: set filter mode and ringmod - - bit 0: ring mod - - bit 1: low pass - - bit 2: high pass - - bit 3: band pass -- `15xx`: set frequency sweep period low byte -- `16xx`: set frequency sweep period high byte -- `17xx`: set volume sweep period low byte -- `18xx`: set volume sweep period high byte -- `19xx`: set cutoff sweep period low byte -- `1Axx`: set cutoff sweep period high byte -- `1Bxx`: set frequency sweep boundary -- `1Cxx`: set volume sweep boundary -- `1Dxx`: set cutoff sweep boundary -- `1Exx`: set phase reset period low byte -- `1Fxx`: set phase reset period high byte -- `20xx`: toggle frequency sweep - - bit 0-6: speed - - bit 7: up direction -- `21xx`: toggle volume sweep - - bit 0-4: speed - - bit 5: up direction - - bit 6: loop - - bit 7: alternate -- `22xx`: toggle cutoff sweep - - bit 0-6: speed - - bit 7: up direction -- `4xxx`: set cutoff (0 to FFF) diff --git a/papers/doc/7-systems/tia.md b/papers/doc/7-systems/tia.md deleted file mode 100644 index 3d9146af..00000000 --- a/papers/doc/7-systems/tia.md +++ /dev/null @@ -1,28 +0,0 @@ -# Atari 2600 (TIA) - -help me! I can't even get this character in where I want! -I've spent hours debugging the issue, counting every possible cycle and I still cannot get it right! - -only 2 channels and 31 frequencies?! - -Furnace isn't complete without this one... - -# effects - -- `10xx` select shape. `xx` may be one of: - - 0: nothing - - 1: buzzy - - 2: low buzzy - - 3: flangy - - 4: square - - 5: square - - 6: pure buzzy - - 7: reedy - - 8: noise - - 9: reedy - - 10: pure buzzy - - 11: nothing - - 12: low square - - 13: low square - - 14: low pure buzzy - - 15: low reedy \ No newline at end of file diff --git a/papers/doc/7-systems/ym2151.md b/papers/doc/7-systems/ym2151.md deleted file mode 100644 index cef663c8..00000000 --- a/papers/doc/7-systems/ym2151.md +++ /dev/null @@ -1,70 +0,0 @@ -# Yamaha YM2151 - -the sound chip powering several arcade boards, the Sharp X1/X68000 and the Commander X16. Eight 4-op FM channels, with overpowered LFO and almost unused noise generator. - -it also was present on several pinball machines and synthesizers of the era, and later surpassed by the YM2414 (OPZ) present in the world-famous TX81Z. - -in most arcade boards the chip was used in combination with a PCM chip, like [SegaPCM](segapcm.md) or [OKI's line of ADPCM chips](oki.md). - -# effects - -- `10xx`: set noise frequency of channel 8 operator 4. 00 disables noise while 01 to 20 enables it. -- `11xx`: set feedback of channel. -- `12xx`: set operator 1 level. -- `13xx`: set operator 2 level. -- `14xx`: set operator 3 level. -- `15xx`: set operator 4 level. -- `16xy`: set multiplier of operator. - - `x` is the operator (1-4). - - `y` is the multiplier. -- `17xx`: set LFO speed. -- `18xx`: set LFO waveform. `xx` may be one of the following: - - `00`: saw - - `01`: square - - `02`: triangle - - `03`: noise -- `19xx`: set attack of all operators. -- `1Axx`: set attack of operator 1. -- `1Bxx`: set attack of operator 2. -- `1Cxx`: set attack of operator 3. -- `1Dxx`: set attack of operator 4. -- `1Exx`: set LFO AM depth. -- `1Fxx`: set LFO PM depth. -- `30xx`: enable envelope hard reset. - - this works by inserting a quick release and tiny delay before a new note. -- `50xy`: set AM of operator. - - `x` is the operator (1-4). a value of 0 means "all operators". - - `y` determines whether AM is on. -- `51xy` set SL of operator. - - `x` is the operator (1-4). a value of 0 means "all operators". - - `y` is the value. -- `52xy` set RR of operator. - - `x` is the operator (1-4). a value of 0 means "all operators". - - `y` is the value. -- `53xy` set DT of operator. - - `x` is the operator (1-4). a value of 0 means "all operators". - - `y` is the value: - - 0: +0 - - 1: +1 - - 2: +2 - - 3: +3 - - 4: -0 - - 5: -3 - - 6: -2 - - 7: -1 -- `54xy` set RS of operator. - - `x` is the operator (1-4). a value of 0 means "all operators". - - `y` is the value. -- `55xy` set DT2 of operator. - - `x` is the operator (1-4). a value of 0 means "all operators". - - `y` is the value. -- `56xx`: set DR of all operators. -- `57xx`: set DR of operator 1. -- `58xx`: set DR of operator 2. -- `59xx`: set DR of operator 3. -- `5Axx`: set DR of operator 4. -- `5Bxx`: set D2R/SR of all operators. -- `5Cxx`: set D2R/SR of operator 1. -- `5Dxx`: set D2R/SR of operator 2. -- `5Exx`: set D2R/SR of operator 3. -- `5Fxx`: set D2R/SR of operator 4. diff --git a/papers/doc/7-systems/ym2203.md b/papers/doc/7-systems/ym2203.md deleted file mode 100644 index b9f76b8e..00000000 --- a/papers/doc/7-systems/ym2203.md +++ /dev/null @@ -1,101 +0,0 @@ -# Yamaha YM2203 (OPN) - -a cost-reduced version of the YM2151 (OPM). -it only has 3 FM channels instead of 8 and removes stereo, the LFO and DT2 (coarse detune). - -however it does contain an AY/SSG part which provides 3 channels of square wave with noise and envelope. - -this chip was used in the NEC PC-88/PC-98 series of computers, the Fujitsu FM-7AV and in some arcade boards. - -several variants of this chip were released as well, with more features. - -# effects - -- `11xx`: set feedback of channel. -- `12xx`: set operator 1 level. -- `13xx`: set operator 2 level. -- `14xx`: set operator 3 level. -- `15xx`: set operator 4 level. -- `16xy`: set multiplier of operator. - - `x` is the operator (1-4). - - `y` is the multiplier. -- `18xx`: toggle extended channel 3 mode. - - 0 disables it and 1 enables it. - - only in extended channel 3 chip. -- `19xx`: set attack of all operators. -- `1Axx`: set attack of operator 1. -- `1Bxx`: set attack of operator 2. -- `1Cxx`: set attack of operator 3. -- `1Dxx`: set attack of operator 4. -- `20xx`: set SSG channel mode. `xx` may be one of the following: - - `00`: square - - `01`: noise - - `02`: square and noise - - `03`: nothing (apparently) - - `04`: envelope and square - - `05`: envelope and noise - - `06`: envelope and square and noise - - `07`: nothing -- `21xx`: set noise frequency. `xx` is a value between 00 and 1F. -- `22xy`: set envelope mode. - - `x` sets the envelope shape, which may be one of the following: - - `0: \___` decay - - `4: /___` attack once - - `8: \\\\` saw - - `9: \___` decay - - `A: \/\/` inverse obelisco - - `B: \¯¯¯` decay once - - `C: ////` inverse saw - - `D: /¯¯¯` attack - - `E: /\/\` obelisco - - `F: /___` attack once - - if `y` is 1 then the envelope will affect this channel. -- `23xx`: set envelope period low byte. -- `24xx`: set envelope period high byte. -- `25xx`: slide envelope period up. -- `26xx`: slide envelope period down. -- `29xy`: enable SSG auto-envelope mode. - - in this mode the envelope period is set to the channel's notes, multiplied by a fraction. - - `x` is the numerator. - - `y` is the denominator. - - if `x` or `y` are 0 this will disable auto-envelope mode. -- `30xx`: enable envelope hard reset. - - this works by inserting a quick release and tiny delay before a new note. -- `50xy`: set AM of operator. - - `x` is the operator (1-4). a value of 0 means "all operators". - - `y` determines whether AM is on. -- `51xy` set SL of operator. - - `x` is the operator (1-4). a value of 0 means "all operators". - - `y` is the value. -- `52xy` set RR of operator. - - `x` is the operator (1-4). a value of 0 means "all operators". - - `y` is the value. -- `53xy` set DT of operator. - - `x` is the operator (1-4). a value of 0 means "all operators". - - `y` is the value: - - 0: +0 - - 1: +1 - - 2: +2 - - 3: +3 - - 4: -0 - - 5: -3 - - 6: -2 - - 7: -1 -- `54xy` set RS of operator. - - `x` is the operator (1-4). a value of 0 means "all operators". - - `y` is the value. -- `55xy` set SSG-EG of operator. - - `x` is the operator (1-4). a value of 0 means "all operators". - - `y` is the value (0-8). - - values between 0 and 7 set SSG-EG. - - value 8 disables it. -- `56xx`: set DR of all operators. -- `57xx`: set DR of operator 1. -- `58xx`: set DR of operator 2. -- `59xx`: set DR of operator 3. -- `5Axx`: set DR of operator 4. -- `5Bxx`: set D2R/SR of all operators. -- `5Cxx`: set D2R/SR of operator 1. -- `5Dxx`: set D2R/SR of operator 2. -- `5Exx`: set D2R/SR of operator 3. -- `5Fxx`: set D2R/SR of operator 4. diff --git a/papers/doc/7-systems/ym2608.md b/papers/doc/7-systems/ym2608.md deleted file mode 100644 index 5eda41c1..00000000 --- a/papers/doc/7-systems/ym2608.md +++ /dev/null @@ -1,101 +0,0 @@ -# Yamaha YM2608 (OPNA) - -like YM2203, but with twice the FM channels, stereo, an ADPCM channel and built-in drums ("rhythm")! - -it was one of the available sound chips for the NEC PC-88VA and PC-98 series of computers. - -the YM2610 (OPNB) and YM2610B chips are very similar to this one, but the built-in drums have been replaced with 6 sample channels. - -# effects - -- `10xy`: set LFO parameters. - - `x` toggles the LFO. - - `y` sets its speed. -- `11xx`: set feedback of channel. -- `12xx`: set operator 1 level. -- `13xx`: set operator 2 level. -- `14xx`: set operator 3 level. -- `15xx`: set operator 4 level. -- `16xy`: set multiplier of operator. - - `x` is the operator (1-4). - - `y` is the multiplier. -- `18xx`: toggle extended channel 3 mode. - - 0 disables it and 1 enables it. - - only in extended channel 3 chip. -- `19xx`: set attack of all operators. -- `1Axx`: set attack of operator 1. -- `1Bxx`: set attack of operator 2. -- `1Cxx`: set attack of operator 3. -- `1Dxx`: set attack of operator 4. -- `20xx`: set SSG channel mode. `xx` may be one of the following: - - `00`: square - - `01`: noise - - `02`: square and noise - - `03`: nothing (apparently) - - `04`: envelope and square - - `05`: envelope and noise - - `06`: envelope and square and noise - - `07`: nothing -- `21xx`: set noise frequency. `xx` is a value between 00 and 1F. -- `22xy`: set envelope mode. - - `x` sets the envelope shape, which may be one of the following: - - `0: \___` decay - - `4: /___` attack once - - `8: \\\\` saw - - `9: \___` decay - - `A: \/\/` inverse obelisco - - `B: \¯¯¯` decay once - - `C: ////` inverse saw - - `D: /¯¯¯` attack - - `E: /\/\` obelisco - - `F: /___` attack once - - if `y` is 1 then the envelope will affect this channel. -- `23xx`: set envelope period low byte. -- `24xx`: set envelope period high byte. -- `25xx`: slide envelope period up. -- `26xx`: slide envelope period down. -- `29xy`: enable SSG auto-envelope mode. - - in this mode the envelope period is set to the channel's notes, multiplied by a fraction. - - `x` is the numerator. - - `y` is the denominator. - - if `x` or `y` are 0 this will disable auto-envelope mode. -- `30xx`: enable envelope hard reset. - - this works by inserting a quick release and tiny delay before a new note. -- `50xy`: set AM of operator. - - `x` is the operator (1-4). a value of 0 means "all operators". - - `y` determines whether AM is on. -- `51xy` set SL of operator. - - `x` is the operator (1-4). a value of 0 means "all operators". - - `y` is the value. -- `52xy` set RR of operator. - - `x` is the operator (1-4). a value of 0 means "all operators". - - `y` is the value. -- `53xy` set DT of operator. - - `x` is the operator (1-4). a value of 0 means "all operators". - - `y` is the value: - - 0: +0 - - 1: +1 - - 2: +2 - - 3: +3 - - 4: -0 - - 5: -3 - - 6: -2 - - 7: -1 -- `54xy` set RS of operator. - - `x` is the operator (1-4). a value of 0 means "all operators". - - `y` is the value. -- `55xy` set SSG-EG of operator. - - `x` is the operator (1-4). a value of 0 means "all operators". - - `y` is the value (0-8). - - values between 0 and 7 set SSG-EG. - - value 8 disables it. -- `56xx`: set DR of all operators. -- `57xx`: set DR of operator 1. -- `58xx`: set DR of operator 2. -- `59xx`: set DR of operator 3. -- `5Axx`: set DR of operator 4. -- `5Bxx`: set D2R/SR of all operators. -- `5Cxx`: set D2R/SR of operator 1. -- `5Dxx`: set D2R/SR of operator 2. -- `5Exx`: set D2R/SR of operator 3. -- `5Fxx`: set D2R/SR of operator 4. diff --git a/papers/doc/7-systems/ym2610.md b/papers/doc/7-systems/ym2610.md deleted file mode 100644 index a18888e6..00000000 --- a/papers/doc/7-systems/ym2610.md +++ /dev/null @@ -1,99 +0,0 @@ -# Neo Geo/Yamaha YM2610 - -originally an arcade board, but SNK shortly adapted it to a rather expensive video game console with the world's biggest cartridges because some people liked the system so much they wanted a home version of it. - -its soundchip is a 4-in-1: 4ch 4-op FM, YM2149 (AY-3-8910 clone) and 2 different format ADPCM in a single package! - -# effects - -- `10xy`: set LFO parameters. - - `x` toggles the LFO. - - `y` sets its speed. -- `11xx`: set feedback of channel. -- `12xx`: set operator 1 level. -- `13xx`: set operator 2 level. -- `14xx`: set operator 3 level. -- `15xx`: set operator 4 level. -- `16xy`: set multiplier of operator. - - `x` is the operator (1-4). - - `y` is the multiplier. -- `18xx`: toggle extended channel 2 mode. - - 0 disables it and 1 enables it. - - only in extended channel 2 chip. -- `19xx`: set attack of all operators. -- `1Axx`: set attack of operator 1. -- `1Bxx`: set attack of operator 2. -- `1Cxx`: set attack of operator 3. -- `1Dxx`: set attack of operator 4. -- `20xx`: set SSG channel mode. `xx` may be one of the following: - - `00`: square - - `01`: noise - - `02`: square and noise - - `03`: nothing (apparently) - - `04`: envelope and square - - `05`: envelope and noise - - `06`: envelope and square and noise - - `07`: nothing -- `21xx`: set noise frequency. `xx` is a value between 00 and 1F. -- `22xy`: set envelope mode. - - `x` sets the envelope shape, which may be one of the following: - - `0: \___` decay - - `4: /___` attack once - - `8: \\\\` saw - - `9: \___` decay - - `A: \/\/` inverse obelisco - - `B: \¯¯¯` decay once - - `C: ////` inverse saw - - `D: /¯¯¯` attack - - `E: /\/\` obelisco - - `F: /___` attack once - - if `y` is 1 then the envelope will affect this channel. -- `23xx`: set envelope period low byte. -- `24xx`: set envelope period high byte. -- `25xx`: slide envelope period up. -- `26xx`: slide envelope period down. -- `29xy`: enable SSG auto-envelope mode. - - in this mode the envelope period is set to the channel's notes, multiplied by a fraction. - - `x` is the numerator. - - `y` is the denominator. - - if `x` or `y` are 0 this will disable auto-envelope mode. -- `30xx`: enable envelope hard reset. - - this works by inserting a quick release and tiny delay before a new note. -- `50xy`: set AM of operator. - - `x` is the operator (1-4). a value of 0 means "all operators". - - `y` determines whether AM is on. -- `51xy` set SL of operator. - - `x` is the operator (1-4). a value of 0 means "all operators". - - `y` is the value. -- `52xy` set RR of operator. - - `x` is the operator (1-4). a value of 0 means "all operators". - - `y` is the value. -- `53xy` set DT of operator. - - `x` is the operator (1-4). a value of 0 means "all operators". - - `y` is the value: - - 0: +0 - - 1: +1 - - 2: +2 - - 3: +3 - - 4: -0 - - 5: -3 - - 6: -2 - - 7: -1 -- `54xy` set RS of operator. - - `x` is the operator (1-4). a value of 0 means "all operators". - - `y` is the value. -- `55xy` set SSG-EG of operator. - - `x` is the operator (1-4). a value of 0 means "all operators". - - `y` is the value (0-8). - - values between 0 and 7 set SSG-EG. - - value 8 disables it. -- `56xx`: set DR of all operators. -- `57xx`: set DR of operator 1. -- `58xx`: set DR of operator 2. -- `59xx`: set DR of operator 3. -- `5Axx`: set DR of operator 4. -- `5Bxx`: set D2R/SR of all operators. -- `5Cxx`: set D2R/SR of operator 1. -- `5Dxx`: set D2R/SR of operator 2. -- `5Exx`: set D2R/SR of operator 3. -- `5Fxx`: set D2R/SR of operator 4. diff --git a/papers/doc/7-systems/ym2610b.md b/papers/doc/7-systems/ym2610b.md deleted file mode 100644 index f20e82ed..00000000 --- a/papers/doc/7-systems/ym2610b.md +++ /dev/null @@ -1,98 +0,0 @@ -# Taito Arcade/Yamaha YM2610B - -YM2610B is basically YM2610 with 2 extra FM channels used at some 90s Taito arcade hardware. -it is backward compatible with the original chip. - -# effects - -- `10xy`: set LFO parameters. - - `x` toggles the LFO. - - `y` sets its speed. -- `11xx`: set feedback of channel. -- `12xx`: set operator 1 level. -- `13xx`: set operator 2 level. -- `14xx`: set operator 3 level. -- `15xx`: set operator 4 level. -- `16xy`: set multiplier of operator. - - `x` is the operator (1-4). - - `y` is the multiplier. -- `18xx`: toggle extended channel 3 mode. - - 0 disables it and 1 enables it. - - only in extended channel 3 chip. -- `19xx`: set attack of all operators. -- `1Axx`: set attack of operator 1. -- `1Bxx`: set attack of operator 2. -- `1Cxx`: set attack of operator 3. -- `1Dxx`: set attack of operator 4. -- `20xx`: set SSG channel mode. `xx` may be one of the following: - - `00`: square - - `01`: noise - - `02`: square and noise - - `03`: nothing (apparently) - - `04`: envelope and square - - `05`: envelope and noise - - `06`: envelope and square and noise - - `07`: nothing -- `21xx`: set noise frequency. `xx` is a value between 00 and 1F. -- `22xy`: set envelope mode. - - `x` sets the envelope shape, which may be one of the following: - - `0: \___` decay - - `4: /___` attack once - - `8: \\\\` saw - - `9: \___` decay - - `A: \/\/` inverse obelisco - - `B: \¯¯¯` decay once - - `C: ////` inverse saw - - `D: /¯¯¯` attack - - `E: /\/\` obelisco - - `F: /___` attack once - - if `y` is 1 then the envelope will affect this channel. -- `23xx`: set envelope period low byte. -- `24xx`: set envelope period high byte. -- `25xx`: slide envelope period up. -- `26xx`: slide envelope period down. -- `29xy`: enable SSG auto-envelope mode. - - in this mode the envelope period is set to the channel's notes, multiplied by a fraction. - - `x` is the numerator. - - `y` is the denominator. - - if `x` or `y` are 0 this will disable auto-envelope mode. -- `30xx`: enable envelope hard reset. - - this works by inserting a quick release and tiny delay before a new note. -- `50xy`: set AM of operator. - - `x` is the operator (1-4). a value of 0 means "all operators". - - `y` determines whether AM is on. -- `51xy` set SL of operator. - - `x` is the operator (1-4). a value of 0 means "all operators". - - `y` is the value. -- `52xy` set RR of operator. - - `x` is the operator (1-4). a value of 0 means "all operators". - - `y` is the value. -- `53xy` set DT of operator. - - `x` is the operator (1-4). a value of 0 means "all operators". - - `y` is the value: - - 0: +0 - - 1: +1 - - 2: +2 - - 3: +3 - - 4: -0 - - 5: -3 - - 6: -2 - - 7: -1 -- `54xy` set RS of operator. - - `x` is the operator (1-4). a value of 0 means "all operators". - - `y` is the value. -- `55xy` set SSG-EG of operator. - - `x` is the operator (1-4). a value of 0 means "all operators". - - `y` is the value (0-8). - - values between 0 and 7 set SSG-EG. - - value 8 disables it. -- `56xx`: set DR of all operators. -- `57xx`: set DR of operator 1. -- `58xx`: set DR of operator 2. -- `59xx`: set DR of operator 3. -- `5Axx`: set DR of operator 4. -- `5Bxx`: set D2R/SR of all operators. -- `5Cxx`: set D2R/SR of operator 1. -- `5Dxx`: set D2R/SR of operator 2. -- `5Exx`: set D2R/SR of operator 3. -- `5Fxx`: set D2R/SR of operator 4. diff --git a/papers/doc/7-systems/ym2612.md b/papers/doc/7-systems/ym2612.md deleted file mode 100644 index 1eeb148e..00000000 --- a/papers/doc/7-systems/ym2612.md +++ /dev/null @@ -1,67 +0,0 @@ -# Yamaha YM2612 - -one of two chips that powered the Sega Genesis. It is a six-channel, four-operator FM synthesizer. Channel #6 can be turned into 8-bit PCM player. - -# effects - -- `10xy`: set LFO parameters. - - `x` toggles the LFO. - - `y` sets its speed. -- `11xx`: set feedback of channel. -- `12xx`: set operator 1 level. -- `13xx`: set operator 2 level. -- `14xx`: set operator 3 level. -- `15xx`: set operator 4 level. -- `16xy`: set multiplier of operator. - - `x` is the operator (1-4). - - `y` is the multiplier. -- `17xx`: enable PCM channel. - - this only works on channel 6. -- `18xx`: toggle extended channel 3 mode. - - 0 disables it and 1 enables it. - - only in extended channel 3 chip. -- `19xx`: set attack of all operators. -- `1Axx`: set attack of operator 1. -- `1Bxx`: set attack of operator 2. -- `1Cxx`: set attack of operator 3. -- `1Dxx`: set attack of operator 4. -- `30xx`: enable envelope hard reset. - - this works by inserting a quick release and tiny delay before a new note. -- `50xy`: set AM of operator. - - `x` is the operator (1-4). a value of 0 means "all operators". - - `y` determines whether AM is on. -- `51xy` set SL of operator. - - `x` is the operator (1-4). a value of 0 means "all operators". - - `y` is the value. -- `52xy` set RR of operator. - - `x` is the operator (1-4). a value of 0 means "all operators". - - `y` is the value. -- `53xy` set DT of operator. - - `x` is the operator (1-4). a value of 0 means "all operators". - - `y` is the value: - - 0: -3 - - 1: -2 - - 2: -1 - - 3: 0 - - 4: 1 - - 5: 2 - - 6: 3 - - 7: -0 -- `54xy` set RS of operator. - - `x` is the operator (1-4). a value of 0 means "all operators". - - `y` is the value. -- `55xy` set SSG-EG of operator. - - `x` is the operator (1-4). a value of 0 means "all operators". - - `y` is the value (0-8). - - values between 0 and 7 set SSG-EG. - - value 8 disables it. -- `56xx`: set DR of all operators. -- `57xx`: set DR of operator 1. -- `58xx`: set DR of operator 2. -- `59xx`: set DR of operator 3. -- `5Axx`: set DR of operator 4. -- `5Bxx`: set D2R/SR of all operators. -- `5Cxx`: set D2R/SR of operator 1. -- `5Dxx`: set D2R/SR of operator 2. -- `5Exx`: set D2R/SR of operator 3. -- `5Fxx`: set D2R/SR of operator 4. diff --git a/papers/format.md b/papers/format.md index 248a98d0..bf0b929e 100644 --- a/papers/format.md +++ b/papers/format.md @@ -32,6 +32,7 @@ these fields are 0 in format versions prior to 100 (0.6pre1). the format versions are: +- 159: Furnace dev159 - 158: Furnace 0.6pre5 - 157: Furnace dev157 - 156: Furnace dev156 @@ -1232,7 +1233,8 @@ size | description | - 2: ping-pong 1 | flags (>=129) or reserved | - 0: BRR emphasis - 1 | reserved + 1 | flags 2 (>=159) or reserved + | - 0: dither 4 | loop start | - -1 means no loop 4 | loop end diff --git a/scripts/release-linux-AppImage.sh b/scripts/release-linux-AppImage.sh index 7c20476f..4cf8a8cd 100755 --- a/scripts/release-linux-AppImage.sh +++ b/scripts/release-linux-AppImage.sh @@ -47,5 +47,3 @@ cd ../../.. [ -e appimagetool-x86_64.AppImage ] || { wget "https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage" && chmod 755 appimagetool-x86_64.AppImage; } ./appimagetool-x86_64.AppImage --appimage-extract ARCH=$(uname -m) ./squashfs-root/AppRun furnace.AppDir - -#zip -r furnace.zip LICENSE.txt Furnace*.dmg README.txt papers diff --git a/scripts/release-linux.sh b/scripts/release-linux.sh index 570712f0..030f8259 100755 --- a/scripts/release-linux.sh +++ b/scripts/release-linux.sh @@ -14,7 +14,7 @@ fi cd linuxbuild -cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS="-O2" -DCMAKE_CXX_FLAGS="-O2 -Wall -Wextra -Wno-unused-parameter -Werror" .. || exit 1 +cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS="-O3" -DCMAKE_CXX_FLAGS="-O3 -Wall -Wextra -Wno-unused-parameter -Werror" .. || exit 1 make -j4 || exit 1 cd .. @@ -51,6 +51,7 @@ cd .. cp ../../../LICENSE . || exit 1 cp ../../../README.md . || exit 1 cp -r ../../../papers papers || exit 1 +cp -r ../../../doc doc || exit 1 rmdir usr || exit 1 strip -s furnace diff --git a/scripts/release-win32.sh b/scripts/release-win32.sh index df603dba..e0c0eec6 100755 --- a/scripts/release-win32.sh +++ b/scripts/release-win32.sh @@ -27,13 +27,14 @@ cp ../../LICENSE LICENSE.txt || exit 1 cp ../../win32build/furnace.exe . || exit 1 cp ../../README.md README.txt || exit 1 cp -r ../../papers papers || exit 1 +cp -r ../../doc doc || exit 1 cp -r ../../demos demos || exit 1 cp -r ../../instruments instruments || exit 1 cp -r ../../wavetables wavetables || exit 1 i686-w64-mingw32-strip -s furnace.exe || exit 1 -zip -r furnace.zip LICENSE.txt furnace.exe README.txt papers demos instruments wavetables +zip -r furnace.zip LICENSE.txt furnace.exe README.txt papers doc demos instruments wavetables furName=$(git describe --tags | sed "s/v0/0/") diff --git a/scripts/release-win64.sh b/scripts/release-win64.sh index e1678eda..9183007b 100755 --- a/scripts/release-win64.sh +++ b/scripts/release-win64.sh @@ -27,13 +27,14 @@ cp ../../LICENSE LICENSE.txt || exit 1 cp ../../winbuild/furnace.exe . || exit 1 cp ../../README.md README.txt || exit 1 cp -r ../../papers papers || exit 1 +cp -r ../../doc doc || exit 1 cp -r ../../demos demos || exit 1 cp -r ../../instruments instruments || exit 1 cp -r ../../wavetables wavetables || exit 1 x86_64-w64-mingw32-strip -s furnace.exe || exit 1 -zip -r furnace.zip LICENSE.txt furnace.exe README.txt papers demos instruments wavetables +zip -r furnace.zip LICENSE.txt furnace.exe README.txt papers doc demos instruments wavetables furName=$(git describe --tags | sed "s/v0/0/") diff --git a/src/audio/rtmidi.cpp b/src/audio/rtmidi.cpp index cbf4dca4..ea1903c3 100644 --- a/src/audio/rtmidi.cpp +++ b/src/audio/rtmidi.cpp @@ -160,6 +160,7 @@ bool TAMidiInRtMidi::quit() { bool TAMidiOutRtMidi::send(const TAMidiMessage& what) { if (!isOpen) return false; + if (!isWorking) return false; if (what.type<0x80) return false; size_t len=0; switch (what.type&0xf0) { @@ -190,6 +191,7 @@ bool TAMidiOutRtMidi::send(const TAMidiMessage& what) { port->sendMessage(what.sysExData.get(),len); } catch (RtMidiError& e) { logE("MIDI output error! %s",e.what()); + isWorking=false; return false; } return true; @@ -209,6 +211,7 @@ bool TAMidiOutRtMidi::send(const TAMidiMessage& what) { port->sendMessage((const unsigned char*)&what.type,len); } catch (RtMidiError& e) { logE("MIDI output error! %s",e.what()); + isWorking=false; return false; } return true; @@ -237,17 +240,20 @@ bool TAMidiOutRtMidi::openDevice(String name) { } isOpen=portOpen; if (!portOpen) logW("could not find MIDI out device..."); + isWorking=true; return portOpen; } catch (RtMidiError& e) { logW("could not open MIDI out device! %s",e.what()); return false; } + isWorking=true; return true; } bool TAMidiOutRtMidi::closeDevice() { if (port==NULL) return false; if (!isOpen) return false; + isWorking=false; try { port->closePort(); } catch (RtMidiError& e) { diff --git a/src/audio/rtmidi.h b/src/audio/rtmidi.h index 5a8e06e0..33a71af5 100644 --- a/src/audio/rtmidi.h +++ b/src/audio/rtmidi.h @@ -38,7 +38,7 @@ class TAMidiInRtMidi: public TAMidiIn { class TAMidiOutRtMidi: public TAMidiOut { RtMidiOut* port; - bool isOpen; + bool isOpen, isWorking; public: bool send(const TAMidiMessage& what); bool isDeviceOpen(); @@ -49,5 +49,6 @@ class TAMidiOutRtMidi: public TAMidiOut { bool init(); TAMidiOutRtMidi(): port(NULL), - isOpen(false) {} + isOpen(false), + isWorking(false) {} }; \ No newline at end of file diff --git a/src/engine/dispatch.h b/src/engine/dispatch.h index 7469f903..c19e7d95 100644 --- a/src/engine/dispatch.h +++ b/src/engine/dispatch.h @@ -284,6 +284,8 @@ struct DivRegWrite { * - xx is the instance ID * - 0xffffxx03: set sample playback direction * - x is the instance ID + * - 0xffffxx04: switch sample bank + * - for use in VGM export * - 0xffffffff: reset */ unsigned int addr; diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index 9f70aef0..1aa8188e 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -1444,9 +1444,6 @@ void DivEngine::initSongWithDesc(const char* description, bool inBase64, bool ol // extra attributes song.subsong[0]->hz=c.getDouble("tickRate",60.0); - if (song.subsong[0]->hz!=60.0) { - song.subsong[0]->customTempo=true; - } } void DivEngine::createNew(const char* description, String sysName, bool inBase64) { @@ -1681,6 +1678,51 @@ int DivEngine::addSubSong() { return song.subsong.size()-1; } +int DivEngine::duplicateSubSong(int index) { + if (song.subsong.size()>=127) return -1; + BUSY_BEGIN; + saveLock.lock(); + DivSubSong* theCopy=new DivSubSong; + DivSubSong* theOrig=song.subsong[index]; + + theCopy->name=theOrig->name; + theCopy->notes=theOrig->notes; + theCopy->hilightA=theOrig->hilightA; + theCopy->hilightB=theOrig->hilightB; + theCopy->timeBase=theOrig->timeBase; + theCopy->arpLen=theOrig->arpLen; + theCopy->speeds=theOrig->speeds; + theCopy->virtualTempoN=theOrig->virtualTempoN; + theCopy->virtualTempoD=theOrig->virtualTempoD; + theCopy->hz=theOrig->hz; + theCopy->patLen=theOrig->patLen; + theCopy->ordersLen=theOrig->ordersLen; + theCopy->orders=theOrig->orders; + + memcpy(theCopy->chanShow,theOrig->chanShow,DIV_MAX_CHANS*sizeof(bool)); + memcpy(theCopy->chanCollapse,theOrig->chanCollapse,DIV_MAX_CHANS); + + for (int i=0; ichanName[i]=theOrig->chanName[i]; + theCopy->chanShortName[i]=theOrig->chanShortName[i]; + + theCopy->pat[i].effectCols=theOrig->pat[i].effectCols; + + for (int j=0; jpat[i].data[j]==NULL) continue; + DivPattern* origPat=theOrig->pat[i].getPattern(j,false); + DivPattern* copyPat=theCopy->pat[i].getPattern(j,true); + origPat->copyOn(copyPat); + } + } + + song.subsong.push_back(theCopy); + + saveLock.unlock(); + BUSY_END; + return song.subsong.size()-1; +} + bool DivEngine::removeSubSong(int index) { if (song.subsong.size()<=1) return false; stop(); @@ -2696,16 +2738,7 @@ void DivEngine::reset() { elapsedBars=0; elapsedBeats=0; nextSpeed=speeds.val[0]; - divider=60; - if (curSubSong->customTempo) { - divider=curSubSong->hz; - } else { - if (curSubSong->pal) { - divider=60; - } else { - divider=50; - } - } + divider=curSubSong->hz; globalPitch=0; for (int i=0; ireset(); @@ -2920,14 +2953,7 @@ const DivGroovePattern& DivEngine::getSpeeds() { } float DivEngine::getHz() { - if (curSubSong->customTempo) { - return curSubSong->hz; - } else if (curSubSong->pal) { - return 60.0; - } else { - return 50.0; - } - return 60.0; + return curSubSong->hz; } float DivEngine::getCurHz() { @@ -4354,23 +4380,11 @@ void DivEngine::updateSysFlags(int system, bool restart) { BUSY_END; } -void DivEngine::setSongRate(float hz, bool pal) { +void DivEngine::setSongRate(float hz) { BUSY_BEGIN; saveLock.lock(); - curSubSong->pal=!pal; curSubSong->hz=hz; - // what? - curSubSong->customTempo=true; - divider=60; - if (curSubSong->customTempo) { - divider=curSubSong->hz; - } else { - if (curSubSong->pal) { - divider=60; - } else { - divider=50; - } - } + divider=curSubSong->hz; saveLock.unlock(); BUSY_END; } diff --git a/src/engine/engine.h b/src/engine/engine.h index bf842aae..21e15b56 100644 --- a/src/engine/engine.h +++ b/src/engine/engine.h @@ -54,8 +54,8 @@ #define EXTERN_BUSY_BEGIN_SOFT e->softLocked=true; e->isBusy.lock(); #define EXTERN_BUSY_END e->isBusy.unlock(); e->softLocked=false; -#define DIV_VERSION "0.6pre5" -#define DIV_ENGINE_VERSION 158 +#define DIV_VERSION "dev159" +#define DIV_ENGINE_VERSION 159 // for imports #define DIV_VERSION_MOD 0xff01 #define DIV_VERSION_FC 0xff02 @@ -489,7 +489,7 @@ class DivEngine { void processRow(int i, bool afterDelay); void nextOrder(); void nextRow(); - void performVGMWrite(SafeWriter* w, DivSystem sys, DivRegWrite& write, int streamOff, double* loopTimer, double* loopFreq, int* loopSample, bool* sampleDir, bool isSecond, int* pendingFreq, int* playingSample, bool directStream); + void performVGMWrite(SafeWriter* w, DivSystem sys, DivRegWrite& write, int streamOff, double* loopTimer, double* loopFreq, int* loopSample, bool* sampleDir, bool isSecond, int* pendingFreq, int* playingSample, size_t bankOffset, bool directStream); // returns true if end of song. bool nextTick(bool noAccum=false, bool inhibitLowLat=false); bool perSystemEffect(int ch, unsigned char effect, unsigned char effectVal); @@ -954,7 +954,7 @@ class DivEngine { void updateSysFlags(int system, bool restart); // set Hz - void setSongRate(float hz, bool pal); + void setSongRate(float hz); // set remaining loops. -1 means loop forever. void setLoops(int loops); @@ -1052,6 +1052,9 @@ class DivEngine { // add subsong int addSubSong(); + // duplicate subsong + int duplicateSubSong(int index); + // remove subsong bool removeSubSong(int index); diff --git a/src/engine/fileOps.cpp b/src/engine/fileOps.cpp index d3ae5421..ed0c0ce9 100644 --- a/src/engine/fileOps.cpp +++ b/src/engine/fileOps.cpp @@ -220,20 +220,22 @@ bool DivEngine::loadDMF(unsigned char* file, size_t len) { ds.subsong[0]->hilightB=reader.readC(); } + bool customTempo=false; + ds.subsong[0]->timeBase=reader.readC(); ds.subsong[0]->speeds.len=2; ds.subsong[0]->speeds.val[0]=reader.readC(); if (ds.version>0x07) { ds.subsong[0]->speeds.val[1]=reader.readC(); - ds.subsong[0]->pal=reader.readC(); - ds.subsong[0]->hz=(ds.subsong[0]->pal)?60:50; - ds.subsong[0]->customTempo=reader.readC(); + bool pal=reader.readC(); + ds.subsong[0]->hz=pal?60:50; + customTempo=reader.readC(); } else { ds.subsong[0]->speeds.len=1; } if (ds.version>0x0a) { String hz=reader.readString(3); - if (ds.subsong[0]->customTempo) { + if (customTempo) { try { ds.subsong[0]->hz=std::stoi(hz); } catch (std::exception& e) { @@ -304,7 +306,6 @@ bool DivEngine::loadDMF(unsigned char* file, size_t len) { ds.subsong[0]->hz=248; break; } - ds.subsong[0]->customTempo=true; ds.subsong[0]->timeBase=0; addWarning("Yamaha YMU759 emulation is incomplete! please migrate your song to the OPL3 system."); } @@ -1864,8 +1865,6 @@ bool DivEngine::loadFur(unsigned char* file, size_t len) { subSong->speeds.val[1]=reader.readC(); subSong->arpLen=reader.readC(); subSong->hz=reader.readF(); - subSong->pal=(subSong->hz>=53); - subSong->customTempo=true; subSong->patLen=reader.readS(); subSong->ordersLen=reader.readS(); @@ -2489,8 +2488,6 @@ bool DivEngine::loadFur(unsigned char* file, size_t len) { subSong->speeds.val[1]=reader.readC(); subSong->arpLen=reader.readC(); subSong->hz=reader.readF(); - subSong->pal=(subSong->hz>=53); - subSong->customTempo=true; subSong->patLen=reader.readS(); subSong->ordersLen=reader.readS(); @@ -3322,9 +3319,7 @@ bool DivEngine::loadMod(unsigned char* file, size_t len) { ds.subsong[0]->pat[ch].effectCols=fxCols; } - ds.subsong[0]->pal=false; ds.subsong[0]->hz=50; - ds.subsong[0]->customTempo=false; ds.systemLen=(chCount+3)/4; for(int i=0; ispeeds.val[0]=(unsigned char)reader.readC(); ds.subsong[0]->hz=((double)reader.readC())/2.5; - ds.subsong[0]->customTempo=true; unsigned char masterVol=reader.readC(); @@ -3993,8 +3987,6 @@ bool DivEngine::loadFC(unsigned char* file, size_t len) { ds.subsong[0]->ordersLen=seqLen; ds.subsong[0]->patLen=32; ds.subsong[0]->hz=50; - ds.subsong[0]->pal=true; - ds.subsong[0]->customTempo=true; ds.subsong[0]->pat[3].effectCols=3; ds.subsong[0]->speeds.val[0]=3; ds.subsong[0]->speeds.len=1; @@ -5691,7 +5683,8 @@ SafeWriter* DivEngine::saveFur(bool notPrimary, bool newPatternFormat) { SafeWriter* DivEngine::saveDMF(unsigned char version) { // fail if version is not supported - if (version<24 || version>26) { + if (version>26) version=26; + if (version<24) { logE("cannot save in this version!"); lastError="invalid version to save in! this is a bug!"; return NULL; @@ -5819,12 +5812,14 @@ SafeWriter* DivEngine::saveDMF(unsigned char version) { w->writeString(song.author,true); w->writeC(curSubSong->hilightA); w->writeC(curSubSong->hilightB); + + int intHz=curSubSong->hz; w->writeC(curSubSong->timeBase); w->writeC(curSubSong->speeds.val[0]); w->writeC((curSubSong->speeds.len>=2)?curSubSong->speeds.val[1]:curSubSong->speeds.val[0]); - w->writeC(curSubSong->pal); - w->writeC(curSubSong->customTempo); + w->writeC((intHz<=53)?0:1); + w->writeC((intHz!=60 && intHz!=50)); char customHz[4]; memset(customHz,0,4); snprintf(customHz,4,"%d",(int)curSubSong->hz); diff --git a/src/engine/platform/amiga.cpp b/src/engine/platform/amiga.cpp index 7c0b8c24..48128bc6 100644 --- a/src/engine/platform/amiga.cpp +++ b/src/engine/platform/amiga.cpp @@ -168,7 +168,7 @@ void DivPlatformAmiga::acquire(short** buf, size_t len) { outL+=(output*sep2)>>7; outR+=(output*sep1)>>7; } - oscBuf[i]->data[oscBuf[i]->needle++]=(amiga.nextOut[i]*MIN(64,amiga.audVol[i]))<<2; + oscBuf[i]->data[oscBuf[i]->needle++]=(amiga.nextOut[i]*MIN(64,amiga.audVol[i]))<<1; } else { oscBuf[i]->data[oscBuf[i]->needle++]=0; } diff --git a/src/engine/platform/arcade.cpp b/src/engine/platform/arcade.cpp index e617fc0d..0e38bf96 100644 --- a/src/engine/platform/arcade.cpp +++ b/src/engine/platform/arcade.cpp @@ -76,7 +76,8 @@ void DivPlatformArcade::acquire_nuked(short** buf, size_t len) { } for (int i=0; i<8; i++) { - oscBuf[i]->data[oscBuf[i]->needle++]=fm.ch_out[i]; + int chOut=(int16_t)fm.ch_out[i]; + oscBuf[i]->data[oscBuf[i]->needle++]=CLAMP(chOut<<1,-32768,32767); } if (o[0]<-32768) o[0]=-32768; @@ -111,7 +112,8 @@ void DivPlatformArcade::acquire_ymfm(short** buf, size_t len) { fm_ymfm->generate(&out_ymfm); for (int i=0; i<8; i++) { - oscBuf[i]->data[oscBuf[i]->needle++]=(fme->debug_channel(i)->debug_output(0)+fme->debug_channel(i)->debug_output(1)); + int chOut=fme->debug_channel(i)->debug_output(0)+fme->debug_channel(i)->debug_output(1); + oscBuf[i]->data[oscBuf[i]->needle++]=CLAMP(chOut,-32768,32767); } os[0]=out_ymfm.data[0]; diff --git a/src/engine/platform/ay.cpp b/src/engine/platform/ay.cpp index 8eaea3fe..c32a4ee2 100644 --- a/src/engine/platform/ay.cpp +++ b/src/engine/platform/ay.cpp @@ -187,9 +187,9 @@ void DivPlatformAY8910::acquire(short** buf, size_t len) { buf[0][i]=ayBuf[0][0]; buf[1][i]=buf[0][i]; - oscBuf[0]->data[oscBuf[0]->needle++]=sunsoftVolTable[31-(ay->lastIndx&31)]<<3; - oscBuf[1]->data[oscBuf[1]->needle++]=sunsoftVolTable[31-((ay->lastIndx>>5)&31)]<<3; - oscBuf[2]->data[oscBuf[2]->needle++]=sunsoftVolTable[31-((ay->lastIndx>>10)&31)]<<3; + oscBuf[0]->data[oscBuf[0]->needle++]=CLAMP(sunsoftVolTable[31-(ay->lastIndx&31)]<<3,-32768,32767); + oscBuf[1]->data[oscBuf[1]->needle++]=CLAMP(sunsoftVolTable[31-((ay->lastIndx>>5)&31)]<<3,-32768,32767); + oscBuf[2]->data[oscBuf[2]->needle++]=CLAMP(sunsoftVolTable[31-((ay->lastIndx>>10)&31)]<<3,-32768,32767); } } else { for (size_t i=0; i>12; - oscBuf[j]->data[oscBuf[j]->needle++]=chanOut; + oscBuf[j]->data[oscBuf[j]->needle++]=chanOut<<1; out+=chanOut; } else { oscBuf[j]->data[oscBuf[j]->needle++]=0; diff --git a/src/engine/platform/es5506.cpp b/src/engine/platform/es5506.cpp index 5f6e2829..f388e860 100644 --- a/src/engine/platform/es5506.cpp +++ b/src/engine/platform/es5506.cpp @@ -168,7 +168,7 @@ void DivPlatformES5506::acquire(short** buf, size_t len) { buf[(o<<1)|1][h]=es5506.rout(o); } for (int i=chanMax; i>=0; i--) { - oscBuf[i]->data[oscBuf[i]->needle++]=(es5506.voice_lout(i)+es5506.voice_rout(i))>>5; + oscBuf[i]->data[oscBuf[i]->needle++]=(es5506.voice_lout(i)+es5506.voice_rout(i))>>6; } } } diff --git a/src/engine/platform/fds.cpp b/src/engine/platform/fds.cpp index 420f3e3a..ea903ced 100644 --- a/src/engine/platform/fds.cpp +++ b/src/engine/platform/fds.cpp @@ -64,7 +64,7 @@ void DivPlatformFDS::acquire_puNES(short* buf, size_t len) { buf[i]=sample; if (++writeOscBuf>=32) { writeOscBuf=0; - oscBuf->data[oscBuf->needle++]=sample<<1; + oscBuf->data[oscBuf->needle++]=sample*3; } } } @@ -80,7 +80,7 @@ void DivPlatformFDS::acquire_NSFPlay(short* buf, size_t len) { buf[i]=sample; if (++writeOscBuf>=32) { writeOscBuf=0; - oscBuf->data[oscBuf->needle++]=sample<<1; + oscBuf->data[oscBuf->needle++]=sample*3; } } } diff --git a/src/engine/platform/ga20.cpp b/src/engine/platform/ga20.cpp index 7b9d86a1..7794d61a 100644 --- a/src/engine/platform/ga20.cpp +++ b/src/engine/platform/ga20.cpp @@ -71,11 +71,16 @@ void DivPlatformGA20::acquire(short** buf, size_t len) { delay=w.delay; } } - short *buffer[4] = {&ga20Buf[0][h],&ga20Buf[1][h],&ga20Buf[2][h],&ga20Buf[3][h]}; - ga20.sound_stream_update(buffer, 1); + short *buffer[4]={ + &ga20Buf[0][h], + &ga20Buf[1][h], + &ga20Buf[2][h], + &ga20Buf[3][h] + }; + ga20.sound_stream_update(buffer,1); buf[0][h]=(signed int)(ga20Buf[0][h]+ga20Buf[1][h]+ga20Buf[2][h]+ga20Buf[3][h])>>2; for (int i=0; i<4; i++) { - oscBuf[i]->data[oscBuf[i]->needle++]=ga20Buf[i][h]; + oscBuf[i]->data[oscBuf[i]->needle++]=ga20Buf[i][h]>>1; } } } diff --git a/src/engine/platform/gb.cpp b/src/engine/platform/gb.cpp index 9a5d6d7d..683f9721 100644 --- a/src/engine/platform/gb.cpp +++ b/src/engine/platform/gb.cpp @@ -19,6 +19,7 @@ #include "gb.h" #include "../engine.h" +#include "../../ta-log.h" #include #define rWrite(a,v) if (!skipRegisterWrites) {writes.emplace(a,v); regPool[(a)&0x7f]=v; if (dumpWrites) {addWrite(a,v);} } @@ -80,6 +81,7 @@ void DivPlatformGB::acquire(short** buf, size_t len) { } void DivPlatformGB::updateWave() { + logV("WAVE UPDATE"); rWrite(0x1a,0); for (int i=0; i<16; i++) { int nibble1=ws.output[((i<<1)+antiClickWavePos)&31]; @@ -299,6 +301,7 @@ void DivPlatformGB::tick(bool sysTick) { } if (chan[i].keyOn) { if (i==2) { // wave + rWrite(16+i*5,0x00); rWrite(16+i*5,0x80); rWrite(16+i*5+2,gbVolMap[chan[i].outVol]); } else { @@ -664,9 +667,7 @@ void DivPlatformGB::setFlags(const DivConfig& flags) { } invertWave=flags.getBool("invertWave",true); enoughAlready=flags.getBool("enoughAlready",false); -} -int DivPlatformGB::init(DivEngine* p, int channels, int sugRate, const DivConfig& flags) { chipClock=4194304; CHECK_CUSTOM_CLOCK; rate=chipClock/16; @@ -675,6 +676,9 @@ int DivPlatformGB::init(DivEngine* p, int channels, int sugRate, const DivConfig oscBuf[i]=new DivDispatchOscBuffer; oscBuf[i]->rate=rate; } +} + +int DivPlatformGB::init(DivEngine* p, int channels, int sugRate, const DivConfig& flags) { parent=p; dumpWrites=false; skipRegisterWrites=false; diff --git a/src/engine/platform/genesis.cpp b/src/engine/platform/genesis.cpp index e32ec528..e7f1fa15 100644 --- a/src/engine/platform/genesis.cpp +++ b/src/engine/platform/genesis.cpp @@ -122,6 +122,8 @@ void DivPlatformGenesis::processDAC(int iRate) { urgentWrite(0x2a,(unsigned char)sample+0x80); chan[5].dacReady=false; } + } else { + urgentWrite(0x2a,0x80); } chan[5].dacPos++; if (!chan[5].dacDirection && (s->isLoopable() && chan[5].dacPos>=(unsigned int)s->loopEnd)) { @@ -184,16 +186,18 @@ void DivPlatformGenesis::acquire_nuked(short** buf, size_t len) { if (i==5) { if (fm.dacen) { if (softPCM) { - oscBuf[5]->data[oscBuf[5]->needle++]=chan[5].dacOutput<<7; - oscBuf[6]->data[oscBuf[6]->needle++]=chan[6].dacOutput<<7; + oscBuf[5]->data[oscBuf[5]->needle++]=chan[5].dacOutput<<6; + oscBuf[6]->data[oscBuf[6]->needle++]=chan[6].dacOutput<<6; } else { - oscBuf[i]->data[oscBuf[i]->needle++]=fm.dacdata<<7; + oscBuf[i]->data[oscBuf[i]->needle++]=((fm.dacdata^0x100)-0x100)<<6; + oscBuf[6]->data[oscBuf[6]->needle++]=0; } } else { - oscBuf[i]->data[oscBuf[i]->needle++]=fm.ch_out[i]<<(chipType==2?0:7); + oscBuf[i]->data[oscBuf[i]->needle++]=CLAMP(fm.ch_out[i]<<(chipType==2?1:6),-32768,32767); + oscBuf[6]->data[oscBuf[6]->needle++]=0; } } else { - oscBuf[i]->data[oscBuf[i]->needle++]=fm.ch_out[i]<<(chipType==2?0:7); + oscBuf[i]->data[oscBuf[i]->needle++]=CLAMP(fm.ch_out[i]<<(chipType==2?1:6),-32768,32767); } } @@ -241,19 +245,21 @@ void DivPlatformGenesis::acquire_ymfm(short** buf, size_t len) { //OPN2_Write(&fm,0,0); for (int i=0; i<6; i++) { - int chOut=(fme->debug_channel(i)->debug_output(0)+fme->debug_channel(i)->debug_output(1))<<6; + int chOut=(fme->debug_channel(i)->debug_output(0)+fme->debug_channel(i)->debug_output(1))<<5; if (chOut<-32768) chOut=-32768; if (chOut>32767) chOut=32767; if (i==5) { if (fm_ymfm->debug_dac_enable()) { if (softPCM) { - oscBuf[5]->data[oscBuf[5]->needle++]=chan[5].dacOutput<<7; - oscBuf[6]->data[oscBuf[6]->needle++]=chan[6].dacOutput<<7; + oscBuf[5]->data[oscBuf[5]->needle++]=chan[5].dacOutput<<6; + oscBuf[6]->data[oscBuf[6]->needle++]=chan[6].dacOutput<<6; } else { - oscBuf[i]->data[oscBuf[i]->needle++]=fm_ymfm->debug_dac_data()<<7; + oscBuf[i]->data[oscBuf[i]->needle++]=((fm_ymfm->debug_dac_data()^0x100)-0x100)<<6; + oscBuf[6]->data[oscBuf[6]->needle++]=0; } } else { oscBuf[i]->data[oscBuf[i]->needle++]=chOut; + oscBuf[6]->data[oscBuf[6]->needle++]=0; } } else { oscBuf[i]->data[oscBuf[i]->needle++]=chOut; @@ -1160,6 +1166,11 @@ int DivPlatformGenesis::dispatch(DivCommand c) { return 1; } +#define DRSLD2R(x) \ + if (chan[i].state.op[x].drdata[oscBuf[i]->needle++]=(lout[i]+rout[i])<<4; + oscBuf[i]->data[oscBuf[i]->needle++]=(lout[i]+rout[i])<<3; } } else { const unsigned char vol=regPool[0xc]; const signed int out[2]={(k007232.output(0)*(vol&0xf)),(k007232.output(1)*((vol>>4)&0xf))}; buf[0][h]=(out[0]+out[1])<<4; for (int i=0; i<2; i++) { - oscBuf[i]->data[oscBuf[i]->needle++]=out[i]<<5; + oscBuf[i]->data[oscBuf[i]->needle++]=out[i]<<4; } } } diff --git a/src/engine/platform/mmc5.cpp b/src/engine/platform/mmc5.cpp index 11b04e81..e9ac6be9 100644 --- a/src/engine/platform/mmc5.cpp +++ b/src/engine/platform/mmc5.cpp @@ -85,9 +85,9 @@ void DivPlatformMMC5::acquire(short** buf, size_t len) { if (++writeOscBuf>=32) { writeOscBuf=0; - oscBuf[0]->data[oscBuf[0]->needle++]=isMuted[0]?0:((mmc5->S3.output*10)<<7); - oscBuf[1]->data[oscBuf[1]->needle++]=isMuted[1]?0:((mmc5->S4.output*10)<<7); - oscBuf[2]->data[oscBuf[2]->needle++]=isMuted[2]?0:((mmc5->pcm.output*2)<<6); + oscBuf[0]->data[oscBuf[0]->needle++]=isMuted[0]?0:((mmc5->S3.output)<<11); + oscBuf[1]->data[oscBuf[1]->needle++]=isMuted[1]?0:((mmc5->S4.output)<<11); + oscBuf[2]->data[oscBuf[2]->needle++]=isMuted[2]?0:((mmc5->pcm.output)<<7); } } } diff --git a/src/engine/platform/msm5232.cpp b/src/engine/platform/msm5232.cpp index eb8d5cbf..55df6128 100644 --- a/src/engine/platform/msm5232.cpp +++ b/src/engine/platform/msm5232.cpp @@ -60,7 +60,7 @@ void DivPlatformMSM5232::acquire(short** buf, size_t len) { ((regPool[12+(i>>4)]&2)?((msm->vo8[i]*partVolume[2+(i&4)])>>8):0)+ ((regPool[12+(i>>4)]&4)?((msm->vo4[i]*partVolume[1+(i&4)])>>8):0)+ ((regPool[12+(i>>4)]&8)?((msm->vo2[i]*partVolume[i&4])>>8):0) - )<<3; + )<<2; oscBuf[i]->data[oscBuf[i]->needle++]=CLAMP(o,-32768,32767); } diff --git a/src/engine/platform/msm6258.cpp b/src/engine/platform/msm6258.cpp index 6591eda5..31002a9c 100644 --- a/src/engine/platform/msm6258.cpp +++ b/src/engine/platform/msm6258.cpp @@ -84,7 +84,7 @@ void DivPlatformMSM6258::acquire(short** buf, size_t len) { } else { buf[0][h]=(msmPan&2)?msmOut:0; buf[1][h]=(msmPan&1)?msmOut:0; - oscBuf[0]->data[oscBuf[0]->needle++]=msmPan?msmOut:0; + oscBuf[0]->data[oscBuf[0]->needle++]=msmPan?(msmOut>>1):0; } } } diff --git a/src/engine/platform/msm6295.cpp b/src/engine/platform/msm6295.cpp index de7fedd5..2aff0006 100644 --- a/src/engine/platform/msm6295.cpp +++ b/src/engine/platform/msm6295.cpp @@ -79,9 +79,8 @@ void DivPlatformMSM6295::acquire(short** buf, size_t len) { if (++updateOsc>=22) { updateOsc=0; - // TODO: per-channel osc for (int i=0; i<4; i++) { - oscBuf[i]->data[oscBuf[i]->needle++]=msm.voice_out(i)<<6; + oscBuf[i]->data[oscBuf[i]->needle++]=msm.voice_out(i)<<5; } } } diff --git a/src/engine/platform/namcowsg.cpp b/src/engine/platform/namcowsg.cpp index 87721eb8..088f1e63 100644 --- a/src/engine/platform/namcowsg.cpp +++ b/src/engine/platform/namcowsg.cpp @@ -177,7 +177,7 @@ void DivPlatformNamcoWSG::acquire(short** buf, size_t len) { }; namco->sound_stream_update(bufC,1); for (int i=0; idata[oscBuf[i]->needle++]=namco->m_channel_list[i].last_out*chans; + oscBuf[i]->data[oscBuf[i]->needle++]=(namco->m_channel_list[i].last_out*chans)>>1; } } } diff --git a/src/engine/platform/nes.cpp b/src/engine/platform/nes.cpp index a25568d0..8fac5235 100644 --- a/src/engine/platform/nes.cpp +++ b/src/engine/platform/nes.cpp @@ -145,7 +145,7 @@ void DivPlatformNES::acquire_NSFPlay(short** buf, size_t len) { oscBuf[0]->data[oscBuf[0]->needle++]=nes1_NP->out[0]<<11; oscBuf[1]->data[oscBuf[1]->needle++]=nes1_NP->out[1]<<11; oscBuf[2]->data[oscBuf[2]->needle++]=nes2_NP->out[0]<<11; - oscBuf[3]->data[oscBuf[3]->needle++]=nes2_NP->out[1]<<11; + oscBuf[3]->data[oscBuf[3]->needle++]=nes2_NP->out[1]<<12; oscBuf[4]->data[oscBuf[4]->needle++]=nes2_NP->out[2]<<8; } } @@ -346,7 +346,11 @@ void DivPlatformNES::tick(bool sysTick) { rWrite(0x4012,(dpcmAddr>>6)&0xff); rWrite(0x4013,dpcmLen&0xff); rWrite(0x4015,31); - dpcmBank=dpcmAddr>>14; + if (dpcmBank!=(dpcmAddr>>14)) { + dpcmBank=dpcmAddr>>14; + logV("switching bank to %d",dpcmBank); + if (dumpWrites) addWrite(0xffff0004,dpcmBank); + } } } else { if (nextDPCMFreq>=0) { @@ -425,7 +429,11 @@ int DivPlatformNES::dispatch(DivCommand c) { rWrite(0x4012,(dpcmAddr>>6)&0xff); rWrite(0x4013,dpcmLen&0xff); rWrite(0x4015,31); - dpcmBank=dpcmAddr>>14; + if (dpcmBank!=(dpcmAddr>>14)) { + dpcmBank=dpcmAddr>>14; + logV("switching bank to %d",dpcmBank); + if (dumpWrites) addWrite(0xffff0004,dpcmBank); + } } } break; @@ -854,6 +862,7 @@ int DivPlatformNES::init(DivEngine* p, int channels, int sugRate, const DivConfi dpcmMem=new unsigned char[262144]; dpcmMemLen=0; dpcmBank=0; + if (dumpWrites) addWrite(0xffff0004,dpcmBank); init_nla_table(500,500); reset(); diff --git a/src/engine/platform/opl.cpp b/src/engine/platform/opl.cpp index a54667a7..d340aa31 100644 --- a/src/engine/platform/opl.cpp +++ b/src/engine/platform/opl.cpp @@ -211,7 +211,7 @@ void DivPlatformOPL::acquire_nuked(short** buf, size_t len) { if (!isMuted[adpcmChan]) { os[0]-=aOut.data[0]>>3; os[1]-=aOut.data[0]>>3; - oscBuf[adpcmChan]->data[oscBuf[adpcmChan]->needle++]=aOut.data[0]; + oscBuf[adpcmChan]->data[oscBuf[adpcmChan]->needle++]=aOut.data[0]>>1; } else { oscBuf[adpcmChan]->data[oscBuf[adpcmChan]->needle++]=0; } @@ -220,47 +220,45 @@ void DivPlatformOPL::acquire_nuked(short** buf, size_t len) { if (fm.rhy&0x20) { for (int i=0; idata[oscBuf[i]->needle]=0; if (fm.channel[i].out[0]!=NULL) { - oscBuf[i]->data[oscBuf[i]->needle]+=*fm.channel[ch].out[0]; + chOut+=*fm.channel[ch].out[0]; } if (fm.channel[i].out[1]!=NULL) { - oscBuf[i]->data[oscBuf[i]->needle]+=*fm.channel[ch].out[1]; + chOut+=*fm.channel[ch].out[1]; } if (fm.channel[i].out[2]!=NULL) { - oscBuf[i]->data[oscBuf[i]->needle]+=*fm.channel[ch].out[2]; + chOut+=*fm.channel[ch].out[2]; } if (fm.channel[i].out[3]!=NULL) { - oscBuf[i]->data[oscBuf[i]->needle]+=*fm.channel[ch].out[3]; + chOut+=*fm.channel[ch].out[3]; } - oscBuf[i]->data[oscBuf[i]->needle]<<=1; - oscBuf[i]->needle++; + oscBuf[i]->data[oscBuf[i]->needle++]=CLAMP(chOut<<(i==melodicChans?1:2),-32768,32767); } // special - oscBuf[melodicChans+1]->data[oscBuf[melodicChans+1]->needle++]=fm.slot[16].out*6; - oscBuf[melodicChans+2]->data[oscBuf[melodicChans+2]->needle++]=fm.slot[14].out*6; - oscBuf[melodicChans+3]->data[oscBuf[melodicChans+3]->needle++]=fm.slot[17].out*6; - oscBuf[melodicChans+4]->data[oscBuf[melodicChans+4]->needle++]=fm.slot[13].out*6; + oscBuf[melodicChans+1]->data[oscBuf[melodicChans+1]->needle++]=fm.slot[16].out*4; + oscBuf[melodicChans+2]->data[oscBuf[melodicChans+2]->needle++]=fm.slot[14].out*4; + oscBuf[melodicChans+3]->data[oscBuf[melodicChans+3]->needle++]=fm.slot[17].out*4; + oscBuf[melodicChans+4]->data[oscBuf[melodicChans+4]->needle++]=fm.slot[13].out*4; } else { for (int i=0; idata[oscBuf[i]->needle]=0; if (fm.channel[i].out[0]!=NULL) { - oscBuf[i]->data[oscBuf[i]->needle]+=*fm.channel[ch].out[0]; + chOut+=*fm.channel[ch].out[0]; } if (fm.channel[i].out[1]!=NULL) { - oscBuf[i]->data[oscBuf[i]->needle]+=*fm.channel[ch].out[1]; + chOut+=*fm.channel[ch].out[1]; } if (fm.channel[i].out[2]!=NULL) { - oscBuf[i]->data[oscBuf[i]->needle]+=*fm.channel[ch].out[2]; + chOut+=*fm.channel[ch].out[2]; } if (fm.channel[i].out[3]!=NULL) { - oscBuf[i]->data[oscBuf[i]->needle]+=*fm.channel[ch].out[3]; + chOut+=*fm.channel[ch].out[3]; } - oscBuf[i]->data[oscBuf[i]->needle]<<=1; - oscBuf[i]->needle++; + oscBuf[i]->data[oscBuf[i]->needle++]=CLAMP(chOut<<2,-32768,32767); } } diff --git a/src/engine/platform/opll.cpp b/src/engine/platform/opll.cpp index 8f30a9dd..38b892e8 100644 --- a/src/engine/platform/opll.cpp +++ b/src/engine/platform/opll.cpp @@ -101,8 +101,16 @@ void DivPlatformOPLL::tick(bool sysTick) { if (chan[i].std.vol.had) { chan[i].outVol=VOL_SCALE_LOG_BROKEN(chan[i].vol,MIN(15,chan[i].std.vol.val),15); - if (i<9) { - rWrite(0x30+i,((15-VOL_SCALE_LOG_BROKEN(chan[i].outVol,15-chan[i].state.op[1].tl,15))&15)|(chan[i].state.opllPreset<<4)); + + if (i>=6 && properDrums) { + drumVol[i-6]=15-chan[i].outVol; + rWrite(0x36,drumVol[0]); + rWrite(0x37,drumVol[1]|(drumVol[4]<<4)); + rWrite(0x38,drumVol[3]|(drumVol[2]<<4)); + } else if (i<6 || !drums) { + if (i<9) { + rWrite(0x30+i,((15-VOL_SCALE_LOG_BROKEN(chan[i].outVol,15-chan[i].state.op[1].tl,15))&15)|(chan[i].state.opllPreset<<4)); + } } } diff --git a/src/engine/platform/pce.cpp b/src/engine/platform/pce.cpp index a920a4d0..47e5bbcd 100644 --- a/src/engine/platform/pce.cpp +++ b/src/engine/platform/pce.cpp @@ -101,7 +101,7 @@ void DivPlatformPCE::acquire(short** buf, size_t len) { pce->ResetTS(0); for (int i=0; i<6; i++) { - oscBuf[i]->data[oscBuf[i]->needle++]=CLAMP((pce->channel[i].blip_prev_samp[0]+pce->channel[i].blip_prev_samp[1])<<1,-32768,32767); + oscBuf[i]->data[oscBuf[i]->needle++]=CLAMP(pce->channel[i].blip_prev_samp[0]+pce->channel[i].blip_prev_samp[1],-32768,32767); } tempL[0]=(tempL[0]>>1)+(tempL[0]>>2); diff --git a/src/engine/platform/pcmdac.cpp b/src/engine/platform/pcmdac.cpp index 283b6e24..3a00e431 100644 --- a/src/engine/platform/pcmdac.cpp +++ b/src/engine/platform/pcmdac.cpp @@ -229,7 +229,7 @@ void DivPlatformPCMDAC::acquire(short** buf, size_t len) { } else { output=output*chan[0].vol*chan[0].envVol/16384; } - oscBuf->data[oscBuf->needle++]=output; + oscBuf->data[oscBuf->needle++]=output>>1; if (outStereo) { buf[0][h]=((output*chan[0].panL)>>(depthScale+8))<>(depthScale+8))<calcFreq(chan[i].baseFreq,chan[i].pitch,chan[i].fixedArp?chan[i].baseNoteOverride:chan[i].arpOff,chan[i].fixedArp,true,0,chan[i].pitch2,chipClock,CHIP_DIVIDER)-1; if (chan[i].freq<0) chan[i].freq=0; if (chan[i].freq>65535) chan[i].freq=65535; - if (chan[i].keyOn) { - on=true; + if (!chan[i].std.vol.had) { + if (chan[i].keyOn) { + on=true; + } } if (chan[i].keyOff) { on=false; diff --git a/src/engine/platform/pokey.cpp b/src/engine/platform/pokey.cpp index 8ee3a169..790346e1 100644 --- a/src/engine/platform/pokey.cpp +++ b/src/engine/platform/pokey.cpp @@ -35,6 +35,7 @@ const char* regCheatSheetPOKEY[]={ "AUDF4", "6", "AUDC4", "7", "AUDCTL", "8", + "SKCTL", "F", NULL }; @@ -85,10 +86,10 @@ void DivPlatformPOKEY::acquireMZ(short* buf, size_t len) { if (++oscBufDelay>=14) { oscBufDelay=0; - oscBuf[0]->data[oscBuf[0]->needle++]=pokey.outvol_0<<11; - oscBuf[1]->data[oscBuf[1]->needle++]=pokey.outvol_1<<11; - oscBuf[2]->data[oscBuf[2]->needle++]=pokey.outvol_2<<11; - oscBuf[3]->data[oscBuf[3]->needle++]=pokey.outvol_3<<11; + oscBuf[0]->data[oscBuf[0]->needle++]=pokey.outvol_0<<10; + oscBuf[1]->data[oscBuf[1]->needle++]=pokey.outvol_1<<10; + oscBuf[2]->data[oscBuf[2]->needle++]=pokey.outvol_2<<10; + oscBuf[3]->data[oscBuf[3]->needle++]=pokey.outvol_3<<10; } } } @@ -154,6 +155,11 @@ void DivPlatformPOKEY::tick(bool sysTick) { } } + if (skctlChanged) { + skctlChanged=false; + rWrite(15,skctl); + } + for (int i=0; i<4; i++) { if (chan[i].freqChanged || chan[i].keyOn || chan[i].keyOff) { chan[i].freq=parent->calcFreq(chan[i].baseFreq,parent->song.linearPitch?chan[i].pitch:0,chan[i].fixedArp?chan[i].baseNoteOverride:chan[i].arpOff,chan[i].fixedArp,true,0,parent->song.linearPitch?chan[i].pitch2:0,chipClock,CHIP_DIVIDER); @@ -320,6 +326,10 @@ int DivPlatformPOKEY::dispatch(DivCommand c) { audctl=c.value&0xff; audctlChanged=true; break; + case DIV_CMD_STD_NOISE_FREQ: + skctl=c.value?0x8b:0x03; + skctlChanged=true; + break; case DIV_CMD_NOTE_PORTA: { int destFreq=NOTE_PERIODIC(c.value2); bool return2=false; @@ -385,6 +395,7 @@ void DivPlatformPOKEY::forceIns() { chan[i].freqChanged=true; } audctlChanged=true; + skctlChanged=true; } void* DivPlatformPOKEY::getChanState(int ch) { @@ -408,7 +419,7 @@ unsigned char* DivPlatformPOKEY::getRegisterPool() { } int DivPlatformPOKEY::getRegisterPoolSize() { - return 9; + return 16; } void DivPlatformPOKEY::reset() { @@ -430,6 +441,8 @@ void DivPlatformPOKEY::reset() { audctl=0; audctlChanged=true; + skctl=3; + skctlChanged=true; } bool DivPlatformPOKEY::keyOffAffectsArp(int ch) { diff --git a/src/engine/platform/pokey.h b/src/engine/platform/pokey.h index f24ea56c..b5087517 100644 --- a/src/engine/platform/pokey.h +++ b/src/engine/platform/pokey.h @@ -48,8 +48,8 @@ class DivPlatformPOKEY: public DivDispatch { QueuedWrite(unsigned char a, unsigned char v): addr(a), val(v) {} }; std::queue writes; - unsigned char audctl; - bool audctlChanged; + unsigned char audctl, skctl; + bool audctlChanged, skctlChanged; unsigned char oscBufDelay; PokeyState pokey; AltASAP::Pokey altASAP; diff --git a/src/engine/platform/pv1000.cpp b/src/engine/platform/pv1000.cpp index 4d32fc5a..bf03df40 100644 --- a/src/engine/platform/pv1000.cpp +++ b/src/engine/platform/pv1000.cpp @@ -42,7 +42,7 @@ void DivPlatformPV1000::acquire(short** buf, size_t len) { short samp=d65010g031_sound_tick(&d65010g031,1); buf[0][h]=samp; for (int i=0; i<3; i++) { - oscBuf[i]->data[oscBuf[i]->needle++]=(d65010g031.out[i]); + oscBuf[i]->data[oscBuf[i]->needle++]=d65010g031.out[i]<<1; } } } diff --git a/src/engine/platform/qsound.cpp b/src/engine/platform/qsound.cpp index b1aeab3e..d7f908f5 100644 --- a/src/engine/platform/qsound.cpp +++ b/src/engine/platform/qsound.cpp @@ -272,7 +272,7 @@ void DivPlatformQSound::acquire(short** buf, size_t len) { buf[1][h]=chip.out[1]; for (int i=0; i<19; i++) { - int data=chip.voice_output[i]<<2; + int data=chip.voice_output[i]<<1; if (data<-32768) data=-32768; if (data>32767) data=32767; oscBuf[i]->data[oscBuf[i]->needle++]=data; diff --git a/src/engine/platform/rf5c68.cpp b/src/engine/platform/rf5c68.cpp index 7be43801..84522c74 100644 --- a/src/engine/platform/rf5c68.cpp +++ b/src/engine/platform/rf5c68.cpp @@ -74,7 +74,7 @@ void DivPlatformRF5C68::acquire(short** buf, size_t len) { rf5c68.sound_stream_update(bufPtrs,chBufPtrs,blockLen); for (int i=0; i<8; i++) { for (size_t j=0; jdata[oscBuf[i]->needle++]=bufC[i*2][j]+bufC[i*2+1][j]; + oscBuf[i]->data[oscBuf[i]->needle++]=(bufC[i*2][j]+bufC[i*2+1][j])>>1; } } pos+=blockLen; diff --git a/src/engine/platform/segapcm.cpp b/src/engine/platform/segapcm.cpp index ce24e2fb..9376bb0c 100644 --- a/src/engine/platform/segapcm.cpp +++ b/src/engine/platform/segapcm.cpp @@ -49,7 +49,7 @@ void DivPlatformSegaPCM::acquire(short** buf, size_t len) { buf[1][h]=os[1]; for (int i=0; i<16; i++) { - oscBuf[i]->data[oscBuf[i]->needle++]=pcm.lastOut[i][0]+pcm.lastOut[i][1]; + oscBuf[i]->data[oscBuf[i]->needle++]=(pcm.lastOut[i][0]+pcm.lastOut[i][1])>>1; } } } @@ -423,7 +423,7 @@ const void* DivPlatformSegaPCM::getSampleMem(int index) { } size_t DivPlatformSegaPCM::getSampleMemCapacity(int index) { - return index == 0 ? 16777216 : 0; + return index == 0 ? 2097152 : 0; } size_t DivPlatformSegaPCM::getSampleMemUsage(int index) { @@ -465,7 +465,7 @@ void DivPlatformSegaPCM::reset() { void DivPlatformSegaPCM::renderSamples(int sysID) { size_t memPos=0; - memset(sampleMem,0,16777216); + memset(sampleMem,0,2097152); memset(sampleLoaded,0,256*sizeof(bool)); memset(sampleOffSegaPCM,0,256*sizeof(unsigned int)); memset(sampleEndSegaPCM,0,256); @@ -482,7 +482,7 @@ void DivPlatformSegaPCM::renderSamples(int sysID) { } logV("- sample %d will be at %x with length %x",i,memPos,alignedSize); sampleLoaded[i]=true; - if (memPos>=16777216) break; + if (memPos>=2097152) break; sampleOffSegaPCM[i]=memPos; for (unsigned int j=0; j=sample->samples) { @@ -491,10 +491,10 @@ void DivPlatformSegaPCM::renderSamples(int sysID) { sampleMem[memPos++]=((unsigned char)sample->data8[j]+0x80); } sampleEndSegaPCM[i]=((memPos+0xff)>>8)-1; - if (memPos>=16777216) break; + if (memPos>=2097152) break; } logV(" and it ends in %d",sampleEndSegaPCM[i]); - if (memPos>=16777216) break; + if (memPos>=2097152) break; } sampleMemLen=memPos; } @@ -522,10 +522,10 @@ int DivPlatformSegaPCM::init(DivEngine* p, int channels, int sugRate, const DivC isMuted[i]=false; oscBuf[i]=new DivDispatchOscBuffer; } - sampleMem=new unsigned char[16777216]; + sampleMem=new unsigned char[2097152]; pcm.set_bank(segapcm_device::BANK_12M|segapcm_device::BANK_MASKF8); pcm.set_read([this](unsigned int addr) -> unsigned char { - return sampleMem[addr&0xffffff]; + return sampleMem[addr&0x1fffff]; }); setFlags(flags); reset(); diff --git a/src/engine/platform/sm8521.cpp b/src/engine/platform/sm8521.cpp index e1f359c0..e72616bd 100644 --- a/src/engine/platform/sm8521.cpp +++ b/src/engine/platform/sm8521.cpp @@ -58,9 +58,9 @@ void DivPlatformSM8521::acquire(short** buf, size_t len) { sm8521_sound_tick(&sm8521,8); buf[0][h]=sm8521.out<<6; for (int i=0; i<2; i++) { - oscBuf[i]->data[oscBuf[i]->needle++]=sm8521.sg[i].base.out<<6; + oscBuf[i]->data[oscBuf[i]->needle++]=sm8521.sg[i].base.out<<7; } - oscBuf[2]->data[oscBuf[2]->needle++]=sm8521.noise.base.out<<6; + oscBuf[2]->data[oscBuf[2]->needle++]=sm8521.noise.base.out<<7; } } diff --git a/src/engine/platform/snes.cpp b/src/engine/platform/snes.cpp index 0c9734c2..43401ebc 100644 --- a/src/engine/platform/snes.cpp +++ b/src/engine/platform/snes.cpp @@ -91,7 +91,7 @@ void DivPlatformSNES::acquire(short** buf, size_t len) { next=(next*254)/MAX(1,globalVolL+globalVolR); if (next<-32768) next=-32768; if (next>32767) next=32767; - oscBuf[i]->data[oscBuf[i]->needle++]=next; + oscBuf[i]->data[oscBuf[i]->needle++]=next>>1; } } } diff --git a/src/engine/platform/sound/pokey/AltASAP.cpp b/src/engine/platform/sound/pokey/AltASAP.cpp index 21bc31a2..e6675027 100644 --- a/src/engine/platform/sound/pokey/AltASAP.cpp +++ b/src/engine/platform/sound/pokey/AltASAP.cpp @@ -39,7 +39,7 @@ static constexpr int MuteInit = 2; static constexpr int MuteSerialInput = 8; //just some magick value to match the audio level of mzpokeysnd static constexpr int16_t MAGICK_VOLUME_BOOSTER = 160; -static constexpr int16_t MAGICK_OSC_VOLUME_BOOSTER = 4; +static constexpr int16_t MAGICK_OSC_VOLUME_BOOSTER = 6; struct PokeyBase { diff --git a/src/engine/platform/t6w28.cpp b/src/engine/platform/t6w28.cpp index 0d7b9223..5d21e1ad 100644 --- a/src/engine/platform/t6w28.cpp +++ b/src/engine/platform/t6w28.cpp @@ -54,7 +54,7 @@ void DivPlatformT6W28::acquire(short** buf, size_t len) { tempL=0; tempR=0; for (int i=0; i<4; i++) { - oscBuf[i]->data[oscBuf[i]->needle++]=(out[i][1].curValue+out[i][2].curValue)<<6; + oscBuf[i]->data[oscBuf[i]->needle++]=(out[i][1].curValue+out[i][2].curValue)<<7; tempL+=out[i][1].curValue<<7; tempR+=out[i][2].curValue<<7; } diff --git a/src/engine/platform/tx81z.cpp b/src/engine/platform/tx81z.cpp index 935390bc..86128340 100644 --- a/src/engine/platform/tx81z.cpp +++ b/src/engine/platform/tx81z.cpp @@ -78,7 +78,7 @@ void DivPlatformTX81Z::acquire(short** buf, size_t len) { fm_ymfm->generate(&out_ymfm); for (int i=0; i<8; i++) { - oscBuf[i]->data[oscBuf[i]->needle++]=(fme->debug_channel(i)->debug_output(0)+fme->debug_channel(i)->debug_output(1)); + oscBuf[i]->data[oscBuf[i]->needle++]=CLAMP(fme->debug_channel(i)->debug_output(0)+fme->debug_channel(i)->debug_output(1),-32768,32767); } os[0]=out_ymfm.data[0]; diff --git a/src/engine/platform/vera.cpp b/src/engine/platform/vera.cpp index 6b2dd56c..0db7660d 100644 --- a/src/engine/platform/vera.cpp +++ b/src/engine/platform/vera.cpp @@ -35,7 +35,7 @@ extern "C" { #define rWritePCMCtrl(d) {regPool[64]=(d); pcm_write_ctrl(pcm,d);} #define rWritePCMRate(d) {regPool[65]=(d); pcm_write_rate(pcm,d);} #define rWritePCMData(d) {regPool[66]=(d); pcm_write_fifo(pcm,d);} -#define rWritePCMVol(d) rWritePCMCtrl((regPool[64]&(~0x3f))|((d)&0x3f)) +#define rWritePCMVol(d) rWritePCMCtrl((regPool[64]&(~0x8f))|((d)&15)) const char* regCheatSheetVERA[]={ "CHxFreq", "00+x*4", @@ -107,9 +107,9 @@ void DivPlatformVERA::acquire(short** buf, size_t len) { pos++; for (int i=0; i<16; i++) { - oscBuf[i]->data[oscBuf[i]->needle++]=psg->channels[i].lastOut<<4; + oscBuf[i]->data[oscBuf[i]->needle++]=psg->channels[i].lastOut<<3; } - int pcmOut=whyCallItBuf[2][i]+whyCallItBuf[3][i]; + int pcmOut=(whyCallItBuf[2][i]+whyCallItBuf[3][i])>>1; if (pcmOut<-32768) pcmOut=-32768; if (pcmOut>32767) pcmOut=32767; oscBuf[16]->data[oscBuf[16]->needle++]=pcmOut; @@ -441,6 +441,15 @@ void DivPlatformVERA::poke(std::vector& wlist) { for (auto &i: wlist) poke(i.addr,i.val); } +void DivPlatformVERA::setFlags(const DivConfig& flags) { + chipClock=25000000; + CHECK_CUSTOM_CLOCK; + rate=chipClock/512; + for (int i=0; i<17; i++) { + oscBuf[i]->rate=rate; + } +} + int DivPlatformVERA::init(DivEngine* p, int channels, int sugRate, const DivConfig& flags) { for (int i=0; i<17; i++) { isMuted[i]=false; @@ -451,12 +460,7 @@ int DivPlatformVERA::init(DivEngine* p, int channels, int sugRate, const DivConf pcm=new struct VERA_PCM; dumpWrites=false; skipRegisterWrites=false; - chipClock=25000000; - CHECK_CUSTOM_CLOCK; - rate=chipClock/512; - for (int i=0; i<17; i++) { - oscBuf[i]->rate=rate; - } + setFlags(flags); reset(); return 17; } diff --git a/src/engine/platform/vera.h b/src/engine/platform/vera.h index 8781dc95..7476a316 100644 --- a/src/engine/platform/vera.h +++ b/src/engine/platform/vera.h @@ -70,6 +70,7 @@ class DivPlatformVERA: public DivDispatch { void reset(); void tick(bool sysTick=true); void muteChannel(int ch, bool mute); + void setFlags(const DivConfig& flags); void notifyInsDeletion(void* ins); float getPostAmp(); int getOutputCount(); diff --git a/src/engine/platform/vrc6.cpp b/src/engine/platform/vrc6.cpp index 2aeb3897..b52bc106 100644 --- a/src/engine/platform/vrc6.cpp +++ b/src/engine/platform/vrc6.cpp @@ -87,7 +87,7 @@ void DivPlatformVRC6::acquire(short** buf, size_t len) { if (++writeOscBuf>=32) { writeOscBuf=0; for (int i=0; i<2; i++) { - oscBuf[i]->data[oscBuf[i]->needle++]=vrc6.pulse_out(i)<<10; + oscBuf[i]->data[oscBuf[i]->needle++]=vrc6.pulse_out(i)<<11; } oscBuf[2]->data[oscBuf[2]->needle++]=vrc6.sawtooth_out()<<10; } diff --git a/src/engine/platform/x1_010.cpp b/src/engine/platform/x1_010.cpp index 44f94d99..29601ae9 100644 --- a/src/engine/platform/x1_010.cpp +++ b/src/engine/platform/x1_010.cpp @@ -222,7 +222,7 @@ void DivPlatformX1_010::acquire(short** buf, size_t len) { if (stereo) buf[1][h]=tempR; for (int i=0; i<16; i++) { - int vo=(x1_010.voice_out(i,0)+x1_010.voice_out(i,1))<<3; + int vo=(x1_010.voice_out(i,0)+x1_010.voice_out(i,1))<<2; oscBuf[i]->data[oscBuf[i]->needle++]=CLAMP(vo,-32768,32767); } } diff --git a/src/engine/platform/ym2203.cpp b/src/engine/platform/ym2203.cpp index cc2d1f3f..135ad140 100644 --- a/src/engine/platform/ym2203.cpp +++ b/src/engine/platform/ym2203.cpp @@ -231,11 +231,11 @@ void DivPlatformYM2203::acquire_combo(short** buf, size_t len) { buf[0][h]=os; for (int i=0; i<3; i++) { - oscBuf[i]->data[oscBuf[i]->needle++]=fm_nuked.ch_out[i]; + oscBuf[i]->data[oscBuf[i]->needle++]=fm_nuked.ch_out[i]<<1; } for (int i=3; i<6; i++) { - oscBuf[i]->data[oscBuf[i]->needle++]=fmout.data[i-2]; + oscBuf[i]->data[oscBuf[i]->needle++]=fmout.data[i-2]<<1; } } } @@ -282,11 +282,11 @@ void DivPlatformYM2203::acquire_ymfm(short** buf, size_t len) { for (int i=0; i<3; i++) { - oscBuf[i]->data[oscBuf[i]->needle++]=(fmChan[i]->debug_output(0)+fmChan[i]->debug_output(1)); + oscBuf[i]->data[oscBuf[i]->needle++]=(fmChan[i]->debug_output(0)+fmChan[i]->debug_output(1))<<1; } for (int i=3; i<6; i++) { - oscBuf[i]->data[oscBuf[i]->needle++]=fmout.data[i-2]; + oscBuf[i]->data[oscBuf[i]->needle++]=fmout.data[i-2]<<1; } } } diff --git a/src/engine/platform/ym2608.cpp b/src/engine/platform/ym2608.cpp index 7c10e76c..589d90d3 100644 --- a/src/engine/platform/ym2608.cpp +++ b/src/engine/platform/ym2608.cpp @@ -402,19 +402,19 @@ void DivPlatformYM2608::acquire_combo(short** buf, size_t len) { for (int i=0; idata[oscBuf[i]->needle++]=fm_nuked.ch_out[i]; + oscBuf[i]->data[oscBuf[i]->needle++]=fm_nuked.ch_out[i]<<1; } ssge->get_last_out(ssgOut); for (int i=psgChanOffs; idata[oscBuf[i]->needle++]=ssgOut.data[i-psgChanOffs]; + oscBuf[i]->data[oscBuf[i]->needle++]=ssgOut.data[i-psgChanOffs]<<1; } for (int i=adpcmAChanOffs; idata[oscBuf[i]->needle++]=adpcmAChan[i-adpcmAChanOffs]->get_last_out(0)+adpcmAChan[i-adpcmAChanOffs]->get_last_out(1); + oscBuf[i]->data[oscBuf[i]->needle++]=(adpcmAChan[i-adpcmAChanOffs]->get_last_out(0)+adpcmAChan[i-adpcmAChanOffs]->get_last_out(1))>>1; } - oscBuf[adpcmBChanOffs]->data[oscBuf[adpcmBChanOffs]->needle++]=abe->get_last_out(0)+abe->get_last_out(1); + oscBuf[adpcmBChanOffs]->data[oscBuf[adpcmBChanOffs]->needle++]=(abe->get_last_out(0)+abe->get_last_out(1))>>1; } } @@ -471,19 +471,19 @@ void DivPlatformYM2608::acquire_ymfm(short** buf, size_t len) { buf[1][h]=os[1]; for (int i=0; i<6; i++) { - oscBuf[i]->data[oscBuf[i]->needle++]=(fmChan[i]->debug_output(0)+fmChan[i]->debug_output(1)); + oscBuf[i]->data[oscBuf[i]->needle++]=(fmChan[i]->debug_output(0)+fmChan[i]->debug_output(1))<<1; } ssge->get_last_out(ssgOut); for (int i=6; i<9; i++) { - oscBuf[i]->data[oscBuf[i]->needle++]=ssgOut.data[i-6]; + oscBuf[i]->data[oscBuf[i]->needle++]=ssgOut.data[i-6]<<1; } for (int i=9; i<15; i++) { - oscBuf[i]->data[oscBuf[i]->needle++]=adpcmAChan[i-9]->get_last_out(0)+adpcmAChan[i-9]->get_last_out(1); + oscBuf[i]->data[oscBuf[i]->needle++]=(adpcmAChan[i-9]->get_last_out(0)+adpcmAChan[i-9]->get_last_out(1))>>1; } - oscBuf[15]->data[oscBuf[15]->needle++]=abe->get_last_out(0)+abe->get_last_out(1); + oscBuf[15]->data[oscBuf[15]->needle++]=(abe->get_last_out(0)+abe->get_last_out(1))>>1; } } diff --git a/src/engine/platform/ym2610.cpp b/src/engine/platform/ym2610.cpp index e9cb021d..66c2f411 100644 --- a/src/engine/platform/ym2610.cpp +++ b/src/engine/platform/ym2610.cpp @@ -333,19 +333,19 @@ void DivPlatformYM2610::acquire_combo(short** buf, size_t len) { for (int i=0; idata[oscBuf[i]->needle++]=fm_nuked.ch_out[bchOffs[i]]; + oscBuf[i]->data[oscBuf[i]->needle++]=fm_nuked.ch_out[bchOffs[i]]<<1; } ssge->get_last_out(ssgOut); for (int i=psgChanOffs; idata[oscBuf[i]->needle++]=ssgOut.data[i-psgChanOffs]; + oscBuf[i]->data[oscBuf[i]->needle++]=ssgOut.data[i-psgChanOffs]<<1; } for (int i=adpcmAChanOffs; idata[oscBuf[i]->needle++]=adpcmAChan[i-adpcmAChanOffs]->get_last_out(0)+adpcmAChan[i-adpcmAChanOffs]->get_last_out(1); + oscBuf[i]->data[oscBuf[i]->needle++]=(adpcmAChan[i-adpcmAChanOffs]->get_last_out(0)+adpcmAChan[i-adpcmAChanOffs]->get_last_out(1))>>1; } - oscBuf[adpcmBChanOffs]->data[oscBuf[adpcmBChanOffs]->needle++]=abe->get_last_out(0)+abe->get_last_out(1); + oscBuf[adpcmBChanOffs]->data[oscBuf[adpcmBChanOffs]->needle++]=(abe->get_last_out(0)+abe->get_last_out(1))>>1; } } @@ -404,19 +404,19 @@ void DivPlatformYM2610::acquire_ymfm(short** buf, size_t len) { buf[1][h]=os[1]; for (int i=0; idata[oscBuf[i]->needle++]=(fmChan[i]->debug_output(0)+fmChan[i]->debug_output(1)); + oscBuf[i]->data[oscBuf[i]->needle++]=(fmChan[i]->debug_output(0)+fmChan[i]->debug_output(1))<<1; } ssge->get_last_out(ssgOut); for (int i=psgChanOffs; idata[oscBuf[i]->needle++]=ssgOut.data[i-psgChanOffs]; + oscBuf[i]->data[oscBuf[i]->needle++]=ssgOut.data[i-psgChanOffs]<<1; } for (int i=adpcmAChanOffs; idata[oscBuf[i]->needle++]=adpcmAChan[i-adpcmAChanOffs]->get_last_out(0)+adpcmAChan[i-adpcmAChanOffs]->get_last_out(1); + oscBuf[i]->data[oscBuf[i]->needle++]=(adpcmAChan[i-adpcmAChanOffs]->get_last_out(0)+adpcmAChan[i-adpcmAChanOffs]->get_last_out(1))>>1; } - oscBuf[adpcmBChanOffs]->data[oscBuf[adpcmBChanOffs]->needle++]=abe->get_last_out(0)+abe->get_last_out(1); + oscBuf[adpcmBChanOffs]->data[oscBuf[adpcmBChanOffs]->needle++]=(abe->get_last_out(0)+abe->get_last_out(1))>>1; } } diff --git a/src/engine/platform/ym2610b.cpp b/src/engine/platform/ym2610b.cpp index 7d28a801..d38ad525 100644 --- a/src/engine/platform/ym2610b.cpp +++ b/src/engine/platform/ym2610b.cpp @@ -401,19 +401,19 @@ void DivPlatformYM2610B::acquire_combo(short** buf, size_t len) { for (int i=0; idata[oscBuf[i]->needle++]=fm_nuked.ch_out[i]; + oscBuf[i]->data[oscBuf[i]->needle++]=fm_nuked.ch_out[i]<<1; } ssge->get_last_out(ssgOut); for (int i=psgChanOffs; idata[oscBuf[i]->needle++]=ssgOut.data[i-psgChanOffs]; + oscBuf[i]->data[oscBuf[i]->needle++]=ssgOut.data[i-psgChanOffs]<<1; } for (int i=adpcmAChanOffs; idata[oscBuf[i]->needle++]=adpcmAChan[i-adpcmAChanOffs]->get_last_out(0)+adpcmAChan[i-adpcmAChanOffs]->get_last_out(1); + oscBuf[i]->data[oscBuf[i]->needle++]=(adpcmAChan[i-adpcmAChanOffs]->get_last_out(0)+adpcmAChan[i-adpcmAChanOffs]->get_last_out(1))>>1; } - oscBuf[adpcmBChanOffs]->data[oscBuf[adpcmBChanOffs]->needle++]=abe->get_last_out(0)+abe->get_last_out(1); + oscBuf[adpcmBChanOffs]->data[oscBuf[adpcmBChanOffs]->needle++]=(abe->get_last_out(0)+abe->get_last_out(1))>>1; } } @@ -471,19 +471,19 @@ void DivPlatformYM2610B::acquire_ymfm(short** buf, size_t len) { for (int i=0; idata[oscBuf[i]->needle++]=(fmChan[i]->debug_output(0)+fmChan[i]->debug_output(1)); + oscBuf[i]->data[oscBuf[i]->needle++]=(fmChan[i]->debug_output(0)+fmChan[i]->debug_output(1))<<1; } ssge->get_last_out(ssgOut); for (int i=psgChanOffs; idata[oscBuf[i]->needle++]=ssgOut.data[i-psgChanOffs]; + oscBuf[i]->data[oscBuf[i]->needle++]=ssgOut.data[i-psgChanOffs]<<1; } for (int i=adpcmAChanOffs; idata[oscBuf[i]->needle++]=adpcmAChan[i-adpcmAChanOffs]->get_last_out(0)+adpcmAChan[i-adpcmAChanOffs]->get_last_out(1); + oscBuf[i]->data[oscBuf[i]->needle++]=(adpcmAChan[i-adpcmAChanOffs]->get_last_out(0)+adpcmAChan[i-adpcmAChanOffs]->get_last_out(1))>>1; } - oscBuf[adpcmBChanOffs]->data[oscBuf[adpcmBChanOffs]->needle++]=abe->get_last_out(0)+abe->get_last_out(1); + oscBuf[adpcmBChanOffs]->data[oscBuf[adpcmBChanOffs]->needle++]=(abe->get_last_out(0)+abe->get_last_out(1))>>1; } } diff --git a/src/engine/platform/ymz280b.cpp b/src/engine/platform/ymz280b.cpp index a8838ae9..496f3568 100644 --- a/src/engine/platform/ymz280b.cpp +++ b/src/engine/platform/ymz280b.cpp @@ -76,7 +76,7 @@ void DivPlatformYMZ280B::acquire(short** buf, size_t len) { for (int j=0; j<8; j++) { dataL+=why[j*2][i]; dataR+=why[j*2+1][i]; - oscBuf[j]->data[oscBuf[j]->needle++]=(short)(((int)why[j*2][i]+why[j*2+1][i])/2); + oscBuf[j]->data[oscBuf[j]->needle++]=(short)(((int)why[j*2][i]+why[j*2+1][i])/4); } buf[0][pos]=(short)(dataL/8); buf[1][pos]=(short)(dataR/8); diff --git a/src/engine/playback.cpp b/src/engine/playback.cpp index 00b4a1d2..ce94b883 100644 --- a/src/engine/playback.cpp +++ b/src/engine/playback.cpp @@ -781,21 +781,17 @@ void DivEngine::processRow(int i, bool afterDelay) { dispatchCmd(DivCommand(DIV_CMD_HINT_VOL_SLIDE,i,chan[i].volSpeed)); break; case 0x07: // tremolo - // TODO - // this effect is really weird. i thought it would alter the tremolo depth but turns out it's completely different - // this is how it works: - // - 07xy enables tremolo - // - when enabled, a "low" boundary is calculated based on the current volume - // - then a volume slide down starts to the low boundary, and then when this is reached a volume slide up begins - // - this process repeats until 0700 or 0Axy are found - // - note that a volume value does not stop tremolo - instead it glitches this whole thing up if (chan[i].tremoloDepth==0) { chan[i].tremoloPos=0; } chan[i].tremoloDepth=effectVal&15; chan[i].tremoloRate=effectVal>>4; - // tremolo and vol slides are incompatiblw - chan[i].volSpeed=0; + if (chan[i].tremoloDepth!=0) { + chan[i].volSpeed=0; + } else { + dispatchCmd(DivCommand(DIV_CMD_VOLUME,i,chan[i].volume>>8)); + dispatchCmd(DivCommand(DIV_CMD_HINT_VOLUME,i,chan[i].volume>>8)); + } break; case 0x0a: // volume ramp // TODO: non-0x-or-x0 value should be treated as 00 @@ -1192,6 +1188,11 @@ void DivEngine::nextRow() { nextSpeed=speeds.val[curSpeed]; } + /* + if (skipping) { + ticks=1; + }*/ + // post row details for (int i=0; iord[i][curOrder],false); @@ -1318,7 +1319,7 @@ bool DivEngine::nextTick(bool noAccum, bool inhibitLowLat) { subticks=tickMult; if (stepPlay!=1) { - tempoAccum+=curSubSong->virtualTempoN; + tempoAccum+=(skipping && curSubSong->virtualTempoNvirtualTempoD)?curSubSong->virtualTempoD:curSubSong->virtualTempoN; while (tempoAccum>=curSubSong->virtualTempoD) { tempoAccum-=curSubSong->virtualTempoD; if (--ticks<=0) { @@ -1568,8 +1569,10 @@ void DivEngine::runMidiClock(int totalCycles) { if (speedSum<1.0) speedSum=1.0; if (vD<1) vD=1; double bpm=((24.0*divider)/(timeBase*hl*speedSum))*(double)curSubSong->virtualTempoN/vD; + if (bpm<1.0) bpm=1.0; + int increment=got.rate*pow(2,MASTER_CLOCK_PREC)/(bpm); - midiClockCycles+=got.rate*pow(2,MASTER_CLOCK_PREC)/(bpm); + midiClockCycles+=increment; midiClockDrift+=fmod(got.rate*pow(2,MASTER_CLOCK_PREC),(double)(bpm)); if (midiClockDrift>=(bpm)) { midiClockDrift-=(bpm); @@ -1688,6 +1691,10 @@ void DivEngine::runMidiTime(int totalCycles) { } void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsigned int size) { + if (!size) { + logW("nextBuf called with size 0!"); + return; + } lastLoopPos=-1; if (out!=NULL) { @@ -2124,7 +2131,7 @@ void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsi for (size_t i=0; iwriteC(depth); w->writeC(loopMode); w->writeC(brrEmphasis); - w->writeC(0); // reserved + w->writeC(dither); w->writeI(loop?loopStart:-1); w->writeI(loop?loopEnd:-1); @@ -131,8 +131,11 @@ DivDataErrors DivSample::readSampleData(SafeReader& reader, short version) { } else { reader.readC(); } - // reserved - reader.readC(); + if (version>=159) { + dither=reader.readC()&1; + } else { + reader.readC(); + } loopStart=reader.readI(); loopEnd=reader.readI(); @@ -389,7 +392,7 @@ bool DivSample::save(const char* path) { if (length16<1) return false; si.channels=1; - si.samplerate=rate; + si.samplerate=centerRate; switch (depth) { case DIV_SAMPLE_DEPTH_8BIT: // 8-bit si.format=SF_FORMAT_PCM_U8|SF_FORMAT_WAV; @@ -409,7 +412,8 @@ bool DivSample::save(const char* path) { SF_INSTRUMENT inst; memset(&inst, 0, sizeof(inst)); inst.gain = 1; - short pitch = (0x3c * 100) + 50 - (log2((double)centerRate/rate) * 12.0 * 100.0); + // TODO: fix + short pitch = (0x3c * 100) + 50 - (log2((double)centerRate/8363.0) * 12.0 * 100.0); inst.basenote = pitch / 100; inst.detune = 50 - (pitch % 100); inst.velocity_hi = 0x7f; @@ -1196,8 +1200,23 @@ void DivSample::render(unsigned int formatMask) { } if (NOT_IN_FORMAT(DIV_SAMPLE_DEPTH_8BIT)) { // 8-bit PCM if (!initInternal(DIV_SAMPLE_DEPTH_8BIT,samples)) return; - for (unsigned int i=0; i>8; + if (dither) { + unsigned short lfsr=0x6438; + unsigned short lfsr1=0x1283; + signed char errorLast=0; + signed char errorCur=0; + for (unsigned int i=0; i>8; + errorLast=errorCur; + errorCur=(val<<8)-data16[i]; + data8[i]=CLAMP(val-((((errorLast+errorCur)>>1)+(lfsr&0xff))>>8),-128,127); + lfsr=(lfsr<<1)|(((lfsr>>1)^(lfsr>>2)^(lfsr>>4)^(lfsr>>15))&1); + lfsr1=(lfsr1<<1)|(((lfsr1>>1)^(lfsr1>>2)^(lfsr1>>4)^(lfsr1>>15))&1); + } + } else { + for (unsigned int i=0; i>8; + } } } if (NOT_IN_FORMAT(DIV_SAMPLE_DEPTH_BRR)) { // BRR @@ -1277,9 +1296,9 @@ DivSampleHistory* DivSample::prepareUndo(bool data, bool doNotPush) { duplicate=new unsigned char[getCurBufLen()]; memcpy(duplicate,getCurBuf(),getCurBufLen()); } - h=new DivSampleHistory(duplicate,getCurBufLen(),samples,depth,rate,centerRate,loopStart,loopEnd,loop,brrEmphasis,loopMode); + h=new DivSampleHistory(duplicate,getCurBufLen(),samples,depth,rate,centerRate,loopStart,loopEnd,loop,brrEmphasis,dither,loopMode); } else { - h=new DivSampleHistory(depth,rate,centerRate,loopStart,loopEnd,loop,brrEmphasis,loopMode); + h=new DivSampleHistory(depth,rate,centerRate,loopStart,loopEnd,loop,brrEmphasis,dither,loopMode); } if (!doNotPush) { while (!redoHist.empty()) { @@ -1312,6 +1331,8 @@ DivSampleHistory* DivSample::prepareUndo(bool data, bool doNotPush) { loopStart=h->loopStart; \ loopEnd=h->loopEnd; \ loop=h->loop; \ + brrEmphasis=h->brrEmphasis; \ + dither=h->dither; \ loopMode=h->loopMode; diff --git a/src/engine/sample.h b/src/engine/sample.h index c2f08ced..ce1bf1fa 100644 --- a/src/engine/sample.h +++ b/src/engine/sample.h @@ -61,10 +61,10 @@ struct DivSampleHistory { unsigned int length, samples; DivSampleDepth depth; int rate, centerRate, loopStart, loopEnd; - bool loop, brrEmphasis; + bool loop, brrEmphasis, dither; DivSampleLoopMode loopMode; bool hasSample; - DivSampleHistory(void* d, unsigned int l, unsigned int s, DivSampleDepth de, int r, int cr, int ls, int le, bool lp, bool be, DivSampleLoopMode lm): + DivSampleHistory(void* d, unsigned int l, unsigned int s, DivSampleDepth de, int r, int cr, int ls, int le, bool lp, bool be, bool di, DivSampleLoopMode lm): data((unsigned char*)d), length(l), samples(s), @@ -75,9 +75,10 @@ struct DivSampleHistory { loopEnd(le), loop(lp), brrEmphasis(be), + dither(di), loopMode(lm), hasSample(true) {} - DivSampleHistory(DivSampleDepth de, int r, int cr, int ls, int le, bool lp, bool be, DivSampleLoopMode lm): + DivSampleHistory(DivSampleDepth de, int r, int cr, int ls, int le, bool lp, bool be, bool di, DivSampleLoopMode lm): data(NULL), length(0), samples(0), @@ -88,6 +89,7 @@ struct DivSampleHistory { loopEnd(le), loop(lp), brrEmphasis(be), + dither(di), loopMode(lm), hasSample(false) {} ~DivSampleHistory(); @@ -108,7 +110,7 @@ struct DivSample { // - 10: VOX ADPCM // - 16: 16-bit PCM DivSampleDepth depth; - bool loop, brrEmphasis; + bool loop, brrEmphasis, dither; // valid values are: // - 0: Forward loop // - 1: Backward loop @@ -323,6 +325,7 @@ struct DivSample { depth(DIV_SAMPLE_DEPTH_16BIT), loop(false), brrEmphasis(true), + dither(false), loopMode(DIV_SAMPLE_LOOP_FORWARD), data8(NULL), data16(NULL), diff --git a/src/engine/song.h b/src/engine/song.h index fd2d1e07..0a6149f8 100644 --- a/src/engine/song.h +++ b/src/engine/song.h @@ -153,8 +153,6 @@ struct DivSubSong { unsigned char timeBase, arpLen; DivGroovePattern speeds; short virtualTempoN, virtualTempoD; - bool pal; - bool customTempo; float hz; int patLen, ordersLen; @@ -177,8 +175,6 @@ struct DivSubSong { arpLen(1), virtualTempoN(150), virtualTempoD(150), - pal(true), - customTempo(false), hz(60.0), patLen(64), ordersLen(1) { diff --git a/src/engine/sysDef.cpp b/src/engine/sysDef.cpp index c590ba10..f4d76ceb 100644 --- a/src/engine/sysDef.cpp +++ b/src/engine/sysDef.cpp @@ -1169,6 +1169,7 @@ void DivEngine::registerSystems() { { {0x10, {DIV_CMD_WAVE, "10xx: Set waveform (0 to 7)"}}, {0x11, {DIV_CMD_STD_NOISE_MODE, "11xx: Set AUDCTL"}}, + {0x12, {DIV_CMD_STD_NOISE_FREQ, "12xx: Toggle two-tone mode"}}, } ); diff --git a/src/engine/vgmOps.cpp b/src/engine/vgmOps.cpp index eb10521a..97c26c56 100644 --- a/src/engine/vgmOps.cpp +++ b/src/engine/vgmOps.cpp @@ -24,7 +24,7 @@ constexpr int MASTER_CLOCK_PREC=(sizeof(void*)==8)?8:0; -void DivEngine::performVGMWrite(SafeWriter* w, DivSystem sys, DivRegWrite& write, int streamOff, double* loopTimer, double* loopFreq, int* loopSample, bool* sampleDir, bool isSecond, int* pendingFreq, int* playingSample, bool directStream) { +void DivEngine::performVGMWrite(SafeWriter* w, DivSystem sys, DivRegWrite& write, int streamOff, double* loopTimer, double* loopFreq, int* loopSample, bool* sampleDir, bool isSecond, int* pendingFreq, int* playingSample, size_t bankOffset, bool directStream) { unsigned char baseAddr1=isSecond?0xa0:0x50; unsigned char baseAddr2=isSecond?0x80:0; unsigned short baseAddr2S=isSecond?0x8000:0; @@ -577,6 +577,28 @@ void DivEngine::performVGMWrite(SafeWriter* w, DivSystem sys, DivRegWrite& write break; } } + if (write.addr==0xffff0004) { // switch sample bank + switch (sys) { + case DIV_SYSTEM_NES: { + unsigned int bankAddr=bankOffset+(write.val<<14); + w->writeC(0x68); + w->writeC(0x6c); + w->writeC(0x07|(isSecond?0x80:0x00)); + w->writeC(bankAddr&0xff); + w->writeC((bankAddr>>8)&0xff); + w->writeC((bankAddr>>16)&0xff); + w->writeC(0x00); + w->writeC(0xc0); + w->writeC(0x00); + w->writeC(0x00); + w->writeC(0x40); + w->writeC(0x00); + break; + } + default: + break; + } + } if (write.addr>=0xffff0000) { // Furnace special command if (!directStream) { unsigned char streamID=streamOff+((write.addr&0xff00)>>8); @@ -600,11 +622,14 @@ void DivEngine::performVGMWrite(SafeWriter* w, DivSystem sys, DivRegWrite& write } } break; - case 1: // set sample freq + case 1: { // set sample freq + int realFreq=write.val; + if (realFreq<0) realFreq=0; + if (realFreq>44100) realFreq=44100; w->writeC(0x92); w->writeC(streamID); - w->writeI(write.val); - loopFreq[streamID]=write.val; + w->writeI(realFreq); + loopFreq[streamID]=realFreq; if (pendingFreq[streamID]!=-1) { DivSample* sample=song.sample[pendingFreq[streamID]]; w->writeC(0x95); @@ -619,6 +644,7 @@ void DivEngine::performVGMWrite(SafeWriter* w, DivSystem sys, DivRegWrite& write pendingFreq[streamID]=-1; } break; + } case 2: // stop sample w->writeC(0x94); w->writeC(streamID); @@ -1054,6 +1080,7 @@ SafeWriter* DivEngine::saveVGM(bool* sysToExport, bool loop, int version, bool p bool willExport[DIV_MAX_CHIPS]; bool isSecond[DIV_MAX_CHIPS]; int streamIDs[DIV_MAX_CHIPS]; + size_t bankOffset[DIV_MAX_CHIPS]; double loopTimer[DIV_MAX_CHANS]; double loopFreq[DIV_MAX_CHANS]; int loopSample[DIV_MAX_CHANS]; @@ -1071,6 +1098,8 @@ SafeWriter* DivEngine::saveVGM(bool* sysToExport, bool loop, int version, bool p bool mayWriteRate=(fmod(curSubSong->hz,1.0)<0.00001 || fmod(curSubSong->hz,1.0)>0.99999); int countDown=MAX(0,trailingTicks)+1; + memset(bankOffset,0,DIV_MAX_CHIPS*sizeof(size_t)); + for (int i=0; ilength8; j++) { w->writeC(((unsigned char)sample->data8[j]+0x80)>>1); } + bankOffsetNESCurrent+=sample->length8; } if (writePCESamples && !directStream) for (int i=0; iwriteI(0); w->write(writeGA20[i]->getSampleMem(),writeGA20[i]->getSampleMemUsage()); } + if (writeNES[i]!=NULL && writeNES[i]->getSampleMemUsage()>0) { + size_t howMuchWillBeWritten=writeNES[i]->getSampleMemUsage(); + w->writeC(0x67); + w->writeC(0x66); + w->writeC(7); + w->writeI(howMuchWillBeWritten); + w->write(writeNES[i]->getSampleMem(),howMuchWillBeWritten); + bankOffsetNES[i]=bankOffsetNESCurrent; + bankOffset[writeNESIndex[i]]=bankOffsetNES[i]; + bankOffsetNESCurrent+=howMuchWillBeWritten; + // force the first bank + w->writeC(0x68); + w->writeC(0x6c); + w->writeC(0x07|(i?0x80:0x00)); + w->writeC(bankOffsetNES[i]&0xff); + w->writeC((bankOffsetNES[i]>>8)&0xff); + w->writeC((bankOffsetNES[i]>>16)&0xff); + w->writeC(0x00); + w->writeC(0xc0); + w->writeC(0x00); + w->writeC(0x00); + w->writeC(0x40); + w->writeC(0x00); + } } // TODO @@ -2177,7 +2241,7 @@ SafeWriter* DivEngine::saveVGM(bool* sysToExport, bool loop, int version, bool p for (int i=0; i& writes=disCont[i].dispatch->getRegisterWrites(); for (DivRegWrite& j: writes) { - performVGMWrite(w,song.system[i],j,streamIDs[i],loopTimer,loopFreq,loopSample,sampleDir,isSecond[i],pendingFreq,playingSample,directStream); + performVGMWrite(w,song.system[i],j,streamIDs[i],loopTimer,loopFreq,loopSample,sampleDir,isSecond[i],pendingFreq,playingSample,bankOffset[i],directStream); writeCount++; } writes.clear(); @@ -2217,7 +2281,9 @@ SafeWriter* DivEngine::saveVGM(bool* sysToExport, bool loop, int version, bool p lastOne=i.second.time; } // write write - performVGMWrite(w,song.system[i.first],i.second.write,streamIDs[i.first],loopTimer,loopFreq,loopSample,sampleDir,isSecond[i.first],pendingFreq,playingSample,directStream); + performVGMWrite(w,song.system[i.first],i.second.write,streamIDs[i.first],loopTimer,loopFreq,loopSample,sampleDir,isSecond[i.first],pendingFreq,playingSample,bankOffset[i.first],directStream); + // handle global Furnace commands + writeCount++; } sortedWrites.clear(); diff --git a/src/engine/zsm.cpp b/src/engine/zsm.cpp index 5fdcd623..b65bbcbb 100644 --- a/src/engine/zsm.cpp +++ b/src/engine/zsm.cpp @@ -23,7 +23,7 @@ #include "song.h" DivZSM::DivZSM() { - w = NULL; + w=NULL; init(); } @@ -31,8 +31,8 @@ DivZSM::~DivZSM() { } void DivZSM::init(unsigned int rate) { - if (w != NULL) delete w; - w = new SafeWriter; + if (w!=NULL) delete w; + w=new SafeWriter; w->init(); // write default ZSM data header w->write("zm",2); // magic header @@ -50,7 +50,7 @@ void DivZSM::init(unsigned int rate) { w->writeS((unsigned short)rate); // 2 reserved bytes (set to zero) w->writeS(0x00); - tickRate = rate; + tickRate=rate; loopOffset=-1; numWrites=0; memset(&ymState,-1,sizeof(ymState)); @@ -63,44 +63,43 @@ int DivZSM::getoffset() { } void DivZSM::writeYM(unsigned char a, unsigned char v) { - int lastMask = ymMask; + int lastMask=ymMask; if (a==0x19 && v>=0x80) a=0x1a; // AMD/PSD use same reg addr. store PMD as 0x1a - if (a==0x08 && (v&0xf8)) ymMask |= (1 << (v & 0x07)); // mark chan as in-use if keyDN - if (a!=0x08) ymState[ym_NEW][a] = v; // cache the newly-written value + if (a==0x08 && (v&0xf8)) ymMask|=(1<<(v&0x07)); // mark chan as in-use if keyDN + if (a!=0x08) ymState[ym_NEW][a]=v; // cache the newly-written value bool writeit=false; // used to suppress spurious writes to unused channels - if (a < 0x20) { - if (a == 0x08) { + if (a<0x20) { + if (a==0x08) { // write keyUPDN messages if channel is active. - writeit = (ymMask & (1 << (v & 0x07))) > 0; - } - else { + writeit=(ymMask&(1<<(v&0x07)))>0; + } else { // do not suppress global registers - writeit = true; + writeit=true; } } else { - writeit = (ymMask & (1 << (a & 0x07))) > 0; // a&0x07 = chan ID for regs >=0x20 + writeit=(ymMask&(1<<(a&0x07)))>0; // a&0x07 = chan ID for regs >=0x20 } - if (lastMask != ymMask) { + if (lastMask!=ymMask) { // if the ymMask just changed, then the channel has become active. - // This can only happen on a KeyDN event, so voice = v & 0x07 + // This can only happen on a KeyDN event, so voice=v&0x07 // insert a keyUP just to be safe. ymwrites.push_back(DivRegWrite(0x08,v&0x07)); numWrites++; // flush the ym_NEW cached states for this channel into the ZSM.... - for ( int i=0x20 + (v&0x07); i <= 0xff ; i+=8) { - if (ymState[ym_NEW][i] != ymState[ym_PREV][i]) { + for (int i=0x20+(v&0x07); i<=0xff; i+=8) { + if (ymState[ym_NEW][i]!=ymState[ym_PREV][i]) { ymwrites.push_back(DivRegWrite(i,ymState[ym_NEW][i])); numWrites++; // ...and update the shadow - ymState[ym_PREV][i] = ymState[ym_NEW][i]; + ymState[ym_PREV][i]=ymState[ym_NEW][i]; } } } // Handle the current write if channel is active - if (writeit && ((ymState[ym_NEW][a] != ymState[ym_PREV][a])||a==0x08) ) { + if (writeit && ((ymState[ym_NEW][a]!=ymState[ym_PREV][a]) || a==0x08)) { // update YM shadow if not the KeyUPDN register. - if (a!=0x008) ymState[ym_PREV][a] = ymState[ym_NEW][a]; - // if reg = PMD, then change back to real register 0x19 + if (a!=8) ymState[ym_PREV][a]=ymState[ym_NEW][a]; + // if reg=PMD, then change back to real register 0x19 if (a==0x1a) a=0x19; ymwrites.push_back(DivRegWrite(a,v)); numWrites++; @@ -109,24 +108,26 @@ void DivZSM::writeYM(unsigned char a, unsigned char v) { void DivZSM::writePSG(unsigned char a, unsigned char v) { // TODO: suppress writes to PSG voice that is not audible (volume=0) - if (a >= 64) { + if (a>=64) { logD ("ZSM: ignoring VERA PSG write a=%02x v=%02x",a,v); return; } - if(psgState[psg_PREV][a] == v) { - if (psgState[psg_NEW][a] != v) + if (psgState[psg_PREV][a]==v) { + if (psgState[psg_NEW][a]!=v) { // NEW value is being reset to the same as PREV value // so it is no longer a new write. numWrites--; + } } else { - if (psgState[psg_PREV][a] == psgState[psg_NEW][a]) + if (psgState[psg_PREV][a]==psgState[psg_NEW][a]) { // if this write changes the NEW cached value to something other // than the PREV value, then this is a new write. numWrites++; + } } - psgState[psg_NEW][a] = v; - // mark channel as used in the psgMask if volume is set > 0. - if ((a % 4 == 2) && (v & 0x3f)) psgMask |= (1 << (a>>2)); + psgState[psg_NEW][a]=v; + // mark channel as used in the psgMask if volume is set>0. + if ((a%4==2) && (v&0x3f)) psgMask|=(1<<(a>>2)); } void DivZSM::writePCM(unsigned char a, unsigned char v) { @@ -135,7 +136,7 @@ void DivZSM::writePCM(unsigned char a, unsigned char v) { void DivZSM::tick(int numticks) { flushWrites(); - ticks += numticks; + ticks+=numticks; } void DivZSM::setLoopPoint() { @@ -154,12 +155,14 @@ void DivZSM::setLoopPoint() { memset(&ymState[ym_PREV],-1,sizeof(ymState[ym_PREV])); // ... and cache (except for unused channels) memset(&ymState[ym_NEW],-1,0x20); - for (int chan=0; chan<8 ; chan++) { + for (int chan=0; chan<8; chan++) { // do not clear state for as-yet-unused channels - if (!(ymMask & (1<writeC(ZSM_EOF); // update channel use masks. w->seek(0x09,SEEK_SET); - w->writeC((unsigned char)(ymMask & 0xff)); - w->writeS((short)(psgMask & 0xffff)); + w->writeC((unsigned char)(ymMask&0xff)); + w->writeS((short)(psgMask&0xffff)); // todo: put PCM offset/data writes here once defined in ZSM standard. return w; } @@ -179,16 +182,16 @@ void DivZSM::flushWrites() { logD("ZSM: flushWrites.... numwrites=%d ticks=%d ymwrites=%d",numWrites,ticks,ymwrites.size()); if (numWrites==0) return; flushTicks(); // only flush ticks if there are writes pending. - for (unsigned char i=0;i<64;i++) { - if (psgState[psg_NEW][i] == psgState[psg_PREV][i]) continue; + for (unsigned char i=0; i<64; i++) { + if (psgState[psg_NEW][i]==psgState[psg_PREV][i]) continue; psgState[psg_PREV][i]=psgState[psg_NEW][i]; w->writeC(i); w->writeC(psgState[psg_NEW][i]); } - int n=0; // n = completed YM writes. used to determine when to write the CMD byte... + int n=0; // n=completed YM writes. used to determine when to write the CMD byte... for (DivRegWrite& write: ymwrites) { - if (n%ZSM_YM_MAX_WRITES == 0) { - if(ymwrites.size()-n > ZSM_YM_MAX_WRITES) { + if (n%ZSM_YM_MAX_WRITES==0) { + if (ymwrites.size()-n>ZSM_YM_MAX_WRITES) { w->writeC((unsigned char)(ZSM_YM_CMD+ZSM_YM_MAX_WRITES)); logD("ZSM: YM-write: %d (%02x) [max]",ZSM_YM_MAX_WRITES,ZSM_YM_MAX_WRITES+ZSM_YM_CMD); } else { @@ -205,10 +208,10 @@ void DivZSM::flushWrites() { } void DivZSM::flushTicks() { - while (ticks > ZSM_DELAY_MAX) { + while (ticks>ZSM_DELAY_MAX) { logD("ZSM: write delay %d (max)",ZSM_DELAY_MAX); w->writeC((unsigned char)(ZSM_DELAY_CMD+ZSM_DELAY_MAX)); - ticks -= ZSM_DELAY_MAX; + ticks-=ZSM_DELAY_MAX; } if (ticks>0) { logD("ZSM: write delay %d",ticks); diff --git a/src/engine/zsmOps.cpp b/src/engine/zsmOps.cpp index 0207a93d..deddd4ec 100644 --- a/src/engine/zsmOps.cpp +++ b/src/engine/zsmOps.cpp @@ -27,36 +27,42 @@ constexpr int MASTER_CLOCK_PREC=(sizeof(void*)==8)?8:0; constexpr int MASTER_CLOCK_MASK=(sizeof(void*)==8)?0xff:0; SafeWriter* DivEngine::saveZSM(unsigned int zsmrate, bool loop) { + int VERA=-1; + int YM=-1; + int IGNORED=0; - int VERA = -1; - int YM = -1; - int IGNORED = 0; - - //loop = false; // find indexes for YM and VERA. Ignore other systems. for (int i=0; i= 0) { IGNORED++;break; } - VERA = i; + if (VERA>=0) { + IGNORED++; + break; + } + VERA=i; logD("VERA detected as chip id %d",i); break; case DIV_SYSTEM_YM2151: - if (YM >= 0) { IGNORED++;break; } - YM = i; + if (YM>=0) { + IGNORED++; + break; + } + YM=i; logD("YM detected as chip id %d",i); break; default: IGNORED++; logD("Ignoring chip %d systemID %d",i,song.system[i]); + break; } } - if (VERA < 0 && YM < 0) { - logE("No supported systems for ZSM"); - return NULL; + if (VERA<0 && YM<0) { + logE("No supported systems for ZSM"); + return NULL; } - if (IGNORED > 0) + if (IGNORED>0) { logW("ZSM export ignoring %d unsupported system%c",IGNORED,IGNORED>1?'s':' '); + } stop(); repeatPattern=false; @@ -64,7 +70,7 @@ SafeWriter* DivEngine::saveZSM(unsigned int zsmrate, bool loop) { BUSY_BEGIN_SOFT; double origRate=got.rate; - got.rate=zsmrate & 0xffff; + got.rate=zsmrate&0xffff; // determine loop point int loopOrder=0; @@ -89,15 +95,14 @@ SafeWriter* DivEngine::saveZSM(unsigned int zsmrate, bool loop) { //size_t tickCount=0; bool done=false; int loopPos=-1; - int writeCount=0; int fracWait=0; // accumulates fractional ticks - if (VERA >= 0) disCont[VERA].dispatch->toggleRegisterDump(true); - if (YM >= 0) { + if (VERA>=0) disCont[VERA].dispatch->toggleRegisterDump(true); + if (YM>=0) { disCont[YM].dispatch->toggleRegisterDump(true); // emit LFO initialization commands - zsm.writeYM(0x18,0); // freq = 0 - zsm.writeYM(0x19,0x7F); // AMD = 7F - zsm.writeYM(0x19,0xFF); // PMD = 7F + zsm.writeYM(0x18,0); // freq=0 + zsm.writeYM(0x19,0x7F); // AMD =7F + zsm.writeYM(0x19,0xFF); // PMD =7F // TODO: incorporate the Furnace meta-command for init data and filter // out writes to otherwise-unused channels. } @@ -126,35 +131,35 @@ SafeWriter* DivEngine::saveZSM(unsigned int zsmrate, bool loop) { int i=0; // dump YM writes first if (j==0) { - if (YM < 0) + if (YM<0) { continue; - else + } else { i=YM; + } } // dump VERA writes second if (j==1) { - if (VERA < 0) + if (VERA<0) { continue; - else { + } else { i=VERA; } } std::vector& writes=disCont[i].dispatch->getRegisterWrites(); - if (writes.size() > 0) - logD("zsmOps: Writing %d messages to chip %d",writes.size(), i); + if (writes.size()>0) + logD("zsmOps: Writing %d messages to chip %d",writes.size(),i); for (DivRegWrite& write: writes) { - if (i==YM) zsm.writeYM(write.addr&0xff, write.val); - if (i==VERA) zsm.writePSG(write.addr&0xff, write.val); - writeCount++; + if (i==YM) zsm.writeYM(write.addr&0xff,write.val); + if (i==VERA) zsm.writePSG(write.addr&0xff,write.val); } writes.clear(); } // write wait int totalWait=cycles>>MASTER_CLOCK_PREC; - fracWait += cycles & MASTER_CLOCK_MASK; - totalWait += fracWait>>MASTER_CLOCK_PREC; - fracWait &= MASTER_CLOCK_MASK; + fracWait+=cycles&MASTER_CLOCK_MASK; + totalWait+=fracWait>>MASTER_CLOCK_PREC; + fracWait&=MASTER_CLOCK_MASK; if (totalWait>0) { zsm.tick(totalWait); //tickCount+=totalWait; @@ -163,9 +168,9 @@ SafeWriter* DivEngine::saveZSM(unsigned int zsmrate, bool loop) { // end of song // done - close out. - got.rate = origRate; - if (VERA >= 0) disCont[VERA].dispatch->toggleRegisterDump(false); - if (YM >= 0) disCont[YM].dispatch->toggleRegisterDump(false); + got.rate=origRate; + if (VERA>=0) disCont[VERA].dispatch->toggleRegisterDump(false); + if (YM>=0) disCont[YM].dispatch->toggleRegisterDump(false); remainingLoops=-1; playing=false; diff --git a/src/gui/about.cpp b/src/gui/about.cpp index fa020b98..8131d3c3 100644 --- a/src/gui/about.cpp +++ b/src/gui/about.cpp @@ -67,6 +67,7 @@ const char* aboutLine[]={ "AmigaX", "AURORA*FIELDS", "battybeats", + "Bernie", "BlueElectric05", "breakthetargets", "brickblock369", @@ -85,6 +86,7 @@ const char* aboutLine[]={ "Fragmare", "freq-mod", "gtr3qq", + "Hortus", "iyatemu", "JayBOB18", "Jimmy-DS", @@ -102,6 +104,7 @@ const char* aboutLine[]={ "MelonadeM", "Miker", "nicco1690", + "niffuM", "", "NyaongI", "potatoTeto", @@ -122,6 +125,7 @@ const char* aboutLine[]={ "Ultraprogramer", "UserSniper", "Weeppiko", + "Xan", "Yuzu4K", "Zaxolotl", "ZoomTen (Zumi)", diff --git a/src/gui/chanOsc.cpp b/src/gui/chanOsc.cpp index 7bcece95..e6306db2 100644 --- a/src/gui/chanOsc.cpp +++ b/src/gui/chanOsc.cpp @@ -22,6 +22,7 @@ #include "../ta-log.h" #include "imgui.h" #include "imgui_internal.h" +#include "misc/cpp/imgui_stdlib.h" #define FURNACE_FFT_SIZE 4096 #define FURNACE_FFT_RATE 80.0 @@ -93,7 +94,7 @@ void FurnaceGUI::calcChanOsc() { unsigned short needlePos=buf->needle; needlePos-=displaySize; for (unsigned short i=0; i<512; i++) { - float y=(float)buf->data[(unsigned short)(needlePos+(i*displaySize/512))]/65536.0f; + float y=(float)buf->data[(unsigned short)(needlePos+(i*displaySize/512))]/32768.0f; if (minLevel>y) minLevel=y; if (maxLevelcreateTexture(true,chanOscGrad.width,chanOscGrad.height); if (chanOscGradTex==NULL) { - logE("error while creating gradient texture! %s",SDL_GetError()); + logE("error while creating gradient texture!"); } else { updateChanOscGradTex=true; } @@ -170,16 +171,16 @@ void FurnaceGUI::drawChanOsc() { if (chanOscGradTex!=NULL) { if (updateChanOscGradTex) { chanOscGrad.render(); - if (SDL_UpdateTexture(chanOscGradTex,NULL,chanOscGrad.grad.get(),chanOscGrad.width*4)==0) { + if (rend->updateTexture(chanOscGradTex,chanOscGrad.grad.get(),chanOscGrad.width*4)) { updateChanOscGradTex=false; } else { - logE("error while updating gradient texture! %s",SDL_GetError()); + logE("error while updating gradient texture!"); } } ImVec2 gradLeft=ImGui::GetCursorPos(); ImVec2 gradSize=ImVec2(400.0f*dpiScale,400.0f*dpiScale); - ImGui::Image(chanOscGradTex,gradSize); + ImGui::Image(rend->getTextureID(chanOscGradTex),gradSize); ImVec2 gradLeftAbs=ImGui::GetItemRectMin(); if (ImGui::IsItemClicked(ImGuiMouseButton_Right)) { if (chanOscGrad.points.size()<32) { @@ -284,151 +285,266 @@ void FurnaceGUI::drawChanOsc() { ImGui::ColorPicker4("Color",(float*)&chanOscColor); } + ImGui::Text("Text format:"); + ImGui::SameLine(); + ImGui::InputText("##TextFormat",&chanOscTextFormat); + if (ImGui::IsItemHovered()) { + if (ImGui::BeginTooltip()) { + ImGui::TextUnformatted( + "format guide:\n" + "- %c: channel name\n" + "- %C: channel short name\n" + "- %d: channel number (starting from 0)\n" + "- %D: channel number (starting from 1)\n" + "- %i: instrument name\n" + "- %I: instrument number (decimal)\n" + "- %x: instrument number (hex)\n" + "- %s: chip name\n" + "- %S: chip ID\n" + "- %v: volume (decimal)\n" + "- %V: volume (percentage)\n" + "- %b: volume (hex)\n" + "- %%: percent sign" + ); + ImGui::EndTooltip(); + } + } + + ImGui::ColorEdit4("Text color",(float*)&chanOscTextColor); + if (ImGui::Button("OK")) { chanOscOptions=false; } - } + } else { + ImGui::PushStyleVar(ImGuiStyleVar_CellPadding,ImVec2(0.0f,0.0f)); + float availY=ImGui::GetContentRegionAvail().y; + if (ImGui::BeginTable("ChanOsc",chanOscCols,ImGuiTableFlags_Borders)) { + std::vector oscBufs; + std::vector oscFFTs; + std::vector oscChans; + int chans=e->getTotalChannelCount(); + ImGuiWindow* window=ImGui::GetCurrentWindow(); + ImVec2 waveform[512]; - ImGui::PushStyleVar(ImGuiStyleVar_CellPadding,ImVec2(0.0f,0.0f)); - float availY=ImGui::GetContentRegionAvail().y; - if (ImGui::BeginTable("ChanOsc",chanOscCols,ImGuiTableFlags_Borders)) { - std::vector oscBufs; - std::vector oscFFTs; - std::vector oscChans; - int chans=e->getTotalChannelCount(); - ImGuiWindow* window=ImGui::GetCurrentWindow(); - ImVec2 waveform[512]; + ImGuiStyle& style=ImGui::GetStyle(); - ImGuiStyle& style=ImGui::GetStyle(); - - for (int i=0; igetOscBuffer(i); - if (buf!=NULL && e->curSubSong->chanShow[i]) { - oscBufs.push_back(buf); - oscFFTs.push_back(&chanOscChan[i]); - oscChans.push_back(i); + for (int i=0; igetOscBuffer(i); + if (buf!=NULL && e->curSubSong->chanShow[i]) { + oscBufs.push_back(buf); + oscFFTs.push_back(&chanOscChan[i]); + oscChans.push_back(i); + } } - } - int rows=(oscBufs.size()+(chanOscCols-1))/chanOscCols; + int rows=(oscBufs.size()+(chanOscCols-1))/chanOscCols; - for (size_t i=0; ireadNeedle=buf->needle; - } + if (centerSettingReset) { + buf->readNeedle=buf->needle; + } - // check FFT status existence - if (fft->plan==NULL) { - logD("creating FFT plan for channel %d",ch); - fft->inBuf=(double*)fftw_malloc(FURNACE_FFT_SIZE*sizeof(double)); - fft->outBuf=(fftw_complex*)fftw_malloc(FURNACE_FFT_SIZE*sizeof(fftw_complex)); - fft->plan=fftw_plan_dft_r2c_1d(FURNACE_FFT_SIZE,fft->inBuf,fft->outBuf,FFTW_ESTIMATE); - } + // check FFT status existence + if (fft->plan==NULL) { + logD("creating FFT plan for channel %d",ch); + fft->inBuf=(double*)fftw_malloc(FURNACE_FFT_SIZE*sizeof(double)); + fft->outBuf=(fftw_complex*)fftw_malloc(FURNACE_FFT_SIZE*sizeof(fftw_complex)); + fft->plan=fftw_plan_dft_r2c_1d(FURNACE_FFT_SIZE,fft->inBuf,fft->outBuf,FFTW_ESTIMATE); + } - int displaySize=(float)(buf->rate)*(chanOscWindowSize/1000.0f); + int displaySize=(float)(buf->rate)*(chanOscWindowSize/1000.0f); - ImVec2 minArea=window->DC.CursorPos; - ImVec2 maxArea=ImVec2( - minArea.x+size.x, - minArea.y+size.y - ); - ImRect rect=ImRect(minArea,maxArea); - ImRect inRect=rect; - inRect.Min.x+=dpiScale; - inRect.Min.y+=dpiScale; - inRect.Max.x-=dpiScale; - inRect.Max.y-=dpiScale; - ImGui::ItemSize(size,style.FramePadding.y); - if (ImGui::ItemAdd(rect,ImGui::GetID("chOscDisplay"))) { - if (!e->isRunning()) { - for (unsigned short i=0; i<512; i++) { - float x=(float)i/512.0f; - waveform[i]=ImLerp(inRect.Min,inRect.Max,ImVec2(x,0.5f)); - } - } else { - float minLevel=1.0f; - float maxLevel=-1.0f; - float dcOff=0.0f; - unsigned short needlePos=buf->needle; - for (int i=0; iinBuf[i]=(double)buf->data[(unsigned short)(needlePos-displaySize*2+((i*displaySize*2)/FURNACE_FFT_SIZE))]/32768.0; - } - fftw_execute(fft->plan); - - // find origin frequency - int point=1; - double candAmp=0.0; - for (unsigned short i=1; i<512; i++) { - fftw_complex& f=fft->outBuf[i]; - // AMPLITUDE - double amp=sqrt(pow(f[0],2.0)+pow(f[1],2.0))/pow((double)i,0.8); - if (amp>candAmp) { - point=i; - candAmp=amp; + ImVec2 minArea=window->DC.CursorPos; + ImVec2 maxArea=ImVec2( + minArea.x+size.x, + minArea.y+size.y + ); + ImRect rect=ImRect(minArea,maxArea); + ImRect inRect=rect; + inRect.Min.x+=dpiScale; + inRect.Min.y+=2.0*dpiScale; + inRect.Max.x-=dpiScale; + inRect.Max.y-=2.0*dpiScale; + + int precision=inRect.Max.x-inRect.Min.x; + if (precision<1) precision=1; + if (precision>512) precision=512; + + ImGui::ItemSize(size,style.FramePadding.y); + if (ImGui::ItemAdd(rect,ImGui::GetID("chOscDisplay"))) { + if (!e->isRunning()) { + for (unsigned short i=0; ineedle; + for (int i=0; iinBuf[i]=(double)buf->data[(unsigned short)(needlePos-displaySize*2+((i*displaySize*2)/FURNACE_FFT_SIZE))]/32768.0; + } + fftw_execute(fft->plan); + + // find origin frequency + int point=1; + double candAmp=0.0; + for (unsigned short i=1; i<512; i++) { + fftw_complex& f=fft->outBuf[i]; + // AMPLITUDE + double amp=sqrt(pow(f[0],2.0)+pow(f[1],2.0))/pow((double)i,0.8); + if (amp>candAmp) { + point=i; + candAmp=amp; + } + } + + // PHASE + fftw_complex& candPoint=fft->outBuf[point]; + double phase=((double)(displaySize*2)/(double)point)*(0.5+(atan2(candPoint[1],candPoint[0])/(M_PI*2))); + + if (chanOscWaveCorr) { + needlePos-=phase; + } + chanOscPitch[ch]=(float)point/32.0f; + + /* + String cPhase=fmt::sprintf("%d cphase: %f vol: %f",point,phase,chanOscVol[ch]); + dl->AddText(inRect.Min,0xffffffff,cPhase.c_str()); + */ + + needlePos-=displaySize; + for (unsigned short i=0; idata[(unsigned short)(needlePos+(i*displaySize/precision))]/32768.0f; + if (minLevel>y) minLevel=y; + if (maxLeveldata[(unsigned short)(needlePos+(i*displaySize/precision))]/32768.0f; + y-=dcOff; + if (y<-0.5f) y=-0.5f; + if (y>0.5f) y=0.5f; + y*=chanOscAmplify; + waveform[i]=ImLerp(inRect.Min,inRect.Max,ImVec2(x,0.5f-y)); } } + ImU32 color=ImGui::GetColorU32(chanOscColor); + if (chanOscUseGrad) { + float xVal=computeGradPos(chanOscColorX,ch); + float yVal=computeGradPos(chanOscColorY,ch); - // PHASE - fftw_complex& candPoint=fft->outBuf[point]; - double phase=((double)(displaySize*2)/(double)point)*(0.5+(atan2(candPoint[1],candPoint[0])/(M_PI*2))); + xVal=CLAMP(xVal,0.0f,1.0f); + yVal=CLAMP(yVal,0.0f,1.0f); - if (chanOscWaveCorr) { - needlePos-=phase; + color=chanOscGrad.get(xVal,1.0f-yVal); } - chanOscPitch[ch]=(float)point/32.0f; - - /* - String cPhase=fmt::sprintf("%d cphase: %f vol: %f",point,phase,chanOscVol[ch]); - dl->AddText(inRect.Min,0xffffffff,cPhase.c_str()); - */ + ImGui::PushClipRect(inRect.Min,inRect.Max,false); - needlePos-=displaySize; - for (unsigned short i=0; i<512; i++) { - float y=(float)buf->data[(unsigned short)(needlePos+(i*displaySize/512))]/65536.0f; - if (minLevel>y) minLevel=y; - if (maxLeveldata[(unsigned short)(needlePos+(i*displaySize/512))]/65536.0f; - if (y<-0.5f) y=-0.5f; - if (y>0.5f) y=0.5f; - waveform[i]=ImLerp(inRect.Min,inRect.Max,ImVec2(x,0.5f-(y-dcOff))); + dl->AddPolyline(waveform,precision,color,ImDrawFlags_None,dpiScale); + + if (!chanOscTextFormat.empty()) { + String text; + bool inFormat=false; + + for (char i: chanOscTextFormat) { + if (inFormat) { + switch (i) { + case 'c': + text+=e->getChannelName(ch); + break; + case 'C': + text+=e->getChannelShortName(ch); + break; + case 'd': + text+=fmt::sprintf("%d",ch); + break; + case 'D': + text+=fmt::sprintf("%d",ch+1); + break; + case 'i': { + DivChannelState* chanState=e->getChanState(ch); + if (chanState==NULL) break; + DivInstrument* ins=e->getIns(chanState->lastIns); + text+=ins->name; + break; + } + case 'I': { + DivChannelState* chanState=e->getChanState(ch); + if (chanState==NULL) break; + text+=fmt::sprintf("%d",chanState->lastIns); + break; + } + case 'x': { + DivChannelState* chanState=e->getChanState(ch); + if (chanState==NULL) break; + if (chanState->lastIns<0) { + text+="??"; + } else { + text+=fmt::sprintf("%.2X",chanState->lastIns); + } + break; + } + case 's': { + text+=e->getSystemName(e->sysOfChan[ch]); + break; + } + case 'S': { + text+=fmt::sprintf("%d",e->dispatchOfChan[ch]); + break; + } + case 'v': + break; + case 'V': + break; + case 'b': + break; + case '%': + text+='%'; + break; + default: + text+='%'; + text+=i; + break; + } + inFormat=false; + } else { + if (i=='%') { + inFormat=true; + } else { + text+=i; + } + } + } + + dl->AddText(ImLerp(inRect.Min,inRect.Max,ImVec2(0.0f,0.0f)),ImGui::GetColorU32(chanOscTextColor),text.c_str()); } + + ImGui::PopClipRect(); } - ImU32 color=ImGui::GetColorU32(chanOscColor); - if (chanOscUseGrad) { - float xVal=computeGradPos(chanOscColorX,ch); - float yVal=computeGradPos(chanOscColorY,ch); - - xVal=CLAMP(xVal,0.0f,1.0f); - yVal=CLAMP(yVal,0.0f,1.0f); - - color=chanOscGrad.get(xVal,1.0f-yVal); - } - dl->AddPolyline(waveform,512,color,ImDrawFlags_None,dpiScale); } } - } - ImGui::EndTable(); + ImGui::EndTable(); - if (ImGui::IsItemClicked(ImGuiMouseButton_Right)) { - chanOscOptions=!chanOscOptions; + if (ImGui::IsItemClicked(ImGuiMouseButton_Right)) { + chanOscOptions=!chanOscOptions; + } } + ImGui::PopStyleVar(); } - ImGui::PopStyleVar(); } if (ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows)) curWindow=GUI_WINDOW_CHAN_OSC; ImGui::End(); diff --git a/src/gui/dataList.cpp b/src/gui/dataList.cpp index 72269988..b9c1e11a 100644 --- a/src/gui/dataList.cpp +++ b/src/gui/dataList.cpp @@ -287,21 +287,17 @@ void FurnaceGUI::insListItem(int i, int dir, int asset) { } else { ImGui::PushStyleColor(ImGuiCol_Text,uiColors[GUI_COLOR_TEXT]); } - if (ImGui::Selectable(name.c_str(),(i==-1)?(curIns<0 || curIns>=e->song.insLen):(curIns==i))) { + bool insReleased=ImGui::Selectable(name.c_str(),(i==-1)?(curIns<0 || curIns>=e->song.insLen):(curIns==i)); + bool insPressed=ImGui::IsItemActivated(); + if (insReleased || (!insListDir && insPressed)) { curIns=i; wavePreviewInit=true; updateFMPreview=true; lastAssetType=0; - if (insListDir) nextWindow=GUI_WINDOW_PATTERN; + if (settings.insFocusesPattern && patternOpen) + nextWindow=GUI_WINDOW_PATTERN; } if (wantScrollList && curIns==i) ImGui::SetScrollHereY(); - if (settings.insFocusesPattern && patternOpen && ImGui::IsItemActivated()) { - if (!insListDir) nextWindow=GUI_WINDOW_PATTERN; - curIns=i; - wavePreviewInit=true; - updateFMPreview=true; - lastAssetType=0; - } if (ImGui::IsItemHovered() && i>=0 && !mobileUI) { ImGui::PushStyleColor(ImGuiCol_Text,uiColors[GUI_COLOR_TEXT]); ImGui::SetTooltip("%s",insType); @@ -697,6 +693,7 @@ void FurnaceGUI::drawInsList(bool asChild) { } } ImGui::SameLine(); + pushDestColor(); if (ImGui::Button(ICON_FA_TIMES "##InsDelete")) { if (settings.unifiedDataView) { switch (lastAssetType) { @@ -714,6 +711,7 @@ void FurnaceGUI::drawInsList(bool asChild) { doAction(GUI_ACTION_INS_LIST_DELETE); } } + popDestColor(); if (ImGui::IsItemHovered()) { ImGui::SetTooltip("Delete"); } @@ -934,9 +932,11 @@ void FurnaceGUI::drawWaveList(bool asChild) { } } ImGui::SameLine(); + pushDestColor(); if (ImGui::Button(ICON_FA_TIMES "##WaveDelete")) { doAction(GUI_ACTION_WAVE_LIST_DELETE); } + popDestColor(); if (ImGui::IsItemHovered()) { ImGui::SetTooltip("Delete"); } @@ -1074,13 +1074,6 @@ void FurnaceGUI::drawSampleList(bool asChild) { } } ImGui::SameLine(); - if (ImGui::Button(ICON_FA_TIMES "##SampleDelete")) { - doAction(GUI_ACTION_SAMPLE_LIST_DELETE); - } - if (ImGui::IsItemHovered()) { - ImGui::SetTooltip("Delete"); - } - ImGui::SameLine(); if (ImGui::Button(ICON_FA_VOLUME_UP "##PreviewSampleL")) { doAction(GUI_ACTION_SAMPLE_LIST_PREVIEW); } @@ -1094,6 +1087,15 @@ void FurnaceGUI::drawSampleList(bool asChild) { if (ImGui::IsItemHovered()) { ImGui::SetTooltip("Stop preview"); } + ImGui::SameLine(); + pushDestColor(); + if (ImGui::Button(ICON_FA_TIMES "##SampleDelete")) { + doAction(GUI_ACTION_SAMPLE_LIST_DELETE); + } + popDestColor(); + if (ImGui::IsItemHovered()) { + ImGui::SetTooltip("Delete"); + } ImGui::Separator(); if (ImGui::BeginTable("SampleListScroll",1,ImGuiTableFlags_ScrollY)) { actualSampleList(); diff --git a/src/gui/debugWindow.cpp b/src/gui/debugWindow.cpp index 7eb3906a..b9dc6c42 100644 --- a/src/gui/debugWindow.cpp +++ b/src/gui/debugWindow.cpp @@ -380,7 +380,7 @@ void FurnaceGUI::drawDebug() { } ImGui::TreePop(); } - if (ImGui::TreeNode("Window Debug")) { + if (ImGui::TreeNodeEx("Window Debug",ImGuiTreeNodeFlags_DefaultOpen)) { ImGui::Text("Screen: %dx%d+%d+%d",scrW,scrH,scrX,scrY); ImGui::Text("Screen (Conf): %dx%d+%d+%d",scrConfW,scrConfH,scrConfX,scrConfY); ImGui::Text("Canvas: %dx%d",canvasW,canvasH); @@ -536,6 +536,9 @@ void FurnaceGUI::drawDebug() { if (ImGui::Button("Spoiler")) { spoilerOpen=!spoilerOpen; } + if (ImGui::Button("Kill Graphics")) { + killGraphics=true; + } ImGui::TreePop(); } if (ImGui::TreeNode("Performance")) { @@ -549,6 +552,7 @@ void FurnaceGUI::drawDebug() { ImGui::Text("audio: %dµs",lastProcTime); ImGui::Text("render: %.0fµs",(double)renderTimeDelta/perfFreq); + ImGui::Text("draw: %.0fµs",(double)drawTimeDelta/perfFreq); ImGui::Text("layout: %.0fµs",(double)layoutTimeDelta/perfFreq); ImGui::Text("event: %.0fµs",(double)eventTimeDelta/perfFreq); ImGui::Separator(); diff --git a/src/gui/doAction.cpp b/src/gui/doAction.cpp index 7520162f..87d74e6c 100644 --- a/src/gui/doAction.cpp +++ b/src/gui/doAction.cpp @@ -791,6 +791,8 @@ void FurnaceGUI::doAction(int what) { sample->loopEnd=prevSample->loopEnd; sample->loop=prevSample->loop; sample->loopMode=prevSample->loopMode; + sample->brrEmphasis=prevSample->brrEmphasis; + sample->dither=prevSample->dither; sample->depth=prevSample->depth; if (sample->init(prevSample->samples)) { if (prevSample->getCurBuf()!=NULL) { diff --git a/src/gui/editing.cpp b/src/gui/editing.cpp index 1a2b1b11..b9e03511 100644 --- a/src/gui/editing.cpp +++ b/src/gui/editing.cpp @@ -245,14 +245,22 @@ void FurnaceGUI::doPullDelete() { updateScroll(cursor.y); } - int iCoarse=selStart.xCoarse; - int iFine=selStart.xFine; - for (; iCoarse<=selEnd.xCoarse; iCoarse++) { + SelectionPoint sStart=selStart; + SelectionPoint sEnd=selEnd; + + if (selStart.xCoarse==selEnd.xCoarse && selStart.xFine==selEnd.xFine && selStart.y==selEnd.y && settings.pullDeleteRow) { + sStart.xFine=0; + sEnd.xFine=2+e->curPat[sEnd.xCoarse].effectCols*2; + } + + int iCoarse=sStart.xCoarse; + int iFine=sStart.xFine; + for (; iCoarse<=sEnd.xCoarse; iCoarse++) { if (!e->curSubSong->chanShow[iCoarse]) continue; DivPattern* pat=e->curPat[iCoarse].getPattern(e->curOrders->ord[iCoarse][curOrder],true); - for (; iFine<3+e->curPat[iCoarse].effectCols*2 && (iCoarsecurPat[iCoarse].effectCols*2 && (iCoarsecurSubSong->patLen; j++) { + for (int j=sStart.y; jcurSubSong->patLen; j++) { if (jcurSubSong->patLen-1) { if (iFine==0) { pat->data[j][iFine]=pat->data[j+1][iFine]; @@ -277,15 +285,23 @@ void FurnaceGUI::doInsert() { prepareUndo(GUI_UNDO_PATTERN_PUSH); curNibble=false; - int iCoarse=selStart.xCoarse; - int iFine=selStart.xFine; - for (; iCoarse<=selEnd.xCoarse; iCoarse++) { + SelectionPoint sStart=selStart; + SelectionPoint sEnd=selEnd; + + if (selStart.xCoarse==selEnd.xCoarse && selStart.xFine==selEnd.xFine && selStart.y==selEnd.y && settings.insertBehavior) { + sStart.xFine=0; + sEnd.xFine=2+e->curPat[sEnd.xCoarse].effectCols*2; + } + + int iCoarse=sStart.xCoarse; + int iFine=sStart.xFine; + for (; iCoarse<=sEnd.xCoarse; iCoarse++) { if (!e->curSubSong->chanShow[iCoarse]) continue; DivPattern* pat=e->curPat[iCoarse].getPattern(e->curOrders->ord[iCoarse][curOrder],true); - for (; iFine<3+e->curPat[iCoarse].effectCols*2 && (iCoarsecurPat[iCoarse].effectCols*2 && (iCoarsecurSubSong->patLen-1; j>=selStart.y; j--) { - if (j==selStart.y) { + for (int j=e->curSubSong->patLen-1; j>=sStart.y; j--) { + if (j==sStart.y) { if (iFine==0) { pat->data[j][iFine]=0; } diff --git a/src/gui/fileDialog.cpp b/src/gui/fileDialog.cpp index 94ffa94e..a0a45e1e 100644 --- a/src/gui/fileDialog.cpp +++ b/src/gui/fileDialog.cpp @@ -1,5 +1,6 @@ #include "fileDialog.h" #include "ImGuiFileDialog.h" +#include "util.h" #include "../ta-log.h" #ifdef USE_NFD @@ -152,6 +153,7 @@ bool FurnaceGUIFileDialog::openLoad(String header, std::vector filter, c ImGuiFileDialog::Instance()->singleClickSel=mobileUI; ImGuiFileDialog::Instance()->DpiScale=dpiScale; ImGuiFileDialog::Instance()->mobileMode=mobileUI; + ImGuiFileDialog::Instance()->homePath=getHomeDir(); ImGuiFileDialog::Instance()->OpenModal("FileDialog",header,noSysFilter,path,allowMultiple?999:1,nullptr,0,clickCallback); } opened=true; @@ -235,6 +237,7 @@ bool FurnaceGUIFileDialog::openSave(String header, std::vector filter, c ImGuiFileDialog::Instance()->singleClickSel=false; ImGuiFileDialog::Instance()->DpiScale=dpiScale; ImGuiFileDialog::Instance()->mobileMode=mobileUI; + ImGuiFileDialog::Instance()->homePath=getHomeDir(); ImGuiFileDialog::Instance()->OpenModal("FileDialog",header,noSysFilter,path,1,nullptr,ImGuiFileDialogFlags_ConfirmOverwrite); } opened=true; diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 614066a1..62608960 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -29,8 +29,6 @@ #include "../fileutils.h" #include "imgui.h" #include "imgui_internal.h" -#include "imgui_impl_sdl.h" -#include "imgui_impl_sdlrenderer.h" #include "ImGuiFileDialog.h" #include "IconsFontAwesome4.h" #include "misc/cpp/imgui_stdlib.h" @@ -499,6 +497,13 @@ bool FurnaceGUI::InvCheckbox(const char* label, bool* value) { return false; } +void FurnaceGUI::sameLineMaybe(float width) { + if (width<0.0f) width=ImGui::GetFrameHeight(); + + ImGui::SameLine(); + if (ImGui::GetContentRegionAvail().xprocessEvent(event); } +#if SDL_VERSION_ATLEAST(2,0,17) +#define VALID_MODS KMOD_NUM|KMOD_CAPS|KMOD_SCROLL +#else +#define VALID_MODS KMOD_NUM|KMOD_CAPS +#endif + int FurnaceGUI::processEvent(SDL_Event* ev) { if (introPos<11.0 && !shortIntro) return 1; #ifdef IS_MOBILE @@ -2963,7 +2974,7 @@ int FurnaceGUI::processEvent(SDL_Event* ev) { } #endif if (ev->type==SDL_KEYDOWN) { - if (!ev->key.repeat && latchTarget==0 && !wantCaptureKeyboard && !sampleMapWaitingInput && (ev->key.keysym.mod&(~(KMOD_NUM|KMOD_CAPS|KMOD_SCROLL)))==0) { + if (!ev->key.repeat && latchTarget==0 && !wantCaptureKeyboard && !sampleMapWaitingInput && (ev->key.keysym.mod&(~(VALID_MODS)))==0) { if (settings.notePreviewBehavior==0) return 1; switch (curWindow) { case GUI_WINDOW_SAMPLE_EDIT: @@ -3416,6 +3427,7 @@ bool FurnaceGUI::loop() { logV("portrait: %d (%dx%d)",portrait,scrW,scrH); logD("window resized to %dx%d",scrW,scrH); updateWindow=true; + rend->resized(ev); break; case SDL_WINDOWEVENT_MOVED: scrX=ev.window.data1; @@ -3450,6 +3462,12 @@ bool FurnaceGUI::loop() { break; } break; +#if SDL_VERSION_ATLEAST(2,0,4) + case SDL_RENDER_DEVICE_RESET: + killGraphics=true; + break; +#endif +#if SDL_VERSION_ATLEAST(2,0,17) case SDL_DISPLAYEVENT: { switch (ev.display.event) { case SDL_DISPLAYEVENT_CONNECTED: @@ -3467,6 +3485,7 @@ bool FurnaceGUI::loop() { } break; } +#endif case SDL_KEYDOWN: if (!ImGui::GetIO().WantCaptureKeyboard) { keyDown(ev); @@ -3483,7 +3502,7 @@ bool FurnaceGUI::loop() { int sampleCountBefore=e->song.sampleLen; std::vector instruments=e->instrumentFromFile(ev.drop.file); DivWavetable* droppedWave=NULL; - DivSample* droppedSample=NULL;; + DivSample* droppedSample=NULL; if (!instruments.empty()) { if (e->song.sampleLen!=sampleCountBefore) { e->renderSamplesP(); @@ -3529,7 +3548,8 @@ bool FurnaceGUI::loop() { // update config x/y/w/h values based on scrMax state if (updateWindow) { logV("updateWindow is true"); - if (!scrMax) { + if (!scrMax && !fullScreen) { + logV("updating scrConf"); scrConfX=scrX; scrConfY=scrY; scrConfW=scrW; @@ -3537,8 +3557,8 @@ bool FurnaceGUI::loop() { } } // update canvas size as well - if (SDL_GetRendererOutputSize(sdlRend,&canvasW,&canvasH)!=0) { - logW("loop: error while getting output size! %s",SDL_GetError()); + if (!rend->getOutputSize(canvasW,canvasH)) { + logW("loop: error while getting output size!"); } else { //logV("updateWindow: canvas size %dx%d",canvasW,canvasH); // and therefore window size @@ -3759,11 +3779,84 @@ bool FurnaceGUI::loop() { }); } + // recover from dead graphics + if (rend->isDead() || killGraphics) { + killGraphics=false; + + logW("graphics are dead! restarting..."); + + if (sampleTex!=NULL) { + rend->destroyTexture(sampleTex); + sampleTex=NULL; + } + + if (chanOscGradTex!=NULL) { + rend->destroyTexture(chanOscGradTex); + chanOscGradTex=NULL; + } + + for (auto& i: images) { + if (i.second->tex!=NULL) { + rend->destroyTexture(i.second->tex); + i.second->tex=NULL; + } + } + + commitState(); + rend->quitGUI(); + rend->quit(); + ImGui_ImplSDL2_Shutdown(); + + int initAttempts=0; + + SDL_Delay(500); + + logD("starting render backend..."); + while (++initAttempts<=5) { + if (rend->init(sdlWin)) { + break; + } + SDL_Delay(1000); + logV("trying again..."); + } + + if (initAttempts>5) { + reportError("can't keep going without graphics! Furnace will quit now."); + quit=true; + break; + } + + rend->clear(ImVec4(0.0,0.0,0.0,1.0)); + rend->present(); + + logD("preparing user interface..."); + rend->initGUI(sdlWin); + + logD("building font..."); + if (!ImGui::GetIO().Fonts->Build()) { + logE("error while building font atlas!"); + showError("error while loading fonts! please check your settings."); + ImGui::GetIO().Fonts->Clear(); + mainFont=ImGui::GetIO().Fonts->AddFontDefault(); + patFont=mainFont; + if (rend) rend->destroyFontsTexture(); + if (!ImGui::GetIO().Fonts->Build()) { + logE("error again while building font atlas!"); + } + } + + firstFrame=true; + mustClear=2; + initialScreenWipe=1.0f; + + continue; + } + bool fontsFailed=false; layoutTimeBegin=SDL_GetPerformanceCounter(); - if (!ImGui_ImplSDLRenderer_NewFrame()) { + if (!rend->newFrame()) { fontsFailed=true; } ImGui_ImplSDL2_NewFrame(sdlWin); @@ -4347,6 +4440,7 @@ bool FurnaceGUI::loop() { MEASURE(log,drawLog()); MEASURE(compatFlags,drawCompatFlags()); MEASURE(stats,drawStats()); + MEASURE(chanOsc,drawChanOsc()); } else { globalWinFlags=0; ImGui::DockSpaceOverViewport(NULL,lockLayout?(ImGuiDockNodeFlags_NoWindowMenuButton|ImGuiDockNodeFlags_NoMove|ImGuiDockNodeFlags_NoResize|ImGuiDockNodeFlags_NoCloseButton|ImGuiDockNodeFlags_NoDocking|ImGuiDockNodeFlags_NoDockingSplitMe|ImGuiDockNodeFlags_NoDockingSplitOther):0); @@ -4418,7 +4512,7 @@ bool FurnaceGUI::loop() { portrait=(scrWgetOutputSize(canvasW,canvasH); #endif if (patternOpen) nextWindow=GUI_WINDOW_PATTERN; #ifdef __APPLE__ @@ -5067,7 +5161,24 @@ bool FurnaceGUI::loop() { newSongQuery=""; newSongFirstFrame=true; displayNew=false; - ImGui::OpenPopup("New Song"); + if (settings.newSongBehavior==1) { + e->createNewFromDefaults(); + undoHist.clear(); + redoHist.clear(); + curFileName=""; + modified=false; + curNibble=false; + orderNibble=false; + orderCursor=-1; + samplePos=0; + updateSampleTex=true; + selStart=SelectionPoint(); + selEnd=SelectionPoint(); + cursor=SelectionPoint(); + updateWindowTitle(); + } else { + ImGui::OpenPopup("New Song"); + } } if (displayEditString) { @@ -5796,33 +5907,35 @@ bool FurnaceGUI::loop() { } } - SDL_SetRenderDrawColor(sdlRend,uiColors[GUI_COLOR_BACKGROUND].x*255, - uiColors[GUI_COLOR_BACKGROUND].y*255, - uiColors[GUI_COLOR_BACKGROUND].z*255, - uiColors[GUI_COLOR_BACKGROUND].w*255); - SDL_RenderClear(sdlRend); + if (!settings.renderClearPos) { + rend->clear(uiColors[GUI_COLOR_BACKGROUND]); + } renderTimeBegin=SDL_GetPerformanceCounter(); ImGui::Render(); renderTimeEnd=SDL_GetPerformanceCounter(); - ImGui_ImplSDLRenderer_RenderDrawData(ImGui::GetDrawData()); + drawTimeBegin=SDL_GetPerformanceCounter(); + rend->renderGUI(); if (mustClear) { - SDL_RenderClear(sdlRend); + rend->clear(ImVec4(0,0,0,0)); mustClear--; } else { if (initialScreenWipe>0.0f && !settings.disableFadeIn) { WAKE_UP; initialScreenWipe-=ImGui::GetIO().DeltaTime*5.0f; if (initialScreenWipe>0.0f) { - SDL_SetRenderDrawBlendMode(sdlRend,SDL_BLENDMODE_BLEND); - SDL_SetRenderDrawColor(sdlRend,0,0,0,255*pow(initialScreenWipe,2.0f)); - SDL_RenderFillRect(sdlRend,NULL); + rend->wipe(pow(initialScreenWipe,2.0f)); } } } - SDL_RenderPresent(sdlRend); + drawTimeEnd=SDL_GetPerformanceCounter(); + rend->present(); + if (settings.renderClearPos) { + rend->clear(uiColors[GUI_COLOR_BACKGROUND]); + } layoutTimeDelta=layoutTimeEnd-layoutTimeBegin; renderTimeDelta=renderTimeEnd-renderTimeBegin; + drawTimeDelta=drawTimeEnd-drawTimeBegin; eventTimeDelta=eventTimeEnd-eventTimeBegin; soloTimeout-=ImGui::GetIO().DeltaTime; @@ -5854,9 +5967,11 @@ bool FurnaceGUI::loop() { ImGui::GetIO().Fonts->Clear(); mainFont=ImGui::GetIO().Fonts->AddFontDefault(); patFont=mainFont; - ImGui_ImplSDLRenderer_DestroyFontsTexture(); + if (rend) rend->destroyFontsTexture(); if (!ImGui::GetIO().Fonts->Build()) { logE("error again while building font atlas!"); + } else { + rend->createFontsTexture(); } } @@ -5972,6 +6087,7 @@ bool FurnaceGUI::init() { pianoOptions=e->getConfBool("pianoOptions",pianoOptions); pianoSharePosition=e->getConfBool("pianoSharePosition",pianoSharePosition); pianoOptionsSet=e->getConfBool("pianoOptionsSet",pianoOptionsSet); + pianoReadonly=e->getConfBool("pianoReadonly",false); pianoOffset=e->getConfInt("pianoOffset",pianoOffset); pianoOffsetEdit=e->getConfInt("pianoOffsetEdit",pianoOffsetEdit); pianoView=e->getConfInt("pianoView",pianoView); @@ -5980,13 +6096,22 @@ bool FurnaceGUI::init() { chanOscCols=e->getConfInt("chanOscCols",3); chanOscColorX=e->getConfInt("chanOscColorX",GUI_OSCREF_CENTER); chanOscColorY=e->getConfInt("chanOscColorY",GUI_OSCREF_CENTER); + chanOscTextX=e->getConfFloat("chanOscTextX",0.0f); + chanOscTextY=e->getConfFloat("chanOscTextY",0.0f); + chanOscAmplify=e->getConfFloat("chanOscAmplify",0.95f); chanOscWindowSize=e->getConfFloat("chanOscWindowSize",20.0f); chanOscWaveCorr=e->getConfBool("chanOscWaveCorr",true); chanOscOptions=e->getConfBool("chanOscOptions",false); + chanOscNormalize=e->getConfBool("chanOscNormalize",false); + chanOscTextFormat=e->getConfString("chanOscTextFormat","%c"); chanOscColor.x=e->getConfFloat("chanOscColorR",1.0f); chanOscColor.y=e->getConfFloat("chanOscColorG",1.0f); chanOscColor.z=e->getConfFloat("chanOscColorB",1.0f); chanOscColor.w=e->getConfFloat("chanOscColorA",1.0f); + chanOscTextColor.x=e->getConfFloat("chanOscTextColorR",1.0f); + chanOscTextColor.y=e->getConfFloat("chanOscTextColorG",1.0f); + chanOscTextColor.z=e->getConfFloat("chanOscTextColorB",1.0f); + chanOscTextColor.w=e->getConfFloat("chanOscTextColorA",0.75f); chanOscUseGrad=e->getConfBool("chanOscUseGrad",false); chanOscGrad.fromString(e->getConfString("chanOscGrad","")); chanOscGrad.render(); @@ -6012,7 +6137,9 @@ bool FurnaceGUI::init() { e->setAutoNotePoly(noteInputPoly); SDL_SetHint(SDL_HINT_VIDEO_ALLOW_SCREENSAVER,"1"); +#if SDL_VERSION_ATLEAST(2,0,17) SDL_SetHint(SDL_HINT_MOUSE_TOUCH_EVENTS,"0"); +#endif SDL_SetHint(SDL_HINT_TOUCH_MOUSE_EVENTS,"0"); // don't disable compositing on KWin #if SDL_VERSION_ATLEAST(2,0,22) @@ -6021,7 +6148,18 @@ bool FurnaceGUI::init() { #endif // initialize SDL - SDL_Init(SDL_INIT_VIDEO|SDL_INIT_HAPTIC); + logD("initializing video..."); + if (SDL_Init(SDL_INIT_VIDEO)!=0) { + logE("could not initialize video! %s",SDL_GetError()); + return false; + } + +#ifdef IS_MOBILE + logD("initializing haptic..."); + if (SDL_Init(SDL_INIT_HAPTIC)!=0) { + logW("could not initialize haptic! %s",SDL_GetError()); + } +#endif const char* videoBackend=SDL_GetCurrentVideoDriver(); if (videoBackend!=NULL) { @@ -6122,7 +6260,28 @@ bool FurnaceGUI::init() { logV("window size: %dx%d",scrW,scrH); - sdlWin=SDL_CreateWindow("Furnace",scrX,scrY,scrW,scrH,SDL_WINDOW_RESIZABLE|SDL_WINDOW_ALLOW_HIGHDPI|(scrMax?SDL_WINDOW_MAXIMIZED:0)|(fullScreen?SDL_WINDOW_FULLSCREEN_DESKTOP:0)); + if (!initRender()) { + if (settings.renderBackend!="SDL" && !settings.renderBackend.empty()) { + settings.renderBackend=""; + e->setConf("renderBackend",""); + e->saveConf(); + lastError=fmt::sprintf("\r\nthe render backend has been set to a safe value. please restart Furnace."); + } else { + lastError=fmt::sprintf("could not init renderer! %s",SDL_GetError()); + if (!settings.renderDriver.empty()) { + settings.renderDriver=""; + e->setConf("renderDriver",""); + e->saveConf(); + lastError=fmt::sprintf("\r\nthe render driver has been set to a safe value. please restart Furnace."); + } + } + return false; + } + + rend->preInit(); + + logD("creating window..."); + sdlWin=SDL_CreateWindow("Furnace",scrX,scrY,scrW,scrH,SDL_WINDOW_RESIZABLE|SDL_WINDOW_ALLOW_HIGHDPI|(scrMax?SDL_WINDOW_MAXIMIZED:0)|(fullScreen?SDL_WINDOW_FULLSCREEN_DESKTOP:0)|rend->getWindowFlags()); if (sdlWin==NULL) { lastError=fmt::sprintf("could not open window! %s",SDL_GetError()); return false; @@ -6186,22 +6345,28 @@ bool FurnaceGUI::init() { SDL_SetHint(SDL_HINT_RENDER_DRIVER,settings.renderDriver.c_str()); } - sdlRend=SDL_CreateRenderer(sdlWin,-1,SDL_RENDERER_ACCELERATED|SDL_RENDERER_PRESENTVSYNC|SDL_RENDERER_TARGETTEXTURE); - - if (sdlRend==NULL) { - lastError=fmt::sprintf("could not init renderer! %s",SDL_GetError()); - if (!settings.renderDriver.empty()) { - settings.renderDriver=""; - e->setConf("renderDriver",""); - e->saveConf(); - lastError=fmt::sprintf("\r\nthe render driver has been set to a safe value. please restart Furnace."); + logD("starting render backend..."); + if (!rend->init(sdlWin)) { + if (settings.renderBackend!="SDL" && !settings.renderBackend.empty()) { + settings.renderBackend=""; + //e->setConf("renderBackend",""); + //e->saveConf(); + //lastError=fmt::sprintf("\r\nthe render backend has been set to a safe value. please restart Furnace."); + } else { + lastError=fmt::sprintf("could not init renderer! %s",SDL_GetError()); + if (!settings.renderDriver.empty()) { + settings.renderDriver=""; + e->setConf("renderDriver",""); + e->saveConf(); + lastError=fmt::sprintf("\r\nthe render driver has been set to a safe value. please restart Furnace."); + } } return false; } // try acquiring the canvas size - if (SDL_GetRendererOutputSize(sdlRend,&canvasW,&canvasH)!=0) { - logW("could not get renderer output size! %s",SDL_GetError()); + if (!rend->getOutputSize(canvasW,canvasH)) { + logW("could not get renderer output size!"); } else { logV("canvas size: %dx%d",canvasW,canvasH); } @@ -6209,30 +6374,47 @@ bool FurnaceGUI::init() { // special consideration for Wayland if (settings.dpiScale<0.5f) { if (strcmp(videoBackend,"wayland")==0) { - dpiScale=(double)canvasW/(double)scrW; + int realW=scrW; + int realH=scrH; + + SDL_GetWindowSize(sdlWin,&realW,&realH); + + if (realW<1) { + logW("screen width is zero!\n"); + dpiScale=1.0; + } else { + dpiScale=(double)canvasW/(double)realW; + logV("we're on Wayland... scaling factor: %f",dpiScale); + } } } + updateWindowTitle(); + + rend->clear(ImVec4(0.0,0.0,0.0,1.0)); + rend->present(); + + logD("preparing user interface..."); IMGUI_CHECKVERSION(); ImGui::CreateContext(); - - ImGui_ImplSDL2_InitForSDLRenderer(sdlWin,sdlRend); - ImGui_ImplSDLRenderer_Init(sdlRend); + rend->initGUI(sdlWin); applyUISettings(); + logD("building font..."); if (!ImGui::GetIO().Fonts->Build()) { logE("error while building font atlas!"); showError("error while loading fonts! please check your settings."); ImGui::GetIO().Fonts->Clear(); mainFont=ImGui::GetIO().Fonts->AddFontDefault(); patFont=mainFont; - ImGui_ImplSDLRenderer_DestroyFontsTexture(); + if (rend) rend->destroyFontsTexture(); if (!ImGui::GetIO().Fonts->Build()) { logE("error again while building font atlas!"); } } + logD("preparing layout..."); strncpy(finalLayoutPath,(e->getConfigPath()+String(LAYOUT_INI)).c_str(),4095); backupPath=e->getConfigPath(); if (backupPath.size()>0) { @@ -6244,8 +6426,6 @@ bool FurnaceGUI::init() { ImGui::GetIO().ConfigFlags|=ImGuiConfigFlags_DockingEnable; toggleMobileUI(mobileUI,true); - updateWindowTitle(); - for (int i=0; isetConf("pianoOptions",pianoOptions); e->setConf("pianoSharePosition",pianoSharePosition); e->setConf("pianoOptionsSet",pianoOptionsSet); + e->setConf("pianoReadonly",pianoReadonly); e->setConf("pianoOffset",pianoOffset); e->setConf("pianoOffsetEdit",pianoOffsetEdit); e->setConf("pianoView",pianoView); @@ -6416,13 +6600,22 @@ void FurnaceGUI::commitState() { e->setConf("chanOscCols",chanOscCols); e->setConf("chanOscColorX",chanOscColorX); e->setConf("chanOscColorY",chanOscColorY); + e->setConf("chanOscTextX",chanOscTextX); + e->setConf("chanOscTextY",chanOscTextY); + e->setConf("chanOscAmplify",chanOscAmplify); e->setConf("chanOscWindowSize",chanOscWindowSize); e->setConf("chanOscWaveCorr",chanOscWaveCorr); e->setConf("chanOscOptions",chanOscOptions); + e->setConf("chanOscNormalize",chanOscNormalize); + e->setConf("chanOscTextFormat",chanOscTextFormat); e->setConf("chanOscColorR",chanOscColor.x); e->setConf("chanOscColorG",chanOscColor.y); e->setConf("chanOscColorB",chanOscColor.z); e->setConf("chanOscColorA",chanOscColor.w); + e->setConf("chanOscTextColorR",chanOscTextColor.x); + e->setConf("chanOscTextColorG",chanOscTextColor.y); + e->setConf("chanOscTextColorB",chanOscTextColor.z); + e->setConf("chanOscTextColorA",chanOscTextColor.w); e->setConf("chanOscUseGrad",chanOscUseGrad); e->setConf("chanOscGrad",chanOscGrad.toString()); @@ -6439,10 +6632,10 @@ void FurnaceGUI::commitState() { bool FurnaceGUI::finish() { commitState(); - ImGui_ImplSDLRenderer_Shutdown(); + rend->quitGUI(); ImGui_ImplSDL2_Shutdown(); + quitRender(); ImGui::DestroyContext(); - SDL_DestroyRenderer(sdlRend); SDL_DestroyWindow(sdlWin); if (vibrator) { @@ -6462,8 +6655,9 @@ bool FurnaceGUI::finish() { FurnaceGUI::FurnaceGUI(): e(NULL), + renderBackend(GUI_BACKEND_SDL), + rend(NULL), sdlWin(NULL), - sdlRend(NULL), vibrator(NULL), vibratorAvailable(false), sampleTex(NULL), @@ -6485,6 +6679,7 @@ FurnaceGUI::FurnaceGUI(): portrait(false), injectBackUp(false), mobileMenuOpen(false), + warnColorPushed(false), wantCaptureKeyboard(false), oldWantCaptureKeyboard(false), displayMacroMenu(false), @@ -6500,6 +6695,7 @@ FurnaceGUI::FurnaceGUI(): modTableHex(false), displayEditString(false), mobileEdit(false), + killGraphics(false), vgmExportVersion(0x171), vgmExportTrailingTicks(-1), drawHalt(10), @@ -6766,6 +6962,9 @@ FurnaceGUI::FurnaceGUI(): renderTimeBegin(0), renderTimeEnd(0), renderTimeDelta(0), + drawTimeBegin(0), + drawTimeEnd(0), + drawTimeDelta(0), eventTimeBegin(0), eventTimeEnd(0), eventTimeDelta(0), @@ -6840,11 +7039,17 @@ FurnaceGUI::FurnaceGUI(): chanOscColorX(GUI_OSCREF_CENTER), chanOscColorY(GUI_OSCREF_CENTER), chanOscWindowSize(20.0f), + chanOscTextX(0.0f), + chanOscTextY(0.0f), + chanOscAmplify(0.95f), chanOscWaveCorr(true), chanOscOptions(false), updateChanOscGradTex(true), chanOscUseGrad(false), + chanOscNormalize(false), + chanOscTextFormat("%c"), chanOscColor(1.0f,1.0f,1.0f,1.0f), + chanOscTextColor(1.0f,1.0f,1.0f,0.75f), chanOscGrad(64,64), chanOscGradTex(NULL), followLog(true), @@ -6854,6 +7059,7 @@ FurnaceGUI::FurnaceGUI(): pianoOptions(true), pianoSharePosition(false), pianoOptionsSet(false), + pianoReadonly(false), pianoOffset(6), pianoOffsetEdit(9), pianoView(PIANO_LAYOUT_AUTOMATIC), @@ -6863,6 +7069,7 @@ FurnaceGUI::FurnaceGUI(): pianoOctavesEdit(4), pianoOptions(false), pianoSharePosition(true), + pianoReadonly(false), pianoOffset(6), pianoOffsetEdit(6), pianoView(PIANO_LAYOUT_STANDARD), @@ -6887,6 +7094,7 @@ FurnaceGUI::FurnaceGUI(): mustClear(2), initialScreenWipe(1.0f), introSkipDo(false), + introStopped(false), curTutorial(-1), curTutorialStep(0) { // value keys diff --git a/src/gui/gui.h b/src/gui/gui.h index 296014e1..a8befff2 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -23,8 +23,7 @@ #include "../engine/engine.h" #include "../engine/waveSynth.h" #include "imgui.h" -#include "imgui_impl_sdl.h" -#include "imgui_impl_sdlrenderer.h" +#include "imgui_impl_sdl2.h" #include #include #include @@ -70,6 +69,25 @@ #define FM_PREVIEW_SIZE 512 +enum FurnaceGUIRenderBackend { + GUI_BACKEND_SDL=0, + GUI_BACKEND_GL, + GUI_BACKEND_DX11 +}; + +#ifdef HAVE_RENDER_SDL +#define GUI_BACKEND_DEFAULT GUI_BACKEND_SDL +#define GUI_BACKEND_DEFAULT_NAME "SDL" +#else +#ifdef HAVE_RENDER_DX11 +#define GUI_BACKEND_DEFAULT GUI_BACKEND_DX11 +#define GUI_BACKEND_DEFAULT_NAME "DirectX 11" +#else +#define GUI_BACKEND_DEFAULT GUI_BACKEND_GL +#define GUI_BACKEND_DEFAULT_NAME "OpenGL" +#endif +#endif + // TODO: // - add colors for FM envelope and waveform // - maybe add "alternate" color for FM modulators/carriers (a bit difficult) @@ -108,6 +126,9 @@ enum FurnaceGUIColors { GUI_COLOR_TOGGLE_ON, GUI_COLOR_EDITING, GUI_COLOR_SONG_LOOP, + GUI_COLOR_DESTRUCTIVE, + GUI_COLOR_WARNING, + GUI_COLOR_ERROR, GUI_COLOR_FILE_DIR, GUI_COLOR_FILE_SONG_NATIVE, @@ -1189,9 +1210,12 @@ struct FurnaceGUIQueryResult { } }; +class FurnaceGUITexture { +}; + struct FurnaceGUIImage { unsigned char* data; - SDL_Texture* tex; + FurnaceGUITexture* tex; int width, height, ch; FurnaceGUIImage(): @@ -1213,15 +1237,53 @@ struct FurnaceGUIPerfMetric { elapsed(0) {} }; +enum FurnaceGUIBlendMode { + GUI_BLEND_MODE_NONE=0, + GUI_BLEND_MODE_BLEND, + GUI_BLEND_MODE_ADD, + GUI_BLEND_MODE_MULTIPLY +}; + +class FurnaceGUIRender { + public: + virtual ImTextureID getTextureID(FurnaceGUITexture* which); + virtual bool lockTexture(FurnaceGUITexture* which, void** data, int* pitch); + virtual bool unlockTexture(FurnaceGUITexture* which); + virtual bool updateTexture(FurnaceGUITexture* which, void* data, int pitch); + virtual FurnaceGUITexture* createTexture(bool dynamic, int width, int height); + virtual bool destroyTexture(FurnaceGUITexture* which); + virtual void setTextureBlendMode(FurnaceGUITexture* which, FurnaceGUIBlendMode mode); + virtual void setBlendMode(FurnaceGUIBlendMode mode); + virtual void resized(const SDL_Event& ev); + virtual void clear(ImVec4 color); + virtual bool newFrame(); + virtual void createFontsTexture(); + virtual void destroyFontsTexture(); + virtual void renderGUI(); + virtual void wipe(float alpha); + virtual void present(); + virtual bool getOutputSize(int& w, int& h); + virtual int getWindowFlags(); + virtual void preInit(); + virtual bool init(SDL_Window* win); + virtual void initGUI(SDL_Window* win); + virtual void quitGUI(); + virtual bool quit(); + virtual bool isDead(); + virtual ~FurnaceGUIRender(); +}; + class FurnaceGUI { DivEngine* e; + FurnaceGUIRenderBackend renderBackend; + FurnaceGUIRender* rend; + SDL_Window* sdlWin; - SDL_Renderer* sdlRend; SDL_Haptic* vibrator; bool vibratorAvailable; - - SDL_Texture* sampleTex; + + FurnaceGUITexture* sampleTex; int sampleTexW, sampleTexH; bool updateSampleTex; @@ -1241,11 +1303,12 @@ class FurnaceGUI { bool quit, warnQuit, willCommit, edit, modified, displayError, displayExporting, vgmExportLoop, zsmExportLoop, vgmExportPatternHints; bool vgmExportDirectStream, displayInsTypeList; - bool portrait, injectBackUp, mobileMenuOpen; + bool portrait, injectBackUp, mobileMenuOpen, warnColorPushed; bool wantCaptureKeyboard, oldWantCaptureKeyboard, displayMacroMenu; bool displayNew, fullScreen, preserveChanPos, wantScrollList, noteInputPoly; bool displayPendingIns, pendingInsSingle, displayPendingRawSample, snesFilterHex, modTableHex, displayEditString; bool mobileEdit; + bool killGraphics; bool willExport[DIV_MAX_CHIPS]; int vgmExportVersion; int vgmExportTrailingTicks; @@ -1447,6 +1510,11 @@ class FurnaceGUI { int orderButtonPos; int compress; int newPatternFormat; + int renderClearPos; + int insertBehavior; + int pullDeleteRow; + int newSongBehavior; + int memUsageUnit; unsigned int maxUndoSteps; String mainFontPath; String patFontPath; @@ -1454,6 +1522,7 @@ class FurnaceGUI { String midiInDevice; String midiOutDevice; String c163Name; + String renderBackend; String renderDriver; String initialSysName; String noteOffLabel; @@ -1594,6 +1663,11 @@ class FurnaceGUI { orderButtonPos(2), compress(1), newPatternFormat(1), + renderClearPos(0), + insertBehavior(1), + pullDeleteRow(1), + newSongBehavior(0), + memUsageUnit(1), maxUndoSteps(100), mainFontPath(""), patFontPath(""), @@ -1601,6 +1675,7 @@ class FurnaceGUI { midiInDevice(""), midiOutDevice(""), c163Name(""), + renderBackend(""), renderDriver(""), initialSysName("Sega Genesis/Mega Drive"), noteOffLabel("OFF"), @@ -1808,6 +1883,7 @@ class FurnaceGUI { int layoutTimeBegin, layoutTimeEnd, layoutTimeDelta; int renderTimeBegin, renderTimeEnd, renderTimeDelta; + int drawTimeBegin, drawTimeEnd, drawTimeDelta; int eventTimeBegin, eventTimeEnd, eventTimeDelta; FurnaceGUIPerfMetric perfMetrics[64]; @@ -1883,11 +1959,12 @@ class FurnaceGUI { // per-channel oscilloscope int chanOscCols, chanOscColorX, chanOscColorY; - float chanOscWindowSize; - bool chanOscWaveCorr, chanOscOptions, updateChanOscGradTex, chanOscUseGrad; - ImVec4 chanOscColor; + float chanOscWindowSize, chanOscTextX, chanOscTextY, chanOscAmplify; + bool chanOscWaveCorr, chanOscOptions, updateChanOscGradTex, chanOscUseGrad, chanOscNormalize; + String chanOscTextFormat; + ImVec4 chanOscColor, chanOscTextColor; Gradient2D chanOscGrad; - SDL_Texture* chanOscGradTex; + FurnaceGUITexture* chanOscGradTex; float chanOscLP0[DIV_MAX_CHANS]; float chanOscLP1[DIV_MAX_CHANS]; float chanOscVol[DIV_MAX_CHANS]; @@ -1939,6 +2016,7 @@ class FurnaceGUI { bool pianoOptions, pianoSharePosition, pianoOptionsSet; float pianoKeyHit[180]; bool pianoKeyPressed[180]; + bool pianoReadonly; int pianoOffset, pianoOffsetEdit; int pianoView, pianoInputPadMode; @@ -1973,7 +2051,7 @@ class FurnaceGUI { double monitorPos; int mustClear; float initialScreenWipe; - bool introSkipDo; + bool introSkipDo, introStopped; ImVec2 introMin, introMax; // tutorial @@ -2015,6 +2093,13 @@ class FurnaceGUI { void pushAccentColors(const ImVec4& one, const ImVec4& two, const ImVec4& border, const ImVec4& borderShadow); void popAccentColors(); + void pushDestColor(); + void popDestColor(); + void pushWarningColor(bool warnCond, bool errorCond=false); + void popWarningColor(); + + void sameLineMaybe(float width=-1.0f); + float calcBPM(const DivGroovePattern& speeds, float hz, int vN, int vD); void patternRow(int i, bool isPlaying, float lineHeight, int chans, int ord, const DivPattern** patCache, bool inhibitSel); @@ -2040,7 +2125,7 @@ class FurnaceGUI { void highlightWindow(const char* winName); FurnaceGUIImage* getImage(FurnaceGUIImages image); - SDL_Texture* getTexture(FurnaceGUIImages image, SDL_BlendMode blendMode=SDL_BLENDMODE_BLEND); + FurnaceGUITexture* getTexture(FurnaceGUIImages image, FurnaceGUIBlendMode blendMode=GUI_BLEND_MODE_BLEND); void drawImage(ImDrawList* dl, FurnaceGUIImages image, const ImVec2& pos, const ImVec2& scale, double rotate, const ImVec2& uvMin, const ImVec2& uvMax, const ImVec4& imgColor); void drawMobileControls(); @@ -2189,6 +2274,9 @@ class FurnaceGUI { String encodeKeyMap(std::map& map); void decodeKeyMap(std::map& map, String source); + bool initRender(); + bool quitRender(); + const char* getSystemName(DivSystem which); public: diff --git a/src/gui/guiConst.cpp b/src/gui/guiConst.cpp index 2989ae72..25364d2d 100644 --- a/src/gui/guiConst.cpp +++ b/src/gui/guiConst.cpp @@ -506,7 +506,7 @@ const FurnaceGUIActionDef guiActions[GUI_ACTION_MAX]={ D("WINDOW_ABOUT", "About", 0), D("WINDOW_SETTINGS", "Settings", 0), D("WINDOW_MIXER", "Mixer", 0), - D("WINDOW_DEBUG", "Debug Menu", 0), + D("WINDOW_DEBUG", "Debug Menu", FURKMOD_CMD|FURKMOD_SHIFT|SDLK_d), D("WINDOW_OSCILLOSCOPE", "Oscilloscope (master)", 0), D("WINDOW_VOL_METER", "Volume Meter", 0), D("WINDOW_STATS", "Statistics", 0), @@ -742,6 +742,9 @@ const FurnaceGUIColorDef guiColors[GUI_COLOR_MAX]={ D(GUI_COLOR_TOGGLE_ON,"",ImVec4(0.2f,0.6f,0.2f,1.0f)), D(GUI_COLOR_EDITING,"",ImVec4(0.2f,0.1f,0.1f,1.0f)), D(GUI_COLOR_SONG_LOOP,"",ImVec4(0.3f,0.5f,0.8f,0.4f)), + D(GUI_COLOR_DESTRUCTIVE,"",ImVec4(1.0f,0.2f,0.2f,1.0f)), + D(GUI_COLOR_WARNING,"",ImVec4(0.98f,0.98f,0.06f,1.0f)), + D(GUI_COLOR_ERROR,"",ImVec4(0.98f,0.06f,0.11f,1.0f)), D(GUI_COLOR_FILE_DIR,"",ImVec4(0.0f,1.0f,1.0f,1.0f)), D(GUI_COLOR_FILE_SONG_NATIVE,"",ImVec4(0.5f,1.0f,0.5f,1.0f)), diff --git a/src/gui/image.cpp b/src/gui/image.cpp index 976504b8..493b5a57 100644 --- a/src/gui/image.cpp +++ b/src/gui/image.cpp @@ -15,9 +15,6 @@ * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * this license only applies to the code. for the license of each font used, - * see `papers/`. */ #include "gui.h" @@ -49,7 +46,7 @@ const unsigned int imageLen[GUI_IMAGE_MAX]={ image_pat_size }; -SDL_Texture* FurnaceGUI::getTexture(FurnaceGUIImages image, SDL_BlendMode blendMode) { +FurnaceGUITexture* FurnaceGUI::getTexture(FurnaceGUIImages image, FurnaceGUIBlendMode blendMode) { FurnaceGUIImage* img=getImage(image); if (img==NULL) return NULL; @@ -57,14 +54,14 @@ SDL_Texture* FurnaceGUI::getTexture(FurnaceGUIImages image, SDL_BlendMode blendM if (img->width<=0 || img->height<=0) return NULL; if (img->tex==NULL) { - img->tex=SDL_CreateTexture(sdlRend,SDL_PIXELFORMAT_ABGR8888,SDL_TEXTUREACCESS_STATIC,img->width,img->height); + img->tex=rend->createTexture(false,img->width,img->height); if (img->tex==NULL) { logE("error while creating image %d texture! %s",(int)image,SDL_GetError()); return NULL; } - SDL_SetTextureBlendMode(img->tex,blendMode); + rend->setTextureBlendMode(img->tex,blendMode); - if (SDL_UpdateTexture(img->tex,NULL,img->data,img->width*4)!=0) { + if (!rend->updateTexture(img->tex,img->data,img->width*4)) { logE("error while updating texture of image %d! %s",(int)image,SDL_GetError()); } } diff --git a/src/gui/insEdit.cpp b/src/gui/insEdit.cpp index e02f3969..f0de1c61 100644 --- a/src/gui/insEdit.cpp +++ b/src/gui/insEdit.cpp @@ -59,79 +59,79 @@ const char* opllVariants[4]={ const char* opllInsNames[4][17]={ /* YM2413 */ { "User", - "Violin", - "Guitar", - "Piano", - "Flute", - "Clarinet", - "Oboe", - "Trumpet", - "Organ", - "Horn", - "Synth", - "Harpsichord", - "Vibraphone", - "Synth Bass", - "Acoustic Bass", - "Electric Guitar", + "1. Violin", + "2. Guitar", + "3. Piano", + "4. Flute", + "5. Clarinet", + "6. Oboe", + "7. Trumpet", + "8. Organ", + "9. Horn", + "10. Synth", + "11. Harpsichord", + "12. Vibraphone", + "13. Synth Bass", + "14. Acoustic Bass", + "15. Electric Guitar", "Drums" }, /* YMF281 */ { "User", - "Electric String", - "Bow wow", - "Electric Guitar", - "Organ", - "Clarinet", - "Saxophone", - "Trumpet", - "Street Organ", - "Synth Brass", - "Electric Piano", - "Bass", - "Vibraphone", - "Chime", - "Tom Tom II", - "Noise", + "1. Electric String", + "2. Bow wow", + "3. Electric Guitar", + "4. Organ", + "5. Clarinet", + "6. Saxophone", + "7. Trumpet", + "8. Street Organ", + "9. Synth Brass", + "10. Electric Piano", + "11. Bass", + "12. Vibraphone", + "13. Chime", + "14. Tom Tom II", + "15. Noise", "Drums" }, /* YM2423 */ { "User", - "Strings", - "Guitar", - "Electric Guitar", - "Electric Piano", - "Flute", - "Marimba", - "Trumpet", - "Harmonica", - "Tuba", - "Synth Brass", - "Short Saw", - "Vibraphone", - "Electric Guitar 2", - "Synth Bass", - "Sitar", + "1. Strings", + "2. Guitar", + "3. Electric Guitar", + "4. Electric Piano", + "5. Flute", + "6. Marimba", + "7. Trumpet", + "8. Harmonica", + "9. Tuba", + "10. Synth Brass", + "11. Short Saw", + "12. Vibraphone", + "13. Electric Guitar 2", + "14. Synth Bass", + "15. Sitar", "Drums" }, // stolen from FamiTracker /* VRC7 */ { "User", - "Bell", - "Guitar", - "Piano", - "Flute", - "Clarinet", - "Rattling Bell", - "Trumpet", - "Reed Organ", - "Soft Bell", - "Xylophone", - "Vibraphone", - "Brass", - "Bass Guitar", - "Synth", - "Chorus", + "1. Bell", + "2. Guitar", + "3. Piano", + "4. Flute", + "5. Clarinet", + "6. Rattling Bell", + "7. Trumpet", + "8. Reed Organ", + "9. Soft Bell", + "10. Xylophone", + "11. Vibraphone", + "12. Brass", + "13. Bass Guitar", + "14. Synth", + "15. Chorus", "Drums" } }; @@ -2262,9 +2262,11 @@ void FurnaceGUI::drawInsEdit() { ImGui::TableNextColumn(); ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); + ImGui::PushID(2+curIns); if (ImGui::InputText("##Name",&ins->name)) { MARK_MODIFIED; } + ImGui::PopID(); ImGui::TableNextRow(); ImGui::TableNextColumn(); diff --git a/src/gui/intro.cpp b/src/gui/intro.cpp index 73f1cac1..bace1439 100644 --- a/src/gui/intro.cpp +++ b/src/gui/intro.cpp @@ -19,12 +19,13 @@ #define _USE_MATH_DEFINES #include "gui.h" +#include "../ta-log.h" #include "imgui_internal.h" #include void FurnaceGUI::drawImage(ImDrawList* dl, FurnaceGUIImages image, const ImVec2& pos, const ImVec2& scale, double rotate, const ImVec2& uvMin, const ImVec2& uvMax, const ImVec4& imgColor) { FurnaceGUIImage* imgI=getImage(image); - SDL_Texture* img=getTexture(image); + FurnaceGUITexture* img=getTexture(image); float squareSize=MAX(introMax.x-introMin.x,introMax.y-introMin.y); float uDiff=uvMax.x-uvMin.x; @@ -69,10 +70,12 @@ void FurnaceGUI::drawImage(ImDrawList* dl, FurnaceGUIImages image, const ImVec2& ImU32 colorConverted=ImGui::GetColorU32(imgColor); - dl->AddImageQuad(img,quad0,quad1,quad2,quad3,uv0,uv1,uv2,uv3,colorConverted); + dl->AddImageQuad(rend->getTextureID(img),quad0,quad1,quad2,quad3,uv0,uv1,uv2,uv3,colorConverted); } void FurnaceGUI::endIntroTune() { + if (introStopped) return; + logV("ending intro"); stop(); if (curFileName.empty()) { e->createNewFromDefaults(); @@ -95,6 +98,8 @@ void FurnaceGUI::endIntroTune() { selEnd=SelectionPoint(); cursor=SelectionPoint(); updateWindowTitle(); + updateScroll(0); + introStopped=true; } void FurnaceGUI::drawIntro(double introTime, bool monitor) { @@ -162,7 +167,7 @@ void FurnaceGUI::drawIntro(double introTime, bool monitor) { getTexture(GUI_IMAGE_TALOGO); getTexture(GUI_IMAGE_TACHIP); getTexture(GUI_IMAGE_LOGO); - getTexture(GUI_IMAGE_INTROBG,SDL_BLENDMODE_ADD); + getTexture(GUI_IMAGE_INTROBG,GUI_BLEND_MODE_ADD); if (monitor) { ImVec2 textPos=ImLerp(top,bottom,ImVec2(0.5,0.5)); @@ -290,7 +295,7 @@ void FurnaceGUI::drawIntro(double introTime, bool monitor) { if (introSkipDo) { introSkip+=ImGui::GetIO().DeltaTime; if (introSkip>=0.5) { - if (e->isPlaying()) endIntroTune(); + if (!shortIntro) endIntroTune(); introPos=0.1; if (introSkip>=0.75) introPos=12.0; } @@ -317,7 +322,7 @@ void FurnaceGUI::drawIntro(double introTime, bool monitor) { e->setRepeatPattern(false); play(); } - if (e->isPlaying() && introPos>=10.0 && !shortIntro) endIntroTune(); + if (introPos>=10.0 && !shortIntro) endIntroTune(); introPos+=ImGui::GetIO().DeltaTime; if (introPos>=(shortIntro?1.0:11.0)) { introPos=12.0; @@ -325,5 +330,7 @@ void FurnaceGUI::drawIntro(double introTime, bool monitor) { commitTutorial(); } } + } else if (!shortIntro) { + endIntroTune(); } } diff --git a/src/gui/pattern.cpp b/src/gui/pattern.cpp index 55498404..a34a856d 100644 --- a/src/gui/pattern.cpp +++ b/src/gui/pattern.cpp @@ -49,11 +49,11 @@ void _popPartBlend(const ImDrawList* drawList, const ImDrawCmd* cmd) { } void FurnaceGUI::pushPartBlend() { - SDL_SetRenderDrawBlendMode(sdlRend,SDL_BLENDMODE_ADD); + rend->setBlendMode(GUI_BLEND_MODE_ADD); } void FurnaceGUI::popPartBlend() { - SDL_SetRenderDrawBlendMode(sdlRend,SDL_BLENDMODE_BLEND); + rend->setBlendMode(GUI_BLEND_MODE_BLEND); } // draw a pattern row @@ -287,7 +287,7 @@ inline void FurnaceGUI::patternRow(int i, bool isPlaying, float lineHeight, int if (pat->data[i][index]>0xff) { snprintf(id,63,"??##PE%d_%d_%d",k,i,j); ImGui::PushStyleColor(ImGuiCol_Text,uiColors[GUI_COLOR_PATTERN_EFFECT_INVALID]); - } else if (pat->data[i][index]>0x10 || settings.oneDigitEffects==0) { + } else if (pat->data[i][index]>=0x10 || settings.oneDigitEffects==0) { const unsigned char data=pat->data[i][index]; snprintf(id,63,"%.2X##PE%d_%d_%d",data,k,i,j); ImGui::PushStyleColor(ImGuiCol_Text,uiColors[fxColors[data]]); diff --git a/src/gui/piano.cpp b/src/gui/piano.cpp index baae316d..4842d05c 100644 --- a/src/gui/piano.cpp +++ b/src/gui/piano.cpp @@ -123,6 +123,7 @@ void FurnaceGUI::drawPiano() { pianoInputPadMode=PIANO_INPUT_PAD_SPLIT_VISIBLE; } ImGui::Checkbox("Share play/edit offset/range",&pianoSharePosition); + ImGui::Checkbox("Read-only (can't input notes)",&pianoReadonly); ImGui::EndPopup(); } @@ -223,7 +224,7 @@ void FurnaceGUI::drawPiano() { //ImGui::ItemSize(size,ImGui::GetStyle().FramePadding.y); if (ImGui::ItemAdd(rect,ImGui::GetID("pianoDisplay"))) { bool canInput=false; - if (ImGui::ItemHoverable(rect,ImGui::GetID("pianoDisplay"))) { + if (!pianoReadonly && ImGui::ItemHoverable(rect,ImGui::GetID("pianoDisplay"))) { canInput=true; ImGui::InhibitInertialScroll(); } diff --git a/src/gui/plot_nolerp.cpp b/src/gui/plot_nolerp.cpp index 2fd7994b..e6c3989e 100644 --- a/src/gui/plot_nolerp.cpp +++ b/src/gui/plot_nolerp.cpp @@ -19,11 +19,11 @@ // portions based on imgui_widgets.cpp -#include "plot_nolerp.h" -#include "imgui.h" #ifndef IMGUI_DEFINE_MATH_OPERATORS #define IMGUI_DEFINE_MATH_OPERATORS #endif +#include "plot_nolerp.h" +#include "imgui.h" #include "imgui_internal.h" struct FurnacePlotArrayGetterData diff --git a/src/gui/presets.cpp b/src/gui/presets.cpp index 1262b453..12b77ceb 100644 --- a/src/gui/presets.cpp +++ b/src/gui/presets.cpp @@ -822,10 +822,15 @@ void FurnaceGUI::initSystemPresets() { } ); ENTRY( - "ZX Spectrum (48K)", { + "ZX Spectrum (48K, SFX-like engine)", { CH(DIV_SYSTEM_SFX_BEEPER, 1.0f, 0, "") } ); + ENTRY( + "ZX Spectrum (48K, QuadTone engine)", { + CH(DIV_SYSTEM_SFX_BEEPER_QUADTONE, 1.0f, 0, "") + } + ); ENTRY( "ZX Spectrum (128K)", { CH(DIV_SYSTEM_AY8910, 1.0f, 0, "clockSel=1") //beeper was also included @@ -2594,10 +2599,15 @@ void FurnaceGUI::initSystemPresets() { } ); ENTRY( - "ZX Spectrum (beeper only)", { + "ZX Spectrum (beeper only, SFX-like engine)", { CH(DIV_SYSTEM_SFX_BEEPER, 1.0f, 0, "") } ); + ENTRY( + "ZX Spectrum (beeper only, QuadTone engine)", { + CH(DIV_SYSTEM_SFX_BEEPER_QUADTONE, 1.0f, 0, "") + } + ); ENTRY( "Sharp SM8521", { CH(DIV_SYSTEM_SM8521, 1.0f, 0, "") diff --git a/src/gui/render.cpp b/src/gui/render.cpp new file mode 100644 index 00000000..5ad753c2 --- /dev/null +++ b/src/gui/render.cpp @@ -0,0 +1,79 @@ +/** + * Furnace Tracker - multi-system chiptune tracker + * Copyright (C) 2021-2023 tildearrow and contributors + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "gui.h" +#include "../ta-log.h" +#ifdef HAVE_RENDER_SDL +#include "render/renderSDL.h" +#endif +#ifdef HAVE_RENDER_GL +#include "render/renderGL.h" +#endif +#ifdef HAVE_RENDER_DX11 +#include "render/renderDX11.h" +#endif + +bool FurnaceGUI::initRender() { + if (rend!=NULL) return false; + + if (settings.renderBackend=="OpenGL") { + renderBackend=GUI_BACKEND_GL; + } else if (settings.renderBackend=="DirectX 11") { + renderBackend=GUI_BACKEND_DX11; + } else if (settings.renderBackend=="SDL") { + renderBackend=GUI_BACKEND_SDL; + } else { + renderBackend=GUI_BACKEND_DEFAULT; + } + + switch (renderBackend) { +#ifdef HAVE_RENDER_GL + case GUI_BACKEND_GL: + logI("render backend: OpenGL"); + rend=new FurnaceGUIRenderGL; + break; +#endif +#ifdef HAVE_RENDER_DX11 + case GUI_BACKEND_DX11: + logI("render backend: DirectX 11"); + rend=new FurnaceGUIRenderDX11; + break; +#endif +#ifdef HAVE_RENDER_SDL + case GUI_BACKEND_SDL: + logI("render backend: SDL_Renderer"); + rend=new FurnaceGUIRenderSDL; + break; +#endif + default: + logE("invalid render backend!"); + return false; + break; + } + + return true; +} + +bool FurnaceGUI::quitRender() { + if (rend==NULL) return false; + bool ret=rend->quit(); + delete rend; + rend=NULL; + return ret; +} diff --git a/src/gui/render/abstract.cpp b/src/gui/render/abstract.cpp new file mode 100644 index 00000000..cf76ebbb --- /dev/null +++ b/src/gui/render/abstract.cpp @@ -0,0 +1,107 @@ +/** + * Furnace Tracker - multi-system chiptune tracker + * Copyright (C) 2021-2023 tildearrow and contributors + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "../gui.h" + +ImTextureID FurnaceGUIRender::getTextureID(FurnaceGUITexture* which) { + return NULL; +} + +bool FurnaceGUIRender::lockTexture(FurnaceGUITexture* which, void** data, int* pitch) { + return false; +} + +bool FurnaceGUIRender::unlockTexture(FurnaceGUITexture* which) { + return false; +} + +bool FurnaceGUIRender::updateTexture(FurnaceGUITexture* which, void* data, int pitch) { + return false; +} + +FurnaceGUITexture* FurnaceGUIRender::createTexture(bool dynamic, int width, int height) { + return NULL; +} + +bool FurnaceGUIRender::destroyTexture(FurnaceGUITexture* which) { + return false; +} + +void FurnaceGUIRender::setTextureBlendMode(FurnaceGUITexture* which, FurnaceGUIBlendMode mode) { +} + +void FurnaceGUIRender::setBlendMode(FurnaceGUIBlendMode mode) { +} + +void FurnaceGUIRender::resized(const SDL_Event& ev) { +} + +void FurnaceGUIRender::clear(ImVec4 color) { +} + +bool FurnaceGUIRender::newFrame() { + return true; +} + +void FurnaceGUIRender::createFontsTexture() { +} + +void FurnaceGUIRender::destroyFontsTexture() { +} + +void FurnaceGUIRender::renderGUI() { +} + +void FurnaceGUIRender::wipe(float alpha) { +} + +void FurnaceGUIRender::present() { +} + +bool FurnaceGUIRender::getOutputSize(int& w, int& h) { + return false; +} + +int FurnaceGUIRender::getWindowFlags() { + return 0; +} + +void FurnaceGUIRender::preInit() { +} + +bool FurnaceGUIRender::init(SDL_Window* win) { + return false; +} + +void FurnaceGUIRender::initGUI(SDL_Window* win) { +} + +bool FurnaceGUIRender::quit() { + return false; +} + +void FurnaceGUIRender::quitGUI() { +} + +bool FurnaceGUIRender::isDead() { + return false; +} + +FurnaceGUIRender::~FurnaceGUIRender() { +} diff --git a/src/gui/render/renderDX11.cpp b/src/gui/render/renderDX11.cpp new file mode 100644 index 00000000..d3bd1306 --- /dev/null +++ b/src/gui/render/renderDX11.cpp @@ -0,0 +1,570 @@ +/** + * Furnace Tracker - multi-system chiptune tracker + * Copyright (C) 2021-2023 tildearrow and contributors + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#define INCLUDE_D3D11 +#include "renderDX11.h" +#include +#include "backends/imgui_impl_dx11.h" +#include "../../ta-log.h" + +typedef HRESULT (__stdcall *D3DCompile_t)(LPCVOID,SIZE_T,LPCSTR,D3D_SHADER_MACRO*,ID3DInclude*,LPCSTR,LPCSTR,UINT,UINT,ID3DBlob**,ID3DBlob*); + +const char* shD3D11_wipe_srcV= + "cbuffer WipeUniform: register(b0) {\n" + " float alpha;\n" + " float padding1;\n" + " float padding2;\n" + " float padding3;\n" + " float4 padding4;\n" + "};\n" + "\n" + "struct vsInput {\n" + " float4 pos: POSITION;\n" + "};\n" + "\n" + "struct fsInput {\n" + " float4 pos: SV_POSITION;\n" + " float4 color: COLOR0;\n" + "};\n" + "\n" + "fsInput main(vsInput input) {\n" + " fsInput output;\n" + " output.pos=input.pos;\n" + " output.color=float4(0.0f,0.0f,0.0f,alpha);\n" + " return output;\n" + "}"; + +const char* shD3D11_wipe_srcF= + "struct fsInput {\n" + " float4 pos: SV_POSITION;\n" + " float4 color: COLOR0;\n" + "};\n" + "\n" + "float4 main(fsInput input): SV_Target {\n" + " return input.color;\n" + "}"; + +const D3D11_INPUT_ELEMENT_DESC shD3D11_wipe_inputLayout={ + "POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 +}; + +const D3D_FEATURE_LEVEL possibleFeatureLevels[2]={ + D3D_FEATURE_LEVEL_11_0, + D3D_FEATURE_LEVEL_10_0 +}; + +class FurnaceDXTexture: public FurnaceGUITexture { + public: + ID3D11Texture2D* tex; + ID3D11ShaderResourceView* view; + int width, height; + unsigned char* lockedData; + bool dynamic; + FurnaceDXTexture(): + tex(NULL), + view(NULL), + width(0), + height(0), + lockedData(NULL), + dynamic(false) {} +}; + +bool FurnaceGUIRenderDX11::destroyRenderTarget() { + if (renderTarget!=NULL) { + renderTarget->Release(); + renderTarget=NULL; + return true; + } + return false; +} + +bool FurnaceGUIRenderDX11::createRenderTarget() { + ID3D11Texture2D* screen=NULL; + HRESULT result; + + destroyRenderTarget(); + + if (swapchain==NULL || device==NULL) { + logW("createRenderTarget: swapchain or device are NULL!"); + return false; + } + + DXGI_SWAP_CHAIN_DESC chainDesc; + memset(&chainDesc,0,sizeof(chainDesc)); + if (swapchain->GetDesc(&chainDesc)!=S_OK) { + logW("createRenderTarget: could not get swapchain desc!"); + } else { + outW=chainDesc.BufferDesc.Width; + outH=chainDesc.BufferDesc.Height; + logI("DX11: buffer desc sizes: %d, %d",chainDesc.BufferDesc.Width,chainDesc.BufferDesc.Height); + } + + result=swapchain->GetBuffer(0,IID_PPV_ARGS(&screen)); + if (result!=S_OK) { + logW("createRenderTarget: could not get buffer! %.8x",result); + return false; + } + if (screen==NULL) { + logW("createRenderTarget: screen is null!"); + return false; + } + + result=device->CreateRenderTargetView(screen,NULL,&renderTarget); + if (result!=S_OK) { + logW("createRenderTarget: could not create render target view! %.8x",result); + screen->Release(); + return false; + } + if (renderTarget==NULL) { + logW("createRenderTarget: what the hell the render target is null?"); + screen->Release(); + return false; + } + + screen->Release(); + return true; +} + +ImTextureID FurnaceGUIRenderDX11::getTextureID(FurnaceGUITexture* which) { + FurnaceDXTexture* t=(FurnaceDXTexture*)which; + return (ImTextureID)t->view; +} + +bool FurnaceGUIRenderDX11::lockTexture(FurnaceGUITexture* which, void** data, int* pitch) { + FurnaceDXTexture* t=(FurnaceDXTexture*)which; + if (t->lockedData!=NULL) return false; + + D3D11_MAPPED_SUBRESOURCE mappedRes; + memset(&mappedRes,0,sizeof(mappedRes)); + + HRESULT result=context->Map(t->tex,D3D11CalcSubresource(0,0,1),D3D11_MAP_WRITE_DISCARD,0,&mappedRes); + if (result!=S_OK) { + logW("could not map texture! %.8x",result); + return false; + } + t->lockedData=(unsigned char*)mappedRes.pData; + *data=mappedRes.pData; + *pitch=mappedRes.RowPitch; + + logV("texture locked... pitch: %d",mappedRes.RowPitch); + return true; +} + +bool FurnaceGUIRenderDX11::unlockTexture(FurnaceGUITexture* which) { + FurnaceDXTexture* t=(FurnaceDXTexture*)which; + if (t->lockedData==NULL) return false; + context->Unmap(t->tex,D3D11CalcSubresource(0,0,1)); + t->lockedData=NULL; + return true; +} + +bool FurnaceGUIRenderDX11::updateTexture(FurnaceGUITexture* which, void* data, int pitch) { + FurnaceDXTexture* t=(FurnaceDXTexture*)which; + if (t->dynamic) { + unsigned char* d=NULL; + int p=0; + if (!lockTexture(t,(void**)&d,&p)) return false; + if (p==pitch) { + memcpy(d,data,p*t->height); + } else { + unsigned char* ucData=(unsigned char*)data; + int srcPos=0; + int destPos=0; + for (int i=0; iheight; i++) { + memcpy(&d[destPos],&ucData[srcPos],pitch); + srcPos+=pitch; + destPos+=p; + } + } + unlockTexture(t); + } else { + context->UpdateSubresource(t->tex,D3D11CalcSubresource(0,0,1),NULL,data,pitch,pitch*t->height); + } + return true; +} + +FurnaceGUITexture* FurnaceGUIRenderDX11::createTexture(bool dynamic, int width, int height) { + D3D11_TEXTURE2D_DESC texDesc; + D3D11_SHADER_RESOURCE_VIEW_DESC viewDesc; + ID3D11Texture2D* tex=NULL; + ID3D11ShaderResourceView* view=NULL; + HRESULT result; + + memset(&texDesc,0,sizeof(texDesc)); + memset(&viewDesc,0,sizeof(viewDesc)); + + texDesc.Width=width; + texDesc.Height=height; + texDesc.MipLevels=1; + texDesc.ArraySize=1; + texDesc.Format=DXGI_FORMAT_R8G8B8A8_UNORM; // ??? + texDesc.SampleDesc.Count=1; + texDesc.SampleDesc.Quality=0; + texDesc.Usage=dynamic?D3D11_USAGE_DYNAMIC:D3D11_USAGE_DEFAULT; + texDesc.BindFlags=D3D11_BIND_SHADER_RESOURCE; + texDesc.CPUAccessFlags=dynamic?D3D11_CPU_ACCESS_WRITE:0; + texDesc.MiscFlags=0; + + result=device->CreateTexture2D(&texDesc,NULL,&tex); + if (result!=S_OK) { + logW("could not create texture! %.8x",result); + return NULL; + } + + viewDesc.Format=texDesc.Format=texDesc.Format; + viewDesc.ViewDimension=D3D11_SRV_DIMENSION_TEXTURE2D; + viewDesc.Texture2D.MostDetailedMip=0; + viewDesc.Texture2D.MipLevels=texDesc.MipLevels; + + result=device->CreateShaderResourceView(tex,&viewDesc,&view); + if (result!=S_OK) { + logW("could not create texture view! %.8x",result); + tex->Release(); + return NULL; + } + + FurnaceDXTexture* ret=new FurnaceDXTexture; + ret->width=width; + ret->height=height; + ret->tex=tex; + ret->view=view; + ret->dynamic=dynamic; + return ret; +} + +bool FurnaceGUIRenderDX11::destroyTexture(FurnaceGUITexture* which) { + FurnaceDXTexture* t=(FurnaceDXTexture*)which; + t->view->Release(); + t->tex->Release(); + delete t; + return true; +} + +void FurnaceGUIRenderDX11::setTextureBlendMode(FurnaceGUITexture* which, FurnaceGUIBlendMode mode) { +} + +void FurnaceGUIRenderDX11::setBlendMode(FurnaceGUIBlendMode mode) { +} + +void FurnaceGUIRenderDX11::resized(const SDL_Event& ev) { + destroyRenderTarget(); + logI("DX11: resizing buffers"); + HRESULT result=swapchain->ResizeBuffers(0,(unsigned int)ev.window.data1,(unsigned int)ev.window.data2,DXGI_FORMAT_UNKNOWN,DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH); + if (result!=S_OK) { + if (result==DXGI_ERROR_DEVICE_REMOVED || result==DXGI_ERROR_DEVICE_RESET) { + dead=true; + } + logW("error while resizing swapchain buffers! %.8x",result); + } + if (!dead) { + createRenderTarget(); + } +} + +void FurnaceGUIRenderDX11::clear(ImVec4 color) { + float floatColor[4]={ + color.x*color.w, + color.y*color.w, + color.z*color.w, + color.w, + }; + + context->OMSetRenderTargets(1,&renderTarget,NULL); + context->ClearRenderTargetView(renderTarget,floatColor); +} + +bool FurnaceGUIRenderDX11::newFrame() { + ImGui_ImplDX11_NewFrame(); + return true; +} + +void FurnaceGUIRenderDX11::createFontsTexture() { + ImGui_ImplDX11_CreateDeviceObjects(); +} + +void FurnaceGUIRenderDX11::destroyFontsTexture() { + ImGui_ImplDX11_InvalidateDeviceObjects(); +} + +void FurnaceGUIRenderDX11::renderGUI() { + ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData()); +} + +const float blendFactor[4]={ + 1.0f, 1.0f, 1.0f, 1.0f +}; + +void FurnaceGUIRenderDX11::wipe(float alpha) { + D3D11_VIEWPORT viewPort; + unsigned int strides=4*sizeof(float); + unsigned int offsets=0; + + memset(&viewPort,0,sizeof(viewPort)); + viewPort.TopLeftX=0.0f; + viewPort.TopLeftY=0.0f; + viewPort.Width=outW; + viewPort.Height=outH; + viewPort.MinDepth=0.0f; + viewPort.MaxDepth=1.0f; + + D3D11_MAPPED_SUBRESOURCE mappedUniform; + if (context->Map(sh_wipe_uniform,0,D3D11_MAP_WRITE_DISCARD,0,&mappedUniform)!=S_OK) { + logW("could not map constant"); + } + WipeUniform* sh_wipe_uniformState=(WipeUniform*)mappedUniform.pData; + sh_wipe_uniformState->alpha=alpha; + context->Unmap(sh_wipe_uniform,0); + + context->RSSetViewports(1,&viewPort); + context->RSSetState(rsState); + + context->OMSetBlendState(omBlendState,blendFactor,0xffffffff); + context->IASetInputLayout(sh_wipe_inputLayout); + context->IASetVertexBuffers(0,1,&quadVertex,&strides,&offsets); + context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); + context->VSSetShader(sh_wipe_vertex,NULL,0); + context->VSSetConstantBuffers(0,1,&sh_wipe_uniform); + context->PSSetShader(sh_wipe_fragment,NULL,0); + + context->Draw(4,0); +} + +void FurnaceGUIRenderDX11::present() { + HRESULT result=swapchain->Present(1,0); + if (result==DXGI_ERROR_DEVICE_REMOVED || result==DXGI_ERROR_DEVICE_RESET) { + dead=true; + } else if (result!=S_OK && result!=DXGI_STATUS_OCCLUDED) { + logE("DX11: present failed! %.8x",result); + } +} + +bool FurnaceGUIRenderDX11::getOutputSize(int& w, int& h) { + w=outW; + h=outH; + return true; +} + +int FurnaceGUIRenderDX11::getWindowFlags() { + return 0; +} + +void FurnaceGUIRenderDX11::preInit() { +} + +const float wipeVertices[4][4]={ + {-1.0, -1.0, 0.0, 1.0}, + { 1.0, -1.0, 0.0, 1.0}, + {-1.0, 1.0, 0.0, 1.0}, + { 1.0, 1.0, 0.0, 1.0} +}; + +bool FurnaceGUIRenderDX11::init(SDL_Window* win) { + SDL_SysWMinfo sysWindow; + D3D_FEATURE_LEVEL featureLevel; + + SDL_VERSION(&sysWindow.version); + if (SDL_GetWindowWMInfo(win,&sysWindow)==SDL_FALSE) { + logE("could not get window WM info! %s",SDL_GetError()); + return false; + } + HWND window=(HWND)sysWindow.info.win.window; + + DXGI_SWAP_CHAIN_DESC chainDesc; + memset(&chainDesc,0,sizeof(chainDesc)); + chainDesc.BufferDesc.Width=0; + chainDesc.BufferDesc.Height=0; + chainDesc.BufferDesc.Format=DXGI_FORMAT_R8G8B8A8_UNORM; + chainDesc.BufferDesc.RefreshRate.Numerator=60; + chainDesc.BufferDesc.RefreshRate.Denominator=1; + chainDesc.SampleDesc.Count=1; + chainDesc.SampleDesc.Quality=0; + chainDesc.BufferUsage=DXGI_USAGE_RENDER_TARGET_OUTPUT; + chainDesc.BufferCount=2; + chainDesc.OutputWindow=window; + chainDesc.Windowed=TRUE; // TODO: what if we're in full screen mode? + chainDesc.SwapEffect=DXGI_SWAP_EFFECT_DISCARD; + chainDesc.Flags=DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH; + + HRESULT result=D3D11CreateDeviceAndSwapChain(NULL,D3D_DRIVER_TYPE_HARDWARE,NULL,0,possibleFeatureLevels,2,D3D11_SDK_VERSION,&chainDesc,&swapchain,&device,&featureLevel,&context); + if (result!=S_OK) { + logE("could not create device and/or swap chain! %.8x",result); + return false; + } + + // https://github.com/ocornut/imgui/pull/638 + D3DCompile_t D3DCompile=NULL; + char dllBuffer[20]; + for (int i=47; (i>30 && !D3DCompile); i--) { + snprintf(dllBuffer,20,"d3dcompiler_%d.dll",i); + HMODULE hDll=LoadLibraryA(dllBuffer); + if (hDll) { + D3DCompile=(D3DCompile_t)GetProcAddress(hDll,"D3DCompile"); + } + } + if (!D3DCompile) { + logE("could not find D3DCompile!"); + return false; + } + + // create wipe shader + ID3DBlob* wipeBlobV=NULL; + ID3DBlob* wipeBlobF=NULL; + D3D11_BUFFER_DESC wipeConstantDesc; + + result=D3DCompile(shD3D11_wipe_srcV,strlen(shD3D11_wipe_srcV),NULL,NULL,NULL,"main","vs_4_0",0,0,&wipeBlobV,NULL); + if (result!=S_OK) { + logE("could not compile vertex shader! %.8x",result); + return false; + } + result=D3DCompile(shD3D11_wipe_srcF,strlen(shD3D11_wipe_srcF),NULL,NULL,NULL,"main","ps_4_0",0,0,&wipeBlobF,NULL); + if (result!=S_OK) { + logE("could not compile pixel shader! %.8x",result); + return false; + } + + result=device->CreateVertexShader(wipeBlobV->GetBufferPointer(),wipeBlobV->GetBufferSize(),NULL,&sh_wipe_vertex); + if (result!=S_OK) { + logE("could not create vertex shader! %.8x",result); + return false; + } + result=device->CreatePixelShader(wipeBlobF->GetBufferPointer(),wipeBlobF->GetBufferSize(),NULL,&sh_wipe_fragment); + if (result!=S_OK) { + logE("could not create pixel shader! %.8x",result); + return false; + } + + result=device->CreateInputLayout(&shD3D11_wipe_inputLayout,1,wipeBlobV->GetBufferPointer(),wipeBlobV->GetBufferSize(),&sh_wipe_inputLayout); + if (result!=S_OK) { + logE("could not create input layout! %.8x",result); + return false; + } + + memset(&wipeConstantDesc,0,sizeof(wipeConstantDesc)); + wipeConstantDesc.ByteWidth=sizeof(WipeUniform); + wipeConstantDesc.Usage=D3D11_USAGE_DYNAMIC; + wipeConstantDesc.BindFlags=D3D11_BIND_CONSTANT_BUFFER; + wipeConstantDesc.CPUAccessFlags=D3D11_CPU_ACCESS_WRITE; + wipeConstantDesc.MiscFlags=0; + wipeConstantDesc.StructureByteStride=0; + + result=device->CreateBuffer(&wipeConstantDesc,NULL,&sh_wipe_uniform); + if (result!=S_OK) { + logE("could not create constant buffer! %.8x",result); + return false; + } + + // create wipe vertices + D3D11_BUFFER_DESC vertexDesc; + D3D11_SUBRESOURCE_DATA vertexRes; + + memset(&vertexDesc,0,sizeof(vertexDesc)); + memset(&vertexRes,0,sizeof(vertexRes)); + + vertexDesc.ByteWidth=4*4*sizeof(float); + vertexDesc.Usage=D3D11_USAGE_DEFAULT; + vertexDesc.BindFlags=D3D11_BIND_VERTEX_BUFFER; + vertexDesc.CPUAccessFlags=0; + vertexDesc.MiscFlags=0; + vertexDesc.StructureByteStride=0; + + vertexRes.pSysMem=wipeVertices; + vertexRes.SysMemPitch=0; + vertexRes.SysMemSlicePitch=0; + + result=device->CreateBuffer(&vertexDesc,&vertexRes,&quadVertex); + if (result!=S_OK) { + logE("could not create vertex buffer! %.8x",result); + return false; + } + + // initialize the rest + D3D11_RASTERIZER_DESC rasterDesc; + D3D11_BLEND_DESC blendDesc; + + memset(&rasterDesc,0,sizeof(rasterDesc)); + memset(&blendDesc,0,sizeof(blendDesc)); + + rasterDesc.FillMode=D3D11_FILL_SOLID; + rasterDesc.CullMode=D3D11_CULL_NONE; + rasterDesc.FrontCounterClockwise=false; + rasterDesc.DepthBias=0; + rasterDesc.DepthBiasClamp=0.0f; + rasterDesc.SlopeScaledDepthBias=0.0f; + rasterDesc.DepthClipEnable=false; + rasterDesc.ScissorEnable=false; + rasterDesc.MultisampleEnable=false; + rasterDesc.AntialiasedLineEnable=false; + result=device->CreateRasterizerState(&rasterDesc,&rsState); + if (result!=S_OK) { + logE("could not create rasterizer state! %.8x",result); + return false; + } + + blendDesc.AlphaToCoverageEnable=false; + blendDesc.IndependentBlendEnable=false; + blendDesc.RenderTarget[0].BlendEnable=true; + blendDesc.RenderTarget[0].SrcBlend=D3D11_BLEND_SRC_ALPHA; + blendDesc.RenderTarget[0].DestBlend=D3D11_BLEND_INV_SRC_ALPHA; + blendDesc.RenderTarget[0].BlendOp=D3D11_BLEND_OP_ADD; + blendDesc.RenderTarget[0].SrcBlendAlpha=D3D11_BLEND_ONE; + blendDesc.RenderTarget[0].DestBlendAlpha=D3D11_BLEND_INV_SRC_ALPHA; + blendDesc.RenderTarget[0].BlendOpAlpha=D3D11_BLEND_OP_ADD; + blendDesc.RenderTarget[0].RenderTargetWriteMask=D3D11_COLOR_WRITE_ENABLE_ALL; + result=device->CreateBlendState(&blendDesc,&omBlendState); + if (result!=S_OK) { + logE("could not create blend state! %.8x",result); + return false; + } + + createRenderTarget(); + return true; +} + +void FurnaceGUIRenderDX11::initGUI(SDL_Window* win) { + ImGui_ImplSDL2_InitForD3D(win); + ImGui_ImplDX11_Init(device,context); +} + +bool FurnaceGUIRenderDX11::quit() { + destroyRenderTarget(); + + if (swapchain!=NULL) { + swapchain->Release(); + swapchain=NULL; + } + if (context!=NULL) { + context->Release(); + context=NULL; + } + if (device!=NULL) { + device->Release(); + device=NULL; + } + + dead=false; + return true; +} + +void FurnaceGUIRenderDX11::quitGUI() { + ImGui_ImplDX11_Shutdown(); +} + +bool FurnaceGUIRenderDX11::isDead() { + return dead; +} diff --git a/src/gui/render/renderDX11.h b/src/gui/render/renderDX11.h new file mode 100644 index 00000000..39cc32df --- /dev/null +++ b/src/gui/render/renderDX11.h @@ -0,0 +1,103 @@ +/** + * Furnace Tracker - multi-system chiptune tracker + * Copyright (C) 2021-2023 tildearrow and contributors + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "../gui.h" +#ifdef INCLUDE_D3D11 +#include +#else +typedef void ID3D11DeviceContext; +typedef void ID3D11RenderTargetView; +typedef void ID3D11Buffer; +typedef void ID3D11RasterizerState; +typedef void ID3D11BlendState; +typedef void ID3D11VertexShader; +typedef void ID3D11PixelShader; +typedef void ID3D11InputLayout; +typedef void IDXGISwapChain; +#endif + +class FurnaceGUIRenderDX11: public FurnaceGUIRender { + ID3D11Device* device; + ID3D11DeviceContext* context; + ID3D11RenderTargetView* renderTarget; + IDXGISwapChain* swapchain; + ID3D11RasterizerState* rsState; + ID3D11BlendState* omBlendState; + + ID3D11Buffer* quadVertex; + int outW, outH; + + bool dead; + + // SHADERS // + // -> wipe + ID3D11VertexShader* sh_wipe_vertex; + ID3D11PixelShader* sh_wipe_fragment; + ID3D11InputLayout* sh_wipe_inputLayout; + ID3D11Buffer* sh_wipe_uniform; + struct WipeUniform { + float alpha; + float padding[7]; + }; + + bool destroyRenderTarget(); + bool createRenderTarget(); + + public: + ImTextureID getTextureID(FurnaceGUITexture* which); + bool lockTexture(FurnaceGUITexture* which, void** data, int* pitch); + bool unlockTexture(FurnaceGUITexture* which); + bool updateTexture(FurnaceGUITexture* which, void* data, int pitch); + FurnaceGUITexture* createTexture(bool dynamic, int width, int height); + bool destroyTexture(FurnaceGUITexture* which); + void setTextureBlendMode(FurnaceGUITexture* which, FurnaceGUIBlendMode mode); + void setBlendMode(FurnaceGUIBlendMode mode); + void resized(const SDL_Event& ev); + void clear(ImVec4 color); + bool newFrame(); + void createFontsTexture(); + void destroyFontsTexture(); + void renderGUI(); + void wipe(float alpha); + void present(); + bool getOutputSize(int& w, int& h); + int getWindowFlags(); + void preInit(); + bool init(SDL_Window* win); + void initGUI(SDL_Window* win); + void quitGUI(); + bool quit(); + bool isDead(); + FurnaceGUIRenderDX11(): + device(NULL), + context(NULL), + renderTarget(NULL), + swapchain(NULL), + rsState(NULL), + omBlendState(NULL), + quadVertex(NULL), + outW(0), + outH(0), + dead(false), + sh_wipe_vertex(NULL), + sh_wipe_fragment(NULL), + sh_wipe_inputLayout(NULL), + sh_wipe_uniform(NULL) { + } +}; diff --git a/src/gui/render/renderGL.cpp b/src/gui/render/renderGL.cpp new file mode 100644 index 00000000..b16f0497 --- /dev/null +++ b/src/gui/render/renderGL.cpp @@ -0,0 +1,402 @@ +/** + * Furnace Tracker - multi-system chiptune tracker + * Copyright (C) 2021-2023 tildearrow and contributors + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "renderGL.h" +#include "../../ta-log.h" +#ifdef USE_GLES +#include "SDL_opengles2.h" +#define PIXEL_FORMAT GL_UNSIGNED_BYTE +#else +#include "SDL_opengl.h" +#define PIXEL_FORMAT GL_UNSIGNED_INT_8_8_8_8_REV +#endif +#include "backends/imgui_impl_opengl3.h" + +#define C(x) x; if (glGetError()!=GL_NO_ERROR) logW("OpenGL error in %s:%d: " #x,__FILE__,__LINE__); + +PFNGLGENBUFFERSPROC furGenBuffers=NULL; +PFNGLBINDBUFFERPROC furBindBuffer=NULL; +PFNGLBUFFERDATAPROC furBufferData=NULL; +PFNGLVERTEXATTRIBPOINTERPROC furVertexAttribPointer=NULL; +PFNGLENABLEVERTEXATTRIBARRAYPROC furEnableVertexAttribArray=NULL; +PFNGLACTIVETEXTUREPROC furActiveTexture=NULL; + +PFNGLCREATESHADERPROC furCreateShader=NULL; +PFNGLSHADERSOURCEPROC furShaderSource=NULL; +PFNGLCOMPILESHADERPROC furCompileShader=NULL; +PFNGLGETSHADERIVPROC furGetShaderiv=NULL; +PFNGLATTACHSHADERPROC furAttachShader=NULL; +PFNGLBINDATTRIBLOCATIONPROC furBindAttribLocation=NULL; +PFNGLCREATEPROGRAMPROC furCreateProgram=NULL; +PFNGLLINKPROGRAMPROC furLinkProgram=NULL; +PFNGLGETPROGRAMIVPROC furGetProgramiv=NULL; +PFNGLUSEPROGRAMPROC furUseProgram=NULL; +PFNGLGETUNIFORMLOCATIONPROC furGetUniformLocation=NULL; +PFNGLUNIFORM1FPROC furUniform1f=NULL; +PFNGLGETSHADERINFOLOGPROC furGetShaderInfoLog=NULL; + +#ifndef USE_GLES +PFNGLGETGRAPHICSRESETSTATUSARBPROC furGetGraphicsResetStatusARB=NULL; +#endif + +class FurnaceGLTexture: public FurnaceGUITexture { + public: + GLuint id; + int width, height; + unsigned char* lockedData; + FurnaceGLTexture(): + id(0), + width(0), + height(0), + lockedData(NULL) {} +}; + +#ifdef USE_GLES +const char* sh_wipe_srcV= + "attribute vec4 fur_position;\n" + "void main() {\n" + " gl_Position=fur_position;\n" + "}\n"; + +const char* sh_wipe_srcF= + "uniform float uAlpha;\n" + "void main() {\n" + " gl_FragColor=vec4(0.0,0.0,0.0,uAlpha);\n" + "}\n"; +#else +const char* sh_wipe_srcV= + "#version 130\n" + "in vec4 fur_position;\n" + "void main() {\n" + " gl_Position=fur_position;\n" + "}\n"; + +const char* sh_wipe_srcF= + "#version 130\n" + "uniform float uAlpha;\n" + "out vec4 fur_FragColor;\n" + "void main() {\n" + " fur_FragColor=vec4(0.0,0.0,0.0,uAlpha);\n" + "}\n"; +#endif + +bool FurnaceGUIRenderGL::createShader(const char* vertexS, const char* fragmentS, int& vertex, int& fragment, int& program) { + int status; + char infoLog[4096]; + int infoLogLen; + + if (!furCreateShader || !furShaderSource || !furCompileShader || !furGetShaderiv || + !furGetShaderInfoLog || !furCreateProgram || !furAttachShader || !furLinkProgram || + !furBindAttribLocation || !furGetProgramiv) { + logW("I can't compile shaders"); + return false; + } + + vertex=furCreateShader(GL_VERTEX_SHADER); + furShaderSource(vertex,1,&vertexS,NULL); + furCompileShader(vertex); + furGetShaderiv(vertex,GL_COMPILE_STATUS,&status); + if (!status) { + logW("failed to compile vertex shader"); + furGetShaderInfoLog(vertex,4095,&infoLogLen,infoLog); + infoLog[infoLogLen]=0; + logW("%s",infoLog); + return false; + } + + fragment=furCreateShader(GL_FRAGMENT_SHADER); + furShaderSource(fragment,1,&fragmentS,NULL); + furCompileShader(fragment); + furGetShaderiv(fragment,GL_COMPILE_STATUS,&status); + if (!status) { + logW("failed to compile fragment shader"); + return false; + } + + program=furCreateProgram(); + furAttachShader(program,vertex); + furAttachShader(program,fragment); + furBindAttribLocation(program,0,"fur_position"); + furLinkProgram(program); + furGetProgramiv(program,GL_LINK_STATUS,&status); + if (!status) { + logW("failed to link shader!"); + return false; + } + + return true; +} + +ImTextureID FurnaceGUIRenderGL::getTextureID(FurnaceGUITexture* which) { + intptr_t ret=((FurnaceGLTexture*)which)->id; + return (ImTextureID)ret; +} + +bool FurnaceGUIRenderGL::lockTexture(FurnaceGUITexture* which, void** data, int* pitch) { + FurnaceGLTexture* t=(FurnaceGLTexture*)which; + if (t->lockedData!=NULL) return false; + t->lockedData=new unsigned char[t->width*t->height*4]; + + *data=t->lockedData; + *pitch=t->width*4; + return true; +} + +bool FurnaceGUIRenderGL::unlockTexture(FurnaceGUITexture* which) { + FurnaceGLTexture* t=(FurnaceGLTexture*)which; + if (t->lockedData==NULL) return false; + + C(glBindTexture(GL_TEXTURE_2D,t->id)); + C(glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,t->width,t->height,0,GL_RGBA,PIXEL_FORMAT,t->lockedData)); + + C(glFlush()); + delete[] t->lockedData; + t->lockedData=NULL; + + return true; +} + +bool FurnaceGUIRenderGL::updateTexture(FurnaceGUITexture* which, void* data, int pitch) { + FurnaceGLTexture* t=(FurnaceGLTexture*)which; + + if (t->width*4!=pitch) return false; + + C(glBindTexture(GL_TEXTURE_2D,t->id)); + C(glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,t->width,t->height,0,GL_RGBA,PIXEL_FORMAT,data)); + return true; +} + +FurnaceGUITexture* FurnaceGUIRenderGL::createTexture(bool dynamic, int width, int height) { + FurnaceGLTexture* t=new FurnaceGLTexture; + C(glGenTextures(1,&t->id)); + C(glBindTexture(GL_TEXTURE_2D,t->id)); + C(glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR)); + C(glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR)); + C(glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,width,height,0,GL_RGBA,PIXEL_FORMAT,NULL)); + C(furActiveTexture(GL_TEXTURE0)); + t->width=width; + t->height=height; + return t; +} + +bool FurnaceGUIRenderGL::destroyTexture(FurnaceGUITexture* which) { + FurnaceGLTexture* t=(FurnaceGLTexture*)which; + C(glDeleteTextures(1,&t->id)); + delete t; + return true; +} + +void FurnaceGUIRenderGL::setTextureBlendMode(FurnaceGUITexture* which, FurnaceGUIBlendMode mode) { +} + +void FurnaceGUIRenderGL::setBlendMode(FurnaceGUIBlendMode mode) { + switch (mode) { + case GUI_BLEND_MODE_NONE: + C(glBlendFunc(GL_ONE,GL_ZERO)); + C(glDisable(GL_BLEND)); + break; + case GUI_BLEND_MODE_BLEND: + C(glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA)); + C(glEnable(GL_BLEND)); + break; + case GUI_BLEND_MODE_ADD: + C(glBlendFunc(GL_SRC_ALPHA,GL_ONE)); + C(glEnable(GL_BLEND)); + break; + case GUI_BLEND_MODE_MULTIPLY: + C(glBlendFunc(GL_ZERO,GL_SRC_COLOR)); + C(glEnable(GL_BLEND)); + break; + } +} + +void FurnaceGUIRenderGL::clear(ImVec4 color) { + SDL_GL_MakeCurrent(sdlWin,context); + C(glClearColor(color.x,color.y,color.z,color.w)); + C(glClear(GL_COLOR_BUFFER_BIT)); +} + +bool FurnaceGUIRenderGL::newFrame() { + ImGui_ImplOpenGL3_NewFrame(); + return true; +} + +void FurnaceGUIRenderGL::createFontsTexture() { + ImGui_ImplOpenGL3_CreateFontsTexture(); +} + +void FurnaceGUIRenderGL::destroyFontsTexture() { + ImGui_ImplOpenGL3_DestroyFontsTexture(); +} + +void FurnaceGUIRenderGL::renderGUI() { + ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); +} + +void FurnaceGUIRenderGL::wipe(float alpha) { + C(glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA)); + C(glEnable(GL_BLEND)); + + quadVertex[0][0]=-1.0f; + quadVertex[0][1]=-1.0f; + quadVertex[0][2]=0.0f; + quadVertex[1][0]=1.0f; + quadVertex[1][1]=-1.0f; + quadVertex[1][2]=0.0f; + quadVertex[2][0]=-1.0f; + quadVertex[2][1]=1.0f; + quadVertex[2][2]=0.0f; + quadVertex[3][0]=1.0f; + quadVertex[3][1]=1.0f; + quadVertex[3][2]=0.0f; + + C(furBindBuffer(GL_ARRAY_BUFFER,quadBuf)); + C(furBufferData(GL_ARRAY_BUFFER,sizeof(quadVertex),quadVertex,GL_STATIC_DRAW)); + C(furVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,0,NULL)); + C(furEnableVertexAttribArray(0)); + C(furActiveTexture(GL_TEXTURE0)); + C(glBindTexture(GL_TEXTURE_2D,0)); + if (furUseProgram && furUniform1f) { + C(furUseProgram(sh_wipe_program)); + C(furUniform1f(sh_wipe_uAlpha,alpha)); + } + C(glDrawArrays(GL_TRIANGLE_STRIP,0,4)); +} + +void FurnaceGUIRenderGL::present() { + SDL_GL_SwapWindow(sdlWin); + C(glFlush()); +} + +bool FurnaceGUIRenderGL::getOutputSize(int& w, int& h) { + SDL_GL_GetDrawableSize(sdlWin,&w,&h); + return true; +} + +int FurnaceGUIRenderGL::getWindowFlags() { + return SDL_WINDOW_OPENGL; +} + +void FurnaceGUIRenderGL::preInit() { +#if defined(USE_GLES) + SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, 0); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK,SDL_GL_CONTEXT_PROFILE_ES); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION,2); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION,0); +#elif defined(__APPLE__) + // not recommended... + SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK,SDL_GL_CONTEXT_PROFILE_CORE); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION,3); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION,2); +#else + SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS,0); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION,3); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION,0); +#endif + + SDL_GL_SetAttribute(SDL_GL_RED_SIZE,8); + SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE,8); + SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE,8); + SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE,0); + SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1); + SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE,24); +} + +#define LOAD_PROC_MANDATORY(_v,_t,_s) \ + _v=(_t)SDL_GL_GetProcAddress(_s); \ + if (!_v) { \ + logE(_s " not found"); \ + return false; \ + } + +#define LOAD_PROC_OPTIONAL(_v,_t,_s) \ + _v=(_t)SDL_GL_GetProcAddress(_s); \ + if (!_v) { \ + logW(_s " not found"); \ + } + +bool FurnaceGUIRenderGL::init(SDL_Window* win) { + sdlWin=win; + context=SDL_GL_CreateContext(win); + if (context==NULL) { + return false; + } + SDL_GL_MakeCurrent(win,context); + SDL_GL_SetSwapInterval(1); + + LOAD_PROC_MANDATORY(furGenBuffers,PFNGLGENBUFFERSPROC,"glGenBuffers"); + LOAD_PROC_MANDATORY(furBindBuffer,PFNGLBINDBUFFERPROC,"glBindBuffer"); + LOAD_PROC_MANDATORY(furBufferData,PFNGLBUFFERDATAPROC,"glBufferData"); + LOAD_PROC_MANDATORY(furVertexAttribPointer,PFNGLVERTEXATTRIBPOINTERPROC,"glVertexAttribPointer"); + LOAD_PROC_MANDATORY(furEnableVertexAttribArray,PFNGLENABLEVERTEXATTRIBARRAYPROC,"glEnableVertexAttribArray"); + LOAD_PROC_MANDATORY(furActiveTexture,PFNGLACTIVETEXTUREPROC,"glActiveTexture"); + + LOAD_PROC_OPTIONAL(furCreateShader,PFNGLCREATESHADERPROC,"glCreateShader"); + LOAD_PROC_OPTIONAL(furShaderSource,PFNGLSHADERSOURCEPROC,"glShaderSource"); + LOAD_PROC_OPTIONAL(furCompileShader,PFNGLCOMPILESHADERPROC,"glCompileShader"); + LOAD_PROC_OPTIONAL(furGetShaderiv,PFNGLGETSHADERIVPROC,"glGetShaderiv"); + LOAD_PROC_OPTIONAL(furAttachShader,PFNGLATTACHSHADERPROC,"glAttachShader"); + LOAD_PROC_OPTIONAL(furBindAttribLocation,PFNGLBINDATTRIBLOCATIONPROC,"glBindAttribLocation"); + LOAD_PROC_OPTIONAL(furCreateProgram,PFNGLCREATEPROGRAMPROC,"glCreateProgram"); + LOAD_PROC_OPTIONAL(furLinkProgram,PFNGLLINKPROGRAMPROC,"glLinkProgram"); + LOAD_PROC_OPTIONAL(furGetProgramiv,PFNGLGETPROGRAMIVPROC,"glGetProgramiv"); + LOAD_PROC_OPTIONAL(furUseProgram,PFNGLUSEPROGRAMPROC,"glUseProgram"); + LOAD_PROC_OPTIONAL(furGetUniformLocation,PFNGLGETUNIFORMLOCATIONPROC,"glGetUniformLocation"); + LOAD_PROC_OPTIONAL(furUniform1f,PFNGLUNIFORM1FPROC,"glUniform1f"); + LOAD_PROC_OPTIONAL(furGetShaderInfoLog,PFNGLGETSHADERINFOLOGPROC,"glGetShaderInfoLog"); + +#ifndef USE_GLES + LOAD_PROC_OPTIONAL(furGetGraphicsResetStatusARB,PFNGLGETGRAPHICSRESETSTATUSARBPROC,"glGetGraphicsResetStatusARB"); +#endif + + if (createShader(sh_wipe_srcV,sh_wipe_srcF,sh_wipe_vertex,sh_wipe_fragment,sh_wipe_program)) { + sh_wipe_uAlpha=furGetUniformLocation(sh_wipe_program,"uAlpha"); + } + + C(furGenBuffers(1,&quadBuf)); + return true; +} + +void FurnaceGUIRenderGL::initGUI(SDL_Window* win) { + ImGui_ImplSDL2_InitForOpenGL(win,context); + ImGui_ImplOpenGL3_Init(); +} + +bool FurnaceGUIRenderGL::quit() { + if (context==NULL) return false; + SDL_GL_DeleteContext(context); + context=NULL; + return true; +} + +void FurnaceGUIRenderGL::quitGUI() { + ImGui_ImplOpenGL3_Shutdown(); +} + +bool FurnaceGUIRenderGL::isDead() { +#ifndef USE_GLES + if (furGetGraphicsResetStatusARB==NULL) return false; + return (furGetGraphicsResetStatusARB()!=GL_NO_ERROR); +#else + // handled by SDL... I think + return false; +#endif +} diff --git a/src/gui/render/renderGL.h b/src/gui/render/renderGL.h new file mode 100644 index 00000000..55d39973 --- /dev/null +++ b/src/gui/render/renderGL.h @@ -0,0 +1,66 @@ +/** + * Furnace Tracker - multi-system chiptune tracker + * Copyright (C) 2021-2023 tildearrow and contributors + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "../gui.h" + +class FurnaceGUIRenderGL: public FurnaceGUIRender { + SDL_GLContext context; + SDL_Window* sdlWin; + float quadVertex[4][3]; + unsigned int quadBuf; + + // SHADERS // + // -> wipe + int sh_wipe_vertex; + int sh_wipe_fragment; + int sh_wipe_program; + int sh_wipe_uAlpha; + + bool createShader(const char* vertexS, const char* fragmentS, int& vertex, int& fragment, int& program); + + public: + ImTextureID getTextureID(FurnaceGUITexture* which); + bool lockTexture(FurnaceGUITexture* which, void** data, int* pitch); + bool unlockTexture(FurnaceGUITexture* which); + bool updateTexture(FurnaceGUITexture* which, void* data, int pitch); + FurnaceGUITexture* createTexture(bool dynamic, int width, int height); + bool destroyTexture(FurnaceGUITexture* which); + void setTextureBlendMode(FurnaceGUITexture* which, FurnaceGUIBlendMode mode); + void setBlendMode(FurnaceGUIBlendMode mode); + void clear(ImVec4 color); + bool newFrame(); + void createFontsTexture(); + void destroyFontsTexture(); + void renderGUI(); + void wipe(float alpha); + void present(); + bool getOutputSize(int& w, int& h); + int getWindowFlags(); + void preInit(); + bool init(SDL_Window* win); + void initGUI(SDL_Window* win); + void quitGUI(); + bool quit(); + bool isDead(); + FurnaceGUIRenderGL(): + context(NULL), + sdlWin(NULL) { + memset(quadVertex,0,4*3*sizeof(float)); + } +}; diff --git a/src/gui/render/renderSDL.cpp b/src/gui/render/renderSDL.cpp new file mode 100644 index 00000000..0fe6b988 --- /dev/null +++ b/src/gui/render/renderSDL.cpp @@ -0,0 +1,164 @@ +/** + * Furnace Tracker - multi-system chiptune tracker + * Copyright (C) 2021-2023 tildearrow and contributors + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "renderSDL.h" +#include "backends/imgui_impl_sdlrenderer2.h" + +class FurnaceSDLTexture: public FurnaceGUITexture { + public: + SDL_Texture* tex; + FurnaceSDLTexture(): + tex(NULL) {} +}; + +ImTextureID FurnaceGUIRenderSDL::getTextureID(FurnaceGUITexture* which) { + FurnaceSDLTexture* t=(FurnaceSDLTexture*)which; + return t->tex; +} + +bool FurnaceGUIRenderSDL::lockTexture(FurnaceGUITexture* which, void** data, int* pitch) { + FurnaceSDLTexture* t=(FurnaceSDLTexture*)which; + return SDL_LockTexture(t->tex,NULL,data,pitch)==0; +} + +bool FurnaceGUIRenderSDL::unlockTexture(FurnaceGUITexture* which) { + FurnaceSDLTexture* t=(FurnaceSDLTexture*)which; + SDL_UnlockTexture(t->tex); + return true; +} + +bool FurnaceGUIRenderSDL::updateTexture(FurnaceGUITexture* which, void* data, int pitch) { + FurnaceSDLTexture* t=(FurnaceSDLTexture*)which; + return SDL_UpdateTexture(t->tex,NULL,data,pitch)==0; +} + +FurnaceGUITexture* FurnaceGUIRenderSDL::createTexture(bool dynamic, int width, int height) { + SDL_Texture* t=SDL_CreateTexture(sdlRend,SDL_PIXELFORMAT_ABGR8888,dynamic?SDL_TEXTUREACCESS_STREAMING:SDL_TEXTUREACCESS_STATIC,width,height); + + if (t==NULL) return NULL; + FurnaceSDLTexture* ret=new FurnaceSDLTexture; + ret->tex=t; + return ret; +} + +bool FurnaceGUIRenderSDL::destroyTexture(FurnaceGUITexture* which) { + FurnaceSDLTexture* t=(FurnaceSDLTexture*)which; + + SDL_DestroyTexture(t->tex); + delete t; + return true; +} + +void FurnaceGUIRenderSDL::setTextureBlendMode(FurnaceGUITexture* which, FurnaceGUIBlendMode mode) { + FurnaceSDLTexture* t=(FurnaceSDLTexture*)which; + switch (mode) { + case GUI_BLEND_MODE_NONE: + SDL_SetTextureBlendMode(t->tex,SDL_BLENDMODE_NONE); + break; + case GUI_BLEND_MODE_BLEND: + SDL_SetTextureBlendMode(t->tex,SDL_BLENDMODE_BLEND); + break; + case GUI_BLEND_MODE_ADD: + SDL_SetTextureBlendMode(t->tex,SDL_BLENDMODE_ADD); + break; + case GUI_BLEND_MODE_MULTIPLY: + SDL_SetTextureBlendMode(t->tex,SDL_BLENDMODE_MOD); + break; + } +} + +void FurnaceGUIRenderSDL::setBlendMode(FurnaceGUIBlendMode mode) { + switch (mode) { + case GUI_BLEND_MODE_NONE: + SDL_SetRenderDrawBlendMode(sdlRend,SDL_BLENDMODE_NONE); + break; + case GUI_BLEND_MODE_BLEND: + SDL_SetRenderDrawBlendMode(sdlRend,SDL_BLENDMODE_BLEND); + break; + case GUI_BLEND_MODE_ADD: + SDL_SetRenderDrawBlendMode(sdlRend,SDL_BLENDMODE_ADD); + break; + case GUI_BLEND_MODE_MULTIPLY: + SDL_SetRenderDrawBlendMode(sdlRend,SDL_BLENDMODE_MOD); + break; + } +} + +void FurnaceGUIRenderSDL::clear(ImVec4 color) { + SDL_SetRenderDrawColor(sdlRend,color.x*255,color.y*255,color.z*255,color.w*255); + SDL_RenderClear(sdlRend); +} + +bool FurnaceGUIRenderSDL::newFrame() { + return ImGui_ImplSDLRenderer2_NewFrame(); +} + +void FurnaceGUIRenderSDL::createFontsTexture() { + ImGui_ImplSDLRenderer2_CreateFontsTexture(); +} + +void FurnaceGUIRenderSDL::destroyFontsTexture() { + ImGui_ImplSDLRenderer2_DestroyFontsTexture(); +} + +void FurnaceGUIRenderSDL::renderGUI() { + ImGui_ImplSDLRenderer2_RenderDrawData(ImGui::GetDrawData()); +} + +void FurnaceGUIRenderSDL::wipe(float alpha) { + SDL_SetRenderDrawBlendMode(sdlRend,SDL_BLENDMODE_BLEND); + SDL_SetRenderDrawColor(sdlRend,0,0,0,255*alpha); + SDL_RenderFillRect(sdlRend,NULL); +} + +void FurnaceGUIRenderSDL::present() { + SDL_RenderPresent(sdlRend); +} + +bool FurnaceGUIRenderSDL::getOutputSize(int& w, int& h) { + return SDL_GetRendererOutputSize(sdlRend,&w,&h)==0; +} + +int FurnaceGUIRenderSDL::getWindowFlags() { + return 0; +} + +void FurnaceGUIRenderSDL::preInit() { +} + +bool FurnaceGUIRenderSDL::init(SDL_Window* win) { + sdlRend=SDL_CreateRenderer(win,-1,SDL_RENDERER_ACCELERATED|SDL_RENDERER_PRESENTVSYNC|SDL_RENDERER_TARGETTEXTURE); + return (sdlRend!=NULL); +} + +void FurnaceGUIRenderSDL::initGUI(SDL_Window* win) { + ImGui_ImplSDL2_InitForSDLRenderer(win,sdlRend); + ImGui_ImplSDLRenderer2_Init(sdlRend); +} + +void FurnaceGUIRenderSDL::quitGUI() { + ImGui_ImplSDLRenderer2_Shutdown(); +} + +bool FurnaceGUIRenderSDL::quit() { + if (sdlRend==NULL) return false; + SDL_DestroyRenderer(sdlRend); + sdlRend=NULL; + return true; +} diff --git a/src/gui/render/renderSDL.h b/src/gui/render/renderSDL.h new file mode 100644 index 00000000..f1913584 --- /dev/null +++ b/src/gui/render/renderSDL.h @@ -0,0 +1,49 @@ +/** + * Furnace Tracker - multi-system chiptune tracker + * Copyright (C) 2021-2023 tildearrow and contributors + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "../gui.h" + +class FurnaceGUIRenderSDL: public FurnaceGUIRender { + SDL_Renderer* sdlRend; + public: + ImTextureID getTextureID(FurnaceGUITexture* which); + bool lockTexture(FurnaceGUITexture* which, void** data, int* pitch); + bool unlockTexture(FurnaceGUITexture* which); + bool updateTexture(FurnaceGUITexture* which, void* data, int pitch); + FurnaceGUITexture* createTexture(bool dynamic, int width, int height); + bool destroyTexture(FurnaceGUITexture* which); + void setTextureBlendMode(FurnaceGUITexture* which, FurnaceGUIBlendMode mode); + void setBlendMode(FurnaceGUIBlendMode mode); + void clear(ImVec4 color); + bool newFrame(); + void createFontsTexture(); + void destroyFontsTexture(); + void renderGUI(); + void wipe(float alpha); + void present(); + bool getOutputSize(int& w, int& h); + int getWindowFlags(); + void preInit(); + bool init(SDL_Window* win); + void initGUI(SDL_Window* win); + void quitGUI(); + bool quit(); + FurnaceGUIRenderSDL(): + sdlRend(NULL) {} +}; \ No newline at end of file diff --git a/src/gui/sampleEdit.cpp b/src/gui/sampleEdit.cpp index 9d0fcc19..d3b8a19a 100644 --- a/src/gui/sampleEdit.cpp +++ b/src/gui/sampleEdit.cpp @@ -43,6 +43,12 @@ const double timeMultipliers[13]={ #define CENTER_TEXT(text) \ ImGui::SetCursorPosX(ImGui::GetCursorPosX()+0.5*(ImGui::GetContentRegionAvail().x-ImGui::CalcTextSize(text).x)); +#define SAMPLE_WARN(_x,_text) \ + if (_x.find(_text)==String::npos) { \ + if (!_x.empty()) _x+='\n'; \ + _x+=_text; \ + } + void FurnaceGUI::drawSampleEdit() { if (nextWindow==GUI_WINDOW_SAMPLE_EDIT) { sampleEditOpen=true; @@ -158,12 +164,17 @@ void FurnaceGUI::drawSampleEdit() { ImGui::Text("Name"); ImGui::SameLine(); ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); + ImGui::PushID(2+curSample); if (ImGui::InputText("##SampleName",&sample->name)) { MARK_MODIFIED; } + ImGui::PopID(); ImGui::Separator(); + String warnLoop, warnLoopMode, warnLoopPos; + String warnLength; + bool isChipVisible[DIV_MAX_CHIPS]; bool isTypeVisible[DIV_MAX_SAMPLE_TYPE]; bool isMemVisible[DIV_MAX_SAMPLE_TYPE][DIV_MAX_CHIPS]; @@ -172,7 +183,104 @@ void FurnaceGUI::drawSampleEdit() { memset(isTypeVisible,0,DIV_MAX_SAMPLE_TYPE*sizeof(bool)); memset(isMemVisible,0,DIV_MAX_CHIPS*DIV_MAX_SAMPLE_TYPE*sizeof(bool)); memset(isMemWarning,0,DIV_MAX_CHIPS*DIV_MAX_SAMPLE_TYPE*sizeof(bool)); + for (int i=0; isong.systemLen; i++) { + // warnings + switch (e->song.system[i]) { + case DIV_SYSTEM_SNES: + if (sample->loop) { + if (sample->loopStart&15 || sample->loopEnd&15) { + SAMPLE_WARN(warnLoopPos,"SNES: loop must be a multiple of 16"); + } + } + break; + case DIV_SYSTEM_QSOUND: + if (sample->loop) { + if (sample->loopEnd-sample->loopStart>32767) { + SAMPLE_WARN(warnLoopPos,"QSound: loop cannot be longer than 32767 samples"); + } + } + if (sample->samples>65535) { + SAMPLE_WARN(warnLength,"QSound: maximum sample length is 65535"); + } + break; + case DIV_SYSTEM_NES: + if (sample->loop) { + if (sample->loopStart!=0 || sample->loopEnd!=(int)(sample->samples)) { + SAMPLE_WARN(warnLoopPos,"NES: loop point ignored on DPCM (may only loop entire sample)"); + } + } + if (sample->samples>32648) { + SAMPLE_WARN(warnLength,"NES: maximum DPCM sample length is 32648"); + } + break; + case DIV_SYSTEM_X1_010: + if (sample->loop) { + SAMPLE_WARN(warnLoop,"X1-010: samples can't loop"); + } + if (sample->samples>131072) { + SAMPLE_WARN(warnLength,"X1-010: maximum sample length is 131072"); + } + break; + case DIV_SYSTEM_GA20: + if (sample->loop) { + SAMPLE_WARN(warnLoop,"GA20: samples can't loop"); + } + break; + case DIV_SYSTEM_YM2608: + case DIV_SYSTEM_YM2608_EXT: + case DIV_SYSTEM_YM2608_CSM: + if (sample->loop) { + if (sample->loopStart!=0 || sample->loopEnd!=(int)(sample->samples)) { + SAMPLE_WARN(warnLoopPos,"YM2608: loop point ignored on ADPCM-B (may only loop entire sample)"); + } + } + break; + case DIV_SYSTEM_YM2610_FULL: + case DIV_SYSTEM_YM2610_FULL_EXT: + case DIV_SYSTEM_YM2610_CSM: + case DIV_SYSTEM_YM2610B: + case DIV_SYSTEM_YM2610B_EXT: + if (sample->loop) { + SAMPLE_WARN(warnLoop,"YM2610: ADPCM-A samples can't loop"); + if (sample->loopStart!=0 || sample->loopEnd!=(int)(sample->samples)) { + SAMPLE_WARN(warnLoopPos,"YM2610: loop point ignored on ADPCM-B (may only loop entire sample)"); + } + } + if (sample->samples>2097152) { + SAMPLE_WARN(warnLength,"YM2610: maximum ADPCM-A sample length is 2097152"); + } + break; + case DIV_SYSTEM_AMIGA: + if (sample->loop) { + if (sample->loopStart&1 || sample->loopEnd&1) { + SAMPLE_WARN(warnLoopPos,"Amiga: loop must be a multiple of 2"); + } + } + if (sample->samples>131070) { + SAMPLE_WARN(warnLength,"Amiga: maximum sample length is 131070"); + } + break; + case DIV_SYSTEM_SEGAPCM: + case DIV_SYSTEM_SEGAPCM_COMPAT: + if (sample->samples>65280) { + SAMPLE_WARN(warnLength,"SegaPCM: maximum sample length is 65280"); + } + break; + default: + break; + } + if (e->song.system[i]!=DIV_SYSTEM_PCM_DAC) { + if (e->song.system[i]==DIV_SYSTEM_ES5506) { + if (sample->loopMode==DIV_SAMPLE_LOOP_BACKWARD) { + SAMPLE_WARN(warnLoopMode,"ES5506: backward loop mode isn't supported"); + } + } else if (sample->loopMode!=DIV_SAMPLE_LOOP_FORWARD) { + SAMPLE_WARN(warnLoopMode,"backward/ping-pong only supported in Generic PCM DAC\nping-pong also on ES5506"); + } + } + + // chips grid DivDispatch* dispatch=e->getDispatch(i); if (dispatch==NULL) continue; @@ -184,6 +292,7 @@ void FurnaceGUI::drawSampleEdit() { if (!dispatch->isSampleLoaded(j,curSample)) isMemWarning[j][i]=true; } } + int selColumns=1; for (int i=0; iloop); + pushWarningColor(!warnLoop.empty()); if (ImGui::Checkbox("Loop",&doLoop)) { MARK_MODIFIED if (doLoop) { sample->loop=true; @@ -236,8 +346,12 @@ void FurnaceGUI::drawSampleEdit() { e->renderSamplesP(); } } - if (ImGui::IsItemHovered() && sample->depth==DIV_SAMPLE_DEPTH_BRR) { - ImGui::SetTooltip("changing the loop in a BRR sample may result in glitches!"); + popWarningColor(); + if (ImGui::IsItemHovered() && (!warnLoop.empty() || sample->depth==DIV_SAMPLE_DEPTH_BRR)) { + if (sample->depth==DIV_SAMPLE_DEPTH_BRR) { + SAMPLE_WARN(warnLoop,"changing the loop in a BRR sample may result in glitches!"); + } + ImGui::SetTooltip("%s",warnLoop.c_str()); } if (selColumns>1) { @@ -291,6 +405,19 @@ void FurnaceGUI::drawSampleEdit() { } } } + if (sample->depth!=DIV_SAMPLE_DEPTH_8BIT && e->getSampleFormatMask()&(1L<dither; + if (ImGui::Checkbox("8-bit dither",&di)) { + sample->prepareUndo(true); + sample->dither=di; + e->renderSamplesP(); + updateSampleTex=true; + MARK_MODIFIED; + } + if (ImGui::IsItemHovered()) { + ImGui::SetTooltip("dither the sample when used on a chip that only supports 8-bit samples."); + } + } int sampleNote=round(64.0+(128.0*12.0*log((double)targetRate/8363.0)/log(2.0))); int sampleNoteCoarse=60+(sampleNote>>7); @@ -402,6 +529,7 @@ void FurnaceGUI::drawSampleEdit() { keepLoopAlive=false; ImGui::Text("Mode"); ImGui::SameLine(); + pushWarningColor(!warnLoopMode.empty()); ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); if (ImGui::BeginCombo("##SampleLoopMode",loopType.c_str())) { for (int i=0; idepth==DIV_SAMPLE_DEPTH_BRR) { - ImGui::SetTooltip("changing the loop in a BRR sample may result in glitches!"); + if (ImGui::IsItemHovered() && (!warnLoopPos.empty() || sample->depth==DIV_SAMPLE_DEPTH_BRR)) { + if (sample->depth==DIV_SAMPLE_DEPTH_BRR) { + SAMPLE_WARN(warnLoopPos,"changing the loop in a BRR sample may result in glitches!"); + } + ImGui::SetTooltip("%s",warnLoopPos.c_str()); } ImGui::Text("End"); @@ -457,9 +593,13 @@ void FurnaceGUI::drawSampleEdit() { if (ImGui::IsItemActive()) { keepLoopAlive=true; } - if (ImGui::IsItemHovered() && sample->depth==DIV_SAMPLE_DEPTH_BRR) { - ImGui::SetTooltip("changing the loop in a BRR sample may result in glitches!"); + if (ImGui::IsItemHovered() && (!warnLoopPos.empty() || sample->depth==DIV_SAMPLE_DEPTH_BRR)) { + if (sample->depth==DIV_SAMPLE_DEPTH_BRR) { + SAMPLE_WARN(warnLoopPos,"changing the loop in a BRR sample may result in glitches!"); + } + ImGui::SetTooltip("%s",warnLoopPos.c_str()); } + popWarningColor(); ImGui::EndDisabled(); if (selColumns>1) { @@ -575,7 +715,7 @@ void FurnaceGUI::drawSampleEdit() { if (ImGui::IsItemHovered()) { ImGui::SetTooltip("Edit mode: Select"); } - ImGui::SameLine(); + sameLineMaybe(); pushToggleColors(sampleDragMode); if (ImGui::Button(ICON_FA_PENCIL "##SDraw")) { sampleDragMode=true; @@ -585,9 +725,9 @@ void FurnaceGUI::drawSampleEdit() { ImGui::SetTooltip("Edit mode: Draw"); } ImGui::BeginDisabled(sample->depth!=DIV_SAMPLE_DEPTH_8BIT && sample->depth!=DIV_SAMPLE_DEPTH_16BIT); - ImGui::SameLine(); + sameLineMaybe(); ImGui::Dummy(ImVec2(4.0*dpiScale,dpiScale)); - ImGui::SameLine(); + sameLineMaybe(); ImGui::Button(ICON_FA_ARROWS_H "##SResize"); if (ImGui::IsItemClicked()) { resizeSize=sample->samples; @@ -622,7 +762,7 @@ void FurnaceGUI::drawSampleEdit() { } else { resizeSize=sample->samples; } - ImGui::SameLine(); + sameLineMaybe(); ImGui::Button(ICON_FA_EXPAND "##SResample"); if (ImGui::IsItemClicked()) { resampleTarget=targetRate; @@ -679,14 +819,14 @@ void FurnaceGUI::drawSampleEdit() { } ImGui::SameLine(); ImGui::Dummy(ImVec2(4.0*dpiScale,dpiScale)); - ImGui::SameLine(); + sameLineMaybe(); if (ImGui::Button(ICON_FA_UNDO "##SUndo")) { doUndoSample(); } if (ImGui::IsItemHovered()) { ImGui::SetTooltip("Undo"); } - ImGui::SameLine(); + sameLineMaybe(); if (ImGui::Button(ICON_FA_REPEAT "##SRedo")) { doRedoSample(); } @@ -695,7 +835,7 @@ void FurnaceGUI::drawSampleEdit() { } ImGui::SameLine(); ImGui::Dummy(ImVec2(4.0*dpiScale,dpiScale)); - ImGui::SameLine(); + sameLineMaybe(); ImGui::Button(ICON_FA_VOLUME_UP "##SAmplify"); if (ImGui::IsItemHovered()) { ImGui::SetTooltip("Amplify"); @@ -743,28 +883,28 @@ void FurnaceGUI::drawSampleEdit() { } ImGui::EndPopup(); } - ImGui::SameLine(); + sameLineMaybe(); if (ImGui::Button(ICON_FA_ARROWS_V "##SNormalize")) { doAction(GUI_ACTION_SAMPLE_NORMALIZE); } if (ImGui::IsItemHovered()) { ImGui::SetTooltip("Normalize"); } - ImGui::SameLine(); + sameLineMaybe(); if (ImGui::Button(ICON_FA_ARROW_UP "##SFadeIn")) { doAction(GUI_ACTION_SAMPLE_FADE_IN); } if (ImGui::IsItemHovered()) { ImGui::SetTooltip("Fade in"); } - ImGui::SameLine(); + sameLineMaybe(); if (ImGui::Button(ICON_FA_ARROW_DOWN "##SFadeOut")) { doAction(GUI_ACTION_SAMPLE_FADE_OUT); } if (ImGui::IsItemHovered()) { ImGui::SetTooltip("Fade out"); } - ImGui::SameLine(); + sameLineMaybe(); ImGui::Button(ICON_FA_ADJUST "##SInsertSilence"); if (ImGui::IsItemHovered()) { ImGui::SetTooltip("Insert silence"); @@ -795,21 +935,21 @@ void FurnaceGUI::drawSampleEdit() { } ImGui::EndPopup(); } - ImGui::SameLine(); + sameLineMaybe(); if (ImGui::Button(ICON_FA_ERASER "##SSilence")) { doAction(GUI_ACTION_SAMPLE_SILENCE); } if (ImGui::IsItemHovered()) { ImGui::SetTooltip("Apply silence"); } - ImGui::SameLine(); + sameLineMaybe(); if (ImGui::Button(ICON_FA_TIMES "##SDelete")) { doAction(GUI_ACTION_SAMPLE_DELETE); } if (ImGui::IsItemHovered()) { ImGui::SetTooltip("Delete"); } - ImGui::SameLine(); + sameLineMaybe(); if (ImGui::Button(ICON_FA_CROP "##STrim")) { doAction(GUI_ACTION_SAMPLE_TRIM); } @@ -818,28 +958,28 @@ void FurnaceGUI::drawSampleEdit() { } ImGui::SameLine(); ImGui::Dummy(ImVec2(4.0*dpiScale,dpiScale)); - ImGui::SameLine(); + sameLineMaybe(); if (ImGui::Button(ICON_FA_BACKWARD "##SReverse")) { doAction(GUI_ACTION_SAMPLE_REVERSE); } if (ImGui::IsItemHovered()) { ImGui::SetTooltip("Reverse"); } - ImGui::SameLine(); + sameLineMaybe(); if (ImGui::Button(ICON_FA_SORT_AMOUNT_ASC "##SInvert")) { doAction(GUI_ACTION_SAMPLE_INVERT); } if (ImGui::IsItemHovered()) { ImGui::SetTooltip("Invert"); } - ImGui::SameLine(); + sameLineMaybe(); if (ImGui::Button(ICON_FA_LEVEL_DOWN "##SSign")) { doAction(GUI_ACTION_SAMPLE_SIGN); } if (ImGui::IsItemHovered()) { ImGui::SetTooltip("Signed/unsigned exchange"); } - ImGui::SameLine(); + sameLineMaybe(); ImGui::Button(ICON_FA_INDUSTRY "##SFilter"); if (ImGui::IsItemHovered()) { ImGui::SetTooltip("Apply filter"); @@ -955,21 +1095,21 @@ void FurnaceGUI::drawSampleEdit() { ImGui::EndDisabled(); ImGui::SameLine(); ImGui::Dummy(ImVec2(4.0*dpiScale,dpiScale)); - ImGui::SameLine(); + sameLineMaybe(); if (ImGui::Button(ICON_FA_PLAY "##PreviewSample")) { e->previewSample(curSample); } if (ImGui::IsItemHovered()) { ImGui::SetTooltip("Preview sample"); } - ImGui::SameLine(); + sameLineMaybe(); if (ImGui::Button(ICON_FA_STOP "##StopSample")) { e->stopSamplePreview(); } if (ImGui::IsItemHovered()) { ImGui::SetTooltip("Stop sample preview"); } - ImGui::SameLine(); + sameLineMaybe(); if (ImGui::Button(ICON_FA_UPLOAD "##MakeIns")) { doAction(GUI_ACTION_SAMPLE_MAKE_INS); } @@ -977,7 +1117,7 @@ void FurnaceGUI::drawSampleEdit() { ImGui::SetTooltip("Create instrument from sample"); } - ImGui::SameLine(); + sameLineMaybe(ImGui::CalcTextSize("Zoom").x+150.0f*dpiScale+ImGui::CalcTextSize("100%").x); double zoomPercent=100.0/sampleZoom; bool checkZoomLimit=false; ImGui::Text("Zoom"); @@ -1110,12 +1250,12 @@ void FurnaceGUI::drawSampleEdit() { if (sampleTex==NULL || sampleTexW!=avail.x || sampleTexH!=avail.y) { if (sampleTex!=NULL) { - SDL_DestroyTexture(sampleTex); + rend->destroyTexture(sampleTex); sampleTex=NULL; } if (avail.x>=1 && avail.y>=1) { logD("recreating sample texture."); - sampleTex=SDL_CreateTexture(sdlRend,SDL_PIXELFORMAT_ABGR8888,SDL_TEXTUREACCESS_STREAMING,avail.x,avail.y); + sampleTex=rend->createTexture(true,avail.x,avail.y); sampleTexW=avail.x; sampleTexH=avail.y; if (sampleTex==NULL) { @@ -1131,7 +1271,7 @@ void FurnaceGUI::drawSampleEdit() { unsigned int* dataT=NULL; int pitch=0; logD("updating sample texture."); - if (SDL_LockTexture(sampleTex,NULL,(void**)&dataT,&pitch)!=0) { + if (!rend->lockTexture(sampleTex,(void**)&dataT,&pitch)) { logE("error while locking sample texture! %s",SDL_GetError()); } else { unsigned int* data=new unsigned int[sampleTexW*sampleTexH]; @@ -1216,14 +1356,24 @@ void FurnaceGUI::drawSampleEdit() { } } - memcpy(dataT,data,sampleTexW*sampleTexH*sizeof(unsigned int)); - SDL_UnlockTexture(sampleTex); + if ((pitch>>2)==sampleTexW) { + memcpy(dataT,data,sampleTexW*sampleTexH*sizeof(unsigned int)); + } else { + int srcY=0; + int destY=0; + for (int i=0; i>2; + } + } + rend->unlockTexture(sampleTex); delete[] data; } updateSampleTex=false; } - ImGui::ImageButton(sampleTex,avail,ImVec2(0,0),ImVec2(1,1),0); + ImGui::ImageButton(rend->getTextureID(sampleTex),avail,ImVec2(0,0),ImVec2(1,1),0); ImVec2 rectMin=ImGui::GetItemRectMin(); ImVec2 rectMax=ImGui::GetItemRectMax(); @@ -1585,7 +1735,16 @@ void FurnaceGUI::drawSampleEdit() { ImGui::TableNextColumn(); ImGui::TextUnformatted(statusBar2.c_str()); ImGui::TableNextColumn(); - ImGui::TextUnformatted(statusBar3.c_str()); + if (!warnLength.empty()) { + ImGui::PushStyleColor(ImGuiCol_Text,uiColors[GUI_COLOR_WARNING]); + ImGui::TextUnformatted(statusBar3.c_str()); + ImGui::PopStyleColor(); + if (ImGui::IsItemHovered()) { + ImGui::SetTooltip("%s",warnLength.c_str()); + } + } else { + ImGui::TextUnformatted(statusBar3.c_str()); + } ImGui::EndTable(); } diff --git a/src/gui/settings.cpp b/src/gui/settings.cpp index e2a30e35..882bc807 100644 --- a/src/gui/settings.cpp +++ b/src/gui/settings.cpp @@ -508,6 +508,14 @@ void FurnaceGUI::drawSettings() { settings.alwaysPlayIntro=3; } + ImGui::Text("When creating new song:"); + if (ImGui::RadioButton("Display system preset selector##NSB0",settings.newSongBehavior==0)) { + settings.newSongBehavior=0; + } + if (ImGui::RadioButton("Start with initial system##NSB1",settings.newSongBehavior==1)) { + settings.newSongBehavior=1; + } + ImGui::Separator(); if (CWSliderFloat("Double-click time (seconds)",&settings.doubleClickTime,0.02,1.0,"%.2f")) { @@ -543,6 +551,16 @@ void FurnaceGUI::drawSettings() { settings.stepOnDelete=stepOnDeleteB; } + bool insertBehaviorB=settings.insertBehavior; + if (ImGui::Checkbox("Insert pushes entire channel row",&insertBehaviorB)) { + settings.insertBehavior=insertBehaviorB; + } + + bool pullDeleteRowB=settings.pullDeleteRow; + if (ImGui::Checkbox("Pull delete affects entire channel row",&pullDeleteRowB)) { + settings.pullDeleteRow=pullDeleteRowB; + } + bool absorbInsInputB=settings.absorbInsInput; if (ImGui::Checkbox("Change current instrument when changing instrument column (absorb)",&absorbInsInputB)) { settings.absorbInsInput=absorbInsInputB; @@ -626,6 +644,14 @@ void FurnaceGUI::drawSettings() { ImGui::SetTooltip("saves power by lowering the frame rate to 2fps when idle.\nmay cause issues under Mesa drivers!"); } + bool renderClearPosB=settings.renderClearPos; + if (ImGui::Checkbox("Late render clear",&renderClearPosB)) { + settings.renderClearPos=renderClearPosB; + } + if (ImGui::IsItemHovered()) { + ImGui::SetTooltip("calls rend->clear() after rend->present(). might reduce UI latency by one frame in some drivers."); + } + #ifndef IS_MOBILE bool noThreadedInputB=settings.noThreadedInput; if (ImGui::Checkbox("Disable threaded input (restart after changing!)",&noThreadedInputB)) { @@ -1278,17 +1304,38 @@ void FurnaceGUI::drawSettings() { ImVec2 settingsViewSize=ImGui::GetContentRegionAvail(); settingsViewSize.y-=ImGui::GetFrameHeight()+ImGui::GetStyle().WindowPadding.y; if (ImGui::BeginChild("SettingsView",settingsViewSize)) { - if (ImGui::BeginCombo("Render driver",settings.renderDriver.empty()?"Automatic":settings.renderDriver.c_str())) { - if (ImGui::Selectable("Automatic",settings.renderDriver.empty())) { - settings.renderDriver=""; + String curRenderBackend=settings.renderBackend.empty()?GUI_BACKEND_DEFAULT_NAME:settings.renderBackend; + if (ImGui::BeginCombo("Render backend",curRenderBackend.c_str())) { +#ifdef HAVE_RENDER_SDL + if (ImGui::Selectable("SDL Renderer",curRenderBackend=="SDL")) { + settings.renderBackend="SDL"; } - for (String& i: availRenderDrivers) { - if (ImGui::Selectable(i.c_str(),i==settings.renderDriver)) { - settings.renderDriver=i; - } +#endif +#ifdef HAVE_RENDER_DX11 + if (ImGui::Selectable("DirectX 11",curRenderBackend=="DirectX 11")) { + settings.renderBackend="DirectX 11"; } +#endif +#ifdef HAVE_RENDER_GL + if (ImGui::Selectable("OpenGL",curRenderBackend=="OpenGL")) { + settings.renderBackend="OpenGL"; + } +#endif ImGui::EndCombo(); } + if (curRenderBackend=="SDL") { + if (ImGui::BeginCombo("Render driver",settings.renderDriver.empty()?"Automatic":settings.renderDriver.c_str())) { + if (ImGui::Selectable("Automatic",settings.renderDriver.empty())) { + settings.renderDriver=""; + } + for (String& i: availRenderDrivers) { + if (ImGui::Selectable(i.c_str(),i==settings.renderDriver)) { + settings.renderDriver=i; + } + } + ImGui::EndCombo(); + } + } bool dpiScaleAuto=(settings.dpiScale<0.5f); if (ImGui::Checkbox("Automatic UI scaling factor",&dpiScaleAuto)) { @@ -1555,6 +1602,16 @@ void FurnaceGUI::drawSettings() { ImGui::Separator(); + ImGui::Text("Chip memory usage unit:"); + if (ImGui::RadioButton("Bytes##MUU0",settings.memUsageUnit==0)) { + settings.memUsageUnit=0; + } + if (ImGui::RadioButton("Kilobytes##MUU1",settings.memUsageUnit==1)) { + settings.memUsageUnit=1; + } + + ImGui::Separator(); + ImGui::Text("Namco 163 chip name"); ImGui::SameLine(); ImGui::InputTextWithHint("##C163Name",DIV_C163_DEFAULT_NAME,&settings.c163Name); @@ -1883,6 +1940,9 @@ void FurnaceGUI::drawSettings() { UI_COLOR_CONFIG(GUI_COLOR_EDITING,"Editing"); UI_COLOR_CONFIG(GUI_COLOR_SONG_LOOP,"Song loop"); UI_COLOR_CONFIG(GUI_COLOR_PLAYBACK_STAT,"Playback status"); + UI_COLOR_CONFIG(GUI_COLOR_DESTRUCTIVE,"Destructive hint"); + UI_COLOR_CONFIG(GUI_COLOR_WARNING,"Warning hint"); + UI_COLOR_CONFIG(GUI_COLOR_ERROR,"Error hint"); ImGui::TreePop(); } if (ImGui::TreeNode("File Picker (built-in)")) { @@ -2711,6 +2771,12 @@ void FurnaceGUI::syncSettings() { settings.orderButtonPos=e->getConfInt("orderButtonPos",2); settings.compress=e->getConfInt("compress",1); settings.newPatternFormat=e->getConfInt("newPatternFormat",1); + settings.renderBackend=e->getConfString("renderBackend","SDL"); + settings.renderClearPos=e->getConfInt("renderClearPos",0); + settings.insertBehavior=e->getConfInt("insertBehavior",1); + settings.pullDeleteRow=e->getConfInt("pullDeleteRow",1); + settings.newSongBehavior=e->getConfInt("newSongBehavior",0); + settings.memUsageUnit=e->getConfInt("memUsageUnit",1); clampSetting(settings.mainFontSize,2,96); clampSetting(settings.patFontSize,2,96); @@ -2833,6 +2899,11 @@ void FurnaceGUI::syncSettings() { clampSetting(settings.orderButtonPos,0,2); clampSetting(settings.compress,0,1); clampSetting(settings.newPatternFormat,0,1); + clampSetting(settings.renderClearPos,0,1); + clampSetting(settings.insertBehavior,0,1); + clampSetting(settings.pullDeleteRow,0,1); + clampSetting(settings.newSongBehavior,0,1); + clampSetting(settings.memUsageUnit,0,1); if (settings.exportLoops<0.0) settings.exportLoops=0.0; if (settings.exportFadeOut<0.0) settings.exportFadeOut=0.0; @@ -3050,6 +3121,12 @@ void FurnaceGUI::commitSettings() { e->setConf("orderButtonPos",settings.orderButtonPos); e->setConf("compress",settings.compress); e->setConf("newPatternFormat",settings.newPatternFormat); + e->setConf("renderBackend",settings.renderBackend); + e->setConf("renderClearPos",settings.renderClearPos); + e->setConf("insertBehavior",settings.insertBehavior); + e->setConf("pullDeleteRow",settings.pullDeleteRow); + e->setConf("newSongBehavior",settings.newSongBehavior); + e->setConf("memUsageUnit",settings.memUsageUnit); // colors for (int i=0; idestroyFontsTexture(); if (!ImGui::GetIO().Fonts->Build()) { logE("error while building font atlas!"); showError("error while loading fonts! please check your settings."); ImGui::GetIO().Fonts->Clear(); mainFont=ImGui::GetIO().Fonts->AddFontDefault(); patFont=mainFont; - ImGui_ImplSDLRenderer_DestroyFontsTexture(); + if (rend) rend->destroyFontsTexture(); if (!ImGui::GetIO().Fonts->Build()) { logE("error again while building font atlas!"); + } else { + rend->createFontsTexture(); } + } else { + rend->createFontsTexture(); } } @@ -3438,6 +3519,35 @@ void FurnaceGUI::popAccentColors() { ImGui::PopStyleColor(24); } +void FurnaceGUI::pushDestColor() { + pushAccentColors(uiColors[GUI_COLOR_DESTRUCTIVE],uiColors[GUI_COLOR_DESTRUCTIVE],uiColors[GUI_COLOR_DESTRUCTIVE],ImVec4(0.0f,0.0f,0.0f,0.0f)); +} + +void FurnaceGUI::popDestColor() { + popAccentColors(); +} + +void FurnaceGUI::pushWarningColor(bool warnCond, bool errorCond) { + if (warnColorPushed) { + logE("warnColorPushed"); + abort(); + } + if (errorCond) { + pushAccentColors(uiColors[GUI_COLOR_ERROR],uiColors[GUI_COLOR_ERROR],uiColors[GUI_COLOR_ERROR],ImVec4(0.0f,0.0f,0.0f,0.0f)); + warnColorPushed=true; + } else if (warnCond) { + pushAccentColors(uiColors[GUI_COLOR_WARNING],uiColors[GUI_COLOR_WARNING],uiColors[GUI_COLOR_WARNING],ImVec4(0.0f,0.0f,0.0f,0.0f)); + warnColorPushed=true; + } +} + +void FurnaceGUI::popWarningColor() { + if (warnColorPushed) { + popAccentColors(); + warnColorPushed=false; + } +} + #define IGFD_FileStyleByExtension IGFD_FileStyleByExtention #ifdef _WIN32 @@ -3805,7 +3915,8 @@ void FurnaceGUI::applyUISettings(bool updateFonts) { } mainFont->FallbackChar='?'; - mainFont->DotChar='.'; + mainFont->EllipsisChar='.'; + mainFont->EllipsisCharCount=3; } // TODO: allow changing these colors. diff --git a/src/gui/speed.cpp b/src/gui/speed.cpp index 9cb5c72d..5557c663 100644 --- a/src/gui/speed.cpp +++ b/src/gui/speed.cpp @@ -56,7 +56,7 @@ void FurnaceGUI::drawSpeed(bool asChild) { if (tempoView) setHz/=2.5; if (setHz<1) setHz=1; if (setHz>999) setHz=999; - e->setSongRate(setHz,setHz<52); + e->setSongRate(setHz); } if (tempoView) { ImGui::SameLine(); diff --git a/src/gui/stats.cpp b/src/gui/stats.cpp index 33e7029c..ed879ff2 100644 --- a/src/gui/stats.cpp +++ b/src/gui/stats.cpp @@ -41,7 +41,12 @@ void FurnaceGUI::drawStats() { for (int j=0; dispatch!=NULL && dispatch->getSampleMemCapacity(j)>0; j++) { size_t capacity=dispatch->getSampleMemCapacity(j); size_t usage=dispatch->getSampleMemUsage(j); - String usageStr=fmt::sprintf("%d/%dKB",usage/1024,capacity/1024); + String usageStr; + if (settings.memUsageUnit==1) { + usageStr=fmt::sprintf("%d/%dKB",usage/1024,capacity/1024); + } else { + usageStr=fmt::sprintf("%d/%d",usage,capacity); + } ImGui::Text("%s [%d]", e->getSystemName(e->song.system[i]), j); ImGui::SameLine(); ImGui::ProgressBar(((float)usage)/((float)capacity),ImVec2(-FLT_MIN,0),usageStr.c_str()); diff --git a/src/gui/subSongs.cpp b/src/gui/subSongs.cpp index c0056b72..5d34c23f 100644 --- a/src/gui/subSongs.cpp +++ b/src/gui/subSongs.cpp @@ -17,7 +17,7 @@ void FurnaceGUI::drawSubSongs(bool asChild) { bool began=asChild?ImGui::BeginChild("Subsongs"):ImGui::Begin("Subsongs",&subSongsOpen,globalWinFlags); if (began) { char id[1024]; - ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x-ImGui::GetFrameHeightWithSpacing()*2.0f-ImGui::GetStyle().ItemSpacing.x); + ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x-ImGui::GetFrameHeightWithSpacing()*3.0f-ImGui::GetStyle().ItemSpacing.x*2.0f); if (e->curSubSong->name.empty()) { snprintf(id,1023,"%d. ",(int)e->getCurrentSubSong()+1); } else { @@ -92,6 +92,29 @@ void FurnaceGUI::drawSubSongs(bool asChild) { ImGui::SetTooltip("Add"); } ImGui::SameLine(); + if (ImGui::Button(ICON_FA_FILES_O "##SubSongDuplicate")) { + if (!e->duplicateSubSong(e->getCurrentSubSong())) { + showError("too many subsongs!"); + } else { + e->changeSongP(e->song.subsong.size()-1); + updateScroll(0); + oldOrder=0; + oldOrder1=0; + oldRow=0; + cursor.xCoarse=0; + cursor.xFine=0; + cursor.y=0; + selStart=cursor; + selEnd=cursor; + curOrder=0; + MARK_MODIFIED; + } + } + if (ImGui::IsItemHovered()) { + ImGui::SetTooltip("Duplicate"); + } + ImGui::SameLine(); + pushDestColor(); if (ImGui::Button(ICON_FA_MINUS "##SubSongDel")) { if (e->song.subsong.size()<=1) { showError("this is the only subsong!"); @@ -99,6 +122,7 @@ void FurnaceGUI::drawSubSongs(bool asChild) { showWarning("are you sure you want to remove this subsong?",GUI_WARN_SUBSONG_DEL); } } + popDestColor(); if (ImGui::IsItemHovered()) { ImGui::SetTooltip("Remove"); } diff --git a/src/gui/sysConf.cpp b/src/gui/sysConf.cpp index 07d39582..58ee524e 100644 --- a/src/gui/sysConf.cpp +++ b/src/gui/sysConf.cpp @@ -863,7 +863,7 @@ bool FurnaceGUI::drawSysConf(int chan, DivSystem type, DivConfig& flags, bool mo if (echoBufSize1<0) echoBufSize1=0; if (echoBufSize1>2725) echoBufSize1=2725; echoDelay=2725-echoBufSize1; - altered=true;; + altered=true; } rightClickable ImGui::Text("Echo feedback:"); if (CWSliderInt("##EchoFeedback",&echoFeedback,0,255)) { diff --git a/src/gui/tutorial.cpp b/src/gui/tutorial.cpp index 71ad3ca4..c1be8912 100644 --- a/src/gui/tutorial.cpp +++ b/src/gui/tutorial.cpp @@ -279,7 +279,7 @@ void FurnaceGUI::drawTutorial() { ImGui::TextWrapped( "if you need help, you may:\n" - "- read the (incomplete) manual: https://github.com/tildearrow/furnace/blob/master/papers/doc/README.md\n" + "- read the (incomplete) manual: https://github.com/tildearrow/furnace/blob/master/doc/README.md\n" "- ask for help in Discussions (https://github.com/tildearrow/furnace/discussions) or the Furnace Discord (https://discord.gg/EfrwT2wq7z)" );