From f0f322b51e77dacbf283ee572e75b9c500f4d2c4 Mon Sep 17 00:00:00 2001 From: Moritz Luedecke Date: Sat, 26 Oct 2019 12:07:53 +0200 Subject: [PATCH 1/8] Add ActivityZoneSingelton. --- Makefile | 1 + src/ActivityZoneSingelton.moon | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 src/ActivityZoneSingelton.moon diff --git a/Makefile b/Makefile index feb5e0c..515e50a 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,7 @@ SOURCES += src/Window.moon SOURCES += src/Mouse.moon SOURCES += src/Rect.moon SOURCES += src/ActivityZone.moon +SOURCES += src/ActivityZoneSingelton.moon SOURCES += src/AnimationQueue.moon SOURCES += src/EventLoop.moon SOURCES += src/Animation.moon diff --git a/src/ActivityZoneSingelton.moon b/src/ActivityZoneSingelton.moon new file mode 100644 index 0000000..4ce8350 --- /dev/null +++ b/src/ActivityZoneSingelton.moon @@ -0,0 +1,34 @@ +-- Only one element can be simultaneously displayed +class ActivityZoneSingelton extends ActivityZone + addUIElement: ( element ) => + element\setActivator self + super element + + update: ( displayRequested, clickPending ) => + nowActive = @displayedElement != nil + + if @active != nowActive or displayRequested + @active = nowActive + + for _, element in ipairs @elements + element\activate element == self.displayedElement + + if clickPending + @clickHandler! + + return nowActive + + -- Called by the element + activate: ( element, duration ) => + elementChanged = @displayedElement != element + @displayedElement = element + + if @displayedElement and elementChanged + @update true + + if duration > 0 + if @displayRequestTimer + @displayRequestTimer\kill! + + @displayRequestTimer = mp.add_timeout duration, -> + @displayedElement = nil From a61a2b560011bee5b0f83ef3fe54293e645eee88 Mon Sep 17 00:00:00 2001 From: Moritz Luedecke Date: Sat, 26 Oct 2019 12:08:37 +0200 Subject: [PATCH 2/8] Add PropertyBarBase. --- Makefile | 1 + src/PropertyBarBase.moon | 105 +++++++++++++++++++++++++++++++++++++++ src/settings.moon | 34 +++++++++++++ torque-progressbar.conf | 27 ++++++++++ 4 files changed, 167 insertions(+) create mode 100644 src/PropertyBarBase.moon diff --git a/Makefile b/Makefile index 515e50a..d3e3e08 100644 --- a/Makefile +++ b/Makefile @@ -22,6 +22,7 @@ SOURCES += src/Chapters.moon SOURCES += src/TimeElapsed.moon SOURCES += src/TimeRemaining.moon SOURCES += src/HoverTime.moon +SOURCES += src/PropertyBarBase.moon SOURCES += src/PauseIndicator.moon SOURCES += src/Title.moon SOURCES += src/SystemTime.moon diff --git a/src/PropertyBarBase.moon b/src/PropertyBarBase.moon new file mode 100644 index 0000000..7bc93a7 --- /dev/null +++ b/src/PropertyBarBase.moon @@ -0,0 +1,105 @@ +class PropertyBarBase extends UIElement + + displayDuration = settings['property-bar-display-duration'] + barWidth = settings['property-bar-width'] * 100 + height = settings['property-bar-height'] * 100 + markerWidth = settings['property-bar-marker-width'] * 100 + + new: ( @propertyName, lowerBoundary, markerBoundary, upperBoundary ) => + super! + + @lowerBoundary = lowerBoundary or -100 + @upperBoundary = upperBoundary or 100 + @markerBoundary = markerBoundary or 0 + @style = settings['bar-foreground-style'] + @line = { + [[{\pos(]], -- 1 + 0, -- 2 + [[)\fscy]], -- 3 + height, -- 4 + + -- background + [[\fscx]], -- 5 + 1, -- 6 + [[{\alpha&H]], -- 7 + [[FF]], -- 8 + ([[\an1%s%s%s\p1}m 0 0 l ]])\format settings['default-style'], settings['bar-default-style'], settings['bar-background-style'], + 0, -- 10 + + -- foreground + [[\fscx]], -- 11 + 0, -- 12 + [[{\alpha&H]], -- 13 + [[FF]], -- 14 + 0, -- 15 + 0, -- 16 + + -- marker + [[\fscx]], -- 17 + 1, -- 18 + [[{\alpha&H]], -- 19 + [[FF]], -- 20 + 0, -- 21 + 0 -- 22 + } + + @animation = Animation 0, 1, @animationDuration, @\animate, nil, 0.5 + + mp.observe_property propertyName, 'number', (event, value) -> + @updatePropertyInfo value + + resize: => + @x0 = Window.w - settings['property-bar-right-margin'] - settings['property-bar-width'] + @y0 = settings['property-bar-top-margin'] + @line[2] = ([[%d,%d]])\format @x0, @y0 + + animate: ( value ) => + alphaStr = ('%02X')\format 255 - value * 255 + @line[8] = alphaStr + @line[14] = alphaStr + @line[20] = alphaStr + @needsUpdate = true + + -- Called by ActivityZoneSingelton + setActivator: ( activityZone ) => + @activityZone = activityZone + + updatePropertyInfo: ( value ) => + if value + if value > @upperBoundary + @value = @upperBoundary + elseif value < @lowerBoundary + @value = @lowerBoundary + else + @value = value + + if @value <= @markerBoundary + @markerStyle = settings['chapter-marker-before-style'] + else + @markerStyle = settings['chapter-marker-after-style'] + + -- Don't execute this branch since the function resize wasn't called yet + if @x0 + limit = @upperBoundary - @lowerBoundary + percent = (@value - @lowerBoundary) / limit + followingEdge = percent * barWidth - barWidth + markerEdge = ((@markerBoundary - @lowerBoundary) * barWidth / limit) - (2 * barWidth + followingEdge) + markerEdgeBegin = markerEdge - markerWidth / 2 + markerEdgeEnd = markerEdgeBegin + markerWidth + + -- background + @line[10] = ([[%d 0 %d 1 0 1]])\format barWidth, barWidth + + -- foreground + @line[12] = percent + @line[15] = ([[\an1%s%s%s\p1}m -%d 0 l ]])\format settings['default-style'], settings['bar-default-style'], @style, barWidth + @line[16] = ([[-%d 1 %d 1 %d 0]])\format barWidth, followingEdge, followingEdge + + -- marker + @line[21] = ([[\an1%s%s%s\p1}m -%d 0 l ]])\format settings['default-style'], settings['bar-default-style'], @markerStyle, markerEdgeBegin + @line[22] = ([[-%d 1 %d 1 %d 0]])\format markerEdgeBegin, markerEdgeEnd, markerEdgeEnd + + @needsUpdate = true + @activityZone\activate @, displayDuration + + return @needsUpdate diff --git a/src/settings.moon b/src/settings.moon index 6d393e5..758958a 100644 --- a/src/settings.moon +++ b/src/settings.moon @@ -424,4 +424,38 @@ will disappear without animating all the way off-screen. Positive values will cause the display to animate the wrong direction. ]] +settings['enable-property-bar'] = true +helpText['enable-property-bar'] = [[Controls whether or not the property bar for +e.g. volume and brightness is drawn at all. +]] + +settings['property-bar-width'] = 100 +helpText['property-bar-width'] = [[Sets the width of the property bar. +]] + +settings['property-bar-height'] = 8 +helpText['property-bar-height'] = [[Sets the height of the property bar. There +is no logic attached to this, so 0 or negative values may have unexpected +results. +]] + +settings['property-bar-top-margin'] = 100 +helpText['property-bar-top-margin'] = [[Controls how far from the top edge of +the window the property bar display is positioned. +]] + +settings['property-bar-right-margin'] = 100 +helpText['property-bar-right-margin'] = [[ Controls how far from the right edge +of the window the property bar display is positioned. +]] + +settings['property-bar-display-duration'] = 1 +helpText['property-bar-display-duration'] = [[Sets the amount of time in seconds +that the property bar stays on the screen. +]] + +settings['property-bar-marker-width'] = 2 +helpText['property-bar-marker-width'] = [[Controls the width of the marker. +]] + settings\_reload! diff --git a/torque-progressbar.conf b/torque-progressbar.conf index 67d636a..f9c58db 100644 --- a/torque-progressbar.conf +++ b/torque-progressbar.conf @@ -304,3 +304,30 @@ system-time-offscreen-pos=-100 # cause the display to animate the wrong direction. title-offscreen-pos=-40 +# Controls whether or not the property bar for +# e.g. volume and brightness is drawn at all. +enable-property-bar=yes + +# Sets the width of the property bar. +property-bar-width=100 + +# Sets the height of the property bar. There +# is no logic attached to this, so 0 or negative values may have unexpected +# results. +property-bar-height=8 + +# Controls how far from the top edge of +# the window the property bar display is positioned. +property-bar-top-margin=100 + +# Controls how far from the right edge +# of the window the property bar display is positioned. +property-bar-right-margin=100 + +# Sets the amount of time in seconds +# that the property bar stays on the screen. +property-bar-display-duration=1 + +# Controls the width of the marker. +property-bar-marker-width=2 + From 54590bc284ee0cda598d7321fc52786896d0968a Mon Sep 17 00:00:00 2001 From: Moritz Luedecke Date: Sat, 26 Oct 2019 15:49:02 +0200 Subject: [PATCH 3/8] Add ContrastBar. --- Makefile | 1 + src/ContrastBar.moon | 4 ++++ src/main.moon | 9 ++++++++- 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 src/ContrastBar.moon diff --git a/Makefile b/Makefile index d3e3e08..a4b4ab7 100644 --- a/Makefile +++ b/Makefile @@ -23,6 +23,7 @@ SOURCES += src/TimeElapsed.moon SOURCES += src/TimeRemaining.moon SOURCES += src/HoverTime.moon SOURCES += src/PropertyBarBase.moon +SOURCES += src/ContrastBar.moon SOURCES += src/PauseIndicator.moon SOURCES += src/Title.moon SOURCES += src/SystemTime.moon diff --git a/src/ContrastBar.moon b/src/ContrastBar.moon new file mode 100644 index 0000000..b19ce0c --- /dev/null +++ b/src/ContrastBar.moon @@ -0,0 +1,4 @@ +class ContrastBar extends PropertyBarBase + + new: => + super "contrast" diff --git a/src/main.moon b/src/main.moon index 98cb2d6..af8a7e7 100644 --- a/src/main.moon +++ b/src/main.moon @@ -17,8 +17,11 @@ hoverTimeZone = ActivityZone => topZone = ActivityZone => @reset 0, 0, Window.w, activeHeight, - ignoreRequestDisplay + => + return false +propertyZone = ActivityZoneSingelton => + @reset 0, 0, Window.w, Window.h -- This is kind of ugly but I have gone insane and don't care any more. -- Watch the rapidly declining quality of this codebase in realtime. @@ -70,12 +73,16 @@ if settings['enable-system-time'] bottomZone\addUIElement systemTime topZone\addUIElement systemTime +if settings['enable-property-bar'] + contrastBar = ContrastBar! + propertyZone\addUIElement contrastBar -- The order of these is important, because the order that elements are added to -- eventLoop matters, because that controls how they are layered (first element -- on the bottom). eventLoop\addZone hoverTimeZone eventLoop\addZone bottomZone eventLoop\addZone topZone +eventLoop\addZone propertyZone notFrameStepping = false if settings['pause-indicator'] From 61cc9c6a30e257599b9ff81fc908bd924499117b Mon Sep 17 00:00:00 2001 From: Moritz Luedecke Date: Sat, 26 Oct 2019 15:57:48 +0200 Subject: [PATCH 4/8] Add BrightnessBar. --- Makefile | 1 + src/BrightnessBar.moon | 4 ++++ src/main.moon | 2 ++ 3 files changed, 7 insertions(+) create mode 100644 src/BrightnessBar.moon diff --git a/Makefile b/Makefile index a4b4ab7..5542b4b 100644 --- a/Makefile +++ b/Makefile @@ -23,6 +23,7 @@ SOURCES += src/TimeElapsed.moon SOURCES += src/TimeRemaining.moon SOURCES += src/HoverTime.moon SOURCES += src/PropertyBarBase.moon +SOURCES += src/BrightnessBar.moon SOURCES += src/ContrastBar.moon SOURCES += src/PauseIndicator.moon SOURCES += src/Title.moon diff --git a/src/BrightnessBar.moon b/src/BrightnessBar.moon new file mode 100644 index 0000000..b580378 --- /dev/null +++ b/src/BrightnessBar.moon @@ -0,0 +1,4 @@ +class BrightnessBar extends PropertyBarBase + + new: => + super "brightness" diff --git a/src/main.moon b/src/main.moon index af8a7e7..eb68e66 100644 --- a/src/main.moon +++ b/src/main.moon @@ -74,7 +74,9 @@ if settings['enable-system-time'] topZone\addUIElement systemTime if settings['enable-property-bar'] + brightnessBar = BrightnessBar! contrastBar = ContrastBar! + propertyZone\addUIElement brightnessBar propertyZone\addUIElement contrastBar -- The order of these is important, because the order that elements are added to -- eventLoop matters, because that controls how they are layered (first element From 2169419cbfeedbbb99a56c1caa0aff0284afb974 Mon Sep 17 00:00:00 2001 From: Moritz Luedecke Date: Sat, 26 Oct 2019 15:58:01 +0200 Subject: [PATCH 5/8] Add GammaBar. --- Makefile | 1 + src/GammaBar.moon | 4 ++++ src/main.moon | 2 ++ 3 files changed, 7 insertions(+) create mode 100644 src/GammaBar.moon diff --git a/Makefile b/Makefile index 5542b4b..1feec75 100644 --- a/Makefile +++ b/Makefile @@ -25,6 +25,7 @@ SOURCES += src/HoverTime.moon SOURCES += src/PropertyBarBase.moon SOURCES += src/BrightnessBar.moon SOURCES += src/ContrastBar.moon +SOURCES += src/GammaBar.moon SOURCES += src/PauseIndicator.moon SOURCES += src/Title.moon SOURCES += src/SystemTime.moon diff --git a/src/GammaBar.moon b/src/GammaBar.moon new file mode 100644 index 0000000..2b7a997 --- /dev/null +++ b/src/GammaBar.moon @@ -0,0 +1,4 @@ +class GammaBar extends PropertyBarBase + + new: => + super "gamma" diff --git a/src/main.moon b/src/main.moon index eb68e66..a453238 100644 --- a/src/main.moon +++ b/src/main.moon @@ -76,8 +76,10 @@ if settings['enable-system-time'] if settings['enable-property-bar'] brightnessBar = BrightnessBar! contrastBar = ContrastBar! + gammaBar = GammaBar! propertyZone\addUIElement brightnessBar propertyZone\addUIElement contrastBar + propertyZone\addUIElement gammaBar -- The order of these is important, because the order that elements are added to -- eventLoop matters, because that controls how they are layered (first element -- on the bottom). From 8dcafc7fba0a89e7134b4345f9d8750e9bf9e314 Mon Sep 17 00:00:00 2001 From: Moritz Luedecke Date: Sat, 26 Oct 2019 15:58:16 +0200 Subject: [PATCH 6/8] Add SaturationBar. --- Makefile | 1 + src/SaturationBar.moon | 4 ++++ src/main.moon | 2 ++ 3 files changed, 7 insertions(+) create mode 100644 src/SaturationBar.moon diff --git a/Makefile b/Makefile index 1feec75..0e143ec 100644 --- a/Makefile +++ b/Makefile @@ -26,6 +26,7 @@ SOURCES += src/PropertyBarBase.moon SOURCES += src/BrightnessBar.moon SOURCES += src/ContrastBar.moon SOURCES += src/GammaBar.moon +SOURCES += src/SaturationBar.moon SOURCES += src/PauseIndicator.moon SOURCES += src/Title.moon SOURCES += src/SystemTime.moon diff --git a/src/SaturationBar.moon b/src/SaturationBar.moon new file mode 100644 index 0000000..655c544 --- /dev/null +++ b/src/SaturationBar.moon @@ -0,0 +1,4 @@ +class SaturationBar extends PropertyBarBase + + new: => + super "saturation" diff --git a/src/main.moon b/src/main.moon index a453238..529cb78 100644 --- a/src/main.moon +++ b/src/main.moon @@ -77,9 +77,11 @@ if settings['enable-property-bar'] brightnessBar = BrightnessBar! contrastBar = ContrastBar! gammaBar = GammaBar! + saturationBar = SaturationBar! propertyZone\addUIElement brightnessBar propertyZone\addUIElement contrastBar propertyZone\addUIElement gammaBar + propertyZone\addUIElement saturationBar -- The order of these is important, because the order that elements are added to -- eventLoop matters, because that controls how they are layered (first element -- on the bottom). From 7e2f4429f875fe2d4e9e3bc123369c1a1adf8d22 Mon Sep 17 00:00:00 2001 From: Moritz Luedecke Date: Sat, 26 Oct 2019 16:11:39 +0200 Subject: [PATCH 7/8] Add VolumeBar. --- Makefile | 1 + src/VolumeBar.moon | 12 ++++++++++++ src/main.moon | 7 +++++++ 3 files changed, 20 insertions(+) create mode 100644 src/VolumeBar.moon diff --git a/Makefile b/Makefile index 0e143ec..d3caeb1 100644 --- a/Makefile +++ b/Makefile @@ -27,6 +27,7 @@ SOURCES += src/BrightnessBar.moon SOURCES += src/ContrastBar.moon SOURCES += src/GammaBar.moon SOURCES += src/SaturationBar.moon +SOURCES += src/VolumeBar.moon SOURCES += src/PauseIndicator.moon SOURCES += src/Title.moon SOURCES += src/SystemTime.moon diff --git a/src/VolumeBar.moon b/src/VolumeBar.moon new file mode 100644 index 0000000..e313d13 --- /dev/null +++ b/src/VolumeBar.moon @@ -0,0 +1,12 @@ +class VolumeBar extends PropertyBarBase + + new: => + super "volume", 0, 100, 300 + + updateMuteInfo: ( muted ) => + if muted + @style = settings['bar-cache-style'] + else + @style = settings['bar-foreground-style'] + + @\updatePropertyInfo() diff --git a/src/main.moon b/src/main.moon index 529cb78..29d4280 100644 --- a/src/main.moon +++ b/src/main.moon @@ -78,10 +78,17 @@ if settings['enable-property-bar'] contrastBar = ContrastBar! gammaBar = GammaBar! saturationBar = SaturationBar! + volumeBar = VolumeBar! + mp.observe_property "mute", "bool", ( event, muted ) -> + if volumeBar + volumeBar\updateMuteInfo muted + propertyZone\addUIElement brightnessBar propertyZone\addUIElement contrastBar propertyZone\addUIElement gammaBar propertyZone\addUIElement saturationBar + propertyZone\addUIElement volumeBar + -- The order of these is important, because the order that elements are added to -- eventLoop matters, because that controls how they are layered (first element -- on the bottom). From 8ec659f4e66ff241655a9017bb0cab237a4e8f85 Mon Sep 17 00:00:00 2001 From: Moritz Luedecke Date: Sat, 26 Oct 2019 16:12:37 +0200 Subject: [PATCH 8/8] Disable OSD. --- src/main.moon | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main.moon b/src/main.moon index 29d4280..59d4e2a 100644 --- a/src/main.moon +++ b/src/main.moon @@ -83,6 +83,7 @@ if settings['enable-property-bar'] if volumeBar volumeBar\updateMuteInfo muted + mp.set_property "osd-level", 0 propertyZone\addUIElement brightnessBar propertyZone\addUIElement contrastBar propertyZone\addUIElement gammaBar