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_GXBOUNDS_CC_UTC20050626084023_DEFINED
00035 #define GROOVX_GFX_GXBOUNDS_CC_UTC20050626084023_DEFINED
00036
00037 #include "gxbounds.h"
00038
00039 #include "geom/box.h"
00040 #include "geom/rect.h"
00041
00042 #include "gfx/bbox.h"
00043 #include "gfx/canvas.h"
00044 #include "gfx/rgbacolor.h"
00045
00046 #include "io/reader.h"
00047 #include "io/writer.h"
00048
00049 #include "rutz/trace.h"
00050 #include "rutz/debug.h"
00051 GVX_DBG_REGISTER
00052
00053 GxBounds::GxBounds(nub::soft_ref<GxNode> child) :
00054 GxBin(child),
00055 isItVisible(false),
00056 isItAnimated(true),
00057 itsPercentBorder(4),
00058 itsStipple(0x0F0F),
00059 itsMask(0x3333)
00060 {}
00061
00062 GxBounds::~GxBounds() throw() {}
00063
00064 void GxBounds::read_from(io::reader& reader)
00065 {
00066 GVX_TRACE("GxBounds::read_from");
00067 reader.read_value("isVisible", isItVisible);
00068 reader.read_value("isAnimated", isItAnimated);
00069 reader.read_value("percentBorder", itsPercentBorder);
00070 }
00071
00072 void GxBounds::write_to(io::writer& writer) const
00073 {
00074 GVX_TRACE("GxBounds::write_to");
00075 writer.write_value("isVisible", isItVisible);
00076 writer.write_value("isAnimated", isItAnimated);
00077 writer.write_value("percentBorder", itsPercentBorder);
00078 }
00079
00080 void GxBounds::draw(Gfx::Canvas& canvas) const
00081 {
00082 GVX_TRACE("GxBounds::draw");
00083
00084 child()->draw(canvas);
00085
00086 if (isItVisible)
00087 {
00088 Gfx::Bbox bbox(canvas);
00089 const double s = 1.0 + itsPercentBorder/100.0;
00090 bbox.scale(geom::vec3<double>(s,s,s));
00091 child()->getBoundingCube(bbox);
00092
00093 geom::rect<double> bounds = bbox.rect();
00094
00095 if (isItAnimated)
00096 {
00097 itsStipple ^= itsMask;
00098 itsMask = ~itsMask;
00099 }
00100
00101 Gfx::AttribSaver saver(canvas);
00102
00103 canvas.setColor(Gfx::RgbaColor(0.0, 0.0, 1.0, 1.0));
00104
00105 canvas.setLineWidth(1.0);
00106 canvas.setLineStipple(itsStipple);
00107 canvas.setPolygonFill(false);
00108
00109 canvas.drawRect(bounds);
00110
00111 canvas.setPointSize(4.0);
00112
00113 {
00114 Gfx::PointsBlock block(canvas);
00115
00116 canvas.vertex2(bounds.bottom_left());
00117 canvas.vertex2(bounds.bottom_right());
00118 canvas.vertex2(bounds.top_right());
00119 canvas.vertex2(bounds.top_left());
00120 canvas.vertex2(bounds.center());
00121 }
00122 }
00123 }
00124
00125 void GxBounds::getBoundingCube(Gfx::Bbox& bbox) const
00126 {
00127 GVX_TRACE("GxBounds::getBoundingCube");
00128
00129 bbox.push();
00130
00131 dbg_eval(3, itsPercentBorder);
00132
00133 const double s = 1.0 + itsPercentBorder/100.0;
00134
00135 bbox.scale(geom::vec3<double>(s,s,s));
00136
00137 child()->getBoundingCube(bbox);
00138
00139 bbox.pop();
00140
00141 dbg_dump(2, bbox.cube());
00142 }
00143
00144 static const char __attribute__((used)) vcid_groovx_gfx_gxbounds_cc_utc20050626084023[] = "$Id: gxbounds.cc 10065 2007-04-12 05:54:56Z rjpeters $ $HeadURL: file:
00145 #endif // !GROOVX_GFX_GXBOUNDS_CC_UTC20050626084023_DEFINED