Skip to content

Commit

Permalink
Add SystemTime class.
Browse files Browse the repository at this point in the history
Displays the system clock time in the top-right corner of the video
window when the OSD is active. For #21.
  • Loading branch information
torque committed Nov 1, 2016
1 parent 3eed2f7 commit 1669260
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ SOURCES += src/TimeRemaining.moon
SOURCES += src/HoverTime.moon
SOURCES += src/PauseIndicator.moon
SOURCES += src/Playlist.moon
SOURCES += src/SystemTime.moon
SOURCES += src/main.moon

TMPDIR := build
Expand Down
41 changes: 41 additions & 0 deletions src/SystemTime.moon
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
class SystemTime extends TopSubscriber

offscreen_position = settings['system-time-offscreen-pos']
top_margin = settings['system-time-top-margin']
time_format = settings['system-time-format']

new: ( @animationQueue ) =>
super!

@line = {
[[{\fn%s\bord2\fs%d\pos(]]\format settings.font, settings['system-time-font-size']
[[-100,0]]
[[)\c&H%s&\3c&H%s&\an9}]]\format settings['system-time-foreground'], settings['system-time-background']
0
}
@lastTime = -1
@position = offscreen_position
@animation = Animation offscreen_position, settings['system-time-right-margin'], 0.25, @\animatePos, nil, 0.25

updateSize: ( w, h ) =>
super w, h
@position = @zone.w - @animation.value
@line[2] = ([[%g,%g]])\format @position, top_margin
return true

animatePos: ( animation, value ) =>
@position = @zone.w - value
@line[2] = ([[%g,%g]])\format @position, top_margin
@needsUpdate = true

update: ( inputState ) =>
update = super inputState

if update or @hovered
systemTime = os.time!
if systemTime != @lastTime
update = true
@line[4] = os.date time_format, systemTime
@lastTime = systemTime

return update
4 changes: 4 additions & 0 deletions src/main.moon
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ if settings['enable-title']
playlist = Playlist animationQueue
aggregator\addSubscriber playlist

if settings['enable-system-time']
systemTime = SystemTime animationQueue
aggregator\addSubscriber systemTime

if settings['pause-indicator']
notFrameStepping = false
PauseIndicatorWrapper = ( event, paused ) ->
Expand Down
12 changes: 12 additions & 0 deletions src/settings.moon
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,17 @@ settings = {
'title-foreground': FG_PLACEHOLDER
'title-background': BG_PLACEHOLDER

--[=[ system time display options ]=]--
'enable-system-time': true
-- This must be a strftime-compatible format string.
'system-time-format': '%H:%M'
-- margins
'system-time-right-margin': 4
'system-time-top-margin': 0
'system-time-font-size': 30
'system-time-foreground': FG_PLACEHOLDER
'system-time-background': BG_PLACEHOLDER

--[=[ pause indicator options ]=]--
-- Flash an icon in the center of the screen when pausing/unpausing.
'pause-indicator': true
Expand Down Expand Up @@ -131,6 +142,7 @@ settings = {
-- goofy.
'elapsed-offscreen-pos': -100
'remaining-offscreen-pos': -100
'system-time-offscreen-pos': -100
'title-offscreen-pos': -40
}

Expand Down
11 changes: 11 additions & 0 deletions torque-progressbar.conf
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ title-font-size=30
title-foreground=FC799E
title-background=2D2D2D

#[=[ system time display options ]=]#
enable-system-time=yes
# This must be a strftime-compatible format string.
system-time-format="%H:%M"
# margins (relative to top and right)
system-time-right-margin=4
system-time-top-margin=0
system-time-font-size=30
system-time-foreground=FG_PLACEHOLDER
system-time-background=BG_PLACEHOLDER

#[=[ pause indicator options ]=]#
# Flash an icon in the center of the screen when pausing/unpausing.
pause-indicator=yes
Expand Down

0 comments on commit 1669260

Please sign in to comment.