Free, open-source 3D sculpting for Linux, macOS and Windows: dense meshes, remeshing, painting, built-in AI (image/text to 3D), Send to Unreal, game-ready LODs, Gaussian splats and OpenUSD.
C++ 3d3d-sculptingcppdear-imguidigital-sculptingfbxgame-developmentgaussian-splattinggltfimage-to-3dmcpopenglopenusdsculptingtext-to-3dunreal-engine
Radial (pie) menus: hold a key, flick, let go (#45)
islandmedaaa8479505d2
diff --git a/CMakeLists.txt b/CMakeLists.txtindex 562d08b1..7c292df6 100644--- a/CMakeLists.txt+++ b/CMakeLists.txt@@ -282,6 +282,7 @@ if(SCULPTFORGE_BUILD_APP)src/app/Tablet.cppsrc/app/SpaceMouse.cppsrc/app/Input.cpp+ src/app/RadialMenu.cppsrc/render/GL.cppsrc/render/Camera.cppsrc/render/Clusters.cppdiff --git a/src/app/App.cpp b/src/app/App.cppindex eafbf52b..f0ecc3cc 100644--- a/src/app/App.cpp+++ b/src/app/App.cpp@@ -1032,6 +1032,7 @@ int App::run() {void App::handleEvent(const SDL_Event& e) {if (dropPenMouseEvent(e)) return; // pen side buttons are mapped in Tablet.cpp, not left to SDLif (strayMouseMotion(e)) return; // neither the canvas nor the UI follows a driver's stray mouse events+ if (radialMouseEvent(e)) return; // clicks on an open radial menu, and the buttons that open one (RadialMenu.cpp)ImGui_ImplSDL3_ProcessEvent(&e);const ImGuiIO& io = ImGui::GetIO();@@ -1045,6 +1046,9 @@ void App::handleEvent(const SDL_Event& e) {case SDL_EVENT_JOYSTICK_BUTTON_DOWN:spaceMouseEvent(e); // a SpaceMouse (SpaceMouse.cpp)break;+ case SDL_EVENT_WINDOW_FOCUS_LOST:+ if (radial_.hold != RadialHold::None) closeRadialMenu(); // its key or button's release won't come here+ break;case SDL_EVENT_WINDOW_CLOSE_REQUESTED:if (e.window.windowID == SDL_GetWindowID(window_)) requestQuit();break;@@ -1083,6 +1087,7 @@ void App::handleEvent(const SDL_Event& e) {break;case SDL_EVENT_KEY_UP:if (e.key.key == SDLK_SPACE) quickMenuKeyUp(); // a held Space closes the QuickMenu when let go+ radialKeyUp(e.key.key); // a radial menu's held key: run the slot pointed atbreak;case SDL_EVENT_DROP_FILE:if (e.drop.data) openPathConfirmed(e.drop.data);@@ -1342,6 +1347,10 @@ void App::onMouseUp() {}void App::onKey(SDL_Keycode key, SDL_Keymod mod) {+ if (key == SDLK_ESCAPE && radial_.menu >= 0) {+ closeRadialMenu();+ return;+ }if (key == SDLK_ESCAPE && !insertType_.empty()) { // Append > Insert (#34) offinsertType_.clear();status_ = "Insert off";@@ -1358,7 +1367,9 @@ void App::onKey(SDL_Keycode key, SDL_Keymod mod) {if (blenderStyle() && uiPrefs_.emulateNumpad && key >= SDLK_0 && key <= SDLK_9 &&!actions_.actionForChord(chordFromEvent(key, mod)))key = key == SDLK_0 ? SDLK_KP_0 : SDL_Keycode(SDLK_KP_1 + (key - SDLK_1));+ keyDown_ = key; // a radial menu's key holds it open until this key is let go (RadialMenu.cpp)actions_.handleKey(key, mod); // the shortcut map: Config.cpp initActions()+ keyDown_ = SDLK_UNKNOWN;}// ---------------------------------------------------------------------------@@ -1918,6 +1929,7 @@ void App::drawUi() {drawShell();drawLightBoxUi(); // thumbnails, the LightBox over the canvas, pickers, size / strength pop-upsdrawQuickMenu(); // Space (Input.cpp)+ drawRadialMenu(); // radial menus (RadialMenu.cpp)drawSubToolPopups();if (showBrushLab_) drawBrushLab();drawBrushGallery();@@ -1951,7 +1963,7 @@ void App::drawUi() {// In Gizmo mode (and with the QRemesh Guides brush) the brush ring shows only while Ctrl masks or Shift smooths.const bool ringOff = gizmoActive() || (guidesMode_ && !(inputMods() & SDL_KMOD_SHIFT)) || sculptableHot() || zsphereActive();if (((!ImGui::GetIO().WantCaptureMouse && canvasRect().contains(mouse.x, mouse.y)) || drag_ == Drag::Stroke) &&- !hideBrushCursor_ && drag_ != Drag::Select && drag_ != Drag::Guide &&+ !hideBrushCursor_ && radial_.menu < 0 && drag_ != Drag::Select && drag_ != Drag::Guide && // (no ring under a pie)(!ringOff || drag_ == Drag::Stroke || ctrlDown(inputMods())))drawBrushCursor();drawSelectionOverlay();diff --git a/src/app/App.h b/src/app/App.hindex cee1b3a5..63f294d7 100644--- a/src/app/App.h+++ b/src/app/App.h@@ -24,6 +24,7 @@#include "core/PenPredictor.h"#include "core/AutoUv.h"#include "core/QRemesh.h"+#include "core/RadialMenu.h"#include "core/Stroke.h"#include "core/StrokePath.h"#include "core/SurfaceCursor.h"@@ -1333,6 +1334,62 @@ private:bool untilLeave = false; // Space let go over the menu: it closes when the pointer leaves itint openedFrame = -1;} quickMenu_;+ // ---- Radial menus (RadialMenu.cpp, core/RadialMenu.h, #45) ----+ // Up to eight pie menus of up to eight actions each. A menu's key (action radial.menuN, set in the keymap like+ // any other) or its mouse / pen button, held: the pie shows at the cursor, a flick toward a slot and letting go+ // runs that action. Tapped: the pie stays open; click a slot (or beside the pie, or Esc, to close it). Edited in+ // Preferences > Input > Radial Menus; Store Config keeps them in ui.json ("radialMenus").+ enum class RadialHold { None, Key, Mouse, Pen };+ void registerRadialActions();+ void refreshRadialActions(); // the radial.menuN actions' labels follow the menus' names+ void applyRadialMenusJson(const Json& j); // ui.json's "radialMenus", checked against the registry+ void resetRadialMenus();+ static std::vector<RadialMenu> defaultRadialMenus();+ RadialVocabulary radialVocabulary() const; // what a menu read from a file may name+ bool radialSlotAction(std::string_view id) const; // an action a slot may run+ void openRadialMenu(int menu, RadialHold hold, int code);+ void closeRadialMenu() {+ radial_.menu = -1;+ radial_.hold = RadialHold::None;+ }+ void radialRelease(); // the key or button that holds the pie open was let go+ void runRadialSlot(int slot);+ bool radialMouseEvent(const SDL_Event& e); // true: the pie used the event (clicks while open, bound buttons)+ bool radialPenButton(int button, bool down, float x, float y);+ void radialKeyUp(SDL_Keycode key);+ int radialMenuForButton(RadialButton b) const; // -1: none+ PenAction penButtonAction(int button) const; // Preferences > Tablet, unless a radial menu claims the button+ void drawRadialMenu();+ void drawRadialMenusSection(); // Preferences > Input > Radial Menus+ void exportRadialMenuDialog(int menu);+ void importRadialMenuDialog();+ bool exportRadialMenu(int menu, const std::string& path);+ bool importRadialMenu(const std::string& path);+ std::vector<RadialMenu> radialMenus_ = defaultRadialMenus();+ struct RadialOpen {+ int menu = -1; // the open menu, or -1+ ImVec2 at{0, 0}; // its centre (the cursor when it opened)+ double openedAt = 0.0; // seconds (a short press is a tap)+ RadialHold hold = RadialHold::None; // what holds it open; None: tapped open, stays until a click or Esc+ int code = 0; // the held key (SDL_Keycode) or mouse / pen button+ int hover = -1; // the slot the pointer points at+ int openedFrame = -1;+ int ran = -1; // the slot run last (UI tests)+ } radial_;+ SDL_Keycode keyDown_ = SDLK_UNKNOWN; // the key onKey is handling: a radial menu's key holds the pie open+ uint32_t radialSwallowUp_ = 0; // mouse buttons whose press the pie took: their release is its too+ std::optional<Json> radialPending_; // radial menus read from ui.json before the actions existed+ struct RadialEdit {+ int menu = 0; // Preferences: the menu being edited+ int selected = -1; // the item whose label and icon show+ int pickSlot = -2; // the slot whose action is being picked (-1: a new slot; -2: none)+ char query[96] = ""; // the action search+ bool focusSearch = false;+ std::string foundQuery = "\x01"; // the search's results, for this query and registry revision+ unsigned foundRevision = ~0u;+ std::vector<size_t> found;+ int exportMenu = -1; // the menu the export dialog was opened for+ } radialEdit_;struct RightClick {bool pending = false; // a right press that hasn't moved past the slop: navigation waitsfloat x = 0.0f, y = 0.0f;diff --git a/src/app/Config.cpp b/src/app/Config.cppindex 31662fd3..3acb9cf0 100644--- a/src/app/Config.cpp+++ b/src/app/Config.cpp@@ -110,7 +110,7 @@ void fromJson(const Json& j, UiPrefs& p) {namespace {-enum UiFileKind { kSaveUi, kLoadUi, kRunScript, kLibraryFolder, kBlenderKeymap, kUiFileKinds };+enum UiFileKind { kSaveUi, kLoadUi, kRunScript, kLibraryFolder, kBlenderKeymap, kRadialImport, kRadialExport, kUiFileKinds };struct UiFileRequest {App* app = nullptr;@@ -127,6 +127,7 @@ void SDLCALL onUiFileChosen(void* userdata, const char* const* files, int) {const SDL_DialogFileFilter kUiFilters[] = {{"SculptForge UI layout", "json"}};const SDL_DialogFileFilter kBlenderKeymapFilters[] = {{"Blender keymap", "py"}, {"All files", "*"}};+const SDL_DialogFileFilter kRadialFilters[] = {{"SculptForge radial menu", "json"}};const SDL_DialogFileFilter kScriptFilters[] = {{"SculptForge script", "sfscript;txt"}, {"All files", "*"}};std::filesystem::path fsPath(const std::string& utf8) { return std::filesystem::path(std::u8string(utf8.begin(), utf8.end())); }@@ -517,6 +518,7 @@ void App::initActions() {actions_.registerCommands(commands_, [this](const std::string& name) { runCommand(name); },[this](const std::string& name) { consolePrefill(name + " "); });+ registerRadialActions(); // last: a radial menu's items may be any of the above (RadialMenu.cpp)if (!uiConfigDeterministic_ && !configDir_.empty()) {console_.loadHistory(configDir_ + "console_history.txt");@@ -616,6 +618,7 @@ bool App::writeUiConfig(const std::string& path, std::string& err) {j.set("layout", toJson(layout_));j.set("shortcuts", actions_.overridesToJson());j.set("prefs", toJson(uiPrefs_));+ j.set("radialMenus", toJson(radialMenus_));std::ofstream f(fsPath(path), std::ios::binary | std::ios::trunc);f << j.dump(true) << "\n";if (!f) {@@ -647,6 +650,7 @@ bool App::readUiConfig(const std::string& path, std::string& err) {layout_.customize = customize;actions_.overridesFromJson(j["shortcuts"]);fromJson(j["prefs"], uiPrefs_);+ if (j.has("radialMenus")) applyRadialMenusJson(j["radialMenus"]); // (an older file keeps the menus there are)applyPerformancePrefs();applyInputStyle();doc_.sculptor.dyntopo.constantDetail = uiPrefs_.dyntopoConstantDetail;@@ -673,6 +677,7 @@ void App::restoreStandardUi() {layout_ = standardLayout();layout_.customize = customize;actions_.clearOverrides();+ resetRadialMenus();layoutBaseline_ = layoutKey();status_ = "Standard UI restored - Store Config (Ctrl+Shift+I) to keep it";}@@ -697,6 +702,15 @@ void App::importBlenderKeymapDialog() {SDL_ShowOpenFileDialog(onUiFileChosen, &g_requests[kBlenderKeymap], window_, kBlenderKeymapFilters, 2, nullptr, false);}+void App::importRadialMenuDialog() {+ SDL_ShowOpenFileDialog(onUiFileChosen, &g_requests[kRadialImport], window_, kRadialFilters, 1, nullptr, false);+}++void App::exportRadialMenuDialog(int menu) {+ radialEdit_.exportMenu = menu;+ SDL_ShowSaveFileDialog(onUiFileChosen, &g_requests[kRadialExport], window_, kRadialFilters, 1, nullptr);+}+void App::loadUiDialog() {SDL_ShowOpenFileDialog(onUiFileChosen, &g_requests[kLoadUi], window_, kUiFilters, 1, nullptr, false);}@@ -807,6 +821,11 @@ void App::drawHelpConsoleUi() {}} else if (kind == kBlenderKeymap) {importBlenderKeymap(path);+ } else if (kind == kRadialImport) {+ importRadialMenu(path);+ } else if (kind == kRadialExport) {+ if (fsPath(path).extension().empty()) path += ".json";+ exportRadialMenu(radialEdit_.exportMenu, path);} else if (kind == kRunScript) {setConsoleOpen(true);console_.queueScriptFile(path);diff --git a/src/app/Input.cpp b/src/app/Input.cppindex 7cfe0fcf..59c62d06 100644--- a/src/app/Input.cpp+++ b/src/app/Input.cpp@@ -427,7 +427,8 @@ void App::drawInputSection() {"Free: the model turns about the screen's axes and can roll over the top, as in ZBrush. Turntable: it ""stays upright, as in Blender or Maya.","Preferences > Input");- drawSpaceMouseSection(); // SpaceMouse.cpp+ drawRadialMenusSection(); // RadialMenu.cpp+ drawSpaceMouseSection(); // SpaceMouse.cpp}void App::drawZIntensitySlider(const char* id) {diff --git a/src/app/RadialMenu.cpp b/src/app/RadialMenu.cppnew file mode 100644index 00000000..4bade484--- /dev/null+++ b/src/app/RadialMenu.cpp@@ -0,0 +1,644 @@+// SculptForge - open source digital sculpting+// SPDX-License-Identifier: GPL-3.0-or-later+//+// Radial (pie) menus (#45): the radial.menuN actions, opening a pie at the cursor from its key or a mouse / pen+// button, flick-and-release or tap-and-click, drawing it, and Preferences > Input > Radial Menus (menus, slots,+// labels, icons, import / export of one menu as a JSON file the user picks). A slot only names an action from the+// registry (the list the command palette searches); a menu file holds nothing that runs. The data, the slot+// geometry and the strict JSON reading are in core/RadialMenu.h.+#include "app/App.h"+#include "app/CommandPalette.h"+#include "app/Ui.h"++#include <IconsLucide.h>++#include <algorithm>+#include <cfloat>+#include <cmath>+#include <cstdio>+#include <filesystem>+#include <fstream>+#include <iterator>+#include <string>++namespace sf {++namespace {++constexpr double kRadialTapSeconds = 0.25; // let go sooner, in the middle: a tap, the pie stays open+constexpr float kRadialDeadZone = 22.0f; // pixels (times the UI scale) around the centre that pick nothing+constexpr float kRadialRadius = 104.0f; // the slots' centres from the pie's centre++// The icons a slot may show instead of its action's own (ui.json stores the name).+struct RadialIcon {+ const char* name;+ const char* glyph;+};+constexpr RadialIcon kRadialIcons[] = {+ {"brush", ICON_LC_BRUSH}, {"paintbrush", ICON_LC_PAINTBRUSH}, {"pen", ICON_LC_PEN_TOOL},+ {"feather", ICON_LC_FEATHER}, {"eraser", ICON_LC_ERASER}, {"square", ICON_LC_SQUARE},+ {"square_dashed", ICON_LC_SQUARE_DASHED}, {"lasso", ICON_LC_LASSO}, {"circle", ICON_LC_CIRCLE},+ {"circle_dot", ICON_LC_CIRCLE_DOT}, {"star", ICON_LC_STAR}, {"heart", ICON_LC_HEART},+ {"eye", ICON_LC_EYE}, {"eye_off", ICON_LC_EYE_OFF}, {"layers", ICON_LC_LAYERS},+ {"grid", ICON_LC_GRID_2X2}, {"shapes", ICON_LC_SHAPES}, {"move", ICON_LC_MOVE},+ {"rotate", ICON_LC_ROTATE_CW}, {"scale", ICON_LC_SCALE_3D}, {"scissors", ICON_LC_SCISSORS},+ {"wand", ICON_LC_WAND_SPARKLES}, {"flip", ICON_LC_FLIP_HORIZONTAL_2}, {"hand", ICON_LC_HAND},+ {"droplet", ICON_LC_DROPLET}, {"palette", ICON_LC_PALETTE}, {"box", ICON_LC_BOX},+ {"sparkles", ICON_LC_SPARKLES}, {"zap", ICON_LC_ZAP}, {"sun", ICON_LC_SUN},+ {"moon", ICON_LC_MOON}, {"undo", ICON_LC_UNDO_2}, {"redo", ICON_LC_REDO_2},+ {"crosshair", ICON_LC_CROSSHAIR}, {"camera", ICON_LC_CAMERA}, {"save", ICON_LC_SAVE},+ {"mountain", ICON_LC_MOUNTAIN}, {"waves", ICON_LC_WAVES}, {"spline", ICON_LC_SPLINE},+ {"target", ICON_LC_TARGET}, {"magnet", ICON_LC_MAGNET},+};++const char* radialIconGlyph(std::string_view name) {+ for (const RadialIcon& i : kRadialIcons)+ if (name == i.name) return i.glyph;+ return nullptr;+}++std::string radialActionId(int menu) { return "radial.menu" + std::to_string(menu + 1); }++ImVec4 col(ImU32 c) { return ImGui::ColorConvertU32ToFloat4(c); }++const char* const kDefaultKeys[] = {"T", "Y"}; // free in every input style (tests/ui/radial_menu.sfui checks)++} // namespace++std::vector<RadialMenu> App::defaultRadialMenus() {+ RadialMenu brushes;+ brushes.name = "Brushes";+ for (const char* id : {"brush.standard", "brush.claybuildup", "brush.move", "brush.damstandard", "brush.inflate",+ "brush.pinch", "brush.flatten", "brush.snakehook"})+ brushes.slots.push_back({id, "", ""});+ RadialMenu masking;+ masking.name = "Masking";+ for (const char* id : {"mask.invert", "mask.lasso", "mask.clear", "mask.rect", "mask.all", "mask.pen",+ "view.mask", "polygroup.group_masked"})+ masking.slots.push_back({id, std::string_view(id) == "view.mask" ? "View Mask" : "", ""}); // (its own: "Mask")+ return {brushes, masking};+}++bool App::radialSlotAction(std::string_view id) const {+ if (id.rfind("radial.", 0) == 0) return false; // no pie inside a pie+ const Action* a = actions_.find(id);+ if (!a || !a->run || a->label.empty()) return false;+ if (!a->command.empty()) // a command that needs parameters would only open the console+ if (const Command* c = commands_.find(a->command))+ for (const ParamSpec& p : c->params)+ if (p.required) return false;+ return true;+}++RadialVocabulary App::radialVocabulary() const {+ RadialVocabulary v;+ v.action = [this](std::string_view id) { return radialSlotAction(id); };+ v.icon = [](std::string_view name) { return radialIconGlyph(name) != nullptr; };+ return v;+}++void App::registerRadialActions() {+ for (int i = 0; i < kRadialMenus; ++i) {+ Action a;+ a.id = radialActionId(i);+ a.icon = ICON_LC_CHART_PIE;+ a.palette = "Preferences > Input > Radial Menus";+ a.shortcut = i < int(std::size(kDefaultKeys)) ? kDefaultKeys[i] : "";+ a.run = [this, i] {+ openRadialMenu(i, keyDown_ != SDLK_UNKNOWN ? RadialHold::Key : RadialHold::None, int(keyDown_));+ };+ a.checked = [this, i] { return radial_.menu == i; };+ actions_.add(std::move(a));+ }+ // The menus ui.json brought (read before the actions existed), checked against the registry now; the defaults+ // are checked too (an action may be missing from this build).+ int dropped = 0;+ radialMenus_ = radialMenusFromJson(radialPending_ ? *radialPending_ : toJson(radialMenus_), radialVocabulary(), &dropped);+ radialPending_.reset();+ if (dropped) SDL_Log("Radial menus: %d unknown or extra entries dropped", dropped);+ refreshRadialActions();+}++void App::refreshRadialActions() {+ for (int i = 0; i < kRadialMenus; ++i) {+ const Action* old = actions_.find(radialActionId(i));+ if (!old) continue;+ Action a = *old;+ const RadialMenu* m = i < int(radialMenus_.size()) ? &radialMenus_[size_t(i)] : nullptr;+ a.label = "Radial menu " + std::to_string(i + 1) + (m && !m->name.empty() ? ": " + m->name : std::string());+ a.description = m && !m->slots.empty()+ ? "Hold the key, flick toward an item and let go to run it; or tap the key and click one. "+ "Edit it in Preferences > Input > Radial Menus."+ : "Empty: give it items in Preferences > Input > Radial Menus.";+ a.enabled = [this, i] { return i < int(radialMenus_.size()) && !radialMenus_[size_t(i)].slots.empty(); };+ actions_.add(std::move(a));+ }+}++void App::applyRadialMenusJson(const Json& j) {+ if (actions_.find(radialActionId(0)) == nullptr) { // ui.json is read before the actions exist+ radialPending_ = j;+ return;+ }+ int dropped = 0;+ radialMenus_ = radialMenusFromJson(j, radialVocabulary(), &dropped);+ if (dropped) SDL_Log("Radial menus: %d unknown or extra entries dropped", dropped);+ closeRadialMenu();+ refreshRadialActions();+}++void App::resetRadialMenus() {+ applyRadialMenusJson(toJson(defaultRadialMenus()));+}++int App::radialMenuForButton(RadialButton b) const {+ if (b == RadialButton::None) return -1;+ for (size_t i = 0; i < radialMenus_.size(); ++i)+ if (radialMenus_[i].button == b && !radialMenus_[i].slots.empty()) return int(i);+ return -1;+}++PenAction App::penButtonAction(int button) const {+ if (button < 1 || button > kPenButtons) return PenAction::None;+ if (radialMenuForButton(RadialButton(int(RadialButton::PenLower) + button - 1)) >= 0) return PenAction::None;+ return uiPrefs_.tablet.buttons[size_t(button - 1)];+}++// ---------------------------------------------------------------------------+// Opening, flicking, clicking+// ---------------------------------------------------------------------------++void App::openRadialMenu(int menu, RadialHold hold, int code) {+ if (menu < 0 || menu >= int(radialMenus_.size()) || radialMenus_[size_t(menu)].slots.empty()) {+ status_ = "Radial menu " + std::to_string(menu + 1) + " is empty: Preferences > Input > Radial Menus";+ return;+ }+ if (radial_.menu == menu && radial_.hold == RadialHold::None) { // tapped open, its key again: close+ closeRadialMenu();+ return;+ }+ if (drag_ != Drag::None) return; // not in the middle of a stroke or a view drag+ quickMenu_.open = false;+ const float s = uiScale_;+ // Keep the whole pie on the canvas; the flick is measured from wherever its centre ends up.+ const CanvasRect c = canvasRect();+ const float mx = (kRadialRadius + 70.0f) * s, my = (kRadialRadius + 24.0f) * s;+ ImVec2 at(mouseX_, mouseY_);+ if (c.w > 2.0f * mx) at.x = std::clamp(at.x, c.x + mx, c.x + c.w - mx);+ if (c.h > 2.0f * my) at.y = std::clamp(at.y, c.y + my, c.y + c.h - my);+ radial_.menu = menu;+ radial_.at = at;+ radial_.openedAt = ImGui::GetTime();+ radial_.hold = hold;+ radial_.code = code;+ radial_.hover = -1;+ radial_.openedFrame = ImGui::GetFrameCount();+}++void App::radialRelease() {+ if (radial_.menu < 0) return;+ const int count = int(radialMenus_[size_t(radial_.menu)].slots.size());+ const int slot = radialSlotAt(mouseX_ - radial_.at.x, mouseY_ - radial_.at.y, count, kRadialDeadZone * uiScale_);+ if (slot >= 0) { // flicked toward a slot+ runRadialSlot(slot);+ return;+ }+ if (ImGui::GetTime() - radial_.openedAt < kRadialTapSeconds) { // a tap: stays open for a click+ radial_.hold = RadialHold::None;+ return;+ }+ closeRadialMenu(); // held and let go in the middle: nothing+}++void App::runRadialSlot(int slot) {+ if (radial_.menu < 0) return;+ const RadialMenu& m = radialMenus_[size_t(radial_.menu)];+ const std::string id = slot >= 0 && slot < int(m.slots.size()) ? m.slots[size_t(slot)].action : std::string();+ closeRadialMenu();+ const Action* a = actions_.find(id);+ if (!a || !a->run) return;+ if (a->enabled && !a->enabled()) {+ status_ = a->label + " isn't available right now";+ return;+ }+ radial_.ran = slot;+ a->run();+}++void App::radialKeyUp(SDL_Keycode key) {+ if (radial_.menu >= 0 && radial_.hold == RadialHold::Key && SDL_Keycode(radial_.code) == key) radialRelease();+}++bool App::radialMouseEvent(const SDL_Event& e) {+ if (e.type != SDL_EVENT_MOUSE_BUTTON_DOWN && e.type != SDL_EVENT_MOUSE_BUTTON_UP) return false;+ const int button = e.button.button;+ const uint32_t bit = button >= 0 && button < 32 ? 1u << button : 0u;+ if (e.type == SDL_EVENT_MOUSE_BUTTON_UP) {+ if (radial_.menu >= 0 && radial_.hold == RadialHold::Mouse && radial_.code == button) {+ mouseX_ = e.button.x;+ mouseY_ = e.button.y;+ radialSwallowUp_ &= ~bit;+ radialRelease();+ return true;+ }+ if (radialSwallowUp_ & bit) { // the press went to the pie: so does the release+ radialSwallowUp_ &= ~bit;+ return true;+ }+ return false;+ }+ if (radial_.menu >= 0) {+ // Open: a left click (mouse or pen tip) on a slot runs it; any other click, or one in the middle or beside+ // the pie, closes it. The click never reaches the canvas or the panels under the pie.+ radialSwallowUp_ |= bit;+ if (radial_.hold == RadialHold::Mouse && radial_.code == button) return true;+ if (button == SDL_BUTTON_LEFT) {+ const int count = int(radialMenus_[size_t(radial_.menu)].slots.size());+ const int slot = radialSlotAt(e.button.x - radial_.at.x, e.button.y - radial_.at.y, count,+ kRadialDeadZone * uiScale_);+ const float r = (kRadialRadius + 70.0f) * uiScale_;+ const float dx = e.button.x - radial_.at.x, dy = e.button.y - radial_.at.y;+ if (slot >= 0 && dx * dx + dy * dy <= r * r) {+ runRadialSlot(slot);+ return true;+ }+ }+ closeRadialMenu();+ return true;+ }+ if (e.button.which == SDL_PEN_MOUSEID) return false; // pen buttons come through radialPenButton+ const RadialButton b = button == SDL_BUTTON_MIDDLE ? RadialButton::MouseMiddle+ : button == SDL_BUTTON_X1 ? RadialButton::MouseBack+ : button == SDL_BUTTON_X2 ? RadialButton::MouseForward+ : RadialButton::None;+ const int menu = radialMenuForButton(b);+ if (menu < 0 || ImGui::GetIO().WantCaptureMouse || !canvasRect().contains(e.button.x, e.button.y)) return false;+ mouseX_ = e.button.x;+ mouseY_ = e.button.y;+ radialSwallowUp_ |= bit;+ openRadialMenu(menu, RadialHold::Mouse, button);+ return true;+}++bool App::radialPenButton(int button, bool down, float x, float y) {+ if (button < 1 || button > kPenButtons) return false;+ const int menu = radialMenuForButton(RadialButton(int(RadialButton::PenLower) + button - 1));+ if (down) {+ if (menu < 0) return false;+ if (radial_.menu < 0 && !ImGui::GetIO().WantCaptureMouse && canvasRect().contains(x, y)) {+ mouseX_ = x;+ mouseY_ = y;+ openRadialMenu(menu, RadialHold::Pen, button);+ }+ return true; // the button belongs to the menu, not to its Preferences > Tablet mapping+ }+ if (radial_.menu >= 0 && radial_.hold == RadialHold::Pen && radial_.code == button) {+ mouseX_ = x;+ mouseY_ = y;+ radialRelease();+ return true;+ }+ return menu >= 0;+}++// ---------------------------------------------------------------------------+// Drawing+// ---------------------------------------------------------------------------++void App::drawRadialMenu() {+ if (radial_.menu < 0) return;+ if (radial_.menu >= int(radialMenus_.size()) || radialMenus_[size_t(radial_.menu)].slots.empty()) {+ closeRadialMenu();+ return;+ }+ if (ImGui::IsKeyPressed(ImGuiKey_Escape, false)) {+ closeRadialMenu();+ return;+ }+ const RadialMenu& m = radialMenus_[size_t(radial_.menu)];+ const float s = uiScale_;+ const int count = int(m.slots.size());+ const ImVec2 c = radial_.at;+ radial_.hover = radialSlotAt(mouseX_ - c.x, mouseY_ - c.y, count, kRadialDeadZone * s);+ ImDrawList* dl = ImGui::GetForegroundDrawList();+ const float dead = kRadialDeadZone * s, radius = kRadialRadius * s;+ // The centre: the dead zone, the menu's name, and a line toward the pointer once it leaves the dead zone.+ dl->AddCircleFilled(c, radius * 0.42f, IM_COL32(0x1b, 0x1b, 0x1d, 0x90), 48);+ dl->AddCircle(c, dead, IM_COL32(0x8c, 0x8c, 0x90, 0xa0), 32, 1.5f * s);+ if (radial_.hover >= 0) {+ float x = 0.0f, y = 0.0f;+ radialSlotDirection(radial_.hover, count, x, y);+ dl->AddLine(ImVec2(c.x + x * dead, c.y + y * dead), ImVec2(c.x + x * radius * 0.6f, c.y + y * radius * 0.6f),+ ui::color::accent, 2.5f * s);+ }+ if (!m.name.empty()) {+ const ImVec2 ts = ImGui::CalcTextSize(m.name.c_str());+ dl->AddText(ImVec2(c.x - ts.x * 0.5f, c.y + dead + 4.0f * s), ui::color::textDim, m.name.c_str());+ }+ for (int i = 0; i < count; ++i) {+ const RadialSlot& slot = m.slots[size_t(i)];+ const Action* a = actions_.find(slot.action);+ const std::string& label = !slot.label.empty() ? slot.label : a ? a->label : slot.action;+ const char* icon = !slot.icon.empty() ? radialIconGlyph(slot.icon) : a ? a->icon : nullptr;+ const bool enabled = a && (!a->enabled || a->enabled());+ const bool checked = a && a->checked && a->checked();+ float x = 0.0f, y = 0.0f;+ radialSlotDirection(i, count, x, y);+ const ImVec2 p(c.x + x * radius, c.y + y * radius);+ const float iconW = icon ? ImGui::GetFontSize() + 6.0f * s : 0.0f;+ const ImVec2 ts = ImGui::CalcTextSize(label.c_str());+ const float w = ts.x + iconW + 20.0f * s, h = ts.y + 14.0f * s;+ // Labels lean away from the centre: the ones on the right grow rightward, on the left leftward.+ const float left = std::abs(x) < 0.2f ? p.x - w * 0.5f : x > 0.0f ? p.x - 18.0f * s : p.x - w + 18.0f * s;+ const ImVec2 a0(left, p.y - h * 0.5f), a1(left + w, p.y + h * 0.5f);+ const bool hot = i == radial_.hover;+ dl->AddRectFilled(a0, a1, hot ? IM_COL32(0x3a, 0x30, 0x28, 0xf8) : IM_COL32(0x25, 0x25, 0x28, 0xf2), h * 0.5f);+ dl->AddRect(a0, a1, hot ? ui::color::accent : checked ? IM_COL32(0xf0, 0x88, 0x2e, 0x80) : ui::color::border,+ h * 0.5f, 0, hot ? 2.0f * s : 1.0f);+ const ImU32 fg = !enabled ? ui::color::textDim : hot ? IM_COL32(0xff, 0xff, 0xff, 0xff) : ui::color::text;+ float tx = a0.x + 10.0f * s;+ if (icon) {+ dl->AddText(ImVec2(tx, a0.y + 7.0f * s), hot || checked ? ui::color::accent : ui::color::textDim, icon);+ tx += iconW;+ }+ dl->AddText(ImVec2(tx, a0.y + 7.0f * s), fg, label.c_str());+ }+}++// ---------------------------------------------------------------------------+// Import / export+// ---------------------------------------------------------------------------++bool App::exportRadialMenu(int menu, const std::string& path) {+ if (menu < 0 || menu >= int(radialMenus_.size())) return false;+ std::ofstream f(std::filesystem::path(std::u8string(path.begin(), path.end())), std::ios::binary | std::ios::trunc);+ f << radialMenuFileText(radialMenus_[size_t(menu)]);+ if (!f) {+ status_ = "Could not write " + path;+ return false;+ }+ status_ = "Radial menu saved to " + path;+ return true;+}++bool App::importRadialMenu(const std::string& path) {+ const std::filesystem::path p(std::u8string(path.begin(), path.end()));+ std::error_code ec;+ const auto size = std::filesystem::file_size(p, ec);+ if (ec || !std::filesystem::is_regular_file(p, ec)) {+ status_ = "Could not read " + path;+ return false;+ }+ if (size > kRadialFileMax) { // refused unread+ status_ = "That file is too big for a radial menu";+ return false;+ }+ std::ifstream f(p, std::ios::binary);+ std::string text(kRadialFileMax + 1, '\0'); // never more than the cap, even if the file grew since+ f.read(text.data(), std::streamsize(text.size()));+ text.resize(size_t(std::max<std::streamsize>(f.gcount(), 0)));+ RadialMenu menu;+ std::string err;+ int dropped = 0;+ if (!f.is_open() || !parseRadialMenuFile(text, radialVocabulary(), menu, err, &dropped)) {+ status_ = err.empty() ? "Could not read " + path : err;+ return false;+ }+ // Into the menu being edited when it's empty, otherwise a new one.+ int at = radialEdit_.menu;+ if (at < 0 || at >= int(radialMenus_.size()) || !radialMenus_[size_t(at)].slots.empty()) {+ if (int(radialMenus_.size()) >= kRadialMenus) {+ status_ = "Eight radial menus already: clear one first";+ return false;+ }+ radialMenus_.emplace_back();+ at = int(radialMenus_.size()) - 1;+ }+ radialMenus_[size_t(at)] = std::move(menu);+ radialEdit_.menu = at;+ refreshRadialActions();+ status_ = "Radial menu " + std::to_string(at + 1) + " imported" ++ (dropped ? " (" + std::to_string(dropped) + " unknown items left out)" : std::string()) ++ " - Store Config keeps it";+ return true;+}++// ---------------------------------------------------------------------------+// Preferences > Input > Radial Menus+// ---------------------------------------------------------------------------++void App::drawRadialMenusSection() {+ const char* path = "Preferences > Input > Radial Menus";+ ImGui::Spacing();+ ImGui::SeparatorText("Radial Menus");+ ui::HelpText("Radial Menus", nullptr,+ "Pie menus of your own: hold a menu's key (or its mouse or pen button), flick toward an item and let "+ "go to run it. Tap the key instead and the pie stays open: click an item, or beside the pie to close "+ "it. Up to 8 menus of 8 items; an item is anything the command palette (F3) finds.",+ path);+ if (radialMenus_.empty()) radialEdit_.menu = -1;+ radialEdit_.menu = std::clamp(radialEdit_.menu, radialMenus_.empty() ? -1 : 0, int(radialMenus_.size()) - 1);+ auto menuTitle = [&](int i) {+ const RadialMenu& m = radialMenus_[size_t(i)];+ const std::string key = actions_.shortcutText(radialActionId(i));+ return std::to_string(i + 1) + " " + (m.name.empty() ? std::string(m.slots.empty() ? "(empty)" : "Menu") : m.name) ++ (key.empty() ? std::string() : " (" + key + ")");+ };+ const float addW = ImGui::GetFrameHeight() * 1.2f;+ ImGui::SetNextItemWidth(-(addW + ImGui::GetStyle().ItemSpacing.x));+ if (ImGui::BeginCombo("##radial.menu", radialEdit_.menu >= 0 ? menuTitle(radialEdit_.menu).c_str() : "No menus")) {+ for (int i = 0; i < int(radialMenus_.size()); ++i)+ if (ImGui::Selectable((menuTitle(i) + "###radialmenu" + std::to_string(i + 1)).c_str(), i == radialEdit_.menu))+ radialEdit_.menu = i, radialEdit_.pickSlot = -2, radialEdit_.selected = -1;+ ImGui::EndCombo();+ }+ ImGui::SameLine();+ ImGui::BeginDisabled(int(radialMenus_.size()) >= kRadialMenus);+ if (ImGui::Button(ICON_LC_PLUS "###radial.add_menu", ImVec2(addW, 0))) {+ radialMenus_.emplace_back();+ radialMenus_.back().name = "Menu " + std::to_string(radialMenus_.size());+ radialEdit_.menu = int(radialMenus_.size()) - 1;+ radialEdit_.pickSlot = -1; // straight to picking its first item+ radialEdit_.selected = -1;+ radialEdit_.query[0] = 0;+ radialEdit_.focusSearch = true;+ refreshRadialActions();+ }+ ImGui::EndDisabled();+ ui::HelpText("Add menu", nullptr, "A new radial menu (up to 8). Give it a key, then items.", path);++ if (radialEdit_.menu >= 0) {+ const int mi = radialEdit_.menu;+ RadialMenu& m = radialMenus_[size_t(mi)];+ ImGui::PushID(mi);+ // Name.+ char name[kRadialNameMax + 1];+ std::snprintf(name, sizeof name, "%s", m.name.c_str());+ ImGui::SetNextItemWidth(-FLT_MIN);+ if (ImGui::InputTextWithHint("##radial.name", "Name", name, sizeof name)) {+ m.name = radialCleanText(name, kRadialNameMax);+ refreshRadialActions();+ }+ // Key (the keymap's, like any action's) and button.+ ImGui::TextDisabled("Key");+ ImGui::SameLine();+ const std::string id = radialActionId(mi);+ const std::string key = actions_.shortcutText(id);+ if (ImGui::Button(((key.empty() ? std::string("Set key") : key) + "###radial.key").c_str()))+ beginShortcutCapture(id);+ ui::HelpText("Key", nullptr,+ "Click, then press the key that opens this menu (Esc cancels, Backspace clears). A key another "+ "action has moves here. Preferences > Hotkeys lists it too.",+ path);+ ImGui::SameLine();+ ImGui::SetNextItemWidth(-FLT_MIN);+ if (ImGui::BeginCombo("##radial.button", radialButtonLabel(m.button))) {+ for (int b = 0; b < int(RadialButton::Count); ++b)+ if (ImGui::Selectable(radialButtonLabel(RadialButton(b)), int(m.button) == b)) m.button = RadialButton(b);+ ImGui::EndCombo();+ }+ ui::HelpText("Button", nullptr,+ "A mouse or pen button that opens this menu while held, besides the key. It then stops doing "+ "what it did before (a pen button's Preferences > Tablet mapping, the middle button's pan).",+ path);++ // Items: one row each (the action, up / down / remove); the selected one also shows its own label and icon,+ // and Change action.+ const float rowH = ImGui::GetFrameHeight();+ const float spacing = ImGui::GetStyle().ItemSpacing.x;+ for (int i = 0; i < int(m.slots.size()); ++i) {+ RadialSlot& slot = m.slots[size_t(i)];+ const Action* a = actions_.find(slot.action);+ const bool selected = radialEdit_.selected == i;+ ImGui::PushID(i);+ const char* glyph = !slot.icon.empty() ? radialIconGlyph(slot.icon) : a ? a->icon : nullptr;+ const std::string shown = !slot.label.empty() ? slot.label : a ? a->label : slot.action;+ const std::string text = std::to_string(i + 1) + " " + (glyph ? std::string(glyph) + " " : std::string()) + shown;+ if (selected) ImGui::PushStyleColor(ImGuiCol_Button, ImGui::GetStyleColorVec4(ImGuiCol_ButtonActive));+ if (ImGui::Button((text + "###radial.slot").c_str(), ImVec2(ImGui::GetContentRegionAvail().x - 3.0f * (rowH + spacing), 0)))+ radialEdit_.selected = selected ? -1 : i, radialEdit_.pickSlot = -2;+ if (selected) ImGui::PopStyleColor();+ ui::HelpText("Item", nullptr, "Click to change its label, icon or action.", path);+ ImGui::SameLine();+ int move = 0;+ ImGui::BeginDisabled(i == 0);+ if (ImGui::Button(ICON_LC_CHEVRON_UP "##radial.up", ImVec2(rowH, 0))) move = -1;+ ImGui::EndDisabled();+ ImGui::SameLine();+ ImGui::BeginDisabled(i + 1 == int(m.slots.size()));+ if (ImGui::Button(ICON_LC_CHEVRON_DOWN "##radial.down", ImVec2(rowH, 0))) move = 1;+ ImGui::EndDisabled();+ ImGui::SameLine();+ const bool remove = ImGui::Button(ICON_LC_X "##radial.remove", ImVec2(rowH, 0));+ if (selected) {+ ImGui::Indent(rowH * 0.5f);+ char label[kRadialLabelMax + 1];+ std::snprintf(label, sizeof label, "%s", slot.label.c_str());+ const float iconW = 2.6f * rowH;+ ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x - iconW - spacing);+ if (ImGui::InputTextWithHint("##radial.label", a ? a->label.c_str() : "Label", label, sizeof label))+ slot.label = radialCleanText(label, kRadialLabelMax);+ ui::HelpText("Label", nullptr, "What the pie shows for it; empty: the action's own name.", path);+ ImGui::SameLine();+ ImGui::SetNextItemWidth(iconW);+ if (ImGui::BeginCombo("##radial.icon", glyph ? glyph : "-")) {+ if (ImGui::Selectable("Action's own###radial.icon_none", slot.icon.empty())) slot.icon.clear();+ for (const RadialIcon& ic : kRadialIcons)+ if (ImGui::Selectable((std::string(ic.glyph) + " " + ic.name + "###radial.icon." + ic.name).c_str(),+ slot.icon == ic.name))+ slot.icon = ic.name;+ ImGui::EndCombo();+ }+ ui::HelpText("Icon", nullptr, "The icon the pie shows for it.", path);+ if (ImGui::Button(ICON_LC_SEARCH " Change action###radial.change", ImVec2(-FLT_MIN, 0))) {+ radialEdit_.pickSlot = radialEdit_.pickSlot == i ? -2 : i;+ radialEdit_.query[0] = 0;+ radialEdit_.focusSearch = true;+ }+ ImGui::Unindent(rowH * 0.5f);+ }+ ImGui::PopID();+ if (remove) {+ m.slots.erase(m.slots.begin() + i);+ radialEdit_.pickSlot = -2;+ radialEdit_.selected = -1;+ break;+ }+ if (move) {+ std::swap(m.slots[size_t(i)], m.slots[size_t(i + move)]);+ radialEdit_.pickSlot = -2;+ if (selected) radialEdit_.selected = i + move;+ break;+ }+ }+ if (int(m.slots.size()) < kRadialSlots && ImGui::Button(ICON_LC_PLUS " Add item###radial.add_slot", ImVec2(-FLT_MIN, 0))) {+ radialEdit_.pickSlot = radialEdit_.pickSlot == -1 ? -2 : -1;+ radialEdit_.query[0] = 0;+ radialEdit_.focusSearch = true;+ }++ // Picking an action: the command palette's search, in place.+ if (radialEdit_.pickSlot >= -1) {+ ImGui::SetNextItemWidth(-FLT_MIN);+ if (radialEdit_.focusSearch) ImGui::SetKeyboardFocusHere();+ radialEdit_.focusSearch = false;+ ImGui::InputTextWithHint("##radial.search", ICON_LC_SEARCH " Search actions", radialEdit_.query,+ sizeof radialEdit_.query);+ if (radialEdit_.foundQuery != radialEdit_.query || radialEdit_.foundRevision != actions_.revision()) {+ radialEdit_.foundQuery = radialEdit_.query;+ radialEdit_.foundRevision = actions_.revision();+ radialEdit_.found = CommandPalette::find(*this, radialEdit_.query, 8,+ [this](const Action& a) { return radialSlotAction(a.id); });+ }+ const std::vector<size_t> found = radialEdit_.found; // (picking one changes the registry's labels)+ const auto& all = actions_.all();+ for (size_t k : found) {+ const Action& a = all[k];+ const std::string row = std::string(a.icon ? a.icon : ICON_LC_CHEVRON_RIGHT) + " " + a.label + "###radial.pick." + a.id;+ if (ImGui::Selectable(row.c_str(), false, ImGuiSelectableFlags_NoAutoClosePopups)) {+ if (radialEdit_.pickSlot >= 0 && radialEdit_.pickSlot < int(m.slots.size()))+ m.slots[size_t(radialEdit_.pickSlot)] = {a.id, "", ""};+ else if (int(m.slots.size()) < kRadialSlots)+ m.slots.push_back({a.id, "", ""});+ radialEdit_.pickSlot = -2;+ refreshRadialActions();+ }+ if (ImGui::IsItemHovered() && !a.palette.empty()) ImGui::SetTooltip("%s", a.palette.c_str());+ }+ if (found.empty()) ImGui::TextDisabled("No matching actions");+ }++ // Import / export / clear.+ ImGui::Spacing();+ const float third = (ImGui::GetContentRegionAvail().x - 2.0f * ImGui::GetStyle().ItemSpacing.x) / 3.0f;+ if (ImGui::Button("Export...##radial.export", ImVec2(third, 0))) exportRadialMenuDialog(mi);+ ui::HelpText("Export", nullptr, "Save this menu as a .json file to share or keep (action names only).", path);+ ImGui::SameLine();+ if (ImGui::Button("Import...##radial.import", ImVec2(third, 0))) importRadialMenuDialog();+ ui::HelpText("Import", nullptr,+ "Load a menu someone exported. Only action names are read; ones this version doesn't have are "+ "left out. Goes into this menu if it's empty, otherwise into a new one.",+ path);+ ImGui::SameLine();+ if (ImGui::Button("Clear##radial.clear", ImVec2(third, 0))) {+ m = RadialMenu();+ while (!radialMenus_.empty() && radialMenus_.back().slots.empty() && radialMenus_.back().name.empty())+ radialMenus_.pop_back(); // empty menus at the end go; one in the middle keeps its place (and key)+ radialEdit_.pickSlot = -2;+ refreshRadialActions();+ }+ ui::HelpText("Clear", nullptr, "Empty this menu. Its key stays; an empty menu does nothing.", path);+ ImGui::PopID();+ } else if (ImGui::Button("Import...##radial.import", ImVec2(-FLT_MIN, 0))) {+ importRadialMenuDialog();+ }+ if (ImGui::Button("Restore default menus##radial.defaults", ImVec2(-FLT_MIN, 0))) {+ resetRadialMenus();+ radialEdit_ = RadialEdit();+ status_ = "Default radial menus restored - Store Config (Ctrl+Shift+I) keeps them";+ }+ ui::HelpText("Restore default menus", nullptr, "Back to the two built-in menus: Brushes (T) and Masking (Y).", path);+ ImGui::TextColored(col(ui::color::textDim), "Store Config keeps them");+}++} // namespace sfdiff --git a/src/app/Tablet.cpp b/src/app/Tablet.cppindex ebc01930..017d3d06 100644--- a/src/app/Tablet.cpp+++ b/src/app/Tablet.cpp@@ -110,8 +110,9 @@ void App::penButton(int button, bool down, float x, float y) {if (((penButtons_ & bit) != 0) == down) return;penButtons_ = down ? penButtons_ | bit : penButtons_ & ~bit;penSeen_ = true;+ if (radialPenButton(button, down, x, y)) return; // a radial menu's button (RadialMenu.cpp)// Invert and Smooth need nothing here: inputMods() reports them as Alt / Shift while held.- const PenAction a = button <= kPenButtons ? uiPrefs_.tablet.buttons[size_t(button - 1)] : PenAction::None;+ const PenAction a = penButtonAction(button);if (a != PenAction::RotateView && a != PenAction::PanView && a != PenAction::RightClick) return;ImGuiIO& io = ImGui::GetIO();if (a == PenAction::RightClick) { // context menus and right-click items in the UI@@ -142,11 +143,12 @@ void App::penButton(int button, bool down, float x, float y) {void App::penLeft() {// A pen lifted out of range mid-stroke: finish the stroke (one undo step) instead of leaving it open.+ if (radial_.hold == RadialHold::Pen) closeRadialMenu(); // a pen button held a radial menu openif (drag_ != Drag::None && dragFromPen_) onMouseUp();ImGuiIO& io = ImGui::GetIO();if (penTouching_) io.AddMouseButtonEvent(ImGuiMouseButton_Left, false);for (int b = 1; b <= kPenButtons; ++b)- if ((penButtons_ & (1u << b)) && uiPrefs_.tablet.buttons[size_t(b - 1)] == PenAction::RightClick)+ if ((penButtons_ & (1u << b)) && penButtonAction(b) == PenAction::RightClick)io.AddMouseButtonEvent(ImGuiMouseButton_Right, false);penInProximity_ = penTouching_ = penEraser_ = false;penButtons_ = 0;@@ -171,7 +173,7 @@ SDL_Keymod App::inputMods() const {}for (int b = 1; b <= kPenButtons; ++b) {if (!(penButtons_ & (1u << b))) continue;- const PenAction a = uiPrefs_.tablet.buttons[size_t(b - 1)];+ const PenAction a = penButtonAction(b);if (a == PenAction::Invert) mods |= SDL_KMOD_LALT;else if (a == PenAction::Smooth) mods |= SDL_KMOD_LSHIFT;}diff --git a/src/app/UiTest.cpp b/src/app/UiTest.cppindex cbc571c6..542fd29c 100644--- a/src/app/UiTest.cpp+++ b/src/app/UiTest.cpp@@ -11,6 +11,10 @@// snapped onto the sculpt like stroke), e.g. to show the brush cursor// hover_window X Y [S] the same to window fractions (anywhere, e.g. the background)// type LABEL TEXT click a text field and type into it+// radial_import FILE import a radial menu file (from the shots folder if radial_export wrote it there,+// otherwise relative to the script), as Import... would+// radial_export N FILE export radial menu N (1-based) to FILE in the shots folder, as Export... would+// key_down KEY / key_up KEY press a key and keep it down / let go of it (key presses and lets go), e.g. key_down t// key COMBO e.g. enter, escape, ctrl+z, ctrl+shift+z, 3, comma, backtick, tab, f3, space, minus,// home, numpad1, ctrl+numpad7, numpad., numpadplus// hold MODS ctrl / shift / alt / ctrl+shift ... or none (for strokes and drags)@@ -104,7 +108,9 @@// 2 DragDot, 3 Spray, 4 LazyMouse), vdms (VDM brush maps), vdm_files (.sfvdm in the library)// z_intensity, smooth_intensity, rgb_intensity (0-100), focal_shift (-100..100), draw_size,// size_popup_open (the S / U / I / O slider), size_knob_x / size_knob_y (its knob, pixels),-// quickmenu_open, right_click_menu, lazy_mouse, input_style (0 ZBrush, 1 SculptForge, 2 Blender), turntable,+// quickmenu_open, right_click_menu, radial_open / radial_menu (-1 none) / radial_held /+// radial_hover / radial_ran (radial menus: open, the menu, held by its key or button, the+// slot pointed at, the slot run last), radial_menus, radial_slots_N, lazy_mouse, input_style (0 ZBrush, 1 SculptForge, 2 Blender), turntable,// camera_ortho, mask_brush (Blender's Mask brush on), shortcut_conflicts (keys two actions// claim), brush_type (BrushType// index, -1 for a custom brush or Paint), last_dab_x / last_dab_y (window pixels), paint_r@@ -404,6 +410,16 @@ double Demo::query(const std::string& name, bool& known) const {if (name == "draw_size") return std::round(app_.radiusPx_);if (name == "quickmenu_open") return app_.quickMenu_.open ? 1.0 : 0.0;if (name == "right_click_menu") return app_.uiPrefs_.rightClickQuickMenu ? 1.0 : 0.0;+ if (name == "radial_open") return app_.radial_.menu >= 0 ? 1.0 : 0.0;+ if (name == "radial_menu") return double(app_.radial_.menu); // -1: none open+ if (name == "radial_held") return app_.radial_.menu >= 0 && app_.radial_.hold != App::RadialHold::None ? 1.0 : 0.0;+ if (name == "radial_hover") return double(app_.radial_.hover);+ if (name == "radial_ran") return double(app_.radial_.ran); // the slot run last, -1: none yet+ if (name == "radial_menus") return double(app_.radialMenus_.size());+ if (name.rfind("radial_slots_", 0) == 0) { // radial_slots_N: menu N's items (1-based), -1: no such menu+ const size_t i = size_t(std::max(0, std::atoi(name.c_str() + 13) - 1));+ return i < app_.radialMenus_.size() ? double(app_.radialMenus_[i].slots.size()) : -1.0;+ }if (name == "size_popup_open" || name == "size_knob_x" || name == "size_knob_y") {ImVec2 knob(-1.0f, -1.0f);const bool open = PickerUi::sliderKnob(knob);@@ -799,6 +815,24 @@ bool Demo::parseStep(int line, const std::vector<std::string>& w, std::string& e} else if (verb == "key") {if (!need(1)) return false;testKey(line, w[1]);+ } else if (verb == "key_down" || verb == "key_up") { // press a key and keep it down / let go of it+ if (!need(1)) return false;+ const SDL_Keycode key = SDL_GetKeyFromName(w[1].c_str());+ if (key == SDLK_UNKNOWN) {+ error = "unknown key \"" + w[1] + "\"";+ return false;+ }+ run([this, key, down = verb == "key_down"] {+ SDL_Event e{};+ e.type = down ? SDL_EVENT_KEY_DOWN : SDL_EVENT_KEY_UP;+ e.key.windowID = SDL_GetWindowID(app_.window_);+ e.key.key = key;+ e.key.scancode = SDL_GetScancodeFromKey(key, nullptr);+ e.key.mod = held_;+ e.key.down = down;+ app_.handleEvent(e);+ });+ wait(0.05f);} else if (verb == "hold") {if (!need(1)) return false;const SDL_Keymod mods = w[1] == "none" ? SDL_KMOD_NONE : parseMods(w[1]);@@ -1119,6 +1153,26 @@ bool Demo::parseStep(int line, const std::vector<std::string>& w, std::string& eif (file.is_relative()) file = std::filesystem::path(std::u8string(scriptDir_.begin(), scriptDir_.end())) / file;const auto u8 = file.lexically_normal().u8string();run([this, path = std::string(u8.begin(), u8.end())] { app_.openPathConfirmed(path); });+ } else if (verb == "radial_import" || verb == "radial_export") {+ // radial_import FILE (relative to the script) / radial_export N FILE (in the shots folder): what the file+ // dialogs of Preferences > Input > Radial Menus do with the path the user picked.+ const bool import = verb == "radial_import";+ if (!need(import ? 1 : 2)) return false;+ const std::string name = w[import ? 1 : 2];+ run([this, line, import, name, menu = int(num(1, 1)) - 1] {+ auto file = std::filesystem::path(std::u8string(name.begin(), name.end()));+ if (file.is_relative()) { // an import reads what radial_export wrote, or else a file beside the script+ const auto out = std::filesystem::path(std::u8string(shotDir_.begin(), shotDir_.end())) / file;+ std::error_code ec;+ file = !import || std::filesystem::exists(out, ec)+ ? out+ : std::filesystem::path(std::u8string(scriptDir_.begin(), scriptDir_.end())) / file;+ }+ const auto u8 = file.lexically_normal().u8string();+ const std::string path(u8.begin(), u8.end());+ const bool ok = import ? app_.importRadialMenu(path) : app_.exportRadialMenu(menu, path);+ if (!ok) fail(line, std::string(import ? "radial_import" : "radial_export") + " failed: " + app_.status_);+ });} else if (verb == "copy") {if (!need(2)) return false;namespace fs = std::filesystem;diff --git a/tests/ui/data/radial/sculpting.json b/tests/ui/data/radial/sculpting.jsonnew file mode 100644index 00000000..ace38292--- /dev/null+++ b/tests/ui/data/radial/sculpting.json@@ -0,0 +1,17 @@+{+ "format": "sculptforge-radial-menu",+ "version": 1,+ "menu": {+ "name": "Sculpting\n\u001b[31m with a name far longer than any menu needs to have",+ "button": "mouse_middle",+ "slots": [+ {"action": "brush.smooth", "label": "Smooth it", "icon": "waves"},+ {"action": "cmd.blender_keymap_import", "label": "needs a path: left out"},+ {"action": "no.such.action"},+ {"action": "brush.inflate", "icon": "../../not-an-icon"},+ {"action": 12},+ "brush.move",+ {"action": "brush.pinch"}+ ]+ }+}diff --git a/tests/ui/radial_menu.sfui b/tests/ui/radial_menu.sfuinew file mode 100644index 00000000..7a109946--- /dev/null+++ b/tests/ui/radial_menu.sfui@@ -0,0 +1,174 @@+# Radial (pie) menus (#45). Two built in: Brushes on T and Masking on Y, keys no other action has in any input+# style. Hold the key, flick toward an item, let go: it runs. Let go in the middle after a moment: nothing. Tap+# the key: the pie stays open; a click on an item runs it, a click in the middle or Esc closes it, and the click+# never reaches the model. A pen or mouse button set on a menu does the same as its key. Preferences > Input >+# Radial Menus: a new menu, an item picked with the palette's search, a key; import and export of one menu (only+# known actions are kept).+run new_sphere subdivisions=3+camera 0 0+expect_value radial_menus == 2+expect_value radial_slots_1 == 8+expect_value radial_slots_2 == 8+expect_shortcut radial.menu1 T+expect_shortcut radial.menu2 Y+expect_value radial_ran == -1+expect_value shortcut_conflicts == 0++# Hold T, flick right, let go: slot 2 of Brushes, Move.+hover_window 0.5 0.5+key_down t+expect_value radial_open == 1+expect_value radial_held == 1+expect_value radial_menu == 0+expect_value radial_hover == -1+shot brushes_open+hover_window 0.57 0.5 0.15+expect_value radial_hover == 2+shot brushes_flick+key_up t+expect_value radial_open == 0+expect_value radial_ran == 2+expect_value brush_type == 3++# Flick up: Standard.+hover_window 0.5 0.5+key_down t+hover_window 0.5 0.4 0.1+expect_value radial_hover == 0+key_up t+expect_value radial_open == 0+expect_value brush_type == 0++# Held, then let go in the middle: it closes and nothing runs.+hover_window 0.5 0.5+key_down t+wait 0.4+key_up t+expect_value radial_open == 0+expect_value radial_ran == 0+expect_value brush_type == 0++# Tapped: it stays open. A click down and to the left (slot 5, Pinch) runs it; the model isn't touched.+snapshot+key t+expect_value radial_open == 1+expect_value radial_held == 0+drag 0.43 0.57 0.43 0.57 0.05+expect_value radial_open == 0+expect_value brush_type == 7+expect_value stroking == 0+expect_value moved == 0++# Tapped, then a click in the middle closes it (no stroke either); Esc closes it; its key again closes it.+hover_window 0.5 0.5+key t+drag 0.5 0.5 0.5 0.5 0.05+expect_value radial_open == 0+expect_value moved == 0+expect_value brush_type == 7+key t+key escape+expect_value radial_open == 0+key t+key_down t+expect_value radial_open == 0+key_up t+expect_value brush_type == 7++# Masking (Y): flick up for Invert Mask, the whole sphere is masked; again, and none is.+expect_value masked == 0+hover_window 0.5 0.5+key_down y+expect_value radial_menu == 1+hover_window 0.5 0.4 0.1+key_up y+expect_value masked > 100+hover_window 0.5 0.5+key_down y+hover_window 0.5 0.4 0.1+key_up y+expect_value masked == 0++# Preferences > Input > Radial Menus: Brushes on the pen's upper button.+click "Preferences##palette.preferences"+click "Input##preferences.input"+expect "##radial.button"+click "##radial.button"+click "Pen upper button"+shot preferences+key escape+pen_hover 0.5 0.5+pen_button 2 down+expect_value radial_open == 1+expect_value radial_held == 1+pen_hover 0.57 0.5 0.15+pen_button 2 up+expect_value radial_open == 0+expect_value brush_type == 3+# The button belongs to the menu now: it no longer inverts (its Preferences > Tablet mapping).+pen_button 2 down+expect_value radial_open == 1+pen_button 2 up+expect_value radial_open == 1+key escape+pen_out++# A new menu: its first item picked with the palette's search (Smooth), then a key (J).+click "Preferences##palette.preferences"+click "###radial.add_menu"+expect_value radial_menus == 3+type "##radial.search" smooth+click "###radial.pick.brush.smooth"+expect_value radial_slots_3 == 1+click "###radial.key"+key j+expect_shortcut radial.menu3 J+expect_value shortcut_conflicts == 0+key escape+hover_window 0.5 0.5+key_down j+expect_value radial_menu == 2+hover_window 0.5 0.4 0.1+key_up j+expect_value brush_type == 2++# Import a menu file: unknown actions, a command that needs a path, a bad icon and a wrong type are left out; its+# middle mouse button opens it (a right flick: Inflate of Smooth / Inflate / Pinch).+radial_import data/radial/sculpting.json+expect_value radial_menus == 4+expect_value radial_slots_4 == 3+button_drag middle 0.5 0.5 0.57 0.5 0.3+expect_value radial_open == 0+expect_value radial_ran == 1+expect_value brush_type == 4++# Export it, clear it, import it back into the same (now empty) menu.+radial_export 4 sculpting_out.json+click "Preferences##palette.preferences"+click "Clear##radial.clear"+expect_value radial_menus == 3+radial_import sculpting_out.json+expect_value radial_menus == 4+expect_value radial_slots_4 == 3+key escape+button_drag middle 0.5 0.5 0.5 0.4 0.3+expect_value brush_type == 2++# Every style keeps T, Y and J free of other actions.+click "Preferences##palette.preferences"+click "SculptForge##input.style_sculptforge"+expect_value shortcut_conflicts == 0+click "Blender##input.style_blender"+expect_value shortcut_conflicts == 0+click "Maya##input.style_maya"+expect_value shortcut_conflicts == 0+click "ZBrush##input.style_zbrush"+expect_value shortcut_conflicts == 0+key escape++# Restore default menus: Brushes and Masking again.+click "Preferences##palette.preferences"+click "Restore default menus##radial.defaults"+expect_value radial_menus == 2+expect_value radial_slots_1 == 8+key escape