From 9b346dde8fa33f822126ab796a401274f9c082ac Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 15 May 2019 10:19:31 +0200 Subject: [PATCH] Restart Simulation Buttom partially implemented --- CockpitSpace/RestartSimulation.js | 83 +++++++++++++++++++++++++++++++ Spaces/CockpitSpace.js | 12 +++++ 2 files changed, 95 insertions(+) create mode 100644 CockpitSpace/RestartSimulation.js diff --git a/CockpitSpace/RestartSimulation.js b/CockpitSpace/RestartSimulation.js new file mode 100644 index 000000000..509748b53 --- /dev/null +++ b/CockpitSpace/RestartSimulation.js @@ -0,0 +1,83 @@ + +function newRestartSimulation () { + const MODULE_NAME = 'Restart Simulation' + + let thisObject = { + visible: true, + container: undefined, + physics: physics, + draw: draw, + getContainer: getContainer, + initialize: initialize, + finalize: finalize + } + + thisObject.container = newContainer() + thisObject.container.initialize(MODULE_NAME) + + thisObject.container.isDraggeable = false + thisObject.container.isWheelable = false + thisObject.container.isClickeable = true + + return thisObject + + function finalize () { + thisObject.container.finalize() + thisObject.container = undefined + } + + function initialize () { + thisObject.container.frame.position.x = thisObject.container.parentContainer.frame.width * 80 / 100 + thisObject.container.frame.position.y = 6 + thisObject.container.frame.width = 100 + thisObject.container.frame.height = COCKPIT_SPACE_HEIGHT - 12 + } + + function getContainer (point, purpose) { + if (thisObject.visible !== true) { return } + + if (thisObject.container.frame.isThisPointHere(point, true) === true) { + return thisObject.container + } else { + return undefined + } + } + + function physics () { + + } + + function draw () { + if (thisObject.visible !== true) { return } + + drawRestartSimulation() + } + + function drawRestartSimulation () { + let fontSize + let label + let xOffset + let yOffset + + const OPACITY = 1 + + /* We put the params.VALUE in the middle */ + + fontSize = 15 + + browserCanvasContext.font = 'bold ' + fontSize + 'px ' + UI_FONT.PRIMARY + + label = 'RESTART SIMULATION' + + xOffset = label.length / 2 * fontSize * FONT_ASPECT_RATIO + yOffset = -45 + + labelPoint = { + x: 0 - xOffset + (thisObject.paramsArray[1].LEFT_OFFSET - thisObject.paramsArray[0].LEFT_OFFSET) / 2 + thisObject.paramsArray[0].LEFT_OFFSET - 20, + y: COCKPIT_SPACE_POSITION - COCKPIT_SPACE_HEIGHT / 2 - yOffset + } + + browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.WHITE + ', ' + OPACITY + ')' + browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y) + } +} diff --git a/Spaces/CockpitSpace.js b/Spaces/CockpitSpace.js index 6696a400b..a47822da3 100644 --- a/Spaces/CockpitSpace.js +++ b/Spaces/CockpitSpace.js @@ -6,6 +6,7 @@ container: undefined, status: 'BOTTOM', assetBalances: undefined, + restartSimulation: undefined, draw: draw, physics: physics, getContainer: getContainer, @@ -34,6 +35,7 @@ thisObject.container.finalize() thisObject.container = undefined thisObject.assetBalances = undefined + thisObject.restartSimulation = undefined } function initialize () { @@ -42,6 +44,10 @@ thisObject.assetBalances = newAssetBalances() thisObject.assetBalances.initialize() + + thisObject.restartSimulation = newRestartSimulation() + thisObject.restartSimulation.initialize() + thisObject.restartSimulation.container.connectToParent(thisObject.container) } function onMouseClick (event) { @@ -89,6 +95,11 @@ } function getContainer (point) { + let container + + container = thisObject.restartSimulation.getContainer(point) + if (container !== undefined) { return container } + if (thisObject.container.frame.isThisPointHere(point, true) === true) { return thisObject.container } else { @@ -102,6 +113,7 @@ drawBackground() thisObject.assetBalances.draw() + thisObject.restartSimulation.draw() } function drawBackground () {