From 4d6c88624e8102ebfad835e2419893c6222df2fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Fri, 10 Sep 2010 12:04:57 +0000 Subject: [PATCH] * _CurrentVideoSizeInPercent() returned wrong values, but it didn't result in wrong behavior before. Implemented more keyboard actions from ticket #2495: * +/- zoom the video now (by +/- 10% of current scale). * ZXCVB (raw keys hardcoded, i.e. the keys along the bottom of the keyboard) act as playback buttons: skip previous (Z), play (X), pause (C), stop (V), skip next (B). * Renamed "No interface" menu item to "Hide interface" and changed the shortcut to Cmd-H. This item is only available with video streams, though. * 'M' will mute/unmute the audio. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38599 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/mediaplayer/MainWin.cpp | 74 +++++++++++++++++++++++++++----- src/apps/mediaplayer/MainWin.h | 1 + 2 files changed, 64 insertions(+), 11 deletions(-) diff --git a/src/apps/mediaplayer/MainWin.cpp b/src/apps/mediaplayer/MainWin.cpp index 0ec60fbf6a..1f6e238063 100644 --- a/src/apps/mediaplayer/MainWin.cpp +++ b/src/apps/mediaplayer/MainWin.cpp @@ -1403,8 +1403,8 @@ MainWin::_CreateMenu() fFileMenu->AddSeparatorItem(); - fNoInterfaceMenuItem = new BMenuItem("No interface", - new BMessage(M_TOGGLE_NO_INTERFACE), 'B'); + fNoInterfaceMenuItem = new BMenuItem("Hide interface", + new BMessage(M_TOGGLE_NO_INTERFACE), 'H'); fFileMenu->AddItem(fNoInterfaceMenuItem); fFileMenu->AddItem(new BMenuItem("Always on top", new BMessage(M_TOGGLE_ALWAYS_ON_TOP), 'A')); @@ -1632,8 +1632,8 @@ MainWin::_CurrentVideoSizeInPercent() const int viewWidth = fVideoView->Bounds().IntegerWidth() + 1; int viewHeight = fVideoView->Bounds().IntegerHeight() + 1; - int widthPercent = videoWidth * 100 / viewWidth; - int heightPercent = videoHeight * 100 / viewHeight; + int widthPercent = viewWidth * 100 / videoWidth; + int heightPercent = viewHeight * 100 / videoHeight; if (widthPercent > heightPercent) return widthPercent; @@ -1641,6 +1641,27 @@ MainWin::_CurrentVideoSizeInPercent() const } +void +MainWin::_ZoomVideoView(int percentDiff) +{ + if (!fHasVideo) + return; + + int percent = _CurrentVideoSizeInPercent(); + int newSize = percent * (100 + percentDiff) / 100; + + if (newSize < 25) + newSize = 25; + if (newSize > 400) + newSize = 400; + if (newSize != percent) { + BMessage message(M_VIEW_SIZE); + message.AddInt32("size", newSize); + PostMessage(&message); + } +} + + void MainWin::_ResizeWindow(int percent, bool useNoVideoWidth, bool stayOnScreen) { @@ -1723,9 +1744,6 @@ MainWin::_ResizeWindow(int percent, bool useNoVideoWidth, bool stayOnScreen) void MainWin::_ResizeVideoView(int x, int y, int width, int height) { - printf("_ResizeVideoView: %d,%d, width %d, height %d\n", x, y, - width, height); - // Keep aspect ratio, place video view inside // the background area (may create black bars). int videoWidth; @@ -1928,8 +1946,6 @@ MainWin::_ShowContextMenu(const BPoint& screenPoint) bool MainWin::_KeyDown(BMessage* msg) { - // TODO: use the shortcut mechanism instead! - uint32 key = msg->FindInt32("key"); uint32 rawChar = msg->FindInt32("raw_char"); uint32 modifier = msg->FindInt32("modifiers"); @@ -1947,6 +1963,10 @@ MainWin::_KeyDown(BMessage* msg) fController->TogglePlaying(); return true; + case 'm': + fController->ToggleMute(); + return true; + case B_ESCAPE: if (!fIsFullscreen) break; @@ -2017,6 +2037,20 @@ MainWin::_KeyDown(BMessage* msg) PostMessage(M_SKIP_PREV); return true; + case '+': + if ((modifier & B_COMMAND_KEY) == 0) { + _ZoomVideoView(10); + return true; + } + break; + + case '-': + if ((modifier & B_COMMAND_KEY) == 0) { + _ZoomVideoView(-10); + return true; + } + break; + case B_DELETE: case 'd': // d for delete case 't': // t for Trash @@ -2034,14 +2068,14 @@ MainWin::_KeyDown(BMessage* msg) switch (key) { case 0x3a: // numeric keypad + if ((modifier & B_COMMAND_KEY) == 0) { - PostMessage(M_VOLUME_UP); + _ZoomVideoView(10); return true; } break; case 0x25: // numeric keypad - if ((modifier & B_COMMAND_KEY) == 0) { - PostMessage(M_VOLUME_DOWN); + _ZoomVideoView(-10); return true; } break; @@ -2063,6 +2097,24 @@ MainWin::_KeyDown(BMessage* msg) case 0x48: // numeric keypad left arrow PostMessage(M_SKIP_PREV); return true; + + // Playback controls along the bottom of the keyboard: + // Z X C V B for US International + case 0x4c: + PostMessage(M_SKIP_PREV); + return true; + case 0x4d: + fController->Play(); + return true; + case 0x4e: + fController->Pause(); + return true; + case 0x4f: + fController->Stop(); + return true; + case 0x50: + PostMessage(M_SKIP_NEXT); + return true; } return false; diff --git a/src/apps/mediaplayer/MainWin.h b/src/apps/mediaplayer/MainWin.h index 12f9557ba3..738b8b11c6 100644 --- a/src/apps/mediaplayer/MainWin.h +++ b/src/apps/mediaplayer/MainWin.h @@ -98,6 +98,7 @@ private: void _GetUnscaledVideoSize(int& videoWidth, int& videoHeight) const; int _CurrentVideoSizeInPercent() const; + void _ZoomVideoView(int percentDiff); void _ResizeWindow(int percent, bool useNoVideoWidth = false, bool stayOnScreen = false);