Add .clang-format
This commit is contained in:
parent
90526946e6
commit
20041deef5
6
src/qt/.clang-format
Normal file
6
src/qt/.clang-format
Normal file
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
BasedOnStyle: Mozilla
|
||||
IndentWidth: 4
|
||||
TabWidth: 4
|
||||
ColumnLimit: 100
|
||||
UseTab: ForIndentation
|
|
@ -8,7 +8,8 @@
|
|||
|
||||
#include <caml/callback.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
int
|
||||
main(int argc, char* argv[])
|
||||
{
|
||||
QCoreApplication::setApplicationName("OBoy");
|
||||
QCoreApplication::setOrganizationName("ffreling");
|
||||
|
|
|
@ -4,15 +4,16 @@
|
|||
#include <QUrl>
|
||||
#include <QtGlobal>
|
||||
|
||||
#include <caml/mlvalues.h>
|
||||
#include <caml/callback.h>
|
||||
#include <caml/alloc.h>
|
||||
#include <caml/bigarray.h>
|
||||
#include <caml/callback.h>
|
||||
#include <caml/memory.h>
|
||||
#include <caml/misc.h>
|
||||
#include <caml/mlvalues.h>
|
||||
#include <caml/osdeps.h>
|
||||
|
||||
OBoy::OBoy(QObject *parent) : QObject(parent)
|
||||
OBoy::OBoy(QObject* parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
const QStringList args = QCoreApplication::arguments();
|
||||
if (args.size() > 1) {
|
||||
|
@ -21,8 +22,10 @@ OBoy::OBoy(QObject *parent) : QObject(parent)
|
|||
}
|
||||
}
|
||||
|
||||
value *fetch_caml_callback(const char *name) {
|
||||
value * closure_f = caml_named_value(name);
|
||||
value*
|
||||
fetch_caml_callback(const char* name)
|
||||
{
|
||||
value* closure_f = caml_named_value(name);
|
||||
if (closure_f == nullptr) {
|
||||
qFatal("Cannot find OCaml function: %s", name);
|
||||
}
|
||||
|
@ -32,41 +35,45 @@ value *fetch_caml_callback(const char *name) {
|
|||
// https://caml.inria.fr/pub/docs/manual-ocaml/intfc.html
|
||||
// http://www.mega-nerd.com/erikd/Blog/CodeHacking/Ocaml/calling_ocaml.html
|
||||
|
||||
QString OBoy::name() const
|
||||
QString
|
||||
OBoy::name() const
|
||||
{
|
||||
CAMLparam0();
|
||||
|
||||
static value * closure_f = fetch_caml_callback("oboy_name");
|
||||
static value* closure_f = fetch_caml_callback("oboy_name");
|
||||
if (closure_f == nullptr) {
|
||||
CAMLdrop;
|
||||
return QString("<Unreachable>");
|
||||
}
|
||||
|
||||
const char *str = String_val(caml_callback(*closure_f, Val_unit));
|
||||
const char* str = String_val(caml_callback(*closure_f, Val_unit));
|
||||
CAMLdrop;
|
||||
return QString(str);
|
||||
}
|
||||
|
||||
QString OBoy::version() const
|
||||
QString
|
||||
OBoy::version() const
|
||||
{
|
||||
CAMLparam0();
|
||||
|
||||
static value * closure_f = fetch_caml_callback("oboy_version");
|
||||
static value* closure_f = fetch_caml_callback("oboy_version");
|
||||
if (closure_f == nullptr) {
|
||||
CAMLdrop;
|
||||
return QString("<Unreachable>");
|
||||
}
|
||||
|
||||
const char *str = String_val(caml_callback(*closure_f, Val_unit));
|
||||
const char* str = String_val(caml_callback(*closure_f, Val_unit));
|
||||
CAMLdrop;
|
||||
return QString(str);
|
||||
}
|
||||
|
||||
bool OBoy::load(const QUrl &path) {
|
||||
bool
|
||||
OBoy::load(const QUrl& path)
|
||||
{
|
||||
CAMLparam0();
|
||||
CAMLlocal1(ocaml_path) ;
|
||||
CAMLlocal1(ocaml_path);
|
||||
|
||||
static value * closure_f = fetch_caml_callback("oboy_load");
|
||||
static value* closure_f = fetch_caml_callback("oboy_load");
|
||||
if (closure_f == nullptr) {
|
||||
CAMLdrop;
|
||||
return false;
|
||||
|
@ -83,25 +90,27 @@ bool OBoy::load(const QUrl &path) {
|
|||
return _loaded;
|
||||
}
|
||||
|
||||
bool OBoy::loaded() const
|
||||
bool
|
||||
OBoy::loaded() const
|
||||
{
|
||||
return _loaded;
|
||||
}
|
||||
|
||||
QImage OBoy::backgroundMap(int index) const
|
||||
QImage
|
||||
OBoy::backgroundMap(int index) const
|
||||
{
|
||||
CAMLparam0();
|
||||
CAMLlocal1(ocaml_index);
|
||||
ocaml_index = index;
|
||||
|
||||
static value * closure_f = fetch_caml_callback("oboy_bg_map");
|
||||
static value* closure_f = fetch_caml_callback("oboy_bg_map");
|
||||
if (closure_f == nullptr) {
|
||||
CAMLdrop;
|
||||
return QImage(0, 0, QImage::Format_Indexed8);
|
||||
}
|
||||
|
||||
const auto bg_array = Caml_ba_array_val(caml_callback(*closure_f, Val_int(ocaml_index)));
|
||||
const auto bg_raw_data = static_cast<caml_ba_uint8 *>(bg_array->data);
|
||||
const auto bg_raw_data = static_cast<caml_ba_uint8*>(bg_array->data);
|
||||
|
||||
Q_ASSERT(bg_array->num_dims == 2);
|
||||
Q_ASSERT(bg_array->flags & CAML_BA_UINT8);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QImage>
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
|
||||
class OBoy : public QObject
|
||||
|
@ -10,18 +10,18 @@ class OBoy : public QObject
|
|||
Q_PROPERTY(QString name READ name CONSTANT)
|
||||
Q_PROPERTY(QString version READ version CONSTANT)
|
||||
Q_PROPERTY(bool loaded READ loaded NOTIFY loadedChanged)
|
||||
public:
|
||||
explicit OBoy(QObject *parent = nullptr);
|
||||
public:
|
||||
explicit OBoy(QObject* parent = nullptr);
|
||||
|
||||
QString name() const;
|
||||
QString version() const;
|
||||
bool loaded() const;
|
||||
Q_INVOKABLE bool load(const QUrl &path);
|
||||
Q_INVOKABLE bool load(const QUrl& path);
|
||||
QImage backgroundMap(int index) const;
|
||||
|
||||
signals:
|
||||
signals:
|
||||
void loadedChanged(bool loaded);
|
||||
|
||||
private:
|
||||
private:
|
||||
bool _loaded = false;
|
||||
};
|
||||
|
|
|
@ -1,17 +1,16 @@
|
|||
#include "oimageprovider.h"
|
||||
#include "oboy.h"
|
||||
|
||||
OImageProvider::OImageProvider(QQmlApplicationEngine &engine)
|
||||
OImageProvider::OImageProvider(QQmlApplicationEngine& engine)
|
||||
: QQuickImageProvider(QQuickImageProvider::Image)
|
||||
, _engine(engine)
|
||||
{
|
||||
{}
|
||||
|
||||
}
|
||||
|
||||
QImage OImageProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize)
|
||||
QImage
|
||||
OImageProvider::requestImage(const QString& id, QSize* size, const QSize& requestedSize)
|
||||
{
|
||||
QList<QObject*> roots = _engine.rootObjects();
|
||||
OBoy *oboy = roots[0]->findChild<OBoy*>("qml_oboy");
|
||||
OBoy* oboy = roots[0]->findChild<OBoy*>("qml_oboy");
|
||||
if (!oboy) {
|
||||
qFatal("Cannot find oboy instance.");
|
||||
}
|
||||
|
|
|
@ -5,10 +5,10 @@
|
|||
|
||||
class OImageProvider : public QQuickImageProvider
|
||||
{
|
||||
public:
|
||||
OImageProvider(QQmlApplicationEngine &engine);
|
||||
QImage requestImage(const QString &id, QSize *size, const QSize &requestedSize) override;
|
||||
public:
|
||||
OImageProvider(QQmlApplicationEngine& engine);
|
||||
QImage requestImage(const QString& id, QSize* size, const QSize& requestedSize) override;
|
||||
|
||||
private:
|
||||
QQmlApplicationEngine &_engine;
|
||||
private:
|
||||
QQmlApplicationEngine& _engine;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue