QTfrontend/util/SDLInteraction.h
changeset 6616 f77bb02b669f
parent 6585 6225b838a630
child 6700 e04da46ee43c
equal deleted inserted replaced
6615:65602f1ef0f8 6616:f77bb02b669f
    30 
    30 
    31 #include "SDL_mixer.h"
    31 #include "SDL_mixer.h"
    32 
    32 
    33 /**
    33 /**
    34  * @brief Class for interacting with SDL (used for music and keys)
    34  * @brief Class for interacting with SDL (used for music and keys)
    35  * 
    35  *
    36  * @see <a href="http://en.wikipedia.org/wiki/Singleton_pattern">singleton pattern</a>
    36  * @see <a href="http://en.wikipedia.org/wiki/Singleton_pattern">singleton pattern</a>
    37  */
    37  */
    38 class SDLInteraction
    38 class SDLInteraction
    39 {
    39 {
    40 
    40 
    41 private:
    41     private:
    42     /**
    42         /**
    43      * @brief Class constructor of the <i>singleton</i>.
    43          * @brief Class constructor of the <i>singleton</i>.
    44      * 
    44          *
    45      * Not to be used from outside the class,
    45          * Not to be used from outside the class,
    46      * use the static {@link HWDataManager::instance()} instead.
    46          * use the static {@link HWDataManager::instance()} instead.
    47      * 
    47          *
    48      * @see <a href="http://en.wikipedia.org/wiki/Singleton_pattern">singleton pattern</a>
    48          * @see <a href="http://en.wikipedia.org/wiki/Singleton_pattern">singleton pattern</a>
    49      */
    49          */
    50     SDLInteraction();
    50         SDLInteraction();
    51 
    51 
    52     /// Initializes SDL for sound output if needed.
    52         /// Initializes SDL for sound output if needed.
    53     void SDLAudioInit();
    53         void SDLAudioInit();
    54 
    54 
    55     bool m_audioInitialized; ///< true if audio is initialized already
    55         bool m_audioInitialized; ///< true if audio is initialized already
    56     Mix_Music * m_music; ///< pointer to the music channel of the mixer
    56         Mix_Music * m_music; ///< pointer to the music channel of the mixer
    57     QString m_musicTrack; ///< path to the music track;
    57         QString m_musicTrack; ///< path to the music track;
    58     bool m_isPlayingMusic; ///< true if music was started but not stopped again.
    58         bool m_isPlayingMusic; ///< true if music was started but not stopped again.
    59 
    59 
    60     QMap<QString,Mix_Chunk*> * m_soundMap; ///< maps sound file paths to channels
    60         QMap<QString,Mix_Chunk*> * m_soundMap; ///< maps sound file paths to channels
    61 
    61 
    62     int lastchannel; ///< channel of the last music played
    62         int lastchannel; ///< channel of the last music played
    63 
    63 
    64 public:
    64     public:
    65     /**
    65         /**
    66      * @brief Returns reference to the <i>singleton</i> instance of this class.
    66          * @brief Returns reference to the <i>singleton</i> instance of this class.
    67      *
    67          *
    68      * @see <a href="http://en.wikipedia.org/wiki/Singleton_pattern">singleton pattern</a>
    68          * @see <a href="http://en.wikipedia.org/wiki/Singleton_pattern">singleton pattern</a>
    69      *
    69          *
    70      * @return reference to the instance.
    70          * @return reference to the instance.
    71      */
    71          */
    72     static SDLInteraction & instance();
    72         static SDLInteraction & instance();
    73 
    73 
    74     /// Class Destructor.
    74         /// Class Destructor.
    75     ~SDLInteraction();
    75         ~SDLInteraction();
    76 
    76 
    77     /**
    77         /**
    78      * @brief Returns available (screen) resolutions.
    78          * @brief Returns available (screen) resolutions.
    79      *
    79          *
    80      * @return list of resolutions in the format WIDTHxHEIGHT.
    80          * @return list of resolutions in the format WIDTHxHEIGHT.
    81      */
    81          */
    82     QStringList getResolutions() const;
    82         QStringList getResolutions() const;
    83 
    83 
    84     /// Adds all available joystick controlls to the list of SDL keys.
    84         /// Adds all available joystick controlls to the list of SDL keys.
    85     void addGameControllerKeys() const;
    85         void addGameControllerKeys() const;
    86 
    86 
    87     /**
    87         /**
    88      * @brief Plays a sound file.
    88          * @brief Plays a sound file.
    89      *
    89          *
    90      * @param soundFile path of the sound file.
    90          * @param soundFile path of the sound file.
    91      */
    91          */
    92     void playSoundFile(const QString & soundFile);
    92         void playSoundFile(const QString & soundFile);
    93 
    93 
    94     /**
    94         /**
    95      * @brief Sets the music track to be played (or not).
    95          * @brief Sets the music track to be played (or not).
    96      *
    96          *
    97      * @param musicFile path of the music file.
    97          * @param musicFile path of the music file.
    98      */
    98          */
    99     void setMusicTrack(const QString & musicFile);
    99         void setMusicTrack(const QString & musicFile);
   100 
   100 
   101     /// Starts the background music if not already playing.
   101         /// Starts the background music if not already playing.
   102     void startMusic();
   102         void startMusic();
   103 
   103 
   104     /// Fades out and stops the background music (if playing).
   104         /// Fades out and stops the background music (if playing).
   105     void stopMusic();
   105         void stopMusic();
   106 };
   106 };
   107 
   107 
   108 
   108 
   109 #endif //HEDGEWARS_SDLINTERACTION_H
   109 #endif //HEDGEWARS_SDLINTERACTION_H
   110 
   110