diff --git a/dlanguilib.visualdproj b/dlanguilib.visualdproj index 8b86a837..510b6bd6 100644 --- a/dlanguilib.visualdproj +++ b/dlanguilib.visualdproj @@ -66,7 +66,7 @@ 0 DebugFocus 0 - EmbedStandardResources Unicode + EmbedStandardResources Unicode USE_SDL USE_FREETYPE 0 0 1 diff --git a/src/dlangui/core/logger.d b/src/dlangui/core/logger.d index af340530..f70fd108 100644 --- a/src/dlangui/core/logger.d +++ b/src/dlangui/core/logger.d @@ -51,7 +51,7 @@ enum LogLevel : int { } /// Returns timestamp in milliseconds since 1970 UTC similar to Java System.currentTimeMillis() -long currentTimeMillis() { +@property long currentTimeMillis() { return std.datetime.Clock.currStdTime / 10000; } diff --git a/src/dlangui/platforms/common/platform.d b/src/dlangui/platforms/common/platform.d index f85eb605..089ea51f 100644 --- a/src/dlangui/platforms/common/platform.d +++ b/src/dlangui/platforms/common/platform.d @@ -86,6 +86,51 @@ class EventList { } } +class TimerInfo { + static ulong nextId; + + this(Widget targetWidget, long intervalMillis) { + _id = ++nextId; + assert(intervalMillis >= 0 && intervalMillis < 7*24*60*60*1000L); + _targetWidget = targetWidget; + _interval = intervalMillis; + _nextTimestamp = currentTimeMillis + _interval; + } + /// cancel timer + void cancel() { + _targetWidget = null; + } + /// cancel timer + void notify() { + if (_targetWidget) { + _nextTimestamp = currentTimeMillis + _interval; + if (!_targetWidget.onTimer(_id)) { + _targetWidget = null; + } + } + } + /// unique Id of timer + @property ulong id() { return _id; } + /// timer interval, milliseconds + @property long interval() { return _interval; } + /// next timestamp to invoke timer at, as per currentTimeMillis() + @property long nextTimestamp() { return _nextTimestamp; } + /// widget to route timer event to + @property Widget targetWidget() { return _targetWidget; } + + protected ulong _id; + protected long _interval; + protected long _nextTimestamp; + protected Widget _targetWidget; +} + +class TimerQueue { + protected TimerInfo[] _queue; + void add(TimerInfo event) { + int len = cast(int)_queue.length; + } +} + /** * Window abstraction layer. Widgets can be shown only inside window. * diff --git a/src/dlangui/widgets/widget.d b/src/dlangui/widgets/widget.d index 7e1a0487..920b7b2b 100644 --- a/src/dlangui/widgets/widget.d +++ b/src/dlangui/widgets/widget.d @@ -923,6 +923,12 @@ class Widget { return res; } + /// handle timer; return true to repeat timer event after next interval, false cancel timer + bool onTimer(ulong id) { + // override to do something useful + return false; + } + /// map key to action Action findKeyAction(uint keyCode, uint flags) { Action action = _acceleratorMap.findByKey(keyCode, flags);