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
00031
00033
00034 #ifndef GROOVX_GFX_TCLPKG_GX_CC_UTC20050628170310_DEFINED
00035 #define GROOVX_GFX_TCLPKG_GX_CC_UTC20050628170310_DEFINED
00036
00037 #include "tcl-gfx/tclpkg-gx.h"
00038
00039 #include "geom/bezier4.h"
00040
00041 #include "gfx/gxaligner.h"
00042 #include "gfx/gxcache.h"
00043 #include "gfx/gxcamera.h"
00044 #include "gfx/gxcolor.h"
00045 #include "gfx/gxcylinder.h"
00046 #include "gfx/gxdisk.h"
00047 #include "gfx/gxdrawstyle.h"
00048 #include "gfx/gxemptynode.h"
00049 #include "gfx/gxlighting.h"
00050 #include "gfx/gxline.h"
00051 #include "gfx/gxmaterial.h"
00052 #include "gfx/gxnode.h"
00053 #include "gfx/gxpixmap.h"
00054 #include "gfx/gxpointset.h"
00055 #include "gfx/gxscaler.h"
00056 #include "gfx/gxseparator.h"
00057 #include "gfx/gxshapekit.h"
00058 #include "gfx/gxsphere.h"
00059 #include "gfx/gxtext.h"
00060 #include "gfx/gxtransform.h"
00061 #include "gfx/pscanvas.h"
00062
00063 #include "nub/objfactory.h"
00064
00065 #include "tcl/itertcl.h"
00066 #include "tcl/objpkg.h"
00067 #include "tcl/list.h"
00068 #include "tcl/channelbuf.h"
00069 #include "tcl/pkg.h"
00070 #include "tcl/interp.h"
00071 #include "tcl/tracertcl.h"
00072
00073 #include "tcl-gfx/recttcl.h"
00074 #include "tcl-gfx/vectcl.h"
00075 #include "tcl-io/fieldpkg.h"
00076
00077 #include "rutz/error.h"
00078
00079 #include "rutz/trace.h"
00080
00081 namespace GxTcl
00082 {
00083 bool contains(nub::ref<GxNode> item, nub::ref<GxNode> other)
00084 {
00085 return item->contains(other.get());
00086 }
00087
00088 void savePS(nub::ref<GxNode> item, const char* filename)
00089 {
00090 Gfx::PSCanvas canvas(filename);
00091
00092 item->draw(canvas);
00093 }
00094
00095 void addChildren(nub::ref<GxSeparator> sep, tcl::list objs)
00096 {
00097 tcl::list::iterator<nub::ref<GxNode> >
00098 itr = objs.begin<nub::ref<GxNode> >(),
00099 end = objs.end<nub::ref<GxNode> >();
00100
00101 while (itr != end)
00102 {
00103 sep->addChild(*itr);
00104 ++itr;
00105 }
00106 }
00107
00108 void removeAllChildren(nub::ref<GxSeparator> sep)
00109 {
00110 while (sep->numChildren() > 0)
00111 sep->removeChildAt(0);
00112 }
00113
00114 geom::rect<double> boundingBox(nub::ref<GxNode> obj,
00115 nub::soft_ref<Gfx::Canvas> canvas)
00116 {
00117 return obj->getBoundingBox(*canvas);
00118 }
00119
00120 rutz::fstring gxsepFields()
00121 {
00122 static rutz::fstring result =
00123 "{addChildren 0 10 1 {NEW_GROUP STRING NO_GET}} "
00124 "{removeChild 0 10 1 {STRING NO_GET}} "
00125 "{children 0 20 1 {STRING NO_SET}} "
00126 "{debugMode 0 1 1 {BOOLEAN TRANSIENT}} ";
00127 return result;
00128 }
00129
00130
00131
00132
00133
00134 #if 0
00135 void saveBitmap(nub::ref<GxNode> obj, const char* filename)
00136 {
00137 obj->saveBitmapCache(Gfx::Canvas::current(), filename);
00138 }
00139 #endif
00140
00141 tcl::list bezier4(double p1, double p2, double p3, double p4,
00142 unsigned int N)
00143 {
00144 GVX_TRACE("<gxtcl.cc>::bezier4");
00145
00146 if (N < 4)
00147 {
00148 throw rutz::error("N must be at least 4", SRC_POS);
00149 }
00150
00151 tcl::list result;
00152
00153 geom::bezier4 bez(p1, p2, p3, p4);
00154
00155 for (unsigned int i = 0; i < N; ++i)
00156 {
00157 const double u = double(i) / double(N-1);
00158 result.append(bez.eval(u));
00159 }
00160
00161 return result;
00162 }
00163 }
00164
00165 extern "C"
00166 int Gx_Init(Tcl_Interp* interp)
00167 {
00168 GVX_TRACE("Gx_Init");
00169
00170 GVX_PKG_CREATE(pkg, interp, "Gx", "4.$Revision: 10065 $");
00171
00172 pkg->def( "bezier4", "p1 p2 p3 p4 N", &GxTcl::bezier4, SRC_POS );
00173
00174 GVX_PKG_RETURN(pkg);
00175 }
00176
00177 extern "C"
00178 int Gxnode_Init(Tcl_Interp* interp)
00179 {
00180 GVX_TRACE("Gxnode_Init");
00181
00182 GVX_PKG_CREATE(pkg, interp, "GxNode", "4.$Revision: 10065 $");
00183 pkg->inherit_pkg("io");
00184 tcl::def_basic_type_cmds<GxNode>(pkg, SRC_POS);
00185
00186 pkg->def( "contains", "objref other_id", &GxTcl::contains, SRC_POS );
00187 pkg->def_vec("deepChildren", "objref(s)", &GxNode::deepChildren, 1, SRC_POS);
00188 pkg->def_vec("boundingBox", "objref(s) canvas", &GxTcl::boundingBox, 1, SRC_POS);
00189 pkg->def( "savePS", "objref filename", &GxTcl::savePS, SRC_POS );
00190
00191 GVX_PKG_RETURN(pkg);
00192 }
00193
00194 extern "C"
00195 int Gxseparator_Init(Tcl_Interp* interp)
00196 {
00197 GVX_TRACE("Gxseparator_Init");
00198
00199 GVX_PKG_CREATE(pkg, interp, "GxSeparator", "4.$Revision: 10065 $");
00200 pkg->inherit_pkg("GxNode");
00201 tcl::def_basic_type_cmds<GxSeparator>(pkg, SRC_POS);
00202
00203 pkg->def( "fields", "", &GxTcl::gxsepFields, SRC_POS );
00204 pkg->def( "allFields", "", &GxTcl::gxsepFields, SRC_POS );
00205
00206 pkg->def( "addChild", "objref child_objref", &GxSeparator::addChild, SRC_POS );
00207 pkg->def( "addChildren", "objref children_objref(s)", &GxTcl::addChildren, SRC_POS );
00208 pkg->def_getter("children", &GxSeparator::children, SRC_POS);
00209 pkg->def_get_set("debugMode",
00210 &GxSeparator::getDebugMode,
00211 &GxSeparator::setDebugMode,
00212 SRC_POS);
00213 pkg->def_getter("numChildren", &GxSeparator::numChildren, SRC_POS);
00214 pkg->def("removeAllChildren", "sep_id(s)", &GxTcl::removeAllChildren, SRC_POS);
00215 pkg->def("removeChildAt", "sep_id(s) child_indices", &GxSeparator::removeChildAt, SRC_POS);
00216 pkg->def("removeChild","sep_id(s) child_id(s)", &GxSeparator::removeChild, SRC_POS);
00217 nub::obj_factory::instance().register_creator(&GxSeparator::make);
00218
00219 GVX_PKG_RETURN(pkg);
00220 }
00221
00222 extern "C"
00223 int Gxcolor_Init(Tcl_Interp* interp)
00224 {
00225 GVX_TRACE("Gxcolor_Init");
00226
00227 GVX_PKG_CREATE(pkg, interp, "GxColor", "4.$Revision: 10065 $");
00228 pkg->inherit_pkg("GxNode");
00229 tcl::defFieldContainer<GxColor>(pkg, SRC_POS);
00230 tcl::def_creator<GxColor>(pkg);
00231
00232 GVX_PKG_RETURN(pkg);
00233 }
00234
00235 extern "C"
00236 int Gxdrawstyle_Init(Tcl_Interp* interp)
00237 {
00238 GVX_TRACE("Gxdrawstyle_Init");
00239
00240 GVX_PKG_CREATE(pkg, interp, "GxDrawStyle", "4.$Revision: 10065 $");
00241 pkg->inherit_pkg("GxNode");
00242 tcl::defFieldContainer<GxDrawStyle>(pkg, SRC_POS);
00243 tcl::def_creator<GxDrawStyle>(pkg);
00244
00245 GVX_PKG_RETURN(pkg);
00246 }
00247
00248 extern "C"
00249 int Gxline_Init(Tcl_Interp* interp)
00250 {
00251 GVX_TRACE("Gxline_Init");
00252
00253 GVX_PKG_CREATE(pkg, interp, "GxLine", "4.$Revision: 10065 $");
00254 pkg->inherit_pkg("GxNode");
00255 tcl::defFieldContainer<GxLine>(pkg, SRC_POS);
00256 tcl::def_creator<GxLine>(pkg);
00257
00258 GVX_PKG_RETURN(pkg);
00259 }
00260
00261 extern "C"
00262 int Gxcylinder_Init(Tcl_Interp* interp)
00263 {
00264 GVX_TRACE("Gxcylinder_Init");
00265
00266 GVX_PKG_CREATE(pkg, interp, "GxCylinder", "4.$Revision: 10065 $");
00267 pkg->inherit_pkg("GxNode");
00268 tcl::defFieldContainer<GxCylinder>(pkg, SRC_POS);
00269 tcl::def_creator<GxCylinder>(pkg);
00270
00271 GVX_PKG_RETURN(pkg);
00272 }
00273
00274 extern "C"
00275 int Gxsphere_Init(Tcl_Interp* interp)
00276 {
00277 GVX_TRACE("Gxsphere_Init");
00278
00279 GVX_PKG_CREATE(pkg, interp, "GxSphere", "4.$Revision: 10065 $");
00280 pkg->inherit_pkg("GxNode");
00281 tcl::defFieldContainer<GxSphere>(pkg, SRC_POS);
00282 tcl::def_creator<GxSphere>(pkg);
00283
00284 GVX_PKG_RETURN(pkg);
00285 }
00286
00287 extern "C"
00288 int Gxlighting_Init(Tcl_Interp* interp)
00289 {
00290 GVX_TRACE("Gxlighting_Init");
00291
00292 GVX_PKG_CREATE(pkg, interp, "GxLighting", "4.$Revision: 10065 $");
00293 pkg->inherit_pkg("GxNode");
00294 tcl::defFieldContainer<GxLighting>(pkg, SRC_POS);
00295 tcl::def_creator<GxLighting>(pkg);
00296
00297 GVX_PKG_RETURN(pkg);
00298 }
00299
00300 extern "C"
00301 int Gxmaterial_Init(Tcl_Interp* interp)
00302 {
00303 GVX_TRACE("Gxmaterial_Init");
00304
00305 GVX_PKG_CREATE(pkg, interp, "GxMaterial", "4.$Revision: 10065 $");
00306 pkg->inherit_pkg("GxNode");
00307 tcl::defFieldContainer<GxMaterial>(pkg, SRC_POS);
00308 tcl::def_creator<GxMaterial>(pkg);
00309
00310 GVX_PKG_RETURN(pkg);
00311 }
00312
00313 extern "C"
00314 int Gxpointset_Init(Tcl_Interp* interp)
00315 {
00316 GVX_TRACE("Gxpointset_Init");
00317
00318 GVX_PKG_CREATE(pkg, interp, "GxPointSet", "4.$Revision: 10065 $");
00319 pkg->inherit_pkg("GxNode");
00320 tcl::defFieldContainer<GxPointSet>(pkg, SRC_POS);
00321 tcl::def_creator<GxPointSet>(pkg);
00322
00323 GVX_PKG_RETURN(pkg);
00324 }
00325
00326 extern "C"
00327 int Gxscaler_Init(Tcl_Interp* interp)
00328 {
00329 GVX_TRACE("Gxscaler_Init");
00330
00331 GVX_PKG_CREATE(pkg, interp, "GxScaler", "4.$Revision: 10065 $");
00332 pkg->inherit_pkg("GxNode");
00333 tcl::def_basic_type_cmds<GxScaler>(pkg, SRC_POS);
00334 tcl::def_creator<GxScaler>(pkg);
00335 pkg->def_get_set("child", &GxScaler::child, &GxScaler::setChild, SRC_POS);
00336 pkg->def_get_set("mode", &GxScaler::getMode, &GxScaler::setMode, SRC_POS);
00337 pkg->def_get_set("width", &GxScaler::scaledWidth, &GxScaler::setWidth, SRC_POS);
00338 pkg->def_get_set("height", &GxScaler::scaledHeight, &GxScaler::setHeight, SRC_POS);
00339 pkg->def_get_set("maxDim", &GxScaler::scaledMaxDim, &GxScaler::setMaxDim, SRC_POS);
00340 pkg->def_get_set("aspect", &GxScaler::aspectRatio, &GxScaler::setAspectRatio, SRC_POS);
00341 pkg->def_get_set("widthFactor", &GxScaler::widthFactor, &GxScaler::setWidthFactor, SRC_POS);
00342 pkg->def_get_set("heightFactor", &GxScaler::heightFactor, &GxScaler::setHeightFactor, SRC_POS);
00343
00344 GVX_PKG_RETURN(pkg);
00345 }
00346
00347 extern "C"
00348 int Gxemptynode_Init(Tcl_Interp* interp)
00349 {
00350 GVX_TRACE("Gxemptynode_Init");
00351
00352 GVX_PKG_CREATE(pkg, interp, "GxEmptyNode", "4.$Revision: 10065 $");
00353 pkg->inherit_pkg("GxNode");
00354 tcl::def_basic_type_cmds<GxEmptyNode>(pkg, SRC_POS);
00355 tcl::def_creator<GxEmptyNode>(pkg);
00356
00357 GVX_PKG_RETURN(pkg);
00358 }
00359
00360 extern "C"
00361 int Gxtransform_Init(Tcl_Interp* interp)
00362 {
00363 GVX_TRACE("Gxtransform_Init");
00364
00365 GVX_PKG_CREATE(pkg, interp, "GxTransform", "4.$Revision: 10065 $");
00366 pkg->inherit_pkg("GxNode");
00367 tcl::def_creator<GxTransform>(pkg);
00368 tcl::defFieldContainer<GxTransform>(pkg, SRC_POS);
00369
00370 GVX_PKG_RETURN(pkg);
00371 }
00372
00373 extern "C"
00374 int Gxshapekit_Init(Tcl_Interp* interp)
00375 {
00376 GVX_TRACE("Gxshapekit_Init");
00377
00378 GVX_PKG_CREATE(pkg, interp, "GxShapeKit", "4.$Revision: 10065 $");
00379 pkg->inherit_pkg("GxNode");
00380
00381 tcl::def_tracing(pkg, GxShapeKit::tracer);
00382
00383 tcl::defFieldContainer<GxShapeKit>(pkg, SRC_POS);
00384
00385 #if 0
00386 pkg->def_vec( "saveBitmap", "objref(s) filename(s)", &GxTcl::saveBitmap, 1, SRC_POS );
00387 #endif
00388
00389 pkg->def_get_set("category", &GxShapeKit::category, &GxShapeKit::setCategory, SRC_POS);
00390
00391 pkg->link_var_copy("GxShapeKit::DIRECT", GxCache::DIRECT);
00392 pkg->link_var_copy("GxShapeKit::GLCOMPILE", GxCache::GLCOMPILE);
00393
00394 pkg->link_var_copy("GxShapeKit::NATIVE_SCALING", GxScaler::NATIVE_SCALING);
00395 pkg->link_var_copy("GxShapeKit::MAINTAIN_ASPECT_SCALING", GxScaler::MAINTAIN_ASPECT_SCALING);
00396 pkg->link_var_copy("GxShapeKit::FREE_SCALING", GxScaler::FREE_SCALING);
00397
00398 pkg->link_var_copy("GxShapeKit::NATIVE_ALIGNMENT", GxAligner::NATIVE_ALIGNMENT);
00399 pkg->link_var_copy("GxShapeKit::CENTER_ON_CENTER", GxAligner::CENTER_ON_CENTER);
00400 pkg->link_var_copy("GxShapeKit::NW_ON_CENTER", GxAligner::NW_ON_CENTER);
00401 pkg->link_var_copy("GxShapeKit::NE_ON_CENTER", GxAligner::NE_ON_CENTER);
00402 pkg->link_var_copy("GxShapeKit::SW_ON_CENTER", GxAligner::SW_ON_CENTER);
00403 pkg->link_var_copy("GxShapeKit::SE_ON_CENTER", GxAligner::SE_ON_CENTER);
00404 pkg->link_var_copy("GxShapeKit::ARBITRARY_ON_CENTER", GxAligner::ARBITRARY_ON_CENTER);
00405
00406 GVX_PKG_RETURN(pkg);
00407 }
00408
00409 namespace
00410 {
00411 void scramble1(nub::ref<GxPixmap> pixmap,
00412 int numsubcols, int numsubrows)
00413 {
00414 pixmap->scramble(numsubcols, numsubrows, 0);
00415 }
00416
00417 void scramble2(nub::ref<GxPixmap> pixmap,
00418 int numsubcols, int numsubrows, int seed)
00419 {
00420 pixmap->scramble(numsubcols, numsubrows, seed);
00421 }
00422
00423 void loadImageStream(tcl::call_context& ctx)
00424 {
00425 using rutz::shared_ptr;
00426 nub::ref<GxPixmap> pixmap = ctx.get_arg<nub::ref<GxPixmap> >(1);
00427 const char* channame = ctx.get_arg<const char*>(2);
00428 Tcl_Interp* interp = ctx.interp().intp();
00429 shared_ptr<std::istream> ist(tcl::ichanopen(interp, channame));
00430 pixmap->loadImageStream(*ist);
00431 }
00432 }
00433
00434 extern "C"
00435 int Gxpixmap_Init(Tcl_Interp* interp)
00436 {
00437 GVX_TRACE("Gxpixmap_Init");
00438
00439 GVX_PKG_CREATE(pkg, interp, "GxPixmap", "4.$Revision: 10065 $");
00440 pkg->inherit_pkg("GxShapeKit");
00441 tcl::def_creator<GxPixmap>(pkg, "Bitmap");
00442 tcl::def_basic_type_cmds<GxPixmap>(pkg, SRC_POS);
00443
00444
00445 pkg->def_get_set("asBitmap", &GxPixmap::getAsBitmap, &GxPixmap::setAsBitmap, SRC_POS);
00446 pkg->def_getter("checkSum", &GxPixmap::checkSum, SRC_POS);
00447 pkg->def_getter("filename", &GxPixmap::filename, SRC_POS );
00448 pkg->def_action("flipContrast", &GxPixmap::flipContrast, SRC_POS);
00449 pkg->def_action("flipVertical", &GxPixmap::flipVertical, SRC_POS);
00450 pkg->def_vec("grabScreenRect", "objref(s) canvas {left top right bottom}",
00451 &GxPixmap::grabScreenRect, 1,
00452 SRC_POS );
00453 pkg->def_vec("grabScreen", "objref(s) canvas", &GxPixmap::grabScreen, 1, SRC_POS );
00454 pkg->def_vec("grabWorldRect", "objref(s) canvas {left top right bottom}",
00455 &GxPixmap::grabWorldRect, 1,
00456 SRC_POS );
00457 pkg->def_raw("loadImageStream", tcl::arg_spec(3),
00458 "objref channame", &loadImageStream, SRC_POS);
00459 pkg->def_vec("loadImage", "objref(s) filename(s)", &GxPixmap::loadImage, 1, SRC_POS );
00460 pkg->def_get_set("purgeable", &GxPixmap::isPurgeable, &GxPixmap::setPurgeable, SRC_POS);
00461 pkg->def_vec("queueImage", "objref(s) filename(s)", &GxPixmap::queueImage, 1, SRC_POS );
00462 pkg->def_action("reload", &GxPixmap::reload, SRC_POS);
00463 pkg->def_vec("saveImage", "objref(s) filename(s)", &GxPixmap::saveImage, 1, SRC_POS );
00464 pkg->def_vec("scramble", "numcols numrows", &scramble1, 1, SRC_POS);
00465 pkg->def_vec("scramble", "numcols numrows ?seed?", &scramble2, 1, SRC_POS);
00466 pkg->def_vec("scramble", "numcols numrows ?seed moveParts flipLR flipTB?",
00467 &GxPixmap::scramble, 1,
00468 SRC_POS);
00469 pkg->def_getter("size", &GxPixmap::size, SRC_POS);
00470 pkg->def_get_set("usingZoom", &GxPixmap::getUsingZoom, &GxPixmap::setUsingZoom, SRC_POS);
00471 pkg->def_get_set("zoom", &GxPixmap::getZoom, &GxPixmap::setZoom, SRC_POS);
00472 pkg->def_setter("zoomTo", &GxPixmap::zoomTo, SRC_POS);
00473
00474 GVX_PKG_RETURN(pkg);
00475 }
00476
00477 extern "C"
00478 int Gxtext_Init(Tcl_Interp* interp)
00479 {
00480 GVX_TRACE("Gxtext_Init");
00481
00482 GVX_PKG_CREATE(pkg, interp, "GxText", "4.$Revision: 10065 $");
00483 pkg->inherit_pkg("GxShapeKit");
00484 tcl::def_creator<GxText>(pkg, "Gtext");
00485 tcl::defFieldContainer<GxText>(pkg, SRC_POS);
00486
00487 GVX_PKG_RETURN(pkg);
00488 }
00489
00490
00491
00492
00493
00494
00495 extern "C"
00496 int Gxfixedscalecamera_Init(Tcl_Interp* interp)
00497 {
00498 GVX_TRACE("Gxfixedscalecamera_Init");
00499
00500 GVX_PKG_CREATE(pkg, interp, "GxFixedScaleCamera", "4.$Revision: 10065 $");
00501 pkg->inherit_pkg("GxNode");
00502 tcl::def_creator<GxFixedScaleCamera>(pkg);
00503 tcl::defFieldContainer<GxFixedScaleCamera>(pkg, SRC_POS);
00504
00505 GVX_PKG_RETURN(pkg);
00506 }
00507
00508 extern "C"
00509 int Gxpsyphycamera_Init(Tcl_Interp* interp)
00510 {
00511 GVX_TRACE("Gxpsyphycamera_Init");
00512
00513 GVX_PKG_CREATE(pkg, interp, "GxPsyphyCamera", "4.$Revision: 10065 $");
00514 pkg->inherit_pkg("GxNode");
00515 tcl::def_creator<GxPsyphyCamera>(pkg);
00516 tcl::defFieldContainer<GxPsyphyCamera>(pkg, SRC_POS);
00517
00518 GVX_PKG_RETURN(pkg);
00519 }
00520
00521 extern "C"
00522 int Gxperspectivecamera_Init(Tcl_Interp* interp)
00523 {
00524 GVX_TRACE("Gxperspectivecamera_Init");
00525
00526 GVX_PKG_CREATE(pkg, interp, "GxPerspectiveCamera", "4.$Revision: 10065 $");
00527 pkg->inherit_pkg("GxNode");
00528 tcl::def_creator<GxPerspectiveCamera>(pkg);
00529 tcl::defFieldContainer<GxPerspectiveCamera>(pkg, SRC_POS);
00530
00531 GVX_PKG_RETURN(pkg);
00532 }
00533
00534 extern "C"
00535 int Gxdisk_Init(Tcl_Interp* interp)
00536 {
00537 GVX_TRACE("Gxdisk_Init");
00538
00539 GVX_PKG_CREATE(pkg, interp, "GxDisk", "4.$Revision: 10065 $");
00540 pkg->inherit_pkg("GxNode");
00541 tcl::def_creator<GxDisk>(pkg);
00542 tcl::defFieldContainer<GxDisk>(pkg, SRC_POS);
00543
00544 GVX_PKG_RETURN(pkg);
00545 }
00546
00547 static const char __attribute__((used)) vcid_groovx_gfx_tclpkg_gx_cc_utc20050628170310[] = "$Id: tclpkg-gx.cc 10065 2007-04-12 05:54:56Z rjpeters $ $HeadURL: file:
00548 #endif // !GROOVX_GFX_TCLPKG_GX_CC_UTC20050628170310_DEFINED