Subversion Repositories spk

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

#ifndef __DISPLAY_H__
#define __DISPLAY_H__

#include <spk.h>
#include "../../src/Visualisation/TextureFile.h"
#include "../Overlay.h"
#include "RenderObject.h"

#include <fmod.hpp>

typedef struct SSound {
        struct SSound () { iStart = 0; bStarted = false; }
        CyString sFilename;
        long    iStart;
        bool    bStarted;
} SSound;

typedef struct SFunction {
        CyString sFunction;
        CyString sBlock;
        CyStringList lVaribles;
        CyStringList lStrings;
} SFunction;

typedef struct SCloseOn {
        struct SCloseOn () { iStart = 0; iEnd = 0; iMouseCommands = 0; iKeyCommands = 0; }
        int iStart;
        int iEnd;
        long iMouseCommands;
        long iKeyCommands;
} SCloseOn;

#define COMMAND_LEFTCLICK               1
#define COMMAND_RIGHTCLICK              2
#define COMMAND_LEFTCLICKIN             4
#define COMMAND_RIGHTCLICKIN    8

#define COMMAND_KEY_ENTER               1
#define COMMAND_KEY_SPACE               2


class CDisplay
{
public:
        CDisplay ( COverlay *overlay, MyDirect3DDevice9 *device, CyString name );
        ~CDisplay ();

        int GetBorderSizeX () { return m_iBorderSizeX; }
        int GetBorderSizeY () { return m_iBorderSizeY; }

        int GetMouseX ();
        int GetMouseY ();

        static void Log ( CyString str )
        {
                FILE *id;
                fopen_s ( &id, "d:/log.txt", "a" );
                fputs ( str.c_str(), id );
                fclose ( id );
        }

        bool HaltMouse () { return m_bHaltMouse; }
        bool IsMouseInGui ();

        void SetMouse ( int *x, int *y )
        {
                m_pMouseX = x;
                m_pMouseY = y;
        
                if ( m_bContainMouse )
                {
                        *m_pMouseX = m_iWidth / 2;
                        *m_pMouseY = m_iHeight / 2;
                }
        }
        void CreateSound ( CyString file, long start );
        virtual void SetSize ( int width, int height, int maxwidth, int maxheight );

        CyString ParseVaribles ( CyString str, CyStringList *varibles );

        void SetTimeout ( long time ) { m_lTimeout = time; }
        long GetTimeout () { return m_lTimeout; }
        void AddObject ( CRenderObject *o )     { m_objects.push_back ( o ); }
        void RemoveObject ( CRenderObject *o ) { m_objects.remove ( o ); }
        void ClearObjects () 
        {
                for ( CRenderObject *o = m_objects.First(); o; o = m_objects.Next() )
                        delete o;
                m_objects.clear();
        }

        virtual float Update ( DWORD timeNow );
        virtual void render ( MyDirect3DDevice9 * );
        virtual void RenderBorder ( MyDirect3DDevice9 * );
        virtual void RenderCursor ( MyDirect3DDevice9 *device );
        virtual void SetBorderTexture ( CyString t );
        virtual void SetCursorTexture ( CyString t );
        virtual void SetLength(int i) { m_iSizeY = i; }
        virtual void SetWidth(int i) { m_iSizeX = i; }
        virtual void SetMaxSize(int x, int y) { m_iMaxWidth = x; m_iMaxHeight = y; }

        virtual bool MouseClick ( int b, bool );
        virtual bool CheckCloseEventKey ( int key );
        bool Closed () { return m_bClosed; }
        bool CheckName(const CyString &name) { return m_sGuiName.Compare(name); }
        bool CheckTimeout(DWORD tNow)
        {
                if ( ((m_lTimeout != -1) && (m_lTimeout < (int)tNow)) || (m_bClosed) )
                        return true;
                return false;
        }

        void SwitchRender () { m_bRender = !m_bRender; }
        virtual void SetPosition(int x, int y);
        virtual void SetSize(int width, int height);

protected:
        RECT *GetFrame ( int frame );

        CLinkList<CRenderObject> m_objects;
        CLinkList<SSound> m_lSounds;
        CLinkList<SCloseOn> m_lClose;
        CLinkList<SFunction> m_lFunctions;

        int m_iCornerX, m_iCornerY;
        int m_iSizeX, m_iSizeY;

        LPDIRECT3DTEXTURE9 m_borderTexture;
        LPDIRECT3DTEXTURE9 m_cursorTexture;
        LPD3DXSPRITE m_sprite;

        bool  m_bRender;
        bool    m_bNoBorder;

        long m_lTimeout;

        int m_iBorderSizeX;
        int m_iBorderSizeY;

        MyDirect3DDevice9 *m_pDevice;

        short m_iAlpha;
        long  m_iFadeIn;
        short m_iFadeState;
        long m_iStartDisplay;

        DWORD m_lastUpdate; // time when the world was last updated

        CTextureFile *m_pBorderFile;
        CTextureFile *m_pCursorFile;

        int *m_pMouseX, *m_pMouseY;

        bool m_bContainMouse;
        bool m_bHaltMouse;

        bool m_bClosed;
        bool m_bLongWait;

        int m_iWidth, m_iHeight;
        int m_iMaxWidth, m_iMaxHeight;

        COverlay *m_pOverlay;

        CyString m_sGuiName;

        bool m_bLog;
};


#endif //__DISPLAY_H__