Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HUD Driver #524

Open
wants to merge 25 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions support/client/lib/vwf.js
Expand Up @@ -323,6 +323,9 @@
"vwf/model/blockly/msg/js/en": {
deps: [ "vwf/model/blockly/blockly_compressed" ]
},
"vwf/model/hud/hud": {
exports: "HUD"
}
}
};

Expand Down Expand Up @@ -363,6 +366,7 @@
active: false
},
{ library: "vwf/model/graphtool", active: false },
{ library: "vwf/model/hud", active: false },
{ library: "vwf/model/sound", active: false },
{ library: "vwf/model/object", active: true },
{ library: "vwf/model/stage/log", active: true },
Expand Down Expand Up @@ -400,6 +404,7 @@
active: false
},
{ library: "vwf/view/blockly", active: false },
{ library: "vwf/view/hud", active: false },
{ library: "vwf/view/sound", active: false },
{ library: "vwf/view/touch", active: false },
{ library: "vwf/view/cesium", active: false },
Expand Down Expand Up @@ -439,6 +444,7 @@
{ library: "vwf/model/cesium", active: false },
{ library: "vwf/model/blockly", active: false },
{ library: "vwf/model/graphtool", active: false },
{ library: "vwf/model/hud", active: false },
{ library: "vwf/model/sound", active: false },
{ library: "vwf/model/kineticjs", active: false },
{ library: "vwf/model/mil-sym", active: false },
Expand All @@ -456,6 +462,7 @@
{ library: "vwf/view/google-earth", active: false },
{ library: "vwf/view/cesium", active: false },
{ library: "vwf/view/blockly", active: false },
{ library: "vwf/view/hud", active: false },
{ library: "vwf/view/sound", active: false },
{ library: "vwf/view/touch", active: false },
{ library: "vwf/view/kineticjs", active: false },
Expand Down
170 changes: 170 additions & 0 deletions support/client/lib/vwf/model/hud.js
@@ -0,0 +1,170 @@
"use strict";

define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utility ) {

var logger;

return model.load( module, {

initialize: function() {
this.state.overlays = {};
this.state.elements = {};
logger = this.logger;
},

creatingNode: function( nodeID, childID, childExtendsID, childImplementsIDs,
childSource, childType, childIndex, childName, callback /* ( ready ) */ ) {

var node;
var protos = this.kernel.prototypes( childID );
if ( protos && isOverlay( protos ) ) {
node = this.state.overlays[ childID ] = {
"id": childID,
"name": childName,
"elements": {},
"properties": {
"visible": undefined,
"enabled": undefined
},
"drawProperties" : {},
"elementPreDraw": undefined,
"elementPostDraw": undefined,
"globalPreDraw": undefined,
"globalPostDraw": undefined,
"initialized": false
};
} else if ( protos && isElement( protos ) ) {
node = this.state.elements[ childID ] = {
"id": childID,
"name": childName,
"overlay": this.state.overlays[ nodeID ],
"properties": {
"images": undefined,
"width": undefined,
"height": undefined,
"visible": undefined,
"enabled": undefined,
"alignH": undefined,
"alignV": undefined,
"offsetH": undefined,
"offsetV": undefined,
"drawOrder": undefined
},
"drawProperties": {},
"initialized": false
};
node.overlay.elements[ childID ] = node;
}
},

creatingProperty: function( nodeID, propertyName, propertyValue ) {
return this.initializingProperty( nodeID, propertyName, propertyValue );
},

initializingProperty: function( nodeID, propertyName, propertyValue ) {
var value;
if ( propertyValue !== undefined ) {
var node = this.state.overlays[ nodeID ] || this.state.elements[ nodeID ] ;
if ( node !== undefined ) {
switch ( propertyName ) {
default:
value = this.settingProperty( nodeID, propertyName, propertyValue );
break;
}
}
}
return value;
},

settingProperty: function( nodeID, propertyName, propertyValue ) {
var node, value, images, keys, i, image;
if ( this.state.overlays[ nodeID ] ) {
node = this.state.overlays[ nodeID ];
if ( node.properties.hasOwnProperty( propertyName ) ) {
node.properties[ propertyName ] = propertyValue;
value = propertyValue;
} else {
node.drawProperties[ propertyName ] = propertyValue;
}
} else if ( this.state.elements[ nodeID ] ) {
node = this.state.elements[ nodeID ];
if ( node.properties.hasOwnProperty( propertyName ) ) {
if ( propertyName === "images" ) {
node.properties.images = propertyValue;
} else {
node.properties[ propertyName ] = propertyValue;
}
} else {
node.drawProperties[ propertyName ] = propertyValue;
}
value = propertyValue;
}

return value;
},

gettingProperty: function( nodeID, propertyName ) {
var node, value;
if ( this.state.overlays[ nodeID ] ) {
node = this.state.overlays[ nodeID ];
if ( node.properties.hasOwnProperty( propertyName ) ) {
value = node.properties[ propertyName ];
}
} else if ( this.state.elements[ nodeID ] ) {
node = this.state.elements[ nodeID ];
if ( node.properties.hasOwnProperty( propertyName ) ) {
value = node.properties[ propertyName ];
} else if ( node.drawProperties.hasOwnProperty( propertyName ) ) {
value = node.drawProperties[ propertyName ];
}
}
return value;
},

callingMethod: function( nodeID, methodName, methodParameters, methodValue ) {
var node;
if ( this.state.overlays[ nodeID ] ) {
node = this.state.overlays[ nodeID ];
switch ( methodName ) {
case "elementPreDraw":
case "elementPostDraw":
case "globalPreDraw":
case "globalPostDraw":
this.logger.errorx( "callingMethod", "The " + methodName + " method should not " +
"be called from outside the HUD driver!" );
return;
break;
}
} else if ( this.state.elements[ nodeID ] ) {
node = this.state.elements[ nodeID ];
if ( methodName === "draw" ) {
this.logger.errorx( "callingMethod", "The draw method should not be called " +
"from outside the HUD driver!" );
return;
}
}
}

} );

function isOverlay( prototypes ) {
var foundOverlay = false;
if ( prototypes ) {
for ( var i = 0; i < prototypes.length && !foundOverlay; i++ ) {
foundOverlay = ( prototypes[i] == "http://vwf.example.com/hud/overlay.vwf" );
}
}
return foundOverlay;
}

function isElement( prototypes ) {
var foundElement = false;
if ( prototypes ) {
for ( var i = 0; i < prototypes.length && !foundElement; i++ ) {
foundElement = ( prototypes[i] == "http://vwf.example.com/hud/element.vwf" );
}
}
return foundElement;
}

} );