/*
 * Copyright  2011 Nokia Corporation.
 *
 */


#ifndef GameWindow_H
#define GameWindow_H

#include <QWidget>

#include "GEAudioOut.h"
#include "GEInterfaces.h"
#include <EGL/egl.h>

#ifdef Q_OS_SYMBIAN
class CRepository;
#endif

namespace GE {

class GameWindow : public QWidget
{
    Q_OBJECT
public:
    explicit GameWindow(QWidget *parent = 0);
    virtual ~GameWindow();

    virtual void create();
    virtual void destroy();
    virtual void pause();
    virtual void resume();

    // Helpers
    float getFrameTime() { return m_frameTime; }
    float getFPS() { return m_fps; }

    // Override paintevent.
    void paintEvent(QPaintEvent *e) {};


    // Audio status / control
    bool isProfileSilent();
    bool isAudioEnabled() {
        if (m_audioOutput)
            return true;
        else
            return false;
    }
    void stopAudio();
    void startAudio();
    CAudioMixer &getMixer() { return m_audioMixer; }


    inline bool audioEnabled() { return m_audioEnabled; }

protected:
    unsigned int getTickCount();
    bool eventFilter(QObject *object, QEvent *event);
    virtual void resizeEvent( QResizeEvent *event );

    virtual void createEGL();

    // Render callback called when window needs to draw
    virtual void render();


    // Application callbacks
    virtual void onRender();
    virtual void onPause() {};
    virtual void onResume() {};
    virtual int onCreate();
    virtual void onDestroy();
    virtual void fullscreen();
    virtual void update(const float fFrameDelta);
    virtual void setSize(int w, int h ) {};

    void timerEvent(QTimerEvent *event);

    bool TestEGLError(const char* pszLocation);
    void CleanupAndExit ( EGLDisplay eglDisplay );

    // EGL variables
    EGLDisplay eglDisplay;
    EGLConfig eglConfig;
    EGLSurface eglSurface;
    EGLContext eglContext;

    // Time calculation
    unsigned int m_prevTime;
    unsigned int m_currentTime;
    float m_frameTime;
    float m_fps;

    bool m_audioEnabled;


    bool m_paused;
    int timerid;

    // AUDIO
    GE::AudioOut *m_audioOutput;
    GE::CAudioMixer m_audioMixer;

#ifdef Q_OS_SYMBIAN
    CRepository *iProfileRepository;
#endif
};

}

#endif // GameWindow_H
