Project

General

Profile

Bug #2048 » WStackedWidget_animation_stutter_20130714a.cc

Bruce Toll, 07/18/2013 08:02 PM

 
#include <Wt/WServer>
#include <Wt/WStackedWidget>
#include <Wt/WAnimation>
#include <Wt/WTimer>
#include <Wt/WText>
#include <Wt/WBreak>
#include <Wt/WTable>
#include <Wt/WBootstrapTheme>

using namespace Wt;

class TestApplication : public WApplication
{
public:
TestApplication(const WEnvironment& env);

private:
void step();
WColor col_color(int col);

static constexpr int Cell_Width {16};
static constexpr int Cell_Height {16};
static constexpr int Table_Cols {48};
static constexpr int Table_Rows {20};
static constexpr int Table_Width {Table_Cols * Cell_Width};
static constexpr int Table_Height {Table_Rows * Cell_Height};
static constexpr int Column_Group {6};
static constexpr int Max_Steps {24};
static constexpr int Step_Time {2000};
static constexpr int Animation_Time {1000};

WBootstrapTheme bs_theme_;
WStackedWidget* sw_ {nullptr};
WTimer timer_;
int cnt_ {0};
};

TestApplication::TestApplication(const WEnvironment& env) : WApplication(env)
{
setTitle("Stuttering WStackedWidget Animations");
setTheme(&bs_theme_);

WContainerWidget *w = new WContainerWidget(root());
new WText("Look for stuttering transitions, particularly with FireFox...", w);
new WBreak(w);

sw_ = new WStackedWidget(w);
sw_->setTransitionAnimation(WAnimation(WAnimation::Fade, WAnimation::Linear, Animation_Time));
sw_->resize(Table_Width, Table_Height);

for (int i = 0; i < 2; ++i) {
auto t0 = new WTable(w);
t0->resize(Table_Width, Table_Height);
for (int r = 0; r < Table_Rows; ++r) {
for (int c = 0; c < Table_Cols; ++c) {
auto w0 = t0->elementAt(r, c);
w0->resize(Cell_Width, Cell_Height);
}
}
sw_->addWidget(t0);
}

// step();
timer_.timeout().connect(this, &TestApplication::step);
timer_.setInterval(Step_Time);
timer_.start();
}

void TestApplication::step() {
int next_index = 1 - sw_->currentIndex();

auto t = dynamic_cast<WTable*>(sw_->widget(next_index));

for (int r = 0; r < Table_Rows; ++r) {
for (int c = 0; c < Table_Cols; ++c) {
t->elementAt(r, c)->decorationStyle().setBackgroundColor(col_color(c));
}
}
sw_->setCurrentIndex(next_index);
if (++cnt_ > Max_Steps)
quit();
}

WColor TestApplication::col_color(int col) {
// sequence active columns through colors: red, blue, green (at 50% alpha)
if ((col % Column_Group) == (cnt_ % Column_Group))
return WColor(!(col % 3) * 256, !((col + 1) % 3) * 256, !((col + 2) % 3) * 256,128);
else
return WColor(white);
}

int main(int argc, char **argv)
{
return WRun(argc, argv, [](const WEnvironment& env) {return new TestApplication(env);});
}
(1-1/2)