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_GXTEXT_CC_UTC20050626084025_DEFINED
00035 #define GROOVX_GFX_GXTEXT_CC_UTC20050626084025_DEFINED
00036
00037 #include "gxtext.h"
00038
00039 #include "gfx/canvas.h"
00040 #include "gfx/gxaligner.h"
00041 #include "gfx/gxcache.h"
00042 #include "gfx/gxfactory.h"
00043 #include "gfx/gxfont.h"
00044 #include "gfx/gxscaler.h"
00045
00046 #include "io/ioproxy.h"
00047 #include "io/reader.h"
00048 #include "io/writer.h"
00049
00050 #include "rutz/trace.h"
00051 #include "rutz/debug.h"
00052 GVX_DBG_REGISTER
00053
00054 using rutz::fstring;
00055
00056 namespace
00057 {
00058 const io::version_id GTEXT_SVID = 3;
00059 }
00060
00062
00063
00064
00066
00067 GxText* GxText::make()
00068 {
00069 GVX_TRACE("GxText::make");
00070 return new GxText;
00071 }
00072
00073 #include "gfx/gxrasterfont.h"
00074
00075 GxText::GxText(const char* text) :
00076 GxShapeKit(),
00077 itsFont(GxFactory::makeFont("helvetica:34")),
00078
00079
00080
00081 itsText(text ? text : ""),
00082 itsStrokeWidth(2)
00083 {
00084 GVX_TRACE("GxText::GxText(const char*)");
00085
00086 setAlignmentMode(GxAligner::CENTER_ON_CENTER);
00087 setScalingMode(GxScaler::MAINTAIN_ASPECT_SCALING);
00088 setRenderMode(GxCache::GLCOMPILE);
00089 setHeight(1.0);
00090 }
00091
00092 GxText::~GxText() throw()
00093 {
00094 GVX_TRACE("GxText::~GxText");
00095 }
00096
00097 io::version_id GxText::class_version_id() const
00098 {
00099 GVX_TRACE("GxText::class_version_id");
00100 return GTEXT_SVID;
00101 }
00102
00103 void GxText::read_from(io::reader& reader)
00104 {
00105 GVX_TRACE("GxText::read_from");
00106
00107 reader.ensure_version_id("GxText", 3,
00108 "Try cvs tag xml_conversion_20040526",
00109 SRC_POS);
00110
00111 reader.read_value("text", itsText);
00112 reader.read_value("strokeWidth", itsStrokeWidth);
00113
00114 reader.read_base_class("GxShapeKit", io::make_proxy<GxShapeKit>(this));
00115 }
00116
00117 void GxText::write_to(io::writer& writer) const
00118 {
00119 GVX_TRACE("GxText::write_to");
00120
00121 writer.ensure_output_version_id("GxText", GTEXT_SVID, 3,
00122 "Try groovx0.8a4", SRC_POS);
00123
00124 writer.write_value("text", itsText);
00125 writer.write_value("strokeWidth", itsStrokeWidth);
00126
00127 writer.write_base_class("GxShapeKit", io::make_const_proxy<GxShapeKit>(this));
00128 }
00129
00130 const FieldMap& GxText::classFields()
00131 {
00132 static const Field FIELD_ARRAY[] =
00133 {
00134 Field("text", &GxText::itsText,
00135 fstring("0"), fstring("0"), fstring("100"), fstring("1"),
00136 Field::NEW_GROUP | Field::STRING),
00137 Field("strokeWidth",
00138 &GxText::getStrokeWidth, &GxText::setStrokeWidth,
00139 1, 1, 20, 1),
00140 Field("font", &GxText::getFont, &GxText::setFont,
00141 fstring(), fstring(), fstring(), fstring(),
00142 Field::STRING | Field::TRANSIENT)
00143 };
00144
00145 static FieldMap GTEXT_FIELDS(FIELD_ARRAY, &GxShapeKit::classFields());
00146
00147 return GTEXT_FIELDS;
00148 }
00149
00150 void GxText::setText(const fstring& text)
00151 {
00152 GVX_TRACE("GxText::setText");
00153 itsText = text;
00154 this->sigNodeChanged.emit();
00155 }
00156
00157 const fstring& GxText::getText() const
00158 {
00159 GVX_TRACE("GxText::getText");
00160 return itsText;
00161 }
00162
00163 void GxText::setStrokeWidth(int width)
00164 {
00165 GVX_TRACE("GxText::setStrokeWidth");
00166 if (width > 0)
00167 {
00168 itsStrokeWidth = width;
00169 setPercentBorder(itsStrokeWidth+4);
00170 this->sigNodeChanged.emit();
00171 }
00172 }
00173
00174 int GxText::getStrokeWidth() const
00175 {
00176 GVX_TRACE("GxText::getStrokeWidth");
00177 return itsStrokeWidth;
00178 }
00179
00180 void GxText::grGetBoundingBox(Gfx::Bbox& bbox) const
00181 {
00182 GVX_TRACE("GxText::grGetBoundingBox");
00183
00184 itsFont->bboxOf(itsText.c_str(), bbox);
00185 }
00186
00187 void GxText::setFont(fstring name)
00188 {
00189 GVX_TRACE("GxText::setFont");
00190 itsFont = GxFactory::makeFont(name.c_str());
00191 this->sigNodeChanged.emit();
00192 }
00193
00194 fstring GxText::getFont() const
00195 {
00196 GVX_TRACE("GxText::getFont");
00197 return itsFont->fontName();
00198 }
00199
00200 void GxText::grRender(Gfx::Canvas& canvas) const
00201 {
00202 GVX_TRACE("GxText::grRender");
00203
00204 Gfx::MatrixSaver msaver(canvas);
00205
00206 Gfx::AttribSaver asaver(canvas);
00207
00208 canvas.setLineWidth(itsStrokeWidth);
00209 itsFont->drawText(itsText.c_str(), canvas);
00210 }
00211
00212 static const char __attribute__((used)) vcid_groovx_gfx_gxtext_cc_utc20050626084025[] = "$Id: gxtext.cc 10065 2007-04-12 05:54:56Z rjpeters $ $HeadURL: file:
00213 #endif // !GROOVX_GFX_GXTEXT_CC_UTC20050626084025_DEFINED