From 2e6ea1eb66e8431c703d1571c846b5aadb6de2aa Mon Sep 17 00:00:00 2001 From: Yan Pujante Date: Sun, 18 Aug 2024 10:14:25 -0700 Subject: [PATCH] use Apple shortcut on mac - upgraded to latest emscripten-glfw - properly handle cut/copy/paste via platform shortcuts - added full screen without resizing the canvas --- external/emscripten-ports/emscripten-glfw3.py | 6 +- .../fontawesome/src/icons/metadata/icons.yml | 44 +++++++++ .../fontawesome/src/webfonts/fa-solid-900.ttf | Bin 4744 -> 5072 bytes external/fonts/src/IconsFontWGPUShaderToy.cpp | 66 ++++++------- external/fonts/src/IconsFontWGPUShaderToy.h | 2 + .../ImGuiColorTextEdit/TextEditor.cpp | 47 ++++----- src/cpp/MainWindow.cpp | 89 +++++++++++------- src/cpp/MainWindow.h | 5 +- src/cpp/gpu/ImGuiWindow.cpp | 6 ++ src/cpp/gpu/Window.cpp | 8 +- src/cpp/gpu/Window.h | 3 +- 11 files changed, 169 insertions(+), 107 deletions(-) diff --git a/external/emscripten-ports/emscripten-glfw3.py b/external/emscripten-ports/emscripten-glfw3.py index 3a6c05d..ab6b5bf 100644 --- a/external/emscripten-ports/emscripten-glfw3.py +++ b/external/emscripten-ports/emscripten-glfw3.py @@ -17,8 +17,8 @@ import os from typing import Union, Dict -TAG = '3.4.0.20240731' -HASH = '1d348f2a6423def537bc11ba5a67347d23696f623e0155e315711d0e23e9b4e6f623019c24c699b6dd5b727322f7093af804d58fc48488f37888ba17300c3aa8' +TAG = '3.4.0.20240817' +HASH = 'f75e711ec47c5eb04cff7fef5f2ef6788445bb86ed570a884ccb0e839744c3ed38b5f94808d1fac1417f356177e753e4ac8cafed9ad808d24d8fd08d23ca07f0' ZIP_URL = f'https://github.com/pongasoft/emscripten-glfw/releases/download/v{TAG}/emscripten-glfw3-{TAG}.zip' # contrib port information (required) @@ -104,7 +104,7 @@ def process_args(ports): args = [ '-I', os.path.join(root_path, 'external'), # '-I', os.path.join(root_path, 'include'), # - '-DEMSCRIPTEN_USE_PORT_CONTRIB_GLFW3' + f'-DEMSCRIPTEN_USE_PORT_CONTRIB_GLFW3={TAG.replace(".", "")}' ] return args diff --git a/external/fontawesome/src/icons/metadata/icons.yml b/external/fontawesome/src/icons/metadata/icons.yml index c82d5b3..21b65e7 100644 --- a/external/fontawesome/src/icons/metadata/icons.yml +++ b/external/fontawesome/src/icons/metadata/icons.yml @@ -14,6 +14,7 @@ backward: - 6.3.0 - 6.4.0 - 6.5.0 + - 6.6.0 label: Backward search: terms: @@ -43,6 +44,7 @@ backward-fast: - 6.3.0 - 6.4.0 - 6.5.0 + - 6.6.0 label: Backward Fast search: terms: @@ -77,6 +79,7 @@ bars: - 6.3.0 - 6.4.0 - 6.5.0 + - 6.6.0 label: Bars search: terms: @@ -117,6 +120,7 @@ camera: - 6.3.0 - 6.4.0 - 6.5.0 + - 6.6.0 label: Camera search: terms: @@ -144,6 +148,7 @@ camera-polaroid: - 6.3.0 - 6.4.0 - 6.5.0 + - 6.6.0 label: Camera Polaroid search: terms: @@ -177,6 +182,7 @@ circle-pause: - 6.3.0 - 6.4.0 - 6.5.0 + - 6.6.0 label: Circle Pause search: terms: @@ -205,6 +211,7 @@ circle-play: - 6.3.0 - 6.4.0 - 6.5.0 + - 6.6.0 label: Circle Play search: terms: @@ -235,6 +242,7 @@ clock-rotate-left: - 6.3.0 - 6.4.0 - 6.5.0 + - 6.6.0 label: Clock Rotate Left search: terms: @@ -262,6 +270,7 @@ expand: - 6.3.0 - 6.4.0 - 6.5.0 + - 6.6.0 label: Expand search: terms: @@ -280,6 +289,37 @@ expand: - solid unicode: f065 voted: false +expand-wide: + aliases: + unicodes: + secondary: + - 10f320 + changes: + - 5.0.0 + - 6.0.0-beta1 + - 6.2.0 + - 6.3.0 + - 6.4.0 + - 6.5.0 + - 6.6.0 + label: Expand Wide + search: + terms: + - maximize + - resize + - scale + - arrows + - bigger + - enlarge + - fullscreen + - resize + - size + - expand + - viewfinder + styles: + - solid + unicode: f320 + voted: false forward: aliases: unicodes: @@ -295,6 +335,7 @@ forward: - 6.3.0 - 6.4.0 - 6.5.0 + - 6.6.0 label: Forward search: terms: @@ -326,6 +367,7 @@ forward-fast: - 6.3.0 - 6.4.0 - 6.5.0 + - 6.6.0 label: Forward Fast search: terms: @@ -356,6 +398,7 @@ hammer: - 6.3.0 - 6.4.0 - 6.5.0 + - 6.6.0 label: Hammer search: terms: @@ -390,6 +433,7 @@ power-off: - 6.3.0 - 6.4.0 - 6.5.0 + - 6.6.0 label: Power Off search: terms: diff --git a/external/fontawesome/src/webfonts/fa-solid-900.ttf b/external/fontawesome/src/webfonts/fa-solid-900.ttf index 3e1d52ffe731b17aea8c0ac6ff155607fcb7b3de..9139f82195f01b0b6e8d40d09d152e17471f4e7c 100644 GIT binary patch delta 1024 zcmZWoT}V@57=FHU&eXH5ogGulN_WDAbEs`&It|f9;HCWtqBrSu%MIMl(1BVPt|0Ix zsJ@FX>mmp$D3C6)2m&vpo4g2=pdT~3DyYMOGJTJ{NF4Wi!dbd0Jbxwr8EKHLVR1 zfn|6oQ{;9TPBrr~YKnf-@^lk%arpFmZ uJ3Y@JzvS++Q3V=!Q19jQdL7gFd;N$+?vI{xI1*FYSSH>ynTqptdG%k+*R&k~ delta 840 zcmZ8fO-K}B7=C7EcXd}?XGTri&34k&Tv6Lr+jXss3WAd8XCbVMjqBD5JI=N)s9m%} zAW?^S51oRb4iyD~7Y_v;I@l@e5Jf@sb16Jjpa~u7o!u{x2Hx*|-sgLs@8|tydHa0Z zEF=Iv%t3*1EVUzcxnXn=kUE$>o3_mSuXpW1uAg$OpU=&ld*m6o2`FzIQ#NCcwZGoG zo3#%(;#nqKKDm;9abHtUY4ciF$l^;XNAK9NTQF0#Ne855?J z>AOKipoTY4KIZMoV$09$A3%G|^Uq6%#Sp$W9lbD8yJr`_RSivbPG2cqp(6ogHOfE3MBh zad~HXi$1y0>5t3H(@}XwV3|AhLtq7i(p!OD8#Hc=N>hUOpi{mlun)udEpQcjv41KvX##kZn42RUQOBc,>>#a?'o/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c>#0Su>#4`1?#8lC?#setStartTime(getCurrentTime()); ImGui::SameLine(); @@ -413,7 +413,7 @@ void MainWindow::renderTimeControls() ImGui::BeginDisabled(fCurrentFragmentShader->getInputs().frame == 0); { ImGui::PushItemFlag(ImGuiItemFlags_ButtonRepeat, true); - auto button = ImGui::Button(isKeyAlt ? fa::kBackward : fa::kBackwardFast); + auto button = ImGui::Button(isKeyAlt ? fa::kBackward : fa::kBackwardFast, fIconButtonSize); if(ImGui::IsItemDeactivated()) fCurrentFragmentShader->stopManualTime(getCurrentTime()); else @@ -428,7 +428,7 @@ void MainWindow::renderTimeControls() ImGui::SameLine(); // Play / Pause - if(ImGui::Button(fCurrentFragmentShader->isRunning() ? fa::kCirclePause : fa::kCirclePlay)) + if(ImGui::Button(fCurrentFragmentShader->isRunning() ? fa::kCirclePause : fa::kCirclePlay, fIconButtonSize)) fCurrentFragmentShader->toggleRunning(getCurrentTime()); ImGui::SameLine(); @@ -436,7 +436,7 @@ void MainWindow::renderTimeControls() // Next frame ImGui::PushItemFlag(ImGuiItemFlags_ButtonRepeat, true); { - auto button = ImGui::Button(isKeyAlt ? fa::kForward : fa::kForwardFast); + auto button = ImGui::Button(isKeyAlt ? fa::kForward : fa::kForwardFast, fIconButtonSize); if(ImGui::IsItemDeactivated()) fCurrentFragmentShader->stopManualTime(getCurrentTime()); else @@ -463,23 +463,25 @@ void MainWindow::renderControlsSection() ImGui::SameLine(); + auto const isKeyAlt = gui::WstGui::IsKeyAlt(); + // Screenshot - if(gui::WstGui::IsKeyAlt()) + if(isKeyAlt) { - if(ImGui::Button(fa::kCamera)) + if(ImGui::Button(fa::kCamera, fIconButtonSize)) promptSaveCurrentFragmentShaderScreenshot(); } else { - if(ImGui::Button(fa::kCameraPolaroid)) + if(ImGui::Button(fa::kCameraPolaroid, fIconButtonSize)) saveCurrentFragmentShaderScreenshot(fCurrentFragmentShader->getName()); } ImGui::SameLine(); // Fullscreen - if(ImGui::Button(fa::kExpand)) - fFragmentShaderWindow->requestFullscreen(); + if(ImGui::Button(isKeyAlt ? fa::kExpand : fa::kExpandWide, fIconButtonSize)) + fFragmentShaderWindow->requestFullscreen(!isKeyAlt); } ImGui::EndDisabled(); @@ -489,7 +491,7 @@ void MainWindow::renderControlsSection() ImGui::SameLine(); - if(ImGui::Button(fa::kPowerOff)) + if(ImGui::Button(fa::kPowerOff, fIconButtonSize)) fCurrentFragmentShader->toggleEnabled(); ImGui::SameLine(); @@ -759,7 +761,7 @@ void MainWindow::renderShaderMenu(TextEditor &iEditor, std::string const &iNewCo // -- Code ------ ImGui::SeparatorText("Shader"); - if(ImGui::MenuItem(ICON_FA_Hammer " Compile", "Ctrl + SPACE", false, iEdited)) + if(ImGui::MenuItem(ICON_FA_Hammer " Compile", getShortcutString("D"), false, iEdited)) compile(iNewCode); if(ImGui::MenuItem("Rename")) promptRenameCurrentShader(); @@ -771,19 +773,12 @@ void MainWindow::renderShaderMenu(TextEditor &iEditor, std::string const &iNewCo // -- Edit ------ ImGui::SeparatorText("Edit"); - if(ImGui::MenuItem("Copy", "Ctrl + C")) - iEditor.Copy(); - if(ImGui::MenuItem("Cut", "Ctrl + X")) - iEditor.Cut(); - if(ImGui::MenuItem("Paste", "Ctrl + V")) - iEditor.OnKeyboardPaste(); - ImGui::Separator(); - if(ImGui::MenuItem("Undo", "Ctrl + Z")) + if(ImGui::MenuItem("Undo", getShortcutString("Z"))) iEditor.Undo(); - if(ImGui::MenuItem("Redo", "Shift + Ctrl + Z")) + if(ImGui::MenuItem("Redo", getShortcutString("Z", "Shift + %s + %s"))) iEditor.Redo(); ImGui::Separator(); - if(ImGui::MenuItem("Select All", "Shift + Ctrl + A")) + if(ImGui::MenuItem("Select All", getShortcutString("A", "Shift + %s + %s"))) iEditor.SelectAll(); // -- Frame ------ @@ -819,7 +814,7 @@ void MainWindow::renderShaderSection(bool iEditorHasFocus) auto edited = newCode != fCurrentFragmentShader->getCode(); // [Keyboard shortcut] - if(iEditorHasFocus && ImGui::GetIO().KeyCtrl && ImGui::IsKeyPressed(ImGuiKey_Space)) + if(iEditorHasFocus && ImGui::IsKeyChordPressed(ImGuiMod_Ctrl | ImGuiKey_D)) { if(edited) compile(newCode); @@ -867,7 +862,6 @@ void MainWindow::renderShaderSection(bool iEditorHasFocus) ImGui::PopStyleColor(hasCompilationError ? 2 : 1); // [Editor] Render - editor.SetOnKeyboardPasteHandler(fKeyboardPasteHandler); editor.Render("Code", iEditorHasFocus, {}, 0, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoNavInputs | ImGuiWindowFlags_HorizontalScrollbar); ImGui::EndTabItem(); @@ -915,6 +909,8 @@ void MainWindow::renderDialog() //------------------------------------------------------------------------ void MainWindow::doRender() { + fIconButtonSize = {ImGui::CalcTextSize(fa::kCameraPolaroid).x + 2 * ImGui::GetStyle().ItemInnerSpacing.x, 0}; + renderMainMenuBar(); bool isDialogOpen = hasDialog(); @@ -1136,12 +1132,6 @@ void MainWindow::beforeFrame() // fAspectRatioRequest = std::nullopt; // } fFragmentShaderWindow->beforeFrame(); - - // handling asynchronous clipboard - if(fClipboardString) - { - onClipboardString(fClipboardString.fetchValue()); - } } //------------------------------------------------------------------------ @@ -1409,20 +1399,21 @@ void MainWindow::help() const {ICON_FA_CirclePause " / " ICON_FA_CirclePlay, {"Pause/Play time/frame"}}, {fa::kForwardFast, {"Steps forward in time (+12 frames) | Hold to repeat"}}, {fa::kCameraPolaroid, {"Take an instant screenshot"}}, - {fa::kExpand, {"Enter fullscreen (ESC to exit)"}}, + {fa::kExpandWide, {"Enter fullscreen (widescreen) (ESC to exit)"}}, + {fa::kPowerOff, {"Disable/Enable shader rendering"}}, }; static const help_t kAltIcons = { {fa::kBackward, {"Steps backward in time (-1 frames) | Hold to repeat"}}, {fa::kForward, {"Steps forward in time (+1 frame) | Hold to repeat"}}, {fa::kCamera, {"Open the menu to take a screenshot (choose format)"}}, - {fa::kPowerOff, {"Disable/Enable shader rendering"}}, + {fa::kExpand, {"Enter fullscreen (ESC to exit)"}}, }; // for the time being we support only Windows shortcuts because the Command key does not work properly in // browsers static const help_t kShortcuts = { - {"Ctrl + SPACE", {"Compile the shader"}}, + {"Ctrl + D", {"Compile the shader"}}, {"Ctrl + C", {"Copy selection"}}, {"Ctrl + X", {"Cut selection / Cut Line (no selection)"}}, {"Ctrl + V", {"Paste"}}, @@ -1431,9 +1422,26 @@ void MainWindow::help() const {"Ctrl + Shift + A", {"Select All"}}, {"Ctrl + [ or ]", {"Indentation change"}}, {"Ctrl + /", {"Toggle line comment"}}, - {"Home or End", {"Beginning or End of line"}}, {"Ctrl + A", {"Beginning of line"}}, {"Ctrl + E", {"End of line"}}, + {"Home or End", {"Beginning or End of line"}}, + {"", {"Arrows, Home, End, PgUp, PgDn: move cursor"}}, + {"Shift + ", {"Select text"}}, + }; + + static const help_t kAppleShortcuts = { + {"Cmd + D", {"Compile the shader"}}, + {"Cmd + C", {"Copy selection"}}, + {"Cmd + X", {"Cut selection / Cut Line (no selection)"}}, + {"Cmd + V", {"Paste"}}, + {"Cmd + Z", {"Undo"}}, + {"Cmd + Shift + Z", {"Redo"}}, + {"Cmd + Shift + A", {"Select All"}}, + {"Cmd + [ or ]", {"Indentation change"}}, + {"Cmd + /", {"Toggle line comment"}}, + {"Cmd|Ctrl + A", {"Beginning of line"}}, + {"Cmd|Ctrl + E", {"End of line"}}, + {"Home or End", {"Beginning or End of line"}}, {"", {"Arrows, Home, End, PgUp, PgDn: move cursor"}}, {"Shift + ", {"Select text"}}, }; @@ -1446,7 +1454,8 @@ void MainWindow::help() const " time: f32,", " frame: i32,", "};", - "@group(0) @binding(0) var inputs: ShaderToyInputs;" + "@group(0) @binding(0)", + "var inputs: ShaderToyInputs;" }}, {"inputs.size.xy", {"size of the viewport (in pixels)"}}, {"inputs.size.zw", {"scale ((1.0,1.0) for low res)"}}, @@ -1482,11 +1491,21 @@ void MainWindow::help() const renderHelp(kIcons, "Icons", "Icons"); renderHelp(kAltIcons, "Alternative Icons (Hold Alt Key)", "Icons"); - renderHelp(kShortcuts, "Keyboard Shortcuts", "Shortcuts"); + renderHelp(fIsRuntimePlatformApple ? kAppleShortcuts : kShortcuts, "Editor Keyboard Shortcuts", "Shortcuts"); renderHelp(kShaderInputs, "Shader Inputs", "Inputs"); } +//------------------------------------------------------------------------ +// MainWindow::getShortcutString +//------------------------------------------------------------------------ +char const *MainWindow::getShortcutString(char const *iKey, char const *iFormat) +{ + static char kShortcut[256]{}; + snprintf(kShortcut, 256, iFormat, fIsRuntimePlatformApple ? "Cmd" : "Ctrl", iKey); + return kShortcut; +} + //------------------------------------------------------------------------ // image::format::getFormatFromMimeType //------------------------------------------------------------------------ diff --git a/src/cpp/MainWindow.h b/src/cpp/MainWindow.h index e0304c9..495780f 100644 --- a/src/cpp/MainWindow.h +++ b/src/cpp/MainWindow.h @@ -133,6 +133,7 @@ class MainWindow : public ImGuiWindow template gui::Dialog &newDialog(std::string iTitle, State const &iState); gui::DialogNoState &newDialog(std::string iTitle); + char const *getShortcutString(char const *iKey, char const *iFormat = "%s + %s"); void deferBeforeImGuiFrame(gui_action_t iAction) { if(iAction) fBeforeImGuiFrameActions.emplace_back(std::move(iAction)); } @@ -167,8 +168,8 @@ class MainWindow : public ImGuiWindow std::optional fCurrentFragmentShaderNameRequest{}; - emscripten::glfw3::FutureClipboardString fClipboardString{}; - TextEditor::keyboard_action_handler_t fKeyboardPasteHandler{[this]() { fClipboardString = emscripten::glfw3::GetClipboardString();}}; + // UI + ImVec2 fIconButtonSize{}; }; } diff --git a/src/cpp/gpu/ImGuiWindow.cpp b/src/cpp/gpu/ImGuiWindow.cpp index 53719ab..c9de3bd 100644 --- a/src/cpp/gpu/ImGuiWindow.cpp +++ b/src/cpp/gpu/ImGuiWindow.cpp @@ -18,6 +18,7 @@ #include #include +#include #include "ImGuiWindow.h" namespace pongasoft::gpu { @@ -41,6 +42,11 @@ ImGuiWindow::ImGuiWindow(std::shared_ptr iGPU, Args const &iArgs) : init_info.RenderTargetFormat = static_cast(fPreferredFormat); ImGui_ImplWGPU_Init(&init_info); + ImGuiIO& io = ImGui::GetIO(); + io.ConfigMacOSXBehaviors = fIsRuntimePlatformApple; + + // essentially disable repeat on Meta + Key + emscripten::glfw3::SetSuperPlusKeyTimeouts(10, 10); } //------------------------------------------------------------------------ diff --git a/src/cpp/gpu/Window.cpp b/src/cpp/gpu/Window.cpp index e86032e..040c3b2 100644 --- a/src/cpp/gpu/Window.cpp +++ b/src/cpp/gpu/Window.cpp @@ -43,7 +43,9 @@ void onFrameBufferSizeChange(GLFWwindow *window, int width, int height) //------------------------------------------------------------------------ // Window::Window //------------------------------------------------------------------------ -Window::Window(std::shared_ptr iGPU, Args const &iArgs) : Renderable(std::move(iGPU)) +Window::Window(std::shared_ptr iGPU, Args const &iArgs) : + Renderable(std::move(iGPU)), + fIsRuntimePlatformApple{emscripten::glfw3::IsRuntimePlatformApple()} { emscripten::glfw3::SetNextWindowCanvasSelector(iArgs.canvas.selector); @@ -219,9 +221,9 @@ double Window::getCurrentTime() //------------------------------------------------------------------------ // Window::requestFullscreen //------------------------------------------------------------------------ -void Window::requestFullscreen() +void Window::requestFullscreen(bool iResizeCanvas) { - emscripten::glfw3::RequestFullscreen(fWindow, false, true); + emscripten::glfw3::RequestFullscreen(fWindow, false, iResizeCanvas); } //------------------------------------------------------------------------ diff --git a/src/cpp/gpu/Window.h b/src/cpp/gpu/Window.h index 5b9efd2..51173d7 100644 --- a/src/cpp/gpu/Window.h +++ b/src/cpp/gpu/Window.h @@ -67,7 +67,7 @@ class Window: public Renderable void setAspectRatio(AspectRatio const &iAspectRatio); bool isHiDPIAware() const; void toggleHiDPIAwareness(); - void requestFullscreen(); + void requestFullscreen(bool iResizeCanvas); void makeCanvasResizable(std::string_view iCanvasResizeSelector, std::optional iHandleSelector = std::nullopt); void setTitle(std::string const &iTitle); @@ -85,6 +85,7 @@ class Window: public Renderable protected: GLFWwindow *fWindow{}; + bool fIsRuntimePlatformApple; private: std::optional fNewFrameBufferSize{};