rename dir
This commit is contained in:
23
doric-Qt/doric/native/native_bridge.cpp
Normal file
23
doric-Qt/doric/native/native_bridge.cpp
Normal file
@@ -0,0 +1,23 @@
|
||||
#include "context_manager.h"
|
||||
#include "native_bridge.h"
|
||||
#include "plugin/shader_plugin.h"
|
||||
|
||||
Q_INVOKABLE void NativeBridge::function(int contextId, QString module, QString methodName, QString callbackId, QJSValue jsValue) {
|
||||
qDebug() << "contextId: " + QString::number(contextId) + ", " +
|
||||
"module: " + module + ", " +
|
||||
"methodName: " + methodName + ", " +
|
||||
"callbackId: " + callbackId + ", " +
|
||||
"arguments: " + jsValue.toString();
|
||||
Context *context = ContextManager::getInstance()->getContext(contextId);
|
||||
QString value = context->driver->getRegistry()->acquirePluginInfo(module);
|
||||
|
||||
qDebug() << value;
|
||||
if (value.contains("ShaderPlugin")) {
|
||||
ShaderPlugin shaderPlugin(context);
|
||||
QMetaObject::invokeMethod(
|
||||
&shaderPlugin,
|
||||
methodName.toStdString().c_str(),
|
||||
Qt::AutoConnection,
|
||||
Q_ARG(QJSValue, jsValue));
|
||||
}
|
||||
}
|
16
doric-Qt/doric/native/native_bridge.h
Normal file
16
doric-Qt/doric/native/native_bridge.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#ifndef NATIVE_BRIDGE_H
|
||||
#define NATIVE_BRIDGE_H
|
||||
|
||||
#include <QJSValue>
|
||||
#include <QObject>
|
||||
|
||||
class NativeBridge : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
NativeBridge(QObject *parent = nullptr) : QObject(parent) {}
|
||||
|
||||
Q_INVOKABLE void function(int contextId, QString module, QString methodName, QString callbackId, QJSValue jsValue);
|
||||
};
|
||||
|
||||
#endif // NATIVE_BRIDGE_H
|
7
doric-Qt/doric/native/native_empty.cpp
Normal file
7
doric-Qt/doric/native/native_empty.cpp
Normal file
@@ -0,0 +1,7 @@
|
||||
#include <QDebug>
|
||||
|
||||
#include "native_empty.h"
|
||||
|
||||
Q_INVOKABLE void NativeEmpty::function() {
|
||||
qDebug() << "nativeEmpty";
|
||||
}
|
15
doric-Qt/doric/native/native_empty.h
Normal file
15
doric-Qt/doric/native/native_empty.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef NATIVE_EMPTY_H
|
||||
#define NATIVE_EMPTY_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class NativeEmpty : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
NativeEmpty(QObject *parent = nullptr) : QObject(parent) {}
|
||||
|
||||
Q_INVOKABLE void function();
|
||||
};
|
||||
|
||||
#endif // NATIVE_EMPTY_H
|
13
doric-Qt/doric/native/native_log.cpp
Normal file
13
doric-Qt/doric/native/native_log.cpp
Normal file
@@ -0,0 +1,13 @@
|
||||
#include <QDebug>
|
||||
|
||||
#include "native_log.h"
|
||||
|
||||
Q_INVOKABLE void NativeLog::function(QString level, QString content) {
|
||||
if (level == 'w') {
|
||||
qWarning() << content;
|
||||
} else if (level == 'd') {
|
||||
qDebug() << content;
|
||||
} else if (level == 'e') {
|
||||
qCritical() << content;
|
||||
}
|
||||
}
|
15
doric-Qt/doric/native/native_log.h
Normal file
15
doric-Qt/doric/native/native_log.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef NATIVELOG_H
|
||||
#define NATIVELOG_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class NativeLog : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
NativeLog(QObject *parent = nullptr) : QObject(parent) {}
|
||||
|
||||
Q_INVOKABLE void function(QString level, QString content);
|
||||
};
|
||||
|
||||
#endif // NATIVELOG_H
|
30
doric-Qt/doric/native/native_timer.cpp
Normal file
30
doric-Qt/doric/native/native_timer.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#include <QTimer>
|
||||
|
||||
#include "native_timer.h"
|
||||
|
||||
Q_INVOKABLE void NativeTimer::setTimer(long timerId, int time, bool repeat) {
|
||||
QTimer *timer = new QTimer(this);
|
||||
timer->setSingleShot(!repeat);
|
||||
connect(timer, &QTimer::timeout, this, [=] () {
|
||||
if (deletedTimerIds->contains(timerId)) {
|
||||
deletedTimerIds->remove(timerId);
|
||||
delete timer;
|
||||
} else {
|
||||
engine->evaluate(
|
||||
Constant::GLOBAL_DORIC + "." +
|
||||
Constant::DORIC_TIMER_CALLBACK + "(" +
|
||||
QString::number(timerId) + ")"
|
||||
);
|
||||
|
||||
if (!repeat) {
|
||||
deletedTimerIds->remove(timerId);
|
||||
delete timer;
|
||||
}
|
||||
}
|
||||
});
|
||||
timer->start(time);
|
||||
}
|
||||
|
||||
void NativeTimer::clearTimer(long timerId) {
|
||||
deletedTimerIds->insert(timerId);
|
||||
}
|
27
doric-Qt/doric/native/native_timer.h
Normal file
27
doric-Qt/doric/native/native_timer.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#ifndef NATIVE_TIMER_H
|
||||
#define NATIVE_TIMER_H
|
||||
|
||||
#include <QJSEngine>
|
||||
#include <QObject>
|
||||
#include <QSet>
|
||||
|
||||
#include "constant.h"
|
||||
|
||||
class NativeTimer : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
QSet<long> *deletedTimerIds = new QSet<long>();
|
||||
QJSEngine *engine;
|
||||
|
||||
public:
|
||||
NativeTimer(QJSEngine *engine, QObject *parent = nullptr) : QObject(parent) {
|
||||
this->engine = engine;
|
||||
}
|
||||
|
||||
Q_INVOKABLE void setTimer(long timerId, int time, bool repeat);
|
||||
|
||||
Q_INVOKABLE void clearTimer(long timerId);
|
||||
|
||||
};
|
||||
#endif // NATIVE_TIMER_H
|
Reference in New Issue
Block a user