diff --git a/cocos2d/base_nodes/CCdomNode.js b/cocos2d/base_nodes/CCdomNode.js
index 796c501305..ecce7802b8 100644
--- a/cocos2d/base_nodes/CCdomNode.js
+++ b/cocos2d/base_nodes/CCdomNode.js
@@ -29,19 +29,14 @@
* @type {Object}
*/
cc.DOM = {};
-/**
- * Set to true to enalbe DOM debugging/editing, which allows you to move, rotate, scale, skew an element.
- * Set to false to turn off debugging/editing
- * @type Boolean
- */
-cc.DOMEditMode = true;
+
/**
* @function
* @private
* @param x
*/
cc.DOM.addMethods = function (x) {
- for (funcs in cc.DOM.methods) {
+ for (var funcs in cc.DOM.methods) {
x[funcs] = cc.DOM.methods[funcs];
}
};
@@ -128,7 +123,7 @@ cc.DOM.methods = /** @lends cc.DOM# */{
this._anchorPoint = point;
this._anchorPointInPoints = cc.p(this._contentSize.width * this._anchorPoint.x,
this._contentSize.height * this._anchorPoint.y);
- this.dom.style[cc.$.pfx + 'TransformOrigin'] = '' + this._anchorPointInPoints.x + 'px ' + this._anchorPointInPoints.y + 'px';
+ this.dom.style[cc.$.pfx + 'TransformOrigin'] = '' + this._anchorPointInPoints.x + 'px ' + -this._anchorPointInPoints.y + 'px';
if (this.isIgnoreAnchorPointForPosition()) {
this.dom.style.marginLeft = 0;
this.dom.style.marginBottom = 0;
@@ -157,11 +152,6 @@ cc.DOM.methods = /** @lends cc.DOM# */{
this.canvas.width = this._contentSize.width;
this.canvas.height = this._contentSize.height;
}
- if (cc.DOMEditMode && !this.placeholder) {
- this.dom.style.width = this._contentSize.width + 'px';
- this.dom.style.height = this._contentSize.height + 'px';
- this.dom.addClass('CCDOMEdit');
- }
this.setNodeDirty();
this.redraw();
},
@@ -176,8 +166,10 @@ cc.DOM.methods = /** @lends cc.DOM# */{
//save dirty region when before change
//this._addDirtyRegionToDirector(this.getBoundingBoxToWorld());
- this._rotation = newRotation;
- this._rotationRadians = this._rotation * (Math.PI / 180);
+ this._rotationX = this._rotationY = newRotation;
+ this._rotationRadiansX = this._rotationX * (Math.PI / 180);
+ this._rotationRadiansY = this._rotationY * (Math.PI / 180);
+
this.setNodeDirty();
this.dom.rotate(newRotation);
},
@@ -210,7 +202,7 @@ cc.DOM.methods = /** @lends cc.DOM# */{
this._visible = x;
this.setNodeDirty();
if (this.dom)
- this.dom.style.visibility = (x) ? 'visible' : 'hidden';
+ this.dom.style.display = (x) ? 'block' : 'none';
},
_setZOrder:function (z) {
this._zOrder = z
@@ -319,14 +311,41 @@ cc.DOM.parentDOM = function (x) {
}
//if parent have dom, attach self to parent
x.dom.appendTo(p.dom);
- var pp;
- if (pp = p.getParent()) {
+ p.setAnchorPoint(p.getAnchorPoint());
+
+ if (p.getParent()) {
cc.DOM.parentDOM(p);
- }
- else {
+ } else {
//parent has no more parent, if its running, then add it to the container
if (p.isRunning()) {
- p.dom.appendTo(cc.container);
+ //find EGLView div
+ var eglViewDiv = cc.$("#EGLViewDiv");
+ if(eglViewDiv){
+ p.dom.appendTo(eglViewDiv);
+ } else {
+ eglViewDiv = cc.$new("div");
+ eglViewDiv.id = "EGLViewDiv";
+
+ var eglViewer = cc.EGLView.getInstance();
+ var designSize = eglViewer.getDesignResolutionSize();
+ var viewPortRect = eglViewer.getViewPortRect();
+ var screenSize = eglViewer.getFrameSize();
+
+ eglViewDiv.style.position = 'absolute';
+ eglViewDiv.style.bottom = 0;
+ //x.dom.style.display='block';
+ eglViewDiv.style.width = designSize.width + "px";
+ eglViewDiv.style.maxHeight = designSize.height + "px";
+ eglViewDiv.style.margin = 0;
+
+ eglViewDiv.resize(eglViewer.getScaleX(), eglViewer.getScaleX());
+ eglViewDiv.style.left = ((viewPortRect.size.width - designSize.width) /2
+ + (screenSize.width -viewPortRect.size.width )/2) + "px";
+ eglViewDiv.style.bottom = ((screenSize.height -viewPortRect.size.height )/2) + "px";
+
+ p.dom.appendTo(eglViewDiv);
+ eglViewDiv.appendTo(cc.container);
+ }
}
}
return true;
@@ -384,11 +403,6 @@ cc.DOM.forSprite = function (x) {
x.canvas = cc.$new('canvas');
x.canvas.width = x.getContentSize().width;
x.canvas.height = x.getContentSize().height;
- if (cc.DOMEditMode) {
- x.dom.style.width = x.getContentSize().width + 'px';
- x.dom.style.height = x.getContentSize().height + 'px';
- x.dom.addClass('CCDOMEdit');
- }
x.dom.style.position = 'absolute';
x.dom.style.bottom = 0;
x.ctx = x.canvas.getContext('2d');
@@ -399,127 +413,6 @@ cc.DOM.forSprite = function (x) {
x.isSprite = true;
};
-/**
- * @function
- * @private
- * @param x
- */
-cc.DOM.forMenuToggler = function (x) {
- x.dom = cc.$new('div');
- x.dom2 = cc.$new('div');
- x.dom.appendChild(x.dom2);
- for (var i = 0; i < x._subItems.length; i++) {
- cc.DOM.convert(x._subItems[i]);
- x.dom2.appendChild(x._subItems[i].dom);
- x._subItems[i].setPosition(cc.p(0, 0));
- }
- x.dom.style.marginLeft = 0;
- x.setSelectedIndex = function (SelectedIndex) {
- this._selectedIndex = SelectedIndex;
- for (var i = 0; i < this._subItems.length; i++) {
- this._subItems[i].setVisible(false);
- }
- this._subItems[SelectedIndex].setVisible(true);
- };
-
-
- x.setSelectedIndex(x.getSelectedIndex());
- x.dom2.addEventListener('click', function () {
- x.activate();
- });
- x.dom2.addEventListener('mousedown', function () {
- for (var i = 0; i < x._subItems.length; i++) {
- x._subItems[i]._isEnabled = true;
- x._subItems[i]._running = true;
- x._subItems[i].selected();
- x._subItems[i]._isEnabled = false;
- x._subItems[i]._running = false;
- }
- x._subItems[x.getSelectedIndex()]._isEnabled = true;
- x._subItems[x.getSelectedIndex()]._running = true;
-
- });
- x.dom2.addEventListener('mouseup', function () {
- for (var i = 0; i < x._subItems.length; i++) {
- x._subItems[i]._isEnabled = true;
- x._subItems[i].unselected();
- x._subItems[i]._isEnabled = false;
- }
- x._subItems[x.getSelectedIndex()]._isEnabled = true;
- });
- x.dom2.addEventListener('mouseout', function () {
- if (x.mouseDown) {
- for (var i = 0; i < x._subItems.length; i++) {
- x._subItems[i]._isEnabled = true;
- x._subItems[i].unselected();
- x._subItems[i]._isEnabled = false;
- }
- x._subItems[x.getSelectedIndex()]._isEnabled = true;
- x.mouseDown = false;
- }
- });
- x.dom.style.position = "absolute";
- x.isToggler = true;
-};
-
-/**
- * @function
- * @private
- * @param x
- */
-cc.DOM.forMenuItem = function (x) {
- x.dom = cc.$new('div');
- x.canvas = cc.$new('canvas');
- x.canvas.width = x.getContentSize().width;
- x.canvas.height = x.getContentSize().height;
- if (cc.DOMEditMode) {
- x.dom.style.width = x.getContentSize().width + 'px';
- x.dom.style.height = x.getContentSize().height + 'px';
- x.dom.addClass('CCDOMEdit');
- }
- x.dom.style.position = 'absolute';
- x.dom.style.bottom = 0;
- x.ctx = x.canvas.getContext('2d');
- x.dom.appendChild(x.canvas);
- if (x.getParent()) {
- cc.DOM.parentDOM(x);
- }
- if (x._selector) {
- //if menu item have callback
- x.canvas.addEventListener('click', function () {
- x.activate();
- });
- x.canvas.addEventListener('mousedown', function () {
- x.selected();
- x.ctx.save();
- x.ctx.setTransform(1, 0, 0, 1, 0, 0);
- x.ctx.clearRect(0, 0, x.canvas.width, x.canvas.height);
- x.ctx.restore();
- x.mouseDown = true;
- cc.Sprite.prototype.visit.call(x, x.ctx);
- });
- x.canvas.addEventListener('mouseup', function () {
- x.unselected();
- x.ctx.save();
- x.ctx.setTransform(1, 0, 0, 1, 0, 0);
- x.ctx.clearRect(0, 0, x.canvas.width, x.canvas.height);
- x.ctx.restore();
- cc.Sprite.prototype.visit.call(x, x.ctx);
- });
- x.canvas.addEventListener('mouseout', function () {
- if (x.mouseDown) {
- x.unselected();
- x.ctx.save();
- x.ctx.setTransform(1, 0, 0, 1, 0, 0);
- x.ctx.clearRect(0, 0, x.canvas.width, x.canvas.height);
- x.ctx.restore();
- cc.Sprite.prototype.visit.call(x, x.ctx);
- x.mouseDown = false;
- }
- })
- }
-};
-
/**
* This creates divs for parent Nodes that are related to the current node
* @function
@@ -546,7 +439,7 @@ cc.DOM.placeHolder = function (x) {
* Converts cc.Sprite or cc.MenuItem to DOM elements
* It currently only supports cc.Sprite and cc.MenuItem
* @function
- * @param {cc.Sprite|cc.MenuItem|Array}
+ * @param {cc.Sprite|cc.MenuItem|Array} nodeObject
* * @example
* // example
* cc.DOM.convert(Sprite1, Sprite2, Menuitem);
@@ -554,27 +447,22 @@ cc.DOM.placeHolder = function (x) {
* var myDOMElements = [Sprite1, Sprite2, MenuItem];
* cc.DOM.convert(myDOMElements);
*/
-cc.DOM.convert = function () {
+cc.DOM.convert = function (nodeObject) {
//if passing by list, make it an array
if (arguments.length > 1) {
- return cc.DOM.convert(arguments);
- }
- else if (arguments.length == 1 && !arguments[0].length) {
- return cc.DOM.convert([arguments[0]]);
+ cc.DOM.convert(arguments);
+ return;
+ } else if (arguments.length == 1 && !arguments[0].length) {
+ cc.DOM.convert([arguments[0]]);
+ return;
}
var args = arguments[0];
for (var i = 0; i < args.length; i++) {
- //first check if its sprite or menuitem
+ //first check if its sprite
if (args[i] instanceof cc.Sprite) {
// create a canvas
if (!args[i].dom)
cc.DOM.forSprite(args[i]);
- } else if (args[i] instanceof cc.MenuItemToggle) {
- if (!args[i].dom)
- cc.DOM.forMenuToggler(args[i]);
- } else if (args[i] instanceof cc.MenuItem) {
- if (!args[i].dom)
- cc.DOM.forMenuItem(args[i]);
} else {
cc.log('DOM converter only supports sprite and menuitems yet');
}
@@ -585,177 +473,5 @@ cc.DOM.convert = function () {
};
cc.DOM.setTransform(args[i]);
args[i].setVisible(args[i].isVisible());
- if (cc.DOMEditMode) {
- //add hover event to popup inspector
- if (!cc.DOM.tooltip) {
- var style = cc.$new('style');
- style.textContent = ".CCDOMEdit:hover{border: rgba(255,0,0,0.5) 2px dashed;left: -2px;} .CCDOMEdit "
- + " #CCCloseButton{width:80px;height:15px;background: rgba(0,0,0,0.4);border:1px solid #aaaaaa;font-size: 9px;line-height:9px;color:#bbbbbb;} "
- + " .CCTipWindow .CCTipMove{cursor:move;} .CCTipWindow .CCTipRotate{cursor:w-resize;} .CCTipWindow .CCTipScale{cursor:ne-resize;} "
- + ".CCTipWindow .CCTipSkew{cursor:se-resize;} .CCTipWindow input{width:40px;background: rgba(0,0,0,0.5);color:white;border:none;border-bottom: 1px solid #fff;} "
- + "div.CCTipWindow:hover{color:rgb(50,50,255);}";
- document.body.appendChild(style);
- cc.container.style.overflow = "visible";
- var tip = cc.DOM.tooltip = cc.$new('div');
- tip.mouseDown = false;
- document.body.appendChild(tip);
- tip.addClass('CCTipWindow');
- tip.style.width = '140px';
- tip.style.height = '134px';
- tip.style.background = 'rgba(50,50,50,0.5)';
- tip.style.border = '1px rgba(255,255,255,0.5) solid';
- tip.style.borderRadius = '5px';
- tip.style.color = 'rgb(255,255,255)';
- tip.style.boxShadow = '0 0 10px 1px rgba(0,0,0,0.5)';
- tip.style.position = 'absolute';
- tip.style.display = 'none';
- tip.style.top = 0;
- tip.style.left = '-150px';
- tip.style[cc.$.pfx + "Transform"] = 'translate3d(0,0,100px)';
- tip.style[cc.$.pfx + 'UserSelect'] = 'none';
- tip.innerHTML = '
* The resolution translate on EGLView *
- * @param {Number} translateX - * @param {Number} translateY + * @param {Number} offsetLeft + * @param {Number} offsetTop */ setContentTranslateLeftTop: function(offsetLeft, offsetTop){ this._contentTranslateLeftTop = {left : offsetLeft, top : offsetTop}; @@ -194,8 +194,7 @@ cc.EGLView = cc.Class.extend(/** @lends cc.EGLView# */{ ** get the resolution translate on EGLView *
- * @param {Number} translateX - * @param {Number} translateY + * @return {cc.Size|Object} */ getContentTranslateLeftTop: function(){ return this._contentTranslateLeftTop; @@ -309,26 +308,26 @@ cc.EGLView = cc.Class.extend(/** @lends cc.EGLView# */{ this._viewPortRect = cc.rect((this._screenSize.width - viewPortW) / 2, (this._screenSize.height - viewPortH) / 2, viewPortW, viewPortH); // reset director's member variables to fit visible rect - var diretor = cc.Director.getInstance(); - diretor._winSizeInPoints = this.getDesignResolutionSize(); + var director = cc.Director.getInstance(); + director._winSizeInPoints = this.getDesignResolutionSize(); if (cc.renderContextType === cc.CANVAS) { - var width = 0, height= 0; + var locWidth = 0, locHeight= 0; if(this._resolutionPolicy === cc.RESOLUTION_POLICY.SHOW_ALL){ - width = (this._screenSize.width - viewPortW) / 2; - height = -(this._screenSize.height - viewPortH) / 2; + locWidth = (this._screenSize.width - viewPortW) / 2; + locHeight = -(this._screenSize.height - viewPortH) / 2; var context = cc.renderContext; context.beginPath(); - context.rect(width, -viewPortH + height, viewPortW, viewPortH); + context.rect(locWidth, -viewPortH + locHeight, viewPortW, viewPortH); context.clip(); context.closePath(); } - cc.renderContext.translate(width, height); + cc.renderContext.translate(locWidth, locHeight); cc.renderContext.scale(this._scaleX, this._scaleY); } else { // reset director's member variables to fit visible rect - cc.Director.getInstance()._createStatsLabel(); - cc.Director.getInstance().setGLDefaultValues(); + director._createStatsLabel(); + director.setGLDefaultValues(); } }, @@ -636,6 +635,7 @@ cc.EGLView = cc.Class.extend(/** @lends cc.EGLView# */{ } this.handleTouchesBegin(i, ids, xs, ys); }, + touchesMoved:function (touches, event) { var ids = []; var xs = []; diff --git a/extensions/CCEditBox.js b/extensions/CCEditBox.js index 857f49964f..e38dac23e2 100644 --- a/extensions/CCEditBox.js +++ b/extensions/CCEditBox.js @@ -216,7 +216,6 @@ cc.EditBox = cc.ControlButton.extend({ this.setContentSize(boxSize); this._domInputSprite = new cc.Sprite(); this._domInputSprite.setColor(cc.BLUE); - this._domInputSprite.setContentSize(cc.size(boxSize.width - 10, boxSize.height - 10)); this._domInputSprite.draw = function(){ }; //redefine draw function this.addChild(this._domInputSprite); var selfPointer = this; @@ -226,11 +225,13 @@ cc.EditBox = cc.ControlButton.extend({ this._edTxt.style.color = "#000000"; this._edTxt.style.border = 0; this._edTxt.style.background = "transparent"; - this._edTxt.style.paddingLeft = "2px"; + //this._edTxt.style.paddingLeft = "2px"; this._edTxt.style.width = "100%"; this._edTxt.style.height = "100%"; this._edTxt.style.active = 0; this._edTxt.style.outline = "medium"; + + // TODO the event listener will be remove when EditBox removes from parent. this._edTxt.addEventListener("input", function () { if (selfPointer._delegate && selfPointer._delegate.editBoxTextChanged) selfPointer._delegate.editBoxTextChanged(selfPointer, this.value); @@ -264,13 +265,13 @@ cc.EditBox = cc.ControlButton.extend({ cc.DOM.convert(this._domInputSprite); this._domInputSprite.dom.appendChild(this._edTxt); this._domInputSprite.dom.showTooltipDiv = false; - this._domInputSprite.dom.className = ""; + this._domInputSprite.dom.style.width = (boxSize.width - 6) +"px"; + this._domInputSprite.dom.style.height = (boxSize.height - 6) +"px"; + //this._domInputSprite.dom.style.borderWidth = "1px"; //this._domInputSprite.dom.style.borderStyle = "solid"; //this._domInputSprite.dom.style.borderRadius = "8px"; this._domInputSprite.canvas.remove(); - - }, /**