File: TextRenderer.cpp

package info (click to toggle)
cgal 6.1.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 144,952 kB
  • sloc: cpp: 811,597; ansic: 208,576; sh: 493; python: 411; makefile: 286; javascript: 174
file content (115 lines) | stat: -rw-r--r-- 3,940 bytes parent folder | download | duplicates (2)
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
#include <CGAL/Three/TextRenderer.h>
#include <CGAL/Three/Scene_item.h>
#include <CGAL/Three/Scene_print_item_interface.h>
void TextRenderer::draw(CGAL::Three::Viewer_interface *viewer, const QVector3D& scaler)
{
    QPainter *painter = viewer->getPainter();
    if (!painter->isActive())
      painter->begin(viewer);
    QRect rect;
    CGAL::qglviewer::Camera* camera = viewer->camera();
    //Display the items textItems
    for(TextListItem* list : textItems)
    {
      CGAL::Three::Scene_print_item_interface* item =
      qobject_cast<CGAL::Three::Scene_print_item_interface*>(scene->item(scene->mainSelectionIndex()));
      if( item &&
          item->shouldDisplayIds(list->item())
         ){
        for(TextItem* item : list->textList())
        {
          CGAL::qglviewer::Vec src(item->position().x(), item->position().y(),item->position().z());
          if(viewer->testDisplayId(src.x, src.y, src.z))
          {
            if(item->is_3D())
            {
              src.x *= scaler.x();
              src.y *= scaler.y();
              src.z *= scaler.z();
              rect = QRect(int(camera->projectedCoordinatesOf(src).x -item->width()/2),
                           int(camera->projectedCoordinatesOf(src).y -item->height()/2),
                           int(item->width()),
                           int(item->height()));
            }
            else
              rect = QRect(int(src.x-item->width()/2),
                           int(src.y-item->height()/2),
                           int(item->width()),
                           int(item->height()));

            painter->setFont(item->font());
            QColor c = item->color().toHsv();
            c.setHsv((c.hsvHue()+180)%360, 255,255,100);
            painter->setBrush(QBrush(c));
            painter->setPen(QPen(QColor(0,0,0,0)));
            painter->drawRect(rect);
            painter->setPen(QPen(item->color()));
            painter->drawText(rect, item->text());
          }
        }
      }
    }

    //Display the local TextItems
    for(TextItem* item : local_textItems)
    {
      CGAL::qglviewer::Vec src(item->position().x(), item->position().y(),item->position().z());
      if(item->is_3D())
      {
        if(item->is_always_visible() || viewer->testDisplayId(src.x, src.y, src.z))
        {
            rect = QRect(int(camera->projectedCoordinatesOf(src).x-item->width()/2),
                         int(camera->projectedCoordinatesOf(src).y-item->height()/2),
                         int(item->width()),
                         int(item->height()));
        }
      }
      else
      {
          rect = QRect(int(src.x-item->width()/2),
                       int(src.y-item->height()/2),
                       int(item->width()),
                       int(item->height()));
      }
      painter->setFont(item->font());
      QColor c = item->color().toHsv();
      c.setHsv((c.hsvHue()+180)%360, 255,255,100);
      painter->setBrush(QBrush(c));
      painter->setPen(QPen(QColor(0,0,0,0)));
      painter->drawRect(rect);
      painter->setPen(QPen(item->color()));
      painter->drawText(rect, item->text());
    }
}

 void TextRenderer::addTextList(TextListItem *tl)
 {
   if(tl->textList().size() > max_textItems)
   {
     Q_EMIT sendMessage("There are too many textItems to display.",5000);
     return;
   }
     textItems.append(tl);
 }

 void TextRenderer::addText(TextItem *ti)
 {
     local_textItems.append(ti);
 }

 void TextRenderer::addText(float p_x, float p_y, float p_z, QString p_text, bool p_3D, QFont p_font , QColor p_color )
 {
     local_textItems.append(new TextItem(p_x, p_y, p_z, p_text, p_3D, p_font, p_color));
 }

 void TextRenderer::removeText(TextItem *item)
 {
     local_textItems.removeAll(item);
 }

 void TextRenderer::removeTextList(TextListItem *p_list)
 {
   for(TextListItem *list : textItems)
         if(list == p_list)
             textItems.removeAll(list);
 }