void Main() { Window::SetTitle(L"10.00"); Stopwatch stopwatch; Effect effect; const Font font(50); const Vec2 pos = font(L"00.00").regionCenter(Window::Center()).pos; while (System::Update()) { if ((!stopwatch.isActive() || stopwatch.isPaused()) && Input::MouseL.clicked) { Graphics::SetVSyncEnabled(false); stopwatch.start(); } else if (stopwatch.isActive() && Input::MouseL.clicked) { Graphics::SetVSyncEnabled(false); stopwatch.pause(); } else if (Input::MouseR.clicked) { stopwatch.reset(); } else if (stopwatch.isPaused() && stopwatch.ms() / 10 == 10'00) { Graphics::SetVSyncEnabled(true); effect.add<Firework>(Circular(200, Random(TwoPi)) + Window::Center(), 30); } font(L"{:0>2}.{:0>2}"_fmt, stopwatch.s(), stopwatch.ms() % 1000 / 10).draw(pos); if (effect.hasEffects()) { Graphics2D::SetBlendState(BlendState::Additive); effect.update(); Graphics2D::SetBlendState(BlendState::Default); } else { System::Sleep(4ms); } } }
/// <summary> /// EasingControllerを開始、再開します。 /// </summary> /// <returns> /// なし /// </returns> void start() { if (m_stopwatch.isActive() && m_stopwatch.ms() >= m_timeMillisec) { m_stopwatch.reset(); std::swap(m_start, m_end); m_swapped = true; } m_stopwatch.start(); }
double elapsed() const { return Min<double>(m_stopwatch.ms(), m_timeMillisec) / m_timeMillisec; }
bool isEnd() const { return m_stopwatch.ms() >= m_timeMillisec; }