@@ -76,16 +76,30 @@ void ShowString::setStateDefaults()
7676 state->setValue (Parameters::FixedVertical, std::string (" Top" ));
7777 state->setValue (Parameters::CoordinateHorizontal, 0.5 );
7878 state->setValue (Parameters::CoordinateVertical, 0.5 );
79+
80+ getOutputPort (RenderedString)->connectConnectionFeedbackListener ([this ](const ModuleFeedback& var) { processWindowResizeFeedback (var); });
81+ }
82+
83+ void ShowString::processWindowResizeFeedback (const ModuleFeedback& var)
84+ {
85+ auto vsf = static_cast <const ViewSceneFeedback&>(var);
86+ if (lastWindowSize_ != vsf.windowSize )
87+ {
88+ lastWindowSize_ = vsf.windowSize ;
89+ needReexecute_ = true ;
90+ enqueueExecuteAgain (false );
91+ }
7992}
8093
8194void ShowString::execute ()
8295{
8396 auto str = getRequiredInput (String);
8497
85- if (needToExecute ())
98+ if (needToExecute () || needReexecute_ )
8699 {
87100 auto geom = buildGeometryObject (str->value ());
88101 sendOutput (RenderedString, geom);
102+ needReexecute_ = false ;
89103 }
90104}
91105
@@ -112,6 +126,8 @@ std::tuple<double, double> ShowString::getTextPosition()
112126 else // "Bottom"
113127 y = 0.3 ;
114128
129+ state->setValue (Parameters::CoordinateHorizontal, x / 2.0 );
130+ state->setValue (Parameters::CoordinateVertical, y / 2.0 );
115131 return std::make_tuple (x, y);
116132 }
117133 else if (" Coordinates" == positionChoice)
@@ -128,33 +144,8 @@ std::tuple<double, double> ShowString::getTextPosition()
128144// TODO: clean up duplication here and in ShowColorMap
129145GeometryBaseHandle ShowString::buildGeometryObject (const std::string& text)
130146{
131- std::vector<Vector> points;
132- std::vector<ColorRGB> colors;
133- std::vector<uint32_t > indices;
134- auto numVBOElements = 0 ;
135-
136- // IBO/VBOs and sizes
137- uint32_t iboSize = sizeof (uint32_t ) * static_cast <uint32_t >(indices.size ());
138- uint32_t vboSize = sizeof (float ) * 7 * static_cast <uint32_t >(points.size ());
139-
140- std::shared_ptr<CPM_VAR_BUFFER_NS::VarBuffer> iboBufferSPtr (new CPM_VAR_BUFFER_NS::VarBuffer (vboSize));
141- std::shared_ptr<CPM_VAR_BUFFER_NS::VarBuffer> vboBufferSPtr (new CPM_VAR_BUFFER_NS::VarBuffer (iboSize));
142-
143- CPM_VAR_BUFFER_NS::VarBuffer* iboBuffer = iboBufferSPtr.get ();
144- CPM_VAR_BUFFER_NS::VarBuffer* vboBuffer = vboBufferSPtr.get ();
145-
146- for (auto a : indices) iboBuffer->write (a);
147-
148- for (size_t i = 0 ; i < points.size (); i++)
149- {
150- vboBuffer->write (static_cast <float >(points[i].x ()));
151- vboBuffer->write (static_cast <float >(points[i].y ()));
152- vboBuffer->write (static_cast <float >(points[i].z ()));
153- vboBuffer->write (static_cast <float >(colors[i].r ()));
154- vboBuffer->write (static_cast <float >(colors[i].g ()));
155- vboBuffer->write (static_cast <float >(colors[i].b ()));
156- vboBuffer->write (static_cast <float >(1 .f ));
157- }
147+ std::shared_ptr<CPM_VAR_BUFFER_NS::VarBuffer> iboBufferSPtr (new CPM_VAR_BUFFER_NS::VarBuffer (0 ));
148+ std::shared_ptr<CPM_VAR_BUFFER_NS::VarBuffer> vboBufferSPtr (new CPM_VAR_BUFFER_NS::VarBuffer (0 ));
158149
159150 auto uniqueNodeID = get_id ().id_ + " _showString_" + text;
160151 auto vboName = uniqueNodeID + " VBO" ;
@@ -168,14 +159,13 @@ GeometryBaseHandle ShowString::buildGeometryObject(const std::string& text)
168159 attribs.push_back (SpireVBO::AttributeData (" aColor" , 4 * sizeof (float )));
169160 std::vector<SpireSubPass::Uniform> uniforms;
170161
171- auto position = getTextPosition ();
172- auto xTrans = std::get<0 >(position);
173- auto yTrans = std::get<1 >(position);
162+ double xTrans, yTrans;
163+ std::tie (xTrans, yTrans) = getTextPosition ();
174164
175165 uniforms.push_back (SpireSubPass::Uniform (" uXTranslate" , xTrans));
176166 uniforms.push_back (SpireSubPass::Uniform (" uYTranslate" , yTrans));
177167
178- SpireVBO geomVBO (vboName, attribs, vboBufferSPtr, numVBOElements , BBox (), true );
168+ SpireVBO geomVBO (vboName, attribs, vboBufferSPtr, 0 , BBox (), true );
179169 SpireIBO geomIBO (iboName, SpireIBO::PRIMITIVE::TRIANGLES, sizeof (uint32_t ), iboBufferSPtr);
180170
181171 RenderState renState;
@@ -220,6 +210,12 @@ GeometryBaseHandle ShowString::buildGeometryObject(const std::string& text)
220210 textBuilder_->setColor (r, g, b, a);
221211 }
222212
213+ auto dims = textBuilder_->getStringDims (text);
214+ auto length = std::get<0 >(dims) + 20 ;
215+ auto width = std::get<1 >(dims) + 10 ;
216+ xTrans *= 1 - length / std::get<0 >(lastWindowSize_);
217+ yTrans *= 1 - width / std::get<1 >(lastWindowSize_);
218+
223219 Vector trans (xTrans, yTrans, 0.0 );
224220 textBuilder_->printString (text, trans, Vector (), text, *geom);
225221
0 commit comments