unsigned gameMode(Screen &/*screen*/, const void * /*data*/){ GameState state; Surface blankBack(SUR_UNINIT, 1, 1, BLUE); MessageBox fpsDisplay(WHITE, Screen::getScreenRes().x / 2 - 40, 2, 1, blankBack, FONT_DEBUG, 0, false, DEBUG); //SDL_ShowCursor(SDL_DISABLE); //flush event queue before accepting game controls, //specifically the mouse up event from clicking "Play Game" SDL_Event event; while(SDL_PollEvent(&event)) debug("Unhandled event: ", int(event.type)); timer_t oldTicks = SDL_GetTicks(); while (state.loop){ //time stuff timer_t newTicks = SDL_GetTicks(); timer_t delta = newTicks - oldTicks; oldTicks = newTicks; double deltaMod = 1.0 * delta / DELTA_MODIFIER; double fps = delta == 0 ? 0 : 1000 / delta; fpsDisplay(format3(fps), "fps | ", delta, "ms "); //force interface refresh pushMouseMove(); //update state updateState(deltaMod, state, fpsDisplay); //render render(state, fpsDisplay); } //Clean up SDL_ShowCursor(SDL_ENABLE); GameOutcome outcome = state.outcome; return outcome; //return something more meaningful }
void TestStyles::testApplyParagraphStyleWithParent() { KoParagraphStyle style1; style1.setStyleId(1002); KoParagraphStyle style2; style2.setStyleId(1003); KoParagraphStyle style3; style3.setStyleId(1004); style3.setParentStyle(&style2); style2.setParentStyle(&style1); style1.setAlignment(Qt::AlignRight); QCOMPARE(style1.alignment(), Qt::AlignRight); QCOMPARE(style2.alignment(), Qt::AlignRight); QCOMPARE(style3.alignment(), Qt::AlignRight); style2.setAlignment(Qt::AlignCenter); QCOMPARE(style1.alignment(), Qt::AlignRight); QCOMPARE(style2.alignment(), Qt::AlignCenter); QCOMPARE(style3.alignment(), Qt::AlignCenter); style3.setAlignment(Qt::AlignLeft | Qt::AlignAbsolute); QCOMPARE(style1.alignment(), Qt::AlignRight); QCOMPARE(style2.alignment(), Qt::AlignCenter); QCOMPARE(style3.alignment(), Qt::AlignLeft | Qt::AlignAbsolute); style3.setLineSpacing(23.45); style3.setLineHeightPercent(150); style3.setLineHeightAbsolute(8.0); QCOMPARE(style3.lineHeightPercent(), 0.0); QCOMPARE(style3.lineHeightAbsolute(), 8.0); QCOMPARE(style3.lineSpacing(), 23.45); QVERIFY(!style3.hasNormalLineHeight()); style3.setNormalLineHeight(); QCOMPARE(style3.lineHeightPercent(), 0.0); QCOMPARE(style3.lineHeightAbsolute(), 0.0); QCOMPARE(style3.lineSpacing(), 0.0); QVERIFY(style3.hasNormalLineHeight()); style3.setLineHeightPercent(150); style3.setLineSpacing(56.78); QCOMPARE(style3.lineHeightPercent(), 150.0); QCOMPARE(style3.lineHeightAbsolute(), 0.0); QCOMPARE(style3.lineSpacing(), 56.78); QVERIFY(!style3.hasNormalLineHeight()); QTextLength length0(QTextLength::FixedLength, 0.0); QTextLength length1(QTextLength::FixedLength, 10.0); QTextLength length2(QTextLength::FixedLength, 20.0); style1.setLeftMargin(length1); QCOMPARE(style1.leftMargin(), 10.0); QCOMPARE(style2.leftMargin(), 10.0); QCOMPARE(style3.leftMargin(), 10.0); style2.setRightMargin(length2); QCOMPARE(style1.rightMargin(), 0.0); QCOMPARE(style2.rightMargin(), 20.0); QCOMPARE(style3.rightMargin(), 20.0); // now actually apply it. QTextBlockFormat rawFormat; style1.applyStyle(rawFormat); KoParagraphStyle format(rawFormat, rawFormat.toCharFormat()); QCOMPARE(rawFormat.properties().count(), 4); QCOMPARE(format.alignment(), Qt::AlignRight); QCOMPARE(rawFormat.property(KoParagraphStyle::StyleId).toInt(), 1002); //since we have not specified any NextStyle it should be the same as the current style QCOMPARE(rawFormat.property(KoParagraphStyle::StyleId).toInt(), rawFormat.property(KoParagraphStyle::NextStyle).toInt()); QCOMPARE(format.leftMargin(), 10.0); QCOMPARE(format.rightMargin(), 0.0); style2.applyStyle(rawFormat); KoParagraphStyle format2(rawFormat, rawFormat.toCharFormat()); QCOMPARE(rawFormat.properties().count(), 5); QCOMPARE(format2.alignment(), Qt::AlignCenter); QCOMPARE(rawFormat.property(KoParagraphStyle::StyleId).toInt(), 1003); //since we have not specified any NextStyle it should be the same as the current style QCOMPARE(rawFormat.property(KoParagraphStyle::StyleId).toInt(), rawFormat.property(KoParagraphStyle::NextStyle).toInt()); QCOMPARE(format2.leftMargin(), 10.0); QCOMPARE(format2.rightMargin(), 20.0); style3.applyStyle(rawFormat); KoParagraphStyle format3(rawFormat, rawFormat.toCharFormat()); QCOMPARE(rawFormat.properties().count(), 9); QCOMPARE(rawFormat.property(KoParagraphStyle::LineSpacing).toReal(), 56.78); QCOMPARE(format3.alignment(), Qt::AlignLeft | Qt::AlignAbsolute); QCOMPARE(rawFormat.property(KoParagraphStyle::StyleId).toInt(), 1004); //since we have not specified any NextStyle it should be the same as the current style QCOMPARE(rawFormat.property(KoParagraphStyle::StyleId).toInt(), rawFormat.property(KoParagraphStyle::NextStyle).toInt()); QCOMPARE(format3.leftMargin(), 10.0); QCOMPARE(format3.rightMargin(), 20.0); }
void tst_QVideoSurfaceFormat::compare() { QVideoSurfaceFormat format1( QSize(16, 16), QVideoFrame::Format_RGB32, QAbstractVideoBuffer::GLTextureHandle); QVideoSurfaceFormat format2( QSize(16, 16), QVideoFrame::Format_RGB32, QAbstractVideoBuffer::GLTextureHandle); QVideoSurfaceFormat format3( QSize(32, 32), QVideoFrame::Format_YUV444, QAbstractVideoBuffer::GLTextureHandle); QVideoSurfaceFormat format4( QSize(16, 16), QVideoFrame::Format_RGB32, QAbstractVideoBuffer::UserHandle); QCOMPARE(format1 == format2, true); QCOMPARE(format1 != format2, false); QCOMPARE(format1 == format3, false); QCOMPARE(format1 != format3, true); QCOMPARE(format1 == format4, false); QCOMPARE(format1 != format4, true); format2.setFrameSize(1024, 768); // Not equal, frame size differs. QCOMPARE(format1 == format2, false); QCOMPARE(format1 != format2, true); format1.setFrameSize(1024, 768); // Equal. QCOMPARE(format1 == format2, true); QCOMPARE(format1 != format2, false); format1.setViewport(QRect(0, 0, 800, 600)); format2.setViewport(QRect(112, 84, 800, 600)); // Not equal, viewports differ. QCOMPARE(format1 == format2, false); QCOMPARE(format1 != format2, true); format1.setViewport(QRect(112, 84, 800, 600)); // Equal. QCOMPARE(format1 == format2, true); QCOMPARE(format1 != format2, false); format2.setScanLineDirection(QVideoSurfaceFormat::BottomToTop); // Not equal scan line direction differs. QCOMPARE(format1 == format2, false); QCOMPARE(format1 != format2, true); format1.setScanLineDirection(QVideoSurfaceFormat::BottomToTop); // Equal. QCOMPARE(format1 == format2, true); QCOMPARE(format1 != format2, false); format1.setFrameRate(7.5); // Not equal frame rate differs. QCOMPARE(format1 == format2, false); QCOMPARE(format1 != format2, true); format2.setFrameRate(qreal(7.50001)); // Equal. QCOMPARE(format1 == format2, true); QCOMPARE(format1 != format2, false); format2.setPixelAspectRatio(4, 3); // Not equal pixel aspect ratio differs. QCOMPARE(format1 == format2, false); QCOMPARE(format1 != format2, true); format1.setPixelAspectRatio(QSize(4, 3)); // Equal. QCOMPARE(format1 == format2, true); QCOMPARE(format1 != format2, false); format2.setYCbCrColorSpace(QVideoSurfaceFormat::YCbCr_xvYCC601); // Not equal yuv color space differs. QCOMPARE(format1 == format2, false); QCOMPARE(format1 != format2, true); format1.setYCbCrColorSpace(QVideoSurfaceFormat::YCbCr_xvYCC601); // Equal. QCOMPARE(format1 == format2, true); QCOMPARE(format1 != format2, false); format1.setProperty("integer", 12); // Not equal, property mismatch. QCOMPARE(format1 == format2, false); QCOMPARE(format1 != format2, true); format2.setProperty("integer", 45); // Not equal, integer differs. QCOMPARE(format1 == format2, false); QCOMPARE(format1 != format2, true); format2.setProperty("integer", 12); // Equal. QCOMPARE(format1 == format2, true); QCOMPARE(format1 != format2, false); format1.setProperty("string", QString::fromLatin1("Hello")); format2.setProperty("size", QSize(12, 54)); // Not equal, property mismatch. QCOMPARE(format1 == format2, false); QCOMPARE(format1 != format2, true); format2.setProperty("string", QString::fromLatin1("Hello")); format1.setProperty("size", QSize(12, 54)); // Equal. QCOMPARE(format1 == format2, true); QCOMPARE(format1 != format2, false); format1.setProperty("string", QVariant()); // Not equal, property mismatch. QCOMPARE(format1 == format2, false); QCOMPARE(format1 != format2, true); }
std::string format(const std::string& format, const std::map<std::string, std::string>& map) { using tokeniter = std::sregex_token_iterator; bool matched = true; auto opacc = [&](std::string& acc, const tokeniter::value_type& sm) { matched = !matched; // toggle if (!matched) return std::ref(acc += sm.str()); const auto replace = map.find(std::string{sm.first + 1, sm.second - 1}); return std::ref(acc += (replace == end(map)?sm.str():replace->second)); }; static const std::regex kDirective{R"((\{[_[:alpha:]][_[:alnum:]]*\}))"}; const tokeniter first{begin(format), end(format), kDirective, {-1, 1}}; const tokeniter last{}; std::string ret; return std::accumulate(first, last, std::ref(ret), opacc); } std::string format2(const std::string& format, const std::map<std::string, std::string>& map) { using tokeniter = std::sregex_token_iterator; bool matched = true; std::string acc; auto opacc = [&](const tokeniter::value_type& sm) { matched = !matched; // toggle if (!matched) return (acc += sm.str()); const auto replace = map.find(std::string{sm.first + 1, sm.second - 1}); return (acc += (replace == end(map)?sm.str():replace->second)); }; static const std::regex kDirective{R"((\{[_[:alpha:]][_[:alnum:]]*\}))"}; const tokeniter first{begin(format), end(format), kDirective, {-1, 1}}; const tokeniter last{}; std::for_each(first, last, opacc); return acc; } std::string format3(const std::string& format, const std::map<std::string, std::string>& map) { using tokeniter = std::sregex_token_iterator; std::string acc; auto appender = [&](const std::string& sm) { acc.append(sm); }; bool matched = true; auto opacc = [&](const tokeniter::value_type& sm) { matched = !matched; // toggle if (!matched) return sm.str(); const auto replace = map.find(std::string{sm.first + 1, sm.second - 1}); return std::string{replace == end(map) ? sm.str() : replace->second}; }; static const std::regex kDirective{R"((\{[_[:alpha:]][_[:alnum:]]*\}))"}; const tokeniter first{begin(format), end(format), kDirective, {-1, 1}}; const tokeniter last{}; std::transform(first, last, boost::make_function_output_iterator(appender), opacc); return acc; } int main() { std::cout << format("a{b1}aaa {a1} {a2} {{a3} bbb", {{"a1", "@11"}, {"a2", "222"}}) << std::endl; std::cout << format2("a{b1}aaa {a1} {a2} {{a3} bbb", {{"a1", "@11"}, {"a2", "222"}}) << std::endl; std::cout << format3("a{b1}aaa {a1} {a2} {{a3} bbb", {{"a1", "@11"}, {"a2", "222"}}) << std::endl; // expected : a{b1}aaa @11 222 {{a3} bbb std::cout << format("aaa {} {{}} {a1} bbb}", {{"a1", "111"}}) << std::endl; std::cout << format2("aaa {} {{}} {a1} bbb}", {{"a1", "111"}}) << std::endl; std::cout << format3("aaa {} {{}} {a1} bbb}", {{"a1", "111"}}) << std::endl; // expected : aaa {} {{}} 111 bbb} return 0; }
bool ValueFormatTest::InitFromString() { WgValueFormat format1("1000"); TEST_ASSERT( format1.decimals == 0 ); TEST_ASSERT( format1.grouping == 0 ); TEST_ASSERT( format1.prefix[0] == 0 ); TEST_ASSERT( format1.suffix[0] == 0 ); WgValueFormat format2("1;000"); TEST_ASSERT( format2.decimals == 0 ); TEST_ASSERT( format2.grouping == 3 ); TEST_ASSERT( format2.separator == ';' ); TEST_ASSERT( format2.prefix[0] == 0 ); TEST_ASSERT( format2.suffix[0] == 0 ); WgValueFormat format3("1;000:0"); TEST_ASSERT( format3.decimals == 1 ); TEST_ASSERT( format3.grouping == 3 ); TEST_ASSERT( format3.separator == ';' ); TEST_ASSERT( format3.period == ':' ); TEST_ASSERT( format3.prefix[0] == 0 ); TEST_ASSERT( format3.suffix[0] == 0 ); TEST_ASSERT( format3.bForceDecimals == true ); WgValueFormat format4("1;00:000"); TEST_ASSERT( format4.decimals == 3 ); TEST_ASSERT( format4.grouping == 2 ); TEST_ASSERT( format4.separator == ';' ); TEST_ASSERT( format4.period == ':' ); TEST_ASSERT( format4.prefix[0] == 0 ); TEST_ASSERT( format4.suffix[0] == 0 ); TEST_ASSERT( format4.bForceDecimals == true ); WgValueFormat format5("100:000"); TEST_ASSERT( format5.decimals == 3 ); TEST_ASSERT( format5.grouping == 0 ); TEST_ASSERT( format5.period == ':' ); TEST_ASSERT( format5.prefix[0] == 0 ); TEST_ASSERT( format5.suffix[0] == 0 ); TEST_ASSERT( format5.bForceDecimals == true ); std::string a = std::string("$\xc2\xa3\xe2\x82\xac") + std::string("1;000000:0000 USD"); // string is '$£€1;000000:0000 USD' WgValueFormat format6( a ); TEST_ASSERT( format6.decimals == 4 ); TEST_ASSERT( format6.grouping == 6 ); TEST_ASSERT( format6.separator == ';' ); TEST_ASSERT( format6.prefix[0] == '$' ); TEST_ASSERT( format6.prefix[1] == 0xa3 ); // pound sign TEST_ASSERT( format6.prefix[2] == 0x20ac ); // euro sign TEST_ASSERT( format6.prefix[3] == 0 ); TEST_ASSERT( format6.suffix[0] == ' ' ); TEST_ASSERT( format6.suffix[1] == 'U' ); TEST_ASSERT( format6.suffix[2] == 'S' ); TEST_ASSERT( format6.suffix[3] == 'D' ); TEST_ASSERT( format6.bForceDecimals == true ); return true; }
unsigned gameMode(Screen &/*screen*/, const void * data){ GameState state; Surface blankBack(SUR_UNINIT, 1, 1, BLUE); MessageBox fpsDisplay(WHITE, Screen::getScreenRes().x / 2 - 40, 2, 1, blankBack, FONT_DEBUG, 0, false, DEBUG); SDL_ShowCursor(SDL_DISABLE); //flush event queue before accepting game controls, //specifically the mouse up event from clicking "Play Game" SDL_Event event; while(SDL_PollEvent(&event)) debug("Unhandled event: ", int(event.type)); timer_t oldTicks = SDL_GetTicks(); //data tells us which level we're in. int level = *(int*)data; //first: tutorial { Surface tutImage(IMAGE_PATH + "level" + format2(level) + ".png"); screenBuf << tutImage; screenBuf.flip(); //wait for key down or mouse down //while (true){ // SDL_PollEvent(&event); // if (event.type == SDL_MOUSEBUTTONUP || event.type == SDL_KEYUP) // break; //} while (true){ SDL_PollEvent(&event); if (event.type == SDL_MOUSEBUTTONDOWN || event.type == SDL_KEYDOWN) break; } while (true){ SDL_PollEvent(&event); if (event.type == SDL_MOUSEBUTTONUP || event.type == SDL_KEYUP) break; } } state.setLevel(level); while (state.loop){ //time stuff timer_t newTicks = SDL_GetTicks(); timer_t delta = newTicks - oldTicks; oldTicks = newTicks; if (delta > 500) continue; double deltaMod = 1.0 * delta / DELTA_MODIFIER; double fps = delta == 0 ? 0 : 1000 / delta; fpsDisplay(format3(fps), "fps | ", delta, "ms "); //force interface refresh pushMouseMove(); //update state updateState(deltaMod, state, fpsDisplay); //render render(state, fpsDisplay); } //Clean up SDL_ShowCursor(SDL_ENABLE); GameOutcome outcome = state.outcome; return outcome; //return something more meaningful }