Warning, /games/kbreakout/src/qml/Bar.qml is written in an unsupported language. File is not indexed.
0001 /*
0002 SPDX-FileCopyrightText: 2012 Viranch Mehta <viranch.mehta@gmail.com>
0003
0004 SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006
0007 import QtQuick 2.3
0008 import org.kde.games.core 0.1 as KgCore
0009 import "globals.js" as Globals
0010
0011 CanvasItem {
0012 id: bar
0013 spriteKey: "PlainBar"
0014
0015 property real barWidth: Globals.DEFAULT_BAR_WIDTH
0016 width: m_scale * barWidth
0017 height: m_scale * Globals.BRICK_HEIGHT
0018
0019 Behavior on width { NumberAnimation { duration: 50 } }
0020
0021 property int direction: 0
0022
0023 property string type
0024 onTypeChanged: spriteKey = type;
0025
0026 // for preserving position relative
0027 // to bgOverlay when canvas is resized
0028 property real posX
0029 x: m_scale * posX
0030
0031 function stopMoving() {
0032 moveTimer.stop();
0033 }
0034
0035 Timer {
0036 id: moveTimer
0037 interval: Globals.DEFAULT_UPDATE_INTERVAL
0038 repeat: true
0039 running: direction!=0 && !paused
0040 onTriggered: moveBy(bar.direction*Globals.BAR_MOVEMENT);
0041 }
0042
0043 function moveTo(newPos) {
0044 if (newPos < 0) {
0045 newPos = 0;
0046 } else if (newPos*m_scale + width > bgOverlay.width) {
0047 newPos = (bgOverlay.width - bar.width)/m_scale;
0048 }
0049
0050 posX = newPos;
0051 }
0052
0053 function moveBy(dx) {
0054 moveTo(posX + dx);
0055 }
0056
0057 function reset() {
0058 var newWidth = Globals.DEFAULT_BAR_WIDTH;
0059 moveBy( (barWidth-newWidth)/2 );
0060 barWidth = newWidth;
0061 type = "PlainBar";
0062 }
0063
0064 function enlarge() {
0065 var newWidth = Math.round(barWidth * Globals.RESIZE_BAR_RATIO);
0066 if (newWidth > Globals.MAX_BAR_WIDTH) {
0067 newWidth = Globals.MAX_BAR_WIDTH;
0068 }
0069 moveBy( (barWidth-newWidth)/2 );
0070 barWidth = newWidth;
0071 }
0072
0073 function shrink() {
0074 var newWidth = Math.round(barWidth / Globals.RESIZE_BAR_RATIO);
0075 if (newWidth < Globals.MIN_BAR_WIDTH) {
0076 newWidth = Globals.MIN_BAR_WIDTH;
0077 }
0078 moveBy( (barWidth-newWidth)/2 );
0079 barWidth = newWidth;
0080 }
0081 }