diff --git a/src/activities/activities.txt b/src/activities/activities.txt index f3d17f4fc..f020a5005 100644 --- a/src/activities/activities.txt +++ b/src/activities/activities.txt @@ -1,122 +1,123 @@ # The list of activities that will be loaded at GCompris start. # Keep it sorted advanced_colors algebra_by algebra_div algebra_minus algebra_plus algorithm align4 align4-2players alphabet-sequence babymatch babyshapes baby_wordprocessor balancebox ballcatch braille_alphabets braille_fun canal_lock chess chess_2players chess_partyend chronos clickanddraw clickgame click_on_letter click_on_letter_up clockgame color_mix color_mix_light colors details drawnumber enumerate erase erase_2clic erase_clic explore_farm_animals explore_monuments explore_world_animals explore_world_music fifteen followline football geo-country geography gletters gnumch-equality gnumch-factors gnumch-inequality gnumch-multiples gnumch-primes graph-coloring guessnumber hangman hanoi hanoi_real hexagon imagename instruments intro_gravity lang leftright lightsoff louis-braille magic-hat-minus magic-hat-plus maze mazeinvisible mazerelative melody memory memory-enumerate memory-math-add memory-math-add-minus memory-math-add-minus-mult-div memory-math-add-minus-mult-div-tux memory-math-add-minus-tux memory-math-add-tux memory-math-div memory-math-div-tux memory-math-minus memory-math-minus-tux memory-math-mult memory-math-mult-div memory-math-mult-div-tux memory-math-mult-tux memory-sound memory-sound-tux memory-tux memory-wordnumber mining missing-letter money money_back money_back_cents money_cents mosaic numbers-odd-even paintings penalty planegame readingh readingv redraw redraw_symmetrical renewable_energy reversecount scalesboard scalesboard_weight scalesboard_weight_avoirdupois simplepaint smallnumbers smallnumbers2 sudoku superbrain +tangram target tic_tac_toe tic_tac_toe_2players traffic watercycle wordsgame diff --git a/tools/menus/tangram.qml b/src/activities/tangram/ActivityInfo.qml similarity index 99% rename from tools/menus/tangram.qml rename to src/activities/tangram/ActivityInfo.qml index 0dbd9c6f6..bc653f0a2 100644 --- a/tools/menus/tangram.qml +++ b/src/activities/tangram/ActivityInfo.qml @@ -1,39 +1,39 @@ /* GCompris - ActivityInfo.qml * * Copyright (C) 2015 Your Name * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see . */ import GCompris 1.0 ActivityInfo { name: "tangram/Tangram.qml" - difficulty: 1 + difficulty: 3 icon: "tangram/tangram.svg" author: "Yves Combe / Philippe Banwarth" demo: true title: qsTr("The tangram puzzle game") description: qsTr("The objective is to form a given shape with seven pieces") goal: qsTr("From Wikipedia, the free encyclopedia. Tangram (Chinese: literally 'seven boards of cunning') is a Chinese puzzle. While the tangram is often said to be ancient, its existence has only been verified as far back as 1800. It consists of 7 pieces, called tans, which fit together to form a square; taking the square as the unit: * 5 right isosceles triangles o 2 small (legs of 1) o 1 medium size (legs of square root of 2) o 2 large size (legs of 2) * 1 square (side of 1) * 1 parallelogram (sides of 1 and square root of 2)") prerequisite: qsTr("Mouse-manipulation") manual: qsTr("Select the tangram to form. Move a piece by dragging it. Right-click on it to create a symmetrical item. Select an item and drag around it to show the rotation you want. Once you've shown what shape you want, the computer will create it. If you need help, click on the shape button, and the border of the shape will be drawn.") credit: qsTr("The original code was written by Philippe Banwarth in 1999. It was ported to GCompris by Yves Combe in 2005.") section: "/puzzle" } diff --git a/src/activities/tangram/CMakeLists.txt b/src/activities/tangram/CMakeLists.txt new file mode 100644 index 000000000..965440ec6 --- /dev/null +++ b/src/activities/tangram/CMakeLists.txt @@ -0,0 +1 @@ +GCOMPRIS_ADD_RCC(activities/tangram *.qml *.svg *.js resource/*) diff --git a/src/activities/tangram/Tangram.qml b/src/activities/tangram/Tangram.qml new file mode 100644 index 000000000..6dce4faaa --- /dev/null +++ b/src/activities/tangram/Tangram.qml @@ -0,0 +1,201 @@ +/* GCompris - tangram.qml + * + * Copyright (C) 2015 Bruno Coudoin + * + * Authors: + * Yves Combe / Philippe Banwarth (GTK+ version) + * Bruno Coudoin (Qt Quick port) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ +import QtQuick 2.1 +import QtGraphicalEffects 1.0 +import GCompris 1.0 + +import "../../core" +import "tangram.js" as Activity + +ActivityBase { + id: activity + + onStart: focus = true + onStop: {} + + pageComponent: Image { + id: background + anchors.fill: parent + signal start + signal stop + fillMode: Image.PreserveAspectCrop + source: Activity.url + "background.svg" + sourceSize.width: parent.width + + + Component.onCompleted: { + activity.start.connect(start) + activity.stop.connect(stop) + } + + onWidthChanged: { + for(var i=0; i < itemList.model; i++) { + itemList.itemAt(i).positionMe() + } + } + + onHeightChanged: { + for(var i=0; i < itemList.model; i++) { + itemList.itemAt(i).positionMe() + } + } + + // Add here the QML items you need to access in javascript + QtObject { + id: items + property Item main: activity.main + property alias background: background + property alias bar: bar + property alias bonus: bonus + property alias itemListModel: itemList.model + property Item selected + } + + onStart: { + Activity.start(items) + } + onStop: { Activity.stop() } + + MouseArea { + id: rotateArea + anchors.fill: parent + enabled: items.selected + property double prevRotation: 0 + onPositionChanged: { + // Calc the angle touch / object center + var rotation = Activity.getAngleOfLineBetweenTwoPoints( + items.selected.x + items.selected.width / 2, items.selected.y + items.selected.height / 2, + mouseX, mouseY) * (180 / Math.PI) + if(prevRotation) { + items.selected.rotation += rotation - prevRotation + } + prevRotation = rotation + } + onReleased: { + prevRotation = 0 + // Force a modulo 5 rotation + items.selected.rotation = items.selected.rotation + (items.selected.rotation + 2.5) % 5 + } + } + + DropArea { + id: dropableArea + anchors.left: background.left + anchors.bottom: background.bottom + width: background.width + height: background.height + } + + Repeater { + id: itemList + Image { + id: tans + // Let the items comes from random side of the screen + x: Math.random() > 0.5 ? - width : background.width + y: Math.random() > 0.5 ? - height : background.height + source: Activity.url + 'triangle.svg' + sourceSize.width: 200 + z: 0 + + property real xRatio + property real yRatio + property bool selected: false + + Component.onCompleted: { + xRatio = Activity.getRandomInt(10, background.width - 220 * ApplicationInfo.ratio) / + (background.width - 220 * ApplicationInfo.ratio) + yRatio = Activity.getRandomInt(10, background.height - 180 * ApplicationInfo.ratio) / + (background.height - 180 * ApplicationInfo.ratio) + positionMe() + } + + function positionMe() { + x = (background.width - 220 * ApplicationInfo.ratio) * xRatio + y = (background.height- 180 * ApplicationInfo.ratio) * yRatio + } + + Drag.active: dragArea.drag.active + Drag.hotSpot.x : width / 2 + Drag.hotSpot.y : height / 2 + + MouseArea { + id: dragArea + anchors.fill: parent + drag.target: parent + onPressed: { + parent.z = ++Activity.globalZ + if(items.selected) + items.selected.selected = false + items.selected = tans + parent.selected = true + } + onReleased: parent.Drag.drop() + } + + Colorize { + id: color + anchors.fill: parent + source: parent + hue: 0.6 + lightness: -0.2 + saturation: 0.5 + opacity: parent.selected ? 1 : 0 + } + Behavior on x { + PropertyAnimation { + duration: 2000 + easing.type: Easing.InOutQuad + } + } + Behavior on y { + PropertyAnimation { + duration: 2000 + easing.type: Easing.InOutQuad + } + } + } + } + + + DialogHelp { + id: dialogHelp + onClose: home() + } + + Bar { + id: bar + content: BarEnumContent { value: help | home | level } + onHelpClicked: { + displayDialog(dialogHelp) + } + onPreviousLevelClicked: Activity.previousLevel() + onNextLevelClicked: Activity.nextLevel() + onHomeClicked: activity.home() + } + + Bonus { + id: bonus + Component.onCompleted: win.connect(Activity.nextLevel) + } + } + +} diff --git a/src/activities/tangram/resource/background.svg b/src/activities/tangram/resource/background.svg new file mode 100644 index 000000000..053488958 --- /dev/null +++ b/src/activities/tangram/resource/background.svg @@ -0,0 +1,69 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/src/activities/tangram/resource/triangle.svg b/src/activities/tangram/resource/triangle.svg new file mode 100644 index 000000000..116457f4d --- /dev/null +++ b/src/activities/tangram/resource/triangle.svg @@ -0,0 +1,67 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/src/activities/tangram/tangram.js b/src/activities/tangram/tangram.js new file mode 100644 index 000000000..1901c8d23 --- /dev/null +++ b/src/activities/tangram/tangram.js @@ -0,0 +1,75 @@ +/* GCompris - tangram.js + * + * Copyright (C) 2015 YOUR NAME + * + * Authors: + * (GTK+ version) + * "YOUR NAME" (Qt Quick port) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ +.pragma library +.import QtQuick 2.0 as Quick + +var url = "qrc:/gcompris/src/activities/tangram/resource/" + +var currentLevel = 0 +var numberOfLevel = 4 +var items + +// We keep a globalZ across all items. It is increased on each +// item selection to put it on top +var globalZ = 0 + +function start(items_) { + items = items_ + currentLevel = 0 + initLevel() +} + +function stop() { +} + +function initLevel() { + items.bar.level = currentLevel + 1 + items.itemListModel = items.bar.level +} + +function nextLevel() { + if(numberOfLevel <= ++currentLevel ) { + currentLevel = 0 + } + initLevel(); +} + +function previousLevel() { + if(--currentLevel < 0) { + currentLevel = numberOfLevel - 1 + } + initLevel(); +} + +function getRandomInt(min, max) { + return Math.floor(Math.random() * (max - min + 1) + min); +} + +// Determines the angle of a straight line drawn between point one and two. +// The number returned, which is a float in radian, +// tells us how much we have to rotate a horizontal line clockwise +// for it to match the line between the two points. +function getAngleOfLineBetweenTwoPoints(x1, y1, x2, y2) { + var xDiff = x2 - x1; + var yDiff = y2 - y1; + return Math.atan2(yDiff, xDiff); +} diff --git a/src/activities/tangram/tangram.svg b/src/activities/tangram/tangram.svg new file mode 100644 index 000000000..40c866f75 --- /dev/null +++ b/src/activities/tangram/tangram.svg @@ -0,0 +1,140 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tools/menus/resource/tangram.svg b/tools/menus/resource/tangram.svg deleted file mode 100644 index 13769d414..000000000 --- a/tools/menus/resource/tangram.svg +++ /dev/null @@ -1,154 +0,0 @@ - - - - - - - - - - image/svg+xml - - - - - - - - - - - - - - - - - - - - - - - - - - - -