mirror of
https://github.com/Rayerd/dfl.git
synced 2025-04-27 05:40:07 +03:00
Add Timer example
This commit is contained in:
parent
a89e010112
commit
e073c378b5
11 changed files with 161 additions and 7 deletions
|
@ -16,6 +16,7 @@ DFL is a Win32 windowing library for the D language.
|
||||||

|

|
||||||

|

|
||||||

|

|
||||||
|

|
||||||
|
|
||||||
## Recent major features
|
## Recent major features
|
||||||
- DUB is available for DFL.
|
- DUB is available for DFL.
|
||||||
|
|
16
examples/timer/.gitignore
vendored
Normal file
16
examples/timer/.gitignore
vendored
Normal file
|
@ -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
|
13
examples/timer/.vscode/launch.json
vendored
Normal file
13
examples/timer/.vscode/launch.json
vendored
Normal file
|
@ -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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
20
examples/timer/.vscode/tasks.json
vendored
Normal file
20
examples/timer/.vscode/tasks.json
vendored
Normal file
|
@ -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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
2
examples/timer/README.md
Normal file
2
examples/timer/README.md
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
# Screen Shot
|
||||||
|

|
16
examples/timer/dub.json
Normal file
16
examples/timer/dub.json
Normal file
|
@ -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"]
|
||||||
|
}
|
BIN
examples/timer/image/screenshot.png
Normal file
BIN
examples/timer/image/screenshot.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.7 KiB |
3
examples/timer/shell.bat
Normal file
3
examples/timer/shell.bat
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
set dmd_path=c:\d\dmd2\windows
|
||||||
|
set dmc_path=c:\dmc\dm
|
||||||
|
cmd
|
65
examples/timer/source/timer_sample.d
Normal file
65
examples/timer/source/timer_sample.d
Normal file
|
@ -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());
|
||||||
|
}
|
12
examples/timer/timer.code-workspace
Normal file
12
examples/timer/timer.code-workspace
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
{
|
||||||
|
"folders": [
|
||||||
|
{
|
||||||
|
"path": "."
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"settings": {
|
||||||
|
"d.projectImportPaths": [
|
||||||
|
"..\\..\\..\\dfl\\source"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,16 +5,23 @@
|
||||||
///
|
///
|
||||||
module dfl.timer;
|
module dfl.timer;
|
||||||
|
|
||||||
private import dfl.internal.winapi, dfl.event, dfl.base, dfl.application,
|
private import dfl.application;
|
||||||
dfl.internal.dlib;
|
private import dfl.base;
|
||||||
|
private import dfl.event;
|
||||||
|
|
||||||
|
private import dfl.internal.dlib;
|
||||||
debug(APP_PRINT)
|
debug(APP_PRINT)
|
||||||
{
|
{
|
||||||
private import dfl.internal.clib;
|
private import dfl.internal.clib;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private import core.sys.windows.windows;
|
||||||
|
|
||||||
|
|
||||||
///
|
///
|
||||||
class Timer // docmain
|
class Timer // docmain
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
//EventHandler tick;
|
//EventHandler tick;
|
||||||
Event!(Timer, EventArgs) tick; ///
|
Event!(Timer, EventArgs) tick; ///
|
||||||
|
|
||||||
|
@ -29,7 +36,7 @@ class Timer // docmain
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ditto
|
/// ditto
|
||||||
@property bool enabled() // getter
|
@property bool enabled() const // getter
|
||||||
{
|
{
|
||||||
return timerId != 0;
|
return timerId != 0;
|
||||||
}
|
}
|
||||||
|
@ -56,7 +63,7 @@ class Timer // docmain
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ditto
|
/// ditto
|
||||||
final @property uint interval() // getter
|
final @property uint interval() const // getter
|
||||||
{
|
{
|
||||||
return _timeout;
|
return _timeout;
|
||||||
}
|
}
|
||||||
|
@ -130,8 +137,7 @@ class Timer // docmain
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
void dispose()
|
void dispose()
|
||||||
{
|
{
|
||||||
stop();
|
stop();
|
||||||
|
@ -145,7 +151,7 @@ class Timer // docmain
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DWORD _timeout = 100;
|
DWORD _timeout = 100;
|
||||||
UINT_PTR timerId = 0;
|
UINT_PTR timerId = 0;
|
||||||
void delegate(Timer) _dg;
|
void delegate(Timer) _dg;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue