Skip to content

Commit

Permalink
qml-box2d#97 moved shared to a plugin called Box2d.Components. qml-b…
Browse files Browse the repository at this point in the history
…ox2d#108 Added qmltypes to make system for Qml tooling. qml-box2d#109 Added qrc file for common icons and removed doubles. qml-box2d#110 Added a example applicaiton that makes it so one can test out all the exmaples without qmlscence. qml-box2d#111 made all examples install to qt's example dir in prep for docs and better stucture, qml-box2d#112 , qml-box2d#13 Set up stucture and role back point for qt-ish style of libs and plugins,
  • Loading branch information
JosephMillsAtWork committed Sep 20, 2016
1 parent 1b37be7 commit c96b1f2
Show file tree
Hide file tree
Showing 203 changed files with 5,159 additions and 3,415 deletions.
42 changes: 0 additions & 42 deletions README

This file was deleted.

70 changes: 70 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
## QML Box2D plugin
----------------

This plugin is meant to be installed to your Qt/imports directory, or shipped
in a directory of which the parent is added as import path.

The goal is to expose the functionality of Box2D as QML components, in order
to make it easy to write physics based games in QML.


#### INSTALLING
-----------

If running into permissions issues please use sudo with sudo if necessary

By default everything gets insalled to your qt examples and plugin directory's

```bash
qmake
make
make install
```


#### RUNNING THE EXAMPLES
-----------

After building all the examples will be located in your $$[QT_INSTALL_EXAMPLE]
directory. But one can also use qtcreator to pick which example they would like
to run. See the section below [using qt creator](#USING-QT-CREATOR)


#### DEPLOYMENT
-----------

Support for deployment to mobile devices like the N900 and N8 is being worked
on.


#### USING QT CREATOR
-----------

Open the box2d pro file and selcet which example project you would like to run
note there is a all-examples example applicaiton that allows one to view all
the examples.

When you have write permissions to Qt's import path, it can be convenient to
add a deployment step to your run settings:

* Go to Projects -> box2d -> Run Settings
* Choose Add Deploy Step -> Make
* Enter "install" under "Make arguments"

This will make sure that before running, the version of the plugin is updated
in Qt's import path.


#### OPTIONAL QML TOOLING
-----------

If you would like to get Syntax highlighting for the Qml Elements/Objects

* Go to Projects -> box2d -> Run Settings
* Choose Add Deploy Step -> Make
* Enter "qmltypes" under "Make arguments"


#### DOCS
-----------
Coming soon.
49 changes: 17 additions & 32 deletions box2d.pro
Original file line number Diff line number Diff line change
@@ -1,32 +1,17 @@
TEMPLATE = lib
CONFIG += plugin
QT += quick
TARGET = $$qtLibraryTarget(Box2D)
TARGETPATH = Box2D
API_VER=2.0
MOC_DIR = .moc
OBJECTS_DIR = .obj

contains(QT_CONFIG, reduce_exports): CONFIG += hide_symbols

# Uncomment the line below to compile qml-box2d plugin with Box2D library, installed in OS
# or pass the variable to qmake in command line:
# qmake DEFINES+=BOX2D_SYSTEM
# Warning: Box2D library must be already installed in system, for example in Debian it could be done with:
# sudo apt-get install libbox2d-dev

#DEFINES += BOX2D_SYSTEM

include(box2d_lib.pri)
include(examples/examples.pri)

importPath = $$[QT_INSTALL_QML]/$$replace(TARGETPATH, \\., /).$$API_VER
target.path = $${importPath}

qmldir.path = $${importPath}
qmldir.files += $$PWD/qmldir


INSTALLS += target qmldir


TEMPLATE = subdirs
CONFIG += ordered
SUBDIRS += \
$$PWD/src/box2d.pro \
$$PWD/src/Components \
$$PWD/examples/examples.pro

OTHER_FILES += \
$$PWD/box2d_lib.pri \
$$PWD/box2d.qbs \
$$PWD/box2d-static.pri \
$$PWD/COPYING \
$$PWD/README.md \
$$PWD/debian/changelog \
$$PWD/debian/compat \
$$PWD/debian/control \
$$PWD/debian/rules
8 changes: 4 additions & 4 deletions box2d.qbs
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@ Project {
name: "box2d"
files: ["Box2D/*.h", "Box2D/*/*.h", "Box2D/*/*/*.h", "Box2D/*.cpp", "Box2D/*/*.cpp", "Box2D/*/*/*.cpp"]
Depends { name: "cpp" }
cpp.includePaths: ["Box2D", "."]
cpp.includePaths: ["Box2D", "src", "src/Components"]

Group { qbs.install: true; fileTagsFilter: product.type;}
}

DynamicLibrary {
name: "box2d_lib"
files: ["*.h", "*.cpp"]
files: ["*.h", "*.cpp" , "*.qml"]
Depends { name: "cpp" }
Depends { name: "box2d" }
Depends { name: "Qt"; submodules: ["core", "qml", "quick"]; }
cpp.includePaths: ["Box2D", "."]
cpp.includePaths: ["Box2D", "src", "src/Components"]

Group { qbs.install: true; fileTagsFilter: product.type;}

Export {
Depends { name: "cpp" }
cpp.includePaths: "."
cpp.includePaths: ["src", "src/Components"]
}
}
}
Expand Down
42 changes: 0 additions & 42 deletions box2d_lib.pri
Original file line number Diff line number Diff line change
Expand Up @@ -18,45 +18,3 @@ contains(DEFINES, BOX2D_SYSTEM) {
} else {
include(Box2D/box2d.pri)
}

SOURCES += \
$$PWD/box2dplugin.cpp \
$$PWD/box2dworld.cpp \
$$PWD/box2dcontact.cpp \
$$PWD/box2dbody.cpp \
$$PWD/box2dfixture.cpp \
$$PWD/box2ddebugdraw.cpp \
$$PWD/box2djoint.cpp \
$$PWD/box2ddistancejoint.cpp \
$$PWD/box2dprismaticjoint.cpp \
$$PWD/box2drevolutejoint.cpp \
$$PWD/box2dmotorjoint.cpp \
$$PWD/box2dweldjoint.cpp \
$$PWD/box2dpulleyjoint.cpp \
$$PWD/box2dfrictionjoint.cpp \
$$PWD/box2dwheeljoint.cpp \
$$PWD/box2dmousejoint.cpp \
$$PWD/box2dgearjoint.cpp \
$$PWD/box2dropejoint.cpp \
$$PWD/box2draycast.cpp

HEADERS += \
$$PWD/box2dplugin.h \
$$PWD/box2dworld.h \
$$PWD/box2dcontact.h \
$$PWD/box2dbody.h \
$$PWD/box2dfixture.h \
$$PWD/box2ddebugdraw.h \
$$PWD/box2djoint.h \
$$PWD/box2ddistancejoint.h \
$$PWD/box2dprismaticjoint.h \
$$PWD/box2drevolutejoint.h \
$$PWD/box2dmotorjoint.h \
$$PWD/box2dweldjoint.h \
$$PWD/box2dpulleyjoint.h \
$$PWD/box2dfrictionjoint.h \
$$PWD/box2dwheeljoint.h \
$$PWD/box2dmousejoint.h \
$$PWD/box2dgearjoint.h \
$$PWD/box2dropejoint.h \
$$PWD/box2draycast.h
4 changes: 2 additions & 2 deletions examples/accelerometer/WoodenBox.qml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import QtQuick 2.0
import Box2D 2.0
import "../shared"
import Box2D.Components 1.0

PhysicsItem {
id: box
Expand All @@ -18,5 +18,5 @@ PhysicsItem {
restitution: 0.5
}

Image { anchors.fill: parent; source: "woodenbox.png" }
Image { anchors.fill: parent; source: "qrc:/images/woodenbox.png" }
}
17 changes: 17 additions & 0 deletions examples/accelerometer/accelerometer.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
TEMPLATE = app

QT += qml quick
CONFIG += c++11

SOURCES += main.cpp

RESOURCES += qml.qrc \
$$PWD/../images/example-images.qrc

# Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH =

target.path = $$[QT_INSTALL_EXAMPLES]/Box2D/$${TARGET}/
export(target.path)
INSTALLS += target
export(INSTALLS)
73 changes: 40 additions & 33 deletions examples/accelerometer/accelerometer.qml
Original file line number Diff line number Diff line change
@@ -1,46 +1,53 @@
import QtQuick 2.0
import Box2D 2.0
import QtQuick.Window 2.0
import QtSensors 5.0
import "../shared"

Image {
id: screen
import Box2D 2.0
import Box2D.Components 1.0

Window{
visible: true
width: 640
height: 480

source: "background.png"

World { id: physicsWorld }

Repeater {
model: 3
delegate: WoodenBox {
x: Math.random() * (screen.width - 100);
y: Math.random() * (screen.height / 3);
rotation: Math.random() * 90;
title: "Accelerometer Example"
Image {
id: screen
width: parent.width
height: parent.height

source: "qrc:/images/background.png"

World { id: physicsWorld }

Repeater {
model: 3
delegate: WoodenBox {
x: Math.random() * (screen.width - 100);
y: Math.random() * (screen.height / 3);
rotation: Math.random() * 90;
}
}
}

ScreenBoundaries {}
ScreenBoundaries {}

DebugDraw {
id: debugDraw
world: physicsWorld
opacity: 0.75
visible: false
}
MouseArea {
id: debugMouseArea
anchors.fill: screen
onPressed: debugDraw.visible = !debugDraw.visible
}
DebugDraw {
id: debugDraw
world: physicsWorld
opacity: 0.75
visible: false
}
MouseArea {
id: debugMouseArea
anchors.fill: screen
onPressed: debugDraw.visible = !debugDraw.visible
}

Accelerometer {
Component.onCompleted: start()
onReadingChanged: {
var r = reading;
physicsWorld.gravity = Qt.point(r.x, r.y);
Accelerometer {
Component.onCompleted: start()
onReadingChanged: {
var r = reading;
physicsWorld.gravity = Qt.point(r.x, r.y);
}
}
}
}
9 changes: 1 addition & 8 deletions examples/main.cpp → examples/accelerometer/main.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QDebug>
#include <QtQml>
#include <box2dplugin.h>

int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);

Box2DPlugin plugin;
plugin.registerTypes("Box2D");

QQmlApplicationEngine engine;
engine.load(QUrl("qrc:/ui.qml"));
engine.load(QUrl(QStringLiteral("qrc:/accelerometer.qml")));

return app.exec();
}

6 changes: 6 additions & 0 deletions examples/accelerometer/qml.qrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<RCC>
<qresource prefix="/">
<file>WoodenBox.qml</file>
<file>accelerometer.qml</file>
</qresource>
</RCC>
Loading

0 comments on commit c96b1f2

Please sign in to comment.