summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2014-07-15 08:41:19 -0600
committerGregory Nutt <gnutt@nuttx.org>2014-07-15 08:41:19 -0600
commitc5b8bd6d3a309d7c075c59df1dbbd03218d679cb (patch)
tree04eddf9fad8c06bb34762385f2eb593296746d39
parentec94d776a6181c7c2f7c901677c65613f78287c3 (diff)
downloadpx4-nuttx-c5b8bd6d3a309d7c075c59df1dbbd03218d679cb.tar.gz
px4-nuttx-c5b8bd6d3a309d7c075c59df1dbbd03218d679cb.tar.bz2
px4-nuttx-c5b8bd6d3a309d7c075c59df1dbbd03218d679cb.zip
NxWM::CMediaPlay: Now receives button events
-rw-r--r--NxWidgets/nxwm/include/cmediaplayer.hxx24
-rw-r--r--NxWidgets/nxwm/src/cmediaplayer.cxx92
2 files changed, 109 insertions, 7 deletions
diff --git a/NxWidgets/nxwm/include/cmediaplayer.hxx b/NxWidgets/nxwm/include/cmediaplayer.hxx
index eff13067a..7f909f478 100644
--- a/NxWidgets/nxwm/include/cmediaplayer.hxx
+++ b/NxWidgets/nxwm/include/cmediaplayer.hxx
@@ -80,19 +80,35 @@ namespace NxWM
{
private:
/**
+ * This enumeration identifies the state of the media player
+ */
+
+ enum EMediaPlayerState
+ {
+ MPLAYER_STOPPED = 0, /**< No media file has been selected */
+ MPLAYER_PLAYING, /**< Playing a media file */
+ MPLAYER_PAUSED, /**< Playing a media file but paused */
+ MPLAYER_FFORWARD, /**< Fast forwarding through a media file */
+ MPLAYER_FREWIND, /**< Rewinding a media file */
+ };
+
+ /**
* The structure defines a pending operation.
*/
struct SPendingOperation
{
- int64_t value; /**< Accumulated value */
- uint8_t operation; /**< Identifies the operations */
+ int64_t value; /**< Accumulated value */
+ uint8_t operation; /**< Identifies the operations */
};
/**
* Media player state data.
*/
+ enum EMediaPlayerState m_state; /**< Media player current state */
+ enum EMediaPlayerState m_prevState; /**< Media player previous state */
+
/**
* Cached constructor parameters.
*/
@@ -147,8 +163,8 @@ namespace NxWM
void close(void);
/**
- * Handle a widget action event. For CImage, this is a button pre-
- * release event.
+ * Handle a widget action event. This includes a button pre/release
+ * release events and volume slider change events.
*
* @param e The event data.
*/
diff --git a/NxWidgets/nxwm/src/cmediaplayer.cxx b/NxWidgets/nxwm/src/cmediaplayer.cxx
index 1190cee19..8e0f41585 100644
--- a/NxWidgets/nxwm/src/cmediaplayer.cxx
+++ b/NxWidgets/nxwm/src/cmediaplayer.cxx
@@ -90,6 +90,10 @@ CMediaPlayer::CMediaPlayer(CTaskbar *taskbar, CApplicationWindow *window)
m_text = (NXWidgets::CLabel *)0;
m_font = (NXWidgets::CNxFont *)0;
+ // Initial state is stopped
+
+ m_state = MPLAYER_STOPPED;
+
// Add our personalized window label
NXWidgets::CNxString myName = getName();
@@ -427,7 +431,7 @@ bool CMediaPlayer::createPlayer(void)
buttonH += 8;
- // Create the Play Image
+ // Create the Play image
nxgl_coord_t playControlX = (m_windowSize.w >> 1) - (playButtonW >> 1);
uint32_t controlY = (180 * m_windowSize.h) >> 8;
@@ -436,6 +440,8 @@ bool CMediaPlayer::createPlayer(void)
CImage(control, playControlX, (nxgl_coord_t)controlY,
playButtonW, buttonH, playBitmap);
+ // Configure the Play image
+
m_playPause->alignHorizontalCenter();
m_playPause->alignVerticalCenter();
#ifndef CONFIG_NXWM_MEDIAPLAYER_BORDERS
@@ -444,7 +450,11 @@ bool CMediaPlayer::createPlayer(void)
m_playPause->setBorderless(false);
#endif
- // Create the Rewind Image
+ // Register to get events from the mouse clicks on the Play image
+
+ m_playPause->addWidgetEventHandler(this);
+
+ // Create the Rewind image
nxgl_coord_t rewControlX = playControlX - rewButtonW -
CONFIG_NXWM_MEDIAPLAYER_XSPACING;
@@ -453,6 +463,8 @@ bool CMediaPlayer::createPlayer(void)
CImage(control, rewControlX, (nxgl_coord_t)controlY,
rewButtonW, buttonH, rewBitmap);
+ // Configure the Rewind image
+
m_rew->alignHorizontalCenter();
m_rew->alignVerticalCenter();
#ifndef CONFIG_NXWM_MEDIAPLAYER_BORDERS
@@ -461,6 +473,10 @@ bool CMediaPlayer::createPlayer(void)
m_rew->setBorderless(false);
#endif
+ // Register to get events from the mouse clicks on the Rewind image
+
+ m_rew->addWidgetEventHandler(this);
+
// Create the Forward Image
nxgl_coord_t fwdControlX = playControlX + playButtonW +
@@ -471,6 +487,8 @@ bool CMediaPlayer::createPlayer(void)
fwdButtonW, buttonH, fwdBitmap);
+ // Configure the Forward image
+
m_fwd->alignHorizontalCenter();
m_fwd->alignVerticalCenter();
#ifndef CONFIG_NXWM_MEDIAPLAYER_BORDERS
@@ -479,6 +497,10 @@ bool CMediaPlayer::createPlayer(void)
m_fwd->setBorderless(false);
#endif
+ // Register to get events from the mouse clicks on the Forward image
+
+ m_fwd->addWidgetEventHandler(this);
+
// Create the Volume control
NXWidgets::CRlePaletteBitmap *volBitmap = new NXWidgets::
@@ -495,10 +517,16 @@ bool CMediaPlayer::createPlayer(void)
volBitmap->getHeight() + 4, volBitmap,
MKRGB(63, 90,192));
+ // Configure the volume control
+
m_volume->setMinimumValue(0);
m_volume->setMaximumValue(100);
m_volume->setValue(15);
+ // Register to get events from the mouse clicks on the Forward image
+
+ m_volume->addWidgetEventHandler(this);
+
return true;
}
@@ -529,7 +557,65 @@ void CMediaPlayer::close(void)
void CMediaPlayer::handleActionEvent(const NXWidgets::CWidgetEventArgs &e)
{
- /* Nothing here yet! Coming soon! */
+ // Check is a media file has been selected. Do nothing if there is
+ // no media file.
+
+ if (m_playPause->isClicked())
+ {
+ printf("Play/pause clicked\n");
+
+ if (m_state == MPLAYER_PLAYING)
+ {
+ printf("Media player is now paused\n");
+ m_state = MPLAYER_PAUSED;
+ m_prevState = MPLAYER_PAUSED;
+ }
+ else
+ {
+ printf("Media player is now playing\n");
+ m_state = MPLAYER_PLAYING;
+ m_prevState = MPLAYER_PLAYING;
+ }
+ }
+
+ if (m_rew->isClicked())
+ {
+ printf("Rewind clicked\n");
+
+ if (m_state == MPLAYER_FREWIND)
+ {
+ // Or increase rewind speed?
+ printf("Reverting to previous Play/Pause state\n");
+ m_state = m_prevState;
+ }
+ else
+ {
+ printf("Rewinding...\n");
+ m_state = MPLAYER_FREWIND;
+ }
+ }
+
+ if (m_fwd->isClicked())
+ {
+ printf("Forward clicked\n");
+
+ if (m_state == MPLAYER_FFORWARD)
+ {
+ // Or increase fast forward speed?
+ printf("Reverting to previous Play/Pause state\n");
+ m_state = m_prevState;
+ }
+ else
+ {
+ printf("Fast forwarding...\n");
+ m_state = MPLAYER_FFORWARD;
+ }
+ }
+
+ if (m_volume->isClicked())
+ {
+ printf("Volume clicked\n");
+ }
}
/**