Commit 7433227a authored by Timothée Giet's avatar Timothée Giet

simplepaint, finish keyboard controls and improve a few things

parent 42142a0c
......@@ -26,7 +26,6 @@ import GCompris 1.0
Item {
id: cursor
property alias color: rectangle.color
property double ix
property double iy
property int nbx
......@@ -41,21 +40,13 @@ Item {
width: r * 2
height: r * 2
Rectangle {
id: rectangle
anchors.fill: parent
//border.width: bar.level == 1 ? 1 : 0
//border.color: "black"
}
Image {
scale: 0.9
width: rectangle.height
height: rectangle.height
sourceSize.width: rectangle.height
sourceSize.height: rectangle.height
source: Activity.url + "eraser.svg"
width: parent.height
height: parent.height
sourceSize.width: height
sourceSize.height: height
source: Activity.url + "cursor.svg"
visible: true
anchors.centerIn: parent
}
......
......@@ -39,112 +39,134 @@ ActivityBase {
signal start
signal stop
focus: true
property bool isColorTab: false
property bool isColorTab: true
property bool spaceIsPressed: false
Keys.onUpPressed: {
if(isColorTab) {
if (--items.current_color<0) {
items.current_color = items.colors.length-1
}
items.colorSelector = items.colors[items.current_color]
moveColorSelector()
}else {
if(cursor.iy>0) {
cursor.iy--
Keys.onPressed: {
items.keyboardControls = true;
if(event.key === Qt.Key_Up) {
if(isColorTab) {
if(--items.current_color < 0) {
items.current_color = items.colors.length - 1;
}
items.selectedColor = items.colors[items.current_color];
moveColorSelector();
} else {
if(cursor.iy > 0) {
cursor.iy--;
}
if(spaceIsPressed) {
spawnBlock();
}
}
}
}
Keys.onDownPressed: {
if(isColorTab) {
if (++items.current_color>items.colors.length-1){
items.current_color = 0
}
items.colorSelector = items.colors[items.current_color]
moveColorSelector()
}else {
if(cursor.iy<(Activity.nby-1)) {
cursor.iy++
if(event.key === Qt.Key_Down) {
if(isColorTab) {
if(++items.current_color > items.colors.length - 1){
items.current_color = 0;
}
items.selectedColor = items.colors[items.current_color];
moveColorSelector();
}else {
if(cursor.iy < (Activity.nby - 1)) {
cursor.iy++;
}
if(spaceIsPressed) {
spawnBlock();
}
}
}
}
Keys.onRightPressed: {
if(!isColorTab) {
if(cursor.ix<(Activity.nbx-1)) {
cursor.ix++
if(event.key === Qt.Key_Right) {
if(!isColorTab) {
if(cursor.ix < (Activity.nbx - 1)) {
cursor.ix++;
}
if(spaceIsPressed) {
spawnBlock();
}
}
}
}
Keys.onLeftPressed: {
if(!isColorTab) {
if(cursor.ix>0) {
cursor.ix--
if(event.key === Qt.Key_Left) {
if(!isColorTab) {
if(cursor.ix > 0) {
cursor.ix--;
}
if(spaceIsPressed) {
spawnBlock();
}
}
}
}
Keys.onSpacePressed: spawnBlock()
Keys.onReturnPressed: spawnBlock()
if(event.key === Qt.Key_Space || event.key === Qt.Key_Return || event.key === Qt.Key_Enter) {
if(!isColorTab) {
spawnBlock();
spaceIsPressed = true;
} else {
changeTab();
}
}
Keys.onEnterPressed: spawnBlock()
if(event.key === Qt.Key_Tab) {
changeTab();
}
}
Keys.onTabPressed:changeTab()
Keys.onReleased: {
if(event.key === Qt.Key_Space || event.key === Qt.Key_Return || event.key === Qt.Key_Enter) {
spaceIsPressed = false;
}
}
function changeTab() {
isColorTab = !isColorTab
if(isColorTab) {
colorSelector.cellWidth = 60 * ApplicationInfo.ratio+20
}else {
colorSelector.cellWidth = 60 * ApplicationInfo.ratio
}
isColorTab = !isColorTab;
}
function spawnBlock() {
if(!isColorTab) {
var block = rootItem.childAt(cursor.x, cursor.y)
var block = rootItem.childAt(cursor.x, cursor.y);
if(block)
block.touched()
block.touched();
}else {
changeTab()
changeTab();
}
}
function refreshCursor() {
cursor.nbx= Activity.nbx
cursor.nby=Activity.nby
cursor.nbx = Activity.nbx;
cursor.nby = Activity.nby;
}
function moveColorSelector() {
moveColorSelectorAnim.running = false
moveColorSelectorAnim.from = colorSelector.contentY
moveColorSelectorAnim.running = false;
moveColorSelectorAnim.from = colorSelector.contentY;
if(items.current_color != (items.colors.length-1)) {
colorSelector.positionViewAtIndex(items.current_color >= 1 ? items.current_color-2 : items.current_color, colorSelector.Contain)
colorSelector.positionViewAtIndex(items.current_color >= 1 ? items.current_color-2 : items.current_color, colorSelector.Contain);
}else {
colorSelector.positionViewAtEnd()
colorSelector.positionViewAtEnd()
colorSelector.positionViewAtEnd();
}
moveColorSelectorAnim.to = colorSelector.contentY
moveColorSelectorAnim.running = true
moveColorSelectorAnim.to = colorSelector.contentY;
moveColorSelectorAnim.running = true;
}
Component.onCompleted: {
activity.start.connect(start)
activity.stop.connect(stop)
activity.start.connect(start);
activity.stop.connect(stop);
}
//Cursor to navigate in cells
PaintCursor {
id:cursor;
visible: items.keyboardControls && !isColorTab
initialX: colorSelector.width + 20 * ApplicationInfo.ratio
z:1
ix: 0
iy: 0
nbx: 20
nby: 10
color: items.colors[0]
}
......@@ -153,29 +175,36 @@ ActivityBase {
property alias background: background
property alias bar: bar
property alias paintModel: paintModel
property alias colorSelector: colorSelector
property var colors: bar.level < 10 ? Activity.colorsSimple : Activity.colorsAdvanced
property int current_color:0
property string colorSelector: colors[current_color]
property int current_color: 1
property string selectedColor: colors[current_color]
property string backgroundImg: Activity.backgrounds[bar.level - 1]
property bool keyboardControls: false
}
onStart: Activity.start(main, items, background)
onStop: Activity.stop()
onStart: Activity.start(main, items, background);
onStop: Activity.stop();
MultiPointTouchArea {
anchors.fill: parent
onPressed: checkTouchPoint(touchPoints)
onTouchUpdated: checkTouchPoint(touchPoints)
onPressed: {
items.keyboardControls = false;
isColorTab = false;
checkTouchPoint(touchPoints);
}
onTouchUpdated: checkTouchPoint(touchPoints);
}
function checkTouchPoint(touchPoints) {
for(var i in touchPoints) {
var touch = touchPoints[i]
var block = rootItem.childAt(touch.x, touch.y)
if(block)
if(rootItem.childAt(touch.x, touch.y)) {
var block = rootItem.childAt(touch.x, touch.y)
cursor.ix = block.ix
cursor.iy = block.iy
block.touched()
}
}
}
......@@ -239,7 +268,18 @@ ActivityBase {
anchors.centerIn: parent
}
property bool iAmSelected: modelData == items.colorSelector
Rectangle {
id: colorCursor
visible: items.keyboardControls && isColorTab
anchors.fill: parent
scale: 1.1
color: "#00FFFFFF"
radius: parent.radius
border.width: rect.iAmSelected ? radius : 0
border.color: "#E0FFFFFF"
}
property bool iAmSelected: modelData == items.selectedColor
states: [
State {
......@@ -310,10 +350,11 @@ ActivityBase {
anchors.fill: parent
hoverEnabled: true
onClicked: {
activity.audioEffects.play('qrc:/gcompris/src/core/resource/sounds/scroll.wav')
items.colorSelector = modelData
items.current_color=items.colors.indexOf(modelData)
items.colorSelector=items.colors[items.current_color]
activity.audioEffects.play('qrc:/gcompris/src/core/resource/sounds/scroll.wav');
items.keyboardControls = false;
items.selectedColor = modelData;
items.current_color = items.colors.indexOf(modelData);
items.selectedColor = items.colors[items.current_color];
}
}
}
......
Copyright: Timothée Giet, 2018
Copyright: Timothée Giet, 2018-2020
License: CC-BY-SA 4.0
Files:
cursor.svg
eraser.svg
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="64"
height="64"
id="svg3760"
version="1.1"
inkscape:version="0.92.4 (5da689c313, 2019-01-14)"
sodipodi:docname="cursor1.svg">
<defs
id="defs3762" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="9.1144347"
inkscape:cx="5.6792031"
inkscape:cy="27.350997"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="true"
fit-margin-top="0"
fit-margin-left="0"
fit-margin-right="0"
fit-margin-bottom="0"
inkscape:window-width="1884"
inkscape:window-height="1054"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:window-maximized="1"
inkscape:showpageshadow="false"
showguides="false">
<sodipodi:guide
position="-0.99999557,22.999999"
orientation="24,0"
id="guide4115"
inkscape:locked="false" />
<sodipodi:guide
position="-0.99999557,-1.0000018"
orientation="0,24"
id="guide4117"
inkscape:locked="false" />
<sodipodi:guide
position="23.000004,-1.0000018"
orientation="-24,0"
id="guide4119"
inkscape:locked="false" />
<sodipodi:guide
position="23.000004,22.999999"
orientation="0,-24"
id="guide4121"
inkscape:locked="false" />
<sodipodi:guide
position="2.0000044,19.999999"
orientation="18,0"
id="guide4123"
inkscape:locked="false" />
<sodipodi:guide
position="2.0000044,1.9999981"
orientation="0,18"
id="guide4125"
inkscape:locked="false" />
<sodipodi:guide
position="20.000004,1.9999981"
orientation="-18,0"
id="guide4127"
inkscape:locked="false" />
<sodipodi:guide
position="20.000004,19.999999"
orientation="0,-18"
id="guide4129"
inkscape:locked="false" />
<sodipodi:guide
position="3.0000044,18.999999"
orientation="16,0"
id="guide4131"
inkscape:locked="false" />
<sodipodi:guide
position="3.0000044,2.9999981"
orientation="0,16"
id="guide4133"
inkscape:locked="false" />
<sodipodi:guide
position="19.000004,2.9999981"
orientation="-16,0"
id="guide4135"
inkscape:locked="false" />
<sodipodi:guide
position="19.000004,18.999999"
orientation="0,-16"
id="guide4137"
inkscape:locked="false" />
<inkscape:grid
type="xygrid"
id="grid4139"
originx="-0.99998114"
originy="-1.0000137"
empspacing="4" />
</sodipodi:namedview>
<metadata
id="metadata3765">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title />
<dc:date>2018</dc:date>
<dc:creator>
<cc:Agent>
<dc:title>Timothée Giet</dc:title>
</cc:Agent>
</dc:creator>
<cc:license
rdf:resource="http://creativecommons.org/licenses/by-sa/4.0/" />
</cc:Work>
<cc:License
rdf:about="http://creativecommons.org/licenses/by-sa/4.0/">
<cc:permits
rdf:resource="http://creativecommons.org/ns#Reproduction" />
<cc:permits
rdf:resource="http://creativecommons.org/ns#Distribution" />
<cc:requires
rdf:resource="http://creativecommons.org/ns#Notice" />
<cc:requires
rdf:resource="http://creativecommons.org/ns#Attribution" />
<cc:permits
rdf:resource="http://creativecommons.org/ns#DerivativeWorks" />
<cc:requires
rdf:resource="http://creativecommons.org/ns#ShareAlike" />
</cc:License>
</rdf:RDF>
</metadata>
<g
inkscape:label="Capa 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(-551.28571,-565.64789)">
<circle
style="opacity:1;vector-effect:none;fill:#f2f2f2;fill-opacity:1;stroke:none;stroke-width:0.5;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
id="path827"
cx="583.28571"
cy="597.64789"
r="28" />
<path
style="opacity:1;vector-effect:none;fill:#202020;fill-opacity:1;stroke:none;stroke-width:0.61237246;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
d="M 18.564453,14.322266 14.322266,18.564453 27.757812,32 14.322266,45.435547 18.564453,49.677734 32,36.242188 45.435547,49.677734 49.677734,45.435547 36.242188,32 49.677734,18.564453 45.435547,14.322266 32,27.757812 Z"
transform="translate(551.28571,565.64789)"
id="rect872"
inkscape:connector-curvature="0" />
</g>
</svg>
......@@ -147,6 +147,9 @@ function stop() {
function initLevel() {
items.bar.level = currentLevel + 1
items.paintModel.clear()
items.current_color = 1
items.selectedColor = items.colors[1]
items.colorSelector.positionViewAtBeginning()
nbx = 20 + currentLevel
nby = Math.floor(nbx * (main.height / main.width))
background.refreshCursor()
......@@ -176,5 +179,5 @@ function previousLevel() {
}
function getColor() {
return items.colorSelector
return items.selectedColor
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment