-- $LastChangedDate: 2011-03-17 19:59:52 -0400 (Thu, 17 Mar 2011) $
-- Macros written in Lua to expand C++ code for bindings between C++/Lua.
-- Avoid lua_/LUA_ which is reserved by Lua.

bindTable = {

class = "View",
typesig = "TYPESIG_VIEW",
luaCanInstantiate = true,

headers =
[[
#include "base/module.hh"
using namespace base;
#include "view/module.hh"
#include "view/view.hh"
#include "view/viewpoint_chase.hh"
#include "view/window.hh"
using namespace view;
]],

func_New = {
    comments = "View:New( {x1,y1,x2,y2} ) -- See C++ View::SetRect()",
    code = [[
        // Pop rectangle table {x1,y1,x2,y2}.
        const Rect<int> rect = POP_TABLE_INTO_RECT( L );

        // Default to chase-view.
        shptr<View> view = new View( ENABLE, rect, new ChaseViewpoint );

        // And add View to Window for Lua.
        GET_WINDOW().AddView( view );

        return NEW_USERDATA_SHPTR<View>( L, view, BIND_METATABLE_NAME );
    ]]
},

func_Destroy = {
    comments = "Lua's garbage collector indirectly invokes this C++ destructor.",
    code = [[
        return DESTROY_USERDATA_SHPTR<View>( L, CheckTypesigView );
    ]]
},

func_Enable = {
    comments = "View:Enable()",
    code = [[
        const bool enable = POP_BOOL( L );

        shptr<View> view = POP_USERDATA_AS_SHPTR<View>( L );
        CHECK_TYPESIG(view,TYPESIG_VIEW);

        view->Enable( enable );
    ]]
},

func_IfEnabled = {
    comments = "bool View:IfEnabled()",
    code = [[
        shptr<View> view = POP_USERDATA_AS_SHPTR<View>( L );
        CHECK_TYPESIG(view,TYPESIG_VIEW);
        lua_pushboolean( L, view->IfEnabled() );
        return 1;  // stack items to return
    ]]
},

func_SetRect = {
    comments = "View:SetRect(x1,y1,x2,y2) (set viewport: (x1,y1) = bottom-left (x2,y2) = top-right)",
    code = [[
        // Set viewport area.
        const LuaNumber y2 = POP_NUMBER( L );
        const LuaNumber x2 = POP_NUMBER( L );
        const LuaNumber y1 = POP_NUMBER( L );
        const LuaNumber x1 = POP_NUMBER( L );
        shptr<View> view     = POP_USERDATA_AS_SHPTR<View>( L );
        CHECK_TYPESIG(view,TYPESIG_VIEW);
        view->SetRect( Rect<int>( x1, y1, x2, y2 ) );
    ]]
},

func_EnableObjectInMainView = {
    comments = "View:EnableObjectInMainView()",
    code = [[
        const bool enable = POP_BOOL( L );
        shptr<Object> object = POP_USERDATA_AS_SHPTR<Object>( L );

        View::EnableObjectInMainView( *object, enable );
    ]]
},

func_SetViewpoint = {
    comments = "View:SetViewpoint()",
    code = [[
        shptr<Viewpoint> viewpoint = POP_USERDATA_AS_SHPTR<Viewpoint>( L );
        CHECK_TYPESIG(viewpoint,TYPESIG_VIEWPOINT);

        shptr<View> view = POP_USERDATA_AS_SHPTR<View>( L );
        CHECK_TYPESIG(view,TYPESIG_VIEW);

        view->SetViewpoint( viewpoint );
    ]]
},

func_TransformWorld2Eye = {
    comments = "Vec3 View:TransformWorld2Eye( x,y,z|Vec3 )",
    code = [[
        const WorldVertex wv = POP_VECTOR3<WorldVertex>( L );

        shptr<View> view = POP_USERDATA_AS_SHPTR<View>( L );
        CHECK_TYPESIG(view,TYPESIG_VIEW);

        const EyeVertex ev = view->TransformWorld2Eye( wv );
        PUSH_VECTOR3( L, ev );
        return 1;  // stack items to return
    ]]
},

func_SetOutlineColor = {
    comments = "View:SetOutlineColor( RGBA )",
    code = [[
        const RGBA outlineColor( POP_RGBA( L ) );
        shptr<View> view = POP_USERDATA_AS_SHPTR<View>( L );
        CHECK_TYPESIG(view,TYPESIG_VIEW);

        view->SetOutlineColor( outlineColor );
    ]]
},

}
