Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
// -*- C++ -*-
//
// Package:     Core
// Class  :     FWTextProjected
//
// Implementation:
//     [Notes on implementation]
//
// Original Author:  Alja Mrak-Tadel
//         Created:  Fri Aug 12 01:12:18 CEST 2011
//

// system include files

// user include files
#include <iostream>

#include "Fireworks/Core/interface/FWTextProjected.h"
#include "TEveProjectionManager.h"
#include "TEveTrans.h"
#include "TGLBoundingBox.h"

#include "TGLIncludes.h"

#include "TGLRnrCtx.h"
#include "TGLUtil.h"
#include "TGLCamera.h"
//______________________________________________________________________________
TClass* FWEveText::ProjectedClass(const TEveProjection*) const {
  // Virtual from TEveProjectable, returns TEvePointSetProjected class.

  return FWEveTextProjected::Class();
}

//______________________________________________________________________________
void FWEveTextProjected::UpdateProjection() {
  //   printf("update projection \n");

  FWEveText& als = *dynamic_cast<FWEveText*>(fProjectable);
  TEveTrans* tr = als.PtrMainTrans(kFALSE);

  fText = als.GetText();
  *fMainColorPtr = als.GetMainColor();
  float pos[3];
  tr->GetPos(pos);

  TEveProjection& proj = *fManager->GetProjection();
  proj.ProjectPoint(pos[0], pos[1], pos[2], fDepth);

  RefMainTrans().SetPos(pos[0], pos[1], pos[2] + als.m_offsetZ);
}
//==============================================================================

void FWEveTextGL::DirectDraw(TGLRnrCtx& rnrCtx) const {
  Int_t fm = fM->GetFontMode();
  if (fm == TGLFont::kBitmap || fm == TGLFont::kPixmap || fm == TGLFont::kTexture)
    rnrCtx.RegisterFont(fM->GetFontSize(), fM->GetFontFile(), fM->GetFontMode(), fFont);
  else
    rnrCtx.RegisterFontNoScale(fM->GetFontSize(), fM->GetFontFile(), fM->GetFontMode(), fFont);

  // rendering
  glPushMatrix();
  fFont.PreRender(fM->GetAutoLighting(), fM->GetLighting());

  const GLdouble* pm = rnrCtx.RefCamera().RefLastNoPickProjM().CArr();

  GLdouble mm[16];
  GLint vp[4];
  glGetDoublev(GL_MODELVIEW_MATRIX, mm);
  glGetIntegerv(GL_VIEWPORT, vp);

  fX[0][0] = fX[0][1] = fX[0][2] = 0;
  GLdouble x, y, z;
  gluProject(fX[0][0], fX[0][1], fX[0][2], mm, pm, vp, &x, &y, &z);
  Float_t bbox[6];
  fFont.BBox(fM->GetText(), bbox[0], bbox[1], bbox[2], bbox[3], bbox[4], bbox[5]);

  gluUnProject(x + bbox[0], y + bbox[1], z, mm, pm, vp, &fX[0][0], &fX[0][1], &fX[0][2]);
  gluUnProject(x + bbox[3], y + bbox[1], z, mm, pm, vp, &fX[1][0], &fX[1][1], &fX[1][2]);
  gluUnProject(x + bbox[3], y + bbox[4], z, mm, pm, vp, &fX[2][0], &fX[2][1], &fX[2][2]);
  gluUnProject(x + bbox[0], y + bbox[4], z, mm, pm, vp, &fX[3][0], &fX[3][1], &fX[3][2]);
  glEnable(GL_POLYGON_OFFSET_FILL);

  FWEveText* model = (FWEveText*)fM;
  double xm = fX[0][0] - model->m_textPad;
  double xM = fX[2][0] + model->m_textPad;
  double ym = fX[0][1] - model->m_textPad;
  double yM = fX[2][1] + model->m_textPad;

  //   TGLUtil::Color(1016);
  if (rnrCtx.ColorSet().Background().GetRed())
    TGLUtil::Color(kWhite);
  else
    TGLUtil::Color(kBlack);

  glPolygonOffset(1, 1);
  glBegin(GL_POLYGON);
  glVertex2d(xm, ym);
  glVertex2d(xM, ym);
  glVertex2d(xM, yM);
  glVertex2d(xm, yM);

  glEnd();

  TGLUtil::Color(fM->GetMainColor());
  if (true) {
    glPolygonOffset(0, 0);
    glBegin(GL_LINE_LOOP);
    glVertex2d(xm, ym);
    glVertex2d(xM, ym);
    glVertex2d(xM, yM);
    glVertex2d(xm, yM);
    glEnd();
  }

  glPolygonOffset(0, 0);

  glRasterPos3i(0, 0, 0);
  fFont.Render(fM->GetText());
  fFont.PostRender();
  glPopMatrix();
}