summaryrefslogtreecommitdiff
path: root/NxWidgets/nxwm/src
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2014-07-28 12:48:05 -0600
committerGregory Nutt <gnutt@nuttx.org>2014-07-28 12:48:05 -0600
commite0e9403c485f542f7f0b40ddd3bf2c9b256fa55f (patch)
treee478778f6071ab5cb9618031ec131d1128c9de8b /NxWidgets/nxwm/src
parentf73e309d512f3740b683fd2fe680b894c8515262 (diff)
downloadnuttx-e0e9403c485f542f7f0b40ddd3bf2c9b256fa55f.tar.gz
nuttx-e0e9403c485f542f7f0b40ddd3bf2c9b256fa55f.tar.bz2
nuttx-e0e9403c485f542f7f0b40ddd3bf2c9b256fa55f.zip
NxWM::CMediaPlayer: Add a CLabel that show the current fast forward/rewind speed
Diffstat (limited to 'NxWidgets/nxwm/src')
-rw-r--r--NxWidgets/nxwm/src/cmediaplayer.cxx119
1 files changed, 112 insertions, 7 deletions
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