QTfrontend/util/SDLInteraction.h
changeset 6165 6fe3e922246e
parent 6164 62aa418ed214
child 6166 701c5b8fac56
equal deleted inserted replaced
6164:62aa418ed214 6165:6fe3e922246e
       
     1 /*
       
     2  * Hedgewars, a free turn based strategy game
       
     3  * Copyright (c) 2007-2011 Andrey Korotaev <unC0Rr@gmail.com>
       
     4  *
       
     5  * This program is free software; you can redistribute it and/or modify
       
     6  * it under the terms of the GNU General Public License as published by
       
     7  * the Free Software Foundation; version 2 of the License
       
     8  *
       
     9  * This program is distributed in the hope that it will be useful,
       
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    12  * GNU General Public License for more details.
       
    13  *
       
    14  * You should have received a copy of the GNU General Public License
       
    15  * along with this program; if not, write to the Free Software
       
    16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
       
    17  */
       
    18 
       
    19 #ifndef HEDGEWARS_SDLINTERACTION_H
       
    20 #define HEDGEWARS_SDLINTERACTION_H
       
    21 
       
    22 
       
    23 #include <QMap>
       
    24 #include <QStringList>
       
    25 
       
    26 #include "SDL_mixer.h"
       
    27 
       
    28 /**
       
    29  * @brief Class for interacting with SDL (used for music and keys)
       
    30  * 
       
    31  * @see <a href="http://en.wikipedia.org/wiki/Singleton_pattern">singleton pattern</a>
       
    32  */
       
    33 class SDLInteraction
       
    34 {
       
    35 
       
    36 private:
       
    37     /**
       
    38      * @brief Class constructor of the <i>singleton</i>.
       
    39      * 
       
    40      * Not to be used from outside the class,
       
    41      * use the static {@link HWDataManager::instance()} instead.
       
    42      * 
       
    43      * @see <a href="http://en.wikipedia.org/wiki/Singleton_pattern">singleton pattern</a>
       
    44      */
       
    45     SDLInteraction();
       
    46 
       
    47     /// Initializes SDL for sound output if needed.
       
    48     void SDLSoundInit();
       
    49 
       
    50     Mix_Music *music;
       
    51     int musicInitialized;
       
    52 
       
    53     QMap<QString,Mix_Chunk*> * soundMap; ///< maps sound file paths to channel
       
    54 
       
    55 public:
       
    56     /**
       
    57      * @brief Returns reference to the <i>singleton</i> instance of this class.
       
    58      * 
       
    59      * @see <a href="http://en.wikipedia.org/wiki/Singleton_pattern">singleton pattern</a>
       
    60      * 
       
    61      * @return reference to the instance.
       
    62      */
       
    63     static SDLInteraction & instance();
       
    64 
       
    65     /// Class Destructor.
       
    66     ~SDLInteraction();
       
    67 
       
    68     /**
       
    69      * @brief Returns available (screen) resolutions.
       
    70      *
       
    71      * @return list of resolutions in the format WIDTHxHEIGHT.
       
    72      */
       
    73     QStringList getResolutions() const;
       
    74 
       
    75     /// Adds all available joystick controlls to the list of SDL keys.
       
    76     void addGameControllerKeys() const;
       
    77 
       
    78     /**
       
    79      * @brief Plays a sound file.
       
    80      * 
       
    81      * @param soundFile path of the sound file.
       
    82      */
       
    83     void playSoundFile(const QString & soundFile);
       
    84 
       
    85     /// Starts the background music.
       
    86     void startMusic();
       
    87 
       
    88     /// Fades out and stops the background music.
       
    89     void stopMusic();
       
    90 };
       
    91 
       
    92 
       
    93 #endif //HEDGEWARS_SDLINTERACTION_H
       
    94