From 2bc149e188cc72c5648330e8a94da765fef172e8 Mon Sep 17 00:00:00 2001 From: Enzo-Demeulenaere Date: Wed, 26 Jun 2024 14:18:48 +0200 Subject: [PATCH] added logarithmic visuals + logarithmic slider --- CoypuIDE/ICLogarithmicSlider.class.st | 22 +++++++++ CoypuIDE/ICMasterCutoff.class.st | 64 +++++++++++++++++++++++++-- 2 files changed, 83 insertions(+), 3 deletions(-) create mode 100644 CoypuIDE/ICLogarithmicSlider.class.st diff --git a/CoypuIDE/ICLogarithmicSlider.class.st b/CoypuIDE/ICLogarithmicSlider.class.st new file mode 100644 index 0000000..8857581 --- /dev/null +++ b/CoypuIDE/ICLogarithmicSlider.class.st @@ -0,0 +1,22 @@ +Class { + #name : #ICLogarithmicSlider, + #superclass : #ICSlider, + #category : #'CoypuIDE-slider' +} + +{ #category : #'api - transformations' } +ICLogarithmicSlider >> valueAtX: aPoint [ + + | value minP maxP minV maxV scale position | + minP := 0. + maxP := self barLength. + minV := self minValue ln. + maxV := self maxValue ln. + + scale := maxV - minV / (maxP - minP). + position := (aPoint - bar position) x. + value := (position - minP * scale + minV) exp. + value := self nearestValue: value. + + ^ value asFloat rounded +] diff --git a/CoypuIDE/ICMasterCutoff.class.st b/CoypuIDE/ICMasterCutoff.class.st index fe563b0..92e4e7f 100644 --- a/CoypuIDE/ICMasterCutoff.class.st +++ b/CoypuIDE/ICMasterCutoff.class.st @@ -10,6 +10,64 @@ Class { #category : #'CoypuIDE-cutoff' } +{ #category : #'as yet unclassified' } +ICMasterCutoff class >> exampleLinearSlider [ + + | master slider container textElt | + master := self new. + + slider := ICSlider new. + + container := BlElement new layout: BlLinearLayout vertical;constraintsDo: [ :c | + c horizontal fitContent. + c vertical fitContent ]. + + container addChild: master. + container addChild: slider. + + slider minValue: master minValue. + slider maxValue: master maxValue. + + textElt := BlTextElement new text: slider minValue asRopedText. + container addChild: textElt. + + slider callBack: [ :value | + master setValue: value. + textElt text: value asRopedText ]. + + container openInSpace +] + +{ #category : #'as yet unclassified' } +ICMasterCutoff class >> exampleLogarithmicSlider [ + + | master slider container textElt | + master := self new. + + slider := ICLogarithmicSlider new. + + container := BlElement new + layout: BlLinearLayout vertical; + constraintsDo: [ :c | + c horizontal fitContent. + c vertical fitContent ]. + + container addChild: master. + container addChild: slider. + + slider minValue: master minValue. + slider maxValue: master maxValue. + + textElt := BlTextElement new text: slider minValue asRopedText. + container addChild: textElt. + + slider callBack: [ :value | + master setValue: value. + textElt text: value asRopedText ]. + + container openInSpace +] + { #category : #'as yet unclassified' } ICMasterCutoff >> defaultLine [ @@ -130,12 +188,12 @@ ICMasterCutoff >> valueToPosition: aNumber [ | minP maxP minV maxV scale result | minP := 0. maxP := self width - 40. - minV := self minValue log. - maxV := self maxValue log. + minV := self minValue ln. + maxV := self maxValue ln. scale := maxV - minV / (maxP - minP). - result := aNumber log - minV / scale + minP. + result := aNumber ln - minV / scale + minP. ^ result ]