00001
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00032
00033 #ifndef GROOVX_GFX_TCLPKG_CANVAS_CC_UTC20050628170310_DEFINED
00034 #define GROOVX_GFX_TCLPKG_CANVAS_CC_UTC20050628170310_DEFINED
00035
00036 #include "tcl-gfx/tclpkg-canvas.h"
00037
00038 #include "gfx/canvas.h"
00039 #include "gfx/glcanvas.h"
00040
00041 #include "media/bmapdata.h"
00042
00043 #include "tcl/objpkg.h"
00044 #include "tcl/pkg.h"
00045
00046 #include "tcl-gfx/recttcl.h"
00047 #include "tcl-gfx/vectcl.h"
00048
00049 #include "rutz/trace.h"
00050
00051 namespace
00052 {
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067 long int pixelCheckSum(nub::soft_ref<GLCanvas> canvas,
00068 int x, int y, int w, int h)
00069 {
00070 media::bmap_data data;
00071
00072 const geom::rect<int> bounds = geom::rect<int>().set_lbwh(x, y, w, h);
00073
00074 canvas->grabPixels(bounds, data);
00075
00076 return data.bytes_sum();
00077 }
00078
00079 long int pixelCheckSumAll(nub::soft_ref<GLCanvas> canvas)
00080 {
00081 const geom::rect<int> viewport = canvas->getScreenViewport();
00082 return pixelCheckSum(canvas,
00083 viewport.left(),
00084 viewport.bottom(),
00085 viewport.width(),
00086 viewport.height());
00087 }
00088
00089 geom::vec3d topLeft(nub::soft_ref<GLCanvas> canvas)
00090 {
00091 const geom::recti vp = canvas->getScreenViewport();
00092 const geom::vec2i tl = vp.top_left();
00093 return canvas->worldFromScreen3(geom::vec3d(tl.x(), tl.y(), 0.5));
00094 }
00095 }
00096
00097 extern "C"
00098 int Canvas_Init(Tcl_Interp* interp)
00099 {
00100 GVX_TRACE("Canvas_Init");
00101
00102 GVX_PKG_CREATE(pkg, interp, "Canvas", "4.$Revision: 10065 $");
00103 pkg->inherit_pkg("Obj");
00104 tcl::def_basic_type_cmds<Gfx::Canvas>(pkg, SRC_POS);
00105
00106 using rutz::bind_last;
00107 using rutz::mem_func;
00108
00109 pkg->def_getter("viewport", &Gfx::Canvas::getScreenViewport, SRC_POS);
00110 pkg->def("topLeft", "canvas", &topLeft, SRC_POS);
00111
00112 pkg->def("throwIfError", "",
00113 bind_last(bind_last(mem_func(&Gfx::Canvas::throwIfError), SRC_POS), ""),
00114 SRC_POS);
00115
00116 GVX_PKG_RETURN(pkg);
00117 }
00118
00119 extern "C"
00120 int Glcanvas_Init(Tcl_Interp* interp)
00121 {
00122 GVX_TRACE("Glcanvas_Init");
00123
00124 GVX_PKG_CREATE(pkg, interp, "GLCanvas", "4.$Revision: 10065 $");
00125 pkg->inherit_pkg("Canvas");
00126 tcl::def_basic_type_cmds<GLCanvas>(pkg, SRC_POS);
00127
00128 pkg->def( "pixelCheckSum", "glcanvas x y w h", &pixelCheckSum, SRC_POS );
00129 pkg->def( "pixelCheckSum", "glcanvas", &pixelCheckSumAll, SRC_POS );
00130
00131 GVX_PKG_RETURN(pkg);
00132 }
00133
00134 static const char __attribute__((used)) vcid_groovx_gfx_tclpkg_canvas_cc_utc20050628170310[] = "$Id: tclpkg-canvas.cc 10065 2007-04-12 05:54:56Z rjpeters $ $HeadURL: file:
00135 #endif // !GROOVX_GFX_TCLPKG_CANVAS_CC_UTC20050628170310_DEFINED