source file RFKTutorialApplication.h

Go to the documentation of this file.

#ifndef RFK_APPLICATION_H
#define RFK_APPLICATION_H

//******************************************************************************
// Copyright (c) 2005 Redway. All rights reserved.
//
// Redway3d is a registered trademark. Any reproduction and / or utilization
// of any material from this document without Redway?s express authorization
// are prohibited.
//******************************************************************************

#include "RFK.h"

#include "REDString.h"
#include "REDColor.h"
#include "REDState.h"
#include "REDLayerSet.h"

namespace RED
{
  class FileInfo;
  class StreamingPolicy;
  class WindowRenderInfo;
}

#define   app   RFK::TutorialApplication


namespace RFK
{
  #define CMD_FLAG_DISABLED     0x01
  #define CMD_FLAG_CHECKABLE    0x02
  #define CMD_FLAG_CHECKED      0x04


  typedef enum
  {
    EVT_ERROR           = 0,
    EVT_INIT            = 1,
    EVT_UPDATE          = 2,
    EVT_RENDER_COMPLETE = 3,
    EVT_CLOSE           = 4,
    EVT_RESIZE          = 5,
    EVT_PAINT           = 6,
    EVT_MOUSE           = 7,
    EVT_KEY_PRESSED     = 8,
    EVT_KEY_RELEASED    = 9,
    EVT_UVAR            = 10,
    EVT_DRAG_ENTER      = 11,
    EVT_DROP_FILE       = 12,
    EVT_ITEM_SELECT     = 13,
    EVT_CLOSE_INSPECTOR = 14,
    EVT_COUNT           = 15
  } EVENT;


  typedef enum
  {
    EVT_FLAG_ERROR          = 1 << 0,
    EVT_FLAG_MOUSE_POS      = 1 << 1,
    EVT_FLAG_MOUSE_BUTTONS  = 1 << 2,
    EVT_FLAG_MOUSE_WHEEL    = 1 << 3,
    EVT_FLAG_KEY            = 1 << 4,
    EVT_FLAG_RESIZE         = 1 << 5,
    EVT_FLAG_UVAR           = 1 << 6,
    EVT_FLAG_PATH           = 1 << 7,
  } EVENT_FLAG;


  typedef enum
  {
    EVT_ERR_NO_NETWORK          = 0,
    EVT_ERR_DOWNLOAD_FAILED     = 1,
    EVT_ERR_MISSING_DEPENDENCY  = 2,
  } EVENT_ERROR;


  typedef enum
  {
    IPR_GEOMETRY      = 0,
    IPR_UVAR          = 1,
    IPR_TONEMAPPING   = 2,
    IPR_PERFORMANCE   = 3,
    IPR_SCENEGRAPH    = 4,
    IPR_MEMORY        = 5,
    IPR_LIGHT         = 6,
    IPR_MATERIAL      = 7,
    IPR_TRANSFORM     = 8,
    IPR_VIEWPOINT     = 9
  } INSPECTOR;


  typedef enum
  {
    UVT_BOOL    = 0,
    UVT_CHAR    = 1,
    UVT_SHORT   = 2,
    UVT_INT     = 3,
    UVT_FLOAT   = 4,
    UVT_DOUBLE  = 5,
    UVT_STRING  = 6,
    UVT_LIST    = 7,
    UVT_FILE    = 8,
    
  } UVAR_TYPE;


  typedef enum
  {
    UVW_SLIDER  = 0,
    UVW_EDIT    = 1,
    UVW_VIEW    = 2
    
  } UVAR_WIDGET;


  typedef enum
  {
    KEY_ESCAPE = 0x01000000,
    KEY_TAB    = 0x01000001,
    KEY_RETURN = 0x01000004,
    KEY_SPACE  = 0x20,
    KEY_SHIFT  = 0x01000020,
    KEY_LEFT   = 0x01000012,
    KEY_UP     = 0x01000013,
    KEY_RIGHT  = 0x01000014,
    KEY_DOWN   = 0x01000015,
    KEY_LSHIFT = 0x01000020,
    KEY_LCTRL  = 0x01000021,
    KEY_MINUS  = 0x2d,
    KEY_PLUS   = 0x2b
    
  } KEYBOARD_KEY;


  typedef enum
  {
    LM_ACTIVE                 = 0,
    LM_PASSIVE                = 1,
    LM_SOFTWARE_BY_SURFACE    = 2,
    LM_SOFTWARE_BY_BLOCKS     = 3,
    LM_SOFTWARE_PATH_TRACING  = 4,
    LM_CUSTOM                 = 5,
    LM_CONSOLE                = 6
    
  } LOOP_MODE;


  typedef enum
  {
    YES     = 0,
    NO      = 1,
    OK      = 2,
    CANCEL  = 3
    
  } CHOICE;


  typedef struct
  {
    // Information validity flags.
    unsigned int _flags;
    
    // Error.
    EVENT_ERROR _error;
    RED::String _error_string;

    // Mouse informations.
    int _mouse_x;       // mouse cursor x coordinate
    int _mouse_y;       // mouse cursor y coordinate
    int _mouse_wheel;   // mouse wheel delta
    bool _mouse_left;   // mouse left button state
    bool _mouse_middle; // mouse middle button state
    bool _mouse_right;  // mouse right button state

    // Keyboard informations.
    int _key;           // key pressed or released

    // Window informations.
    int _win_width;     // window width
    int _win_height;    // window height

    // User variable informations.
    int _uvar;          // index of the modified user variable in the list

    // Drag & drop file.
    RED::String _path;  // path to the drag & drop file 

    // Item select.
    RED::Object*                _selected_item;       // selected item
    RED::Vector< RED::Object* > _selected_item_path;  // selected item path
    RFK::INSPECTOR _inspector;                        // inspector from which the object is selected
    bool _double_clicked;                             // test if double click

  } EventInfo;


  class UserVariable : public RED::Object
  {
  public:
    
    UserVariable()
    {
      _type = RFK::UVT_INT;
      _widget = RFK::UVW_VIEW;
      _d = 0.0;
      _dmin = 0.0;
      _dmax = 0.0;
      _dstep = 0.0;
      _list_current_index = 0;
    }
    
    UVAR_TYPE _type;
    
    UVAR_WIDGET _widget;
    
    union
    {
      bool _b;
      char _c;
      short _s;
      int _i;
      float _f;
      double _d;
    };
    
    union
    {
      char _cmin;
      short _smin;
      int _imin;
      float _fmin;
      double _dmin;
    };
    
    union
    {
      char _cmax;
      short _smax;
      int _imax;
      float _fmax;
      double _dmax;
    };
    
    union
    {
      char _cstep;
      short _sstep;
      int _istep;
      float _fstep;
      double _dstep;
    };
    
    RED::String _string;

    RED::Vector< RED::String > _list;
    
    int _list_current_index;

    // Extensions of the UVT_FILE variable
    RED::String _file_extensions;

    RED::String _name;
  };


  typedef RED_RC (*EVENT_CALLBACK)( EventInfo& iEventInfo, void* iParam );
  

  typedef RED_RC (*COMMAND_CALLBACK)( int iCommand );


  class RFKExp TutorialApplication
  {
  public:

    static int MainLoop( const RED::String&     iTitle, 
                         RFK::LOOP_MODE         iLoopMode = RFK::LM_PASSIVE,
                         double                 iFeedbackInterval = 500.0,
                         RED::WindowRenderInfo* iWindowRenderInfo = NULL,
                         bool                   iUseHybridREDsdk = true );


    static RED_RC Close( int iCommand = 0 );


    static RED_RC ShowSystemInformation( int iCommand = 0 );


    static RED_RC CreateCommand( int&                   oCommandID,
                                 const RED::String&     iDescription, 
                                 const RED::String&     iIconPath,
                                 const RED::String&     iShortCut,
                                 RFK::COMMAND_CALLBACK  iDo, 
                                 RFK::COMMAND_CALLBACK  iUndo = NULL,
                                 int                    iFlags = 0 ); 


    static RED_RC RunCommand( int iCommandID );


    static RED_RC DeleteCommand( int iCommandID );


    static RED_RC RemoveCommand( int iCommandID, 
                                 int iUIID = -1 );


    static int GetCommandState( int iCommandID );

    
    static void SetCommandState( int iCommandID,
                                 int iFlags );
    
    
    static RED_RC AddToolBar( int&                oUIID, 
                              const RED::String&  iLabel );


    static RED_RC AddMenu( int&                oUIID, 
                           const RED::String&  iLabel,
                           int                 iParentID = -1 );


    static RED_RC RemoveUIComponent( int iUIID );


    static void EnableUI( bool iEnabled );


    static RED_RC AddCommand( int iUIID, 
                              int iCommandID );


    static RED_RC AddSeparator( int iUIID );
    
    
    static RED_RC OpenFileDialog( RED::Vector< RED::String >& oFilesList,
                                  const RED::String&          iCaption,
                                  const RED::String&          iDirectory,
                                  const RED::String&          iFilter );
    
    
    static RED_RC ShowInspector( RFK::INSPECTOR                               iInspector, 
                                 RED::Object*                                 iObject = NULL,
                                 bool                                         iClosable = true,
                                 const RED::Map< unsigned int, RED::String >* iIDToNames = NULL );
    
    
    static void HideInspector( RFK::INSPECTOR iInspector );


    static bool IsInspectorVisible( RFK::INSPECTOR iInspector );


    static RED_RC SetInspectedObject( RFK::INSPECTOR                               iInspector, 
                                      RED::Object*                                 iObject,
                                      const RED::Map< unsigned int, RED::String >* iIDToNames = NULL );


    static RED_RC GetInspectedObject( RED::Object*&  oObject,
                                      RFK::INSPECTOR iInspector );


    static RED_RC RefreshInspector( RFK::INSPECTOR iInspector );


    static RED_RC SetSelectedItem( RFK::INSPECTOR iInspector,
                                   RED::Object*   iItem );


    static RED_RC SetUserVariables( const RED::Vector< RFK::UserVariable >& iUserVariables );


    static void UpdateUserVariables( const RED::Vector< RFK::UserVariable >& iUserVariables );


    static void GetUserVariables( RED::Vector< RFK::UserVariable >& oUserVariables );
    
    
    static void UpdateUserVariable( const RFK::UserVariable& iUserVariable );
    
    
    static void SetEventCallback( RFK::EVENT          iEvent, 
                                  RFK::EVENT_CALLBACK iCallback, 
                                  void*               iParam = NULL );


    static RFK::EVENT_CALLBACK GetEventCallback( RFK::EVENT iEvent, 
                                                 void**     iParam = NULL );


    static void SetMessage( const RED::String& iMessage );


    static RED_RC SetViewpoint( RED::Object* iViewpoint );


    static RED::Object* GetResourceManager();

  
    static RED::Object* GetViewpoint();


    static RED::Object* GetWindow();

    
    static RED_RC SetLoopMode( RFK::LOOP_MODE iLoopMode );


    static LOOP_MODE GetLoopMode();


    static void ResizeWindow( int iWidth, 
                              int iHeight );


    static void GetContentSize( int& oWidth, 
                                int& oHeight );


    static void GetContentPosition( int& oTop,
                                    int& oLeft );


    static RED_RC SaveContent( const RED::String& iFile );


    static RED_RC SendEvent( RFK::EVENT       iEvent, 
                             RFK::EventInfo&  iEventInfo );


    static RED_RC Invalidate();


    static RED_RC Redraw();

    
    static RED_RC StopFrameTracingIfNeeded();


    static RED_RC AddStringsMap( const RED::Map< unsigned int, RED::String >& iStringsMap );


    static const RED::Map< unsigned int, RED::String >& GetStringsMap();


    static RED::String GetStringFromID( unsigned int iID );


    static RED_RC TakeSnapshot( int iCommand = 0 );


    static void DisplayError( RED_RC      iRC, 
                              const char* iCaller, 
                              const void* iObject, 
                              const char* iExpression, 
                              const char* iInfo );


    static void DisplayError( RED_RC      iRC, 
                              const char* iFile, 
                              int         iLine );


    static void DisplayError( const RED::String& iHeader,
                              const RED::String& iMessage );
    
    
    static void DisplayMessage( const RED::String& iHeader,
                                const RED::String& iMessage );
    
    
    static void ShowProgressBar( bool iShow );


    static void UpdateProgressBar( float iValue, bool iForceRefresh = false );


    static void ShowFPS( bool iShow );
    

    static void ShowResolution( bool iShow );


    static float GetTime();
    
    
    static float GetREDTimeElapsed();


    static RED_RC SetBackgroundColor( const RED::Color& iColor );


    static RED::String GetFilePath( const RED::String& iExtensions );


    static void UpdateFPSCounter( float iFrameTime );


    static CHOICE Ask( const RED::String& iQuestion );


    static bool SaveImageStamp( const RED::String&  iFilePath, 
                                unsigned char*      iRGBA, 
                                int                 iWidth, 
                                int                 iHeight, 
                                RED::String         iText );


    static RED_RC OpenURL( const RED::String& iURL );


    static RED_RC AddFrameTracingImages( RED::Object* iColorImage,
                                         RED::Object* iDepthImage,
                                         RED::Object* iViewpoint );


    static RED_RC RemoveFrameTracingImages( RED::Object* iColorImage,
                                            RED::Object* iDepthImage,
                                            RED::Object* iViewpoint );


    static RED_RC ClearFrameTracingImages();

    
    // Files management:
    // -----------------
    
    static RED_RC LoadREDFile( RED::Object*&         oCamera,
                               unsigned int&         oDataContext,
                               RED::FileInfo*        oFileInfo,
                               const RED::String&    iPath,
                               RED::StreamingPolicy* iPolicy = NULL );


    static RED_RC LoadFBXFile( RED::Object*&        oCamera,
                               unsigned int&        oDataContext,
                               const RED::String&   iPath,
                               const RED::LayerSet* iRealTimeLayerSet,
                               const RED::LayerSet* iPhotorealisticLayerSet );
    

    static RED_RC SetRecentFiles( const RED::Vector< RED::String >& iRecentFiles );


    static const RED::Vector< RED::String >& GetRecentFiles();


    static RED::String GetCurrentExecutablePath();
    
    
    // Mouse cursor control:
    // ---------------------
    
    static void GetMouseCursorPosition( int& oX,
                                        int& oY );
    
    
    static void SetMouseCursorPosition( int iX,
                                        int iY );
    
    
    static void HideMouseCursor();
    
    
    static void ShowMouseCursor();

    
    static void SetCustomLicense( const RED::String& iLicenseKey,
                                  unsigned int       iCustomerID );
  };
};

#endif