Merge branch 'develop' of github.com:cocos-creator/cocos2d-x-lite into develop

This commit is contained in:
Nan Wang
2016-07-21 15:37:42 +08:00
15 changed files with 198 additions and 32 deletions
+15 -1
View File
@@ -93,7 +93,21 @@ bool TMXLayer::initWithTilesetInfo(TMXTilesetInfo *tilesetInfo, TMXLayerInfo *la
_atlasIndexArray = ccCArrayNew(totalNumberOfTiles);
this->setContentSize(CC_SIZE_PIXELS_TO_POINTS(Size(_layerSize.width * _mapTileSize.width, _layerSize.height * _mapTileSize.height)));
float width = 0;
float height = 0;
if (_layerOrientation == TMXOrientationHex) {
if (_staggerAxis == TMXStaggerAxis_X) {
height = _mapTileSize.height * (_layerSize.height + 0.5);
width = (_mapTileSize.width + _hexSideLength) * ((int)(_layerSize.width / 2)) + _mapTileSize.width * ((int)_layerSize.width % 2);
} else {
width = _mapTileSize.width * (_layerSize.width + 0.5);
height = (_mapTileSize.height + _hexSideLength) * ((int)(_layerSize.height / 2)) + _mapTileSize.height * ((int)_layerSize.height % 2);
}
} else {
width = _layerSize.width * _mapTileSize.width;
height = _layerSize.height * _mapTileSize.height;
}
this->setContentSize(CC_SIZE_PIXELS_TO_POINTS(Size(width, height)));
_useAutomaticVertexZ = false;
_vertexZvalue = 0;
+4
View File
@@ -563,6 +563,10 @@ void EventDispatcher::removeEventListener(EventListener* listener)
if (listener == nullptr)
return;
// just return if listener is in _toRemovedListeners to avoid remove listeners more than once
if (std::find(_toRemovedListeners.begin(), _toRemovedListeners.end(), listener) != _toRemovedListeners.end())
return;
bool isFound = false;
auto removeListenerInVector = [&](std::vector<EventListener*>* listeners){
@@ -44,7 +44,7 @@
#define VECTOR_INIT_VERTS_SIZE 256
#define VECTOR_KAPPA90 0.5522847493f // Length proportional to radius of a cubic bezier handle for 90deg arcs.
#define VECTOR_KAPPA90 0.5522847493f // Length proportional to radius of a cubic bezier handle for 90deg arcs.
#define EPSILON 0.0000000001f
@@ -84,12 +84,12 @@ GraphicsNode::GraphicsNode()
{
_miterLimit = 10.0f;
setDeviceRatio(2);
setDeviceRatio(1);
_strokeColor = Color4F::BLACK;
_fillColor = Color4F::WHITE;
_verts = (VecVertex*)malloc(sizeof(VecVertex) * _nVerts);
_verts = (VecVertex*)malloc(sizeof(VecVertex) * _nVerts);
_indices = (GLushort*)malloc(sizeof(GLushort) * _nIndices);
auto glprogram = GLProgram::createWithByteArrays(ccGraphicsVert, ccGraphicsFrag);
@@ -180,7 +180,7 @@ void GraphicsNode::arcTo(float x1, float y1, float x2, float y2, float radius)
a = acosf(dx0*dx1 + dy0*dy1);
d = radius / tanf(a/2.0f);
// printf("a=%f° d=%f\n", a/NVG_PI*180.0f, d);
// printf("a=%f° d=%f\n", a/NVG_PI*180.0f, d);
if (d > 10000.0f) {
lineTo(x1,y1);
@@ -641,8 +641,10 @@ void GraphicsNode::expandStroke(float w, int lineCap, int lineJoin, float miterL
vset(p1->x + (p1->dmx * w), p1->y + (p1->dmy * w), 0,1);
vset(p1->x - (p1->dmx * w), p1->y - (p1->dmy * w), 1,1);
}
p0 = p1;
p1 = pts[j+1];
if (!loop || (loop && j < (e - 1))) {
p0 = p1;
p1 = pts[j + 1];
}
}
if (loop) {
@@ -742,8 +744,11 @@ void GraphicsNode::expandFill(float w, int lineJoin, float miterLimit)
} else {
vset(p1->x + (p1->dmx * woff), p1->y + (p1->dmy * woff), 0.5f,1);
}
p0 = p1;
p1 = pts[j+1];
if (j < (pathSize - 1)) {
p0 = p1;
p1 = pts[j + 1];
}
}
} else {
for (j = 0; j < pathSize; ++j) {
@@ -794,8 +799,8 @@ void GraphicsNode::expandFill(float w, int lineJoin, float miterLimit)
// Create only half a fringe for convex shapes so that
// the shape can be rendered without stenciling.
if (convex) {
lw = woff; // This should generate the same vertex as fill inset above.
lu = 0.5f; // Set outline fade at middle.
lw = woff; // This should generate the same vertex as fill inset above.
lu = 0.5f; // Set outline fade at middle.
}
// Looping
@@ -809,8 +814,11 @@ void GraphicsNode::expandFill(float w, int lineJoin, float miterLimit)
vset(p1->x + (p1->dmx * lw), p1->y + (p1->dmy * lw), lu,1);
vset(p1->x - (p1->dmx * rw), p1->y - (p1->dmy * rw), ru,1);
}
p0 = p1;
p1 = pts[j+1];
if (j < (pathSize - 1)) {
p0 = p1;
p1 = pts[j + 1];
}
}
// Loop it
@@ -854,15 +862,17 @@ void GraphicsNode::flattenPaths()
p0 = pts.back();
}
for(int j = 0, size = pts.size(); j < size; j++) {
for (int j = 0, size = pts.size(); j < size; j++) {
// Calculate segment direction and length
p0->dx = p1->x - p0->x;
p0->dy = p1->y - p0->y;
p0->len = normalize(&p0->dx, &p0->dy);
// Advance
p0 = p1;
p1 = pts[j+1];
if (j < (size - 1)) {
p0 = p1;
p1 = pts[j + 1];
}
}
}
}
@@ -870,14 +880,14 @@ void GraphicsNode::flattenPaths()
void GraphicsNode::calculateJoins(float w, int lineJoin, float miterLimit)
{
int i, j, il, jl;
int i, j, ii, jj;
float iw = 0.0f;
if (w > 0.0f)
iw = 1.0f / w;
// Calculate which joins needs extra vertices to append, and gather vertex count.
for (i = _pathOffset, il = _nPath; i < il; i++) {
for (i = _pathOffset, ii = _nPath; i < ii; i++) {
Path* path = _paths[i];
VecPointVector& pts = path->points;
@@ -887,7 +897,7 @@ void GraphicsNode::calculateJoins(float w, int lineJoin, float miterLimit)
path->nbevel = 0;
for (j = 0, jl = pts.size(); j < jl; j++) {
for (j = 0, jj = pts.size(); j < jj; j++) {
float dlx0, dly0, dlx1, dly1, dmr2, cross, limit;
dlx0 = p0->dy;
dly0 = -p0->dx;
@@ -931,8 +941,10 @@ void GraphicsNode::calculateJoins(float w, int lineJoin, float miterLimit)
if ((p1->flags & (PT_BEVEL | PT_INNERBEVEL)) != 0)
path->nbevel++;
p0 = p1;
p1 = pts[j+1];
if (j < (jj - 1)) {
p0 = p1;
p1 = pts[j + 1];
}
}
path->convex = nleft == pts.size();
+2 -3
View File
@@ -31,7 +31,6 @@ THE SOFTWARE.
#include "base/ccMacros.h"
#include "base/CCDirector.h"
#include "platform/CCSAXParser.h"
#include "base/ccUtils.h"
#include "tinyxml2/tinyxml2.h"
#ifdef MINIZIP_FROM_SYSTEM
@@ -274,7 +273,7 @@ public:
else if (sName == "integer")
_curArray->push_back(Value(atoi(_curValue.c_str())));
else
_curArray->push_back(Value(utils::atof(_curValue.c_str())));
_curArray->push_back(Value(std::atof(_curValue.c_str())));
}
else if (SAX_DICT == curState)
{
@@ -283,7 +282,7 @@ public:
else if (sName == "integer")
(*_curDict)[_curKey] = Value(atoi(_curValue.c_str()));
else
(*_curDict)[_curKey] = Value(utils::atof(_curValue.c_str()));
(*_curDict)[_curKey] = Value(std::atof(_curValue.c_str()));
}
_curValue.clear();
@@ -74,6 +74,11 @@ public class Cocos2dxEditBoxHelper {
editBoxEditingDidEnd(index, text);
}
private static native void editBoxEditingReturn(int index);
public static void __editBoxEditingReturn(int index) {
editBoxEditingReturn(index);
}
public Cocos2dxEditBoxHelper() {
sEditBoxArray = new SparseArray<Cocos2dxEditBox>();
}
@@ -190,10 +195,14 @@ public class Cocos2dxEditBoxHelper {
// If the event is a key-down event on the "enter" button
if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
(keyCode == KeyEvent.KEYCODE_ENTER)) {
//if editbox doesn't support multiline, just hide the keyboard
if ((editBox.getInputType() & InputType.TYPE_TEXT_FLAG_MULTI_LINE) != InputType.TYPE_TEXT_FLAG_MULTI_LINE) {
Cocos2dxEditBoxHelper.runEditBoxEditingReturnInGLThread(index);
Cocos2dxEditBoxHelper.closeKeyboardOnUiThread(index);
return true;
} else {
Cocos2dxEditBoxHelper.runEditBoxEditingReturnInGLThread(index);
}
}
return false;
@@ -217,6 +226,15 @@ public class Cocos2dxEditBoxHelper {
return sViewTag++;
}
private static void runEditBoxEditingReturnInGLThread(final int index) {
Cocos2dxActivity.COCOS_ACTIVITY.runOnGLThread(new Runnable() {
@Override
public void run() {
Cocos2dxEditBoxHelper.__editBoxEditingReturn(index);
}
});
}
public static void removeEditBox(final int index) {
Cocos2dxActivity.COCOS_ACTIVITY.runOnUiThread(new Runnable() {
@Override
@@ -2128,6 +2128,85 @@ bool js_cocos2dx_CCScheduler_isScheduled(JSContext *cx, uint32_t argc, jsval *vp
return false;
}
bool js_cocos2dx_CCScheduler_pauseAllTargets(JSContext *cx, uint32_t argc, jsval *vp)
{
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
JS::RootedObject obj(cx, args.thisv().toObjectOrNull());
js_proxy_t *proxy = jsb_get_js_proxy(obj);
cocos2d::Scheduler* cobj = (cocos2d::Scheduler *)(proxy ? proxy->ptr : nullptr);
TEST_NATIVE_OBJECT(cx, cobj);
if (argc == 0) {
cobj->pauseAllTargets();
args.rval().setUndefined();
return true;
}
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1);
return false;
}
bool js_cocos2dx_CCScheduler_pauseAllTargetsWithMinPriority(JSContext *cx, uint32_t argc, jsval *vp)
{
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
JS::RootedObject obj(cx, args.thisv().toObjectOrNull());
js_proxy_t *proxy = jsb_get_js_proxy(obj);
cocos2d::Scheduler* cobj = (cocos2d::Scheduler *)(proxy ? proxy->ptr : nullptr);
TEST_NATIVE_OBJECT(cx, cobj);
bool ok = true;
if (argc == 1) {
int arg0;
ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0);
JSB_PRECONDITION2(ok, cx, false, "Error processing arguments");
cobj->pauseAllTargetsWithMinPriority(arg0);
args.rval().setUndefined();
return true;
}
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1);
return false;
}
bool js_cocos2dx_CCScheduler_resumeTargets(JSContext *cx, uint32_t argc, jsval *vp)
{
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
JS::RootedObject obj(cx, args.thisv().toObjectOrNull());
js_proxy_t *proxy = jsb_get_js_proxy(obj);
cocos2d::Scheduler* cobj = (cocos2d::Scheduler *)(proxy ? proxy->ptr : nullptr);
TEST_NATIVE_OBJECT(cx, cobj);
bool ok = true;
if (argc == 1) {
JS::RootedValue v(cx, args.get(0));
bool ok = v.isObject() && JS_ValueToObject(cx, v, &obj);
JSB_PRECONDITION3(ok, cx, false, "Error converting value to object");
JSB_PRECONDITION3(obj && JS_IsArrayObject(cx, obj), cx, false, "Object must be an array");
uint32_t len = 0;
JS_GetArrayLength(cx, obj, &len);
std::set<void*> arg0;
for (uint32_t i = 0; i < len; i++) {
JS::RootedValue value(cx);
if (JS_GetElement(cx, obj, i, &value)) {
if (value.isObject()) {
JS::RootedObject element(cx, value.toObjectOrNull());
arg0.insert(element);
}
}
}
cobj->resumeTargets(arg0);
args.rval().setUndefined();
return true;
}
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1);
return false;
}
bool js_forceGC(JSContext *cx, uint32_t argc, jsval *vp) {
JSRuntime *rt = JS_GetRuntime(cx);
JS_GC(rt);
@@ -5071,6 +5150,9 @@ void register_cocos2dx_js_core(JSContext* cx, JS::HandleObject global)
JS_DefineFunction(cx, tmpObj, "unscheduleAllCallbacksWithMinPriority", js_cocos2dx_CCScheduler_unscheduleAllCallbacksWithMinPriority, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT);
JS_DefineFunction(cx, tmpObj, "isTargetPaused", js_cocos2dx_CCScheduler_isTargetPaused, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT);
JS_DefineFunction(cx, tmpObj, "isScheduled", js_cocos2dx_CCScheduler_isScheduled, 2, JSPROP_ENUMERATE | JSPROP_PERMANENT);
JS_DefineFunction(cx, tmpObj, "pauseAllTargets", js_cocos2dx_CCScheduler_pauseAllTargets, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT);
JS_DefineFunction(cx, tmpObj, "pauseAllTargetsWithMinPriority", js_cocos2dx_CCScheduler_pauseAllTargetsWithMinPriority, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT);
JS_DefineFunction(cx, tmpObj, "resumeTargets", js_cocos2dx_CCScheduler_resumeTargets, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT);
tmpObj.set(jsb_cocos2d_ActionManager_prototype);
JS_DefineFunction(cx, tmpObj, "retain", js_cocos2dx_retain, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT);
@@ -157,13 +157,13 @@ public:
ScriptingCore::getInstance()->executeFunctionWithOwner(_JSDelegate.ref().get(), "editBoxTextChanged", 2, dataVal);
}
virtual void editBoxReturn(EditBox* editBox) override
virtual void editBoxEditingReturn(EditBox* editBox) override
{
js_proxy_t * p = jsb_get_native_proxy(editBox);
if (!p) return;
jsval arg = OBJECT_TO_JSVAL(p->obj);
ScriptingCore::getInstance()->executeFunctionWithOwner(_JSDelegate.ref().get(), "editBoxReturn", 1, &arg);
ScriptingCore::getInstance()->executeFunctionWithOwner(_JSDelegate.ref().get(), "editBoxEditingReturn", 1, &arg);
}
void setJSDelegate(JS::HandleValue pJSDelegate)
@@ -171,6 +171,10 @@
- (void)controlTextDidEndEditing:(NSNotification *)notification
{
_editState = NO;
if ( [[[notification userInfo] objectForKey:@"NSTextMovement"] intValue] == NSReturnTextMovement )
{
getEditBoxImplMac()->editBoxEditingReturn();
}
getEditBoxImplMac()->editBoxEditingDidEnd([self getText]);
}
@@ -324,6 +328,10 @@
return YES;
}
if ([replacementString isEqualToString:[NSString stringWithUTF8String:"\n"]]) {
getEditBoxImplMac()->editBoxEditingReturn();
}
if (affectedCharRange.length + affectedCharRange.location > textView.string.length) {
return NO;
}
+1 -1
View File
@@ -78,7 +78,7 @@ namespace ui {
* This method is called when the return button was pressed or the outside area of keyboard was touched.
* @param editBox The edit box object that generated the event.
*/
virtual void editBoxReturn(EditBox* editBox) = 0;
virtual void editBoxEditingReturn(EditBox* editBox) = 0;
};
@@ -48,6 +48,7 @@ namespace ui {
static void editBoxEditingDidBegin(int index);
static void editBoxEditingDidChanged(int index, const std::string& text);
static void editBoxEditingDidEnd(int index, const std::string& text);
static void editBoxEditingReturn(int index);
extern "C"{
JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxEditBoxHelper_editBoxEditingDidBegin(JNIEnv *env, jclass, jint index) {
editBoxEditingDidBegin(index);
@@ -62,6 +63,10 @@ extern "C"{
std::string textString = cocos2d::JniHelper::getStringUTFCharsJNI(env,text);
editBoxEditingDidEnd(index, textString);
}
JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxEditBoxHelper_editBoxEditingReturn(JNIEnv *env, jclass, jint index) {
editBoxEditingReturn(index);
}
}
static std::unordered_map<int, EditBoxImplAndroid*> s_allEditBoxes;
@@ -235,6 +240,15 @@ void editBoxEditingDidEnd(int index, const std::string& text)
}
}
void editBoxEditingReturn(int index)
{
auto it = s_allEditBoxes.find(index);
if (it != s_allEditBoxes.end())
{
s_allEditBoxes[index]->editBoxEditingReturn();
}
}
const char* EditBoxImplAndroid::getNativeDefaultFontName()
{
return "sans-serif";
@@ -338,7 +338,6 @@ void EditBoxImplCommon::editBoxEditingDidEnd(const std::string& text)
if (pDelegate != nullptr)
{
pDelegate->editBoxEditingDidEnd(_editBox);
pDelegate->editBoxReturn(_editBox);
}
#if CC_ENABLE_SCRIPT_BINDING
@@ -379,6 +378,15 @@ void EditBoxImplCommon::editBoxEditingChanged(const std::string& text)
}
#endif
}
void EditBoxImplCommon::editBoxEditingReturn()
{
cocos2d::ui::EditBoxDelegate *pDelegate = _editBox->getDelegate();
if (pDelegate != nullptr)
{
pDelegate->editBoxEditingReturn(_editBox);
}
}
}
@@ -93,6 +93,7 @@ public:
void editBoxEditingDidBegin();
void editBoxEditingChanged(const std::string& text);
void editBoxEditingDidEnd(const std::string& text);
void editBoxEditingReturn();
virtual bool isEditing() override = 0;
virtual void createNativeControl(const Rect& frame) = 0;
@@ -305,9 +305,11 @@
- (BOOL)textFieldShouldReturn:(UITextField *)sender
{
getEditBoxImplIOS()->editBoxEditingReturn();
if (sender == self.textInput) {
[sender resignFirstResponder];
}
return NO;
}
@@ -356,6 +358,10 @@
{
return YES;
}
if ([text isEqualToString:[NSString stringWithUTF8String:"\n"]]) {
getEditBoxImplIOS()->editBoxEditingReturn();
}
// Prevent crashing undo bug http://stackoverflow.com/questions/433337/set-the-maximum-character-length-of-a-uitextfield
if (range.length + range.location > textView.text.length) {
@@ -43,7 +43,7 @@ void ConfigParser::readConfig(const string &filepath)
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
// revert search path
searchPathArray.erase(searchPathArray.end() - 1);
searchPathArray.erase(searchPathArray.begin());
FileUtils::getInstance()->setSearchPaths(searchPathArray);
#endif
@@ -150,9 +150,9 @@ ConnectWaitLayer::ConnectWaitLayer()
ConnectWaitLayer::~ConnectWaitLayer()
{
CC_SAFE_DELETE(_imagebg);
CC_SAFE_DELETE(_imageplay);
CC_SAFE_DELETE(_imageShine);
CC_SAFE_RELEASE(_imagebg);
CC_SAFE_RELEASE(_imageplay);
CC_SAFE_RELEASE(_imageShine);
}
// clean up: ignore stdin, stdout and stderr