Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
34 changes: 34 additions & 0 deletions src/ActivityZoneSingelton.moon
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions src/BrightnessBar.moon
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class BrightnessBar extends PropertyBarBase

new: =>
super "brightness"
4 changes: 4 additions & 0 deletions src/ContrastBar.moon
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class ContrastBar extends PropertyBarBase

new: =>
super "contrast"
4 changes: 4 additions & 0 deletions src/GammaBar.moon
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class GammaBar extends PropertyBarBase

new: =>
super "gamma"
105 changes: 105 additions & 0 deletions src/PropertyBarBase.moon
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions src/SaturationBar.moon
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class SaturationBar extends PropertyBarBase

new: =>
super "saturation"
12 changes: 12 additions & 0 deletions src/VolumeBar.moon
Original file line number Diff line number Diff line change
@@ -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()
23 changes: 22 additions & 1 deletion src/main.moon
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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']
Expand Down
34 changes: 34 additions & 0 deletions src/settings.moon
Original file line number Diff line number Diff line change
Expand Up @@ -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!
27 changes: 27 additions & 0 deletions torque-progressbar.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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