-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.d
61 lines (42 loc) · 1.35 KB
/
main.d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// main.d, example of using fltk in D
// Copyright 2012 Philippe Quesnel
// Licensed under the Academic Free License version 3.0
module main;
import std.stdio;
import std.string;
import std.c.string;
import std.utf;
import std.conv;
import fltkLib.interfaces.cppInterface;
// code that will be called from c++/fltk gui
class TextProcessor : ITextProcessorD {
string text;
extern (C++) void setText(const char* ptext){
text = to!string(ptext);
}
extern (C++) void process() {
writeln("D textprocess: ", text);
}
}
int main(string[] args)
{
writefln("Hello World\n");
auto textProcessor = new TextProcessor;
auto mainWindow = createMainWindow(textProcessor);
string ss = "bonjour";
mainWindow.toto("allo".toStringz, // this toStringz not required apparently !
"allo pas stringz",
ss.toStringz);
// convert 'args' to an argv array to pass to window.show(argc, char** argv)
char*[] argv;
foreach (arg; args)
argv ~= toUTFz!(char*)(arg);
mainWindow.show(cast(int)argv.length, argv.ptr);
fl_run();
// call C++ method that returns the text from dragndrop
const char* ptext = mainWindow.getDroppedText();
writeln("getDroppedText() : ", to!string(ptext));
// will delete mainWindow in C++
freeMainWindow(mainWindow);
return 0;
}