summaryrefslogtreecommitdiff
path: root/NxWidgets/nxwm
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2014-07-15 19:47:56 -0600
committerGregory Nutt <gnutt@nuttx.org>2014-07-15 19:47:56 -0600
commit74c42dfcc7593b2709a7ebf314c87fa6abd8cb78 (patch)
tree2df773c5e905e42025f53626e9b30646cf85f82a /NxWidgets/nxwm
parent3b23fa49224b3134f09d7773bc5fd9c2d768f5fa (diff)
downloadnuttx-74c42dfcc7593b2709a7ebf314c87fa6abd8cb78.tar.gz
nuttx-74c42dfcc7593b2709a7ebf314c87fa6abd8cb78.tar.bz2
nuttx-74c42dfcc7593b2709a7ebf314c87fa6abd8cb78.zip
NxWM::CMediaPlayer: Fix issues with state changes performed on the PreRelese event handler
Diffstat (limited to 'NxWidgets/nxwm')
-rw-r--r--NxWidgets/nxwm/include/cmediaplayer.hxx23
-rw-r--r--NxWidgets/nxwm/src/cmediaplayer.cxx64
2 files changed, 79 insertions, 8 deletions
diff --git a/NxWidgets/nxwm/include/cmediaplayer.hxx b/NxWidgets/nxwm/include/cmediaplayer.hxx
index 8c07eea2d..f0888b57f 100644
--- a/NxWidgets/nxwm/include/cmediaplayer.hxx
+++ b/NxWidgets/nxwm/include/cmediaplayer.hxx
@@ -93,6 +93,13 @@ namespace NxWM
MPLAYER_FREWIND, /**< Rewinding a media file */
};
+ enum EPendingRelease
+ {
+ PENDING_NONE = 0, /**< Nothing is pending */
+ PENDING_PLAY_RELEASE, /**< Expect play image to be released */
+ PENDING_PAUSE_RELEASE /**< Expect pause image to be released */
+ };
+
/**
* The structure defines a pending operation.
*/
@@ -109,6 +116,7 @@ namespace NxWM
enum EMediaPlayerState m_state; /**< Media player current state */
enum EMediaPlayerState m_prevState; /**< Media player previous state */
+ enum EPendingRelease m_pending; /**< Pending image release event */
/**
* Cached constructor parameters.
@@ -181,6 +189,21 @@ namespace NxWM
void handleActionEvent(const NXWidgets::CWidgetEventArgs &e);
+ /**
+ * Handle a widget release event. Only the play and pause image release
+ * are of interest.
+ */
+
+ void handleReleaseEvent(const NXWidgets::CWidgetEventArgs &e);
+
+ /**
+ * Handle a widget release event when the widget WAS dragged outside of
+ * its original bounding box. Only the play and pause image release
+ * are of interest.
+ */
+
+ void handleReleaseOutsideEvent(const NXWidgets::CWidgetEventArgs &e);
+
public:
/**
* CMediaPlayer constructor
diff --git a/NxWidgets/nxwm/src/cmediaplayer.cxx b/NxWidgets/nxwm/src/cmediaplayer.cxx
index 566386e18..759eeead2 100644
--- a/NxWidgets/nxwm/src/cmediaplayer.cxx
+++ b/NxWidgets/nxwm/src/cmediaplayer.cxx
@@ -3,6 +3,7 @@
*
* Copyright (C) 2013 Ken Pettit. All rights reserved.
* Author: Ken Pettit <pettitkd@gmail.com>
+ * Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -82,17 +83,19 @@ CMediaPlayer::CMediaPlayer(CTaskbar *taskbar, CApplicationWindow *window)
{
// Save the constructor data
- m_taskbar = taskbar;
- m_window = window;
+ m_taskbar = taskbar;
+ m_window = window;
// Nullify widgets that will be instantiated when the window is started
- m_text = (NXWidgets::CLabel *)0;
- m_font = (NXWidgets::CNxFont *)0;
+ m_text = (NXWidgets::CLabel *)0;
+ m_font = (NXWidgets::CNxFont *)0;
// Initial state is stopped
- m_state = MPLAYER_STOPPED;
+ m_state = MPLAYER_STOPPED;
+ m_prevState = MPLAYER_STOPPED;
+ m_pending = PENDING_NONE;
// Add our personalized window label
@@ -832,7 +835,11 @@ void CMediaPlayer::handleActionEvent(const NXWidgets::CWidgetEventArgs &e)
if (m_play->isClicked() && m_state != MPLAYER_PLAYING)
{
- setMediaPlayerState(MPLAYER_PLAYING);
+ // Just arm the state change now, but don't do anything until the
+ // release occurs. Trying to do the state change before the NxWidgets
+ // release processing completes causes issues.
+
+ m_pending = PENDING_PLAY_RELEASE;
}
// These only make sense in non-STOPPED states
@@ -843,9 +850,11 @@ void CMediaPlayer::handleActionEvent(const NXWidgets::CWidgetEventArgs &e)
if (m_pause->isClicked() && m_state != MPLAYER_PAUSED)
{
- // Yes... then now we are playing
+ // Just arm the state change now, but don't do anything until the
+ // release occurs. Trying to do the state change before the NxWidgets
+ // release processing completes causes issues.
- setMediaPlayerState(MPLAYER_PAUSED);
+ m_pending = PENDING_PAUSE_RELEASE;
}
// Check if the rewind image was clicked
@@ -904,6 +913,45 @@ printf("Volume clicked\n"); // REMOVE ME
}
/**
+ * Handle a widget release event. Only the play and pause image release
+ * are of interest.
+ */
+
+void CMediaPlayer::handleReleaseEvent(const NXWidgets::CWidgetEventArgs &e)
+{
+ // Check if the Play image was released
+
+ if (m_pending == PENDING_PLAY_RELEASE && !m_play->isClicked())
+ {
+ // Now perform the delayed state change
+
+ setMediaPlayerState(MPLAYER_PLAYING);
+ m_pending = PENDING_NONE;
+ }
+
+ // Check if the Pause image was released
+
+ else if (m_pending == PENDING_PAUSE_RELEASE && !m_pause->isClicked())
+ {
+ // Now perform the delayed state change
+
+ setMediaPlayerState(MPLAYER_PAUSED);
+ m_pending = PENDING_NONE;
+ }
+}
+
+/**
+ * Handle a widget release event when the widget WAS dragged outside of
+ * its original bounding box. Only the play and pause image release
+ * are of interest.
+ */
+
+void CMediaPlayer::handleReleaseOutsideEvent(const NXWidgets::CWidgetEventArgs &e)
+{
+ handleReleaseEvent(e);
+}
+
+/**
* CMediaPlayerFactory Constructor
*
* @param taskbar. The taskbar instance used to terminate the console