tclpkg-toglet.cc

Go to the documentation of this file.
00001 
00003 
00004 //
00005 // Copyright (c) 1998-2004 California Institute of Technology
00006 // Copyright (c) 2004-2007 University of Southern California
00007 // Rob Peters <rjpeters at usc dot edu>
00008 //
00009 // created: Mon Nov  2 08:00:00 1998 (as objtogl.cc)
00010 // commit: $Id: tclpkg-toglet.cc 10065 2007-04-12 05:54:56Z rjpeters $
00011 // $HeadURL: file:///lab/rjpeters/svnrepo/code/trunk/groovx/src/tcl-gfx/tclpkg-toglet.cc $
00012 //
00013 // --------------------------------------------------------------------
00014 //
00015 // This file is part of GroovX.
00016 //   [http://ilab.usc.edu/rjpeters/groovx/]
00017 //
00018 // GroovX is free software; you can redistribute it and/or modify it
00019 // under the terms of the GNU General Public License as published by
00020 // the Free Software Foundation; either version 2 of the License, or
00021 // (at your option) any later version.
00022 //
00023 // GroovX is distributed in the hope that it will be useful, but
00024 // WITHOUT ANY WARRANTY; without even the implied warranty of
00025 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00026 // General Public License for more details.
00027 //
00028 // You should have received a copy of the GNU General Public License
00029 // along with GroovX; if not, write to the Free Software Foundation,
00030 // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
00031 //
00033 
00034 #ifndef GROOVX_GFX_TCLPKG_TOGLET_CC_UTC20050628170310_DEFINED
00035 #define GROOVX_GFX_TCLPKG_TOGLET_CC_UTC20050628170310_DEFINED
00036 
00037 #include "tcl-gfx/tclpkg-toglet.h"
00038 
00039 #include "gfx/glcanvas.h"
00040 #include "gfx/gxcamera.h"
00041 #include "gfx/gxnode.h"
00042 
00043 #include "nub/objfactory.h"
00044 #include "nub/ref.h"
00045 
00046 #include "tcl/objpkg.h"
00047 #include "tcl/list.h"
00048 #include "tcl/pkg.h"
00049 
00050 #include "tcl-gfx/toglet.h"
00051 #include "tcl-gfx/vectcl.h"
00052 
00053 #include "rutz/error.h"
00054 
00055 #include "rutz/trace.h"
00056 
00057 namespace
00058 {
00059   // Make a specified GxNode the widget's current drawable, and draw
00060   // it in the OpenGL window. The widget's visibility is set to true.
00061   nub::uid see(nub::soft_ref<Toglet> widg, nub::ref<GxNode> item)
00062   {
00063     widg->setDrawable(item);
00064     widg->setVisibility(true);
00065     widg->fullRender();
00066     return item->id();
00067   }
00068 
00069   // We need to eagerly drop references to objects at shutdown time,
00070   // because Tcl tends to prematurely unload dynamically-loaded
00071   // packages... so we need to make sure we don't have any references
00072   // to objects whose members are defined in such packages.
00073   void clear_on_exit()
00074   {
00075     if (Toglet::getCurrent().is_valid())
00076       {
00077         Toglet::getCurrent()->setVisibility(false);
00078       }
00079   }
00080 }
00081 
00082 #include <tcl.h>
00083 
00084 extern "C"
00085 int Toglet_Init(Tcl_Interp* interp)
00086 {
00087 GVX_TRACE("Toglet_Init");
00088 
00089   if (Tcl_PkgRequire(interp, "Tk", 0, 0) == 0)
00090     return 1;
00091 
00092   GVX_PKG_CREATE(pkg, interp, "Toglet", "4.$Revision: 10065 $");
00093 
00094   pkg->on_exit( &clear_on_exit );
00095 
00096   pkg->inherit_pkg("TkWidget");
00097   tcl::def_basic_type_cmds<Toglet>(pkg, SRC_POS);
00098 
00099   nub::obj_factory::instance().register_creator( &Toglet::make );
00100   nub::obj_factory::instance().register_creator( &Toglet::makeToplevel,
00101                                               "TopToglet" );
00102 
00103   pkg->def( "::tog", 0, &Toglet::getCurrent, SRC_POS );
00104   pkg->def( "::cv", 0, &GLCanvas::getCurrent, SRC_POS );
00105 
00106   pkg->def( "current", "toglet_id", &Toglet::setCurrent, SRC_POS );
00107   pkg->def( "current", 0, &Toglet::getCurrent, SRC_POS );
00108   pkg->def( "defaultParent", "parent", &Toglet::defaultParent, SRC_POS );
00109   pkg->def( "see", "gxnode_id", &see, SRC_POS );
00110 
00111   pkg->def_setter("allowRefresh", &Toglet::allowRefresh, SRC_POS);
00112   pkg->def("animate", "objref(s) frames_per_second", &Toglet::animate, SRC_POS);
00113   pkg->def_get_set("camera", &Toglet::getCamera, &Toglet::setCamera, SRC_POS);
00114   pkg->def_getter("canvas", &Toglet::getCanvas, SRC_POS);
00115   pkg->def_action("clearscreen", &Toglet::fullClearscreen, SRC_POS);
00116   pkg->def("hold", "objref(s) hold_on", &Toglet::setHold, SRC_POS);
00117   pkg->def("setVisible", "objref(s) visibility", &Toglet::setVisibility, SRC_POS);
00118   pkg->def_get_set("size", &Toglet::size, &Toglet::setSize, SRC_POS);
00119   pkg->def_action("swapBuffers", &Toglet::swapBuffers, SRC_POS);
00120   pkg->def_action("undraw", &Toglet::undraw, SRC_POS);
00121 
00122   Toglet::make();
00123 
00124   pkg->eval("proc ::clearscreen {} { Toglet::clearscreen [Toglet::current] }\n"
00125             "proc ::see {id} { Toglet::see [Toglet::current] $id }\n"
00126             "proc ::undraw {} { Toglet::undraw [Toglet::current] }\n"
00127             );
00128 
00129   GVX_PKG_RETURN(pkg);
00130 }
00131 
00132 static const char __attribute__((used)) vcid_groovx_gfx_tclpkg_toglet_cc_utc20050628170310[] = "$Id: tclpkg-toglet.cc 10065 2007-04-12 05:54:56Z rjpeters $ $HeadURL: file:
00133 #endif // !GROOVX_GFX_TCLPKG_TOGLET_CC_UTC20050628170310_DEFINED

The software described here is Copyright (c) 1998-2005, Rob Peters.
This page was generated Wed Dec 3 06:49:41 2008 by Doxygen version 1.5.5.