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_VISX_MASKHATCH_CC_UTC20050626084015_DEFINED
00035 #define GROOVX_VISX_MASKHATCH_CC_UTC20050626084015_DEFINED
00036
00037 #include "visx/maskhatch.h"
00038
00039 #include "geom/rect.h"
00040
00041 #include "gfx/bbox.h"
00042 #include "gfx/canvas.h"
00043 #include "gfx/gxaligner.h"
00044
00045 #include "io/ioproxy.h"
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 namespace
00054 {
00055 const io::version_id MASKHATCH_SVID = 3;
00056 }
00057
00058 const FieldMap& MaskHatch::classFields()
00059 {
00060 static const Field MASK_FINFOS[] =
00061 {
00062 Field("numLines", &MaskHatch::itsNumLines, 5, 0, 25, 1, Field::NEW_GROUP),
00063 Field("lineWidth", &MaskHatch::itsLineWidth, 1, 0, 25, 1, Field::CHECKED)
00064 };
00065
00066 static FieldMap MASK_FIELDS(MASK_FINFOS, &GxShapeKit::classFields());
00067
00068 return MASK_FIELDS;
00069 }
00070
00071 MaskHatch* MaskHatch::make()
00072 {
00073 GVX_TRACE("MaskHatch::make");
00074 return new MaskHatch;
00075 }
00076
00077 MaskHatch::MaskHatch () :
00078 GxShapeKit(),
00079 itsNumLines(10),
00080 itsLineWidth(1)
00081 {
00082 GVX_TRACE("MaskHatch::MaskHatch");
00083
00084 sigNodeChanged.connect(this, &MaskHatch::update);
00085
00086 setFieldMap(MaskHatch::classFields());
00087
00088 setAlignmentMode(GxAligner::CENTER_ON_CENTER);
00089 dbg_eval(3, getAlignmentMode());
00090 }
00091
00092 MaskHatch::~MaskHatch() throw()
00093 {
00094 GVX_TRACE("MaskHatch::~MaskHatch");
00095 }
00096
00097 io::version_id MaskHatch::class_version_id() const
00098 {
00099 GVX_TRACE("MaskHatch::class_version_id");
00100 return MASKHATCH_SVID;
00101 }
00102
00103 void MaskHatch::read_from(io::reader& reader)
00104 {
00105 GVX_TRACE("MaskHatch::read_from");
00106
00107 reader.ensure_version_id("MaskHatch", 3,
00108 "Try cvs tag xml_conversion_20040526",
00109 SRC_POS);
00110
00111 readFieldsFrom(reader, classFields());
00112
00113 reader.read_base_class("GxShapeKit", io::make_proxy<GxShapeKit>(this));
00114 }
00115
00116 void MaskHatch::write_to(io::writer& writer) const
00117 {
00118 GVX_TRACE("MaskHatch::write_to");
00119
00120 writer.ensure_output_version_id("MaskHatch",
00121 MASKHATCH_SVID, 3,
00122 "Try groovx0.8a4", SRC_POS);
00123
00124 writeFieldsTo(writer, classFields(), MASKHATCH_SVID);
00125
00126 writer.write_base_class("GxShapeKit", io::make_const_proxy<GxShapeKit>(this));
00127 }
00128
00129 void MaskHatch::update()
00130 {
00131 setPercentBorder(itsLineWidth/2 + 2);
00132 }
00133
00134 void MaskHatch::grGetBoundingBox(Gfx::Bbox& bbox) const
00135 {
00136 GVX_TRACE("MaskHatch::grGetBoundingBox");
00137
00138 bbox.drawRect(geom::rect<double>::lbwh(0.0, 0.0, 1.0, 1.0));
00139 }
00140
00141 void MaskHatch::grRender(Gfx::Canvas& canvas) const
00142 {
00143 GVX_TRACE("MaskHatch::grRender");
00144
00145 if (itsNumLines == 0) return;
00146
00147 Gfx::AttribSaver attribSaver(canvas);
00148
00149 canvas.setLineWidth(itsLineWidth);
00150
00151 Gfx::LinesBlock b(canvas);
00152
00153 using geom::vec2d;
00154
00155 for (int i = 0; i < itsNumLines; ++i)
00156 {
00157 double position = double(i)/itsNumLines;
00158
00159
00160 canvas.vertex2(vec2d(0.0, position));
00161 canvas.vertex2(vec2d(1.0, position));
00162
00163
00164 canvas.vertex2(vec2d(position, 0.0));
00165 canvas.vertex2(vec2d(position, 1.0));
00166
00167
00168 canvas.vertex2(vec2d(0.0, position));
00169 canvas.vertex2(vec2d(1.0-position, 1.0));
00170
00171 canvas.vertex2(vec2d(position, 0.0));
00172 canvas.vertex2(vec2d(1.0, 1.0-position));
00173
00174
00175 canvas.vertex2(vec2d(0.0, 1.0-position));
00176 canvas.vertex2(vec2d(1.0-position, 0.0));
00177
00178 canvas.vertex2(vec2d(position, 1.0));
00179 canvas.vertex2(vec2d(1.0, position));
00180 }
00181
00182
00183 canvas.vertex2(vec2d(0.0, 1.0));
00184 canvas.vertex2(vec2d(1.0, 1.0));
00185
00186 canvas.vertex2(vec2d(1.0, 0.0));
00187 canvas.vertex2(vec2d(1.0, 1.0));
00188 }
00189
00190 static const char __attribute__((used)) vcid_groovx_visx_maskhatch_cc_utc20050626084015[] = "$Id: maskhatch.cc 10065 2007-04-12 05:54:56Z rjpeters $ $HeadURL: file:
00191 #endif // !GROOVX_VISX_MASKHATCH_CC_UTC20050626084015_DEFINED