// changed at Tue Apr 17 2012 14:30:49 GMT-0700 (PDT) by TedKaehler
this.addScript(function addBackground() {
// add an empty background after the current page
// It comes with page controls. You can delete them.
var newBKgnd = this.baseBackground.copy();
newBKgnd.stack = this;
newBKgnd.setFill(Color.white);
this.newPage(newBKgnd);
this.addPageControlsTo(newBKgnd);
return newBKgnd;
}).tag([]);
// changed at Fri Apr 27 2012 13:41:27 GMT-0700 (PDT) by TedKaehler
this.addScript(function addPageControlsTo(layer) {
// in button scripts, owner.owner.owner will be the stack (fragile)
var tray = layer.addMorph(Morph.makeRectangle(0, 0, 116, 24));
tray.align(tray.bounds().bottomCenter(),
layer.innerBounds().bottomCenter().addXY(0, -10));
tray.setFill(null);
tray.applyStyle({borderWidth: 0});
this.beInBackground(tray);
var menuButton = tray.addMorph(new ButtonMorph (new Rectangle(0, 0, 26, 20), '<>'));
menuButton.addScript(function onMouseUp(evt) {this.owner.owner.owner.showMenu(evt)});
menuButton.align(menuButton.bounds().bottomCenter(),
tray.innerBounds().bottomCenter().addXY(2, -2));
var downButton = tray.addMorph(new ButtonMorph (new Rectangle(0, 0, 20, 20), '<'));
downButton.addScript(function onMouseUp(evt) {this.owner.owner.owner.showPageInc(-1)});
downButton.align(downButton.bounds().topRight(), menuButton.bounds().topLeft());
var removeButton = tray.addMorph(new ButtonMorph (new Rectangle(0, 0, 26, 20), '<<'));
removeButton.addScript(function onMouseUp(evt) {this.owner.owner.owner.showPageNum(1)});
removeButton.align(removeButton.bounds().topRight(), downButton.bounds().topLeft());
var upButton = tray.addMorph(new ButtonMorph (new Rectangle(0, 0, 20, 20), '>'));
upButton.addScript(function onMouseUp(evt) {this.owner.owner.owner.showPageInc(1)});
upButton.align(upButton.bounds().topLeft(), menuButton.bounds().topRight());
var addButton = tray.addMorph(new ButtonMorph (new Rectangle(0, 0, 20, 20), '+'));
addButton.addScript(function onMouseUp(evt) {this.owner.owner.owner.newPageHere()});
addButton.align(addButton.bounds().topLeft(), upButton.bounds().topRight());
}).tag([]);
// changed at Fri Apr 06 2012 17:33:32 GMT-0700 (PDT) by TedKaehler
this.addScript(function addPageSpecific(pgData) {
// take morphs in pageMorphs, and add them to the page.
var len=pgData.pageMorphs.length;
for(var ii=len-1; ii>=0; ii--) { // reverse
pgData.background.addMorph(pgData.pageMorphs[ii]);
};
this.loadPageText(pgData);
}).tag([]);
// changed at Tue Apr 17 2012 09:53:50 GMT-0700 (PDT) by TedKaehler
this.addScript(function beInBackground(aMorph) {
// make the morph be in the background
delete aMorph.pageSpecific;
}).tag([]);
// changed at Wed Apr 18 2012 10:17:49 GMT-0700 (PDT) by TedKaehler
this.addScript(function beInPage(aMorph) {
// make the morph be on this page only
aMorph.pageSpecific = true;
}).tag([]);
// changed at Fri Apr 06 2012 17:05:44 GMT-0700 (PDT) by TedKaehler
this.addScript(function bePerPageText(textMorph) {
// make the text be in the background and set it up to save the text data in pageData
delete textMorph.pageSpecific;
textMorph.dbjrDataGetter = textMorph.name + 'Contents';
// later set a kind
}).tag([]);
// changed at Tue Apr 17 2012 14:26:53 GMT-0700 (PDT) by TedKaehler
this.addScript(function deletePage() {
// remove the current page
this.showPageInc(1); // show page after deleted
if (this.pageIndex - 2 < 0) { // delete last page
this.pageArray.splice(-1, 1);
} else {
this.pageArray.splice(this.pageIndex - 2, 1);
this.pageIndex = this.pageIndex - 1;
};
}).tag([]);
// changed at Tue Apr 17 2012 14:29:13 GMT-0700 (PDT) by TedKaehler
this.addScript(function demo() {
// Construct a stack with pages and objects on them.
master = this.owner.get('Stack');
var stk = master.newStack();
var ourBkgnd = stk.submorphs[0];
var txt = new lively.morphic.Text( new Rectangle(10, 10, 200, 75),"Text on page one.");
ourBkgnd.addMorph(txt.applyStyle({fontSize: 20, borderWidth: 1, fill: null}));
txt.name = 'bkField';
this.bePerPageText(txt); // put it in background
stk.newPage(ourBkgnd); // page 2
if (!(stk.pageIndex == 2)) {this.error('index problem')};
txt.setPosition(pt(10,10));
var ell = Morph.makeEllipse(new Rectangle(0, 0, 100, 75), 1, Color.black, Color.green);
ourBkgnd.addMorph(ell); // this page only
ell.setPosition(pt(75,250));
stk.addPageControlsTo(ourBkgnd);
var newBKgnd = stk.addBackground(); // page 3
newBKgnd.setFill(Color.yellow);
var ell2 = Morph.makeEllipse(new Rectangle(0, 0, 75, 100), 1, Color.black, Color.red);
stk.submorphs[0].addMorph(ell2); // this page only
ell2.setPosition(pt(100,200));
stk.showPageNum(1); // 1-order
}).tag([]);
// changed at Fri Apr 27 2012 15:20:13 GMT-0700 (PDT) by TedKaehler
this.addScript(function initialize() {
this.removeAllMorphs();
this.pageIndex = 0; // 1-order
this.pageArray = [];
this.showBackground = null;
this.baseBackground = this.owner.pageProto;
var newBKgnd = this.baseBackground.copy();
newBKgnd.stack = this;
this.newPage(newBKgnd);
}).tag([]);
// changed at Sun Apr 29 2012 21:58:00 GMT-0700 (PDT) by TedKaehler
this.addScript(function loadPageText(pgData) {
// take text from property fldNameContents in pageData nd put it into its background.
var subs = pgData.background.submorphs;
var len = subs.length;
var mm = null;
for(var ii=0; ii<len; ii++) { // skip background morphs
mm = subs[ii];
if (! mm.pageSpecific) {
if ('dbjrDataGetter' in mm) {
var theText = pgData[mm.dbjrDataGetter];
if (theText == undefined) {
mm.textString = ''} // later with style
else {
mm.setRichText2(theText) }}};
};
}).tag([]);
// changed at Fri Apr 27 2012 10:10:14 GMT-0700 (PDT) by TedKaehler
this.addScript(function newPage(aBackground) {
var pgData = new PageData(aBackground, []);
this.pageArray.splice(this.pageIndex, 0, pgData);
// splice is 1-order
if (this.pageArray.length == 1) {
this.addMorph(aBackground);
aBackground.setOrigin(pt(0,0));
aBackground.setPosition(pt(5,5));
this.pageIndex = 1}
else {
this.showPageNum(this.pageIndex + 1); // 1-order
if (this.pageArray[this.pageIndex - 1].background !== this.pageArray[this.pageIndex - 2].background) {
//changed backgrounds
aBackground.setOrigin(pt(0,0));
aBackground.setPosition(pt(0,10))}};
}).tag([]);
// changed at Fri Apr 13 2012 23:46:43 GMT-0700 (PDT) by TedKaehler
this.addScript(function newPageHere() {
this.newPage(this.pageArray[this.pageIndex - 1].background);
}).tag([]);
// changed at Thu Apr 05 2012 14:07:37 GMT-0700 (PDT) by TedKaehler
this.addScript(function newStack() {
stk = this.copy();
this.owner.addMorph(stk);
stk.initialize();
return stk;
}).tag([]);
// changed at Sun Apr 29 2012 21:59:27 GMT-0700 (PDT) by TedKaehler
this.addScript(function removePageSpecific(pgData) {
// remove page specific morphs and put them in pageMorphs
var subs = pgData.background.submorphs;
var len = subs.length;
var mm = null;
pgData.pageMorphs = [];
for(var ii=0; ii<len; ii++) { // skip background morphs
mm = subs[ii];
if (mm.pageSpecific) {
pgData.pageMorphs.push(mm) }
else {
if ('dbjrDataGetter' in mm) {
pgData[mm.dbjrDataGetter] = mm.getRichText2() }};
};
var pmLen = pgData.pageMorphs.length;
for(var jj=0; jj<pmLen; jj++) {
pgData.pageMorphs[jj].remove() };
}).tag([]);
// changed at Tue Apr 17 2012 12:45:49 GMT-0700 (PDT) by TedKaehler
this.addScript(function showMenu(evt) {
// menu in page controls <>
var self = this, items = [];
items.push(['delete page', function(evt2) {
self.deletePage()}]);
items.push(['new background', function(evt2) {
self.addBackground()}]);
lively.morphic.Menu.openAt(evt.getPosition(), 'Stack Menu', items);
}).tag([]);
// changed at Fri Apr 13 2012 23:27:17 GMT-0700 (PDT) by TedKaehler
this.addScript(function showPageInc(delta) {
// turn to a page and show it. newIndex is 1 based.
this.showPageNum(this.pageIndex + delta)
}).tag([]);
// changed at Fri Apr 27 2012 10:09:26 GMT-0700 (PDT) by TedKaehler
this.addScript(function showPageNum(newIndexIn) {
// turn to a page and show it. newIndex is 1 based.
if (this.pageIndex == newIndexIn) {return this;};
var newIndex = (newIndexIn + (this.pageArray.length) - 1) % (this.pageArray.length) + 1;
var newData = this.pageArray[newIndex - 1];
if (! newData) {this.alert('page number out of range')};
var oldData = this.pageArray[this.pageIndex - 1];
this.removePageSpecific(oldData); // includes storing text
this.pageIndex = newIndex;
if (oldData.background !== newData.background) { //change backgrounds
oldData.background.remove();
this.addMorph(newData.background);
newData.background.setOrigin(pt(0,0));
newData.background.setPosition(pt(0,10));
};
this.addPageSpecific(newData); // includes loading text
}).tag([]);
this.addScript(function showPageWithProperty(propertyN, value) {
// Search pages for pageData with the property and value.
// idNum, 3452 is a useful property to set and search for
// Note: property is on the pageData object
// (stack.pageArray[stack.pageIndex - 1]), not the morph!
var paLen = this.pageArray.length;
var data = null;
for(var jj=0; jj<paLen; jj++) {
data = this.pageArray[jj];
if (data[propertyN] == value) {
this.showPageNum(jj+1);
return true}
};
}).tag([]);
// changed at Wed Apr 18 2012 10:22:08 GMT-0700 (PDT) by TedKaehler
this.addScript(function stackMenuItems(aMorph, items) {
// return a list of stack-related menu items for aMorph
var self = this;
if (aMorph.pageSpecific) {
items.push(['be in background', function(evt2) {
self.beInBackground(aMorph)}]) }
else {
items.push(['be in this page only', function(evt2) {
self.beInPage(aMorph)}])
};
items.push(['be per page text', function(evt2) {
self.bePerPageText(aMorph)}]);
return items
}).tag([])