diff --git a/Makefile b/Makefile index feb5e0c..d3caeb1 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 @@ -21,6 +22,12 @@ SOURCES += src/Chapters.moon 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/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/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 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/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/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/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/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/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 98cb2d6..59d4e2a 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,30 @@ if settings['enable-system-time'] bottomZone\addUIElement systemTime topZone\addUIElement systemTime +if settings['enable-property-bar'] + brightnessBar = BrightnessBar! + contrastBar = ContrastBar! + gammaBar = GammaBar! + saturationBar = SaturationBar! + volumeBar = VolumeBar! + mp.observe_property "mute", "bool", ( event, muted ) -> + if volumeBar + volumeBar\updateMuteInfo muted + + mp.set_property "osd-level", 0 + 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). eventLoop\addZone hoverTimeZone eventLoop\addZone bottomZone eventLoop\addZone topZone +eventLoop\addZone propertyZone notFrameStepping = false if settings['pause-indicator'] 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 +