-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmultiline_text.cpp
121 lines (102 loc) · 5.13 KB
/
multiline_text.cpp
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
#include "vtkActor2D.h"
#include "vtkCoordinate.h"
#include "vtkNamedColors.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkSmartPointer.h"
#include "vtkTextMapper.h"
#include "vtkTextProperty.h"
#include "platform.h"
auto main(int argc, char** argv) -> int {
const int font_size = 24;
const double line_spaceing = 0.8;
const auto single_line_prop = vtkSmartPointer<vtkTextProperty>::New();
single_line_prop->SetFontSize(font_size);
single_line_prop->SetFontFamilyToArial();
single_line_prop->SetBold(VTK_FALSE);
single_line_prop->SetItalic(VTK_FALSE);
single_line_prop->SetShadow(VTK_FALSE);
const auto multiline_line_prop = vtkSmartPointer<vtkTextProperty>::New();
multiline_line_prop->ShallowCopy(single_line_prop);
multiline_line_prop->SetBold(VTK_TRUE);
multiline_line_prop->SetItalic(VTK_TRUE);
multiline_line_prop->SetShadow(VTK_TRUE);
multiline_line_prop->SetLineSpacing(line_spaceing);
const auto colors = vtkSmartPointer<vtkNamedColors>::New();
const auto single_line_text_mapper_bottom
= vtkSmartPointer<vtkTextMapper>::New();
single_line_text_mapper_bottom->SetInput("Single Line(bottom)");
auto text_property = single_line_text_mapper_bottom->GetTextProperty();
text_property->ShallowCopy(single_line_prop);
text_property->SetVerticalJustificationToBottom();
text_property->SetColor(colors->GetColor3d("Tomata").GetData());
const auto single_line_text_actor_bottom = vtkSmartPointer<vtkActor2D>::New();
single_line_text_actor_bottom->SetMapper(single_line_text_mapper_bottom);
single_line_text_actor_bottom->GetPositionCoordinate()
->SetCoordinateSystemToNormalizedDisplay();
single_line_text_actor_bottom->GetPositionCoordinate()->SetValue(0.05, 0.85);
const auto single_line_text_mapper_center
= vtkSmartPointer<vtkTextMapper>::New();
single_line_text_mapper_center->SetInput("Single line(centerd)");
text_property = single_line_text_mapper_center->GetTextProperty();
text_property->ShallowCopy(single_line_prop);
text_property->SetVerticalJustificationToCentered();
text_property->SetColor(colors->GetColor4d("DarkerGreen").GetData());
const auto single_line_text_actor_center = vtkSmartPointer<vtkActor2D>::New();
single_line_text_actor_center->SetMapper(single_line_text_mapper_center);
single_line_text_actor_center->GetPositionCoordinate()
->SetCoordinateSystemToNormalizedDisplay();
single_line_text_actor_center->GetPositionCoordinate()->SetValue(0.05, 0.75);
const auto single_line_text_mapper_top
= vtkSmartPointer<vtkTextMapper>::New();
single_line_text_mapper_top->SetInput("Single line (Top)");
text_property = single_line_text_mapper_top->GetTextProperty();
text_property->ShallowCopy(single_line_prop);
text_property->SetVerticalJustificationToTop();
text_property->SetColor(colors->GetColor4d("Peacock").GetData());
const auto single_line_text_actor_top = vtkSmartPointer<vtkActor2D>::New();
single_line_text_actor_top->SetMapper(single_line_text_mapper_top);
single_line_text_actor_top->GetPositionCoordinate()
->SetCoordinateSystemToNormalizedDisplay();
single_line_text_actor_top->GetPositionCoordinate()->SetValue(0.05, 0.65);
const auto multi_line_mapper_left = vtkSmartPointer<vtkTextMapper>::New();
multi_line_mapper_left->SetInput(
"This is \nMulti_line\ntext output\n(left-top)");
text_property = multi_line_mapper_left->GetTextProperty();
text_property->ShallowCopy(multiline_line_prop);
text_property->SetJustificationToLeft();
text_property->SetVerticalJustificationToTop();
text_property->SetColor(colors->GetColor4d("Tomata").GetData());
const auto multi_line_actor_left = vtkSmartPointer<vtkActor2D>::New();
multi_line_actor_left->SetMapper(multi_line_mapper_left);
multi_line_actor_left->GetPositionCoordinate()
->SetCoordinateSystemToNormalizedDisplay();
multi_line_actor_left->GetPositionCoordinate()->SetValue(0.05, 0.5);
const auto multi_line_mapper_center = vtkSmartPointer<vtkTextMapper>::New();
multi_line_mapper_center->SetInput(
"This is \nMulti line\ntext output(centerd)");
text_property = multi_line_mapper_center->GetTextProperty();
text_property->ShallowCopy(multiline_line_prop);
text_property->SetJustificationToCentered();
text_property->SetVerticalJustificationToCentered();
text_property->SetColor(colors->GetColor4d("DarkGreen").GetData());
const auto multi_line_actor_center = vtkSmartPointer<vtkActor2D>::New();
multi_line_actor_center->SetMapper(multi_line_mapper_center);
multi_line_actor_center->GetPositionCoordinate()
->SetCoordinateSystemToNormalizedDisplay();
multi_line_actor_center->GetPositionCoordinate()->SetValue(0.5, 0.5);
vtkNew<vtkRenderer> render;
render->AddActor(single_line_text_actor_bottom);
render->AddActor(single_line_text_actor_center);
render->AddActor(single_line_text_actor_top);
render->AddActor(multi_line_actor_center);
render->AddActor(multi_line_actor_left);
vtkNew<vtkRenderWindow> window;
window->AddRenderer(render);
vtkNew<vtkRenderWindowInteractor> interactor;
interactor->SetRenderWindow(window);
window->Render();
interactor->Initialize();
interactor->Start();
}