Skip to content

Commit f41488f

Browse files
committed
Check in resizeEvent
1 parent 48fc0f3 commit f41488f

File tree

5 files changed

+31
-21
lines changed

5 files changed

+31
-21
lines changed

src/Interface/Modules/Render/ViewScene.cc

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ DEALINGS IN THE SOFTWARE.
3939
#include <Graphics/Glyphs/GlyphGeom.h>
4040
#include <Graphics/Datatypes/GeometryImpl.h>
4141
#include <Core/GeometryPrimitives/Transform.h>
42+
#include <boost/timer.hpp>
4243

4344
using namespace SCIRun::Gui;
4445
using namespace SCIRun::Dataflow::Networks;
@@ -213,9 +214,19 @@ void ViewSceneDialog::mousePressEvent(QMouseEvent* event)
213214

214215
void ViewSceneDialog::resizeEvent(QResizeEvent *event)
215216
{
216-
ViewSceneFeedback vsf;
217-
vsf.windowSize = std::make_tuple(event->size().width(), event->size().height());
218-
state_->setTransientValue(Parameters::GeometryFeedbackInfo, vsf);
217+
static boost::timer timer;
218+
static Mutex lock("VS::resize");
219+
220+
{
221+
Guard g(lock.get());
222+
if (timer.elapsed() > 1)
223+
{
224+
timer.restart();
225+
ViewSceneFeedback vsf;
226+
vsf.windowSize = std::make_tuple(event->size().width(), event->size().height());
227+
state_->setTransientValue(Parameters::GeometryFeedbackInfo, vsf);
228+
}
229+
}
219230

220231
ModuleDialogGeneric::resizeEvent(event);
221232
}
@@ -1040,7 +1051,7 @@ GeometryHandle ViewSceneDialog::buildGeometryScaleBar()
10401051
oneline = ss.str();
10411052
double text_len = 0.0;
10421053
if (textBuilder_.isReady())
1043-
text_len = textBuilder_.getStringLen(oneline);
1054+
text_len = std::get<0>(textBuilder_.getStringDims(oneline));
10441055
text_len += 5;//add a 5-pixel gap
10451056

10461057
std::vector<Vector> points;
@@ -1679,8 +1690,8 @@ namespace //TODO: move to appropriate location
16791690

16801691
void ViewSceneDialog::sendGeometryFeedbackToState(int x, int y, const std::string& selName)
16811692
{
1682-
std::shared_ptr<SRInterface> spire = mSpire.lock();
1683-
glm::mat4 trans = spire->getWidgetTransform().transform;
1693+
auto spire = mSpire.lock();
1694+
auto trans = spire->getWidgetTransform().transform;
16841695

16851696
ViewSceneFeedback vsf;
16861697
vsf.transform = toSciTransform(trans);

src/Modules/Visualization/ShowString.cc

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,12 @@ void ShowString::setStateDefaults()
8080
getOutputPort(RenderedString)->connectConnectionFeedbackListener([this](const ModuleFeedback& var) { processWindowResizeFeedback(var); });
8181
}
8282

83-
void ShowString::processWindowResizeFeedback(const Core::Datatypes::ModuleFeedback& var)
83+
void ShowString::processWindowResizeFeedback(const ModuleFeedback& var)
8484
{
8585
auto vsf = static_cast<const ViewSceneFeedback&>(var);
86-
auto width = std::get<0>(vsf.windowSize);
87-
if (lastWindowSize_ != width)
86+
if (lastWindowSize_ != vsf.windowSize)
8887
{
89-
lastWindowSize_ = width;
88+
lastWindowSize_ = vsf.windowSize;
9089
needReexecute_ = true;
9190
enqueueExecuteAgain(false);
9291
}
@@ -211,12 +210,12 @@ GeometryBaseHandle ShowString::buildGeometryObject(const std::string& text)
211210
textBuilder_->setColor(r, g, b, a);
212211
}
213212

214-
auto length = textBuilder_->getStringLen(text) + 20;
215-
// std::cout << "xTrans before " << xTrans <<
216-
// " lastWindowSize_ " << lastWindowSize_ <<
217-
// " multiplier " << (1 - length / lastWindowSize_) <<
218-
// " xTrans after " << (xTrans * (1 - length / lastWindowSize_)) << std::endl;
219-
xTrans *= 1 - length / lastWindowSize_;
213+
auto dims = textBuilder_->getStringDims(text);
214+
auto length = std::get<0>(dims) + 20;
215+
xTrans *= 1 - length / std::get<0>(lastWindowSize_);
216+
217+
std::cout << "Rows from string dims: " << std::get<1>(dims) << " yTrans: " << yTrans << std::endl;
218+
220219
Vector trans(xTrans, yTrans, 0.0);
221220
textBuilder_->printString(text, trans, Vector(), text, *geom);
222221

src/Modules/Visualization/ShowString.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ namespace Visualization {
7373
Core::Datatypes::GeometryBaseHandle buildGeometryObject(const std::string& text);
7474
std::tuple<double, double> getTextPosition();
7575
void processWindowResizeFeedback(const Core::Datatypes::ModuleFeedback& var);
76-
int lastWindowSize_ {450};
76+
std::tuple<int,int> lastWindowSize_ { 450, 1000 };
7777
bool needReexecute_ {true};
7878
};
7979
}}}

src/Modules/Visualization/TextBuilder.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,10 +260,10 @@ void TextBuilder::printString(const std::string& oneline,
260260
}
261261
}
262262

263-
double TextBuilder::getStringLen(const std::string& oneline) const
263+
std::tuple<double, double> TextBuilder::getStringDims(const std::string& oneline) const
264264
{
265265
if (!ftValid_)
266-
return 0.0;
266+
return {};
267267

268268
auto len = 0.0;
269269
auto rows = 0;
@@ -275,7 +275,7 @@ double TextBuilder::getStringLen(const std::string& oneline) const
275275
len += g->bitmap.width;
276276
rows = g->bitmap.rows;
277277
}
278-
return len;
278+
return std::make_tuple(len, rows);
279279
}
280280

281281
bool TextBuilder::initialize(size_t textSize)

src/Modules/Visualization/TextBuilder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ namespace SCIRun {
6767

6868
//get string length based on current settings
6969
//return value in pixels
70-
double getStringLen(const std::string& oneline) const;
70+
std::tuple<double,double> getStringDims(const std::string& oneline) const;
7171

7272
private:
7373
std::string getUniqueFontString(char p, double x, double y, double z, double w, double h) const;

0 commit comments

Comments
 (0)