summaryrefslogtreecommitdiff
path: root/NxWidgets/nxwm/src
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2014-07-15 15:09:13 -0600
committerGregory Nutt <gnutt@nuttx.org>2014-07-15 15:09:13 -0600
commit30bd1b4ab2fbc7420dad999b18091d04e6438689 (patch)
tree3257395bedc7f2b8423bd4812ce3b2d5df6d114b /NxWidgets/nxwm/src
parentb5f93038acbef20d72d4c7fa8aed3f10825aef39 (diff)
downloadnuttx-30bd1b4ab2fbc7420dad999b18091d04e6438689.tar.gz
nuttx-30bd1b4ab2fbc7420dad999b18091d04e6438689.tar.bz2
nuttx-30bd1b4ab2fbc7420dad999b18091d04e6438689.zip
NxWM::CMediaPlayer: Some improved state management
Diffstat (limited to 'NxWidgets/nxwm/src')
-rw-r--r--NxWidgets/nxwm/src/cmediaplayer.cxx253
1 files changed, 180 insertions, 73 deletions
diff --git a/NxWidgets/nxwm/src/cmediaplayer.cxx b/NxWidgets/nxwm/src/cmediaplayer.cxx
index c57ed8dcc..bb9266ccc 100644
--- a/NxWidgets/nxwm/src/cmediaplayer.cxx
+++ b/NxWidgets/nxwm/src/cmediaplayer.cxx
@@ -246,39 +246,12 @@ void CMediaPlayer::hide(void)
void CMediaPlayer::redraw(void)
{
- char buffer[24];
+ // Redraw widgets (only)
- snprintf(buffer, 24, "Coming soon!");
-
- // setText will perform the redraw as well
-
- m_text->setText(buffer);
-
- // Get the widget control associated with the application window
-
- NXWidgets::CWidgetControl *control = m_window->getWidgetControl();
-
- // Get the CCGraphicsPort instance for this window
-
- NXWidgets::CGraphicsPort *port = control->getGraphicsPort();
-
- // Fill the entire window with the background color
-
- port->drawFilledRect(0, 0, m_windowSize.w, m_windowSize.h,
- CONFIG_NXWM_MEDIAPLAYER_BACKGROUNDCOLOR);
-
- // Enable and redraw widgets
-
- m_text->enableDrawing();
m_text->redraw();
-
- m_rew->enableDrawing();
- m_rew->redraw();
- m_playPause->enableDrawing();
m_playPause->redraw();
- m_fwd->enableDrawing();
+ m_rew->redraw();
m_fwd->redraw();
- m_volume->enableDrawing();
m_volume->redraw();
}
@@ -368,6 +341,10 @@ bool CMediaPlayer::createPlayer(void)
m_text->setFont(m_font);
+ // Add some dummy text for now
+
+ m_text->setText("Coming soon...");
+
// Create all bitmaps
NXWidgets::CRlePaletteBitmap *playBitmap = new NXWidgets::
@@ -442,6 +419,7 @@ bool CMediaPlayer::createPlayer(void)
// Configure the Play image
+ m_playPause->disableDrawing();
m_playPause->alignHorizontalCenter();
m_playPause->alignVerticalCenter();
#ifndef CONFIG_NXWM_MEDIAPLAYER_BORDERS
@@ -465,6 +443,7 @@ bool CMediaPlayer::createPlayer(void)
// Configure the Rewind image
+ m_rew->disableDrawing();
m_rew->alignHorizontalCenter();
m_rew->alignVerticalCenter();
#ifndef CONFIG_NXWM_MEDIAPLAYER_BORDERS
@@ -488,6 +467,7 @@ bool CMediaPlayer::createPlayer(void)
// Configure the Forward image
+ m_fwd->disableDrawing();
m_fwd->alignHorizontalCenter();
m_fwd->alignVerticalCenter();
#ifndef CONFIG_NXWM_MEDIAPLAYER_BORDERS
@@ -518,6 +498,7 @@ bool CMediaPlayer::createPlayer(void)
// Configure the volume control
+ m_volume->disableDrawing();
m_volume->setMinimumValue(0);
m_volume->setMaximumValue(100);
m_volume->setValue(15);
@@ -526,6 +507,32 @@ bool CMediaPlayer::createPlayer(void)
m_volume->addWidgetEventHandler(this);
+ // Make sure that all widgets are setup for the STOPPED state
+
+ setMediaPlayerState(MPLAYER_STOPPED);
+
+ // Redraw the background once only
+ // Get the CCGraphicsPort instance for this window
+
+ NXWidgets::CGraphicsPort *port = control->getGraphicsPort();
+
+ // Fill the entire window with the background color
+
+ port->drawFilledRect(0, 0, m_windowSize.w, m_windowSize.h,
+ CONFIG_NXWM_MEDIAPLAYER_BACKGROUNDCOLOR);
+
+ // Enable drawing of all widgets
+
+ m_text->enableDrawing();
+ m_playPause->enableDrawing();
+ m_rew->enableDrawing();
+ m_fwd->enableDrawing();
+ m_volume->enableDrawing();
+
+ // And redraw them
+
+ redraw();
+
return true;
}
@@ -548,6 +555,105 @@ void CMediaPlayer::close(void)
}
/**
+ * Transition to a new media player state.
+ *
+ * @param state The new state to enter.
+ */
+
+void CMediaPlayer::setMediaPlayerState(enum EMediaPlayerState state)
+{
+ // Handle according to the new state
+
+ switch (state)
+ {
+ case MPLAYER_STOPPED: // Initial state. Also the state after playing completes
+ m_state = MPLAYER_STOPPED;
+
+ m_text->enable();
+
+ m_playPause->enable();
+
+ m_fwd->disable();
+ m_fwd->setStuckSelection(false);
+
+ m_rew->disable();
+ m_rew->setStuckSelection(false);
+
+ m_volume->enable();
+ break;
+
+ case MPLAYER_PLAYING: // Playing a media file
+ m_state = MPLAYER_PLAYING;
+ m_prevState = MPLAYER_PLAYING;
+
+ m_text->disable();
+
+ m_playPause->enable();
+
+ m_fwd->enable();
+ m_fwd->setStuckSelection(false);
+
+ m_rew->enable();
+ m_rew->setStuckSelection(false);
+
+ m_volume->enable();
+ break;
+
+ case MPLAYER_PAUSED: // Playing a media file but paused
+ m_state = MPLAYER_PAUSED;
+ m_prevState = MPLAYER_PAUSED;
+
+ m_text->enable();
+
+ m_playPause->enable();
+
+ m_fwd->enable();
+ m_fwd->setStuckSelection(false);
+
+ m_rew->enable();
+ m_rew->setStuckSelection(false);
+
+ m_volume->enable();
+ break;
+
+ case MPLAYER_FFORWARD: // Fast forwarding through a media file */
+ m_state = MPLAYER_FFORWARD;
+
+ m_text->disable();
+
+ m_playPause->enable();
+
+ m_fwd->enable();
+ m_fwd->setStuckSelection(true);
+
+ m_rew->enable();
+ m_rew->setStuckSelection(false);
+
+ m_volume->enable();
+ break;
+
+ case MPLAYER_FREWIND: // Rewinding a media file
+ m_state = MPLAYER_FREWIND;
+
+ m_text->disable();
+
+ m_playPause->enable();
+
+ m_fwd->enable();
+ m_fwd->setStuckSelection(false);
+
+ m_rew->enable();
+ m_rew->setStuckSelection(true);
+
+ m_volume->enable();
+ break;
+
+ default:
+ break;
+ }
+}
+
+/**
* Handle a widget action event. For CButtonArray, this is a button pre-
* release event.
*
@@ -556,87 +662,88 @@ void CMediaPlayer::close(void)
void CMediaPlayer::handleActionEvent(const NXWidgets::CWidgetEventArgs &e)
{
- // Check is a media file has been selected. Do nothing if there is
- // no media file.
+ // Check if the Play/Pause button was clicked
if (m_playPause->isClicked())
{
- printf("Play/pause clicked\n");
-
- // Playing or pausing?
+ // Were we playing before?
if (m_state == MPLAYER_PLAYING)
{
- printf("Media player is now paused\n");
- m_state = MPLAYER_PAUSED;
- m_prevState = MPLAYER_PAUSED;
+ // Yes.. then now we are now paused
+
+ setMediaPlayerState(MPLAYER_PAUSED);
}
- else
+
+ // Were we paused or stopped before?
+
+ else if (m_state == MPLAYER_STOPPED || m_state == MPLAYER_PAUSED)
{
- printf("Media player is now playing\n");
- m_state = MPLAYER_PLAYING;
- m_prevState = MPLAYER_PLAYING;
+ // Yes... then now we are playing
+
+ setMediaPlayerState(MPLAYER_PLAYING);
}
- // In any case, we are certainly no longer fast forwarding or rewinding
+ // If the play/pause button was pressed while were were fast
+ // forwarding or rewinding, then revert back to the previous
+ // play/pause state.
- m_rew->setStuckSelection(false);
- m_fwd->setStuckSelection(false);
+
+ else
+ {
+ setMediaPlayerState(m_prevState);
+ }
}
+ // Check if the rewind button was clicked
+
if (m_rew->isClicked())
{
- printf("Rewind clicked\n");
+ // Were we already rewinding?
if (m_state == MPLAYER_FREWIND)
{
- // Or increase rewind speed?
- printf("Reverting to previous Play/Pause state\n");
- m_state = m_prevState;
-
- // Show that we are no longer rewinding
+ // Yes.. then revert to the previous play/pause state
+ // REVISIT: Or just increase rewind speed?
- m_rew->setStuckSelection(false);
- }
- else
- {
- printf("Rewinding...\n");
- m_state = MPLAYER_FREWIND;
+ setMediaPlayerState(m_prevState);
}
- // In any case, we are certainly no longer fast forwarding
+ // We should not be stopped here, but let's check anyway
- m_fwd->setStuckSelection(false);
+ else if (m_state != MPLAYER_STOPPED)
+ {
+ // Start rewinding
+
+ setMediaPlayerState(MPLAYER_FREWIND);
+ }
}
if (m_fwd->isClicked())
{
- printf("Forward clicked\n");
+ // Were we already fast forwarding?
if (m_state == MPLAYER_FFORWARD)
{
- // Or increase fast forward speed?
- printf("Reverting to previous Play/Pause state\n");
- m_state = m_prevState;
-
- // Show that we are no longer fast forwarding
+ // Yes.. then revert to the previous play/pause state
+ // REVISIT: Or just increase fast forward speed?
- m_fwd->setStuckSelection(false);
- }
- else
- {
- printf("Fast forwarding...\n");
- m_state = MPLAYER_FFORWARD;
+ setMediaPlayerState(m_prevState);
}
- // In any case, we are certainly no longer rewinding
+ // We should not be stopped here, but let's check anyway
- m_rew->setStuckSelection(false);
+ else if (m_state != MPLAYER_STOPPED)
+ {
+ // Start fast forwarding
+
+ setMediaPlayerState(MPLAYER_FFORWARD);
+ }
}
if (m_volume->isClicked())
{
- printf("Volume clicked\n");
+printf("Volume clicked\n"); // REMOVE ME
}
}