00001
00002
00003
00004
00005
00006
00007 #include "std/support.H"
00008 #include "glew/glew.H"
00009
00010 #include "disp/colors.H"
00011 #include "geom/text2d.H"
00012
00013 using namespace mlib;
00014
00015 static int tm=DECODER_ADD(TEXT2D);
00016
00017 DLhandler TEXT2D::_dl;
00018 bool TEXT2D::_suppress_draw = false;
00019
00020 GLubyte rasters[][13] = {
00021 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
00022 {0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18},
00023 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x36, 0x36, 0x36},
00024 {0x00, 0x00, 0x00, 0x66, 0x66, 0xff, 0x66, 0x66, 0xff, 0x66, 0x66, 0x00, 0x00},
00025 {0x00, 0x00, 0x18, 0x7e, 0xff, 0x1b, 0x1f, 0x7e, 0xf8, 0xd8, 0xff, 0x7e, 0x18},
00026 {0x00, 0x00, 0x0e, 0x1b, 0xdb, 0x6e, 0x30, 0x18, 0x0c, 0x76, 0xdb, 0xd8, 0x70},
00027 {0x00, 0x00, 0x7f, 0xc6, 0xcf, 0xd8, 0x70, 0x70, 0xd8, 0xcc, 0xcc, 0x6c, 0x38},
00028 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x1c, 0x0c, 0x0e},
00029 {0x00, 0x00, 0x0c, 0x18, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x18, 0x0c},
00030 {0x00, 0x00, 0x30, 0x18, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x18, 0x30},
00031 {0x00, 0x00, 0x00, 0x00, 0x99, 0x5a, 0x3c, 0xff, 0x3c, 0x5a, 0x99, 0x00, 0x00},
00032 {0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0xff, 0xff, 0x18, 0x18, 0x18, 0x00, 0x00},
00033 {0x00, 0x00, 0x30, 0x18, 0x1c, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
00034 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00},
00035 {0x00, 0x00, 0x00, 0x38, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
00036 {0x00, 0x60, 0x60, 0x30, 0x30, 0x18, 0x18, 0x0c, 0x0c, 0x06, 0x06, 0x03, 0x03},
00037 {0x00, 0x00, 0x3c, 0x66, 0xc3, 0xe3, 0xf3, 0xdb, 0xcf, 0xc7, 0xc3, 0x66, 0x3c},
00038 {0x00, 0x00, 0x7e, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x78, 0x38, 0x18},
00039 {0x00, 0x00, 0xff, 0xc0, 0xc0, 0x60, 0x30, 0x18, 0x0c, 0x06, 0x03, 0xe7, 0x7e},
00040 {0x00, 0x00, 0x7e, 0xe7, 0x03, 0x03, 0x07, 0x7e, 0x07, 0x03, 0x03, 0xe7, 0x7e},
00041 {0x00, 0x00, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0xff, 0xcc, 0x6c, 0x3c, 0x1c, 0x0c},
00042 {0x00, 0x00, 0x7e, 0xe7, 0x03, 0x03, 0x07, 0xfe, 0xc0, 0xc0, 0xc0, 0xc0, 0xff},
00043 {0x00, 0x00, 0x7e, 0xe7, 0xc3, 0xc3, 0xc7, 0xfe, 0xc0, 0xc0, 0xc0, 0xe7, 0x7e},
00044 {0x00, 0x00, 0x30, 0x30, 0x30, 0x30, 0x18, 0x0c, 0x06, 0x03, 0x03, 0x03, 0xff},
00045 {0x00, 0x00, 0x7e, 0xe7, 0xc3, 0xc3, 0xe7, 0x7e, 0xe7, 0xc3, 0xc3, 0xe7, 0x7e},
00046 {0x00, 0x00, 0x7e, 0xe7, 0x03, 0x03, 0x03, 0x7f, 0xe7, 0xc3, 0xc3, 0xe7, 0x7e},
00047 {0x00, 0x00, 0x00, 0x38, 0x38, 0x00, 0x00, 0x38, 0x38, 0x00, 0x00, 0x00, 0x00},
00048 {0x00, 0x00, 0x30, 0x18, 0x1c, 0x1c, 0x00, 0x00, 0x1c, 0x1c, 0x00, 0x00, 0x00},
00049 {0x00, 0x00, 0x06, 0x0c, 0x18, 0x30, 0x60, 0xc0, 0x60, 0x30, 0x18, 0x0c, 0x06},
00050 {0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00},
00051 {0x00, 0x00, 0x60, 0x30, 0x18, 0x0c, 0x06, 0x03, 0x06, 0x0c, 0x18, 0x30, 0x60},
00052 {0x00, 0x00, 0x18, 0x00, 0x00, 0x18, 0x18, 0x0c, 0x06, 0x03, 0xc3, 0xc3, 0x7e},
00053 {0x00, 0x00, 0x3f, 0x60, 0xcf, 0xdb, 0xd3, 0xdd, 0xc3, 0x7e, 0x00, 0x00, 0x00},
00054 {0x00, 0x00, 0xc3, 0xc3, 0xc3, 0xc3, 0xff, 0xc3, 0xc3, 0xc3, 0x66, 0x3c, 0x18},
00055 {0x00, 0x00, 0xfe, 0xc7, 0xc3, 0xc3, 0xc7, 0xfe, 0xc7, 0xc3, 0xc3, 0xc7, 0xfe},
00056 {0x00, 0x00, 0x7e, 0xe7, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xe7, 0x7e},
00057 {0x00, 0x00, 0xfc, 0xce, 0xc7, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc7, 0xce, 0xfc},
00058 {0x00, 0x00, 0xff, 0xc0, 0xc0, 0xc0, 0xc0, 0xfc, 0xc0, 0xc0, 0xc0, 0xc0, 0xff},
00059 {0x00, 0x00, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xfc, 0xc0, 0xc0, 0xc0, 0xff},
00060 {0x00, 0x00, 0x7e, 0xe7, 0xc3, 0xc3, 0xcf, 0xc0, 0xc0, 0xc0, 0xc0, 0xe7, 0x7e},
00061 {0x00, 0x00, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xff, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3},
00062 {0x00, 0x00, 0x7e, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x7e},
00063 {0x00, 0x00, 0x7c, 0xee, 0xc6, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06},
00064 {0x00, 0x00, 0xc3, 0xc6, 0xcc, 0xd8, 0xf0, 0xe0, 0xf0, 0xd8, 0xcc, 0xc6, 0xc3},
00065 {0x00, 0x00, 0xff, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0},
00066 {0x00, 0x00, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xdb, 0xff, 0xff, 0xe7, 0xc3},
00067 {0x00, 0x00, 0xc7, 0xc7, 0xcf, 0xcf, 0xdf, 0xdb, 0xfb, 0xf3, 0xf3, 0xe3, 0xe3},
00068 {0x00, 0x00, 0x7e, 0xe7, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xe7, 0x7e},
00069 {0x00, 0x00, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xfe, 0xc7, 0xc3, 0xc3, 0xc7, 0xfe},
00070 {0x00, 0x00, 0x3f, 0x6e, 0xdf, 0xdb, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0x66, 0x3c},
00071 {0x00, 0x00, 0xc3, 0xc6, 0xcc, 0xd8, 0xf0, 0xfe, 0xc7, 0xc3, 0xc3, 0xc7, 0xfe},
00072 {0x00, 0x00, 0x7e, 0xe7, 0x03, 0x03, 0x07, 0x7e, 0xe0, 0xc0, 0xc0, 0xe7, 0x7e},
00073 {0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xff},
00074 {0x00, 0x00, 0x7e, 0xe7, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3},
00075 {0x00, 0x00, 0x18, 0x3c, 0x3c, 0x66, 0x66, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3},
00076 {0x00, 0x00, 0xc3, 0xe7, 0xff, 0xff, 0xdb, 0xdb, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3},
00077 {0x00, 0x00, 0xc3, 0x66, 0x66, 0x3c, 0x3c, 0x18, 0x3c, 0x3c, 0x66, 0x66, 0xc3},
00078 {0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x3c, 0x66, 0x66, 0xc3},
00079 {0x00, 0x00, 0xff, 0xc0, 0xc0, 0x60, 0x30, 0x7e, 0x0c, 0x06, 0x03, 0x03, 0xff},
00080 {0x00, 0x00, 0x3c, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x3c},
00081 {0x00, 0x03, 0x03, 0x06, 0x06, 0x0c, 0x0c, 0x18, 0x18, 0x30, 0x30, 0x60, 0x60},
00082 {0x00, 0x00, 0x3c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x3c},
00083 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc3, 0x66, 0x3c, 0x18},
00084 {0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
00085 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x38, 0x30, 0x70},
00086 {0x00, 0x00, 0x7f, 0xc3, 0xc3, 0x7f, 0x03, 0xc3, 0x7e, 0x00, 0x00, 0x00, 0x00},
00087 {0x00, 0x00, 0xfe, 0xc3, 0xc3, 0xc3, 0xc3, 0xfe, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0},
00088 {0x00, 0x00, 0x7e, 0xc3, 0xc0, 0xc0, 0xc0, 0xc3, 0x7e, 0x00, 0x00, 0x00, 0x00},
00089 {0x00, 0x00, 0x7f, 0xc3, 0xc3, 0xc3, 0xc3, 0x7f, 0x03, 0x03, 0x03, 0x03, 0x03},
00090 {0x00, 0x00, 0x7f, 0xc0, 0xc0, 0xfe, 0xc3, 0xc3, 0x7e, 0x00, 0x00, 0x00, 0x00},
00091 {0x00, 0x00, 0x30, 0x30, 0x30, 0x30, 0x30, 0xfc, 0x30, 0x30, 0x30, 0x33, 0x1e},
00092 {0x7e, 0xc3, 0x03, 0x03, 0x7f, 0xc3, 0xc3, 0xc3, 0x7e, 0x00, 0x00, 0x00, 0x00},
00093 {0x00, 0x00, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xfe, 0xc0, 0xc0, 0xc0, 0xc0},
00094 {0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x18, 0x00},
00095 {0x38, 0x6c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x00, 0x00, 0x0c, 0x00},
00096 {0x00, 0x00, 0xc6, 0xcc, 0xf8, 0xf0, 0xd8, 0xcc, 0xc6, 0xc0, 0xc0, 0xc0, 0xc0},
00097 {0x00, 0x00, 0x7e, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x78},
00098 {0x00, 0x00, 0xdb, 0xdb, 0xdb, 0xdb, 0xdb, 0xdb, 0xfe, 0x00, 0x00, 0x00, 0x00},
00099 {0x00, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xfc, 0x00, 0x00, 0x00, 0x00},
00100 {0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00},
00101 {0xc0, 0xc0, 0xc0, 0xfe, 0xc3, 0xc3, 0xc3, 0xc3, 0xfe, 0x00, 0x00, 0x00, 0x00},
00102 {0x03, 0x03, 0x03, 0x7f, 0xc3, 0xc3, 0xc3, 0xc3, 0x7f, 0x00, 0x00, 0x00, 0x00},
00103 {0x00, 0x00, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xe0, 0xfe, 0x00, 0x00, 0x00, 0x00},
00104 {0x00, 0x00, 0xfe, 0x03, 0x03, 0x7e, 0xc0, 0xc0, 0x7f, 0x00, 0x00, 0x00, 0x00},
00105 {0x00, 0x00, 0x1c, 0x36, 0x30, 0x30, 0x30, 0x30, 0xfc, 0x30, 0x30, 0x30, 0x00},
00106 {0x00, 0x00, 0x7e, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00, 0x00},
00107 {0x00, 0x00, 0x18, 0x3c, 0x3c, 0x66, 0x66, 0xc3, 0xc3, 0x00, 0x00, 0x00, 0x00},
00108 {0x00, 0x00, 0xc3, 0xe7, 0xff, 0xdb, 0xc3, 0xc3, 0xc3, 0x00, 0x00, 0x00, 0x00},
00109 {0x00, 0x00, 0xc3, 0x66, 0x3c, 0x18, 0x3c, 0x66, 0xc3, 0x00, 0x00, 0x00, 0x00},
00110 {0xc0, 0x60, 0x60, 0x30, 0x18, 0x3c, 0x66, 0x66, 0xc3, 0x00, 0x00, 0x00, 0x00},
00111 {0x00, 0x00, 0xff, 0x60, 0x30, 0x18, 0x0c, 0x06, 0xff, 0x00, 0x00, 0x00, 0x00},
00112 {0x00, 0x00, 0x0f, 0x18, 0x18, 0x18, 0x38, 0xf0, 0x38, 0x18, 0x18, 0x18, 0x0f},
00113 {0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18},
00114 {0x00, 0x00, 0xf0, 0x18, 0x18, 0x18, 0x1c, 0x0f, 0x1c, 0x18, 0x18, 0x18, 0xf0},
00115 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x8f, 0xf1, 0x60, 0x00, 0x00, 0x00}
00116 };
00117
00118 TEXT2D::TEXT2D(Cstr_ptr &n, Cstr_ptr &s, CXYpt &p) :
00119 GEOM(n),
00120 _string(s),
00121 _is2d(1),
00122 _center(0),
00123 _can_intersect(0),
00124 _show_boxes(0)
00125 {
00126 _xform = Wtransf(Wpt(p[0],p[1],0));
00127 }
00128
00129 void
00130 TEXT2D::recompute_xform()
00131 {
00132
00133 if (!_is2d)
00134 _pt2d = xform().origin();
00135 else _pt2d = XYpt(xform().origin()[0], xform().origin()[1]);
00136 }
00137
00138 char *
00139 TEXT2D::get_string() const
00140 {
00141 char *s;
00142 if ((**_tmp_string)[0] == '\0') {
00143 ((TEXT2D *)this)->update();
00144 s = **_string;
00145 } else
00146 s = **_tmp_string;
00147 return s;
00148 }
00149
00150
00151
00152
00153
00154
00155
00156 int
00157 TEXT2D::draw(
00158 CVIEWptr &view
00159 )
00160 {
00161
00162
00163 if (_suppress_draw || view->grabbing_screen())
00164 return 0;
00165
00166
00167 char *s = get_string();
00168
00169
00170 if (!s || *s == '\0')
00171 return 0;
00172
00173
00174 glPushAttrib(GL_ENABLE_BIT | GL_LIST_BIT | GL_CURRENT_BIT | GL_LINE_BIT);
00175
00176
00177 glDisable(GL_LIGHTING);
00178
00179
00180 if (_has_color) {
00181 glColor3dv(_color.data());
00182 } else {
00183
00184
00185 if (HSVCOLOR(view->color())[2] > 0.5 && view->get_alpha() > 0.5)
00186 glColor3dv(Color::black.data());
00187 else
00188 glColor3dv(Color::white.data());
00189 }
00190
00191
00192 glMatrixMode(GL_PROJECTION);
00193 glPushMatrix();
00194 glLoadMatrixd(view->xypt_proj().transpose().matrix());
00195
00196 glMatrixMode(GL_MODELVIEW);
00197 glPushMatrix();
00198 glLoadIdentity();
00199
00200 int highlight(HIGHLIGHTED.get(this));
00201
00202 if (highlight || _center ) {
00203 const int border = (_show_boxes || highlight > 1) ? 9 : 5;
00204 BBOX2D bbox(bbox2d(border, s, true));
00205 int w, h;
00206 view->get_size(w, h);
00207 XYvec pixel(2.0 / double(w), 2.0 / double(h));
00208 XYpt ll(bbox.min()), tr(bbox.max());
00209 XYpt lr(bbox.max()[0],bbox.min()[1]), tl(bbox.min()[0],bbox.max()[1]);
00210 BBOX2D bboxll(ll, ll + pixel * border);
00211 BBOX2D bboxlr(lr - XYvec(pixel[0],0) * border,
00212 lr + XYvec(0, pixel[1])* border);
00213 BBOX2D bboxtl(tl - XYvec(0,pixel[1]) * border,
00214 tl + XYvec(pixel[0],0) * border);
00215 BBOX2D bboxtr(tr - pixel * border, tr);
00216 if (highlight) {
00217 glLineWidth(float(view->line_scale()*2));
00218 glBegin(GL_LINE_LOOP);
00219 glVertex2d(bbox.min()[0], bbox.min()[1]);
00220 glVertex2d(bbox.max()[0], bbox.min()[1]);
00221 glVertex2d(bbox.max()[0], bbox.max()[1]);
00222 glVertex2d(bbox.min()[0], bbox.max()[1]);
00223 glEnd();
00224 if (_show_boxes || highlight > 1) {
00225 if (highlight == 2) glBegin(GL_POLYGON);
00226 else glBegin(GL_LINE_LOOP);
00227 glVertex2d(bboxll.min()[0], bboxll.min()[1]);
00228 glVertex2d(bboxll.max()[0], bboxll.min()[1]);
00229 glVertex2d(bboxll.max()[0], bboxll.max()[1]);
00230 glVertex2d(bboxll.min()[0], bboxll.max()[1]);
00231 glEnd();
00232 if (highlight == 3) glBegin(GL_POLYGON);
00233 else glBegin(GL_LINE_LOOP);
00234 glVertex2d(bboxlr.min()[0], bboxlr.min()[1]);
00235 glVertex2d(bboxlr.max()[0], bboxlr.min()[1]);
00236 glVertex2d(bboxlr.max()[0], bboxlr.max()[1]);
00237 glVertex2d(bboxlr.min()[0], bboxlr.max()[1]);
00238 glEnd();
00239 if (highlight == 4) glBegin(GL_POLYGON);
00240 else glBegin(GL_LINE_LOOP);
00241 glVertex2d(bboxtl.min()[0], bboxtl.min()[1]);
00242 glVertex2d(bboxtl.max()[0], bboxtl.min()[1]);
00243 glVertex2d(bboxtl.max()[0], bboxtl.max()[1]);
00244 glVertex2d(bboxtl.min()[0], bboxtl.max()[1]);
00245 glEnd();
00246 if (highlight == 5) glBegin(GL_POLYGON);
00247 else glBegin(GL_LINE_LOOP);
00248 glVertex2d(bboxtr.min()[0], bboxtr.min()[1]);
00249 glVertex2d(bboxtr.max()[0], bboxtr.min()[1]);
00250 glVertex2d(bboxtr.max()[0], bboxtr.max()[1]);
00251 glVertex2d(bboxtr.min()[0], bboxtr.max()[1]);
00252 glEnd();
00253 }
00254 glLineWidth(float(view->line_scale()*1));
00255 }
00256 } else {
00257
00258
00259
00260 recompute_xform();
00261 }
00262
00263
00264 if (!_dl.valid(view))
00265 initialize(view);
00266
00267
00268 glRasterPos2d(_pt2d[0], _pt2d[1]);
00269 glListBase(_dl.dl(view));
00270 glCallLists(strlen(s), GL_UNSIGNED_BYTE, (GLubyte *) s);
00271
00272
00273 glMatrixMode(GL_PROJECTION);
00274 glPopMatrix();
00275
00276
00277 glMatrixMode(GL_MODELVIEW);
00278 glPopMatrix();
00279
00280
00281 glPopAttrib();
00282
00283 return 0;
00284 }
00285
00286 void
00287 TEXT2D::draw_debug(
00288 const char* ,
00289 XYpt & ,
00290 CVIEWptr& )
00291 {
00292
00293 return;
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330 }
00331
00332 void TEXT2D::draw_debug(const char* str, Wpt &pos, CVIEWptr& view)
00333 {
00334 if (view->rendering() == RCOLOR_ID || view->grabbing_screen())
00335 return;
00336
00337 if (!_dl.valid(view)) initialize(view);
00338
00339
00340 glPushAttrib(GL_ENABLE_BIT);
00341
00342
00343 glDisable(GL_LIGHTING);
00344
00345
00346
00347
00348 glRasterPos3dv(pos.data());
00349 glPushAttrib (GL_LIST_BIT);
00350 glListBase(_dl.dl(view));
00351 glCallLists(strlen(str), GL_UNSIGNED_BYTE, (GLubyte *) str);
00352 glPopAttrib ();
00353
00354 glEnable(GL_LIGHTING);
00355 glPopAttrib();
00356 glFlush();
00357
00358 }
00359
00360
00361
00362
00363
00364
00365
00366
00367 void
00368 TEXT2D::initialize(CVIEWptr &v)
00369 {
00370 GLuint i;
00371 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
00372
00373 unsigned int dlbase = _dl.get_dl(v, 128);
00374 for (i = 32; i < 127; i++) {
00375 glNewList(i + dlbase, GL_COMPILE);
00376 glBitmap(8, 13, 0.0, 2.0, 10.0, 0.0, rasters[i-32]);
00377 glEndList();
00378 }
00379
00380
00381 }
00382
00383 RAYhit &
00384 TEXT2D::intersect(
00385 RAYhit &r,
00386 CWtransf &m,
00387 int
00388 ) const
00389 {
00390
00391
00392 if (_can_intersect) {
00393 ((TEXT2D *)this)->recompute_xform();
00394 BBOX2D bbox(bbox2d(0,0));
00395
00396 CXYpt pick_pt(r.point() + r.vec());
00397 if (bbox.contains(pick_pt)) {
00398 Wvec ray(r.point() - xform().origin());
00399
00400
00401 r.check(0, 0, 0, (TEXT2D *)this, ray.normalized(),
00402 r.point() + r.vec()*0.1, Wpt::Origin(),
00403 (APPEAR *) this, XYpt());
00404
00405 return r;
00406 }
00407 }
00408
00409 GEOM::intersect(r,m);
00410 return r;
00411 }
00412
00413
00414
00415
00416
00417 BBOX2D
00418 TEXT2D::bbox2d(
00419 int border,
00420 char *s,
00421 int force
00422 ) const
00423 {
00424 if (s == 0)
00425 s = get_string();
00426
00427 int w, h;
00428 XYpt start, endpt;
00429 VIEW::peek_size(w,h);
00430
00431
00432 XYpt pixel(2.0 / double(w), 2.0 / double(h));
00433
00434 const double xsize = 10.0 * pixel[0];
00435 const double ysize = 13.0 * pixel[1];
00436
00437
00438
00439 if (force)
00440 ((TEXT2D *)this)->recompute_xform();
00441
00442
00443 start = _pt2d;
00444 endpt = XYpt(_pt2d[0] + double(strlen(s)) * xsize, _pt2d[1] + ysize);
00445
00446 if (_center)
00447 {
00448 double diff = endpt[0] - _pt2d[0];
00449
00450 ((TEXT2D *)this)->_pt2d[0] -= diff/2;
00451 start[0] -= diff/2;
00452 endpt[0] -= diff/2;
00453 }
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464 start -= pixel * border;
00465 endpt += pixel * border;
00466
00467 return BBOX2D(start, endpt);
00468 }
00469
00470 bool
00471 TEXT2D::inside(
00472 CXYpt_list &lasso
00473 ) const
00474 {
00475 if (_is2d) return false;
00476
00477 char *s = get_string();
00478
00479
00480 if (!s || *s == '\0')
00481 return false;
00482
00483 BBOX2D bbox(bbox2d(0, s, true));
00484
00485 return lasso.contains(bbox.min()) ||
00486 lasso.contains(bbox.max()) ||
00487 lasso.contains(XYpt(bbox.min()[0], bbox.max()[1])) ||
00488 lasso.contains(XYpt(bbox.max()[0], bbox.min()[1]));
00489 }