uses std::chrono
This commit is contained in:
parent
7de40cdc69
commit
f697f4c338
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Definition of Notifier
|
||||
* Nana C++ Library(http://www.nanapro.org)
|
||||
* Copyright(C) 2003-2016 Jinhao(cnjinhao@hotmail.com)
|
||||
* Copyright(C) 2003-2019 Jinhao(cnjinhao@hotmail.com)
|
||||
*
|
||||
* Distributed under the Boost Software License, Version 1.0.
|
||||
* (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@ -59,7 +59,11 @@ namespace nana
|
||||
void text(const ::std::string&);
|
||||
void icon(const ::std::string& icon_file);
|
||||
void insert_icon(const ::std::string& icon_file);
|
||||
#if 0 //deprecated
|
||||
void period(unsigned millisecond);
|
||||
#else
|
||||
void period(std::chrono::milliseconds time);
|
||||
#endif
|
||||
detail::notifier_events& events();
|
||||
window handle() const;
|
||||
private:
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* A Timer Implementation
|
||||
* Copyright(C) 2003-2015 Jinhao(cnjinhao@hotmail.com)
|
||||
* Copyright(C) 2003-2019 Jinhao(cnjinhao@hotmail.com)
|
||||
*
|
||||
* Distributed under the Boost Software License, Version 1.0.
|
||||
* (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@ -11,6 +11,8 @@
|
||||
* A timer can repeatedly call a piece of code. The duration between
|
||||
* calls is specified in milliseconds. Timer is defferent from other graphics
|
||||
* controls, it has no graphics interface.
|
||||
*
|
||||
* @contributors: rbrugo(#417)
|
||||
*/
|
||||
|
||||
#ifndef NANA_GUI_TIMER_HPP
|
||||
@ -38,12 +40,16 @@ namespace nana
|
||||
timer& operator=(timer&&) = delete;
|
||||
public:
|
||||
timer();
|
||||
#if 0 //deprecated
|
||||
[[deprecated("prefer a std::chrono::duration (like std::chrono::milliseconds) over "
|
||||
"raw integers for durations")]]
|
||||
timer(unsigned int ms) : timer{} { interval_(ms); } /// Accepts an initial interval in ms
|
||||
|
||||
template <typename Rep, typename Period> /// Accepts an initial interval in any chrono unit
|
||||
explicit timer(std::chrono::duration<Rep, Period> const & time) : timer{} { interval(time); }
|
||||
|
||||
#else
|
||||
explicit timer(std::chrono::milliseconds ms);
|
||||
#endif
|
||||
~timer();
|
||||
|
||||
template<typename Function>
|
||||
@ -57,22 +63,30 @@ namespace nana
|
||||
bool started() const;
|
||||
void stop();
|
||||
|
||||
#if 0 //deprecated
|
||||
[[deprecated("prefer a std::chrono::duration (like std::chrono::milliseconds) over "
|
||||
"raw integers for durations")]]
|
||||
inline void interval(unsigned milliseconds) { interval_(milliseconds); }
|
||||
|
||||
template <typename Rep, typename Period>
|
||||
inline void interval(std::chrono::duration<Rep, Period> const & time_interval) ///< Set the duration between calls, accepts std::chrono
|
||||
{
|
||||
interval_(std::chrono::duration_cast<std::chrono::milliseconds>(time_interval).count());
|
||||
_m_interval(static_cast<unsigned>(std::chrono::duration_cast<std::chrono::milliseconds>(time_interval).count()));
|
||||
}
|
||||
#else
|
||||
void interval(std::chrono::milliseconds ms);
|
||||
#endif
|
||||
|
||||
#if 0 //deprecated
|
||||
unsigned interval() const;
|
||||
#endif
|
||||
template <typename Duration = std::chrono::milliseconds>
|
||||
inline Duration interval() const
|
||||
{
|
||||
return std::chrono::duration_cast<Duration>(std::chrono::milliseconds(interval));
|
||||
return std::chrono::duration_cast<Duration>(std::chrono::milliseconds{ _m_interval() });
|
||||
}
|
||||
private:
|
||||
void interval_(unsigned milliseconds); ///< Set the duration between calls (millisec ??)
|
||||
unsigned _m_interval() const;
|
||||
private:
|
||||
nana::basic_event<arg_elapse> elapse_;
|
||||
implement * const impl_;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* A Scroll Implementation
|
||||
* Nana C++ Library(http://www.nanapro.org)
|
||||
* Copyright(C) 2003-2018 Jinhao(cnjinhao@hotmail.com)
|
||||
* Copyright(C) 2003-2019 Jinhao(cnjinhao@hotmail.com)
|
||||
*
|
||||
* Distributed under the Boost Software License, Version 1.0.
|
||||
* (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@ -258,7 +258,7 @@ namespace nana
|
||||
case buttons::first:
|
||||
case buttons::second:
|
||||
make_step(drawer_.metrics.what == buttons::second, 1);
|
||||
timer_.interval(1000);
|
||||
timer_.interval(std::chrono::seconds{1});
|
||||
timer_.start();
|
||||
break;
|
||||
case buttons::scroll:
|
||||
@ -321,7 +321,7 @@ namespace nana
|
||||
{
|
||||
make_step(drawer_.metrics.what == buttons::second, 1);
|
||||
API::refresh_window(widget_->handle());
|
||||
timer_.interval(100);
|
||||
timer_.interval(std::chrono::milliseconds{ 100 });
|
||||
}
|
||||
private:
|
||||
::nana::scroll<Vertical> * widget_;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Implementation of Notifier
|
||||
* Nana C++ Library(http://www.nanapro.org)
|
||||
* Copyright(C) 2003-2018 Jinhao(cnjinhao@hotmail.com)
|
||||
* Copyright(C) 2003-2019 Jinhao(cnjinhao@hotmail.com)
|
||||
*
|
||||
* Distributed under the Boost Software License, Version 1.0.
|
||||
* (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@ -351,13 +351,14 @@ namespace nana
|
||||
#endif
|
||||
}
|
||||
|
||||
void notifier::period(unsigned ms)
|
||||
void notifier::period(std::chrono::milliseconds ms)
|
||||
{
|
||||
#if defined(NANA_WINDOWS)
|
||||
if (ms && impl_->icons.size())
|
||||
if (ms.count() && impl_->icons.size())
|
||||
{
|
||||
ms /= static_cast<unsigned>(impl_->icons.size());
|
||||
impl_->ani_timer.interval(ms < 16 ? 16 : ms);
|
||||
auto frame_ms = (std::max)(ms.count() / static_cast<long long>(impl_->icons.size()), static_cast<long long>(16));
|
||||
|
||||
impl_->ani_timer.interval(std::chrono::milliseconds{frame_ms});
|
||||
impl_->ani_timer.start();
|
||||
}
|
||||
else
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* A Timer Implementation
|
||||
* Nana C++ Library(http://www.nanapro.org)
|
||||
* Copyright(C) 2003-2018 Jinhao(cnjinhao@hotmail.com)
|
||||
* Copyright(C) 2003-2019 Jinhao(cnjinhao@hotmail.com)
|
||||
*
|
||||
* Distributed under the Boost Software License, Version 1.0.
|
||||
* (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@ -175,6 +175,12 @@ namespace nana
|
||||
{
|
||||
}
|
||||
|
||||
timer::timer(std::chrono::milliseconds ms):
|
||||
timer()
|
||||
{
|
||||
this->interval(ms);
|
||||
}
|
||||
|
||||
timer::~timer()
|
||||
{
|
||||
if (impl_->tm_core)
|
||||
@ -220,17 +226,17 @@ namespace nana
|
||||
timer_driver::instance().destroy(tmid);
|
||||
}
|
||||
|
||||
void timer::interval_(unsigned ms)
|
||||
void timer::interval(std::chrono::milliseconds ms)
|
||||
{
|
||||
if (ms != impl_->interval)
|
||||
if (ms.count() != static_cast<long long>(impl_->interval))
|
||||
{
|
||||
impl_->interval = ms;
|
||||
impl_->interval = static_cast<unsigned>(ms.count());
|
||||
if (impl_->tm_core)
|
||||
impl_->tm_core->interval(ms);
|
||||
impl_->tm_core->interval(impl_->interval);
|
||||
}
|
||||
}
|
||||
|
||||
unsigned timer::interval() const
|
||||
unsigned timer::_m_interval() const
|
||||
{
|
||||
return impl_->interval;
|
||||
}
|
||||
|
||||
@ -86,12 +86,12 @@ namespace nana
|
||||
timer_.reset();
|
||||
if (duration_)
|
||||
{
|
||||
timer_.interval(static_cast<unsigned>(duration_));
|
||||
timer_.interval(std::chrono::milliseconds{ duration_ });
|
||||
timer_.elapse(std::bind(&tip_form::_m_tick_duration, this));
|
||||
}
|
||||
else
|
||||
{
|
||||
timer_.interval(500);
|
||||
timer_.interval(std::chrono::milliseconds{ 500 });
|
||||
timer_.elapse(std::bind(&tip_form::_m_tick, this));
|
||||
}
|
||||
timer_.start();
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* A Menu implementation
|
||||
* Nana C++ Library(http://www.nanapro.org)
|
||||
* Copyright(C) 2009-2017 Jinhao(cnjinhao@hotmail.com)
|
||||
* Copyright(C) 2009-2019 Jinhao(cnjinhao@hotmail.com)
|
||||
*
|
||||
* Distributed under the Boost Software License, Version 1.0.
|
||||
* (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@ -819,7 +819,7 @@ namespace nana
|
||||
events.mouse_down.connect_unignorable(fn);
|
||||
events.mouse_up.connect_unignorable(fn);
|
||||
|
||||
timer_.interval(100);
|
||||
timer_.interval(std::chrono::milliseconds{ 100 });
|
||||
timer_.elapse([this]{
|
||||
this->_m_open_sub(500); //Try to open submenu
|
||||
});
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* A Content View Implementation
|
||||
* Nana C++ Library(http://www.nanapro.org)
|
||||
* Copyright(C) 2017-2018 Jinhao(cnjinhao@hotmail.com)
|
||||
* Copyright(C) 2017-2019 Jinhao(cnjinhao@hotmail.com)
|
||||
*
|
||||
* Distributed under the Boost Software License, Version 1.0.
|
||||
* (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@ -132,7 +132,7 @@ namespace nana {
|
||||
}
|
||||
else if (this->drag_view_move && this->drive(arg.pos))
|
||||
{
|
||||
tmr.interval(16);
|
||||
tmr.interval(std::chrono::milliseconds{ 16 });
|
||||
tmr.start();
|
||||
}
|
||||
}
|
||||
|
||||
@ -275,11 +275,11 @@ namespace nana
|
||||
API::update_window(editor_->window_handle());
|
||||
|
||||
auto intv = timer_.interval();
|
||||
if (intv > 50)
|
||||
if (intv.count() > 50)
|
||||
timer_.interval(intv / 2);
|
||||
});
|
||||
|
||||
timer_.interval(600);
|
||||
timer_.interval(std::chrono::milliseconds{ 600 });
|
||||
}
|
||||
|
||||
void attach(::nana::widget& wdg, ::nana::paint::graphics& graph)
|
||||
@ -396,7 +396,7 @@ namespace nana
|
||||
API::release_capture(editor_->window_handle());
|
||||
|
||||
timer_.stop();
|
||||
timer_.interval(600);
|
||||
timer_.interval(std::chrono::milliseconds{ 600 });
|
||||
}
|
||||
|
||||
if (buttons::none != spin_stated_)
|
||||
|
||||
@ -1735,7 +1735,7 @@ namespace nana
|
||||
}
|
||||
});
|
||||
|
||||
impl_->adjust.timer.interval(16);
|
||||
impl_->adjust.timer.interval(std::chrono::milliseconds{ 16 });
|
||||
impl_->adjust.timer.start();
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user