From e0e9403c485f542f7f0b40ddd3bf2c9b256fa55f Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 28 Jul 2014 12:48:05 -0600 Subject: NxWM::CMediaPlayer: Add a CLabel that show the current fast forward/rewind speed --- NxWidgets/nxwm/src/cmediaplayer.cxx | 119 +++++++++++++++++++++++++++++++++--- 1 file changed, 112 insertions(+), 7 deletions(-) (limited to 'NxWidgets/nxwm/src') diff --git a/NxWidgets/nxwm/src/cmediaplayer.cxx b/NxWidgets/nxwm/src/cmediaplayer.cxx index 1ffde57a0..3091d6758 100644 --- a/NxWidgets/nxwm/src/cmediaplayer.cxx +++ b/NxWidgets/nxwm/src/cmediaplayer.cxx @@ -125,6 +125,9 @@ CMediaPlayer::CMediaPlayer(CTaskbar *taskbar, CApplicationWindow *window) m_rewind = (NXWidgets::CStickyImage *)0; m_fforward = (NXWidgets::CStickyImage *)0; m_volume = (NXWidgets::CGlyphSliderHorizontal *)0; +#if !defined(CONFIG_AUDIO_EXCLUDE_FFORWARD) || !defined(CONFIG_AUDIO_EXCLUDE_REWIND) + m_speed = (NXWidgets::CLabel *)0; +#endif // Nullify bitmaps that will be instantiated when the window is started @@ -144,7 +147,7 @@ CMediaPlayer::CMediaPlayer(CTaskbar *taskbar, CApplicationWindow *window) #ifndef CONFIG_AUDIO_EXCLUDE_VOLUME m_level = 0; #endif -#ifndef CONFIG_AUDIO_EXCLUDE_FFORWARD +#if !defined(CONFIG_AUDIO_EXCLUDE_FFORWARD) || !defined(CONFIG_AUDIO_EXCLUDE_REWIND) m_subSample = 0; #endif m_fileReady = false; @@ -208,6 +211,13 @@ CMediaPlayer::~CMediaPlayer(void) delete m_volume; } +#if !defined(CONFIG_AUDIO_EXCLUDE_FFORWARD) || !defined(CONFIG_AUDIO_EXCLUDE_REWIND) + if (m_speed) + { + delete m_speed; + } +#endif + // Destroy bitmaps if (m_playBitmap) @@ -332,6 +342,9 @@ void CMediaPlayer::stop(void) m_rewind->disableDrawing(); m_fforward->disableDrawing(); m_volume->disableDrawing(); +#if !defined(CONFIG_AUDIO_EXCLUDE_FFORWARD) || !defined(CONFIG_AUDIO_EXCLUDE_REWIND) + m_speed->disableDrawing(); +#endif } /** @@ -1011,6 +1024,32 @@ bool CMediaPlayer::createPlayer(void) m_volume->addWidgetEventHandler(this); #endif +#if !defined(CONFIG_AUDIO_EXCLUDE_FFORWARD) || !defined(CONFIG_AUDIO_EXCLUDE_REWIND) + // Create the speed of motion indicator + // The bounding box is determined by the font size + + nxgl_coord_t motionW = (nxgl_coord_t)(3 * m_font->getMaxWidth()); + nxgl_coord_t motionH = (nxgl_coord_t)(m_font->getHeight()); + + // Horizontal position: aligned with the right size of volume slider + // Vertical postion: same as the motion controls + + m_speed = new NXWidgets::CLabel(control, + volumeControlX + volumeControlW - motionW, + controlTop + (controlH - motionH) / 2, + motionW, motionH, ""); + + // Configure the speed indicator + + m_speed->disableDrawing(); + m_speed->setBorderless(true); + m_speed->setRaisesEvents(false); + m_speed->setFont(m_font); + m_speed->setTextAlignmentHoriz(NXWidgets::CLabel::TEXT_ALIGNMENT_HORIZ_RIGHT); + m_speed->setTextAlignmentVert(NXWidgets::CLabel::TEXT_ALIGNMENT_VERT_CENTER); + m_speed->hide(); +#endif + // Make sure that all widgets are setup for the STOPPED state. Among other this, // this will enable drawing in the play widget (only) @@ -1098,6 +1137,11 @@ void CMediaPlayer::redrawWidgets(void) m_fforward->enableDrawing(); m_fforward->redraw(); +#if !defined(CONFIG_AUDIO_EXCLUDE_FFORWARD) || !defined(CONFIG_AUDIO_EXCLUDE_REWIND) + m_speed->enableDrawing(); + m_speed->redraw(); +#endif + m_volume->enableDrawing(); m_volume->redraw(); } @@ -1147,9 +1191,9 @@ void CMediaPlayer::setMediaPlayerState(enum EMediaPlayerState state) m_rewind->disable(); m_rewind->setStuckSelection(false); +#ifndef CONFIG_AUDIO_EXCLUDE_VOLUME // Volume slider is available -#ifndef CONFIG_AUDIO_EXCLUDE_VOLUME m_volume->enable(); #endif break; @@ -1182,9 +1226,9 @@ void CMediaPlayer::setMediaPlayerState(enum EMediaPlayerState state) m_rewind->disable(); m_rewind->setStuckSelection(false); +#ifndef CONFIG_AUDIO_EXCLUDE_VOLUME // Volume slider is available -#ifndef CONFIG_AUDIO_EXCLUDE_VOLUME m_volume->enable(); #endif break; @@ -1353,6 +1397,12 @@ void CMediaPlayer::setMediaPlayerState(enum EMediaPlayerState state) break; } +#if !defined(CONFIG_AUDIO_EXCLUDE_FFORWARD) || !defined(CONFIG_AUDIO_EXCLUDE_REWIND) + // Update the motion indicator for the new state + + updateMotionIndicator(); +#endif + // Re-enable drawing and redraw all widgets for the new state redrawWidgets(); @@ -1470,6 +1520,57 @@ void CMediaPlayer::checkFileSelection(void) } } +/** + * Update fast forward/rewind speed indicator. Called on each state change + * and after each change in the speed of motion. + */ + +#if !defined(CONFIG_AUDIO_EXCLUDE_FFORWARD) || !defined(CONFIG_AUDIO_EXCLUDE_REWIND) +void CMediaPlayer::updateMotionIndicator(void) +{ + m_speed->disableDrawing(); + if (m_state == MPLAYER_FFORWARD || m_state == MPLAYER_FREWIND) + { + // Set the new speed string + + char buffer[8]; + (void)std::snprintf(buffer, 8, "%dX", g_motionSteps[m_subSample]); + + NXWidgets::CNxString speed(buffer); + m_speed->setText(speed); + + // Show (un-hide) the speed indicator + + m_speed->show(); + + // Redraw the speed indicator + + m_speed->enableDrawing(); + m_speed->redraw(); + } + + // No, then the speed indicator should be hidden. But don't redraw if + // it is already hidden + + else if (!m_speed->isHidden()) + { + // Clear the new speed string + + NXWidgets::CNxString nospeed(""); + m_speed->setText(nospeed); + + // Redraw the empty speed indicator + + m_speed->enableDrawing(); + m_speed->redraw(); + + // Hide the speed indicator + + m_speed->hide(); + } +} +#endif + /** * Handle a widget action event. For this application, that means image * pre-release events. @@ -1528,10 +1629,10 @@ void CMediaPlayer::handleActionEvent(const NXWidgets::CWidgetEventArgs &e) { dbg("ERROR: nxplayer_rewind failed: %d\n", ret); } - else - { - setMediaPlayerState(m_prevState); - } + + // Update the speed indicator + + updateMotionIndicator(); } // We should not be in a STOPPED state here, but let's check anyway @@ -1578,6 +1679,10 @@ void CMediaPlayer::handleActionEvent(const NXWidgets::CWidgetEventArgs &e) { dbg("ERROR: nxplayer_fforward failed: %d\n", ret); } + + // Update the speed indicator + + updateMotionIndicator(); } // We should not be in a STOPPED state here, but let's check anyway -- cgit v1.2.3