Skip to content

Make PageView indicator more tunable #3266

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

Merged
merged 1 commit into from
May 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions extensions/ccui/uiwidgets/scroll-widget/UIPageView.js
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,65 @@ ccui.PageView = ccui.ListView.extend(/** @lends ccui.PageView# */{
{
cc.assert(this._indicator !== null, "");
return this._indicator.getSelectedIndexColor();
},

/**
* Set color of page indicator's index nodes.
* @param {cc.Color} color Color for indicator
*/
setIndicatorIndexNodesColor: function(color)
{
if(this._indicator)
{
this._indicator.setIndexNodesColor(color);
}
},

/**
* Get the color of page indicator's index nodes.
* @returns {cc.Color}
*/
getIndicatorIndexNodesColor: function()
{
cc.assert(this._indicator !== null, "");
return this._indicator.getIndexNodesColor();
},

/**
* Set scale of page indicator's index nodes.
* @param {Number} scale Scale for indicator
*/
setIndicatorIndexNodesScale: function(indexNodesScale)
{
if(this._indicator)
{
this._indicator.setIndexNodesScale(indexNodesScale);
this._indicator.indicate(this._curPageIdx);
}
},

/**
* Get the scale of page indicator's index nodes.
* @returns {Number}
*/
getIndicatorIndexNodesScale: function()
{
cc.assert(this._indicator !== null, "");
return this._indicator.getIndexNodesScale();
},

/**
* Sets texture of indicator index nodes
* @param {String} texName
* @param {ccui.Widget.LOCAL_TEXTURE | ccui.Widget.PLIST_TEXTURE} [texType = ccui.Widget.LOCAL_TEXTURE]
*/
setIndicatorIndexNodesTexture: function(texName, texType)
{
if(this._indicator)
{
this._indicator.setIndexNodesTexture(texName, texType);
this._indicator.indicate(this._curPageIdx);
}
}
});
/**
Expand Down
129 changes: 126 additions & 3 deletions extensions/ccui/uiwidgets/scroll-widget/UIPageViewIndicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ ccui.PageViewIndicator = ccui.ProtectedNode.extend(/** @lends ccui.PageViewIndic
_indexNodes: null,
_currentIndexNode: null,
_spaceBetweenIndexNodes: 0,
_indexNodesScale: 1.0,
_indexNodesColor: null,
_useDefaultTexture: true,
_indexNodesTextureFile: "",
_indexNodesTexType: ccui.Widget.LOCAL_TEXTURE,

_className: "PageViewIndicator",

/**
Expand All @@ -47,6 +53,7 @@ ccui.PageViewIndicator = ccui.ProtectedNode.extend(/** @lends ccui.PageViewIndic
this._direction = ccui.ScrollView.DIR_HORIZONTAL;
this._indexNodes = [];
this._spaceBetweenIndexNodes = ccui.PageViewIndicator.SPACE_BETWEEN_INDEX_NODES_DEFAULT;
this._indexNodesColor = cc.color.WHITE;

this.init();

Expand Down Expand Up @@ -188,12 +195,128 @@ ccui.PageViewIndicator = ccui.ProtectedNode.extend(/** @lends ccui.PageViewIndic
return this._currentIndexNode.getColor();
},

/**
* Sets color of index nodes
* @param {cc.Color} indexNodesColor
*/
setIndexNodesColor: function(indexNodesColor)
{
this._indexNodesColor = indexNodesColor;

for(var i = 0 ; i < this._indexNodes.length; ++i)
{
this._indexNodes[i].setColor(indexNodesColor);
}
},

/**
* Gets color of index nodes
* @returns {cc.Color}
*/
getIndexNodesColor: function()
{
var locRealColor = this._indexNodesColor;
return cc.color(locRealColor.r, locRealColor.g, locRealColor.b, locRealColor.a);
},

/**
* Sets scale of index nodes
* @param {Number} indexNodesScale
*/
setIndexNodesScale: function(indexNodesScale)
{
if(this._indexNodesScale === indexNodesScale)
{
return;
}
this._indexNodesScale = indexNodesScale;

this._currentIndexNode.setScale(indexNodesScale);

for(var i = 0 ; i < this._indexNodes.length; ++i)
{
this._indexNodes[i].setScale(this,_indexNodesScale);
}

this._rearrange();
},

/**
* Gets scale of index nodes
* @returns {Number}
*/
getIndexNodesScale: function()
{
return this._indexNodesScale;
},

/**
* Sets texture of index nodes
* @param {String} texName
* @param {ccui.Widget.LOCAL_TEXTURE | ccui.Widget.PLIST_TEXTURE} [texType = ccui.Widget.LOCAL_TEXTURE]
*/
setIndexNodesTexture: function(texName, texType)
{
if(texType === undefined)
texType = ccui.Widget.LOCAL_TEXTURE;

this._useDefaultTexture = false;
this._indexNodesTextureFile = texName;
this._indexNodesTexType = texType;

switch (texType)
{
case ccui.Widget.LOCAL_TEXTURE:
this._currentIndexNode.setTexture(texName);
for(var i = 0 ; i < this._indexNodes.length; ++i)
{
this._indexNodes[i].setTexture(texName);
}
break;
case ccui.Widget.PLIST_TEXTURE:
this._currentIndexNode.setSpriteFrame(texName);
for(var i = 0 ; i < this._indexNodes.length; ++i)
{
this._indexNodes[i].setSpriteFrame(texName);
}
break;
default:
break;
}

this._rearrange();
},

_increaseNumberOfPages: function()
{
var image = new Image();
image.src = ccui.PageViewIndicator.CIRCLE_IMAGE;
var indexNode;

if(this._useDefaultTexture)
{
var image = new Image();
image.src = ccui.PageViewIndicator.CIRCLE_IMAGE;

indexNode = new cc.Sprite(image);
}
else
{
indexNode = new cc.Sprite();
switch (this._indexNodesTexType)
{
case ccui.Widget.LOCAL_TEXTURE:
indexNode.initWithFile(this._indexNodesTextureFile);
break;
case ccui.Widget.PLIST_TEXTURE:
indexNode.initWithSpriteFrameName(this._indexNodesTextureFile);
break;
default:
break;
}
}

indexNode.setColor(this._indexNodesColor);
indexNode.setScale(this._indexNodesScale);

var indexNode = new cc.Sprite(image);
this.addProtectedChild(indexNode);
this._indexNodes.push(indexNode);
},
Expand Down