diff options
Diffstat (limited to 'NxWidgets')
-rw-r--r-- | NxWidgets/nxwm/include/cmediaplayer.hxx | 15 | ||||
-rw-r--r-- | NxWidgets/nxwm/src/cmediaplayer.cxx | 119 |
2 files changed, 126 insertions, 8 deletions
diff --git a/NxWidgets/nxwm/include/cmediaplayer.hxx b/NxWidgets/nxwm/include/cmediaplayer.hxx index 35a1630f0..f36036a2a 100644 --- a/NxWidgets/nxwm/include/cmediaplayer.hxx +++ b/NxWidgets/nxwm/include/cmediaplayer.hxx @@ -51,6 +51,7 @@ #include "cnxfont.hxx" #include "cimage.hxx" #include "cstickyimage.hxx" +#include "clabel.hxx" #include "clistbox.hxx" #include "clistboxdataitem.hxx" #include "cglyphsliderhorizontal.hxx" @@ -159,7 +160,7 @@ namespace NxWM #ifndef CONFIG_AUDIO_EXCLUDE_VOLUME uint8_t m_level; /**< Current volume level, range 0-100 */ #endif -#ifndef CONFIG_AUDIO_EXCLUDE_FFORWARD +#if !defined(CONFIG_AUDIO_EXCLUDE_FFORWARD) || !defined(CONFIG_AUDIO_EXCLUDE_REWIND) uint8_t m_subSample; /**< Current FFFORWARD subsampling index */ #endif @@ -187,6 +188,9 @@ namespace NxWM NXWidgets::CStickyImage *m_rewind; /**< Rewind control */ NXWidgets::CStickyImage *m_fforward; /**< Fast forward control */ NXWidgets::CGlyphSliderHorizontal *m_volume; /**< Volume control */ +#if !defined(CONFIG_AUDIO_EXCLUDE_FFORWARD) || !defined(CONFIG_AUDIO_EXCLUDE_REWIND) + NXWidgets::CLabel *m_speed; /**< FForward/rewind speed */ +#endif /** * Bitmaps @@ -300,6 +304,15 @@ namespace NxWM inline void checkFileSelection(void); +#if !defined(CONFIG_AUDIO_EXCLUDE_FFORWARD) || !defined(CONFIG_AUDIO_EXCLUDE_REWIND) + /** + * Update fast forward/rewind speed indicator. Called on each state + * change and after each change in the speed of motion. + */ + + void updateMotionIndicator(void); +#endif + /** * Handle a widget action event. For this application, that means image * pre-release events. 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(); @@ -1471,6 +1521,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 |