Warning, /education/gcompris/external/qml-box2d/examples/mouse/main.qml is written in an unsupported language. File is not indexed.
0001 import QtQuick 2.2 0002 import Box2D 2.0 0003 import "../shared" 0004 0005 Rectangle { 0006 width: 800 0007 height: 600 0008 0009 property Body pressedBody: null 0010 0011 function randomColor() { 0012 return Qt.rgba(Math.random(), Math.random(), Math.random(), Math.random()); 0013 } 0014 0015 MouseJoint { 0016 id: mouseJoint 0017 bodyA: anchor 0018 dampingRatio: 0.8 0019 maxForce: 100 0020 } 0021 0022 MouseArea { 0023 id: mouseArea 0024 anchors.fill: parent 0025 0026 onPressed: { 0027 if (pressedBody != null) { 0028 mouseJoint.maxForce = pressedBody.getMass() * 500; 0029 mouseJoint.target = Qt.point(mouseX, mouseY); 0030 mouseJoint.bodyB = pressedBody; 0031 } 0032 } 0033 0034 onPositionChanged: { 0035 mouseJoint.target = Qt.point(mouseX, mouseY); 0036 } 0037 0038 onReleased: { 0039 mouseJoint.bodyB = null; 0040 pressedBody = null; 0041 } 0042 } 0043 0044 World { id: physicsWorld } 0045 0046 RectangleBoxBody { 0047 id: ground 0048 color: "#DEDEDE" 0049 height: 40 0050 anchors { 0051 left: parent.left 0052 right: parent.right 0053 bottom: parent.bottom 0054 } 0055 world: physicsWorld 0056 friction: 1 0057 density: 1 0058 } 0059 0060 Wall { 0061 id: topWall 0062 height: 40 0063 anchors { 0064 left: parent.left 0065 right: parent.right 0066 top: parent.top 0067 } 0068 } 0069 0070 Wall { 0071 id: leftWall 0072 width: 40 0073 anchors { 0074 left: parent.left 0075 top: parent.top 0076 bottom: parent.bottom 0077 bottomMargin: 40 0078 } 0079 } 0080 0081 Wall { 0082 id: rightWall 0083 width: 40 0084 anchors { 0085 right: parent.right 0086 top: parent.top 0087 bottom: parent.bottom 0088 bottomMargin: 40 0089 } 0090 } 0091 0092 Body { 0093 id: anchor 0094 world: physicsWorld 0095 } 0096 0097 Repeater { 0098 model: 20 0099 Rectangle { 0100 id: rectangle 0101 0102 x: 40 + Math.random() * 720 0103 y: 40 + Math.random() * 520 0104 width: 20 + Math.random() * 100 0105 height: 20 + Math.random() * 100 0106 rotation: Math.random() * 360 0107 color: randomColor() 0108 border.color: randomColor() 0109 smooth: true 0110 0111 Body { 0112 id: rectangleBody 0113 0114 target: rectangle 0115 world: physicsWorld 0116 bodyType: Body.Dynamic 0117 0118 Box { 0119 width: rectangle.width 0120 height: rectangle.height 0121 density: 0.5 0122 restitution: 0.5 0123 friction: 0.5 0124 } 0125 } 0126 0127 MouseArea { 0128 anchors.fill: parent 0129 propagateComposedEvents: true 0130 onPressed: { 0131 mouse.accepted = false; 0132 pressedBody = rectangleBody; 0133 } 0134 } 0135 } 0136 } 0137 0138 Rectangle { 0139 id: debugButton 0140 x: 50 0141 y: 50 0142 width: 120 0143 height: 30 0144 Text { 0145 text: debugDraw.visible ? "Debug view: on" : "Debug view: off" 0146 anchors.centerIn: parent 0147 } 0148 color: "#DEDEDE" 0149 border.color: "#999" 0150 radius: 5 0151 MouseArea { 0152 anchors.fill: parent 0153 onClicked: debugDraw.visible = !debugDraw.visible; 0154 } 0155 } 0156 0157 DebugDraw { 0158 id: debugDraw 0159 world: physicsWorld 0160 opacity: 0.75 0161 visible: false 0162 } 0163 }