From dbc17bb0035584024095e9766de3a9a781773742 Mon Sep 17 00:00:00 2001 From: Fabien Freling Date: Wed, 8 May 2019 23:09:31 +0200 Subject: [PATCH] Integrate OCaml in Qt project --- Makefile | 2 +- src/core/oboy.ml | 5 ++++- src/core/version.ml | 6 ++++++ src/qt/About.qml | 19 +++++++++++++++++++ src/qt/main.cpp | 10 ++++++++++ src/qt/main.qml | 12 ++++++++++++ src/qt/oboy.pro | 6 ++++++ src/qt/qml.qrc | 1 + 8 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 src/core/version.ml create mode 100644 src/qt/About.qml diff --git a/Makefile b/Makefile index f60518b..0315897 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ all: dune build src/lib/oboy.exe core: - dune build src/retroarch + dune build src/core/oboy.a check: ocamlbuild -use-ocamlfind -I src -lflag -g test/test_bit.byte -- diff --git a/src/core/oboy.ml b/src/core/oboy.ml index 521cf16..efd1338 100644 --- a/src/core/oboy.ml +++ b/src/core/oboy.ml @@ -60,7 +60,7 @@ let power_up cartridge = run cpu mem screen -let () = +let main = if Array.length Sys.argv < 2 then begin prerr_endline "Please specify a ROM."; eprintf "Usage: %s path/to/rom\n" Sys.argv.(0); @@ -71,3 +71,6 @@ let () = match cartridge with | None -> print_endline "Invalid ROM file." | Some c -> power_up c + +(** let () = + main *) diff --git a/src/core/version.ml b/src/core/version.ml new file mode 100644 index 0000000..f4a02c3 --- /dev/null +++ b/src/core/version.ml @@ -0,0 +1,6 @@ +let name () = "oboy" +let version () = "1.0a" + +let () = + Callback.register "name" name; + Callback.register "version" version; diff --git a/src/qt/About.qml b/src/qt/About.qml new file mode 100644 index 0000000..d1e4c8a --- /dev/null +++ b/src/qt/About.qml @@ -0,0 +1,19 @@ +import QtQuick 2.4 +import QtQuick.Window 2.0 + +Window { + title: "About" + // A background map is 32 x 32 tiles. + // Each tile is 8 x 8 pixels. + width: 128 + height: 128 + maximumWidth: width + minimumWidth: width + maximumHeight: height + minimumHeight: height + + Text { + id: name + text: qsTr("About name") + } +} diff --git a/src/qt/main.cpp b/src/qt/main.cpp index 1e5bf58..023fb6d 100644 --- a/src/qt/main.cpp +++ b/src/qt/main.cpp @@ -1,6 +1,14 @@ #include #include +#include +#include + +void load_caml(char *argv[]) +{ + caml_main(argv); +} + int main(int argc, char *argv[]) { QApplication app(argc, argv); @@ -8,5 +16,7 @@ int main(int argc, char *argv[]) QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); + load_caml(argv); + return app.exec(); } diff --git a/src/qt/main.qml b/src/qt/main.qml index 568df8c..1d7f72e 100644 --- a/src/qt/main.qml +++ b/src/qt/main.qml @@ -35,6 +35,18 @@ ApplicationWindow { } } + Menu { + title: qsTr("Help") + MenuItem { + text: qsTr("About") + onTriggered: { + var component = Qt.createComponent("About.qml") + var about = component.createObject(root) + about.show() + } + } + } + } MainForm { diff --git a/src/qt/oboy.pro b/src/qt/oboy.pro index 0b0dfb7..b0433a6 100644 --- a/src/qt/oboy.pro +++ b/src/qt/oboy.pro @@ -6,6 +6,12 @@ CONFIG += c++11 SOURCES += main.cpp +# `ocamlc -where` = /usr/lib/ocaml +INCLUDEPATH += /usr/lib/ocaml + +LIBS += -L/home/fabs/Code/oboy/_build/default/src/core -loboy # TODO: fix path to OCaml library +LIBS += -L/usr/lib/ocaml -lm -ldl -lasmrun # /usr/lib/ocaml/Makefile.config | grep NATIVECCLIBS + RESOURCES += qml.qrc # Additional import path used to resolve QML modules in Qt Creator's code model diff --git a/src/qt/qml.qrc b/src/qt/qml.qrc index 5cb382a..44a9dba 100644 --- a/src/qt/qml.qrc +++ b/src/qt/qml.qrc @@ -4,5 +4,6 @@ MainForm.ui.qml BackgroundMap.qml BackgroundMapForm.ui.qml + About.qml