##:@* channel ## ##@ include ##proto @vr-proto-slide-element-line.wrl ##proto @vr-proto-slide-element-image.wrl ##proto @vr-proto-slide-element-vrml.wrl ##proto @vr-proto-slide-element-text.wrl ##proto @vr-proto-slide-element-break.wrl ##proto @vr-proto-slide-element-bullet.wrl ##proto @vr-proto-slide-element-nesting.wrl ##proto @vr-proto-slide-element-block.wrl ##@ text ## Needs IO, ## In: show-a-certain-level ## Out: I-have-this-many-levels PROTO TextBlock [ exposedField SFString blockType "TEXTBLOCK" exposedField SFBool warnOnSize FALSE field SFFloat width 25 ## AE field SFFloat height 15 eventOut SFFloat realHeight exposedField SFVec3f location 0 0 0 exposedField SFRotation rotation 0 1 0 0 exposedField SFVec3f scale 1 1 1 ## AE exposedField SFBool absolute FALSE ##exposedField SFString url "image.gif" exposedField SFString url "" exposedField SFInt32 bgType 0 eventIn SFColor color eventIn SFFloat alpha exposedField SFColor bgColor 0 0 1 exposedField SFFloat bgTransparency 0.5 eventIn SFInt32 showLevel exposedField SFInt32 lastLevel -1 eventIn SFTime startTime eventIn SFTime stopTime exposedField MFNode elements [] ] { ##@ body Transform { translation IS location rotation IS rotation scale IS scale children [ DEF BOXTRANSFORM Transform { translation 0 0 -1 scale 1.1 1 1 } DEF TRANSFORM Transform { children [ DEF GROUP Group {} ] } ] } ##@ script DEF SCRIPT Script { mustEvaluate TRUE directOutput TRUE eventIn SFColor color IS color eventIn SFFloat alpha IS alpha eventIn SFTime startTime IS startTime eventIn SFTime stopTime IS stopTime field MFNode back NULL field SFNode me USE SCRIPT field SFNode groupNode USE GROUP field SFNode transform USE TRANSFORM field SFNode boxTransform USE BOXTRANSFORM field SFFloat width IS width field SFFloat height IS height eventOut SFFloat realHeight IS realHeight field SFInt32 lastLevel IS lastLevel eventOut SFInt32 lastLevel_changed IS lastLevel field MFNode elements IS elements field SFString xurl IS url field SFInt32 bgType IS bgType field SFColor bgColor IS bgColor field SFFloat bgTransparency IS bgTransparency eventIn SFInt32 layoutLevel IS showLevel field SFInt32 currentLevel -1 field SFBool absolute IS absolute ##@ functions url "javascript: function initialize() { // Setup translation so (0,0) is in left/top corner if (!absolute) transform.translation = new SFVec3f(-width/2,height/2,0); countLevels(); layoutLevel(0,0); var bgBox; // Setup backgroundBox to be size widthXheight if ( bgType == 0 ) { bgBox = Browser.createVrmlFromString(' Shape { appearance Appearance { material Material { diffuseColor 0 0 0 specularColor 0 0 0 emissiveColor ' + bgColor + ' transparency ' + bgTransparency + ' } } geometry Box { size ' + width + ' ' + height + ' 0.01 } } '); } else if ( bgType == 1 ) { bgBox = Browser.createVrmlFromString(' Shape { appearance Appearance { material Material { diffuseColor 0 0 0 specularColor 0 0 0 emissiveColor ' + bgColor + ' transparency ' + bgTransparency + ' } texture ImageTexture { url \"' + xurl + '\" } } geometry Box { size ' + width + ' ' + height + ' 0.01 } } '); } else if ( bgType == 2 ) { bgBox = Browser.createVrmlFromString(' Shape { appearance Appearance { material Material { diffuseColor 0 0 0 specularColor 0 0 0 emissiveColor ' + bgColor + ' transparency ' + bgTransparency + ' } texture DEF MOVIE MovieTexture { loop TRUE url \"' + xurl + '\" } } geometry Box { size ' + width + ' ' + height + ' 0.01 } } Sound { source USE MOVIE } '); } else if ( bgType == 3 ) { bgBox = Browser.createVrmlFromString(' slide-vcr { video \"' + xurl + '\" size ' + width + ' ' + height + ' 0.1 }'); } back = bgBox; boxTransform.children = bgBox; // boxTransform.scale = new SFVec3f(width,height,1); } ##@ color function color(value) { bgColor = value; back[0].appearance.material.emissiveColor = value; //print('bgcolor ' + value); } function alpha(value) { bgTransparency = value; back[0].appearance.material.transparency = value; //print('alpha ' + value); } function startTime(value) { if (bgType == 3) back[0].startTime = value; } function stopTime(value) { if (bgType == 3) back[0].stopTime = value; } ##@ levels function countLevels() { var i = 0; var last = -1; for(i=0;i last) { last = elements[i].startLevel; } } if(elements[i].endLevel != -1) { if(elements[i].endLevel > last) { last = elements[i].endLevel; } } } //lastLevel = -1; lastLevel = last; lastLevel_changed = last; } ##@ layout function layoutLevel(level,time) { if(level==currentLevel) { if (bgType == 3) { bgBox.stopTime = Browser.getTime(); } return; } currentLevel = level; var nodes = getNodesForLevel(level); var block = new MFNode(); var nesting = 0; var i = 0; var j = 0; var n = 0; var x = 0.0; var y = -1.0; // need proper initialize ! var first = 0; for(i=0;i 0) { for(j=first;j width) { x = 0; y = y - block[n-1].height; first = n; } //} if (!nodes[i].absolute) { nodes[i].position[0] = x; nodes[i].position[1] = y; } block[n] = nodes[i]; n = n + 1; if(block[n-1].elementType == 'TEXTELEMENT') { if((x + block[n-1].width) > width) { block[n-1] = copyTextElement(block[n-1]); } while((x + block[n-1].width) > width) { var tail = splitLine(block[n-1],width-x); x = x + block[n-1].width; if(first!=n && block[first].justify[0]!='BEGIN') { var delta = width - x; if(block[first].justify[0]=='MIDDLE') { delta = delta / 2; } if(delta > 0) { for(j=first;j 0) { for(j=first;j= level) ) { if(elements[i].elementType == 'BLOCKELEMENT' ) { elements[i].showLevel = level; block[n] = elements[i]; } else { block[n] = elements[i]; } n = n + 1; } } return block; } ##@ copy elements function copyTextElement(line) { var copy = Browser.createVrmlFromString(' TextElement { bgTransparency '+ line.bgTransparency + ' bgColor ' + line.bgColor + ' } '); copy[0].height = line.height; copy[0].linebreak = line.linebreak; copy[0].nochange = line.nochange; copy[0].color = line.color; copy[0].alpha = line.alpha; copy[0].justify = line.justify; copy[0].family = line.family; copy[0].style = line.style; copy[0].position = line.position; copy[0].width = line.width; copy[0].string[0] = line.string[0]; return copy[0]; } function splitLine(line,maxWidth) { if (line.nochange) return line; // print('input char= '+line.string[0].length+' width= '+line.width+' '+line.string[0]); // print('Should be splitting now...'); var tail = Browser.createVrmlFromString(' TextElement { bgTransparency '+ line.bgTransparency + ' bgColor ' + line.bgColor + ' } '); // tail[0].bgTransparency = line.bgTransparency; // tail[0].bgColor = line.bgColor; tail[0].height = line.height; tail[0].linebreak = line.linebreak; tail[0].color = line.color; tail[0].justify = line.justify; tail[0].family = line.family; tail[0].style = line.style; var fraction = maxWidth/line.width; var characters = Math.floor(fraction*line.string[0].length); characters = characters + 3; while(line.string[0].charAt(characters) != ' ' && characters > 0) characters--; fraction = characters/line.string[0].length; tail[0].width = line.width - fraction * line.width; line.width = line.width - tail[0].width; tail[0].string[0] = line.string[0].substring(characters+1, line.string[0].length); line.string[0] = line.string[0].substring(0,characters+1); // print('characters = '+characters); // print('line char= '+line.string[0].length+' width= '+line.width+' ' + line.string[0]); // print('tail char= '+tail[0].string[0].length+' width= '+tail[0].width+' ' + tail[0].string[0]); return tail[0]; } " } } ##