From 74c42dfcc7593b2709a7ebf314c87fa6abd8cb78 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 15 Jul 2014 19:47:56 -0600 Subject: NxWM::CMediaPlayer: Fix issues with state changes performed on the PreRelese event handler --- NxWidgets/nxwm/include/cmediaplayer.hxx | 23 ++++++++++++ NxWidgets/nxwm/src/cmediaplayer.cxx | 64 ++++++++++++++++++++++++++++----- 2 files changed, 79 insertions(+), 8 deletions(-) (limited to 'NxWidgets/nxwm') 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 + * Gregory Nutt * * 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 @@ -903,6 +912,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 * -- cgit v1.2.3