diff --git a/README.md b/README.md index 35607e7..5440bd0 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ DFL is a Win32 windowing library for the D language. ![screen shot](./examples/clippingform/image/screenshot.png "screen shot") ![screen shot](./examples/picturebox/image/screenshot.png "screen shot") ![screen shot](./examples/notifyicon/image/screenshot.png "screen shot") +![screen shot](./examples/timer/image/screenshot.png "screen shot") ## Recent major features - DUB is available for DFL. diff --git a/examples/timer/.gitignore b/examples/timer/.gitignore new file mode 100644 index 0000000..60a5f2a --- /dev/null +++ b/examples/timer/.gitignore @@ -0,0 +1,16 @@ +.dub +docs.json +__dummy.html +docs/ +/hello_dfl +hello_dfl.so +hello_dfl.dylib +hello_dfl.dll +hello_dfl.a +hello_dfl.lib +hello_dfl-test-* +*.exe +*.pdb +*.o +*.obj +*.lst diff --git a/examples/timer/.vscode/launch.json b/examples/timer/.vscode/launch.json new file mode 100644 index 0000000..5172b75 --- /dev/null +++ b/examples/timer/.vscode/launch.json @@ -0,0 +1,13 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "C++ Launch (Windows) timer", + "type": "cppvsdbg", + "request": "launch", + "cwd": "${workspaceRoot}", + "program": "./bin/timer_sample.exe", + "console": "internalConsole" + } + ] +} \ No newline at end of file diff --git a/examples/timer/.vscode/tasks.json b/examples/timer/.vscode/tasks.json new file mode 100644 index 0000000..8232b04 --- /dev/null +++ b/examples/timer/.vscode/tasks.json @@ -0,0 +1,20 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "type": "dub", + "run": false, + "cwd": ".", + "compiler": "$current", + "archType": "$current", + "buildType": "$current", + "configuration": "$current", + "problemMatcher": [ + "$dmd" + ], + "group": "build", + "label": "dub: Build timer_sample", + "detail": "dub build --compiler=dmd.EXE -a=x86_64 -b=debug -c=application" + } + ] +} \ No newline at end of file diff --git a/examples/timer/README.md b/examples/timer/README.md new file mode 100644 index 0000000..b1a86ca --- /dev/null +++ b/examples/timer/README.md @@ -0,0 +1,2 @@ +# Screen Shot +![screen shot](./image/screenshot.png "screen shot") diff --git a/examples/timer/dub.json b/examples/timer/dub.json new file mode 100644 index 0000000..2ab5323 --- /dev/null +++ b/examples/timer/dub.json @@ -0,0 +1,16 @@ +{ + "authors": ["haru-s"], + "copyright": "Copyright (C) 2023 haru-s", + "description": "DFL sample code.", + "name": "timer_sample", + "targetType": "executable", + "targetPath": "bin", + "dependencies": { + "dfl": { + "path": "../../../dfl" + } + }, + "lflags-windows-x86_omf-dmd": ["/exet:nt/su:windows:6.0"], + "lflags-windows-x86_mscoff-dmd": ["/SUBSYSTEM:WINDOWS", "/ENTRY:mainCRTStartup"], + "lflags-windows-x86_64-dmd": ["/SUBSYSTEM:WINDOWS", "/ENTRY:mainCRTStartup"] +} \ No newline at end of file diff --git a/examples/timer/image/screenshot.png b/examples/timer/image/screenshot.png new file mode 100644 index 0000000..a87a34f Binary files /dev/null and b/examples/timer/image/screenshot.png differ diff --git a/examples/timer/shell.bat b/examples/timer/shell.bat new file mode 100644 index 0000000..49ab56b --- /dev/null +++ b/examples/timer/shell.bat @@ -0,0 +1,3 @@ +set dmd_path=c:\d\dmd2\windows +set dmc_path=c:\dmc\dm +cmd diff --git a/examples/timer/source/timer_sample.d b/examples/timer/source/timer_sample.d new file mode 100644 index 0000000..3d77403 --- /dev/null +++ b/examples/timer/source/timer_sample.d @@ -0,0 +1,65 @@ +import dfl; +import std.conv; + +version(Have_dfl) // For DUB. +{ +} +else +{ + pragma(lib, "dfl.lib"); +} + +class MainForm : Form +{ + private Label _label; + private Timer _timer; + private Button _start; + private Button _stop; + private uint _count; + + public this() + { + this.text = "Timer example"; + this.size = Size(300, 200); + + _label = new Label; + _label.location = Point(100, 0); + _label.font = new Font("Verdana", 50f); + _label.autoSize = true; + _label.text = to!string(_count); + _label.parent = this; + + _timer = new Timer; + _timer.interval = 1000; + _timer.tick ~= (Timer t, EventArgs e) { + _label.text = to!string(_count); + _count++; + }; + + _start = new Button; + _start.text = "Start"; + _start.location = Point(10, 10); + _start.click ~= (Control c, EventArgs e) { + _timer.start(); + }; + _start.parent = this; + + _stop = new Button; + _stop.text = "Stop"; + _stop.location = Point(10, 50); + _stop.click ~= (Control c, EventArgs e) { + _timer.stop(); + }; + _stop.parent = this; + } +} + +static this() +{ + Application.enableVisualStyles(); +} + +void main() +{ + Application.run(new MainForm()); +} diff --git a/examples/timer/timer.code-workspace b/examples/timer/timer.code-workspace new file mode 100644 index 0000000..7e696bc --- /dev/null +++ b/examples/timer/timer.code-workspace @@ -0,0 +1,12 @@ +{ + "folders": [ + { + "path": "." + } + ], + "settings": { + "d.projectImportPaths": [ + "..\\..\\..\\dfl\\source" + ] + } +} \ No newline at end of file diff --git a/source/dfl/timer.d b/source/dfl/timer.d index 5a8e5eb..ed63440 100644 --- a/source/dfl/timer.d +++ b/source/dfl/timer.d @@ -5,16 +5,23 @@ /// module dfl.timer; -private import dfl.internal.winapi, dfl.event, dfl.base, dfl.application, - dfl.internal.dlib; +private import dfl.application; +private import dfl.base; +private import dfl.event; + +private import dfl.internal.dlib; debug(APP_PRINT) { private import dfl.internal.clib; } +private import core.sys.windows.windows; + + /// class Timer // docmain { +public: //EventHandler tick; Event!(Timer, EventArgs) tick; /// @@ -29,7 +36,7 @@ class Timer // docmain } /// ditto - @property bool enabled() // getter + @property bool enabled() const // getter { return timerId != 0; } @@ -56,7 +63,7 @@ class Timer // docmain } /// ditto - final @property uint interval() // getter + final @property uint interval() const // getter { return _timeout; } @@ -130,8 +137,7 @@ class Timer // docmain } - protected: - +protected: void dispose() { stop(); @@ -145,7 +151,7 @@ class Timer // docmain } - private: +private: DWORD _timeout = 100; UINT_PTR timerId = 0; void delegate(Timer) _dg;