Permalink
Browse files

Fixes #10306. Adds night mode support.

  • Loading branch information...
1 parent 833e6f5 commit a76823a2b98944d1cacd670f5aad9e7aa65e05a6 @daniel-kristjansson daniel-kristjansson committed Feb 4, 2012
@@ -85,6 +85,9 @@ static unsigned dbg_ident(const MythPlayer*);
#define LOC QString("Player(%1): ").arg(dbg_ident(this),0,36)
#define LOC_DEC QString("Player(%1): ").arg(dbg_ident(m_mp),0,36)
+const int MythPlayer::kNightModeBrightenssAdjustment = 10;
+const int MythPlayer::kNightModeContrastAdjustment = 10;
+
void DecoderThread::run(void)
{
RunProlog();
@@ -4879,6 +4882,47 @@ void MythPlayer::ToggleStudioLevels(void)
SetOSDMessage(msg, kOSDTimeout_Med);
}
+void MythPlayer::ToggleNightMode(void)
+{
+ if (!videoOutput)
+ return;
+
+ if (!(videoOutput->GetSupportedPictureAttributes() &
+ kPictureAttributeSupported_Brightness))
+ return;
+
+ int b = videoOutput->GetPictureAttribute(kPictureAttribute_Brightness);
+ int c = 0;
+ bool has_contrast = (videoOutput->GetSupportedPictureAttributes() &
+ kPictureAttributeSupported_Contrast);
+ if (has_contrast)
+ c = videoOutput->GetPictureAttribute(kPictureAttribute_Contrast);
+
+ int nm = gCoreContext->GetNumSetting("NightModeEnabled", 0);
+ QString msg;
+ if (!nm)
+ {
+ msg = QObject::tr("Enabled Night Mode");
+ b -= kNightModeBrightenssAdjustment;
+ c -= kNightModeContrastAdjustment;
+ }
+ else
+ {
+ msg = QObject::tr("Disabled Night Mode");
+ b += kNightModeBrightenssAdjustment;
+ c += kNightModeContrastAdjustment;
+ }
+ b = clamp(b, 0, 100);
+ c = clamp(c, 0, 100);
+
+ gCoreContext->SaveSetting("NightModeEnabled", nm ? "0" : "1");
+ videoOutput->SetPictureAttribute(kPictureAttribute_Brightness, b);
+ if (has_contrast)
+ videoOutput->SetPictureAttribute(kPictureAttribute_Contrast, c);
+
+ SetOSDMessage(msg, kOSDTimeout_Med);
+}
+
bool MythPlayer::CanVisualise(void)
{
if (videoOutput)
@@ -324,6 +324,7 @@ class MTV_PUBLIC MythPlayer
// Public picture controls
void ToggleStudioLevels(void);
+ void ToggleNightMode(void);
// Visualisations
bool CanVisualise(void);
@@ -335,6 +336,9 @@ class MTV_PUBLIC MythPlayer
void SaveTotalDuration(void);
void ResetTotalDuration(void);
+ static const int kNightModeBrightenssAdjustment;
+ static const int kNightModeContrastAdjustment;
+
protected:
// Initialization
void OpenDummy(void);
@@ -49,6 +49,7 @@
/* Picture */
#define ACTION_TOGGLESTUDIOLEVELS "TOGGLESTUDIOLEVELS"
+#define ACTION_TOGGLENIGHTMODE "TOGGLENIGHTMODE"
#define ACTION_SETBRIGHTNESS "SETBRIGHTNESS"
#define ACTION_SETCONTRAST "SETCONTRAST"
#define ACTION_SETCOLOUR "SETCOLOUR"
@@ -723,6 +723,8 @@ void TV::InitKeys(void)
REG_KEY("TV Playback", "TOGGLEPICCONTROLS",
QT_TRANSLATE_NOOP("MythControls", "Playback picture adjustments"),
"F");
+ REG_KEY("TV Playback", ACTION_TOGGLENIGHTMODE,
+ QT_TRANSLATE_NOOP("MythControls", "Toggle night mode"), "Ctrl+F");
REG_KEY("TV Playback", ACTION_SETBRIGHTNESS,
QT_TRANSLATE_NOOP("MythControls", "Set the picture brightness"), "");
REG_KEY("TV Playback", ACTION_SETCONTRAST,
@@ -4403,6 +4405,8 @@ bool TV::ToggleHandleAction(PlayerContext *ctx,
DoTogglePictureAttribute(ctx, kAdjustingPicture_Playback);
else if (has_action(ACTION_TOGGLESTUDIOLEVELS, actions))
DoToggleStudioLevels(ctx);
+ else if (has_action(ACTION_TOGGLENIGHTMODE, actions))
+ DoToggleNightMode(ctx);
else if (has_action("TOGGLESTRETCH", actions))
ToggleTimeStretch(ctx);
else if (has_action(ACTION_TOGGLEUPMIX, actions))
@@ -9116,6 +9120,13 @@ void TV::DoToggleStudioLevels(const PlayerContext *ctx)
ctx->UnlockDeletePlayer(__FILE__, __LINE__);
}
+void TV::DoToggleNightMode(const PlayerContext *ctx)
+{
+ ctx->LockDeletePlayer(__FILE__, __LINE__);
+ ctx->player->ToggleNightMode();
+ ctx->UnlockDeletePlayer(__FILE__, __LINE__);
+}
+
void TV::DoTogglePictureAttribute(const PlayerContext *ctx,
PictureAdjustType type)
{
@@ -10007,6 +10018,10 @@ void TV::OSDDialogEvent(int result, QString text, QString action)
{
DoToggleStudioLevels(actx);
}
+ else if (action == ACTION_TOGGLENIGHTMODE)
+ {
+ DoToggleNightMode(actx);
+ }
else if (action.left(12) == "TOGGLEASPECT")
{
ToggleAspectOverride(actx,
@@ -10483,6 +10498,10 @@ void TV::FillOSDMenuVideo(const PlayerContext *ctx, OSD *osd,
}
}
}
+ osd->DialogAddButton(
+ gCoreContext->GetNumSetting("NightModeEnabled", 0) ?
+ tr("Disable Night Mode") : tr("Enable Night Mode"),
+ ACTION_TOGGLENIGHTMODE);
}
else if (category == "3D")
{
@@ -491,6 +491,7 @@ class MTV_PUBLIC TV : public QObject
void ToggleAdjustFill(PlayerContext*,
AdjustFillMode adjustfillMode = kAdjustFill_Toggle);
void DoToggleStudioLevels(const PlayerContext *ctx);
+ void DoToggleNightMode(const PlayerContext*);
void DoTogglePictureAttribute(const PlayerContext*,
PictureAdjustType type);
void DoChangePictureAttribute(

0 comments on commit a76823a

Please sign in to comment.