Skip to content

Commit

Permalink
Merge pull request #9 from LinqLover/basic-radial-menu
Browse files Browse the repository at this point in the history
WIP: Basic radial menu
  • Loading branch information
LinqLover authored Feb 23, 2021
2 parents 444ce94 + bd3ea35 commit c72fd78
Show file tree
Hide file tree
Showing 127 changed files with 732 additions and 177 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
accessing
angleWidth

self isArc ifFalse: [^ Float pi * 2].

^ (self startAngle <= self stopAngle
ifTrue: [self stopAngle]
ifFalse: [self stopAngle + (Float pi * 2)])
- self startAngle
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
accessing
centerAngle: radialNumber

^ self
centerAngle: radialNumber
angleWidth: self angleWidth
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
accessing
centerAngle: radialNumberCenter angleWidth: radialNumberWidth

^ self
startAngle: radialNumberCenter - (radialNumberWidth / 2)
stopAngle: radialNumberCenter + (radialNumberWidth / 2)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
centerAngle

^ self startAngle + (self angleWidth / 2)

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ drawCircleOn: aCanvas
radius := self radius x min: self radius y.
minOctant := (self startAngle / (Float pi * 2) * 8 \\ 8) floor.
maxOctant := (self stopAngle / (Float pi * 2) * 8 \\ 8 - 1) ceiling.
self stopAngle - self startAngle > Float epsilon ifFalse: [
self stopAngle - self startAngle > 1e-10 ifFalse: [
maxOctant := maxOctant + 8].
min := self startAngle sinCos * radius.
max := self stopAngle sinCos * radius.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ drawEllipseOn: aCanvas
radius := self radius.
minQuadrant := (self startAngle / (Float pi * 2) * 4 \\ 4) floor.
maxQuadrant := (self stopAngle / (Float pi * 2) * 4 \\ 4 - 1) ceiling.
self stopAngle - self startAngle > Float epsilon ifFalse: [
self stopAngle - self startAngle > 1e-10 ifFalse: [
maxQuadrant := maxQuadrant + 4].
min := self startAngle sinCos * radius.
max := self stopAngle sinCos * radius.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
accessing
innerRadius: innerRadius outerRadius: outerRadius

self assert: innerRadius x / innerRadius y = (outerRadius x / outerRadius y).
self radius: outerRadius.
self innerFraction: innerRadius r / outerRadius r outerFraction: 1.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
accessing
radius: aNumber

self flag: #deprecate. "ct: Do we need it?"
self extent: self extent * (aNumber / self radius)
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
"class" : {
},
"instance" : {
"angleWidth" : "ct 2/8/2021 20:10",
"borderCorrectionOffset" : "ct 2/7/2021 21:20",
"changed" : "ct 2/7/2021 19:16",
"centerAngle" : "ct 2/8/2021 19:13",
"centerAngle:" : "ct 2/8/2021 20:45",
"centerAngle:angleWidth:" : "ct 2/8/2021 20:09",
"containsAngle:" : "ct 2/5/2021 19:45",
"containsPoint:" : "ct 2/7/2021 19:14",
"drawCircleOn:" : "ct 2/7/2021 21:19",
"drawEllipseOn:" : "ct 2/7/2021 21:19",
"drawCircleOn:" : "ct 2/8/2021 22:39",
"drawEllipseOn:" : "ct 2/9/2021 01:44",
"drawOn:" : "ct 1/31/2021 18:56",
"effectiveBounds" : "ct 2/7/2021 19:14",
"initialize" : "ct 2/5/2021 18:45",
Expand All @@ -16,13 +19,15 @@
"innerFraction:" : "ct 2/7/2021 19:39",
"innerFraction:outerFraction:" : "ct 2/7/2021 19:59",
"innerRadius" : "ct 1/31/2021 00:53",
"innerRadius:outerRadius:" : "ct 2/8/2021 20:07",
"isArc" : "ct 2/5/2021 19:44",
"isCircle" : "ct 1/31/2021 18:51",
"outerBounds" : "ct 2/7/2021 19:11",
"outerFraction" : "ct 1/31/2021 00:40",
"outerFraction:" : "ct 2/7/2021 19:40",
"outerRadius" : "ct 1/31/2021 00:55",
"radius" : "ct 1/31/2021 18:50",
"radius:" : "ct 2/8/2021 19:13",
"startAngle" : "ct 1/31/2021 00:32",
"startAngle:" : "ct 2/7/2021 19:38",
"startAngle:stopAngle:" : "ct 2/7/2021 19:59",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
menus
addToMenu: menu coloredItem: label action: action

| item |
item := menu add: label action: action.

(item isKindOf: RadialMenuItemMorph) ifTrue: [
(self colorForLabel: label) ifNotNil: [:labelColor |
item baseColor: (labelColor mixed: 0.6 with: item defaultBaseColor)]].
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
menus
addToMenu: menu coloredItem: label subMenu: subMenu

| item |
item := menu add: label subMenu: subMenu.

(item isKindOf: RadialMenuItemMorph) ifTrue: [
(self colorForLabel: label) ifNotNil: [:labelColor |
item baseColor: (labelColor mixed: 0.6 with: item defaultBaseColor)]].
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
menus
buildDiscreteMenu: menuFactory

| menu |
menu := menuFactory value.

"These buttons do not open a submenu; hence they are handled separately."
menu
add: 'random' action: #setRandom;
addLine.
self
addToMenu: menu coloredItem: 'lighter' action: #setLighter;
addToMenu: menu coloredItem: 'darker' action: #setDarker.
menu addLine.

self labelGroups do: [:group |
group do: [:attrib |
self addToMenu: menu coloredItem: attrib asString subMenu: (
self buildDiscreteMenu: menuFactory attribute: attrib)].
menu addLine].

^ menu
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
menus
buildDiscreteMenu: menuFactory attribute: aSymbol

^ self buildDiscreteMenu: menuFactory attribute: aSymbol levels: self defaultNumberOfLevels
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
menus
contextMenuWithLevels: levels forAttrib: aSymbol
buildDiscreteMenu: menuFactory attribute: aSymbol levels: levels

| menu setter |
menu := MenuMorph new defaultTarget: self.
menu := menuFactory value.
setter := ('set{1}:' format: {aSymbol capitalized}) asSymbol.

0 to: levels - 1 do: [:level |
menu add: ('{1}%' format: {(level / (levels - 1) * 100) rounded}) action: [
menu defaultTarget perform: setter with: level / (levels - 1)]].
self perform: setter with: level / (levels - 1)]].

^ menu
^ menu
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
menus
colorForLabel: label

| symbol |
symbol := label asSymbol.

symbol = #darker ifTrue: [ ^ Color veryVeryDarkGray ].
symbol = #lighter ifTrue: [ ^ Color lightGray ].
symbol = #random ifTrue: [ ^ nil ].

(Color class canUnderstand: symbol) ifTrue: [ ^ Color perform: symbol ].

^ nil
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
menus
contextMenu

| menu |
menu := MenuMorph new defaultTarget: self.

menu
add: 'random' action: #setRandom;
addLine.

#((red green blue) (hue saturation lightness brightness) (cyan magenta yellow black) (alpha))
do: [:group |
group do: [:attrib |
menu
add: attrib asString
subMenu: (self contextMenuWithLevelsForAttrib: attrib)]]
separatedBy: [menu addLine].

^ menu
^ self buildDiscreteMenu: [MenuMorph new
defaultTarget: self;
yourself]

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
private
defaultNumberOfLevels

^ 6
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@
menus
discreteRadialMenu
"Menu items are only chosen in an illustrative fashion. To be replaced soon in order to align with #contextMenu."

| menu |
menu := RadialMenuMorph new.
menu target: self.
menu addItemMorph: (RadialMenuItemMorph new
label: 'random';
action: #setRandom;
yourself).
menu addItemMorph: (RadialMenuItemMorph new
label: 'lighter';
action: [self setBrightness: self color brightness + 0.2];
yourself).
menu addItemMorph: (RadialMenuItemMorph new
label: 'darker';
action: [self setBrightness: self color brightness - 0.2];
yourself).
^ menu
^ self buildDiscreteMenu: [RadialMenuMorph new
target: self;
innerFraction: 0.35;
yourself]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
menus
labelGroups

^ #((red green blue) (hue saturation lightness brightness) (cyan magenta yellow black) (alpha))
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
actions
setDarker

self setBrightness: self color brightness - (1 / (self defaultNumberOfLevels - 1)) asFloat
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
actions
setLighter

self setBrightness: self color brightness + (1 / (self defaultNumberOfLevels - 1)) asFloat
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
event handling
yellowButtonActivity: shiftState

self menuMode caseOf: {
[nil] -> [self flash].
[#popUp] -> [self contextMenu popUpInWorld: self currentWorld].
[#discrete] -> [self discreteRadialMenu popUpFor: self currentEvent].
}.
(self menuMode caseOf: {
[nil] -> [^ self flash].
[#popUp] -> [self contextMenu].
[#discrete] -> [self discreteRadialMenu].
}) popUpInWorld.
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@
"class" : {
},
"instance" : {
"addToMenu:coloredItem:action:" : "ct 2/23/2021 10:43",
"addToMenu:coloredItem:subMenu:" : "ct 2/23/2021 10:28",
"buildDiscreteMenu:" : "ct 2/23/2021 10:29",
"buildDiscreteMenu:attribute:" : "Kiwi 2/9/2021 14:17",
"buildDiscreteMenu:attribute:levels:" : "ct 2/8/2021 19:44",
"color:" : "ct 2/4/2021 15:37",
"contextMenu" : "ct 2/4/2021 20:49",
"contextMenuWithLevels:forAttrib:" : "ct 2/4/2021 20:26",
"contextMenuWithLevelsForAttrib:" : "ct 2/4/2021 20:18",
"discreteRadialMenu" : "ct 2/7/2021 19:22",
"colorForLabel:" : "ct 2/23/2021 10:25",
"contextMenu" : "ct 2/8/2021 19:46",
"defaultNumberOfLevels" : "Kiwi 2/9/2021 14:16",
"discreteRadialMenu" : "Kiwi 2/9/2021 15:54",
"drawOn:" : "ct 2/4/2021 21:26",
"handlesMouseDown:" : "ct 2/4/2021 21:10",
"hatchForm" : "ct 2/4/2021 21:31",
"labelGroups" : "Kiwi 2/8/2021 15:57",
"menuMode" : "ct 2/5/2021 23:54",
"menuMode:" : "ct 2/5/2021 23:54",
"newHatchForm" : "ct 2/4/2021 21:34",
Expand All @@ -18,13 +24,15 @@
"setBlue:" : "ct 2/4/2021 20:32",
"setBrightness:" : "ct 2/4/2021 20:53",
"setCyan:" : "ct 2/4/2021 21:01",
"setDarker" : "Kiwi 2/9/2021 16:22",
"setGreen:" : "ct 2/4/2021 20:32",
"setHue:" : "ct 2/4/2021 20:52",
"setLighter" : "Kiwi 2/9/2021 16:22",
"setLightness:" : "ct 2/4/2021 20:53",
"setMagenta:" : "ct 2/4/2021 21:01",
"setRandom" : "ct 2/4/2021 21:34",
"setRed:" : "ct 2/4/2021 20:32",
"setSaturation:" : "ct 2/4/2021 20:53",
"setYellow:" : "ct 2/4/2021 21:02",
"update:with:" : "ct 2/5/2021 23:54",
"yellowButtonActivity:" : "ct 2/6/2021 00:01" } }
"yellowButtonActivity:" : "ct 2/8/2021 19:52" } }
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
*ColorContextMenu-Core-focus handling-override
newMouseFocus: aMorphOrNil
"Make the given morph the new mouse focus, canceling the previous mouse focus if any. If the argument is nil, the current mouse focus is cancelled."

| newFocus oldFocus |
oldFocus := self mouseFocus.
newFocus := aMorphOrNil.

self mouseFocus: newFocus.

oldFocus == newFocus ifFalse: [
oldFocus ifNotNil: [:m | m mouseFocusChange: false].
newFocus ifNotNil: [:m | m mouseFocusChange: true]].
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"class" : {
},
"instance" : {
"newMouseFocus:" : "ct 2/17/2021 20:24" } }
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
"name" : "HandMorph" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*ColorContextMenu-Core-event handling-pseudo-override
mouseFocusChange: aBoolean
"The message is sent to a morph when its mouse focus change. The given argument indicates that the receiver is gaining mouse focus (versus losing) the mouse focus."
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"class" : {
},
"instance" : {
"mouseFocusChange:" : "ct 2/17/2021 20:24" } }
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
"name" : "Morph" }
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*ColorContextMenu-Core-mathematical functions-override
*ColorContextMenu-Core-mathematical functions-pseudo-override
sinCos

^ self asPoint sinCos
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*ColorContextMenu-Core-polar coordinates-override
*ColorContextMenu-Core-polar coordinates-pseudo-override
sinCos

^ x sin @ y cos
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*ColorContextMenu-Core-arithmetic-override
*ColorContextMenu-Core-arithmetic-pseudo-override
squared

^ self dotProduct: self
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
accessing
baseColor: aColor

baseColor := aColor.
self interactionState: self interactionState.
Loading

0 comments on commit c72fd78

Please sign in to comment.