|
57 | 57 | piemenuModes, piemenuPitches, piemenuCustomNotes, piemenuGrid, |
58 | 58 | piemenuBlockContext, piemenuIntervals, piemenuVoices, piemenuBoolean, |
59 | 59 | piemenuBasic, piemenuColor, piemenuNumber, piemenuNthModalPitch, |
60 | | - piemenuNoteValue, piemenuAccidentals, piemenuKey, piemenuChords |
| 60 | + piemenuNoteValue, piemenuAccidentals, piemenuKey, piemenuChords, |
| 61 | + piemenuDissectNumber |
61 | 62 | */ |
62 | 63 |
|
63 | 64 | const setWheelSize = i => { |
@@ -4017,3 +4018,141 @@ const piemenuKey = activity => { |
4017 | 4018 | modenameWheel.navigateWheel(j); |
4018 | 4019 | } |
4019 | 4020 | }; |
| 4021 | + |
| 4022 | +/** |
| 4023 | + * Shows a pie menu for selecting the rhythm dissect number. |
| 4024 | + * Displays different options based on beginner mode. |
| 4025 | + * @param {Object} widget - The widget instance (RhythmRuler). |
| 4026 | + * @returns {void} |
| 4027 | + */ |
| 4028 | +const piemenuDissectNumber = widget => { |
| 4029 | + // Use activity.beginnerMode as the global beginnerMode variable references the DOM element |
| 4030 | + const isBeginnerMode = widget.activity.beginnerMode; |
| 4031 | + |
| 4032 | + // Determine wheel values based on beginner mode |
| 4033 | + const wheelValues = isBeginnerMode ? [2, 3, 4] : [2, 3, 4, 5, 7]; |
| 4034 | + |
| 4035 | + const currentValue = parseInt(widget._dissectNumber.value) || 2; |
| 4036 | + |
| 4037 | + // Show the wheel div |
| 4038 | + docById("wheelDiv").style.display = ""; |
| 4039 | + |
| 4040 | + // Create the number wheel |
| 4041 | + const numberWheel = new wheelnav("wheelDiv", null, 600, 600); |
| 4042 | + const exitWheel = new wheelnav("_exitWheel", numberWheel.raphael); |
| 4043 | + |
| 4044 | + // Prepare labels with spacer |
| 4045 | + const wheelLabels = wheelValues.map(v => v.toString()); |
| 4046 | + wheelLabels.push(null); // spacer |
| 4047 | + |
| 4048 | + wheelnav.cssMode = true; |
| 4049 | + numberWheel.keynavigateEnabled = false; |
| 4050 | + numberWheel.colors = platformColor.numberWheelcolors; |
| 4051 | + numberWheel.slicePathFunction = slicePath().DonutSlice; |
| 4052 | + numberWheel.slicePathCustom = slicePath().DonutSliceCustomization(); |
| 4053 | + numberWheel.slicePathCustom.minRadiusPercent = 0.2; |
| 4054 | + numberWheel.slicePathCustom.maxRadiusPercent = 0.6; |
| 4055 | + numberWheel.sliceSelectedPathCustom = numberWheel.slicePathCustom; |
| 4056 | + numberWheel.sliceInitPathCustom = numberWheel.slicePathCustom; |
| 4057 | + numberWheel.animatetime = 0; |
| 4058 | + numberWheel.createWheel(wheelLabels); |
| 4059 | + |
| 4060 | + // Create exit wheel with close, minus, and plus buttons |
| 4061 | + exitWheel.colors = platformColor.exitWheelcolors2; |
| 4062 | + exitWheel.slicePathFunction = slicePath().DonutSlice; |
| 4063 | + exitWheel.slicePathCustom = slicePath().DonutSliceCustomization(); |
| 4064 | + exitWheel.slicePathCustom.minRadiusPercent = 0.0; |
| 4065 | + exitWheel.slicePathCustom.maxRadiusPercent = 0.2; |
| 4066 | + exitWheel.sliceSelectedPathCustom = exitWheel.slicePathCustom; |
| 4067 | + exitWheel.sliceInitPathCustom = exitWheel.slicePathCustom; |
| 4068 | + exitWheel.clickModeRotate = false; |
| 4069 | + exitWheel.initWheel(["×", "-", "+"]); // Close, minus, plus |
| 4070 | + exitWheel.navItems[0].sliceSelectedAttr.cursor = "pointer"; |
| 4071 | + exitWheel.navItems[0].sliceHoverAttr.cursor = "pointer"; |
| 4072 | + exitWheel.navItems[0].titleSelectedAttr.cursor = "pointer"; |
| 4073 | + exitWheel.navItems[0].titleHoverAttr.cursor = "pointer"; |
| 4074 | + exitWheel.navItems[1].sliceSelectedAttr.cursor = "pointer"; |
| 4075 | + exitWheel.navItems[1].sliceHoverAttr.cursor = "pointer"; |
| 4076 | + exitWheel.navItems[1].titleSelectedAttr.cursor = "pointer"; |
| 4077 | + exitWheel.navItems[1].titleHoverAttr.cursor = "pointer"; |
| 4078 | + exitWheel.navItems[2].sliceSelectedAttr.cursor = "pointer"; |
| 4079 | + exitWheel.navItems[2].sliceHoverAttr.cursor = "pointer"; |
| 4080 | + exitWheel.navItems[2].titleSelectedAttr.cursor = "pointer"; |
| 4081 | + exitWheel.navItems[2].titleHoverAttr.cursor = "pointer"; |
| 4082 | + exitWheel.createWheel(); |
| 4083 | + |
| 4084 | + // Handle selection |
| 4085 | + const __selectionChanged = () => { |
| 4086 | + const selectedIndex = numberWheel.selectedNavItemIndex; |
| 4087 | + const newValue = wheelValues[selectedIndex]; |
| 4088 | + widget._dissectNumber.value = newValue; |
| 4089 | + }; |
| 4090 | + |
| 4091 | + // Handle exit |
| 4092 | + const __exitMenu = () => { |
| 4093 | + docById("wheelDiv").style.display = "none"; |
| 4094 | + numberWheel.removeWheel(); |
| 4095 | + exitWheel.removeWheel(); |
| 4096 | + }; |
| 4097 | + |
| 4098 | + // Get button position for positioning the pie menu |
| 4099 | + const buttonRect = widget._dissectNumber.getBoundingClientRect(); |
| 4100 | + const canvasLeft = widget.activity.canvas.offsetLeft + 28; |
| 4101 | + const canvasTop = widget.activity.canvas.offsetTop + 6; |
| 4102 | + |
| 4103 | + // Position the wheel |
| 4104 | + docById("wheelDiv").style.position = "absolute"; |
| 4105 | + setWheelSize(300); |
| 4106 | + |
| 4107 | + const left = Math.round(buttonRect.left - canvasLeft); |
| 4108 | + const top = Math.round(buttonRect.top - canvasTop); |
| 4109 | + |
| 4110 | + // Position to the left of the button as shown in user image |
| 4111 | + // left - 300 (wheel size) - 10px padding |
| 4112 | + // top + half button height - 150 (half wheel size) for vertical centering |
| 4113 | + docById("wheelDiv").style.left = Math.max(0, left - 300 - 10) + "px"; |
| 4114 | + docById("wheelDiv").style.top = Math.max(0, top + buttonRect.height / 2 - 150) + "px"; |
| 4115 | + |
| 4116 | + // Navigate to current value |
| 4117 | + const currentIndex = wheelValues.indexOf(currentValue); |
| 4118 | + if (currentIndex !== -1) { |
| 4119 | + numberWheel.navigateWheel(currentIndex); |
| 4120 | + } |
| 4121 | + |
| 4122 | + // Set up click handlers for number selections |
| 4123 | + for (let i = 0; i < wheelValues.length; i++) { |
| 4124 | + numberWheel.navItems[i].navigateFunction = () => { |
| 4125 | + __selectionChanged(); |
| 4126 | + __exitMenu(); |
| 4127 | + }; |
| 4128 | + } |
| 4129 | + |
| 4130 | + // Set up exit button (×) |
| 4131 | + exitWheel.navItems[0].navigateFunction = () => { |
| 4132 | + __exitMenu(); |
| 4133 | + }; |
| 4134 | + |
| 4135 | + // Set up decrement button (-) |
| 4136 | + exitWheel.navItems[1].navigateFunction = () => { |
| 4137 | + const currentVal = parseInt(widget._dissectNumber.value); |
| 4138 | + const currentIdx = wheelValues.indexOf(currentVal); |
| 4139 | + |
| 4140 | + // Move to previous value in the array, or stay at first |
| 4141 | + if (currentIdx > 0) { |
| 4142 | + const newValue = wheelValues[currentIdx - 1]; |
| 4143 | + widget._dissectNumber.value = newValue; |
| 4144 | + } |
| 4145 | + }; |
| 4146 | + |
| 4147 | + // Set up increment button (+) |
| 4148 | + exitWheel.navItems[2].navigateFunction = () => { |
| 4149 | + const currentVal = parseInt(widget._dissectNumber.value); |
| 4150 | + const currentIdx = wheelValues.indexOf(currentVal); |
| 4151 | + |
| 4152 | + // Move to next value in the array, or stay at last |
| 4153 | + if (currentIdx < wheelValues.length - 1) { |
| 4154 | + const newValue = wheelValues[currentIdx + 1]; |
| 4155 | + widget._dissectNumber.value = newValue; |
| 4156 | + } |
| 4157 | + }; |
| 4158 | +}; |
0 commit comments