g4tools  5.4.0
tools
Go to the documentation of this file.
1 // Copyright (C) 2010, Guy Barrand. All rights reserved.
2 // See the file tools.license for terms.
3 
4 #ifndef tools_sg_tools
5 #define tools_sg_tools
6 
7 #include "separator"
8 #include "matrix"
9 #include "text_hershey"
10 #include "base_freetype"
11 
12 #include <cstdio> //sscanf
13 //#include <sstream>
14 //#include <cmath>
15 
16 namespace tools {
17 namespace sg {
18 
19 inline void add_string(
20  separator& a_sep
21 ,const std::string& a_font
22 ,font_modeling& a_font_modeling
23 ,const std::string& a_encoding
24 ,bool //a_smoothing
25 ,const std::string& a_string
26 ,float a_x,float a_y,float a_z
27 ,const vec3f& a_X
28 ,const vec3f& a_Y
29 ,float a_size
30 ,hjust a_hjust
31 ,vjust a_vjust
32 ,const base_freetype& a_ttf
33 ){
34  if(a_string.empty()) return;
35 
36  matrix* tsf = new matrix;
37 
38  {tsf->mul_translate(a_x,a_y,a_z);
39  vec3f X = a_X;
40  vec3f Y = a_Y;
41  X.normalize();
42  Y.normalize();
43  vec3f Z;X.cross(Y,Z);
44  Z.cross(X,Y);
45  mat4f r(X.v0(),Y.v0(),Z.v0(),0, //first row
46  X.v1(),Y.v1(),Z.v1(),0,
47  X.v2(),Y.v2(),Z.v2(),0,
48  0,0,0,1);
49  tsf->mul_mtx(r);
50  tsf->mul_scale(a_size,a_size,1);} //applied first on GL
51 
52  a_sep.add(tsf);
53 
54  if(a_font==font_hershey()) {
55 
57  text->encoding.value(a_encoding);
58  text->strings.add(a_string);
59  text->hjust.value(a_hjust);
60  text->vjust.value(a_vjust);
61  a_sep.add(text);
62 
63  } else {
64 
66 
67  text->font = a_font;
68 
69  //text->modeling.value(font_outline);
70  //text->encoding.value(a_encoding);
71  //text->smooting.value(a_smoothing);
72  text->strings.add(a_string);
73  text->hjust.value(a_hjust);
74  text->vjust.value(a_vjust);
75  text->modeling = a_font_modeling;
76  a_sep.add(text);
77 
78  }
79 
80 }
81 
83  separator& a_sep
84 ,const std::string& a_font
85 ,font_modeling a_font_modeling
86 ,const std::string& a_encoding
87 ,bool //a_smoothing
88 ,const std::string& a_string
89 ,float a_x,float a_y,float a_z
90 ,mat4f& a_scale_rot
91 ,hjust a_hjust
92 ,vjust a_vjust
93 ,const base_freetype& a_ttf
94 ){
95  //used in axis::update_sg()
96  if(a_string.empty()) return 0;
97 
98  matrix* tsf = new matrix;
99  tsf->mul_translate(a_x,a_y,a_z);
100  tsf->mul_mtx(a_scale_rot);
101  a_sep.add(tsf);
102 
103  if(a_font==font_hershey()) {
104 
106  text->encoding.value(a_encoding);
107  text->strings.add(a_string);
108  text->hjust.value(a_hjust);
109  text->vjust.value(a_vjust);
110  a_sep.add(text);
111 
112  } else {
113 
114  std::string _s = a_string;
115  if(a_encoding==encoding_PAW()) {
116  int mag;
117  if(::sscanf(a_string.c_str(),"10^%d?",&mag)==1) {
118  _s[2] = 'e';
119  _s = _s.substr(0,_s.size()-1);
120  //std::ostringstream oss;
121  //oss << ::pow(10.0,mag);
122  //_s = oss.str();
123  }
124  }
125 
127 
128  text->font = a_font;
129 
130  //text->modeling.value(font_outline);
131  //text->encoding.value(a_encoding);
132  //text->smooting.value(a_smoothing);
133  text->strings.add(_s);
134  text->hjust.value(a_hjust);
135  text->vjust.value(a_vjust);
136  text->modeling = a_font_modeling;
137  a_sep.add(text);
138 
139  }
140 
141  return tsf;
142 }
143 
144 }}
145 
146 #endif
tools::sg::text::vjust
sf_enum< sg::vjust > vjust
Definition: text:49
tools::vec3::v2
const T & v2() const
Definition: vec3:78
tools::vec3::v1
const T & v1() const
Definition: vec3:77
tools::sg::bmf::add
void add(const T &a_value)
Definition: bmf:73
tools::sg::hjust
hjust
Definition: enums:73
tools::sg::text::font
sf_string font
Definition: text:32
tools::sg::matrix::mul_mtx
void mul_mtx(const mat4f &a_m)
Definition: matrix:100
tools::sg::encoding_PAW
const std::string & encoding_PAW()
Definition: strings:42
tools::sg::text
Definition: text:25
tools::vec3::v0
const T & v0() const
Definition: vec3:76
tools::sg::base_freetype
Definition: base_freetype:16
tools::sg::text::strings
mf_string strings
Definition: text:28
tools::sg::text_hershey
Definition: text_hershey:82
matrix
base_freetype
tools::sg::font_modeling
font_modeling
Definition: enums:91
tools::sg::group::add
void add(node *a_node)
Definition: group:96
tools::sg::vjust
vjust
Definition: enums:79
tools::vec3f
Definition: vec3f:13
tools::sg::separator
Definition: separator:15
tools::vec3::cross
void cross(const vec3< T > &aV, vec3< T > &a_value) const
Definition: vec3:131
tools
inlined C code : ///////////////////////////////////
Definition: aida_ntuple:26
tools::sg::base_freetype::create
static base_freetype * create(const base_freetype &a_ttf)
Definition: base_freetype:108
tools::sg::matrix
Definition: matrix:19
tools::sg::add_string
void add_string(separator &a_sep, const std::string &a_font, font_modeling &a_font_modeling, const std::string &a_encoding, bool, const std::string &a_string, float a_x, float a_y, float a_z, const vec3f &a_X, const vec3f &a_Y, float a_size, hjust a_hjust, vjust a_vjust, const base_freetype &a_ttf)
Definition: tools:19
tools::sg::matrix::mul_translate
void mul_translate(float a_x, float a_y, float a_z)
Definition: matrix:102
tools::mat4f
Definition: mat4f:12
tools::sg::text::hjust
sf_enum< sg::hjust > hjust
Definition: text:48
tools::sg::bsf::value
T & value()
Definition: bsf:98
tools::sg::font_hershey
const std::string & font_hershey()
Definition: strings:186
tools::vec3f::normalize
float normalize()
Definition: vec3f:74
tools::sg::matrix::mul_scale
void mul_scale(float a_x, float a_y, float a_z)
Definition: matrix:104
text_hershey
separator
tools::sg::text::encoding
sf_string encoding
Definition: text:35
tools::sg::add_string_opt
matrix * add_string_opt(separator &a_sep, const std::string &a_font, font_modeling a_font_modeling, const std::string &a_encoding, bool, const std::string &a_string, float a_x, float a_y, float a_z, mat4f &a_scale_rot, hjust a_hjust, vjust a_vjust, const base_freetype &a_ttf)
Definition: tools:82