Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

text2d.C

Go to the documentation of this file.
00001 /*************************************************************************
00002  *    NAME: Loring Holden
00003  *    USER: lsh
00004  *    FILE: text2d.C
00005  *    DATE: Tue Apr  1 22:57:46 US/Eastern 1997
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    // If this text is attached to a 3D point, project it to screen space
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  * Function Name: TEXT2D::draw
00152  * Parameters: 
00153  * Returns: int
00154  * Effects: 
00155  *************************************************************************/
00156 int
00157 TEXT2D::draw(
00158    CVIEWptr &view
00159    )
00160 {
00161    // leave the ID reference image alone,
00162    // and don't draw text into screen grabs:
00163    if (_suppress_draw || view->grabbing_screen())
00164       return 0;
00165    
00166    // Get string we are going to display
00167    char *s = get_string();
00168 
00169    // quit early if we aren't displaying anything
00170    if (!s || *s == '\0')
00171       return 0; // No triangles
00172 
00173    // GL initialization
00174    glPushAttrib(GL_ENABLE_BIT | GL_LIST_BIT | GL_CURRENT_BIT | GL_LINE_BIT);
00175 
00176    // No lighting
00177    glDisable(GL_LIGHTING);              // GL_ENABLE_BIT
00178 
00179    // Color
00180    if (_has_color) {
00181       glColor3dv(_color.data());        // GL_CURRENT_BIT
00182    } else {
00183       // draw black if background is light,
00184       // draw white if background is dark.
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    // Setup projection for drawing in XY coords
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));      // GL_LINE_BIT
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       // If this text is attached to a 3D point, project it to screen space
00258       // If this text is 2D, the location is stored in the xform(), so
00259       // copy that into _pt2d
00260       recompute_xform();
00261    }
00262 
00263    // Initialize bitmaps for the letters
00264    if (!_dl.valid(view)) 
00265       initialize(view);
00266 
00267    // Actually draw the text
00268    glRasterPos2d(_pt2d[0], _pt2d[1]);
00269    glListBase(_dl.dl(view));
00270    glCallLists(strlen(s), GL_UNSIGNED_BYTE, (GLubyte *) s);
00271 
00272    // Restore projection matrix
00273    glMatrixMode(GL_PROJECTION);
00274    glPopMatrix();
00275 
00276    // Restore modelview matrix
00277    glMatrixMode(GL_MODELVIEW);
00278    glPopMatrix();
00279 
00280    // Restore gl state
00281    glPopAttrib();
00282 
00283    return 0; // No triangles
00284 }
00285 
00286 void 
00287 TEXT2D::draw_debug(
00288    const char* /* str */,
00289    XYpt & /* pos */,
00290    CVIEWptr& /* view */)
00291 {
00292    // XXX Incorrect behavior. Disabled for the moment
00293    return;
00294    /*
00295    if (view->rendering() == RCOLOR_ID || view->grabbing_screen())
00296       return;
00297    
00298    if (!_dl.valid(view)) initialize(view);
00299 
00300    // GL initialization
00301    glPushAttrib(GL_ENABLE_BIT); // (GL_ENABLE_BIT)
00302 
00303    // No lighting
00304    glDisable(GL_LIGHTING);
00305    // Color
00306 
00307    glColor3dv(COLOR::white.data());
00308    
00309    // Position so 2D coordinates are in screen space
00310    glMatrixMode(GL_PROJECTION);
00311    glPushMatrix();
00312    glLoadMatrixd(view->xypt_proj().transpose().matrix());
00313    glMatrixMode(GL_MODELVIEW);
00314    glLoadIdentity();
00315    
00316    glRasterPos2d(pos[0], pos[1]);
00317    glPushAttrib (GL_LIST_BIT); // (GL_LIST_BIT)
00318    glListBase(_dl.dl(view));  
00319    glCallLists(strlen(str), GL_UNSIGNED_BYTE, (GLubyte *) str);
00320    glPopAttrib (); // (GL_LIST_BIT)   
00321    
00322    glMatrixMode(GL_PROJECTION);
00323    glPopMatrix();
00324    glMatrixMode(GL_MODELVIEW);
00325    glEnable(GL_LIGHTING);
00326    glPopAttrib(); // (GL_ENABLE_BIT)
00327    glFlush();
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    // GL initialization
00340    glPushAttrib(GL_ENABLE_BIT); // (GL_ENABLE_BIT)
00341 
00342    // No lighting
00343    glDisable(GL_LIGHTING);
00344    // Color
00345 
00346    //glColor3dv(COLOR::white.data());
00347    
00348    glRasterPos3dv(pos.data());
00349    glPushAttrib (GL_LIST_BIT); // (GL_LIST_BIT)
00350    glListBase(_dl.dl(view));  
00351    glCallLists(strlen(str), GL_UNSIGNED_BYTE, (GLubyte *) str);
00352    glPopAttrib (); // (GL_LIST_BIT)   
00353    
00354    glEnable(GL_LIGHTING);
00355    glPopAttrib(); // (GL_ENABLE_BIT)
00356    glFlush();
00357 
00358 }
00359 
00360 
00361 /*************************************************************************
00362  * Function Name: TEXT2D::initialize
00363  * Parameters: 
00364  * Returns: void
00365  * Effects: 
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       //uv
00388    ) const
00389 {
00390    // Only pick text when it is associated w/ a 3D point and we know
00391    // the window size
00392    if (_can_intersect) {
00393       ((TEXT2D *)this)->recompute_xform(); // Update text location
00394       BBOX2D bbox(bbox2d(0,0));            // Get bounding box 
00395 
00396       CXYpt pick_pt(r.point() + r.vec());
00397       if (bbox.contains(pick_pt)) {  // picked!
00398          Wvec ray(r.point() - xform().origin());
00399          // assume text is always close to the camera
00400          // for now, that means 0.1 distance along viewing vector
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); // Check if children were intersected
00410    return r;
00411 }
00412 
00413 /*************************************************************************
00414  * Function Name: text2d::bbox
00415  * Effects: 
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    // Size of a pixel in NDC (-1 to 1)
00432    XYpt pixel(2.0 / double(w), 2.0 / double(h));
00433    // xsize, ysize are NDC size of each letter
00434    const double xsize = 10.0 * pixel[0];
00435    const double ysize = 13.0 * pixel[1];
00436 
00437    // NOTE: this function isn't really 'const' since we
00438    //       have to recompute cached xform values
00439    if (force) 
00440       ((TEXT2D *)this)->recompute_xform();
00441 
00442    // start, endpt - defines box
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    if (_center) 
00457    {
00458       double diff = endpt[0] - _pt2d[0];
00459       ((TEXT2D *)this)->_pt2d[0] = -diff / 2;
00460       endpt[0] = _pt2d[0] + diff;
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    // Blow this pop stand if there isn't anything to intersect
00480    if (!s || *s == '\0')
00481       return false; // No intersection
00482 
00483    BBOX2D bbox(bbox2d(0, s, true));
00484    // Intersect with corners of bounding box
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 }

Generated on Mon Sep 18 11:39:34 2006 for jot by  doxygen 1.4.4