Warning, /include/Geant4/tools/sg/text_valop is written in an unsupported language. File is not indexed.
0001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
0002 // See the file tools.license for terms.
0003
0004 #ifndef tools_sg_text_valop
0005 #define tools_sg_text_valop
0006
0007 #include "base_text"
0008 #include "valop2sg"
0009 #include "nodekit"
0010 #include "base_freetype"
0011 #include "mnmx"
0012 #include "../nostream"
0013
0014 namespace tools {
0015 namespace sg {
0016
0017 class text_valop : public base_text {
0018 public:
0019 TOOLS_NODE(text_valop,tools::sg::text_valop,base_text)
0020 public:
0021 sf_string encoding;
0022 sf_string font;
0023 sf_enum<sg::font_modeling> font_modeling;
0024 public:
0025 virtual const desc_fields& node_desc_fields() const {
0026 TOOLS_FIELD_DESC_NODE_CLASS(tools::sg::text_valop)
0027 static const desc_fields s_v(parent::node_desc_fields(),3, //WARNING : take care of count.
0028 TOOLS_ARG_FIELD_DESC(encoding),
0029 TOOLS_ARG_FIELD_DESC(font),
0030 TOOLS_ARG_FIELD_DESC_ENUMS_BEG(font_modeling,3)
0031 TOOLS_ARG_ENUM(font_outline),
0032 TOOLS_ARG_ENUM(font_filled),
0033 TOOLS_ARG_ENUM(font_pixmap)
0034 TOOLS_ARG_FIELD_DESC_ENUMS_END
0035 );
0036 return s_v;
0037 }
0038 private:
0039 void add_fields(){
0040 add_field(&encoding);
0041 add_field(&font);
0042 add_field(&font_modeling);
0043 }
0044 public:
0045 virtual void render(render_action& a_action) {
0046 if(touched()) {
0047 update_sg(a_action.out());
0048 reset_touched();
0049 }
0050 m_sep.render(a_action);
0051 }
0052 virtual void pick(pick_action& a_action) {
0053 if(touched()) {
0054 update_sg(a_action.out());
0055 reset_touched();
0056 }
0057 nodekit_pick(a_action,m_sep,this);
0058 }
0059 virtual void bbox(bbox_action& a_action) {
0060 if(touched()) {
0061 update_sg(a_action.out());
0062 reset_touched();
0063 }
0064 m_sep.bbox(a_action);
0065 }
0066 virtual void search(search_action& a_action) {
0067 if(touched()) {
0068 update_sg(a_action.out());
0069 reset_touched();
0070 }
0071 parent::search(a_action);
0072 if(a_action.done()) return;
0073 if(a_action.do_path()) a_action.path_push(this);
0074 m_sep.search(a_action);
0075 if(a_action.done()) return;
0076 if(a_action.do_path()) a_action.path_pop();
0077 }
0078 public:
0079 text_valop(const base_freetype& a_ttf)
0080 :parent()
0081 ,encoding(encoding_none())
0082 ,font(font_hershey())
0083 ,font_modeling(font_filled)
0084 ,m_ttf(a_ttf)
0085 {
0086 add_fields();
0087 }
0088 virtual ~text_valop(){}
0089 public:
0090 text_valop(const text_valop& a_from)
0091 :parent(a_from)
0092 ,encoding(a_from.encoding)
0093 ,font(a_from.font)
0094 ,font_modeling(a_from.font_modeling)
0095 ,m_ttf(a_from.m_ttf)
0096 {
0097 add_fields();
0098 }
0099 text_valop& operator=(const text_valop& a_from){
0100 parent::operator=(a_from);
0101 encoding = a_from.encoding;
0102 font = a_from.font;
0103 font_modeling = a_from.font_modeling;
0104 return *this;
0105 }
0106 public: //sg::base_text :
0107 virtual void get_bounds(float /*a_height*/,
0108 float& a_mn_x,float& a_mn_y,float& a_mn_z,
0109 float& a_mx_x,float& a_mx_y,float& a_mx_z) const {
0110 text_valop& self = const_cast<text_valop&>(*this);
0111 if(self.touched()) {
0112 self.update_sg(self.m_out);
0113 self.reset_touched();
0114 }
0115 vec3f mn,mx;
0116 mnmx(self.m_out,self.m_sep,mn,mx);
0117 a_mn_x = mn[0];a_mn_y = mn[1];a_mn_z = mn[2];
0118 a_mx_x = mx[0];a_mx_y = mx[1];a_mx_z = mx[2];
0119 //::printf("debug : get_bounds : %g %g %g : %g %g %g\n",a_mn_x,a_mn_y,a_mn_z,a_mx_x,a_mx_y,a_mx_z);
0120 }
0121 virtual float ascent(float) const {return 1;}
0122 virtual float y_advance(float) const {return 1;}
0123 virtual float descent(float) const {return 0;}
0124 virtual bool truncate(const std::string&,float,float,std::string&) const {return false;}
0125 protected:
0126 void update_sg(std::ostream& a_out) {
0127 m_sep.clear();
0128 matrix* tsf = new matrix;
0129 m_sep.add(tsf);
0130 tools_vforcit(std::string,strings.values(),it) {
0131 valop* _valop = new valop(valop::STRING,*it);
0132 valop2sg v(a_out,m_sep,m_ttf);
0133 if(!v.visit(*_valop)) {
0134 a_out << "tools::sg::text_valop::upate_sg : valop2sg.visit() failed." << std::endl;
0135 m_sep.clear();
0136 delete _valop;
0137 return;
0138 }
0139 delete _valop;
0140 }
0141 vec3f mn,mx;
0142 mnmx(a_out,m_sep,mn,mx);
0143 float h = mx[1]-mn[1];
0144 if(!h) {
0145 a_out << "tools::sg::text_valop::upate_sg : valop has null height." << std::endl;
0146 m_sep.clear();
0147 return;
0148 }
0149 float scale = height.value()/h;
0150 tsf->set_scale(scale,scale,1);
0151 }
0152 protected:
0153 const base_freetype& m_ttf;
0154 separator m_sep;
0155 nostream m_out;
0156 };
0157
0158 }}
0159
0160 #endif