mirror of https://github.com/axmolengine/axmol.git
Merge branch 'v3' into fixJstestsReleaseError
This commit is contained in:
commit
e3f09d03b1
|
@ -2358,6 +2358,7 @@
|
|||
185663411B41553A009EF2AE /* js-tests */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
185664541B42364E009EF2AE /* script */,
|
||||
185664001B422F45009EF2AE /* project */,
|
||||
185663FD1B422EF0009EF2AE /* src */,
|
||||
185663FA1B422EE0009EF2AE /* project.json */,
|
||||
|
@ -3826,7 +3827,6 @@
|
|||
1AC35E0318CEE78300F37B72 /* tests */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
185664541B42364E009EF2AE /* script */,
|
||||
185663411B41553A009EF2AE /* js-tests */,
|
||||
15CBA087196EE66D005877BB /* lua-game-controller-test */,
|
||||
3E6176B51960FA6300DE83F5 /* game-controller-test */,
|
||||
|
|
|
@ -164,7 +164,7 @@ bool FontAtlas::getLetterDefinitionForChar(char16_t utf16Char, FontLetterDefinit
|
|||
if (outIterator != _letterDefinitions.end())
|
||||
{
|
||||
letterDefinition = (*outIterator).second;
|
||||
return true;
|
||||
return letterDefinition.validDefinition;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -274,25 +274,21 @@ int FontFreeType::getFontAscender() const
|
|||
unsigned char* FontFreeType::getGlyphBitmap(unsigned short theChar, long &outWidth, long &outHeight, Rect &outRect,int &xAdvance)
|
||||
{
|
||||
bool invalidChar = true;
|
||||
unsigned char * ret = nullptr;
|
||||
unsigned char* ret = nullptr;
|
||||
|
||||
do
|
||||
do
|
||||
{
|
||||
if (!_fontRef)
|
||||
break;
|
||||
|
||||
auto glyphIndex = FT_Get_Char_Index(_fontRef, theChar);
|
||||
if(!glyphIndex)
|
||||
if (_fontRef == nullptr)
|
||||
break;
|
||||
|
||||
if (_distanceFieldEnabled)
|
||||
{
|
||||
if (FT_Load_Glyph(_fontRef,glyphIndex,FT_LOAD_RENDER | FT_LOAD_NO_HINTING | FT_LOAD_NO_AUTOHINT))
|
||||
if (FT_Load_Char(_fontRef, theChar, FT_LOAD_RENDER | FT_LOAD_NO_HINTING | FT_LOAD_NO_AUTOHINT))
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (FT_Load_Glyph(_fontRef,glyphIndex,FT_LOAD_RENDER | FT_LOAD_NO_AUTOHINT))
|
||||
if (FT_Load_Char(_fontRef, theChar, FT_LOAD_RENDER | FT_LOAD_NO_AUTOHINT))
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -400,9 +396,7 @@ unsigned char* FontFreeType::getGlyphBitmap(unsigned short theChar, long &outWid
|
|||
unsigned char * FontFreeType::getGlyphBitmapWithOutline(unsigned short theChar, FT_BBox &bbox)
|
||||
{
|
||||
unsigned char* ret = nullptr;
|
||||
|
||||
FT_UInt gindex = FT_Get_Char_Index(_fontRef, theChar);
|
||||
if (FT_Load_Glyph(_fontRef, gindex, FT_LOAD_NO_BITMAP) == 0)
|
||||
if (FT_Load_Char(_fontRef, theChar, FT_LOAD_NO_BITMAP) == 0)
|
||||
{
|
||||
if (_fontRef->glyph->format == FT_GLYPH_FORMAT_OUTLINE)
|
||||
{
|
||||
|
|
|
@ -253,7 +253,8 @@ void Menu::removeChild(Node* child, bool cleanup)
|
|||
|
||||
bool Menu::onTouchBegan(Touch* touch, Event* event)
|
||||
{
|
||||
if (_state != Menu::State::WAITING || ! _visible || !_enabled)
|
||||
auto camera = Camera::getVisitingCamera();
|
||||
if (_state != Menu::State::WAITING || ! _visible || !_enabled || !camera)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -266,10 +267,11 @@ bool Menu::onTouchBegan(Touch* touch, Event* event)
|
|||
}
|
||||
}
|
||||
|
||||
_selectedItem = this->getItemForTouch(touch);
|
||||
_selectedItem = this->getItemForTouch(touch, camera);
|
||||
if (_selectedItem)
|
||||
{
|
||||
_state = Menu::State::TRACKING_TOUCH;
|
||||
_selectedWithCamera = camera;
|
||||
_selectedItem->selected();
|
||||
|
||||
return true;
|
||||
|
@ -288,6 +290,7 @@ void Menu::onTouchEnded(Touch* touch, Event* event)
|
|||
_selectedItem->activate();
|
||||
}
|
||||
_state = Menu::State::WAITING;
|
||||
_selectedWithCamera = nullptr;
|
||||
this->release();
|
||||
}
|
||||
|
||||
|
@ -306,7 +309,7 @@ void Menu::onTouchCancelled(Touch* touch, Event* event)
|
|||
void Menu::onTouchMoved(Touch* touch, Event* event)
|
||||
{
|
||||
CCASSERT(_state == Menu::State::TRACKING_TOUCH, "[Menu ccTouchMoved] -- invalid state");
|
||||
MenuItem *currentItem = this->getItemForTouch(touch);
|
||||
MenuItem *currentItem = this->getItemForTouch(touch, _selectedWithCamera);
|
||||
if (currentItem != _selectedItem)
|
||||
{
|
||||
if (_selectedItem)
|
||||
|
@ -553,12 +556,10 @@ void Menu::alignItemsInRowsWithArray(const ValueVector& columns)
|
|||
}
|
||||
}
|
||||
|
||||
MenuItem* Menu::getItemForTouch(Touch *touch)
|
||||
MenuItem* Menu::getItemForTouch(Touch *touch, const Camera *camera)
|
||||
{
|
||||
Vec2 touchLocation = touch->getLocation();
|
||||
auto camera = Camera::getVisitingCamera();
|
||||
|
||||
if (!_children.empty() && nullptr != camera)
|
||||
if (!_children.empty())
|
||||
{
|
||||
for (auto iter = _children.crbegin(); iter != _children.crend(); ++iter)
|
||||
{
|
||||
|
|
|
@ -179,7 +179,7 @@ CC_CONSTRUCTOR_ACCESS:
|
|||
/**
|
||||
* @js ctor
|
||||
*/
|
||||
Menu() : _selectedItem(nullptr) {}
|
||||
Menu() : _selectedItem(nullptr), _selectedWithCamera(nullptr) {}
|
||||
virtual ~Menu();
|
||||
|
||||
/** initializes an empty Menu */
|
||||
|
@ -195,10 +195,10 @@ protected:
|
|||
/** whether or not the menu will receive events */
|
||||
bool _enabled;
|
||||
|
||||
virtual MenuItem* getItemForTouch(Touch * touch);
|
||||
virtual MenuItem* getItemForTouch(Touch * touch, const Camera *camera);
|
||||
State _state;
|
||||
MenuItem *_selectedItem;
|
||||
|
||||
const Camera *_selectedWithCamera;
|
||||
private:
|
||||
CC_DISALLOW_COPY_AND_ASSIGN(Menu);
|
||||
};
|
||||
|
|
|
@ -282,6 +282,7 @@ bool Sprite::initWithTexture(Texture2D *texture, const Rect& rect, bool rotated)
|
|||
|
||||
Sprite::Sprite(void)
|
||||
: _batchNode(nullptr)
|
||||
, _textureAtlas(nullptr)
|
||||
, _shouldBeHidden(false)
|
||||
, _texture(nullptr)
|
||||
, _spriteFrame(nullptr)
|
||||
|
@ -607,6 +608,16 @@ void Sprite::updateTransform(void)
|
|||
|
||||
float x2 = x1 + size.width;
|
||||
float y2 = y1 + size.height;
|
||||
|
||||
if (_flippedX)
|
||||
{
|
||||
std::swap(x1, x2);
|
||||
}
|
||||
if (_flippedY)
|
||||
{
|
||||
std::swap(y1, y2);
|
||||
}
|
||||
|
||||
float x = _transformToBatch.m[12];
|
||||
float y = _transformToBatch.m[13];
|
||||
|
||||
|
@ -922,6 +933,9 @@ void Sprite::setFlippedX(bool flippedX)
|
|||
auto& v = _polyInfo.triangles.verts[i].vertices;
|
||||
v.x = _contentSize.width -v.x;
|
||||
}
|
||||
if (_textureAtlas) {
|
||||
setDirty(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -939,6 +953,9 @@ void Sprite::setFlippedY(bool flippedY)
|
|||
auto& v = _polyInfo.triangles.verts[i].vertices;
|
||||
v.y = _contentSize.height -v.y;
|
||||
}
|
||||
if (_textureAtlas) {
|
||||
setDirty(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -92,10 +92,10 @@ public:
|
|||
bool setAttachment (const std::string& slotName, const char* attachmentName);
|
||||
|
||||
// --- BlendProtocol
|
||||
virtual void setBlendFunc (const cocos2d::BlendFunc& blendFunc);
|
||||
virtual const cocos2d::BlendFunc& getBlendFunc () const;
|
||||
virtual void setOpacityModifyRGB (bool value);
|
||||
virtual bool isOpacityModifyRGB () const;
|
||||
virtual void setBlendFunc (const cocos2d::BlendFunc& blendFunc) override;
|
||||
virtual const cocos2d::BlendFunc& getBlendFunc () const override;
|
||||
virtual void setOpacityModifyRGB (bool value) override;
|
||||
virtual bool isOpacityModifyRGB () const override;
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
SkeletonRenderer ();
|
||||
|
|
|
@ -227,10 +227,10 @@ Vec2 GLView::getVisibleOrigin() const
|
|||
|
||||
void GLView::setViewPortInPoints(float x , float y , float w , float h)
|
||||
{
|
||||
experimental::Viewport vp = {(float)(x * _scaleX + _viewPortRect.origin.x),
|
||||
experimental::Viewport vp((float)(x * _scaleX + _viewPortRect.origin.x),
|
||||
(float)(y * _scaleY + _viewPortRect.origin.y),
|
||||
(float)(w * _scaleX),
|
||||
(float)(h * _scaleY)};
|
||||
(float)(h * _scaleY));
|
||||
Camera::setDefaultViewport(vp);
|
||||
}
|
||||
|
||||
|
|
|
@ -29,11 +29,9 @@ import android.hardware.Sensor;
|
|||
import android.hardware.SensorEvent;
|
||||
import android.hardware.SensorEventListener;
|
||||
import android.hardware.SensorManager;
|
||||
import android.util.Log;
|
||||
import android.view.Display;
|
||||
import android.view.Surface;
|
||||
import android.view.WindowManager;
|
||||
import android.os.Build.*;
|
||||
|
||||
public class Cocos2dxAccelerometer implements SensorEventListener {
|
||||
// ===========================================================
|
||||
|
|
|
@ -23,13 +23,6 @@ THE SOFTWARE.
|
|||
****************************************************************************/
|
||||
package org.cocos2dx.lib;
|
||||
|
||||
import javax.microedition.khronos.egl.EGL10;
|
||||
import javax.microedition.khronos.egl.EGLConfig;
|
||||
import javax.microedition.khronos.egl.EGLDisplay;
|
||||
|
||||
import org.cocos2dx.lib.Cocos2dxHelper.Cocos2dxHelperListener;
|
||||
import com.chukong.cocosplay.client.CocosPlayClient;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
@ -39,14 +32,63 @@ import android.graphics.PixelFormat;
|
|||
import android.opengl.GLSurfaceView;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.preference.PreferenceManager.OnActivityResultListener;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import com.chukong.cocosplay.client.CocosPlayClient;
|
||||
|
||||
import org.cocos2dx.lib.Cocos2dxHelper.Cocos2dxHelperListener;
|
||||
|
||||
import javax.microedition.khronos.egl.EGL10;
|
||||
import javax.microedition.khronos.egl.EGLConfig;
|
||||
import javax.microedition.khronos.egl.EGLDisplay;
|
||||
|
||||
class ResizeLayout extends FrameLayout{
|
||||
private boolean mEnableForceDoLayout = false;
|
||||
|
||||
public ResizeLayout(Context context){
|
||||
super(context);
|
||||
}
|
||||
|
||||
public ResizeLayout(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public void setEnableForceDoLayout(boolean flag){
|
||||
mEnableForceDoLayout = flag;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLayout(boolean changed, int l, int t, int r, int b) {
|
||||
super.onLayout(changed, l, t, r, b);
|
||||
if(mEnableForceDoLayout){
|
||||
/*This is a hot-fix for some android devices which don't do layout when the main window
|
||||
* is paned. We refersh the layout in 24 frames per seconds.
|
||||
* When the editBox is lose focus or when user begin to type, the do layout is disabled.
|
||||
*/
|
||||
final Handler handler = new Handler();
|
||||
handler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
//Do something after 100ms
|
||||
requestLayout();
|
||||
invalidate();
|
||||
}
|
||||
}, 1000 / 24);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelperListener {
|
||||
// ===========================================================
|
||||
|
@ -65,6 +107,11 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
|
|||
private static Cocos2dxActivity sContext = null;
|
||||
private Cocos2dxVideoHelper mVideoHelper = null;
|
||||
private Cocos2dxWebViewHelper mWebViewHelper = null;
|
||||
private Cocos2dxEditBoxHelper mEditBoxHelper = null;
|
||||
|
||||
public Cocos2dxGLSurfaceView getGLSurfaceView(){
|
||||
return mGLSurfaceView;
|
||||
}
|
||||
|
||||
public class Cocos2dxEGLConfigChooser implements GLSurfaceView.EGLConfigChooser
|
||||
{
|
||||
|
@ -169,8 +216,9 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
|
|||
};
|
||||
EGLConfig[] configs = new EGLConfig[1];
|
||||
int[] numConfigs = new int[1];
|
||||
|
||||
if (egl.eglChooseConfig(display, EGLattribs, configs, 1, numConfigs)) {
|
||||
boolean eglChooseResult = egl.eglChooseConfig(display, EGLattribs, configs, 1, numConfigs);
|
||||
if (eglChooseResult && numConfigs[0] > 0)
|
||||
{
|
||||
return configs[0];
|
||||
}
|
||||
|
||||
|
@ -179,8 +227,8 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
|
|||
EGL10.EGL_RENDERABLE_TYPE, 4, //EGL_OPENGL_ES2_BIT
|
||||
EGL10.EGL_NONE
|
||||
};
|
||||
|
||||
if(egl.eglChooseConfig(display, EGLV2attribs, null, 0, numConfigs)) {
|
||||
eglChooseResult = egl.eglChooseConfig(display, EGLV2attribs, null, 0, numConfigs);
|
||||
if(eglChooseResult && numConfigs[0] > 0) {
|
||||
int num = numConfigs[0];
|
||||
ConfigValue[] cfgVals = new ConfigValue[num];
|
||||
|
||||
|
@ -268,6 +316,13 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
|
|||
if(mWebViewHelper == null){
|
||||
mWebViewHelper = new Cocos2dxWebViewHelper(mFrameLayout);
|
||||
}
|
||||
|
||||
if(mEditBoxHelper == null){
|
||||
mEditBoxHelper = new Cocos2dxEditBoxHelper(mFrameLayout);
|
||||
}
|
||||
|
||||
Window window = this.getWindow();
|
||||
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
|
||||
}
|
||||
|
||||
//native method,call GLViewImpl::getGLContextAttrs() to get the OpenGL ES context attributions
|
||||
|
@ -293,6 +348,7 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
|
|||
if (hasFocus) {
|
||||
Cocos2dxHelper.onResume();
|
||||
mGLSurfaceView.onResume();
|
||||
mGLSurfaceView.requestFocus();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -301,6 +357,7 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
|
|||
super.onPause();
|
||||
Cocos2dxHelper.onPause();
|
||||
mGLSurfaceView.onPause();
|
||||
mGLSurfaceView.setSoftKeyboardShown(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -315,14 +372,6 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
|
|||
msg.obj = new Cocos2dxHandler.DialogMessage(pTitle, pMessage);
|
||||
this.mHandler.sendMessage(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showEditTextDialog(final String pTitle, final String pContent, final int pInputMode, final int pInputFlag, final int pReturnType, final int pMaxLength) {
|
||||
Message msg = new Message();
|
||||
msg.what = Cocos2dxHandler.HANDLER_SHOW_EDITBOX_DIALOG;
|
||||
msg.obj = new Cocos2dxHandler.EditBoxMessage(pTitle, pContent, pInputMode, pInputFlag, pReturnType, pMaxLength);
|
||||
this.mHandler.sendMessage(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runOnGLThread(final Runnable pRunnable) {
|
||||
|
@ -340,7 +389,7 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
|
|||
}
|
||||
|
||||
|
||||
protected FrameLayout mFrameLayout = null;
|
||||
protected ResizeLayout mFrameLayout = null;
|
||||
// ===========================================================
|
||||
// Methods
|
||||
// ===========================================================
|
||||
|
@ -350,7 +399,9 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
|
|||
ViewGroup.LayoutParams framelayout_params =
|
||||
new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.MATCH_PARENT);
|
||||
mFrameLayout = new FrameLayout(this);
|
||||
|
||||
mFrameLayout = new ResizeLayout(this);
|
||||
|
||||
mFrameLayout.setLayoutParams(framelayout_params);
|
||||
|
||||
// Cocos2dxEditText layout
|
||||
|
@ -360,7 +411,7 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
|
|||
Cocos2dxEditText edittext = new Cocos2dxEditText(this);
|
||||
edittext.setLayoutParams(edittext_layout_params);
|
||||
|
||||
// ...add to FrameLayout
|
||||
|
||||
mFrameLayout.addView(edittext);
|
||||
|
||||
// Cocos2dxGLSurfaceView
|
||||
|
@ -379,6 +430,7 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
|
|||
// Set framelayout as the content view
|
||||
setContentView(mFrameLayout);
|
||||
}
|
||||
|
||||
|
||||
public Cocos2dxGLSurfaceView onCreateView() {
|
||||
Cocos2dxGLSurfaceView glSurfaceView = new Cocos2dxGLSurfaceView(this);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
||||
Copyright (c) 2013-2015 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
|
@ -24,9 +24,6 @@ THE SOFTWARE.
|
|||
****************************************************************************/
|
||||
package org.cocos2dx.lib;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
|
@ -38,6 +35,9 @@ import android.text.TextPaint;
|
|||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
public final class Cocos2dxBitmap {
|
||||
// ===========================================================
|
||||
// Constants
|
||||
|
@ -211,7 +211,7 @@ public final class Cocos2dxBitmap {
|
|||
return null;
|
||||
}
|
||||
|
||||
private static int getFontSizeAccordingHeight(int height) {
|
||||
public static int getFontSizeAccordingHeight(int height) {
|
||||
TextPaint paint = new TextPaint();
|
||||
Rect bounds = new Rect();
|
||||
|
||||
|
|
|
@ -0,0 +1,238 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
Copyright (c) 2013-2015 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
package org.cocos2dx.lib;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.text.InputFilter;
|
||||
import android.text.InputType;
|
||||
import android.view.Gravity;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.widget.EditText;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
public class Cocos2dxEditBox extends EditText {
|
||||
/**
|
||||
* The user is allowed to enter any text, including line breaks.
|
||||
*/
|
||||
private final int kEditBoxInputModeAny = 0;
|
||||
|
||||
/**
|
||||
* The user is allowed to enter an e-mail address.
|
||||
*/
|
||||
private final int kEditBoxInputModeEmailAddr = 1;
|
||||
|
||||
/**
|
||||
* The user is allowed to enter an integer value.
|
||||
*/
|
||||
private final int kEditBoxInputModeNumeric = 2;
|
||||
|
||||
/**
|
||||
* The user is allowed to enter a phone number.
|
||||
*/
|
||||
private final int kEditBoxInputModePhoneNumber = 3;
|
||||
|
||||
/**
|
||||
* The user is allowed to enter a URL.
|
||||
*/
|
||||
private final int kEditBoxInputModeUrl = 4;
|
||||
|
||||
/**
|
||||
* The user is allowed to enter a real number value. This extends kEditBoxInputModeNumeric by allowing a decimal point.
|
||||
*/
|
||||
private final int kEditBoxInputModeDecimal = 5;
|
||||
|
||||
/**
|
||||
* The user is allowed to enter any text, except for line breaks.
|
||||
*/
|
||||
private final int kEditBoxInputModeSingleLine = 6;
|
||||
|
||||
/**
|
||||
* Indicates that the text entered is confidential data that should be obscured whenever possible. This implies EDIT_BOX_INPUT_FLAG_SENSITIVE.
|
||||
*/
|
||||
private final int kEditBoxInputFlagPassword = 0;
|
||||
|
||||
/**
|
||||
* Indicates that the text entered is sensitive data that the implementation must never store into a dictionary or table for use in predictive, auto-completing, or other accelerated input schemes. A credit card number is an example of sensitive data.
|
||||
*/
|
||||
private final int kEditBoxInputFlagSensitive = 1;
|
||||
|
||||
/**
|
||||
* This flag is a hint to the implementation that during text editing, the initial letter of each word should be capitalized.
|
||||
*/
|
||||
private final int kEditBoxInputFlagInitialCapsWord = 2;
|
||||
|
||||
/**
|
||||
* This flag is a hint to the implementation that during text editing, the initial letter of each sentence should be capitalized.
|
||||
*/
|
||||
private final int kEditBoxInputFlagInitialCapsSentence = 3;
|
||||
|
||||
/**
|
||||
* Capitalize all characters automatically.
|
||||
*/
|
||||
private final int kEditBoxInputFlagInitialCapsAllCharacters = 4;
|
||||
|
||||
private final int kKeyboardReturnTypeDefault = 0;
|
||||
private final int kKeyboardReturnTypeDone = 1;
|
||||
private final int kKeyboardReturnTypeSend = 2;
|
||||
private final int kKeyboardReturnTypeSearch = 3;
|
||||
private final int kKeyboardReturnTypeGo = 4;
|
||||
|
||||
private int mInputFlagConstraints;
|
||||
private int mInputModeContraints;
|
||||
private int mMaxLength;
|
||||
|
||||
public Cocos2dxEditBox(Context context){
|
||||
super(context);
|
||||
|
||||
this.setFocusable(true);
|
||||
this.setFocusableInTouchMode(true);
|
||||
|
||||
this.setInputFlag(kEditBoxInputFlagInitialCapsAllCharacters);
|
||||
this.setInputMode(kEditBoxInputModeSingleLine);
|
||||
this.setReturnType(kKeyboardReturnTypeDefault);
|
||||
this.setHintTextColor(Color.GRAY);
|
||||
this.setVisibility(View.INVISIBLE);
|
||||
this.setBackgroundColor(Color.TRANSPARENT);
|
||||
this.setTextColor(Color.WHITE);
|
||||
this.setSingleLine();
|
||||
}
|
||||
|
||||
public void setEditBoxViewRect(int left, int top, int maxWidth, int maxHeight) {
|
||||
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT,
|
||||
FrameLayout.LayoutParams.WRAP_CONTENT);
|
||||
layoutParams.leftMargin = left;
|
||||
layoutParams.topMargin = top;
|
||||
layoutParams.width = maxWidth;
|
||||
layoutParams.height = maxHeight;
|
||||
layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
|
||||
this.setLayoutParams(layoutParams);
|
||||
}
|
||||
|
||||
public void setMaxLength(int maxLength){
|
||||
this.mMaxLength = maxLength;
|
||||
|
||||
this.setFilters(new InputFilter[]{new InputFilter.LengthFilter(this.mMaxLength) });
|
||||
}
|
||||
|
||||
public void setMultilineEnabled(boolean flag){
|
||||
this.mInputModeContraints |= InputType.TYPE_TEXT_FLAG_MULTI_LINE;
|
||||
}
|
||||
|
||||
public void setReturnType(int returnType) {
|
||||
switch (returnType) {
|
||||
case kKeyboardReturnTypeDefault:
|
||||
this.setImeOptions(EditorInfo.IME_ACTION_NONE | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
|
||||
break;
|
||||
case kKeyboardReturnTypeDone:
|
||||
this.setImeOptions(EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
|
||||
break;
|
||||
case kKeyboardReturnTypeSend:
|
||||
this.setImeOptions(EditorInfo.IME_ACTION_SEND | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
|
||||
break;
|
||||
case kKeyboardReturnTypeSearch:
|
||||
this.setImeOptions(EditorInfo.IME_ACTION_SEARCH | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
|
||||
break;
|
||||
case kKeyboardReturnTypeGo:
|
||||
this.setImeOptions(EditorInfo.IME_ACTION_GO | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
|
||||
break;
|
||||
default:
|
||||
this.setImeOptions(EditorInfo.IME_ACTION_NONE | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void setInputMode(int inputMode){
|
||||
|
||||
switch (inputMode) {
|
||||
case kEditBoxInputModeAny:
|
||||
this.mInputModeContraints = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE;
|
||||
break;
|
||||
case kEditBoxInputModeEmailAddr:
|
||||
this.mInputModeContraints = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS;
|
||||
break;
|
||||
case kEditBoxInputModeNumeric:
|
||||
this.mInputModeContraints = InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED;
|
||||
break;
|
||||
case kEditBoxInputModePhoneNumber:
|
||||
this.mInputModeContraints = InputType.TYPE_CLASS_PHONE;
|
||||
break;
|
||||
case kEditBoxInputModeUrl:
|
||||
this.mInputModeContraints = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI;
|
||||
break;
|
||||
case kEditBoxInputModeDecimal:
|
||||
this.mInputModeContraints = InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_NUMBER_FLAG_SIGNED;
|
||||
break;
|
||||
case kEditBoxInputModeSingleLine:
|
||||
this.mInputModeContraints = InputType.TYPE_CLASS_TEXT;
|
||||
break;
|
||||
default:
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
this.setInputType(this.mInputModeContraints | this.mInputFlagConstraints);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(final int pKeyCode, final KeyEvent pKeyEvent) {
|
||||
switch (pKeyCode) {
|
||||
case KeyEvent.KEYCODE_BACK:
|
||||
Cocos2dxActivity activity = (Cocos2dxActivity)this.getContext();
|
||||
activity.getGLSurfaceView().requestFocus();
|
||||
return true;
|
||||
default:
|
||||
return super.onKeyDown(pKeyCode, pKeyEvent);
|
||||
}
|
||||
}
|
||||
|
||||
public void setInputFlag(int inputFlag) {
|
||||
|
||||
switch (inputFlag) {
|
||||
case kEditBoxInputFlagPassword:
|
||||
this.mInputFlagConstraints = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD;
|
||||
break;
|
||||
case kEditBoxInputFlagSensitive:
|
||||
this.mInputFlagConstraints = InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS;
|
||||
break;
|
||||
case kEditBoxInputFlagInitialCapsWord:
|
||||
this.mInputFlagConstraints = InputType.TYPE_TEXT_FLAG_CAP_WORDS;
|
||||
break;
|
||||
case kEditBoxInputFlagInitialCapsSentence:
|
||||
this.mInputFlagConstraints = InputType.TYPE_TEXT_FLAG_CAP_SENTENCES;
|
||||
break;
|
||||
case kEditBoxInputFlagInitialCapsAllCharacters:
|
||||
this.mInputFlagConstraints = InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
this.setInputType(this.mInputFlagConstraints | this.mInputModeContraints);
|
||||
}
|
||||
}
|
|
@ -1,321 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
package org.cocos2dx.lib;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.text.InputFilter;
|
||||
import android.text.InputType;
|
||||
import android.util.TypedValue;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.WindowManager;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.TextView.OnEditorActionListener;
|
||||
|
||||
public class Cocos2dxEditBoxDialog extends Dialog {
|
||||
// ===========================================================
|
||||
// Constants
|
||||
// ===========================================================
|
||||
|
||||
/**
|
||||
* The user is allowed to enter any text, including line breaks.
|
||||
*/
|
||||
private final int kEditBoxInputModeAny = 0;
|
||||
|
||||
/**
|
||||
* The user is allowed to enter an e-mail address.
|
||||
*/
|
||||
private final int kEditBoxInputModeEmailAddr = 1;
|
||||
|
||||
/**
|
||||
* The user is allowed to enter an integer value.
|
||||
*/
|
||||
private final int kEditBoxInputModeNumeric = 2;
|
||||
|
||||
/**
|
||||
* The user is allowed to enter a phone number.
|
||||
*/
|
||||
private final int kEditBoxInputModePhoneNumber = 3;
|
||||
|
||||
/**
|
||||
* The user is allowed to enter a URL.
|
||||
*/
|
||||
private final int kEditBoxInputModeUrl = 4;
|
||||
|
||||
/**
|
||||
* The user is allowed to enter a real number value. This extends kEditBoxInputModeNumeric by allowing a decimal point.
|
||||
*/
|
||||
private final int kEditBoxInputModeDecimal = 5;
|
||||
|
||||
/**
|
||||
* The user is allowed to enter any text, except for line breaks.
|
||||
*/
|
||||
private final int kEditBoxInputModeSingleLine = 6;
|
||||
|
||||
/**
|
||||
* Indicates that the text entered is confidential data that should be obscured whenever possible. This implies EDIT_BOX_INPUT_FLAG_SENSITIVE.
|
||||
*/
|
||||
private final int kEditBoxInputFlagPassword = 0;
|
||||
|
||||
/**
|
||||
* Indicates that the text entered is sensitive data that the implementation must never store into a dictionary or table for use in predictive, auto-completing, or other accelerated input schemes. A credit card number is an example of sensitive data.
|
||||
*/
|
||||
private final int kEditBoxInputFlagSensitive = 1;
|
||||
|
||||
/**
|
||||
* This flag is a hint to the implementation that during text editing, the initial letter of each word should be capitalized.
|
||||
*/
|
||||
private final int kEditBoxInputFlagInitialCapsWord = 2;
|
||||
|
||||
/**
|
||||
* This flag is a hint to the implementation that during text editing, the initial letter of each sentence should be capitalized.
|
||||
*/
|
||||
private final int kEditBoxInputFlagInitialCapsSentence = 3;
|
||||
|
||||
/**
|
||||
* Capitalize all characters automatically.
|
||||
*/
|
||||
private final int kEditBoxInputFlagInitialCapsAllCharacters = 4;
|
||||
|
||||
private final int kKeyboardReturnTypeDefault = 0;
|
||||
private final int kKeyboardReturnTypeDone = 1;
|
||||
private final int kKeyboardReturnTypeSend = 2;
|
||||
private final int kKeyboardReturnTypeSearch = 3;
|
||||
private final int kKeyboardReturnTypeGo = 4;
|
||||
|
||||
// ===========================================================
|
||||
// Fields
|
||||
// ===========================================================
|
||||
|
||||
private EditText mInputEditText;
|
||||
private TextView mTextViewTitle;
|
||||
|
||||
private final String mTitle;
|
||||
private final String mMessage;
|
||||
private final int mInputMode;
|
||||
private final int mInputFlag;
|
||||
private final int mReturnType;
|
||||
private final int mMaxLength;
|
||||
|
||||
private int mInputFlagConstraints;
|
||||
private int mInputModeContraints;
|
||||
private boolean mIsMultiline;
|
||||
|
||||
// ===========================================================
|
||||
// Constructors
|
||||
// ===========================================================
|
||||
|
||||
public Cocos2dxEditBoxDialog(final Context pContext, final String pTitle, final String pMessage, final int pInputMode, final int pInputFlag, final int pReturnType, final int pMaxLength) {
|
||||
super(pContext, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
|
||||
// super(context, R.style.Theme_Translucent);
|
||||
|
||||
this.mTitle = pTitle;
|
||||
this.mMessage = pMessage;
|
||||
this.mInputMode = pInputMode;
|
||||
this.mInputFlag = pInputFlag;
|
||||
this.mReturnType = pReturnType;
|
||||
this.mMaxLength = pMaxLength;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(final Bundle pSavedInstanceState) {
|
||||
super.onCreate(pSavedInstanceState);
|
||||
|
||||
this.getWindow().setBackgroundDrawable(new ColorDrawable(0x80000000));
|
||||
|
||||
final LinearLayout layout = new LinearLayout(this.getContext());
|
||||
layout.setOrientation(LinearLayout.VERTICAL);
|
||||
|
||||
final LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
||||
|
||||
this.mTextViewTitle = new TextView(this.getContext());
|
||||
final LinearLayout.LayoutParams textviewParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
textviewParams.leftMargin = textviewParams.rightMargin = this.convertDipsToPixels(10);
|
||||
this.mTextViewTitle.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
|
||||
layout.addView(this.mTextViewTitle, textviewParams);
|
||||
|
||||
this.mInputEditText = new EditText(this.getContext());
|
||||
final LinearLayout.LayoutParams editTextParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
editTextParams.leftMargin = editTextParams.rightMargin = this.convertDipsToPixels(10);
|
||||
|
||||
layout.addView(this.mInputEditText, editTextParams);
|
||||
|
||||
this.setContentView(layout, layoutParams);
|
||||
|
||||
this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
|
||||
this.mTextViewTitle.setText(this.mTitle);
|
||||
this.mInputEditText.setText(this.mMessage);
|
||||
|
||||
int oldImeOptions = this.mInputEditText.getImeOptions();
|
||||
this.mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
|
||||
oldImeOptions = this.mInputEditText.getImeOptions();
|
||||
|
||||
switch (this.mInputMode) {
|
||||
case kEditBoxInputModeAny:
|
||||
this.mInputModeContraints = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE;
|
||||
break;
|
||||
case kEditBoxInputModeEmailAddr:
|
||||
this.mInputModeContraints = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS;
|
||||
break;
|
||||
case kEditBoxInputModeNumeric:
|
||||
this.mInputModeContraints = InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED;
|
||||
break;
|
||||
case kEditBoxInputModePhoneNumber:
|
||||
this.mInputModeContraints = InputType.TYPE_CLASS_PHONE;
|
||||
break;
|
||||
case kEditBoxInputModeUrl:
|
||||
this.mInputModeContraints = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI;
|
||||
break;
|
||||
case kEditBoxInputModeDecimal:
|
||||
this.mInputModeContraints = InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_NUMBER_FLAG_SIGNED;
|
||||
break;
|
||||
case kEditBoxInputModeSingleLine:
|
||||
this.mInputModeContraints = InputType.TYPE_CLASS_TEXT;
|
||||
break;
|
||||
default:
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (this.mIsMultiline) {
|
||||
this.mInputModeContraints |= InputType.TYPE_TEXT_FLAG_MULTI_LINE;
|
||||
}
|
||||
|
||||
this.mInputEditText.setInputType(this.mInputModeContraints | this.mInputFlagConstraints);
|
||||
|
||||
switch (this.mInputFlag) {
|
||||
case kEditBoxInputFlagPassword:
|
||||
this.mInputFlagConstraints = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD;
|
||||
break;
|
||||
case kEditBoxInputFlagSensitive:
|
||||
this.mInputFlagConstraints = InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS;
|
||||
break;
|
||||
case kEditBoxInputFlagInitialCapsWord:
|
||||
this.mInputFlagConstraints = InputType.TYPE_TEXT_FLAG_CAP_WORDS;
|
||||
break;
|
||||
case kEditBoxInputFlagInitialCapsSentence:
|
||||
this.mInputFlagConstraints = InputType.TYPE_TEXT_FLAG_CAP_SENTENCES;
|
||||
break;
|
||||
case kEditBoxInputFlagInitialCapsAllCharacters:
|
||||
this.mInputFlagConstraints = InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
this.mInputEditText.setInputType(this.mInputFlagConstraints | this.mInputModeContraints);
|
||||
|
||||
switch (this.mReturnType) {
|
||||
case kKeyboardReturnTypeDefault:
|
||||
this.mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_ACTION_NONE);
|
||||
break;
|
||||
case kKeyboardReturnTypeDone:
|
||||
this.mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_ACTION_DONE);
|
||||
break;
|
||||
case kKeyboardReturnTypeSend:
|
||||
this.mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_ACTION_SEND);
|
||||
break;
|
||||
case kKeyboardReturnTypeSearch:
|
||||
this.mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_ACTION_SEARCH);
|
||||
break;
|
||||
case kKeyboardReturnTypeGo:
|
||||
this.mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_ACTION_GO);
|
||||
break;
|
||||
default:
|
||||
this.mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_ACTION_NONE);
|
||||
break;
|
||||
}
|
||||
|
||||
if (this.mMaxLength > 0) {
|
||||
this.mInputEditText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(this.mMaxLength) });
|
||||
}
|
||||
|
||||
final Handler initHandler = new Handler();
|
||||
initHandler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Cocos2dxEditBoxDialog.this.mInputEditText.requestFocus();
|
||||
Cocos2dxEditBoxDialog.this.mInputEditText.setSelection(Cocos2dxEditBoxDialog.this.mInputEditText.length());
|
||||
Cocos2dxEditBoxDialog.this.openKeyboard();
|
||||
}
|
||||
}, 200);
|
||||
|
||||
this.mInputEditText.setOnEditorActionListener(new OnEditorActionListener() {
|
||||
@Override
|
||||
public boolean onEditorAction(final TextView v, final int actionId, final KeyEvent event) {
|
||||
// If user didn't set keyboard type, this callback will be invoked twice with 'KeyEvent.ACTION_DOWN' and 'KeyEvent.ACTION_UP'.
|
||||
if (actionId != EditorInfo.IME_NULL || (actionId == EditorInfo.IME_NULL && event != null && event.getAction() == KeyEvent.ACTION_DOWN)) {
|
||||
Cocos2dxHelper.setEditTextDialogResult(Cocos2dxEditBoxDialog.this.mInputEditText.getText().toString());
|
||||
Cocos2dxEditBoxDialog.this.closeKeyboard();
|
||||
Cocos2dxEditBoxDialog.this.dismiss();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// ===========================================================
|
||||
// Getter & Setter
|
||||
// ===========================================================
|
||||
|
||||
// ===========================================================
|
||||
// Methods for/from SuperClass/Interfaces
|
||||
// ===========================================================
|
||||
|
||||
// ===========================================================
|
||||
// Methods
|
||||
// ===========================================================
|
||||
|
||||
private int convertDipsToPixels(final float pDIPs) {
|
||||
final float scale = this.getContext().getResources().getDisplayMetrics().density;
|
||||
return Math.round(pDIPs * scale);
|
||||
}
|
||||
|
||||
private void openKeyboard() {
|
||||
final InputMethodManager imm = (InputMethodManager) this.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.showSoftInput(this.mInputEditText, 0);
|
||||
}
|
||||
|
||||
private void closeKeyboard() {
|
||||
final InputMethodManager imm = (InputMethodManager) this.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.hideSoftInputFromWindow(this.mInputEditText.getWindowToken(), 0);
|
||||
}
|
||||
|
||||
// ===========================================================
|
||||
// Inner and Anonymous Classes
|
||||
// ===========================================================
|
||||
}
|
|
@ -0,0 +1,367 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
Copyright (c) 2013-2015 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
package org.cocos2dx.lib;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Typeface;
|
||||
import android.text.Editable;
|
||||
import android.text.InputType;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.Log;
|
||||
import android.util.SparseArray;
|
||||
import android.util.TypedValue;
|
||||
import android.view.Gravity;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
|
||||
public class Cocos2dxEditBoxHelper {
|
||||
private static final String TAG = Cocos2dxEditBoxHelper.class.getSimpleName();
|
||||
private static Cocos2dxActivity mCocos2dxActivity;
|
||||
private static ResizeLayout mFrameLayout;
|
||||
|
||||
private static SparseArray<Cocos2dxEditBox> mEditBoxArray;
|
||||
private static int mViewTag = 0;
|
||||
|
||||
//Call native methods
|
||||
private static native void editBoxEditingDidBegin(int index);
|
||||
public static void __editBoxEditingDidBegin(int index){
|
||||
editBoxEditingDidBegin(index);
|
||||
}
|
||||
|
||||
private static native void editBoxEditingChanged(int index, String text);
|
||||
public static void __editBoxEditingChanged(int index, String text){
|
||||
editBoxEditingChanged(index, text);
|
||||
}
|
||||
|
||||
private static native void editBoxEditingDidEnd(int index, String text);
|
||||
public static void __editBoxEditingDidEnd(int index, String text){
|
||||
editBoxEditingDidEnd(index, text);
|
||||
}
|
||||
|
||||
|
||||
public Cocos2dxEditBoxHelper(ResizeLayout layout) {
|
||||
Cocos2dxEditBoxHelper.mFrameLayout = layout;
|
||||
|
||||
Cocos2dxEditBoxHelper.mCocos2dxActivity = (Cocos2dxActivity) Cocos2dxActivity.getContext();
|
||||
Cocos2dxEditBoxHelper.mEditBoxArray = new SparseArray<Cocos2dxEditBox>();
|
||||
}
|
||||
|
||||
|
||||
public static int createEditBox(final int left, final int top, final int width, final int height) {
|
||||
final int index = mViewTag;
|
||||
mCocos2dxActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final Cocos2dxEditBox editBox = new Cocos2dxEditBox(mCocos2dxActivity);
|
||||
FrameLayout.LayoutParams lParams = new FrameLayout.LayoutParams(
|
||||
FrameLayout.LayoutParams.WRAP_CONTENT,
|
||||
FrameLayout.LayoutParams.WRAP_CONTENT);
|
||||
|
||||
lParams.leftMargin = left;
|
||||
lParams.topMargin = top;
|
||||
lParams.width = width;
|
||||
lParams.height = height+20;
|
||||
lParams.gravity = Gravity.TOP | Gravity.LEFT;
|
||||
|
||||
mFrameLayout.addView(editBox, lParams);
|
||||
|
||||
editBox.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(final CharSequence s, int start, int before, int count) {
|
||||
mFrameLayout.setEnableForceDoLayout(false);
|
||||
mCocos2dxActivity.runOnGLThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Cocos2dxEditBoxHelper.__editBoxEditingChanged(index, s.toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
editBox.setOnFocusChangeListener(new View.OnFocusChangeListener() {
|
||||
|
||||
@Override
|
||||
public void onFocusChange(View v, boolean hasFocus) {
|
||||
if (hasFocus) {
|
||||
mCocos2dxActivity.runOnGLThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Cocos2dxEditBoxHelper.__editBoxEditingDidBegin(index);
|
||||
}
|
||||
});
|
||||
editBox.setSelection(editBox.getText().length());
|
||||
mFrameLayout.setEnableForceDoLayout(true);
|
||||
mCocos2dxActivity.getGLSurfaceView().setSoftKeyboardShown(true);
|
||||
Log.d(TAG, "edit box get focus");
|
||||
} else {
|
||||
editBox.setVisibility(View.GONE);
|
||||
mCocos2dxActivity.runOnGLThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Cocos2dxEditBoxHelper.__editBoxEditingDidEnd(index, editBox.getText().toString());
|
||||
}
|
||||
});
|
||||
mFrameLayout.setEnableForceDoLayout(false);
|
||||
Log.d(TAG, "edit box lose focus");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
editBox.setOnKeyListener(new View.OnKeyListener() {
|
||||
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
||||
// 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.closeKeyboard(index);
|
||||
mCocos2dxActivity.getGLSurfaceView().requestFocus();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
editBox.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
||||
@Override
|
||||
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
||||
if (actionId == EditorInfo.IME_ACTION_DONE) {
|
||||
Cocos2dxEditBoxHelper.closeKeyboard(index);
|
||||
mCocos2dxActivity.getGLSurfaceView().requestFocus();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
mEditBoxArray.put(index, editBox);
|
||||
}
|
||||
});
|
||||
return mViewTag++;
|
||||
}
|
||||
|
||||
public static void removeEditBox(final int index) {
|
||||
mCocos2dxActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Cocos2dxEditBox editBox = mEditBoxArray.get(index);
|
||||
if (editBox != null) {
|
||||
mEditBoxArray.remove(index);
|
||||
mFrameLayout.removeView(editBox);
|
||||
Log.e(TAG, "remove EditBox");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void setFont(final int index, final String fontName, final float fontSize){
|
||||
mCocos2dxActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Cocos2dxEditBox editBox = mEditBoxArray.get(index);
|
||||
if (editBox != null) {
|
||||
Typeface tf;
|
||||
if (!fontName.isEmpty()) {
|
||||
tf = Typeface.create(fontName, Typeface.NORMAL);
|
||||
}else{
|
||||
tf = Typeface.DEFAULT;
|
||||
}
|
||||
//TODO: The font size is not the same across all the anroid devices...
|
||||
if (fontSize >= 0){
|
||||
editBox.setTextSize(TypedValue.COMPLEX_UNIT_SP, fontSize);
|
||||
}
|
||||
editBox.setTypeface(tf);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void setFontColor(final int index, final int red, final int green, final int blue, final int alpha){
|
||||
mCocos2dxActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Cocos2dxEditBox editBox = mEditBoxArray.get(index);
|
||||
if (editBox != null) {
|
||||
editBox.setTextColor(Color.argb(alpha, red, green, blue));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void setPlaceHolderText(final int index, final String text){
|
||||
mCocos2dxActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Cocos2dxEditBox editBox = mEditBoxArray.get(index);
|
||||
if (editBox != null) {
|
||||
editBox.setHint(text);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void setPlaceHolderTextColor(final int index, final int red, final int green, final int blue, final int alpha){
|
||||
mCocos2dxActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Cocos2dxEditBox editBox = mEditBoxArray.get(index);
|
||||
if (editBox != null) {
|
||||
editBox.setHintTextColor(Color.argb(alpha, red, green, blue));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void setMaxLength(final int index, final int maxLength) {
|
||||
mCocos2dxActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Cocos2dxEditBox editBox = mEditBoxArray.get(index);
|
||||
if (editBox != null) {
|
||||
editBox.setMaxLength(maxLength);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void setVisible(final int index, final boolean visible) {
|
||||
mCocos2dxActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Cocos2dxEditBox editBox = mEditBoxArray.get(index);
|
||||
if (editBox != null) {
|
||||
editBox.setVisibility(visible ? View.VISIBLE : View.GONE);
|
||||
if (visible) {
|
||||
editBox.requestFocus();
|
||||
Cocos2dxEditBoxHelper.openKeyboard(index);
|
||||
}else{
|
||||
mCocos2dxActivity.getGLSurfaceView().requestFocus();
|
||||
Cocos2dxEditBoxHelper.closeKeyboard(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public static void setText(final int index, final String text){
|
||||
mCocos2dxActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Cocos2dxEditBox editBox = mEditBoxArray.get(index);
|
||||
if (editBox != null) {
|
||||
editBox.setText(text);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void setReturnType(final int index, final int returnType) {
|
||||
mCocos2dxActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Cocos2dxEditBox editBox = mEditBoxArray.get(index);
|
||||
if (editBox != null) {
|
||||
editBox.setReturnType(returnType);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void setInputMode(final int index, final int inputMode) {
|
||||
mCocos2dxActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Cocos2dxEditBox editBox = mEditBoxArray.get(index);
|
||||
if (editBox != null) {
|
||||
editBox.setInputMode(inputMode);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void setInputFlag(final int index, final int inputFlag) {
|
||||
mCocos2dxActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Cocos2dxEditBox editBox = mEditBoxArray.get(index);
|
||||
if (editBox != null) {
|
||||
editBox.setInputFlag(inputFlag);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public static void setEditBoxViewRect(final int index, final int left, final int top, final int maxWidth, final int maxHeight) {
|
||||
mCocos2dxActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Cocos2dxEditBox editBox = mEditBoxArray.get(index);
|
||||
if (editBox != null) {
|
||||
editBox.setEditBoxViewRect(left, top, maxWidth, maxHeight);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void openKeyboard(int index) {
|
||||
final InputMethodManager imm = (InputMethodManager) mCocos2dxActivity.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
Cocos2dxEditBox editBox = mEditBoxArray.get(index);
|
||||
if (null != editBox) {
|
||||
imm.showSoftInput(editBox, 0);
|
||||
mCocos2dxActivity.getGLSurfaceView().setSoftKeyboardShown(true);
|
||||
}
|
||||
}
|
||||
|
||||
public static void closeKeyboard(int index) {
|
||||
final InputMethodManager imm = (InputMethodManager) mCocos2dxActivity.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
Cocos2dxEditBox editBox = mEditBoxArray.get(index);
|
||||
if (null != editBox) {
|
||||
imm.hideSoftInputFromWindow(editBox.getWindowToken(), 0);
|
||||
mCocos2dxActivity.getGLSurfaceView().setSoftKeyboardShown(false);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -23,6 +23,7 @@ THE SOFTWARE.
|
|||
****************************************************************************/
|
||||
package org.cocos2dx.lib;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.opengl.GLSurfaceView;
|
||||
import android.os.Handler;
|
||||
|
@ -31,6 +32,7 @@ import android.util.AttributeSet;
|
|||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
|
||||
public class Cocos2dxGLSurfaceView extends GLSurfaceView {
|
||||
|
@ -56,6 +58,17 @@ public class Cocos2dxGLSurfaceView extends GLSurfaceView {
|
|||
private Cocos2dxRenderer mCocos2dxRenderer;
|
||||
private Cocos2dxEditText mCocos2dxEditText;
|
||||
|
||||
public boolean isSoftKeyboardShown() {
|
||||
return mSoftKeyboardShown;
|
||||
}
|
||||
|
||||
public void setSoftKeyboardShown(boolean softKeyboardShown) {
|
||||
this.mSoftKeyboardShown = softKeyboardShown;
|
||||
}
|
||||
|
||||
private boolean mSoftKeyboardShown = false;
|
||||
|
||||
|
||||
// ===========================================================
|
||||
// Constructors
|
||||
// ===========================================================
|
||||
|
@ -187,6 +200,14 @@ public class Cocos2dxGLSurfaceView extends GLSurfaceView {
|
|||
final float[] xs = new float[pointerNumber];
|
||||
final float[] ys = new float[pointerNumber];
|
||||
|
||||
if (mSoftKeyboardShown){
|
||||
InputMethodManager imm = (InputMethodManager)this.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
View view = ((Activity)this.getContext()).getCurrentFocus();
|
||||
imm.hideSoftInputFromWindow(view.getWindowToken(),0);
|
||||
this.requestFocus();
|
||||
mSoftKeyboardShown = false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < pointerNumber; i++) {
|
||||
ids[i] = pMotionEvent.getPointerId(i);
|
||||
xs[i] = pMotionEvent.getX(i);
|
||||
|
|
|
@ -24,20 +24,19 @@ THE SOFTWARE.
|
|||
|
||||
package org.cocos2dx.lib;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
public class Cocos2dxHandler extends Handler {
|
||||
// ===========================================================
|
||||
// Constants
|
||||
// ===========================================================
|
||||
public final static int HANDLER_SHOW_DIALOG = 1;
|
||||
public final static int HANDLER_SHOW_EDITBOX_DIALOG = 2;
|
||||
|
||||
|
||||
// ===========================================================
|
||||
// Fields
|
||||
// ===========================================================
|
||||
|
@ -64,12 +63,9 @@ public class Cocos2dxHandler extends Handler {
|
|||
|
||||
public void handleMessage(Message msg) {
|
||||
switch (msg.what) {
|
||||
case Cocos2dxHandler.HANDLER_SHOW_DIALOG:
|
||||
showDialog(msg);
|
||||
break;
|
||||
case Cocos2dxHandler.HANDLER_SHOW_EDITBOX_DIALOG:
|
||||
showEditBoxDialog(msg);
|
||||
break;
|
||||
case Cocos2dxHandler.HANDLER_SHOW_DIALOG:
|
||||
showDialog(msg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -89,17 +85,7 @@ public class Cocos2dxHandler extends Handler {
|
|||
}
|
||||
}).create().show();
|
||||
}
|
||||
|
||||
private void showEditBoxDialog(Message msg) {
|
||||
EditBoxMessage editBoxMessage = (EditBoxMessage)msg.obj;
|
||||
new Cocos2dxEditBoxDialog(this.mActivity.get(),
|
||||
editBoxMessage.title,
|
||||
editBoxMessage.content,
|
||||
editBoxMessage.inputMode,
|
||||
editBoxMessage.inputFlag,
|
||||
editBoxMessage.returnType,
|
||||
editBoxMessage.maxLength).show();
|
||||
}
|
||||
|
||||
|
||||
// ===========================================================
|
||||
// Inner and Anonymous Classes
|
||||
|
@ -114,22 +100,4 @@ public class Cocos2dxHandler extends Handler {
|
|||
this.message = message;
|
||||
}
|
||||
}
|
||||
|
||||
public static class EditBoxMessage {
|
||||
public String title;
|
||||
public String content;
|
||||
public int inputMode;
|
||||
public int inputFlag;
|
||||
public int returnType;
|
||||
public int maxLength;
|
||||
|
||||
public EditBoxMessage(String title, String content, int inputMode, int inputFlag, int returnType, int maxLength){
|
||||
this.content = content;
|
||||
this.title = title;
|
||||
this.inputMode = inputMode;
|
||||
this.inputFlag = inputFlag;
|
||||
this.returnType = returnType;
|
||||
this.maxLength = maxLength;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,34 +24,31 @@ THE SOFTWARE.
|
|||
****************************************************************************/
|
||||
package org.cocos2dx.lib;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Locale;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.lang.Runnable;
|
||||
|
||||
import com.chukong.cocosplay.client.CocosPlayClient;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ComponentName; //Enhance API modification
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.ServiceConnection;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.res.AssetManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.IBinder; //Enhance API modification
|
||||
import android.os.IBinder;
|
||||
import android.os.Vibrator;
|
||||
import android.preference.PreferenceManager.OnActivityResultListener;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log; //Enhance API modification
|
||||
import android.view.Display;
|
||||
import android.view.WindowManager;
|
||||
import android.content.ServiceConnection; //Enhance API modification
|
||||
|
||||
import com.enhance.gameservice.IGameTuningService; //Enhance API modification
|
||||
import com.chukong.cocosplay.client.CocosPlayClient;
|
||||
import com.enhance.gameservice.IGameTuningService;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class Cocos2dxHelper {
|
||||
// ===========================================================
|
||||
|
@ -176,7 +173,6 @@ public class Cocos2dxHelper {
|
|||
public static String getCocos2dxPackageName() {
|
||||
return Cocos2dxHelper.sPackageName;
|
||||
}
|
||||
|
||||
public static String getCocos2dxWritablePath() {
|
||||
return Cocos2dxHelper.sFileDirectory;
|
||||
}
|
||||
|
@ -345,9 +341,6 @@ public class Cocos2dxHelper {
|
|||
Cocos2dxHelper.sCocos2dxHelperListener.showDialog(pTitle, pMessage);
|
||||
}
|
||||
|
||||
private static void showEditTextDialog(final String pTitle, final String pMessage, final int pInputMode, final int pInputFlag, final int pReturnType, final int pMaxLength) {
|
||||
Cocos2dxHelper.sCocos2dxHelperListener.showEditTextDialog(pTitle, pMessage, pInputMode, pInputFlag, pReturnType, pMaxLength);
|
||||
}
|
||||
|
||||
public static void setEditTextDialogResult(final String pResult) {
|
||||
try {
|
||||
|
@ -550,7 +543,6 @@ public class Cocos2dxHelper {
|
|||
|
||||
public static interface Cocos2dxHelperListener {
|
||||
public void showDialog(final String pTitle, final String pMessage);
|
||||
public void showEditTextDialog(final String pTitle, final String pMessage, final int pInputMode, final int pInputFlag, final int pReturnType, final int pMaxLength);
|
||||
|
||||
public void runOnGLThread(final Runnable pRunnable);
|
||||
}
|
||||
|
|
|
@ -23,44 +23,35 @@ THE SOFTWARE.
|
|||
****************************************************************************/
|
||||
package org.cocos2dx.lib;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.InflaterInputStream;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
|
||||
import java.net.ProtocolException;
|
||||
import java.net.URL;
|
||||
import java.security.KeyStore;
|
||||
import java.security.cert.Certificate;
|
||||
import java.security.cert.CertificateFactory;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.InflaterInputStream;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import javax.net.ssl.SSLContext;
|
||||
|
||||
import java.security.cert.Certificate;
|
||||
import java.security.cert.CertificateFactory;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.security.KeyStore;
|
||||
|
||||
import javax.net.ssl.TrustManagerFactory;
|
||||
|
||||
import org.cocos2dx.lib.Cocos2dxHelper;
|
||||
|
||||
import android.content.res.AssetManager;
|
||||
import android.util.Log;
|
||||
|
||||
public class Cocos2dxHttpURLConnection
|
||||
{
|
||||
private static final String POST_METHOD = "POST" ;
|
||||
|
|
|
@ -25,15 +25,15 @@ THE SOFTWARE.
|
|||
|
||||
package org.cocos2dx.lib;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
|
||||
import com.chukong.cocosplay.client.CocosPlayClient;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.AssetFileDescriptor;
|
||||
import android.media.MediaPlayer;
|
||||
import android.util.Log;
|
||||
|
||||
import com.chukong.cocosplay.client.CocosPlayClient;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
|
||||
public class Cocos2dxMusic {
|
||||
// ===========================================================
|
||||
// Constants
|
||||
|
|
|
@ -23,12 +23,10 @@ THE SOFTWARE.
|
|||
****************************************************************************/
|
||||
package org.cocos2dx.lib;
|
||||
|
||||
import javax.microedition.khronos.egl.EGLConfig;
|
||||
import javax.microedition.khronos.opengles.GL10;
|
||||
|
||||
import android.opengl.GLSurfaceView;
|
||||
|
||||
import org.cocos2dx.lib.Cocos2dxHelper;
|
||||
import javax.microedition.khronos.egl.EGLConfig;
|
||||
import javax.microedition.khronos.opengles.GL10;
|
||||
public class Cocos2dxRenderer implements GLSurfaceView.Renderer {
|
||||
// ===========================================================
|
||||
// Constants
|
||||
|
|
|
@ -24,12 +24,6 @@ THE SOFTWARE.
|
|||
****************************************************************************/
|
||||
package org.cocos2dx.lib;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import android.content.Context;
|
||||
import android.media.AudioManager;
|
||||
import android.media.SoundPool;
|
||||
|
@ -37,6 +31,13 @@ import android.util.Log;
|
|||
|
||||
import com.chukong.cocosplay.client.CocosPlayClient;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class Cocos2dxSound {
|
||||
// ===========================================================
|
||||
// Constants
|
||||
|
|
|
@ -24,11 +24,11 @@ THE SOFTWARE.
|
|||
****************************************************************************/
|
||||
package org.cocos2dx.lib;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Typeface;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class Cocos2dxTypefaces {
|
||||
// ===========================================================
|
||||
// Constants
|
||||
|
|
|
@ -24,10 +24,6 @@ THE SOFTWARE.
|
|||
|
||||
package org.cocos2dx.lib;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
import org.cocos2dx.lib.Cocos2dxVideoView.OnVideoEventListener;
|
||||
|
||||
import android.graphics.Rect;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
|
@ -35,6 +31,10 @@ import android.util.SparseArray;
|
|||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import org.cocos2dx.lib.Cocos2dxVideoView.OnVideoEventListener;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
public class Cocos2dxVideoHelper {
|
||||
|
||||
private FrameLayout mLayout = null;
|
||||
|
|
|
@ -34,11 +34,11 @@ import android.view.SurfaceView;
|
|||
import android.widget.FrameLayout;
|
||||
import android.widget.MediaController.MediaPlayerControl;
|
||||
|
||||
import com.chukong.cocosplay.client.CocosPlayClient;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
import com.chukong.cocosplay.client.CocosPlayClient;
|
||||
|
||||
public class Cocos2dxVideoView extends SurfaceView implements MediaPlayerControl {
|
||||
private String TAG = "Cocos2dxVideoView";
|
||||
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
package org.cocos2dx.lib;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URI;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
@ -12,6 +9,9 @@ import android.webkit.WebView;
|
|||
import android.webkit.WebViewClient;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URI;
|
||||
|
||||
public class Cocos2dxWebView extends WebView {
|
||||
private static final String TAG = Cocos2dxWebViewHelper.class.getSimpleName();
|
||||
|
||||
|
|
|
@ -6,12 +6,12 @@ import android.util.SparseArray;
|
|||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import com.chukong.cocosplay.client.CocosPlayClient;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.FutureTask;
|
||||
|
||||
import com.chukong.cocosplay.client.CocosPlayClient;
|
||||
|
||||
|
||||
public class Cocos2dxWebViewHelper {
|
||||
private static final String TAG = Cocos2dxWebViewHelper.class.getSimpleName();
|
||||
|
|
|
@ -38,6 +38,7 @@ THE SOFTWARE.
|
|||
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
|
||||
|
||||
#define CLASS_NAME "org/cocos2dx/lib/Cocos2dxHelper"
|
||||
#define EDITBOX_CLASS_NAME "org/cocos2dx/lib/Cocos2dxEditBoxHelper"
|
||||
|
||||
static EditTextCallback s_editTextCallback = nullptr;
|
||||
static void* s_ctx = nullptr;
|
||||
|
@ -76,6 +77,7 @@ extern "C" {
|
|||
if (s_editTextCallback) s_editTextCallback("", s_ctx);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const char * getApkPath() {
|
||||
|
@ -106,35 +108,6 @@ void showDialogJNI(const char * message, const char * title) {
|
|||
}
|
||||
}
|
||||
|
||||
void showEditTextDialogJNI(const char* title, const char* message, int inputMode, int inputFlag, int returnType, int maxLength, EditTextCallback callback, void* ctx) {
|
||||
if (message == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
s_editTextCallback = callback;
|
||||
s_ctx = ctx;
|
||||
|
||||
JniMethodInfo t;
|
||||
if (JniHelper::getStaticMethodInfo(t, CLASS_NAME, "showEditTextDialog", "(Ljava/lang/String;Ljava/lang/String;IIII)V")) {
|
||||
jstring stringArg1;
|
||||
|
||||
if (!title) {
|
||||
|
||||
stringArg1 = t.env->NewStringUTF("");
|
||||
} else {
|
||||
stringArg1 = cocos2d::StringUtils::newStringUTFJNI(t.env, title);
|
||||
}
|
||||
|
||||
jstring stringArg2 = cocos2d::StringUtils::newStringUTFJNI(t.env, message);
|
||||
|
||||
t.env->CallStaticVoidMethod(t.classID, t.methodID, stringArg1, stringArg2,inputMode, inputFlag, returnType, maxLength);
|
||||
|
||||
t.env->DeleteLocalRef(stringArg1);
|
||||
t.env->DeleteLocalRef(stringArg2);
|
||||
t.env->DeleteLocalRef(t.classID);
|
||||
}
|
||||
}
|
||||
|
||||
void terminateProcessJNI() {
|
||||
JniMethodInfo t;
|
||||
|
||||
|
@ -417,6 +390,168 @@ void deleteValueForKeyJNI(const char* key)
|
|||
}
|
||||
}
|
||||
|
||||
int addEditBoxJNI(int left, int top, int width, int height){
|
||||
JniMethodInfo t;
|
||||
|
||||
int ret = -1;
|
||||
if (JniHelper::getStaticMethodInfo(t, EDITBOX_CLASS_NAME, "createEditBox", "(IIII)I")) {
|
||||
ret = t.env->CallStaticIntMethod(t.classID, t.methodID, left, top, width, height);
|
||||
t.env->DeleteLocalRef(t.classID);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void removeEditBoxJNI(int index)
|
||||
{
|
||||
JniMethodInfo t;
|
||||
|
||||
if (JniHelper::getStaticMethodInfo(t, EDITBOX_CLASS_NAME, "removeEditBox", "(I)V")) {
|
||||
t.env->CallStaticVoidMethod(t.classID, t.methodID, index);
|
||||
t.env->DeleteLocalRef(t.classID);
|
||||
}
|
||||
}
|
||||
|
||||
void setEditBoxViewRectJNI(int index, int left, int top, int width, int height)
|
||||
{
|
||||
JniMethodInfo t;
|
||||
|
||||
if (JniHelper::getStaticMethodInfo(t, EDITBOX_CLASS_NAME, "setEditBoxViewRect", "(IIIII)V")) {
|
||||
t.env->CallStaticVoidMethod(t.classID, t.methodID, index, left, top, width, height);
|
||||
t.env->DeleteLocalRef(t.classID);
|
||||
}
|
||||
}
|
||||
|
||||
void setMaxLengthJNI(int index, int maxLength)
|
||||
{
|
||||
JniMethodInfo t;
|
||||
|
||||
if (JniHelper::getStaticMethodInfo(t, EDITBOX_CLASS_NAME, "setMaxLength", "(II)V")) {
|
||||
t.env->CallStaticVoidMethod(t.classID, t.methodID, index, maxLength);
|
||||
t.env->DeleteLocalRef(t.classID);
|
||||
}
|
||||
}
|
||||
|
||||
void openEditBoxKeyboardJNI(int index)
|
||||
{
|
||||
JniMethodInfo t;
|
||||
|
||||
if (JniHelper::getStaticMethodInfo(t, EDITBOX_CLASS_NAME, "openKeyboard", "(I)V")) {
|
||||
t.env->CallStaticVoidMethod(t.classID, t.methodID, index);
|
||||
t.env->DeleteLocalRef(t.classID);
|
||||
}
|
||||
}
|
||||
|
||||
void closeEditBoxKeyboardJNI(int index)
|
||||
{
|
||||
JniMethodInfo t;
|
||||
|
||||
if (JniHelper::getStaticMethodInfo(t, EDITBOX_CLASS_NAME, "closeKeyboard", "(I)V")) {
|
||||
t.env->CallStaticVoidMethod(t.classID, t.methodID, index);
|
||||
t.env->DeleteLocalRef(t.classID);
|
||||
}
|
||||
}
|
||||
|
||||
void setVisibleEditBoxJNI(int index, bool visibility)
|
||||
{
|
||||
JniMethodInfo t;
|
||||
|
||||
if (JniHelper::getStaticMethodInfo(t, EDITBOX_CLASS_NAME, "setVisible", "(IZ)V")) {
|
||||
t.env->CallStaticVoidMethod(t.classID, t.methodID, index, visibility);
|
||||
t.env->DeleteLocalRef(t.classID);
|
||||
}
|
||||
}
|
||||
|
||||
void setReturnTypeEditBoxJNI(int index, int returnType)
|
||||
{
|
||||
JniMethodInfo t;
|
||||
|
||||
if (JniHelper::getStaticMethodInfo(t, EDITBOX_CLASS_NAME, "setReturnType", "(II)V")) {
|
||||
t.env->CallStaticVoidMethod(t.classID, t.methodID, index, returnType);
|
||||
t.env->DeleteLocalRef(t.classID);
|
||||
}
|
||||
}
|
||||
|
||||
void setInputFlagEditBoxJNI(int index, int returnType)
|
||||
{
|
||||
JniMethodInfo t;
|
||||
|
||||
if (JniHelper::getStaticMethodInfo(t, EDITBOX_CLASS_NAME, "setInputFlag", "(II)V")) {
|
||||
t.env->CallStaticVoidMethod(t.classID, t.methodID, index, returnType);
|
||||
t.env->DeleteLocalRef(t.classID);
|
||||
}
|
||||
}
|
||||
|
||||
void setInputModeEditBoxJNI(int index, int inputMode)
|
||||
{
|
||||
JniMethodInfo t;
|
||||
|
||||
if (JniHelper::getStaticMethodInfo(t, EDITBOX_CLASS_NAME, "setInputMode", "(II)V")) {
|
||||
t.env->CallStaticVoidMethod(t.classID, t.methodID, index, inputMode);
|
||||
t.env->DeleteLocalRef(t.classID);
|
||||
}
|
||||
}
|
||||
|
||||
void setTextEditBoxJNI(int index, const char* text)
|
||||
{
|
||||
JniMethodInfo t;
|
||||
|
||||
if (JniHelper::getStaticMethodInfo(t, EDITBOX_CLASS_NAME, "setText", "(ILjava/lang/String;)V")) {
|
||||
jstring stringText = StringUtils::newStringUTFJNI(t.env,text);
|
||||
t.env->CallStaticVoidMethod(t.classID, t.methodID,index, stringText);
|
||||
t.env->DeleteLocalRef(stringText);
|
||||
t.env->DeleteLocalRef(t.classID);
|
||||
}
|
||||
}
|
||||
|
||||
void setFontEditBoxJNI(int index, const char* fontName, float fontSize)
|
||||
{
|
||||
JniMethodInfo t;
|
||||
|
||||
if (JniHelper::getStaticMethodInfo(t, EDITBOX_CLASS_NAME, "setFont", "(ILjava/lang/String;F)V")) {
|
||||
jstring stringText = StringUtils::newStringUTFJNI(t.env,fontName);
|
||||
t.env->CallStaticVoidMethod(t.classID, t.methodID,index, stringText, fontSize);
|
||||
|
||||
t.env->DeleteLocalRef(t.classID);
|
||||
t.env->DeleteLocalRef(stringText);
|
||||
}
|
||||
}
|
||||
|
||||
void setFontColorEditBoxJNI(int index, int red, int green, int blue, int alpha)
|
||||
{
|
||||
JniMethodInfo t;
|
||||
|
||||
if (JniHelper::getStaticMethodInfo(t, EDITBOX_CLASS_NAME, "setFontColor", "(IIIII)V")) {
|
||||
t.env->CallStaticVoidMethod(t.classID, t.methodID,index, red, green, blue, alpha);
|
||||
|
||||
t.env->DeleteLocalRef(t.classID);
|
||||
}
|
||||
}
|
||||
|
||||
void setPlaceHolderTextEditBoxJNI(int index, const char* text)
|
||||
{
|
||||
JniMethodInfo t;
|
||||
|
||||
if (JniHelper::getStaticMethodInfo(t, EDITBOX_CLASS_NAME, "setPlaceHolderText", "(ILjava/lang/String;)V")) {
|
||||
jstring stringText = StringUtils::newStringUTFJNI(t.env,text);
|
||||
t.env->CallStaticVoidMethod(t.classID, t.methodID,index, stringText);
|
||||
|
||||
t.env->DeleteLocalRef(t.classID);
|
||||
t.env->DeleteLocalRef(stringText);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void setPlaceHolderTextColorEditBoxJNI(int index, int red, int green, int blue, int alpha)
|
||||
{
|
||||
JniMethodInfo t;
|
||||
|
||||
if (JniHelper::getStaticMethodInfo(t, EDITBOX_CLASS_NAME, "setPlaceHolderTextColor", "(IIIII)V")) {
|
||||
t.env->CallStaticVoidMethod(t.classID, t.methodID,index, red, green, blue, alpha);
|
||||
|
||||
t.env->DeleteLocalRef(t.classID);
|
||||
}
|
||||
}
|
||||
|
||||
void conversionEncodingJNI(const char* src, int byteSize, const char* fromCharset, char* dst, const char* newCharset)
|
||||
{
|
||||
JniMethodInfo methodInfo;
|
||||
|
|
|
@ -31,7 +31,6 @@ typedef void (*EditTextCallback)(const char* text, void* ctx);
|
|||
|
||||
extern const char * getApkPath();
|
||||
extern void showDialogJNI(const char * message, const char * title);
|
||||
extern void showEditTextDialogJNI(const char* title, const char* content, int inputMode, int inputFlag, int returnType, int maxLength, EditTextCallback callback, void* ctx);
|
||||
extern void terminateProcessJNI();
|
||||
extern std::string getCurrentLanguageJNI();
|
||||
extern std::string getPackageNameJNI();
|
||||
|
@ -54,7 +53,22 @@ extern void setFloatForKeyJNI(const char* key, float value);
|
|||
extern void setDoubleForKeyJNI(const char* key, double value);
|
||||
extern void setStringForKeyJNI(const char* key, const char* value);
|
||||
extern void deleteValueForKeyJNI(const char* key);
|
||||
|
||||
extern void conversionEncodingJNI(const char* src, int byteSize, const char* fromCharset, char* dst, const char* newCharset);
|
||||
//Added for new Android EditBox
|
||||
extern int addEditBoxJNI(int left, int top, int width, int height);
|
||||
extern void removeEditBoxJNI(int index);
|
||||
extern void setEditBoxViewRectJNI(int index, int left, int top, int width, int height);
|
||||
extern void setMaxLengthJNI(int index, int maxLength);
|
||||
extern void openEditBoxKeyboardJNI(int index);
|
||||
extern void closeEditBoxKeyboardJNI(int index);
|
||||
extern void setVisibleEditBoxJNI(int index, bool visibility);
|
||||
extern void setReturnTypeEditBoxJNI(int index, int returnType);
|
||||
extern void setInputFlagEditBoxJNI(int index, int inputFlag);
|
||||
extern void setInputModeEditBoxJNI(int index, int inputMode);
|
||||
extern void setTextEditBoxJNI(int index, const char* text);
|
||||
extern void setFontEditBoxJNI(int index, const char* fontName, float fontSize);
|
||||
extern void setFontColorEditBoxJNI(int index, int red, int green, int blue, int alpha);
|
||||
extern void setPlaceHolderTextEditBoxJNI(int index, const char* text);
|
||||
extern void setPlaceHolderTextColorEditBoxJNI(int index, int red, int green, int blue, int alpha);
|
||||
|
||||
#endif /* __Java_org_cocos2dx_lib_Cocos2dxHelper_H__ */
|
||||
|
|
|
@ -572,10 +572,10 @@ void GLViewImpl::setFrameSize(float width, float height)
|
|||
|
||||
void GLViewImpl::setViewPortInPoints(float x , float y , float w , float h)
|
||||
{
|
||||
experimental::Viewport vp = {(float)(x * _scaleX * _retinaFactor * _frameZoomFactor + _viewPortRect.origin.x * _retinaFactor * _frameZoomFactor),
|
||||
experimental::Viewport vp((float)(x * _scaleX * _retinaFactor * _frameZoomFactor + _viewPortRect.origin.x * _retinaFactor * _frameZoomFactor),
|
||||
(float)(y * _scaleY * _retinaFactor * _frameZoomFactor + _viewPortRect.origin.y * _retinaFactor * _frameZoomFactor),
|
||||
(float)(w * _scaleX * _retinaFactor * _frameZoomFactor),
|
||||
(float)(h * _scaleY * _retinaFactor * _frameZoomFactor)};
|
||||
(float)(h * _scaleY * _retinaFactor * _frameZoomFactor));
|
||||
Camera::setDefaultViewport(vp);
|
||||
}
|
||||
|
||||
|
|
|
@ -50,16 +50,6 @@ setBonesToSetupPose : function (
|
|||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method isOpacityModifyRGB
|
||||
* @return {bool}
|
||||
*/
|
||||
isOpacityModifyRGB : function (
|
||||
)
|
||||
{
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method initWithData
|
||||
* @param {spSkeletonData} arg0
|
||||
|
@ -90,16 +80,6 @@ setSlotsToSetupPose : function (
|
|||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setOpacityModifyRGB
|
||||
* @param {bool} arg0
|
||||
*/
|
||||
setOpacityModifyRGB : function (
|
||||
bool
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setToSetupPose
|
||||
*/
|
||||
|
|
|
@ -4703,6 +4703,18 @@ long
|
|||
return ;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method convertBoundingBoxToScreen
|
||||
* @param {cc.Node} arg0
|
||||
* @return {rect_object}
|
||||
*/
|
||||
convertBoundingBoxToScreen : function (
|
||||
node
|
||||
)
|
||||
{
|
||||
return cc.Rect;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method changeLayoutSystemActiveState
|
||||
* @param {bool} arg0
|
||||
|
|
|
@ -145,24 +145,6 @@ bool js_cocos2dx_spine_SkeletonRenderer_setBonesToSetupPose(JSContext *cx, uint3
|
|||
JS_ReportError(cx, "js_cocos2dx_spine_SkeletonRenderer_setBonesToSetupPose : wrong number of arguments: %d, was expecting %d", argc, 0);
|
||||
return false;
|
||||
}
|
||||
bool js_cocos2dx_spine_SkeletonRenderer_isOpacityModifyRGB(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);
|
||||
spine::SkeletonRenderer* cobj = (spine::SkeletonRenderer *)(proxy ? proxy->ptr : NULL);
|
||||
JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_spine_SkeletonRenderer_isOpacityModifyRGB : Invalid Native Object");
|
||||
if (argc == 0) {
|
||||
bool ret = cobj->isOpacityModifyRGB();
|
||||
jsval jsret = JSVAL_NULL;
|
||||
jsret = BOOLEAN_TO_JSVAL(ret);
|
||||
args.rval().set(jsret);
|
||||
return true;
|
||||
}
|
||||
|
||||
JS_ReportError(cx, "js_cocos2dx_spine_SkeletonRenderer_isOpacityModifyRGB : wrong number of arguments: %d, was expecting %d", argc, 0);
|
||||
return false;
|
||||
}
|
||||
bool js_cocos2dx_spine_SkeletonRenderer_initWithData(JSContext *cx, uint32_t argc, jsval *vp)
|
||||
{
|
||||
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
||||
|
@ -231,26 +213,6 @@ bool js_cocos2dx_spine_SkeletonRenderer_setSlotsToSetupPose(JSContext *cx, uint3
|
|||
JS_ReportError(cx, "js_cocos2dx_spine_SkeletonRenderer_setSlotsToSetupPose : wrong number of arguments: %d, was expecting %d", argc, 0);
|
||||
return false;
|
||||
}
|
||||
bool js_cocos2dx_spine_SkeletonRenderer_setOpacityModifyRGB(JSContext *cx, uint32_t argc, jsval *vp)
|
||||
{
|
||||
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
||||
bool ok = true;
|
||||
JS::RootedObject obj(cx, args.thisv().toObjectOrNull());
|
||||
js_proxy_t *proxy = jsb_get_js_proxy(obj);
|
||||
spine::SkeletonRenderer* cobj = (spine::SkeletonRenderer *)(proxy ? proxy->ptr : NULL);
|
||||
JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_spine_SkeletonRenderer_setOpacityModifyRGB : Invalid Native Object");
|
||||
if (argc == 1) {
|
||||
bool arg0;
|
||||
arg0 = JS::ToBoolean(args.get(0));
|
||||
JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_spine_SkeletonRenderer_setOpacityModifyRGB : Error processing arguments");
|
||||
cobj->setOpacityModifyRGB(arg0);
|
||||
args.rval().setUndefined();
|
||||
return true;
|
||||
}
|
||||
|
||||
JS_ReportError(cx, "js_cocos2dx_spine_SkeletonRenderer_setOpacityModifyRGB : wrong number of arguments: %d, was expecting %d", argc, 1);
|
||||
return false;
|
||||
}
|
||||
bool js_cocos2dx_spine_SkeletonRenderer_setToSetupPose(JSContext *cx, uint32_t argc, jsval *vp)
|
||||
{
|
||||
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
||||
|
@ -913,11 +875,9 @@ void js_register_cocos2dx_spine_SkeletonRenderer(JSContext *cx, JS::HandleObject
|
|||
JS_FN("getDebugSlotsEnabled", js_cocos2dx_spine_SkeletonRenderer_getDebugSlotsEnabled, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||
JS_FN("setAttachment", js_cocos2dx_spine_SkeletonRenderer_setAttachment, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||
JS_FN("setBonesToSetupPose", js_cocos2dx_spine_SkeletonRenderer_setBonesToSetupPose, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||
JS_FN("isOpacityModifyRGB", js_cocos2dx_spine_SkeletonRenderer_isOpacityModifyRGB, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||
JS_FN("initWithData", js_cocos2dx_spine_SkeletonRenderer_initWithData, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||
JS_FN("setDebugSlotsEnabled", js_cocos2dx_spine_SkeletonRenderer_setDebugSlotsEnabled, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||
JS_FN("setSlotsToSetupPose", js_cocos2dx_spine_SkeletonRenderer_setSlotsToSetupPose, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||
JS_FN("setOpacityModifyRGB", js_cocos2dx_spine_SkeletonRenderer_setOpacityModifyRGB, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||
JS_FN("setToSetupPose", js_cocos2dx_spine_SkeletonRenderer_setToSetupPose, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||
JS_FN("getBlendFunc", js_cocos2dx_spine_SkeletonRenderer_getBlendFunc, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||
JS_FN("drawSkeleton", js_cocos2dx_spine_SkeletonRenderer_drawSkeleton, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||
|
|
|
@ -16,11 +16,9 @@ bool js_cocos2dx_spine_SkeletonRenderer_setTimeScale(JSContext *cx, uint32_t arg
|
|||
bool js_cocos2dx_spine_SkeletonRenderer_getDebugSlotsEnabled(JSContext *cx, uint32_t argc, jsval *vp);
|
||||
bool js_cocos2dx_spine_SkeletonRenderer_setAttachment(JSContext *cx, uint32_t argc, jsval *vp);
|
||||
bool js_cocos2dx_spine_SkeletonRenderer_setBonesToSetupPose(JSContext *cx, uint32_t argc, jsval *vp);
|
||||
bool js_cocos2dx_spine_SkeletonRenderer_isOpacityModifyRGB(JSContext *cx, uint32_t argc, jsval *vp);
|
||||
bool js_cocos2dx_spine_SkeletonRenderer_initWithData(JSContext *cx, uint32_t argc, jsval *vp);
|
||||
bool js_cocos2dx_spine_SkeletonRenderer_setDebugSlotsEnabled(JSContext *cx, uint32_t argc, jsval *vp);
|
||||
bool js_cocos2dx_spine_SkeletonRenderer_setSlotsToSetupPose(JSContext *cx, uint32_t argc, jsval *vp);
|
||||
bool js_cocos2dx_spine_SkeletonRenderer_setOpacityModifyRGB(JSContext *cx, uint32_t argc, jsval *vp);
|
||||
bool js_cocos2dx_spine_SkeletonRenderer_setToSetupPose(JSContext *cx, uint32_t argc, jsval *vp);
|
||||
bool js_cocos2dx_spine_SkeletonRenderer_getBlendFunc(JSContext *cx, uint32_t argc, jsval *vp);
|
||||
bool js_cocos2dx_spine_SkeletonRenderer_drawSkeleton(JSContext *cx, uint32_t argc, jsval *vp);
|
||||
|
|
|
@ -12140,6 +12140,32 @@ bool js_cocos2dx_ui_Helper_getSubStringOfUTF8String(JSContext *cx, uint32_t argc
|
|||
return false;
|
||||
}
|
||||
|
||||
bool js_cocos2dx_ui_Helper_convertBoundingBoxToScreen(JSContext *cx, uint32_t argc, jsval *vp)
|
||||
{
|
||||
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
||||
bool ok = true;
|
||||
if (argc == 1) {
|
||||
cocos2d::Node* arg0;
|
||||
do {
|
||||
if (args.get(0).isNull()) { arg0 = nullptr; break; }
|
||||
if (!args.get(0).isObject()) { ok = false; break; }
|
||||
js_proxy_t *jsProxy;
|
||||
JSObject *tmpObj = args.get(0).toObjectOrNull();
|
||||
jsProxy = jsb_get_js_proxy(tmpObj);
|
||||
arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL);
|
||||
JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object");
|
||||
} while (0);
|
||||
JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Helper_convertBoundingBoxToScreen : Error processing arguments");
|
||||
cocos2d::Rect ret = cocos2d::ui::Helper::convertBoundingBoxToScreen(arg0);
|
||||
jsval jsret = JSVAL_NULL;
|
||||
jsret = ccrect_to_jsval(cx, ret);
|
||||
args.rval().set(jsret);
|
||||
return true;
|
||||
}
|
||||
JS_ReportError(cx, "js_cocos2dx_ui_Helper_convertBoundingBoxToScreen : wrong number of arguments");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool js_cocos2dx_ui_Helper_changeLayoutSystemActiveState(JSContext *cx, uint32_t argc, jsval *vp)
|
||||
{
|
||||
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
||||
|
@ -12333,6 +12359,7 @@ void js_register_cocos2dx_ui_Helper(JSContext *cx, JS::HandleObject global) {
|
|||
|
||||
static JSFunctionSpec st_funcs[] = {
|
||||
JS_FN("getSubStringOfUTF8String", js_cocos2dx_ui_Helper_getSubStringOfUTF8String, 3, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||
JS_FN("convertBoundingBoxToScreen", js_cocos2dx_ui_Helper_convertBoundingBoxToScreen, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||
JS_FN("changeLayoutSystemActiveState", js_cocos2dx_ui_Helper_changeLayoutSystemActiveState, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||
JS_FN("seekActionWidgetByActionTag", js_cocos2dx_ui_Helper_seekActionWidgetByActionTag, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||
JS_FN("seekWidgetByName", js_cocos2dx_ui_Helper_seekWidgetByName, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||
|
|
|
@ -615,6 +615,7 @@ void js_cocos2dx_ui_Helper_finalize(JSContext *cx, JSObject *obj);
|
|||
void js_register_cocos2dx_ui_Helper(JSContext *cx, JS::HandleObject global);
|
||||
void register_all_cocos2dx_ui(JSContext* cx, JS::HandleObject obj);
|
||||
bool js_cocos2dx_ui_Helper_getSubStringOfUTF8String(JSContext *cx, uint32_t argc, jsval *vp);
|
||||
bool js_cocos2dx_ui_Helper_convertBoundingBoxToScreen(JSContext *cx, uint32_t argc, jsval *vp);
|
||||
bool js_cocos2dx_ui_Helper_changeLayoutSystemActiveState(JSContext *cx, uint32_t argc, jsval *vp);
|
||||
bool js_cocos2dx_ui_Helper_seekActionWidgetByActionTag(JSContext *cx, uint32_t argc, jsval *vp);
|
||||
bool js_cocos2dx_ui_Helper_seekWidgetByName(JSContext *cx, uint32_t argc, jsval *vp);
|
||||
|
|
|
@ -535,7 +535,6 @@ static bool js_cocos2dx_CCTableView_init(JSContext *cx, uint32_t argc, jsval *vp
|
|||
cocos2d::Node* arg2;
|
||||
do
|
||||
{
|
||||
js_proxy_t *proxy;
|
||||
JSObject *tmpObj = args.get(2).toObjectOrNull();
|
||||
proxy = jsb_get_js_proxy(tmpObj);
|
||||
arg2 = (cocos2d::Node*)(proxy ? proxy->ptr : NULL);
|
||||
|
@ -567,22 +566,19 @@ class JSB_ControlButtonTarget : public Ref
|
|||
{
|
||||
public:
|
||||
JSB_ControlButtonTarget()
|
||||
: _jsFunc(nullptr),
|
||||
: _callback(nullptr),
|
||||
_jsFunc(nullptr),
|
||||
_type(Control::EventType::TOUCH_DOWN),
|
||||
_jsTarget(nullptr),
|
||||
_needUnroot(false)
|
||||
{}
|
||||
|
||||
virtual ~JSB_ControlButtonTarget()
|
||||
{
|
||||
CCLOGINFO("In the destruction of JSB_ControlButtonTarget ...");
|
||||
JSContext* cx = ScriptingCore::getInstance()->getGlobalContext();
|
||||
if (_needUnroot)
|
||||
if (_callback != nullptr)
|
||||
{
|
||||
JS::RemoveObjectRoot(cx, &_jsTarget);
|
||||
CC_SAFE_DELETE(_callback);
|
||||
}
|
||||
|
||||
JS::RemoveObjectRoot(cx, &_jsFunc);
|
||||
|
||||
for (auto iter = _jsNativeTargetMap.begin(); iter != _jsNativeTargetMap.end(); ++iter)
|
||||
{
|
||||
|
@ -604,36 +600,26 @@ public:
|
|||
return;
|
||||
}
|
||||
|
||||
JSContext* cx = ScriptingCore::getInstance()->getGlobalContext();
|
||||
|
||||
jsval dataVal[2];
|
||||
dataVal[0] = OBJECT_TO_JSVAL(p->obj);
|
||||
int arg1 = (int)event;
|
||||
dataVal[1] = INT_TO_JSVAL(arg1);
|
||||
|
||||
JSContext* cx = ScriptingCore::getInstance()->getGlobalContext();
|
||||
JS::RootedValue jsRet(cx);
|
||||
|
||||
ScriptingCore::getInstance()->executeJSFunctionWithThisObj(JS::RootedValue(cx, OBJECT_TO_JSVAL(_jsTarget)), JS::RootedValue(cx, OBJECT_TO_JSVAL(_jsFunc)), JS::HandleValueArray::fromMarkedLocation(2, dataVal), &jsRet);
|
||||
}
|
||||
|
||||
void setJSTarget(JSObject* pJSTarget)
|
||||
{
|
||||
_jsTarget = pJSTarget;
|
||||
|
||||
js_proxy_t* p = jsb_get_js_proxy(_jsTarget);
|
||||
if (!p)
|
||||
{
|
||||
JSContext* cx = ScriptingCore::getInstance()->getGlobalContext();
|
||||
JS::AddNamedObjectRoot(cx, &_jsTarget, "JSB_ControlButtonTarget, target");
|
||||
_needUnroot = true;
|
||||
}
|
||||
_callback->invoke(2, dataVal, &jsRet);
|
||||
}
|
||||
|
||||
void setJSAction(JSObject* jsFunc)
|
||||
void setJSCallback(jsval jsFunc, JSObject* jsTarget)
|
||||
{
|
||||
_jsFunc = jsFunc;
|
||||
|
||||
if (_callback != nullptr)
|
||||
{
|
||||
CC_SAFE_DELETE(_callback);
|
||||
}
|
||||
JSContext* cx = ScriptingCore::getInstance()->getGlobalContext();
|
||||
JS::AddNamedObjectRoot(cx, &_jsFunc, "JSB_ControlButtonTarget, func");
|
||||
_callback = new JSFunctionWrapper(cx, jsTarget, jsFunc);
|
||||
_jsFunc = jsFunc.toObjectOrNull();
|
||||
}
|
||||
|
||||
void setEventType(Control::EventType type)
|
||||
|
@ -643,10 +629,10 @@ public:
|
|||
public:
|
||||
|
||||
static std::multimap<JSObject*, JSB_ControlButtonTarget*> _jsNativeTargetMap;
|
||||
JS::Heap<JSObject*> _jsFunc;
|
||||
JSFunctionWrapper *_callback;
|
||||
Control::EventType _type;
|
||||
JSObject *_jsFunc;
|
||||
private:
|
||||
JS::Heap<JSObject*> _jsTarget;
|
||||
bool _needUnroot;
|
||||
};
|
||||
|
||||
|
@ -684,8 +670,7 @@ static bool js_cocos2dx_CCControl_addTargetWithActionForControlEvents(JSContext
|
|||
// save the delegate
|
||||
JSB_ControlButtonTarget* nativeDelegate = new JSB_ControlButtonTarget();
|
||||
|
||||
nativeDelegate->setJSTarget(jsDelegate);
|
||||
nativeDelegate->setJSAction(jsFunc);
|
||||
nativeDelegate->setJSCallback(args.get(1), jsDelegate);
|
||||
nativeDelegate->setEventType(arg2);
|
||||
|
||||
__Array* nativeDelegateArray = static_cast<__Array*>(cobj->getUserObject());
|
||||
|
|
|
@ -32,84 +32,45 @@
|
|||
|
||||
using namespace cocos2d::network;
|
||||
|
||||
class JSB_SIOEvent : public cocos2d::Object {
|
||||
public:
|
||||
JSB_SIOEvent();
|
||||
virtual ~JSB_SIOEvent();
|
||||
void setJSCallbackFunc(jsval obj);
|
||||
const jsval& getJSCallbackFunc() const;
|
||||
|
||||
private:
|
||||
JS::Heap<jsval> _jsCallback;
|
||||
JS::Heap<jsval> _extraData;
|
||||
|
||||
};
|
||||
|
||||
JSB_SIOEvent::JSB_SIOEvent()
|
||||
: _jsCallback(JSVAL_VOID), _extraData(JSVAL_VOID)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
JSB_SIOEvent::~JSB_SIOEvent()
|
||||
{
|
||||
JSContext* cx = ScriptingCore::getInstance()->getGlobalContext();
|
||||
JS::RemoveValueRoot(cx, &_jsCallback);
|
||||
}
|
||||
|
||||
void JSB_SIOEvent::setJSCallbackFunc(jsval func) {
|
||||
_jsCallback = func;
|
||||
JSContext* cx = ScriptingCore::getInstance()->getGlobalContext();
|
||||
// Root the callback function.
|
||||
JS::AddNamedValueRoot(cx, &_jsCallback, "JSB_SIOEvent_callback_func");
|
||||
}
|
||||
|
||||
const jsval& JSB_SIOEvent::getJSCallbackFunc() const
|
||||
{
|
||||
return _jsCallback;
|
||||
}
|
||||
|
||||
//c++11 map to callbacks
|
||||
typedef std::unordered_map<std::string, JSB_SIOEvent> JSB_SIOEventRegistry;
|
||||
typedef std::unordered_map<std::string, std::shared_ptr<JSFunctionWrapper>> JSB_SIOCallbackRegistry;
|
||||
|
||||
class JSB_SocketIODelegate : public SocketIO::SIODelegate {
|
||||
class JSB_SocketIODelegate : public SocketIO::SIODelegate
|
||||
{
|
||||
public:
|
||||
|
||||
JSB_SocketIODelegate() {
|
||||
JSB_SIOEvent tmp;
|
||||
JSB_SocketIODelegate()
|
||||
{
|
||||
std::string s = "default";
|
||||
_eventRegistry[s] = tmp;
|
||||
_eventRegistry[s] = nullptr;
|
||||
}
|
||||
|
||||
virtual void onConnect(SIOClient* client) {
|
||||
virtual void onConnect(SIOClient* client)
|
||||
{
|
||||
CCLOG("JSB SocketIO::SIODelegate->onConnect method called from native");
|
||||
|
||||
this->fireEventToScript(client, "connect", "");
|
||||
|
||||
}
|
||||
|
||||
virtual void onMessage(SIOClient* client, const std::string& data) {
|
||||
virtual void onMessage(SIOClient* client, const std::string& data)
|
||||
{
|
||||
CCLOG("JSB SocketIO::SIODelegate->onMessage method called from native with data: %s", data.c_str());
|
||||
|
||||
this->fireEventToScript(client, "message", data);
|
||||
|
||||
}
|
||||
|
||||
virtual void onClose(SIOClient* client) {
|
||||
virtual void onClose(SIOClient* client)
|
||||
{
|
||||
CCLOG("JSB SocketIO::SIODelegate->onClose method called from native");
|
||||
|
||||
this->fireEventToScript(client, "disconnect", "");
|
||||
|
||||
}
|
||||
|
||||
virtual void onError(SIOClient* client, const std::string& data) {
|
||||
virtual void onError(SIOClient* client, const std::string& data)
|
||||
{
|
||||
CCLOG("JSB SocketIO::SIODelegate->onError method called from native with data: %s", data.c_str());
|
||||
|
||||
this->fireEventToScript(client, "error", data);
|
||||
|
||||
}
|
||||
|
||||
virtual void fireEventToScript(SIOClient* client, const std::string& eventName, const std::string& data) {
|
||||
virtual void fireEventToScript(SIOClient* client, const std::string& eventName, const std::string& data)
|
||||
{
|
||||
CCLOG("JSB SocketIO::SIODelegate->fireEventToScript method called from native with name '%s' data: %s", eventName.c_str(), data.c_str());
|
||||
|
||||
js_proxy_t * p = jsb_get_native_proxy(client);
|
||||
|
@ -118,63 +79,71 @@ public:
|
|||
JSContext* cx = ScriptingCore::getInstance()->getGlobalContext();
|
||||
|
||||
jsval args;
|
||||
if(data == "") {
|
||||
if(data == "")
|
||||
{
|
||||
args = JSVAL_NULL;
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
args = std_string_to_jsval(cx, data);
|
||||
}
|
||||
|
||||
//ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(_JSDelegate), eventName.c_str(), 1, &args);
|
||||
|
||||
JSB_SIOEventRegistry::iterator it = _eventRegistry.find(eventName);
|
||||
JSB_SIOCallbackRegistry::iterator it = _eventRegistry.find(eventName);
|
||||
|
||||
if(it != _eventRegistry.end()) {
|
||||
JSB_SIOEvent e = it->second;
|
||||
JS::RootedValue rval(cx);
|
||||
ScriptingCore::getInstance()->executeJSFunctionWithThisObj(JS::RootedValue(cx, OBJECT_TO_JSVAL(p->obj)), JS::RootedValue(cx, e.getJSCallbackFunc()), JS::HandleValueArray::fromMarkedLocation(1, &args), &rval);
|
||||
if(it != _eventRegistry.end())
|
||||
{
|
||||
std::shared_ptr<JSFunctionWrapper> callback = it->second;
|
||||
if (callback != nullptr)
|
||||
{
|
||||
JS::RootedValue rval(cx);
|
||||
callback->invoke(1, &args, &rval);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void setJSDelegate(JSObject* pJSDelegate) {
|
||||
void setJSDelegate(JSObject* pJSDelegate)
|
||||
{
|
||||
_JSDelegate = pJSDelegate;
|
||||
}
|
||||
|
||||
void addEvent(const std::string& eventName, JSB_SIOEvent jsevent) {
|
||||
_eventRegistry[eventName] = jsevent;
|
||||
void addEvent(const std::string& eventName, std::shared_ptr<JSFunctionWrapper> callback)
|
||||
{
|
||||
_eventRegistry[eventName] = callback;
|
||||
}
|
||||
|
||||
private:
|
||||
JS::Heap<JSObject*> _JSDelegate;
|
||||
|
||||
JSB_SIOEventRegistry _eventRegistry;
|
||||
JSB_SIOCallbackRegistry _eventRegistry;
|
||||
|
||||
};
|
||||
|
||||
JSClass *js_cocos2dx_socketio_class;
|
||||
JSObject *js_cocos2dx_socketio_prototype;
|
||||
|
||||
void js_cocos2dx_SocketIO_finalize(JSFreeOp *fop, JSObject *obj) {
|
||||
void js_cocos2dx_SocketIO_finalize(JSFreeOp *fop, JSObject *obj)
|
||||
{
|
||||
CCLOG("jsbindings: finalizing JS object %p (SocketIO)", obj);
|
||||
}
|
||||
|
||||
bool js_cocos2dx_SocketIO_constructor(JSContext *cx, uint32_t argc, jsval *vp)
|
||||
{
|
||||
JS_ReportError(cx, "SocketIO isn't meant to be instantiated, use SocketIO.connect() instead");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool js_cocos2dx_SocketIO_connect(JSContext* cx, uint32_t argc, jsval* vp){
|
||||
bool js_cocos2dx_SocketIO_connect(JSContext* cx, uint32_t argc, jsval* vp)
|
||||
{
|
||||
CCLOG("JSB SocketIO.connect method called");
|
||||
|
||||
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
||||
|
||||
if (argc == 1 || argc == 2) {
|
||||
|
||||
if (argc == 1 || argc == 2)
|
||||
{
|
||||
std::string url;
|
||||
|
||||
do {
|
||||
do
|
||||
{
|
||||
bool ok = jsval_to_std_string(cx, args.get(0), &url);
|
||||
JSB_PRECONDITION2( ok, cx, false, "Error processing arguments");
|
||||
} while (0);
|
||||
|
@ -182,41 +151,41 @@ bool js_cocos2dx_SocketIO_connect(JSContext* cx, uint32_t argc, jsval* vp){
|
|||
JSB_SocketIODelegate* siodelegate = new JSB_SocketIODelegate();
|
||||
|
||||
CCLOG("Calling native SocketIO.connect method");
|
||||
SIOClient* ret = SocketIO::connect(*siodelegate, url);
|
||||
SIOClient* ret = SocketIO::connect(url, *siodelegate);
|
||||
|
||||
jsval jsret;
|
||||
do{
|
||||
if (ret) {
|
||||
do
|
||||
{
|
||||
if (ret)
|
||||
{
|
||||
// link the native object with the javascript object
|
||||
js_proxy_t *p;
|
||||
HASH_FIND_PTR(_native_js_global_ht, &ret, p);
|
||||
if(!p) {
|
||||
if(!p)
|
||||
{
|
||||
//previous connection not found, create a new one
|
||||
JSObject *obj = JS_NewObject(cx, js_cocos2dx_socketio_class, JS::RootedObject(cx, js_cocos2dx_socketio_prototype), JS::NullPtr());
|
||||
p = jsb_new_proxy(ret, obj);
|
||||
JS::AddNamedObjectRoot(cx, &p->obj, "SocketIO");
|
||||
siodelegate->setJSDelegate(p->obj);
|
||||
}
|
||||
|
||||
jsret = OBJECT_TO_JSVAL(p->obj);
|
||||
|
||||
}
|
||||
else{
|
||||
else
|
||||
{
|
||||
jsret = JSVAL_NULL;
|
||||
}
|
||||
} while(0);
|
||||
|
||||
args.rval().set(jsret);
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
JS_ReportError(cx, "JSB SocketIO.connect: Wrong number of arguments");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool js_cocos2dx_SocketIO_send(JSContext* cx, uint32_t argc, jsval* vp){
|
||||
bool js_cocos2dx_SocketIO_send(JSContext* cx, uint32_t argc, jsval* vp)
|
||||
{
|
||||
CCLOG("JSB SocketIO.send method called");
|
||||
|
||||
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
||||
|
@ -225,11 +194,12 @@ bool js_cocos2dx_SocketIO_send(JSContext* cx, uint32_t argc, jsval* vp){
|
|||
SIOClient* cobj = (SIOClient *)(proxy ? proxy->ptr : NULL);
|
||||
JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object");
|
||||
|
||||
if (argc == 1) {
|
||||
|
||||
if (argc == 1)
|
||||
{
|
||||
std::string payload;
|
||||
|
||||
do {
|
||||
do
|
||||
{
|
||||
bool ok = jsval_to_std_string(cx, args.get(0), &payload);
|
||||
JSB_PRECONDITION2( ok, cx, false, "Error processing arguments");
|
||||
} while (0);
|
||||
|
@ -237,17 +207,15 @@ bool js_cocos2dx_SocketIO_send(JSContext* cx, uint32_t argc, jsval* vp){
|
|||
CCLOG("JSB SocketIO send mesage: %s", payload.c_str());
|
||||
|
||||
cobj->send(payload);
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
JS_ReportError(cx, "Wrong number of arguments");
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
bool js_cocos2dx_SocketIO_emit(JSContext* cx, uint32_t argc, jsval* vp){
|
||||
bool js_cocos2dx_SocketIO_emit(JSContext* cx, uint32_t argc, jsval* vp)
|
||||
{
|
||||
CCLOG("JSB SocketIO.emit method called");
|
||||
|
||||
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
||||
|
@ -256,17 +224,16 @@ bool js_cocos2dx_SocketIO_emit(JSContext* cx, uint32_t argc, jsval* vp){
|
|||
SIOClient* cobj = (SIOClient *)(proxy ? proxy->ptr : NULL);
|
||||
JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object");
|
||||
|
||||
if (argc == 2) {
|
||||
|
||||
if (argc == 2)
|
||||
{
|
||||
std::string eventName;
|
||||
|
||||
do {
|
||||
do
|
||||
{
|
||||
bool ok = jsval_to_std_string(cx, args.get(0), &eventName);
|
||||
JSB_PRECONDITION2( ok, cx, false, "Error processing arguments");
|
||||
} while (0);
|
||||
|
||||
std::string payload;
|
||||
|
||||
do {
|
||||
bool ok = jsval_to_std_string(cx, args.get(1), &payload);
|
||||
JSB_PRECONDITION2( ok, cx, false, "Error processing arguments");
|
||||
|
@ -275,17 +242,14 @@ bool js_cocos2dx_SocketIO_emit(JSContext* cx, uint32_t argc, jsval* vp){
|
|||
CCLOG("JSB SocketIO emit event '%s' with payload: %s", eventName.c_str(), payload.c_str());
|
||||
|
||||
cobj->emit(eventName, payload);
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
JS_ReportError(cx, "JSB SocketIO.emit: Wrong number of arguments");
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
bool js_cocos2dx_SocketIO_disconnect(JSContext* cx, uint32_t argc, jsval* vp){
|
||||
bool js_cocos2dx_SocketIO_disconnect(JSContext* cx, uint32_t argc, jsval* vp)
|
||||
{
|
||||
CCLOG("JSB SocketIO.disconnect method called");
|
||||
|
||||
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
||||
|
@ -294,8 +258,8 @@ bool js_cocos2dx_SocketIO_disconnect(JSContext* cx, uint32_t argc, jsval* vp){
|
|||
SIOClient* cobj = (SIOClient *)(proxy ? proxy->ptr : NULL);
|
||||
JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object");
|
||||
|
||||
if(argc == 0) {
|
||||
|
||||
if(argc == 0)
|
||||
{
|
||||
cobj->disconnect();
|
||||
args.rval().setUndefined();
|
||||
return true;
|
||||
|
@ -303,13 +267,14 @@ bool js_cocos2dx_SocketIO_disconnect(JSContext* cx, uint32_t argc, jsval* vp){
|
|||
|
||||
JS_ReportError(cx, "JSB SocketIO.disconnect: Wrong number of arguments");
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
bool js_cocos2dx_SocketIO_close(JSContext* cx, uint32_t argc, jsval* vp){
|
||||
bool js_cocos2dx_SocketIO_close(JSContext* cx, uint32_t argc, jsval* vp)
|
||||
{
|
||||
CCLOG("JSB SocketIO.close method called");
|
||||
|
||||
if(argc == 0) {
|
||||
if(argc == 0)
|
||||
{
|
||||
|
||||
//This method was previously implemented to take care of the HTTPClient instance not being destroyed properly
|
||||
//SocketIO::close();
|
||||
|
@ -320,7 +285,6 @@ bool js_cocos2dx_SocketIO_close(JSContext* cx, uint32_t argc, jsval* vp){
|
|||
|
||||
JS_ReportError(cx, "JSB SocketIO.close: Wrong number of arguments");
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
static bool _js_set_SIOClient_tag(JSContext* cx, uint32_t argc, jsval* vp)
|
||||
|
@ -332,17 +296,18 @@ static bool _js_set_SIOClient_tag(JSContext* cx, uint32_t argc, jsval* vp)
|
|||
SIOClient* cobj = (SIOClient *)(proxy ? proxy->ptr : NULL);
|
||||
JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object");
|
||||
|
||||
if (cobj) {
|
||||
if (cobj)
|
||||
{
|
||||
std::string out = "";
|
||||
|
||||
jsval_to_std_string(cx, args.get(0), &out);
|
||||
cobj->setTag(out.c_str());
|
||||
return true;
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
JS_ReportError(cx, "Error: SocketIO instance is invalid.");
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static bool _js_get_SIOClient_tag(JSContext* cx, uint32_t argc, jsval* vp)
|
||||
|
@ -354,18 +319,20 @@ static bool _js_get_SIOClient_tag(JSContext* cx, uint32_t argc, jsval* vp)
|
|||
SIOClient* cobj = (SIOClient *)(proxy ? proxy->ptr : NULL);
|
||||
JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object");
|
||||
|
||||
if (cobj) {
|
||||
if (cobj)
|
||||
{
|
||||
args.rval().set(std_string_to_jsval(cx, cobj->getTag()));
|
||||
return true;
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
JS_ReportError(cx, "Error: SocketIO instance is invalid.");
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool js_cocos2dx_SocketIO_on(JSContext* cx, uint32_t argc, jsval* vp){
|
||||
bool js_cocos2dx_SocketIO_on(JSContext* cx, uint32_t argc, jsval* vp)
|
||||
{
|
||||
CCLOG("JSB SocketIO.on method called");
|
||||
|
||||
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
||||
|
@ -374,36 +341,31 @@ bool js_cocos2dx_SocketIO_on(JSContext* cx, uint32_t argc, jsval* vp){
|
|||
SIOClient* cobj = (SIOClient *)(proxy ? proxy->ptr : NULL);
|
||||
JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object");
|
||||
|
||||
if(argc == 2) {
|
||||
|
||||
if(argc == 2)
|
||||
{
|
||||
std::string eventName;
|
||||
|
||||
do {
|
||||
do
|
||||
{
|
||||
bool ok = jsval_to_std_string(cx, args.get(0), &eventName);
|
||||
JSB_PRECONDITION2( ok, cx, false, "Error processing arguments");
|
||||
} while (0);
|
||||
|
||||
CCLOG("JSB SocketIO eventName to: '%s'", eventName.c_str());
|
||||
|
||||
std::shared_ptr<JSFunctionWrapper> callback(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), args.get(1)));
|
||||
|
||||
JSB_SIOEvent tmpCobj;
|
||||
tmpCobj.setJSCallbackFunc(args.get(1));
|
||||
|
||||
((JSB_SocketIODelegate *)cobj->getDelegate())->addEvent(eventName, tmpCobj);
|
||||
((JSB_SocketIODelegate *)cobj->getDelegate())->addEvent(eventName, callback);
|
||||
|
||||
args.rval().set(OBJECT_TO_JSVAL(proxy->obj));
|
||||
|
||||
JS_SetReservedSlot(proxy->obj, 0, args.get(1));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
JS_ReportError(cx, "JSB SocketIO.close: Wrong number of arguments");
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
void register_jsb_socketio(JSContext *cx, JS::HandleObject global) {
|
||||
|
||||
void register_jsb_socketio(JSContext *cx, JS::HandleObject global)
|
||||
{
|
||||
js_cocos2dx_socketio_class = (JSClass *)calloc(1, sizeof(JSClass));
|
||||
js_cocos2dx_socketio_class->name = "SocketIO";
|
||||
js_cocos2dx_socketio_class->addProperty = JS_PropertyStub;
|
||||
|
@ -416,12 +378,14 @@ void register_jsb_socketio(JSContext *cx, JS::HandleObject global) {
|
|||
js_cocos2dx_socketio_class->finalize = js_cocos2dx_SocketIO_finalize;
|
||||
js_cocos2dx_socketio_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2);
|
||||
|
||||
static JSPropertySpec properties[] = {
|
||||
static JSPropertySpec properties[] =
|
||||
{
|
||||
JS_PSGS("tag", _js_get_SIOClient_tag, _js_set_SIOClient_tag, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||
JS_PS_END
|
||||
};
|
||||
|
||||
static JSFunctionSpec funcs[] = {
|
||||
static JSFunctionSpec funcs[] =
|
||||
{
|
||||
JS_FN("send", js_cocos2dx_SocketIO_send, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||
JS_FN("emit", js_cocos2dx_SocketIO_emit, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||
JS_FN("disconnect", js_cocos2dx_SocketIO_disconnect, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||
|
@ -429,7 +393,8 @@ void register_jsb_socketio(JSContext *cx, JS::HandleObject global) {
|
|||
JS_FS_END
|
||||
};
|
||||
|
||||
static JSFunctionSpec st_funcs[] = {
|
||||
static JSFunctionSpec st_funcs[] =
|
||||
{
|
||||
JS_FN("connect", js_cocos2dx_SocketIO_connect, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||
JS_FN("close", js_cocos2dx_SocketIO_close, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||
JS_FS_END
|
||||
|
@ -442,10 +407,9 @@ void register_jsb_socketio(JSContext *cx, JS::HandleObject global) {
|
|||
js_cocos2dx_SocketIO_constructor, 0, // constructor
|
||||
nullptr,
|
||||
funcs,
|
||||
nullptr, // no static properties
|
||||
properties,
|
||||
st_funcs);
|
||||
|
||||
JSObject* jsclassObj = anonEvaluate(cx, global, "(function () { return SocketIO; })()").toObjectOrNull();
|
||||
|
||||
anonEvaluate(cx, global, "(function () { return SocketIO; })()").toObjectOrNull();
|
||||
}
|
||||
|
||||
|
|
|
@ -226,7 +226,6 @@
|
|||
1A119E5418BDF19200352BAA /* js_bindings_ccbreader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = js_bindings_ccbreader.h; sourceTree = "<group>"; };
|
||||
1A119E5718BDF19200352BAA /* jsb_cocos2dx_studio_manual.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = jsb_cocos2dx_studio_manual.cpp; sourceTree = "<group>"; };
|
||||
1A119E5818BDF19200352BAA /* jsb_cocos2dx_studio_manual.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = jsb_cocos2dx_studio_manual.h; sourceTree = "<group>"; };
|
||||
1A119E5A18BDF19200352BAA /* Android.mk */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Android.mk; sourceTree = "<group>"; };
|
||||
1A119E5B18BDF19200352BAA /* jsb_cocos2dx_extension_manual.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = jsb_cocos2dx_extension_manual.cpp; sourceTree = "<group>"; };
|
||||
1A119E5C18BDF19200352BAA /* jsb_cocos2dx_extension_manual.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = jsb_cocos2dx_extension_manual.h; sourceTree = "<group>"; };
|
||||
1A119E6118BDF19200352BAA /* js_bindings_config.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = js_bindings_config.h; sourceTree = "<group>"; };
|
||||
|
@ -249,7 +248,6 @@
|
|||
1A119E7318BDF19200352BAA /* js_bindings_system_functions_registration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = js_bindings_system_functions_registration.h; sourceTree = "<group>"; };
|
||||
1A119E7418BDF19200352BAA /* js_bindings_system_registration.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = js_bindings_system_registration.cpp; sourceTree = "<group>"; };
|
||||
1A119E7518BDF19200352BAA /* js_bindings_system_registration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = js_bindings_system_registration.h; sourceTree = "<group>"; };
|
||||
1A119E7718BDF19200352BAA /* Android.mk */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Android.mk; sourceTree = "<group>"; };
|
||||
1A119E7818BDF19200352BAA /* jsb_websocket.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = jsb_websocket.cpp; sourceTree = "<group>"; };
|
||||
1A119E7918BDF19200352BAA /* jsb_websocket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = jsb_websocket.h; sourceTree = "<group>"; };
|
||||
1A119E7A18BDF19200352BAA /* XMLHTTPRequest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = XMLHTTPRequest.cpp; sourceTree = "<group>"; };
|
||||
|
@ -463,7 +461,6 @@
|
|||
1A119E5918BDF19200352BAA /* extension */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
1A119E5A18BDF19200352BAA /* Android.mk */,
|
||||
1A119E5B18BDF19200352BAA /* jsb_cocos2dx_extension_manual.cpp */,
|
||||
1A119E5C18BDF19200352BAA /* jsb_cocos2dx_extension_manual.h */,
|
||||
);
|
||||
|
@ -486,7 +483,6 @@
|
|||
1A119E7618BDF19200352BAA /* network */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
1A119E7718BDF19200352BAA /* Android.mk */,
|
||||
83A5661718DA878400FC31A0 /* jsb_socketio.cpp */,
|
||||
83A5661818DA878400FC31A0 /* jsb_socketio.h */,
|
||||
1A119E7818BDF19200352BAA /* jsb_websocket.cpp */,
|
||||
|
|
|
@ -165,8 +165,6 @@ cc.defineGetterSetter(_proto, "glServerState", _proto.getGLServerState, _proto.s
|
|||
cc.defineGetterSetter(_proto, "tag", _proto.getTag, _proto.setTag);
|
||||
cc.defineGetterSetter(_proto, "userObject", _proto.getUserObject, _proto.setUserObject);
|
||||
cc.defineGetterSetter(_proto, "arrivalOrder", _proto.getArrivalOrder, _proto.setArrivalOrder);
|
||||
|
||||
_proto = cc.NodeRGBA.prototype;
|
||||
cc.defineGetterSetter(_proto, "opacity", _proto.getOpacity, _proto.setOpacity);
|
||||
cc.defineGetterSetter(_proto, "opacityModifyRGB", _proto.isOpacityModifyRGB, _proto.setOpacityModifyRGB);
|
||||
cc.defineGetterSetter(_proto, "cascadeOpacity", _proto.isCascadeOpacityEnabled, _proto.setCascadeOpacityEnabled);
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
-- @return EditBox#EditBox self (return value: ccui.EditBox)
|
||||
|
||||
--------------------------------
|
||||
-- Set the placeholder's font name.<br>
|
||||
-- Set the placeholder's font name. only system font is allowed.<br>
|
||||
-- param pFontName The font name.
|
||||
-- @function [parent=#EditBox] setPlaceholderFontName
|
||||
-- @param self
|
||||
|
@ -51,7 +51,7 @@
|
|||
-- @return char#char ret (return value: char)
|
||||
|
||||
--------------------------------
|
||||
-- Set the font name.<br>
|
||||
-- Set the font name. Only system font is allowed.<br>
|
||||
-- param pFontName The font name.
|
||||
-- @function [parent=#EditBox] setFontName
|
||||
-- @param self
|
||||
|
@ -150,7 +150,7 @@
|
|||
-- @return EditBox#EditBox self (return value: ccui.EditBox)
|
||||
|
||||
--------------------------------
|
||||
-- Set the placeholder's font.<br>
|
||||
-- Set the placeholder's font. Only system font is allowed.<br>
|
||||
-- param pFontName The font name.<br>
|
||||
-- param fontSize The font size.
|
||||
-- @function [parent=#EditBox] setPlaceholderFont
|
||||
|
@ -228,7 +228,7 @@
|
|||
-- @return EditBox#EditBox self (return value: ccui.EditBox)
|
||||
|
||||
--------------------------------
|
||||
-- Set the font.<br>
|
||||
-- Set the font. Only system font is allowed.<br>
|
||||
-- param pFontName The font name.<br>
|
||||
-- param fontSize The font size.
|
||||
-- @function [parent=#EditBox] setFont
|
||||
|
@ -255,6 +255,16 @@
|
|||
-- @param #vec2_table anchorPoint
|
||||
-- @return EditBox#EditBox self (return value: ccui.EditBox)
|
||||
|
||||
--------------------------------
|
||||
-- js NA<br>
|
||||
-- lua NA
|
||||
-- @function [parent=#EditBox] draw
|
||||
-- @param self
|
||||
-- @param #cc.Renderer renderer
|
||||
-- @param #mat4_table parentTransform
|
||||
-- @param #unsigned int parentFlags
|
||||
-- @return EditBox#EditBox self (return value: ccui.EditBox)
|
||||
|
||||
--------------------------------
|
||||
-- Returns the "class name" of widget.
|
||||
-- @function [parent=#EditBox] getDescription
|
||||
|
|
|
@ -18,6 +18,15 @@
|
|||
-- @param #unsigned long length
|
||||
-- @return string#string ret (return value: string)
|
||||
|
||||
--------------------------------
|
||||
-- brief Convert a node's boundingBox rect into screen coordinates.<br>
|
||||
-- param node Any node pointer.<br>
|
||||
-- return A Rect in screen coordinates.
|
||||
-- @function [parent=#Helper] convertBoundingBoxToScreen
|
||||
-- @param self
|
||||
-- @param #cc.Node node
|
||||
-- @return rect_table#rect_table ret (return value: rect_table)
|
||||
|
||||
--------------------------------
|
||||
-- Change the active property of Layout's @see `LayoutComponent`<br>
|
||||
-- param active A boolean value.
|
||||
|
|
|
@ -23,12 +23,6 @@
|
|||
-- @param self
|
||||
-- @return SkeletonRenderer#SkeletonRenderer self (return value: sp.SkeletonRenderer)
|
||||
|
||||
--------------------------------
|
||||
--
|
||||
-- @function [parent=#SkeletonRenderer] isOpacityModifyRGB
|
||||
-- @param self
|
||||
-- @return bool#bool ret (return value: bool)
|
||||
|
||||
--------------------------------
|
||||
--
|
||||
-- @function [parent=#SkeletonRenderer] initWithData
|
||||
|
@ -50,13 +44,6 @@
|
|||
-- @param self
|
||||
-- @return SkeletonRenderer#SkeletonRenderer self (return value: sp.SkeletonRenderer)
|
||||
|
||||
--------------------------------
|
||||
--
|
||||
-- @function [parent=#SkeletonRenderer] setOpacityModifyRGB
|
||||
-- @param self
|
||||
-- @param #bool value
|
||||
-- @return SkeletonRenderer#SkeletonRenderer self (return value: sp.SkeletonRenderer)
|
||||
|
||||
--------------------------------
|
||||
--
|
||||
-- @function [parent=#SkeletonRenderer] setToSetupPose
|
||||
|
@ -135,12 +122,6 @@
|
|||
-- @param #float scale
|
||||
-- @return SkeletonRenderer#SkeletonRenderer ret (return value: sp.SkeletonRenderer)
|
||||
|
||||
--------------------------------
|
||||
--
|
||||
-- @function [parent=#SkeletonRenderer] getBoundingBox
|
||||
-- @param self
|
||||
-- @return rect_table#rect_table ret (return value: rect_table)
|
||||
|
||||
--------------------------------
|
||||
--
|
||||
-- @function [parent=#SkeletonRenderer] onEnter
|
||||
|
@ -153,6 +134,25 @@
|
|||
-- @param self
|
||||
-- @return SkeletonRenderer#SkeletonRenderer self (return value: sp.SkeletonRenderer)
|
||||
|
||||
--------------------------------
|
||||
--
|
||||
-- @function [parent=#SkeletonRenderer] setOpacityModifyRGB
|
||||
-- @param self
|
||||
-- @param #bool value
|
||||
-- @return SkeletonRenderer#SkeletonRenderer self (return value: sp.SkeletonRenderer)
|
||||
|
||||
--------------------------------
|
||||
--
|
||||
-- @function [parent=#SkeletonRenderer] getBoundingBox
|
||||
-- @param self
|
||||
-- @return rect_table#rect_table ret (return value: rect_table)
|
||||
|
||||
--------------------------------
|
||||
--
|
||||
-- @function [parent=#SkeletonRenderer] isOpacityModifyRGB
|
||||
-- @param self
|
||||
-- @return bool#bool ret (return value: bool)
|
||||
|
||||
--------------------------------
|
||||
-- @overload self, spSkeletonData, bool
|
||||
-- @overload self
|
||||
|
|
|
@ -148,53 +148,6 @@ int lua_cocos2dx_spine_SkeletonRenderer_setBonesToSetupPose(lua_State* tolua_S)
|
|||
|
||||
return 0;
|
||||
}
|
||||
int lua_cocos2dx_spine_SkeletonRenderer_isOpacityModifyRGB(lua_State* tolua_S)
|
||||
{
|
||||
int argc = 0;
|
||||
spine::SkeletonRenderer* cobj = nullptr;
|
||||
bool ok = true;
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
tolua_Error tolua_err;
|
||||
#endif
|
||||
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
if (!tolua_isusertype(tolua_S,1,"sp.SkeletonRenderer",0,&tolua_err)) goto tolua_lerror;
|
||||
#endif
|
||||
|
||||
cobj = (spine::SkeletonRenderer*)tolua_tousertype(tolua_S,1,0);
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
if (!cobj)
|
||||
{
|
||||
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_spine_SkeletonRenderer_isOpacityModifyRGB'", nullptr);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
argc = lua_gettop(tolua_S)-1;
|
||||
if (argc == 0)
|
||||
{
|
||||
if(!ok)
|
||||
{
|
||||
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_spine_SkeletonRenderer_isOpacityModifyRGB'", nullptr);
|
||||
return 0;
|
||||
}
|
||||
bool ret = cobj->isOpacityModifyRGB();
|
||||
tolua_pushboolean(tolua_S,(bool)ret);
|
||||
return 1;
|
||||
}
|
||||
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "sp.SkeletonRenderer:isOpacityModifyRGB",argc, 0);
|
||||
return 0;
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
tolua_lerror:
|
||||
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_spine_SkeletonRenderer_isOpacityModifyRGB'.",&tolua_err);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
int lua_cocos2dx_spine_SkeletonRenderer_initWithData(lua_State* tolua_S)
|
||||
{
|
||||
int argc = 0;
|
||||
|
@ -361,56 +314,6 @@ int lua_cocos2dx_spine_SkeletonRenderer_setSlotsToSetupPose(lua_State* tolua_S)
|
|||
|
||||
return 0;
|
||||
}
|
||||
int lua_cocos2dx_spine_SkeletonRenderer_setOpacityModifyRGB(lua_State* tolua_S)
|
||||
{
|
||||
int argc = 0;
|
||||
spine::SkeletonRenderer* cobj = nullptr;
|
||||
bool ok = true;
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
tolua_Error tolua_err;
|
||||
#endif
|
||||
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
if (!tolua_isusertype(tolua_S,1,"sp.SkeletonRenderer",0,&tolua_err)) goto tolua_lerror;
|
||||
#endif
|
||||
|
||||
cobj = (spine::SkeletonRenderer*)tolua_tousertype(tolua_S,1,0);
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
if (!cobj)
|
||||
{
|
||||
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_spine_SkeletonRenderer_setOpacityModifyRGB'", nullptr);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
argc = lua_gettop(tolua_S)-1;
|
||||
if (argc == 1)
|
||||
{
|
||||
bool arg0;
|
||||
|
||||
ok &= luaval_to_boolean(tolua_S, 2,&arg0, "sp.SkeletonRenderer:setOpacityModifyRGB");
|
||||
if(!ok)
|
||||
{
|
||||
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_spine_SkeletonRenderer_setOpacityModifyRGB'", nullptr);
|
||||
return 0;
|
||||
}
|
||||
cobj->setOpacityModifyRGB(arg0);
|
||||
lua_settop(tolua_S, 1);
|
||||
return 1;
|
||||
}
|
||||
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "sp.SkeletonRenderer:setOpacityModifyRGB",argc, 1);
|
||||
return 0;
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
tolua_lerror:
|
||||
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_spine_SkeletonRenderer_setOpacityModifyRGB'.",&tolua_err);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
int lua_cocos2dx_spine_SkeletonRenderer_setToSetupPose(lua_State* tolua_S)
|
||||
{
|
||||
int argc = 0;
|
||||
|
@ -1216,11 +1119,9 @@ int lua_register_cocos2dx_spine_SkeletonRenderer(lua_State* tolua_S)
|
|||
tolua_function(tolua_S,"setTimeScale",lua_cocos2dx_spine_SkeletonRenderer_setTimeScale);
|
||||
tolua_function(tolua_S,"getDebugSlotsEnabled",lua_cocos2dx_spine_SkeletonRenderer_getDebugSlotsEnabled);
|
||||
tolua_function(tolua_S,"setBonesToSetupPose",lua_cocos2dx_spine_SkeletonRenderer_setBonesToSetupPose);
|
||||
tolua_function(tolua_S,"isOpacityModifyRGB",lua_cocos2dx_spine_SkeletonRenderer_isOpacityModifyRGB);
|
||||
tolua_function(tolua_S,"initWithData",lua_cocos2dx_spine_SkeletonRenderer_initWithData);
|
||||
tolua_function(tolua_S,"setDebugSlotsEnabled",lua_cocos2dx_spine_SkeletonRenderer_setDebugSlotsEnabled);
|
||||
tolua_function(tolua_S,"setSlotsToSetupPose",lua_cocos2dx_spine_SkeletonRenderer_setSlotsToSetupPose);
|
||||
tolua_function(tolua_S,"setOpacityModifyRGB",lua_cocos2dx_spine_SkeletonRenderer_setOpacityModifyRGB);
|
||||
tolua_function(tolua_S,"setToSetupPose",lua_cocos2dx_spine_SkeletonRenderer_setToSetupPose);
|
||||
tolua_function(tolua_S,"getBlendFunc",lua_cocos2dx_spine_SkeletonRenderer_getBlendFunc);
|
||||
tolua_function(tolua_S,"initialize",lua_cocos2dx_spine_SkeletonRenderer_initialize);
|
||||
|
|
|
@ -41,8 +41,6 @@ int register_all_cocos2dx_spine(lua_State* tolua_S);
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -19791,6 +19791,42 @@ int lua_cocos2dx_ui_Helper_getSubStringOfUTF8String(lua_State* tolua_S)
|
|||
#endif
|
||||
return 0;
|
||||
}
|
||||
int lua_cocos2dx_ui_Helper_convertBoundingBoxToScreen(lua_State* tolua_S)
|
||||
{
|
||||
int argc = 0;
|
||||
bool ok = true;
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
tolua_Error tolua_err;
|
||||
#endif
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
if (!tolua_isusertable(tolua_S,1,"ccui.Helper",0,&tolua_err)) goto tolua_lerror;
|
||||
#endif
|
||||
|
||||
argc = lua_gettop(tolua_S) - 1;
|
||||
|
||||
if (argc == 1)
|
||||
{
|
||||
cocos2d::Node* arg0;
|
||||
ok &= luaval_to_object<cocos2d::Node>(tolua_S, 2, "cc.Node",&arg0, "ccui.Helper:convertBoundingBoxToScreen");
|
||||
if(!ok)
|
||||
{
|
||||
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_ui_Helper_convertBoundingBoxToScreen'", nullptr);
|
||||
return 0;
|
||||
}
|
||||
cocos2d::Rect ret = cocos2d::ui::Helper::convertBoundingBoxToScreen(arg0);
|
||||
rect_to_luaval(tolua_S, ret);
|
||||
return 1;
|
||||
}
|
||||
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d\n ", "ccui.Helper:convertBoundingBoxToScreen",argc, 1);
|
||||
return 0;
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
tolua_lerror:
|
||||
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_ui_Helper_convertBoundingBoxToScreen'.",&tolua_err);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
int lua_cocos2dx_ui_Helper_changeLayoutSystemActiveState(lua_State* tolua_S)
|
||||
{
|
||||
int argc = 0;
|
||||
|
@ -20028,6 +20064,7 @@ int lua_register_cocos2dx_ui_Helper(lua_State* tolua_S)
|
|||
|
||||
tolua_beginmodule(tolua_S,"Helper");
|
||||
tolua_function(tolua_S,"getSubStringOfUTF8String", lua_cocos2dx_ui_Helper_getSubStringOfUTF8String);
|
||||
tolua_function(tolua_S,"convertBoundingBoxToScreen", lua_cocos2dx_ui_Helper_convertBoundingBoxToScreen);
|
||||
tolua_function(tolua_S,"changeLayoutSystemActiveState", lua_cocos2dx_ui_Helper_changeLayoutSystemActiveState);
|
||||
tolua_function(tolua_S,"seekActionWidgetByActionTag", lua_cocos2dx_ui_Helper_seekActionWidgetByActionTag);
|
||||
tolua_function(tolua_S,"seekWidgetByName", lua_cocos2dx_ui_Helper_seekWidgetByName);
|
||||
|
|
|
@ -576,6 +576,7 @@ int register_all_cocos2dx_ui(lua_State* tolua_S);
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // __cocos2dx_ui_h__
|
||||
|
|
|
@ -203,6 +203,7 @@ const char* EditBox::getText(void)
|
|||
|
||||
void EditBox::setFont(const char* pFontName, int fontSize)
|
||||
{
|
||||
CCASSERT(pFontName != nullptr, "fontName can't be nullptr");
|
||||
_fontName = pFontName;
|
||||
_fontSize = fontSize;
|
||||
if (pFontName != nullptr)
|
||||
|
@ -216,8 +217,9 @@ void EditBox::setFont(const char* pFontName, int fontSize)
|
|||
|
||||
void EditBox::setFontName(const char* pFontName)
|
||||
{
|
||||
CCASSERT(pFontName != nullptr, "fontName can't be nullptr");
|
||||
_fontName = pFontName;
|
||||
if (_editBoxImpl != nullptr && _fontSize != -1)
|
||||
if (_editBoxImpl != nullptr)
|
||||
{
|
||||
_editBoxImpl->setFont(pFontName, _fontSize);
|
||||
}
|
||||
|
@ -226,7 +228,7 @@ void EditBox::setFontName(const char* pFontName)
|
|||
void EditBox::setFontSize(int fontSize)
|
||||
{
|
||||
_fontSize = fontSize;
|
||||
if (_editBoxImpl != nullptr && _fontName.length() > 0)
|
||||
if (_editBoxImpl != nullptr)
|
||||
{
|
||||
_editBoxImpl->setFont(_fontName.c_str(), _fontSize);
|
||||
}
|
||||
|
@ -248,6 +250,7 @@ void EditBox::setFontColor(const Color4B& color)
|
|||
|
||||
void EditBox::setPlaceholderFont(const char* pFontName, int fontSize)
|
||||
{
|
||||
CCASSERT(pFontName != nullptr, "fontName can't be nullptr");
|
||||
_placeholderFontName = pFontName;
|
||||
_placeholderFontSize = fontSize;
|
||||
if (pFontName != nullptr)
|
||||
|
@ -261,8 +264,9 @@ void EditBox::setPlaceholderFont(const char* pFontName, int fontSize)
|
|||
|
||||
void EditBox::setPlaceholderFontName(const char* pFontName)
|
||||
{
|
||||
CCASSERT(pFontName != nullptr, "fontName can't be nullptr");
|
||||
_placeholderFontName = pFontName;
|
||||
if (_editBoxImpl != nullptr && _placeholderFontSize != -1)
|
||||
if (_editBoxImpl != nullptr)
|
||||
{
|
||||
_editBoxImpl->setPlaceholderFont(pFontName, _fontSize);
|
||||
}
|
||||
|
@ -271,7 +275,7 @@ void EditBox::setPlaceholderFontName(const char* pFontName)
|
|||
void EditBox::setPlaceholderFontSize(int fontSize)
|
||||
{
|
||||
_placeholderFontSize = fontSize;
|
||||
if (_editBoxImpl != nullptr && _placeholderFontName.length() > 0)
|
||||
if (_editBoxImpl != nullptr)
|
||||
{
|
||||
_editBoxImpl->setPlaceholderFont(_placeholderFontName.c_str(), fontSize);
|
||||
}
|
||||
|
@ -400,12 +404,12 @@ std::string EditBox::getDescription() const
|
|||
return "EditBox";
|
||||
}
|
||||
|
||||
void EditBox::visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags)
|
||||
void EditBox::draw(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags)
|
||||
{
|
||||
Widget::visit(renderer, parentTransform, parentFlags);
|
||||
Widget::draw(renderer, parentTransform, parentFlags);
|
||||
if (_editBoxImpl != nullptr)
|
||||
{
|
||||
_editBoxImpl->visit();
|
||||
_editBoxImpl->draw(renderer, parentTransform, parentFlags & FLAGS_TRANSFORM_DIRTY);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -308,14 +308,14 @@ namespace ui {
|
|||
const char* getText(void);
|
||||
|
||||
/**
|
||||
* Set the font.
|
||||
* Set the font. Only system font is allowed.
|
||||
* @param pFontName The font name.
|
||||
* @param fontSize The font size.
|
||||
*/
|
||||
void setFont(const char* pFontName, int fontSize);
|
||||
|
||||
/**
|
||||
* Set the font name.
|
||||
* Set the font name. Only system font is allowed.
|
||||
* @param pFontName The font name.
|
||||
*/
|
||||
void setFontName(const char* pFontName);
|
||||
|
@ -333,14 +333,14 @@ namespace ui {
|
|||
void setFontColor(const Color4B& color);
|
||||
|
||||
/**
|
||||
* Set the placeholder's font.
|
||||
* Set the placeholder's font. Only system font is allowed.
|
||||
* @param pFontName The font name.
|
||||
* @param fontSize The font size.
|
||||
*/
|
||||
void setPlaceholderFont(const char* pFontName, int fontSize);
|
||||
|
||||
/**
|
||||
* Set the placeholder's font name.
|
||||
* Set the placeholder's font name. only system font is allowed.
|
||||
* @param pFontName The font name.
|
||||
*/
|
||||
void setPlaceholderFontName(const char* pFontName);
|
||||
|
@ -423,7 +423,7 @@ namespace ui {
|
|||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
virtual void visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags) override;
|
||||
virtual void draw(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags) override;
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
|
|
|
@ -28,18 +28,118 @@
|
|||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
|
||||
#include "UIEditBox.h"
|
||||
#include <jni.h>
|
||||
#include "jni/Java_org_cocos2dx_lib_Cocos2dxBitmap.h"
|
||||
#include "jni/Java_org_cocos2dx_lib_Cocos2dxHelper.h"
|
||||
#include "2d/CCLabel.h"
|
||||
#include "base/ccUTF8.h"
|
||||
#include "math/Vec2.h"
|
||||
#include "ui/UIHelper.h"
|
||||
#include "base/ccUTF8.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
||||
namespace ui {
|
||||
|
||||
EditBoxImpl* __createSystemEditBox(EditBox* pEditBox)
|
||||
#define LOGD(...) __android_log_print(ANDROID_LOG_ERROR,"",__VA_ARGS__)
|
||||
static void editBoxEditingDidBegin(int index);
|
||||
static void editBoxEditingDidChanged(int index, const std::string& text);
|
||||
static void editBoxEditingDidEnd(int index, const std::string& text);
|
||||
extern "C"{
|
||||
JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxEditBoxHelper_editBoxEditingDidBegin(JNIEnv *env, jclass, jint index) {
|
||||
editBoxEditingDidBegin(index);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxEditBoxHelper_editBoxEditingChanged(JNIEnv *env, jclass, jint index, jstring text) {
|
||||
std::string textString = StringUtils::getStringUTFCharsJNI(env,text);
|
||||
editBoxEditingDidChanged(index, textString);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxEditBoxHelper_editBoxEditingDidEnd(JNIEnv *env, jclass, jint index, jstring text) {
|
||||
std::string textString = StringUtils::getStringUTFCharsJNI(env,text);
|
||||
editBoxEditingDidEnd(index, textString);
|
||||
}
|
||||
}
|
||||
|
||||
static std::unordered_map<int, EditBoxImplAndroid*> s_allEditBoxes;
|
||||
|
||||
|
||||
EditBoxImpl* __createSystemEditBox(EditBox* editBox)
|
||||
{
|
||||
return new EditBoxImplAndroid(pEditBox);
|
||||
return new EditBoxImplAndroid(editBox);
|
||||
}
|
||||
|
||||
void EditBoxImplAndroid::editBoxEditingDidBegin()
|
||||
{
|
||||
// LOGD("textFieldShouldBeginEditing...");
|
||||
cocos2d::ui::EditBoxDelegate *pDelegate = _editBox->getDelegate();
|
||||
|
||||
if (pDelegate != nullptr)
|
||||
{
|
||||
pDelegate->editBoxEditingDidBegin(_editBox);
|
||||
}
|
||||
|
||||
#if CC_ENABLE_SCRIPT_BINDING
|
||||
if (NULL != _editBox && 0 != _editBox->getScriptEditBoxHandler())
|
||||
{
|
||||
cocos2d::CommonScriptData data(_editBox->getScriptEditBoxHandler(), "began", _editBox);
|
||||
cocos2d::ScriptEvent event(cocos2d::kCommonEvent, (void *)&data);
|
||||
cocos2d::ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void EditBoxImplAndroid::editBoxEditingDidEnd(const std::string& text)
|
||||
{
|
||||
// LOGD("textFieldShouldEndEditing...");
|
||||
_text = text;
|
||||
this->refreshInactiveText();
|
||||
|
||||
cocos2d::ui::EditBoxDelegate *pDelegate = _editBox->getDelegate();
|
||||
if (pDelegate != nullptr)
|
||||
{
|
||||
pDelegate->editBoxEditingDidEnd(_editBox);
|
||||
pDelegate->editBoxReturn(_editBox);
|
||||
}
|
||||
|
||||
#if CC_ENABLE_SCRIPT_BINDING
|
||||
if (_editBox != nullptr && 0 != _editBox->getScriptEditBoxHandler())
|
||||
{
|
||||
cocos2d::CommonScriptData data(_editBox->getScriptEditBoxHandler(), "ended", _editBox);
|
||||
cocos2d::ScriptEvent event(cocos2d::kCommonEvent, (void *)&data);
|
||||
cocos2d::ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event);
|
||||
memset(data.eventName, 0, sizeof(data.eventName));
|
||||
strncpy(data.eventName, "return", sizeof(data.eventName));
|
||||
event.data = (void *)&data;
|
||||
cocos2d::ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (_editBox != nullptr)
|
||||
{
|
||||
this->onEndEditing(text);
|
||||
}
|
||||
}
|
||||
|
||||
void EditBoxImplAndroid::editBoxEditingChanged(const std::string& text)
|
||||
{
|
||||
// LOGD("editBoxTextChanged...");
|
||||
cocos2d::ui::EditBoxDelegate *pDelegate = _editBox->getDelegate();
|
||||
_text = text;
|
||||
if (pDelegate != nullptr)
|
||||
{
|
||||
pDelegate->editBoxTextChanged(_editBox, text);
|
||||
}
|
||||
|
||||
#if CC_ENABLE_SCRIPT_BINDING
|
||||
if (NULL != _editBox && 0 != _editBox->getScriptEditBoxHandler())
|
||||
{
|
||||
cocos2d::CommonScriptData data(_editBox->getScriptEditBoxHandler(), "changed", _editBox);
|
||||
cocos2d::ScriptEvent event(cocos2d::kCommonEvent, (void *)&data);
|
||||
cocos2d::ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
EditBoxImplAndroid::EditBoxImplAndroid(EditBox* pEditText)
|
||||
|
@ -52,13 +152,14 @@ EditBoxImplAndroid::EditBoxImplAndroid(EditBox* pEditText)
|
|||
, _colText(Color3B::WHITE)
|
||||
, _colPlaceHolder(Color3B::GRAY)
|
||||
, _maxLength(-1)
|
||||
, _editBoxIndex(-1)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
EditBoxImplAndroid::~EditBoxImplAndroid()
|
||||
{
|
||||
|
||||
s_allEditBoxes.erase(_editBoxIndex);
|
||||
removeEditBoxJNI(_editBoxIndex);
|
||||
}
|
||||
|
||||
void EditBoxImplAndroid::doAnimationWhenKeyboardMove(float duration, float distance)
|
||||
|
@ -70,7 +171,10 @@ static const int CC_EDIT_BOX_PADDING = 5;
|
|||
|
||||
bool EditBoxImplAndroid::initWithSize(const Size& size)
|
||||
{
|
||||
int fontSize = getFontSizeAccordingHeightJni(size.height-12);
|
||||
auto rect = Rect(0,0, size.width, size.height);
|
||||
_editBoxIndex = addEditBoxJNI(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
|
||||
s_allEditBoxes[_editBoxIndex] = this;
|
||||
|
||||
_label = Label::create();
|
||||
_label->setSystemFontSize(size.height-12);
|
||||
// align the text vertically center
|
||||
|
@ -94,45 +198,72 @@ bool EditBoxImplAndroid::initWithSize(const Size& size)
|
|||
|
||||
void EditBoxImplAndroid::setFont(const char* pFontName, int fontSize)
|
||||
{
|
||||
if(_label != NULL) {
|
||||
_label->setSystemFontName(pFontName);
|
||||
_label->setSystemFontSize(fontSize);
|
||||
}
|
||||
if(_label != NULL)
|
||||
{
|
||||
if(strlen(pFontName) > 0)
|
||||
{
|
||||
_label->setSystemFontName(pFontName);
|
||||
}
|
||||
if(fontSize > 0)
|
||||
{
|
||||
_label->setSystemFontSize(fontSize);
|
||||
}
|
||||
}
|
||||
|
||||
if(_labelPlaceHolder != NULL) {
|
||||
_labelPlaceHolder->setSystemFontName(pFontName);
|
||||
_labelPlaceHolder->setSystemFontSize(fontSize);
|
||||
}
|
||||
if(_labelPlaceHolder != NULL)
|
||||
{
|
||||
if(strlen(pFontName) > 0)
|
||||
{
|
||||
_labelPlaceHolder->setSystemFontName(pFontName);
|
||||
}
|
||||
if(fontSize > 0)
|
||||
{
|
||||
_labelPlaceHolder->setSystemFontSize(fontSize);
|
||||
}
|
||||
}
|
||||
setFontEditBoxJNI(_editBoxIndex, pFontName, fontSize);
|
||||
}
|
||||
|
||||
void EditBoxImplAndroid::setFontColor(const Color4B& color)
|
||||
{
|
||||
_colText = color;
|
||||
_label->setTextColor(color);
|
||||
setFontColorEditBoxJNI(_editBoxIndex, color.r, color.g, color.b, color.a);
|
||||
}
|
||||
|
||||
void EditBoxImplAndroid::setPlaceholderFont(const char* pFontName, int fontSize)
|
||||
{
|
||||
if(_labelPlaceHolder != NULL) {
|
||||
_labelPlaceHolder->setSystemFontName(pFontName);
|
||||
_labelPlaceHolder->setSystemFontSize(fontSize);
|
||||
}
|
||||
if(_labelPlaceHolder != NULL)
|
||||
{
|
||||
if(strlen(pFontName) > 0)
|
||||
{
|
||||
_labelPlaceHolder->setSystemFontName(pFontName);
|
||||
}
|
||||
if(fontSize > 0)
|
||||
{
|
||||
_labelPlaceHolder->setSystemFontSize(fontSize);
|
||||
}
|
||||
}
|
||||
CCLOG("Wraning! You can't change Andriod Hint fontName and fontSize");
|
||||
}
|
||||
|
||||
void EditBoxImplAndroid::setPlaceholderFontColor(const Color4B& color)
|
||||
{
|
||||
_colPlaceHolder = color;
|
||||
_labelPlaceHolder->setTextColor(color);
|
||||
setPlaceHolderTextColorEditBoxJNI(_editBoxIndex, color.r, color.g, color.b, color.a);
|
||||
}
|
||||
|
||||
void EditBoxImplAndroid::setInputMode(EditBox::InputMode inputMode)
|
||||
{
|
||||
_editBoxInputMode = inputMode;
|
||||
setInputModeEditBoxJNI(_editBoxIndex, static_cast<int>(inputMode));
|
||||
}
|
||||
|
||||
void EditBoxImplAndroid::setMaxLength(int maxLength)
|
||||
{
|
||||
_maxLength = maxLength;
|
||||
setMaxLengthJNI(_editBoxIndex, _maxLength);
|
||||
}
|
||||
|
||||
int EditBoxImplAndroid::getMaxLength()
|
||||
|
@ -143,11 +274,13 @@ int EditBoxImplAndroid::getMaxLength()
|
|||
void EditBoxImplAndroid::setInputFlag(EditBox::InputFlag inputFlag)
|
||||
{
|
||||
_editBoxInputFlag = inputFlag;
|
||||
setInputFlagEditBoxJNI(_editBoxIndex, static_cast<int>(inputFlag));
|
||||
}
|
||||
|
||||
void EditBoxImplAndroid::setReturnType(EditBox::KeyboardReturnType returnType)
|
||||
{
|
||||
_keyboardReturnType = returnType;
|
||||
setReturnTypeEditBoxJNI(_editBoxIndex, static_cast<int>(returnType));
|
||||
}
|
||||
|
||||
bool EditBoxImplAndroid::isEditing()
|
||||
|
@ -155,48 +288,46 @@ bool EditBoxImplAndroid::isEditing()
|
|||
return false;
|
||||
}
|
||||
|
||||
void EditBoxImplAndroid::setInactiveText(const char* pText)
|
||||
{
|
||||
if(EditBox::InputFlag::PASSWORD == _editBoxInputFlag)
|
||||
{
|
||||
std::string passwordString;
|
||||
for(int i = 0; i < strlen(pText); ++i)
|
||||
passwordString.append("\u25CF");
|
||||
_label->setString(passwordString.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
_label->setString(pText);
|
||||
}
|
||||
// Clip the text width to fit to the text box
|
||||
float fMaxWidth = _editBox->getContentSize().width - CC_EDIT_BOX_PADDING * 2;
|
||||
Size labelSize = _label->getContentSize();
|
||||
if(labelSize.width > fMaxWidth) {
|
||||
_label->setDimensions(fMaxWidth,labelSize.height);
|
||||
}
|
||||
}
|
||||
|
||||
void EditBoxImplAndroid::refreshInactiveText()
|
||||
{
|
||||
setInactiveText(_text.c_str());
|
||||
if(_text.size() == 0)
|
||||
{
|
||||
_label->setVisible(false);
|
||||
_labelPlaceHolder->setVisible(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
_label->setVisible(true);
|
||||
_labelPlaceHolder->setVisible(false);
|
||||
}
|
||||
}
|
||||
void EditBoxImplAndroid::setText(const char* pText)
|
||||
{
|
||||
if (pText != NULL)
|
||||
{
|
||||
_text = pText;
|
||||
|
||||
if (_text.length() > 0)
|
||||
{
|
||||
_labelPlaceHolder->setVisible(false);
|
||||
|
||||
std::string strToShow;
|
||||
|
||||
if (EditBox::InputFlag::PASSWORD == _editBoxInputFlag)
|
||||
{
|
||||
long length = cc_utf8_strlen(_text.c_str(), -1);
|
||||
for (long i = 0; i < length; i++)
|
||||
{
|
||||
strToShow.append("*");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
strToShow = _text;
|
||||
}
|
||||
|
||||
_label->setString(strToShow.c_str());
|
||||
|
||||
// Clip the text width to fit to the text box
|
||||
|
||||
float fMaxWidth = _editSize.width - CC_EDIT_BOX_PADDING * 2;
|
||||
auto labelSize = _label->getContentSize();
|
||||
if(labelSize.width > fMaxWidth) {
|
||||
_label->setDimensions(fMaxWidth,labelSize.height);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_labelPlaceHolder->setVisible(true);
|
||||
_label->setString("");
|
||||
}
|
||||
|
||||
}
|
||||
setTextEditBoxJNI(_editBoxIndex, pText);
|
||||
_text = pText;
|
||||
refreshInactiveText();
|
||||
}
|
||||
|
||||
const char* EditBoxImplAndroid::getText(void)
|
||||
|
@ -215,105 +346,98 @@ void EditBoxImplAndroid::setPlaceHolder(const char* pText)
|
|||
}
|
||||
|
||||
_labelPlaceHolder->setString(_placeHolder.c_str());
|
||||
setPlaceHolderTextEditBoxJNI(_editBoxIndex, pText);
|
||||
}
|
||||
}
|
||||
|
||||
void EditBoxImplAndroid::setPosition(const Vec2& pos)
|
||||
{ // don't need to be implemented on android platform.
|
||||
|
||||
}
|
||||
|
||||
void EditBoxImplAndroid::setVisible(bool visible)
|
||||
{ // don't need to be implemented on android platform.
|
||||
|
||||
setVisibleEditBoxJNI(_editBoxIndex, visible);
|
||||
}
|
||||
|
||||
void EditBoxImplAndroid::setContentSize(const Size& size)
|
||||
{ // don't need to be implemented on android platform.
|
||||
|
||||
}
|
||||
|
||||
void EditBoxImplAndroid::setAnchorPoint(const Vec2& anchorPoint)
|
||||
{ // don't need to be implemented on android platform.
|
||||
|
||||
}
|
||||
|
||||
void EditBoxImplAndroid::visit(void)
|
||||
void EditBoxImplAndroid::draw(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags)
|
||||
{ // don't need to be implemented on android platform.
|
||||
|
||||
if(parentFlags)
|
||||
{
|
||||
auto rect = ui::Helper::convertBoundingBoxToScreen(_editBox);
|
||||
setEditBoxViewRectJNI(_editBoxIndex, rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
|
||||
}
|
||||
}
|
||||
|
||||
void EditBoxImplAndroid::onEnter(void)
|
||||
{ // don't need to be implemented on android platform.
|
||||
|
||||
}
|
||||
|
||||
static void editBoxCallbackFunc(const char* pText, void* ctx)
|
||||
{
|
||||
EditBoxImplAndroid* thiz = (EditBoxImplAndroid*)ctx;
|
||||
thiz->setText(pText);
|
||||
|
||||
if (thiz->getDelegate() != NULL)
|
||||
{
|
||||
thiz->getDelegate()->editBoxTextChanged(thiz->getEditBox(), thiz->getText());
|
||||
thiz->getDelegate()->editBoxEditingDidEnd(thiz->getEditBox());
|
||||
thiz->getDelegate()->editBoxReturn(thiz->getEditBox());
|
||||
}
|
||||
|
||||
#if CC_ENABLE_SCRIPT_BINDING
|
||||
EditBox* pEditBox = thiz->getEditBox();
|
||||
if (NULL != pEditBox && 0 != pEditBox->getScriptEditBoxHandler())
|
||||
{
|
||||
CommonScriptData data(pEditBox->getScriptEditBoxHandler(), "changed",pEditBox);
|
||||
ScriptEvent event(kCommonEvent,(void*)&data);
|
||||
ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event);
|
||||
memset(data.eventName, 0, sizeof(data.eventName));
|
||||
strncpy(data.eventName, "ended", sizeof(data.eventName));
|
||||
event.data = (void*)&data;
|
||||
ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event);
|
||||
memset(data.eventName, 0, sizeof(data.eventName));
|
||||
strncpy(data.eventName, "return", sizeof(data.eventName));
|
||||
event.data = (void*)&data;
|
||||
ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void EditBoxImplAndroid::openKeyboard()
|
||||
{
|
||||
if (_delegate != NULL)
|
||||
{
|
||||
_delegate->editBoxEditingDidBegin(_editBox);
|
||||
}
|
||||
|
||||
#if CC_ENABLE_SCRIPT_BINDING
|
||||
EditBox* pEditBox = this->getEditBox();
|
||||
if (NULL != pEditBox && 0 != pEditBox->getScriptEditBoxHandler())
|
||||
{
|
||||
CommonScriptData data(pEditBox->getScriptEditBoxHandler(), "began",pEditBox);
|
||||
ScriptEvent event(cocos2d::kCommonEvent,(void*)&data);
|
||||
ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event);
|
||||
}
|
||||
#endif
|
||||
|
||||
showEditTextDialogJNI( _placeHolder.c_str(),
|
||||
_text.c_str(),
|
||||
(int)_editBoxInputMode,
|
||||
(int)_editBoxInputFlag,
|
||||
(int)_keyboardReturnType,
|
||||
_maxLength,
|
||||
editBoxCallbackFunc,
|
||||
(void*)this );
|
||||
|
||||
_label->setVisible(false);
|
||||
_labelPlaceHolder->setVisible(false);
|
||||
|
||||
//it will also open up the soft keyboard
|
||||
setVisibleEditBoxJNI(_editBoxIndex,true);
|
||||
}
|
||||
|
||||
|
||||
void EditBoxImplAndroid::closeKeyboard()
|
||||
{
|
||||
|
||||
closeEditBoxKeyboardJNI(_editBoxIndex);
|
||||
}
|
||||
|
||||
void EditBoxImplAndroid::onEndEditing(const std::string& text)
|
||||
{
|
||||
setVisibleEditBoxJNI(_editBoxIndex, false);
|
||||
if(text.size() == 0)
|
||||
{
|
||||
_label->setVisible(false);
|
||||
_labelPlaceHolder->setVisible(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
_label->setVisible(true);
|
||||
_labelPlaceHolder->setVisible(false);
|
||||
setInactiveText(text.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void editBoxEditingDidBegin(int index)
|
||||
{
|
||||
auto it = s_allEditBoxes.find(index);
|
||||
if (it != s_allEditBoxes.end())
|
||||
{
|
||||
s_allEditBoxes[index]->editBoxEditingDidBegin();
|
||||
}
|
||||
}
|
||||
void editBoxEditingDidChanged(int index, const std::string& text)
|
||||
{
|
||||
auto it = s_allEditBoxes.find(index);
|
||||
if (it != s_allEditBoxes.end())
|
||||
{
|
||||
s_allEditBoxes[index]->editBoxEditingChanged(text);
|
||||
}
|
||||
}
|
||||
|
||||
void editBoxEditingDidEnd(int index, const std::string& text)
|
||||
{
|
||||
auto it = s_allEditBoxes.find(index);
|
||||
if (it != s_allEditBoxes.end())
|
||||
{
|
||||
s_allEditBoxes[index]->editBoxEditingDidEnd(text);
|
||||
}
|
||||
}
|
||||
} //end of ui namespace
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif /* #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) */
|
||||
|
|
|
@ -53,40 +53,49 @@ public:
|
|||
*/
|
||||
virtual ~EditBoxImplAndroid();
|
||||
|
||||
virtual bool initWithSize(const Size& size);
|
||||
virtual void setFont(const char* pFontName, int fontSize);
|
||||
virtual void setFontColor(const Color4B& color);
|
||||
virtual void setPlaceholderFont(const char* pFontName, int fontSize);
|
||||
virtual void setPlaceholderFontColor(const Color4B& color);
|
||||
virtual void setInputMode(EditBox::InputMode inputMode);
|
||||
virtual void setInputFlag(EditBox::InputFlag inputFlag);
|
||||
virtual void setMaxLength(int maxLength);
|
||||
virtual int getMaxLength();
|
||||
virtual void setReturnType(EditBox::KeyboardReturnType returnType);
|
||||
virtual bool isEditing();
|
||||
virtual bool initWithSize(const Size& size) override;
|
||||
virtual void setFont(const char* pFontName, int fontSize) override;
|
||||
virtual void setFontColor(const Color4B& color) override;
|
||||
virtual void setPlaceholderFont(const char* pFontName, int fontSize) override;
|
||||
virtual void setPlaceholderFontColor(const Color4B& color) override;
|
||||
virtual void setInputMode(EditBox::InputMode inputMode) override;
|
||||
virtual void setInputFlag(EditBox::InputFlag inputFlag) override;
|
||||
virtual void setMaxLength(int maxLength) override;
|
||||
virtual int getMaxLength() override;
|
||||
virtual void setReturnType(EditBox::KeyboardReturnType returnType) override;
|
||||
virtual bool isEditing() override;
|
||||
|
||||
virtual void setText(const char* pText);
|
||||
virtual const char* getText(void);
|
||||
virtual void setPlaceHolder(const char* pText);
|
||||
virtual void setPosition(const Vec2& pos);
|
||||
virtual void setVisible(bool visible);
|
||||
virtual void setContentSize(const Size& size);
|
||||
virtual void setAnchorPoint(const Vec2& anchorPoint);
|
||||
virtual void setText(const char* pText) override;
|
||||
virtual const char* getText(void) override;
|
||||
virtual void setPlaceHolder(const char* pText) override;
|
||||
virtual void setPosition(const Vec2& pos) override;
|
||||
virtual void setVisible(bool visible) override;
|
||||
virtual void setContentSize(const Size& size) override;
|
||||
virtual void setAnchorPoint(const Vec2& anchorPoint) override;
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
virtual void visit(void);
|
||||
virtual void draw(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags) override;
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
virtual void onEnter(void);
|
||||
virtual void doAnimationWhenKeyboardMove(float duration, float distance);
|
||||
virtual void openKeyboard();
|
||||
virtual void closeKeyboard();
|
||||
|
||||
virtual void onEnter(void) override;
|
||||
virtual void doAnimationWhenKeyboardMove(float duration, float distance) override;
|
||||
virtual void openKeyboard() override;
|
||||
virtual void closeKeyboard() override;
|
||||
|
||||
|
||||
void editBoxEditingDidBegin();
|
||||
void editBoxEditingChanged(const std::string& text);
|
||||
void editBoxEditingDidEnd(const std::string& text);
|
||||
private:
|
||||
void setInactiveText(const char* pText);
|
||||
void onEndEditing(const std::string& text);
|
||||
void refreshInactiveText();
|
||||
|
||||
|
||||
Label* _label;
|
||||
Label* _labelPlaceHolder;
|
||||
EditBox::InputMode _editBoxInputMode;
|
||||
|
@ -101,6 +110,8 @@ private:
|
|||
|
||||
int _maxLength;
|
||||
Size _editSize;
|
||||
|
||||
int _editBoxIndex;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -79,7 +79,7 @@ public:
|
|||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
virtual void visit(void);
|
||||
virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)override;
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
|
@ -95,6 +95,7 @@ private:
|
|||
void setInactiveText(const char* pText);
|
||||
void adjustTextFieldPosition();
|
||||
void placeInactiveLabels();
|
||||
UIFont* constructFont(const char* fontName, int fontSize);
|
||||
|
||||
Label* _label;
|
||||
Label* _labelPlaceHolder;
|
||||
|
|
|
@ -406,36 +406,53 @@ void EditBoxImplIOS::setInactiveText(const char* pText)
|
|||
_label->setDimensions(fMaxWidth,labelSize.height);
|
||||
}
|
||||
}
|
||||
|
||||
UIFont* EditBoxImplIOS::constructFont(const char *fontName, int fontSize)
|
||||
{
|
||||
CCASSERT(fontName != nullptr, "fontName can't be nullptr");
|
||||
CCEAGLView *eaglview = static_cast<CCEAGLView *>(cocos2d::Director::getInstance()->getOpenGLView()->getEAGLView());
|
||||
float retinaFactor = eaglview.contentScaleFactor;
|
||||
NSString * fntName = [NSString stringWithUTF8String:fontName];
|
||||
|
||||
auto glview = cocos2d::Director::getInstance()->getOpenGLView();
|
||||
float scaleFactor = glview->getScaleX();
|
||||
|
||||
if (fontSize == -1)
|
||||
{
|
||||
fontSize = [_systemControl.textField frame].size.height*2/3;
|
||||
}
|
||||
else
|
||||
{
|
||||
fontSize = fontSize * scaleFactor / retinaFactor;
|
||||
}
|
||||
|
||||
UIFont *textFont = nil;
|
||||
if (strlen(fontName) > 0)
|
||||
{
|
||||
textFont = [UIFont fontWithName:fntName size:fontSize];
|
||||
}
|
||||
else
|
||||
{
|
||||
textFont = [UIFont systemFontOfSize:fontSize];
|
||||
}
|
||||
return textFont;
|
||||
}
|
||||
|
||||
void EditBoxImplIOS::setFont(const char* pFontName, int fontSize)
|
||||
{
|
||||
bool isValidFontName = true;
|
||||
if(pFontName == NULL || strlen(pFontName) == 0) {
|
||||
isValidFontName = false;
|
||||
}
|
||||
|
||||
CCEAGLView *eaglview = static_cast<CCEAGLView *>(cocos2d::Director::getInstance()->getOpenGLView()->getEAGLView());
|
||||
float retinaFactor = eaglview.contentScaleFactor;
|
||||
NSString * fntName = [NSString stringWithUTF8String:pFontName];
|
||||
|
||||
auto glview = cocos2d::Director::getInstance()->getOpenGLView();
|
||||
|
||||
float scaleFactor = glview->getScaleX();
|
||||
UIFont *textFont = nil;
|
||||
if (isValidFontName) {
|
||||
textFont = [UIFont fontWithName:fntName size:fontSize * scaleFactor / retinaFactor];
|
||||
}
|
||||
|
||||
if (!isValidFontName || textFont == nil){
|
||||
textFont = [UIFont systemFontOfSize:fontSize * scaleFactor / retinaFactor];
|
||||
}
|
||||
|
||||
UIFont* textFont = constructFont(pFontName, fontSize);
|
||||
if(textFont != nil) {
|
||||
[_systemControl.textField setFont:textFont];
|
||||
}
|
||||
|
||||
_label->setSystemFontName(pFontName);
|
||||
_label->setSystemFontSize(fontSize);
|
||||
if(strlen(pFontName) > 0)
|
||||
{
|
||||
_label->setSystemFontName(pFontName);
|
||||
}
|
||||
if(fontSize > 0)
|
||||
{
|
||||
_label->setSystemFontSize(fontSize);
|
||||
}
|
||||
}
|
||||
|
||||
void EditBoxImplIOS::setFontColor(const Color4B& color)
|
||||
|
@ -446,8 +463,14 @@ void EditBoxImplIOS::setFontColor(const Color4B& color)
|
|||
|
||||
void EditBoxImplIOS::setPlaceholderFont(const char* pFontName, int fontSize)
|
||||
{
|
||||
_labelPlaceHolder->setSystemFontName(pFontName);
|
||||
_labelPlaceHolder->setSystemFontSize(fontSize);
|
||||
if( strlen(pFontName) > 0)
|
||||
{
|
||||
_labelPlaceHolder->setSystemFontName(pFontName);
|
||||
}
|
||||
if(fontSize > 0)
|
||||
{
|
||||
_labelPlaceHolder->setSystemFontSize(fontSize);
|
||||
}
|
||||
}
|
||||
|
||||
void EditBoxImplIOS::setPlaceholderFontColor(const Color4B &color)
|
||||
|
@ -647,7 +670,7 @@ void EditBoxImplIOS::setAnchorPoint(const Vec2& anchorPoint)
|
|||
setPosition(_position);
|
||||
}
|
||||
|
||||
void EditBoxImplIOS::visit(void)
|
||||
void EditBoxImplIOS::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -76,7 +76,7 @@ public:
|
|||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
virtual void visit(void);
|
||||
virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)override;
|
||||
virtual void doAnimationWhenKeyboardMove(float duration, float distance);
|
||||
virtual void openKeyboard();
|
||||
virtual void closeKeyboard();
|
||||
|
@ -89,12 +89,13 @@ public:
|
|||
private:
|
||||
NSPoint convertDesignCoordToScreenCoord(const Vec2& designCoord, bool bInRetinaMode);
|
||||
void adjustTextFieldPosition();
|
||||
Size _contentSize;
|
||||
Vec2 _position;
|
||||
Vec2 _anchorPoint;
|
||||
int _maxTextLength;
|
||||
bool _inRetinaMode;
|
||||
UIEditBoxImplMac* _sysEdit;
|
||||
NSFont* constructFont(const char* fontName, int fontSize);
|
||||
Size _contentSize;
|
||||
Vec2 _position;
|
||||
Vec2 _anchorPoint;
|
||||
int _maxTextLength;
|
||||
bool _inRetinaMode;
|
||||
UIEditBoxImplMac* _sysEdit;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -352,14 +352,40 @@ bool EditBoxImplMac::initWithSize(const Size& size)
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
void EditBoxImplMac::setFont(const char* pFontName, int fontSize)
|
||||
|
||||
NSFont* EditBoxImplMac::constructFont(const char *fontName, int fontSize)
|
||||
{
|
||||
NSString * fntName = [NSString stringWithUTF8String:pFontName];
|
||||
NSString * fntName = [NSString stringWithUTF8String:fontName];
|
||||
float retinaFactor = _inRetinaMode ? 2.0f : 1.0f;
|
||||
auto glview = cocos2d::Director::getInstance()->getOpenGLView();
|
||||
float scaleFactor = glview->getScaleX();
|
||||
NSFont *textFont = [NSFont fontWithName:fntName size:fontSize * scaleFactor / retinaFactor];
|
||||
|
||||
if (fontSize == -1)
|
||||
{
|
||||
NSRect frameRect = [_sysEdit.textField frame];
|
||||
fontSize = frameRect.size.height*2/3;
|
||||
}
|
||||
else
|
||||
{
|
||||
fontSize = fontSize * scaleFactor / retinaFactor;
|
||||
}
|
||||
|
||||
NSFont *textFont = nil;
|
||||
if (strlen(fontName) == 0)
|
||||
{
|
||||
textFont = [NSFont systemFontOfSize:fontSize];
|
||||
}
|
||||
else
|
||||
{
|
||||
textFont = [NSFont fontWithName:fntName size:fontSize];
|
||||
}
|
||||
|
||||
return textFont;
|
||||
}
|
||||
|
||||
void EditBoxImplMac::setFont(const char* pFontName, int fontSize)
|
||||
{
|
||||
NSFont* textFont = constructFont(pFontName, fontSize);
|
||||
if (textFont != nil) {
|
||||
[_sysEdit.textField setFont:textFont];
|
||||
[_sysEdit.secureTextField setFont:textFont];
|
||||
|
@ -368,18 +394,14 @@ void EditBoxImplMac::setFont(const char* pFontName, int fontSize)
|
|||
|
||||
void EditBoxImplMac::setPlaceholderFont(const char* pFontName, int fontSize)
|
||||
{
|
||||
NSString *fontName = [NSString stringWithUTF8String:pFontName];
|
||||
float retinaFactor = _inRetinaMode ? 2.0f : 1.0f;
|
||||
auto glview = cocos2d::Director::getInstance()->getOpenGLView();
|
||||
float scaleFactor = glview->getScaleX();
|
||||
NSFont *font = [NSFont fontWithName:fontName size:fontSize * scaleFactor / retinaFactor];
|
||||
NSFont *textFont = constructFont(pFontName, fontSize);
|
||||
|
||||
if (!font) {
|
||||
if (!textFont) {
|
||||
CCLOGWARN("Font not found: %s", pFontName);
|
||||
return;
|
||||
}
|
||||
|
||||
[_sysEdit.placeholderAttributes setObject:font forKey:NSFontAttributeName];
|
||||
[_sysEdit.placeholderAttributes setObject:textFont forKey:NSFontAttributeName];
|
||||
|
||||
/* reload placeholder */
|
||||
const char *placeholder = [_sysEdit.textField.cell placeholderAttributedString].string.UTF8String;
|
||||
|
@ -550,7 +572,7 @@ void EditBoxImplMac::setAnchorPoint(const Vec2& anchorPoint)
|
|||
setPosition(_position);
|
||||
}
|
||||
|
||||
void EditBoxImplMac::visit(void)
|
||||
void EditBoxImplMac::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -530,16 +530,28 @@ bool EditBoxImplWin::initWithSize(const Size& size)
|
|||
void EditBoxImplWin::setFont(const char* pFontName, int fontSize)
|
||||
{
|
||||
if (_label != nullptr)
|
||||
{
|
||||
_label->setSystemFontName(pFontName);
|
||||
_label->setSystemFontSize(fontSize);
|
||||
}
|
||||
{
|
||||
if(strlen(pFontName) > 0)
|
||||
{
|
||||
_label->setSystemFontName(pFontName);
|
||||
}
|
||||
if(fontSize > 0)
|
||||
{
|
||||
_label->setSystemFontSize(fontSize);
|
||||
}
|
||||
}
|
||||
|
||||
if (_labelPlaceHolder != nullptr)
|
||||
{
|
||||
_labelPlaceHolder->setSystemFontName(pFontName);
|
||||
_labelPlaceHolder->setSystemFontSize(fontSize);
|
||||
}
|
||||
{
|
||||
if(strlen(pFontName) > 0)
|
||||
{
|
||||
_labelPlaceHolder->setSystemFontName(pFontName);
|
||||
}
|
||||
if(fontSize > 0)
|
||||
{
|
||||
_labelPlaceHolder->setSystemFontSize(fontSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EditBoxImplWin::setFontColor(const Color4B& color)
|
||||
|
@ -551,10 +563,16 @@ void EditBoxImplWin::setFontColor(const Color4B& color)
|
|||
void EditBoxImplWin::setPlaceholderFont(const char* pFontName, int fontSize)
|
||||
{
|
||||
if (_labelPlaceHolder != nullptr)
|
||||
{
|
||||
_labelPlaceHolder->setSystemFontName(pFontName);
|
||||
_labelPlaceHolder->setSystemFontSize(fontSize);
|
||||
}
|
||||
{
|
||||
if(strlen(pFontName) > 0)
|
||||
{
|
||||
_labelPlaceHolder->setSystemFontName(pFontName);
|
||||
}
|
||||
if(fontSize > 0)
|
||||
{
|
||||
_labelPlaceHolder->setSystemFontSize(fontSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EditBoxImplWin::setPlaceholderFontColor(const Color4B& color)
|
||||
|
@ -676,7 +694,7 @@ void EditBoxImplWin::setAnchorPoint(const Vec2& anchorPoint)
|
|||
|
||||
}
|
||||
|
||||
void EditBoxImplWin::visit(void)
|
||||
void EditBoxImplWin::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@ public:
|
|||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
virtual void visit(void);
|
||||
virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)override;
|
||||
virtual void doAnimationWhenKeyboardMove(float duration, float distance);
|
||||
virtual void openKeyboard();
|
||||
virtual void closeKeyboard();
|
||||
|
|
|
@ -392,14 +392,27 @@ bool UIEditBoxImplWinrt::initWithSize( const Size& size )
|
|||
|
||||
void UIEditBoxImplWinrt::setFont( const char* pFontName, int fontSize )
|
||||
{
|
||||
if(m_pLabel != NULL) {
|
||||
m_pLabel->setSystemFontName(pFontName);
|
||||
m_pLabel->setSystemFontSize(fontSize);
|
||||
if(m_pLabel != NULL)
|
||||
{
|
||||
if(strlen(pFontName) > 0)
|
||||
{
|
||||
m_pLabel->setSystemFontName(pFontName);
|
||||
}
|
||||
if(fontSize > 0)
|
||||
{
|
||||
m_pLabel->setSystemFontSize(fontSize);
|
||||
}
|
||||
}
|
||||
|
||||
if(m_pLabelPlaceHolder != NULL) {
|
||||
m_pLabelPlaceHolder->setSystemFontName(pFontName);
|
||||
m_pLabelPlaceHolder->setSystemFontSize(fontSize);
|
||||
if(strlen(pFontName) > 0)
|
||||
{
|
||||
m_pLabelPlaceHolder->setSystemFontName(pFontName);
|
||||
}
|
||||
if(fontSize > 0)
|
||||
{
|
||||
m_pLabelPlaceHolder->setSystemFontSize(fontSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -411,9 +424,16 @@ void UIEditBoxImplWinrt::setFontColor( const Color4B& color )
|
|||
|
||||
void UIEditBoxImplWinrt::setPlaceholderFont( const char* pFontName, int fontSize )
|
||||
{
|
||||
if(m_pLabelPlaceHolder != NULL) {
|
||||
m_pLabelPlaceHolder->setSystemFontName(pFontName);
|
||||
m_pLabelPlaceHolder->setSystemFontSize(fontSize);
|
||||
if(m_pLabelPlaceHolder != NULL)
|
||||
{
|
||||
if(strlen(pFontName) > 0)
|
||||
{
|
||||
m_pLabelPlaceHolder->setSystemFontName(pFontName);
|
||||
}
|
||||
if(fontSize > 0)
|
||||
{
|
||||
m_pLabelPlaceHolder->setSystemFontSize(fontSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -530,7 +550,7 @@ void UIEditBoxImplWinrt::setAnchorPoint( const Vec2& anchorPoint )
|
|||
|
||||
}
|
||||
|
||||
void UIEditBoxImplWinrt::visit( void )
|
||||
void UIEditBoxImplWinrt::draw(cocos2d::Renderer *renderer, cocos2d::Mat4 const &transform, uint32_t flags)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -110,7 +110,7 @@ namespace ui {
|
|||
virtual void setVisible(bool visible);
|
||||
virtual void setContentSize(const Size& size);
|
||||
virtual void setAnchorPoint(const Vec2& anchorPoint);
|
||||
virtual void visit(void);
|
||||
virtual void draw(cocos2d::Renderer *renderer, cocos2d::Mat4 const &transform, uint32_t flags) override;
|
||||
virtual void doAnimationWhenKeyboardMove(float duration, float distance);
|
||||
virtual void openKeyboard();
|
||||
virtual void closeKeyboard();
|
||||
|
|
|
@ -78,7 +78,7 @@ namespace cocos2d {
|
|||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
virtual void visit(void) = 0;
|
||||
virtual void draw(cocos2d::Renderer *renderer, cocos2d::Mat4 const &transform, uint32_t flags) = 0;
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
|
|
|
@ -25,6 +25,7 @@ THE SOFTWARE.
|
|||
#include "ui/UIHelper.h"
|
||||
#include "ui/UIWidget.h"
|
||||
#include "ui/UILayoutComponent.h"
|
||||
#include "base/CCDirector.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -191,6 +192,26 @@ Rect Helper::restrictCapInsetRect(const cocos2d::Rect &capInsets, const Size& te
|
|||
}
|
||||
return Rect(x, y, width, height);
|
||||
}
|
||||
|
||||
Rect Helper::convertBoundingBoxToScreen(Node* node)
|
||||
{
|
||||
auto director = Director::getInstance();
|
||||
auto glView = director->getOpenGLView();
|
||||
auto frameSize = glView->getFrameSize();
|
||||
|
||||
auto winSize = director->getWinSize();
|
||||
auto leftBottom = node->convertToWorldSpace(Point::ZERO);
|
||||
|
||||
auto contentSize = node->getContentSize();
|
||||
auto rightTop = node->convertToWorldSpace(Point(contentSize.width, contentSize.height));
|
||||
|
||||
auto uiLeft = frameSize.width / 2 + (leftBottom.x - winSize.width / 2 ) * glView->getScaleX();
|
||||
auto uiTop = frameSize.height /2 - (rightTop.y - winSize.height / 2) * glView->getScaleY();
|
||||
|
||||
return Rect(uiLeft,uiTop,
|
||||
(rightTop.x - leftBottom.x) * glView->getScaleX(),
|
||||
(rightTop.y - leftBottom.y) * glView->getScaleY());
|
||||
}
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -111,6 +111,15 @@ public:
|
|||
*@return a restricted capInset.
|
||||
*/
|
||||
static Rect restrictCapInsetRect(const Rect& capInsets, const Size& textureSize);
|
||||
|
||||
/**
|
||||
*@brief Convert a node's boundingBox rect into screen coordinates.
|
||||
*
|
||||
* @param node Any node pointer.
|
||||
*
|
||||
* @return A Rect in screen coordinates.
|
||||
*/
|
||||
static Rect convertBoundingBoxToScreen(Node* node);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -507,6 +507,10 @@ void ListView::selectedItemEvent(TouchEventType event)
|
|||
void ListView::interceptTouchEvent(TouchEventType event, Widget *sender, Touch* touch)
|
||||
{
|
||||
ScrollView::interceptTouchEvent(event, sender, touch);
|
||||
if (!_touchEnabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (event != TouchEventType::MOVED)
|
||||
{
|
||||
Widget* parent = sender;
|
||||
|
|
|
@ -699,6 +699,11 @@ void PageView::handleReleaseLogic(Touch *touch)
|
|||
|
||||
void PageView::interceptTouchEvent(TouchEventType event, Widget *sender, Touch *touch)
|
||||
{
|
||||
if (!_touchEnabled)
|
||||
{
|
||||
Layout::interceptTouchEvent(event, sender, touch);
|
||||
return;
|
||||
}
|
||||
Vec2 touchPoint = touch->getLocation();
|
||||
|
||||
switch (event)
|
||||
|
|
|
@ -921,6 +921,12 @@ void ScrollView::update(float dt)
|
|||
|
||||
void ScrollView::interceptTouchEvent(Widget::TouchEventType event, Widget *sender,Touch* touch)
|
||||
{
|
||||
if(!_touchEnabled)
|
||||
{
|
||||
Layout::interceptTouchEvent(event, sender, touch);
|
||||
return;
|
||||
}
|
||||
|
||||
Vec2 touchPoint = touch->getLocation();
|
||||
switch (event)
|
||||
{
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
#include "base/CCDirector.h"
|
||||
#include "base/CCEventListenerKeyboard.h"
|
||||
#include "platform/CCFileUtils.h"
|
||||
#include "ui/UIHelper.h"
|
||||
|
||||
//-----------------------------------------------------------------------------------------------------------
|
||||
#define CLASS_NAME "org/cocos2dx/lib/Cocos2dxVideoHelper"
|
||||
|
@ -212,21 +213,10 @@ void VideoPlayer::draw(Renderer* renderer, const Mat4 &transform, uint32_t flags
|
|||
|
||||
if (flags & FLAGS_TRANSFORM_DIRTY)
|
||||
{
|
||||
auto directorInstance = Director::getInstance();
|
||||
auto glView = directorInstance->getOpenGLView();
|
||||
auto frameSize = glView->getFrameSize();
|
||||
auto uiRect = cocos2d::ui::Helper::convertBoundingBoxToScreen(this);
|
||||
|
||||
auto winSize = directorInstance->getWinSize();
|
||||
|
||||
auto leftBottom = convertToWorldSpace(Point::ZERO);
|
||||
auto rightTop = convertToWorldSpace(Point(_contentSize.width,_contentSize.height));
|
||||
|
||||
auto uiLeft = frameSize.width / 2 + (leftBottom.x - winSize.width / 2 ) * glView->getScaleX();
|
||||
auto uiTop = frameSize.height /2 - (rightTop.y - winSize.height / 2) * glView->getScaleY();
|
||||
|
||||
setVideoRectJNI(_videoPlayerIndex,uiLeft,uiTop,
|
||||
(rightTop.x - leftBottom.x) * glView->getScaleX(),
|
||||
(rightTop.y - leftBottom.y) * glView->getScaleY());
|
||||
setVideoRectJNI(_videoPlayerIndex, uiRect.origin.x, uiRect.origin.y,
|
||||
uiRect.size.width, uiRect.size.height);
|
||||
}
|
||||
|
||||
#if CC_VIDEOPLAYER_DEBUG_DRAW
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#include "platform/CCGLView.h"
|
||||
#include "base/CCDirector.h"
|
||||
#include "platform/CCFileUtils.h"
|
||||
#include "ui/UIHelper.h"
|
||||
|
||||
#define CLASS_NAME "org/cocos2dx/lib/Cocos2dxWebViewHelper"
|
||||
|
||||
|
@ -443,21 +444,10 @@ namespace cocos2d {
|
|||
|
||||
void WebViewImpl::draw(cocos2d::Renderer *renderer, cocos2d::Mat4 const &transform, uint32_t flags) {
|
||||
if (flags & cocos2d::Node::FLAGS_TRANSFORM_DIRTY) {
|
||||
auto directorInstance = cocos2d::Director::getInstance();
|
||||
auto glView = directorInstance->getOpenGLView();
|
||||
auto frameSize = glView->getFrameSize();
|
||||
auto uiRect = cocos2d::ui::Helper::convertBoundingBoxToScreen(_webView);
|
||||
|
||||
auto winSize = directorInstance->getWinSize();
|
||||
|
||||
auto leftBottom = this->_webView->convertToWorldSpace(cocos2d::Point::ZERO);
|
||||
auto rightTop = this->_webView->convertToWorldSpace(cocos2d::Point(this->_webView->getContentSize().width,this->_webView->getContentSize().height));
|
||||
|
||||
auto uiLeft = frameSize.width / 2 + (leftBottom.x - winSize.width / 2 ) * glView->getScaleX();
|
||||
auto uiTop = frameSize.height /2 - (rightTop.y - winSize.height / 2) * glView->getScaleY();
|
||||
|
||||
setWebViewRectJNI(_viewTag,uiLeft,uiTop,
|
||||
(rightTop.x - leftBottom.x) * glView->getScaleX(),
|
||||
(rightTop.y - leftBottom.y) * glView->getScaleY());
|
||||
setWebViewRectJNI(_viewTag, uiRect.origin.x, uiRect.origin.y,
|
||||
uiRect.size.width, uiRect.size.height);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 97 KiB After Width: | Height: | Size: 98 KiB |
|
@ -1,10 +1,9 @@
|
|||
{
|
||||
"version":"v3-deps-70",
|
||||
"zip_file_size":"130531291",
|
||||
"version":"v3-deps-71",
|
||||
"zip_file_size":"119277304",
|
||||
"repo_name":"cocos2d-x-3rd-party-libs-bin",
|
||||
"repo_parent":"https://github.com/cocos2d/",
|
||||
"move_dirs":{
|
||||
"fbx-conv":"tools",
|
||||
"plutil-win32":"tools/framework-compile/bin/proj_modifier"
|
||||
"fbx-conv":"tools"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -919,7 +919,8 @@
|
|||
"cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxAccelerometer.java",
|
||||
"cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxActivity.java",
|
||||
"cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxBitmap.java",
|
||||
"cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxEditBoxDialog.java",
|
||||
"cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxEditBox.java",
|
||||
"cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxEditBoxHelper.java",
|
||||
"cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxEditText.java",
|
||||
"cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxGLSurfaceView.java",
|
||||
"cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxHandler.java",
|
||||
|
@ -5222,92 +5223,6 @@
|
|||
"tools/fbx-conv/README.md",
|
||||
"tools/fbx-conv/mac/fbx-conv",
|
||||
"tools/fbx-conv/mac/libfbxsdk.dylib",
|
||||
"tools/framework-compile/bin-templates/cpp-template-default/Classes/AppDelegate.cpp",
|
||||
"tools/framework-compile/bin-templates/cpp-template-default/Classes/HelloWorldScene.cpp",
|
||||
"tools/framework-compile/bin-templates/cpp-template-default/Classes/HelloWorldScene.h",
|
||||
"tools/framework-compile/bin-templates/cpp-template-default/cocos-project-template.json",
|
||||
"tools/framework-compile/bin-templates/cpp-template-default/proj.android/jni/Android.mk",
|
||||
"tools/framework-compile/bin-templates/cpp-template-default/proj.win32/HelloCpp.sln",
|
||||
"tools/framework-compile/bin-templates/cpp-template-default/proj.win32/main.cpp",
|
||||
"tools/framework-compile/bin-templates/cpp-template-default/res-landscape/HelloCpp.ccs",
|
||||
"tools/framework-compile/bin-templates/cpp-template-default/res-landscape/HelloCpp.cfg",
|
||||
"tools/framework-compile/bin-templates/cpp-template-default/res-landscape/HelloCpp.udf",
|
||||
"tools/framework-compile/bin-templates/cpp-template-default/res-landscape/Resources/res/HelloWorld.png",
|
||||
"tools/framework-compile/bin-templates/cpp-template-default/res-landscape/Resources/res/MainScene.csb",
|
||||
"tools/framework-compile/bin-templates/cpp-template-default/res-landscape/cocosstudio/HelloWorld.png",
|
||||
"tools/framework-compile/bin-templates/cpp-template-default/res-landscape/cocosstudio/MainScene.csd",
|
||||
"tools/framework-compile/bin-templates/cpp-template-default/res-portrait/HelloCpp.ccs",
|
||||
"tools/framework-compile/bin-templates/cpp-template-default/res-portrait/HelloCpp.cfg",
|
||||
"tools/framework-compile/bin-templates/cpp-template-default/res-portrait/HelloCpp.udf",
|
||||
"tools/framework-compile/bin-templates/cpp-template-default/res-portrait/Resources/res/HelloWorld.png",
|
||||
"tools/framework-compile/bin-templates/cpp-template-default/res-portrait/Resources/res/MainScene.csb",
|
||||
"tools/framework-compile/bin-templates/cpp-template-default/res-portrait/cocosstudio/HelloWorld.png",
|
||||
"tools/framework-compile/bin-templates/cpp-template-default/res-portrait/cocosstudio/MainScene.csd",
|
||||
"tools/framework-compile/bin-templates/cpp-template-default/res-portrait/proj.ios_mac/ios/Default-568h@2x.png",
|
||||
"tools/framework-compile/bin-templates/cpp-template-default/res-portrait/proj.ios_mac/ios/Default-667h@2x.png",
|
||||
"tools/framework-compile/bin-templates/cpp-template-default/res-portrait/proj.ios_mac/ios/Default-736h@3x.png",
|
||||
"tools/framework-compile/bin-templates/cpp-template-default/res-portrait/proj.ios_mac/ios/Default.png",
|
||||
"tools/framework-compile/bin-templates/cpp-template-default/res-portrait/proj.ios_mac/ios/Default@2x.png",
|
||||
"tools/framework-compile/bin-templates/js-template-runtime/.project",
|
||||
"tools/framework-compile/bin-templates/js-template-runtime/cocos-project-template.json",
|
||||
"tools/framework-compile/bin-templates/js-template-runtime/frameworks/runtime-src/proj.android/build-cfg.json",
|
||||
"tools/framework-compile/bin-templates/js-template-runtime/frameworks/runtime-src/proj.android/jni/Android.mk",
|
||||
"tools/framework-compile/bin-templates/js-template-runtime/frameworks/runtime-src/proj.win32/HelloJavascript.sln",
|
||||
"tools/framework-compile/bin-templates/js-template-runtime/frameworks/runtime-src/proj.win32/build-cfg.json",
|
||||
"tools/framework-compile/bin-templates/js-template-runtime/frameworks/runtime-src/proj.win32/main.cpp",
|
||||
"tools/framework-compile/bin-templates/js-template-runtime/frameworks/runtime-src/proj.win32/stdafx.cpp",
|
||||
"tools/framework-compile/bin-templates/js-template-runtime/frameworks/runtime-src/proj.win32/stdafx.h",
|
||||
"tools/framework-compile/bin-templates/js-template-runtime/frameworks/runtime-src/proj.win32/targetver.h",
|
||||
"tools/framework-compile/bin-templates/js-template-runtime/index.html",
|
||||
"tools/framework-compile/bin-templates/js-template-runtime/main.js",
|
||||
"tools/framework-compile/bin-templates/js-template-runtime/project.json",
|
||||
"tools/framework-compile/bin-templates/js-template-runtime/res-landscape/HelloJavascript.ccs",
|
||||
"tools/framework-compile/bin-templates/js-template-runtime/res-landscape/HelloJavascript.cfg",
|
||||
"tools/framework-compile/bin-templates/js-template-runtime/res-landscape/HelloJavascript.udf",
|
||||
"tools/framework-compile/bin-templates/js-template-runtime/res-landscape/cocosstudio/HelloWorld.png",
|
||||
"tools/framework-compile/bin-templates/js-template-runtime/res-landscape/cocosstudio/MainScene.csd",
|
||||
"tools/framework-compile/bin-templates/js-template-runtime/res-landscape/res/HelloWorld.png",
|
||||
"tools/framework-compile/bin-templates/js-template-runtime/res-landscape/res/MainScene.json",
|
||||
"tools/framework-compile/bin-templates/js-template-runtime/res-portrait/HelloJavascript.ccs",
|
||||
"tools/framework-compile/bin-templates/js-template-runtime/res-portrait/HelloJavascript.cfg",
|
||||
"tools/framework-compile/bin-templates/js-template-runtime/res-portrait/HelloJavascript.udf",
|
||||
"tools/framework-compile/bin-templates/js-template-runtime/res-portrait/cocosstudio/HelloWorld.png",
|
||||
"tools/framework-compile/bin-templates/js-template-runtime/res-portrait/cocosstudio/MainScene.csd",
|
||||
"tools/framework-compile/bin-templates/js-template-runtime/res-portrait/frameworks/runtime-src/proj.ios_mac/ios/Default-568h@2x.png",
|
||||
"tools/framework-compile/bin-templates/js-template-runtime/res-portrait/frameworks/runtime-src/proj.ios_mac/ios/Default-667h@2x.png",
|
||||
"tools/framework-compile/bin-templates/js-template-runtime/res-portrait/frameworks/runtime-src/proj.ios_mac/ios/Default-736h@3x.png",
|
||||
"tools/framework-compile/bin-templates/js-template-runtime/res-portrait/frameworks/runtime-src/proj.ios_mac/ios/Default.png",
|
||||
"tools/framework-compile/bin-templates/js-template-runtime/res-portrait/frameworks/runtime-src/proj.ios_mac/ios/Default@2x.png",
|
||||
"tools/framework-compile/bin-templates/js-template-runtime/res-portrait/res/HelloWorld.png",
|
||||
"tools/framework-compile/bin-templates/js-template-runtime/res-portrait/res/MainScene.json",
|
||||
"tools/framework-compile/bin-templates/js-template-runtime/src/app.js",
|
||||
"tools/framework-compile/bin-templates/js-template-runtime/src/resource.js",
|
||||
"tools/framework-compile/bin-templates/lua-template-runtime/cocos-project-template.json",
|
||||
"tools/framework-compile/bin-templates/lua-template-runtime/frameworks/runtime-src/proj.android/jni/Android.mk",
|
||||
"tools/framework-compile/bin-templates/lua-template-runtime/frameworks/runtime-src/proj.win32/HelloLua.sln",
|
||||
"tools/framework-compile/bin-templates/lua-template-runtime/frameworks/runtime-src/proj.win32/main.cpp",
|
||||
"tools/framework-compile/bin-templates/lua-template-runtime/res-landscape/HelloLua.ccs",
|
||||
"tools/framework-compile/bin-templates/lua-template-runtime/res-landscape/HelloLua.cfg",
|
||||
"tools/framework-compile/bin-templates/lua-template-runtime/res-landscape/HelloLua.udf",
|
||||
"tools/framework-compile/bin-templates/lua-template-runtime/res-landscape/cocosstudio/HelloWorld.png",
|
||||
"tools/framework-compile/bin-templates/lua-template-runtime/res-landscape/cocosstudio/MainScene.csd",
|
||||
"tools/framework-compile/bin-templates/lua-template-runtime/res-landscape/res/HelloWorld.png",
|
||||
"tools/framework-compile/bin-templates/lua-template-runtime/res-landscape/res/MainScene.csb",
|
||||
"tools/framework-compile/bin-templates/lua-template-runtime/res-portrait/HelloLua.ccs",
|
||||
"tools/framework-compile/bin-templates/lua-template-runtime/res-portrait/HelloLua.cfg",
|
||||
"tools/framework-compile/bin-templates/lua-template-runtime/res-portrait/HelloLua.udf",
|
||||
"tools/framework-compile/bin-templates/lua-template-runtime/res-portrait/cocosstudio/HelloWorld.png",
|
||||
"tools/framework-compile/bin-templates/lua-template-runtime/res-portrait/cocosstudio/MainScene.csd",
|
||||
"tools/framework-compile/bin-templates/lua-template-runtime/res-portrait/frameworks/runtime-src/proj.ios_mac/ios/Default-568h@2x.png",
|
||||
"tools/framework-compile/bin-templates/lua-template-runtime/res-portrait/frameworks/runtime-src/proj.ios_mac/ios/Default-667h@2x.png",
|
||||
"tools/framework-compile/bin-templates/lua-template-runtime/res-portrait/frameworks/runtime-src/proj.ios_mac/ios/Default-736h@3x.png",
|
||||
"tools/framework-compile/bin-templates/lua-template-runtime/res-portrait/frameworks/runtime-src/proj.ios_mac/ios/Default.png",
|
||||
"tools/framework-compile/bin-templates/lua-template-runtime/res-portrait/frameworks/runtime-src/proj.ios_mac/ios/Default@2x.png",
|
||||
"tools/framework-compile/bin-templates/lua-template-runtime/res-portrait/res/HelloWorld.png",
|
||||
"tools/framework-compile/bin-templates/lua-template-runtime/res-portrait/res/MainScene.csb",
|
||||
"tools/framework-compile/bin-templates/lua-template-runtime/src/app/MyApp.lua",
|
||||
"tools/framework-compile/bin-templates/lua-template-runtime/src/app/views/MainScene.lua",
|
||||
"tools/framework-compile/bin-templates/lua-template-runtime/src/config.lua",
|
||||
"tools/missing-tools.txt",
|
||||
"tools/particle/convert_YCoordFlipped.py",
|
||||
"tools/simulator/.cocos-project.json",
|
||||
|
|
|
@ -37,6 +37,7 @@ enum
|
|||
|
||||
CocosStudio3DTests::CocosStudio3DTests()
|
||||
{
|
||||
FileUtils::getInstance()->addSearchPath("ccs-res/CocosStudio3DTest");
|
||||
ADD_TEST_CASE(CSNode3DTest);
|
||||
ADD_TEST_CASE(CSSprite3DTest);
|
||||
ADD_TEST_CASE(CSUserCameraTest);
|
||||
|
|
|
@ -87,6 +87,7 @@ NewLabelTests::NewLabelTests()
|
|||
ADD_TEST_CASE(LabelFullTypeFontTest);
|
||||
ADD_TEST_CASE(LabelIssue10688Test);
|
||||
ADD_TEST_CASE(LabelIssue13202Test);
|
||||
ADD_TEST_CASE(LabelIssue9500Test);
|
||||
};
|
||||
|
||||
LabelTTFAlignmentNew::LabelTTFAlignmentNew()
|
||||
|
@ -445,7 +446,7 @@ LabelFNTandTTFEmpty::LabelFNTandTTFEmpty()
|
|||
auto label2 = Label::createWithTTF(ttfConfig,"", TextHAlignment::CENTER,s.width);
|
||||
addChild(label2, 0, kTagBitmapAtlas2);
|
||||
label2->setPosition(Vec2(s.width/2, s.height / 2));
|
||||
|
||||
|
||||
auto label3 = Label::createWithCharMap("fonts/tuffy_bold_italic-charmap.plist");
|
||||
addChild(label3, 0, kTagBitmapAtlas3);
|
||||
label3->setPosition(Vec2(s.width/2, 100));
|
||||
|
@ -813,7 +814,7 @@ std::string LabelFNTUNICODELanguages::title() const
|
|||
|
||||
std::string LabelFNTUNICODELanguages::subtitle() const
|
||||
{
|
||||
return "You should see 4 differnt labels:\nIn Spanish, Chinese, Russian and Korean";
|
||||
return "You should see 4 differnt labels:\nIn Spanish, Chinese, Russian and Japanese";
|
||||
}
|
||||
|
||||
LabelFNTBounds::LabelFNTBounds()
|
||||
|
@ -2085,3 +2086,22 @@ std::string LabelIssue13202Test::subtitle() const
|
|||
{
|
||||
return "FontAtlasCache::purgeCachedData should not cause crash.";
|
||||
}
|
||||
|
||||
LabelIssue9500Test::LabelIssue9500Test()
|
||||
{
|
||||
auto center = VisibleRect::center();
|
||||
|
||||
auto label = Label::createWithTTF("Spaces should not be lost", "fonts/Fingerpop.ttf", 20);
|
||||
label->setPosition(center);
|
||||
addChild(label);
|
||||
}
|
||||
|
||||
std::string LabelIssue9500Test::title() const
|
||||
{
|
||||
return "Test for Issue #9500";
|
||||
}
|
||||
|
||||
std::string LabelIssue9500Test::subtitle() const
|
||||
{
|
||||
return "Spaces should not be lost if label created with Fingerpop.ttf";
|
||||
}
|
||||
|
|
|
@ -669,4 +669,15 @@ public:
|
|||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
||||
class LabelIssue9500Test : public AtlasDemoNew
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(LabelIssue9500Test);
|
||||
|
||||
LabelIssue9500Test();
|
||||
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -34,7 +34,9 @@ using namespace cocos2d::experimental;
|
|||
|
||||
AudioEngineTests::AudioEngineTests()
|
||||
{
|
||||
ADD_TEST_CASE(AudioIssue11143Test);
|
||||
ADD_TEST_CASE(AudioControlTest);
|
||||
ADD_TEST_CASE(AudioLoadTest);
|
||||
ADD_TEST_CASE(PlaySimultaneouslyTest);
|
||||
ADD_TEST_CASE(AudioProfileTest);
|
||||
ADD_TEST_CASE(InvalidAudioFileTest);
|
||||
|
@ -266,21 +268,6 @@ bool AudioControlTest::init()
|
|||
loopItem->setPosition(layerSize.width * 0.5f, layerSize.height * 0.5f);
|
||||
addChild(loopItem);
|
||||
|
||||
auto preloadItem = TextButton::create("preload", [&](TextButton* button){
|
||||
AudioEngine::preload("background.mp3");
|
||||
});
|
||||
preloadItem->setPosition(layerSize.width * 0.3f, layerSize.height * 0.6f);
|
||||
addChild(preloadItem);
|
||||
|
||||
auto uncacheItem = TextButton::create("uncache", [&](TextButton* button){
|
||||
AudioEngine::uncache("background.mp3");
|
||||
|
||||
_audioID = AudioEngine::INVALID_AUDIO_ID;
|
||||
((TextButton*)_playItem)->setEnabled(true);
|
||||
});
|
||||
uncacheItem->setPosition(layerSize.width * 0.7f,layerSize.height * 0.6f);
|
||||
addChild(uncacheItem);
|
||||
|
||||
auto volumeSlider = SliderEx::create();
|
||||
volumeSlider->setPercent(100);
|
||||
volumeSlider->addEventListener([&](Ref* sender, Slider::EventType event){
|
||||
|
@ -356,9 +343,54 @@ AudioControlTest::~AudioControlTest()
|
|||
|
||||
std::string AudioControlTest::title() const
|
||||
{
|
||||
return "audio control test";
|
||||
return "Audio control test";
|
||||
}
|
||||
|
||||
bool AudioLoadTest::init()
|
||||
{
|
||||
if (AudioEngineTestDemo::init())
|
||||
{
|
||||
auto& layerSize = this->getContentSize();
|
||||
|
||||
auto stateLabel = Label::createWithTTF("status:", "fonts/arial.ttf", 30);
|
||||
stateLabel->setPosition(layerSize.width / 2, layerSize.height * 0.7f);
|
||||
addChild(stateLabel);
|
||||
|
||||
auto preloadItem = TextButton::create("preload", [&, stateLabel](TextButton* button){
|
||||
stateLabel->setString("status:loading...");
|
||||
AudioEngine::preload("audio/SoundEffectsFX009/FX082.mp3", [stateLabel](bool isSuccess){
|
||||
if (isSuccess)
|
||||
{
|
||||
stateLabel->setString("status:load success");
|
||||
}
|
||||
else
|
||||
{
|
||||
stateLabel->setString("status:load fail");
|
||||
}
|
||||
});
|
||||
});
|
||||
preloadItem->setPosition(layerSize.width * 0.35f, layerSize.height * 0.5f);
|
||||
addChild(preloadItem);
|
||||
|
||||
auto uncacheItem = TextButton::create("uncache", [&, stateLabel](TextButton* button){
|
||||
stateLabel->setString("status:uncache");
|
||||
AudioEngine::uncache("audio/SoundEffectsFX009/FX082.mp3");
|
||||
});
|
||||
uncacheItem->setPosition(layerSize.width * 0.65f, layerSize.height * 0.5f);
|
||||
addChild(uncacheItem);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string AudioLoadTest::title() const
|
||||
{
|
||||
return "Audio preload/uncache test";
|
||||
}
|
||||
|
||||
|
||||
// PlaySimultaneouslyTest
|
||||
bool PlaySimultaneouslyTest::init()
|
||||
{
|
||||
|
@ -571,4 +603,36 @@ std::string LargeAudioFileTest::title() const
|
|||
return "Test large audio file";
|
||||
}
|
||||
|
||||
bool AudioIssue11143Test::init()
|
||||
{
|
||||
if (AudioEngineTestDemo::init())
|
||||
{
|
||||
auto& layerSize = this->getContentSize();
|
||||
|
||||
auto playItem = TextButton::create("play", [](TextButton* button){
|
||||
auto audioId = AudioEngine::play2d("audio/SoundEffectsFX009/FX082.mp3", true);
|
||||
button->scheduleOnce([audioId](float dt){
|
||||
AudioEngine::stop(audioId);
|
||||
AudioEngine::play2d("audio/SoundEffectsFX009/FX083.mp3");
|
||||
}, 2.f, "play another sound");
|
||||
});
|
||||
playItem->setPosition(layerSize.width * 0.5f, layerSize.height * 0.5f);
|
||||
addChild(playItem);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string AudioIssue11143Test::title() const
|
||||
{
|
||||
return "Test for issue 11143";
|
||||
}
|
||||
|
||||
std::string AudioIssue11143Test::subtitle() const
|
||||
{
|
||||
return "2 seconds after first sound play,you should hear another sound.";
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -143,5 +143,26 @@ private:
|
|||
|
||||
};
|
||||
|
||||
class AudioLoadTest : public AudioEngineTestDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(AudioLoadTest);
|
||||
|
||||
virtual bool init() override;
|
||||
|
||||
virtual std::string title() const override;
|
||||
};
|
||||
|
||||
class AudioIssue11143Test : public AudioEngineTestDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(AudioIssue11143Test);
|
||||
|
||||
virtual bool init() override;
|
||||
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
||||
#endif /* defined(__NEWAUDIOENGINE_TEST_H_) */
|
||||
#endif
|
||||
|
|
|
@ -137,6 +137,7 @@ bool Physics3DTestDemo::init()
|
|||
void Physics3DTestDemo::onTouchesBegan(const std::vector<Touch*>& touches, cocos2d::Event *event)
|
||||
{
|
||||
_needShootBox = true;
|
||||
event->stopPropagation();
|
||||
}
|
||||
|
||||
void Physics3DTestDemo::onTouchesMoved(const std::vector<Touch*>& touches, cocos2d::Event *event)
|
||||
|
@ -154,6 +155,7 @@ void Physics3DTestDemo::onTouchesMoved(const std::vector<Touch*>& touches, cocos
|
|||
{
|
||||
_needShootBox = false;
|
||||
}
|
||||
event->stopPropagation();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -169,6 +171,7 @@ void Physics3DTestDemo::onTouchesEnded(const std::vector<Touch*>& touches, cocos
|
|||
farP = _camera->unproject(farP);
|
||||
Vec3 dir(farP - nearP);
|
||||
shootBox(_camera->getPosition3D() + dir * 10.0f);
|
||||
event->stopPropagation();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -530,6 +533,7 @@ void Physics3DConstraintDemo::onTouchesBegan(const std::vector<cocos2d::Touch*>&
|
|||
_constraint = Physics3DPointToPointConstraint::create(static_cast<Physics3DRigidBody*>(result.hitObj), position);
|
||||
physicsScene->getPhysics3DWorld()->addPhysics3DConstraint(_constraint, true);
|
||||
_pickingDistance = (result.hitPosition - nearP).length();
|
||||
event->stopPropagation();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -551,6 +555,7 @@ void Physics3DConstraintDemo::onTouchesMoved(const std::vector<cocos2d::Touch*>&
|
|||
_camera->unproject(size, &farP, &farP);
|
||||
auto dir = (farP - nearP).getNormalized();
|
||||
p2pConstraint->setPivotPointInB(nearP + dir * _pickingDistance);
|
||||
event->stopPropagation();
|
||||
return;
|
||||
}
|
||||
Physics3DTestDemo::onTouchesMoved(touches, event);
|
||||
|
@ -561,6 +566,7 @@ void Physics3DConstraintDemo::onTouchesEnded(const std::vector<cocos2d::Touch*>&
|
|||
{
|
||||
physicsScene->getPhysics3DWorld()->removePhysics3DConstraint(_constraint);
|
||||
_constraint = nullptr;
|
||||
event->stopPropagation();
|
||||
return;
|
||||
}
|
||||
Physics3DTestDemo::onTouchesEnded(touches, event);
|
||||
|
|
|
@ -277,7 +277,7 @@ Sprite3DUVAnimationTest::Sprite3DUVAnimationTest()
|
|||
schedule(schedule_selector(Sprite3DUVAnimationTest::cylinderUpdate));
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
|
||||
_backToForegroundListener = EventListenerCustom::create(EVENT_RENDERER_RECREATED,
|
||||
_backToForegroundListener = EventListenerCustom::create(EVENT_COME_TO_FOREGROUND,
|
||||
[this](EventCustom*)
|
||||
{
|
||||
auto glProgram = _state->getGLProgram();
|
||||
|
@ -413,7 +413,7 @@ Sprite3DFakeShadowTest::Sprite3DFakeShadowTest()
|
|||
schedule(CC_SCHEDULE_SELECTOR(Sprite3DFakeShadowTest::updateCamera), 0.0f);
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
|
||||
_backToForegroundListener = EventListenerCustom::create(EVENT_RENDERER_RECREATED,
|
||||
_backToForegroundListener = EventListenerCustom::create(EVENT_COME_TO_FOREGROUND,
|
||||
[this](EventCustom*)
|
||||
{
|
||||
auto glProgram = _state->getGLProgram();
|
||||
|
@ -642,7 +642,7 @@ Sprite3DBasicToonShaderTest::Sprite3DBasicToonShaderTest()
|
|||
setCameraMask(2);
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
|
||||
_backToForegroundListener = EventListenerCustom::create(EVENT_RENDERER_RECREATED,
|
||||
_backToForegroundListener = EventListenerCustom::create(EVENT_COME_TO_FOREGROUND,
|
||||
[this](EventCustom*)
|
||||
{
|
||||
auto glProgram = _state->getGLProgram();
|
||||
|
@ -945,12 +945,15 @@ Effect3DOutline::Effect3DOutline()
|
|||
, _sprite(nullptr)
|
||||
{
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
|
||||
_backToForegroundListener = EventListenerCustom::create(EVENT_RENDERER_RECREATED,
|
||||
_backToForegroundListener = EventListenerCustom::create(EVENT_COME_TO_FOREGROUND,
|
||||
[this](EventCustom*)
|
||||
{
|
||||
auto glProgram = _glProgramState->getGLProgram();
|
||||
glProgram->reset();
|
||||
if(!_sprite->getMesh()->getSkin())
|
||||
glProgram->initWithFilenames(_vertShaderFile, _fragShaderFile);
|
||||
else
|
||||
glProgram->initWithFilenames(_vertSkinnedShaderFile, _fragSkinnedShaderFile);
|
||||
glProgram->link();
|
||||
glProgram->updateUniforms();
|
||||
}
|
||||
|
@ -2489,7 +2492,7 @@ void Sprite3DCubeMapTest::addNewSpriteWithCoords(Vec2 p)
|
|||
setCameraMask(2);
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
|
||||
_backToForegroundListener = EventListenerCustom::create(EVENT_RENDERER_RECREATED,
|
||||
_backToForegroundListener = EventListenerCustom::create(EVENT_COME_TO_FOREGROUND,
|
||||
[this](EventCustom*)
|
||||
{
|
||||
auto state = _teapot->getGLProgramState();
|
||||
|
|
|
@ -60,11 +60,12 @@ bool UIEditBoxTest::init()
|
|||
_editName = ui::EditBox::create(editBoxSize, ui::Scale9Sprite::create(pNormalSprite));
|
||||
_editName->setPosition(Vec2(visibleOrigin.x+visibleSize.width/2, visibleOrigin.y+visibleSize.height*3/4));
|
||||
_editName->setFontName("Paint Boy");
|
||||
_editName->setFontSize(25);
|
||||
_editName->setFontColor(Color3B::RED);
|
||||
_editName->setPlaceHolder("Name:");
|
||||
_editName->setPlaceholderFontColor(Color3B::WHITE);
|
||||
_editName->setMaxLength(8);
|
||||
_editName->setFontSize(editBoxSize.height/2);
|
||||
_editName->setText("v👐👊💝");
|
||||
_editName->setReturnType(ui::EditBox::KeyboardReturnType::DONE);
|
||||
_editName->setDelegate(this);
|
||||
addChild(_editName);
|
||||
|
@ -77,15 +78,18 @@ bool UIEditBoxTest::init()
|
|||
_editPassword->setMaxLength(6);
|
||||
_editPassword->setInputFlag(ui::EditBox::InputFlag::PASSWORD);
|
||||
_editPassword->setInputMode(ui::EditBox::InputMode::SINGLE_LINE);
|
||||
_editPassword->setFontSize(editBoxSize.height/2);
|
||||
_editPassword->setDelegate(this);
|
||||
addChild(_editPassword);
|
||||
|
||||
// bottom
|
||||
_editEmail = ui::EditBox::create(Size(editBoxSize.width, editBoxSize.height), "extensions/yellow_edit.png");
|
||||
auto bottomButtonSize = Size(editBoxSize.width, editBoxSize.height + 10);
|
||||
_editEmail = ui::EditBox::create(bottomButtonSize, "extensions/yellow_edit.png");
|
||||
_editEmail->setPosition(Vec2(visibleOrigin.x+visibleSize.width/2, visibleOrigin.y+visibleSize.height/4));
|
||||
_editEmail->setPlaceHolder("Email:");
|
||||
_editEmail->setInputMode(ui::EditBox::InputMode::EMAIL_ADDRESS);
|
||||
_editEmail->setDelegate(this);
|
||||
_editEmail->setFontSize(bottomButtonSize.height/2);
|
||||
addChild(_editEmail);
|
||||
|
||||
return true;
|
||||
|
|
|
@ -10,6 +10,7 @@ UIListViewTests::UIListViewTests()
|
|||
ADD_TEST_CASE(UIListViewTest_Vertical);
|
||||
ADD_TEST_CASE(UIListViewTest_Horizontal);
|
||||
ADD_TEST_CASE(Issue12692);
|
||||
ADD_TEST_CASE(Issue8316);
|
||||
}
|
||||
|
||||
// UIListViewTest_Vertical
|
||||
|
@ -474,3 +475,73 @@ bool Issue12692::init()
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool Issue8316::init()
|
||||
{
|
||||
if (UIScene::init())
|
||||
{
|
||||
Size widgetSize = _widget->getContentSize();
|
||||
|
||||
auto label = Text::create("Issue 8316", "fonts/Marker Felt.ttf", 32);
|
||||
label->setAnchorPoint(Vec2(0.5f, -1.0f));
|
||||
label->setPosition(Vec2(widgetSize.width / 2.0f,
|
||||
widgetSize.height / 2.0f + label->getContentSize().height * 1.5f));
|
||||
_uiLayer->addChild(label);
|
||||
|
||||
|
||||
Text* alert = Text::create("ListView Disable Touch", "fonts/Marker Felt.ttf", 20);
|
||||
alert->setColor(Color3B(159, 168, 176));
|
||||
alert->setPosition(Vec2(widgetSize.width / 2.0f,
|
||||
widgetSize.height / 2.0f - alert->getContentSize().height * 3.075f));
|
||||
_uiLayer->addChild(alert);
|
||||
|
||||
Layout* root = static_cast<Layout*>(_uiLayer->getChildByTag(81));
|
||||
|
||||
Layout* background = dynamic_cast<Layout*>(root->getChildByName("background_Panel"));
|
||||
Size backgroundSize = background->getContentSize();
|
||||
|
||||
// Create the list view ex
|
||||
ListView* listView = ListView::create();
|
||||
// set list view ex direction
|
||||
listView->setDirection(ui::ScrollView::Direction::VERTICAL);
|
||||
listView->setBounceEnabled(true);
|
||||
listView->setTouchEnabled(false);
|
||||
listView->setBackGroundImage("cocosui/green_edit.png");
|
||||
listView->setBackGroundImageScale9Enabled(true);
|
||||
listView->setContentSize(Size(240, 130));
|
||||
listView->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f +
|
||||
(backgroundSize.width - listView->getContentSize().width) / 2.0f,
|
||||
(widgetSize.height - backgroundSize.height) / 2.0f +
|
||||
(backgroundSize.height - listView->getContentSize().height) / 2.0f));
|
||||
listView->setScrollBarPositionFromCorner(Vec2(7, 7));
|
||||
listView->setClippingEnabled(true);
|
||||
listView->setClippingType(ui::Layout::ClippingType::SCISSOR);
|
||||
listView->setName("listview1");
|
||||
|
||||
{
|
||||
Button* default_button = Button::create("cocosui/backtotoppressed.png", "cocosui/backtotopnormal.png");
|
||||
default_button->setName("Title Button");
|
||||
|
||||
Layout* default_item = Layout::create();
|
||||
default_item->setTouchEnabled(true);
|
||||
default_item->setContentSize(default_button->getContentSize());
|
||||
default_button->setPosition(Vec2(default_item->getContentSize().width / 2.0f,
|
||||
default_item->getContentSize().height / 2.0f));
|
||||
default_item->addChild(default_button);
|
||||
|
||||
// set model
|
||||
listView->setItemModel(default_item);
|
||||
listView->pushBackDefaultItem();
|
||||
listView->pushBackDefaultItem();
|
||||
listView->pushBackDefaultItem();
|
||||
}
|
||||
|
||||
_uiLayer->addChild(listView);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -76,4 +76,12 @@ public:
|
|||
virtual bool init() override;
|
||||
};
|
||||
|
||||
class Issue8316 : public UIScene
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(Issue8316);
|
||||
|
||||
virtual bool init() override;
|
||||
};
|
||||
|
||||
#endif /* defined(__TestCpp__UIListViewTest__) */
|
||||
|
|
|
@ -13,6 +13,7 @@ UIPageViewTests::UIPageViewTests()
|
|||
ADD_TEST_CASE(UIPageViewDynamicAddAndRemoveTest);
|
||||
ADD_TEST_CASE(UIPageViewJumpToPageTest);
|
||||
ADD_TEST_CASE(UIPageViewVerticalTest);
|
||||
ADD_TEST_CASE(UIPageViewDisableTouchTest);
|
||||
}
|
||||
|
||||
// UIPageViewTest
|
||||
|
@ -903,3 +904,77 @@ void UIPageViewVerticalTest::pageViewEvent(Ref *pSender, PageView::EventType typ
|
|||
}
|
||||
}
|
||||
|
||||
// UIPageViewDisableTouchTest
|
||||
UIPageViewDisableTouchTest::UIPageViewDisableTouchTest()
|
||||
: _displayValueLabel(nullptr)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
UIPageViewDisableTouchTest::~UIPageViewDisableTouchTest()
|
||||
{
|
||||
}
|
||||
|
||||
bool UIPageViewDisableTouchTest::init()
|
||||
{
|
||||
if (UIScene::init())
|
||||
{
|
||||
Size widgetSize = _widget->getContentSize();
|
||||
|
||||
// Add a label in which the dragpanel events will be displayed
|
||||
_displayValueLabel = Text::create("PageView disable touch", "fonts/Marker Felt.ttf", 32);
|
||||
_displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f));
|
||||
_displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f,
|
||||
widgetSize.height / 2.0f +
|
||||
_displayValueLabel->getContentSize().height * 1.5));
|
||||
_uiLayer->addChild(_displayValueLabel);
|
||||
|
||||
// Add the black background
|
||||
Text* alert = Text::create("PageView", "fonts/Marker Felt.ttf", 30);
|
||||
alert->setColor(Color3B(159, 168, 176));
|
||||
alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.075f));
|
||||
_uiLayer->addChild(alert);
|
||||
|
||||
Layout* root = static_cast<Layout*>(_uiLayer->getChildByTag(81));
|
||||
|
||||
Layout* background = dynamic_cast<Layout*>(root->getChildByName("background_Panel"));
|
||||
|
||||
// Create the page view
|
||||
PageView* pageView = PageView::create();
|
||||
pageView->setContentSize(Size(240.0f, 130.0f));
|
||||
Size backgroundSize = background->getContentSize();
|
||||
pageView->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f +
|
||||
(backgroundSize.width - pageView->getContentSize().width) / 2.0f,
|
||||
(widgetSize.height - backgroundSize.height) / 2.0f +
|
||||
(backgroundSize.height - pageView->getContentSize().height) / 2.0f));
|
||||
pageView->setDirection(ui::PageView::Direction::VERTICAL);
|
||||
pageView->setTouchEnabled(false);
|
||||
pageView->removeAllPages();
|
||||
|
||||
int pageCount = 4;
|
||||
for (int i = 0; i < pageCount; ++i)
|
||||
{
|
||||
Layout* layout = Layout::create();
|
||||
layout->setContentSize(Size(240.0f, 130.0f));
|
||||
|
||||
ImageView* imageView = ImageView::create("cocosui/scrollviewbg.png");
|
||||
imageView->setScale9Enabled(true);
|
||||
imageView->setContentSize(Size(240, 130));
|
||||
imageView->setPosition(Vec2(layout->getContentSize().width / 2.0f, layout->getContentSize().height / 2.0f));
|
||||
layout->addChild(imageView);
|
||||
|
||||
Text* label = Text::create(StringUtils::format("page %d",(i+1)), "fonts/Marker Felt.ttf", 30);
|
||||
label->setColor(Color3B(192, 192, 192));
|
||||
label->setPosition(Vec2(layout->getContentSize().width / 2.0f, layout->getContentSize().height / 2.0f));
|
||||
layout->addChild(label);
|
||||
|
||||
pageView->insertPage(layout,i);
|
||||
}
|
||||
|
||||
_uiLayer->addChild(pageView);
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -142,4 +142,18 @@ protected:
|
|||
cocos2d::ui::Text* _displayValueLabel;
|
||||
};
|
||||
|
||||
class UIPageViewDisableTouchTest : public UIScene
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(UIPageViewDisableTouchTest);
|
||||
|
||||
UIPageViewDisableTouchTest();
|
||||
~UIPageViewDisableTouchTest();
|
||||
virtual bool init() override;
|
||||
|
||||
protected:
|
||||
|
||||
cocos2d::ui::Text* _displayValueLabel;
|
||||
};
|
||||
|
||||
#endif /* defined(__TestCpp__UIPageViewTest__) */
|
||||
|
|
|
@ -12,6 +12,7 @@ UIScrollViewTests::UIScrollViewTests()
|
|||
ADD_TEST_CASE(UIScrollViewTest_ScrollToPercentBothDirection_Bounce);
|
||||
ADD_TEST_CASE(UIScrollViewNestTest);
|
||||
ADD_TEST_CASE(UIScrollViewRotated);
|
||||
ADD_TEST_CASE(UIScrollViewDisableTest);
|
||||
}
|
||||
// UIScrollViewTest_Vertical
|
||||
|
||||
|
@ -534,4 +535,84 @@ bool UIScrollViewRotated::init()
|
|||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// UIScrollViewDisableTest
|
||||
|
||||
UIScrollViewDisableTest::UIScrollViewDisableTest()
|
||||
: _displayValueLabel(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
UIScrollViewDisableTest::~UIScrollViewDisableTest()
|
||||
{
|
||||
}
|
||||
|
||||
bool UIScrollViewDisableTest::init()
|
||||
{
|
||||
if (UIScene::init())
|
||||
{
|
||||
Size widgetSize = _widget->getContentSize();
|
||||
|
||||
// Add a label in which the scrollview alert will be displayed
|
||||
_displayValueLabel = Text::create("ScrollView Disable Test", "fonts/Marker Felt.ttf", 32);
|
||||
_displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f));
|
||||
_displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f,
|
||||
widgetSize.height / 2.0f + _displayValueLabel->getContentSize().height * 1.5f));
|
||||
_uiLayer->addChild(_displayValueLabel);
|
||||
|
||||
// Add the alert
|
||||
Text* alert = Text::create("ScrollView vertical", "fonts/Marker Felt.ttf", 30);
|
||||
alert->setColor(Color3B(159, 168, 176));
|
||||
alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.075f));
|
||||
_uiLayer->addChild(alert);
|
||||
|
||||
Layout* root = static_cast<Layout*>(_uiLayer->getChildByTag(81));
|
||||
|
||||
Layout* background = dynamic_cast<Layout*>(root->getChildByName("background_Panel"));
|
||||
|
||||
// Create the scrollview by vertical
|
||||
ui::ScrollView* scrollView = ui::ScrollView::create();
|
||||
scrollView->setContentSize(Size(280.0f, 100.0f));
|
||||
Size backgroundSize = background->getContentSize();
|
||||
scrollView->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f +
|
||||
(backgroundSize.width - scrollView->getContentSize().width) / 2.0f,
|
||||
(widgetSize.height - backgroundSize.height) / 2.0f +
|
||||
(backgroundSize.height - scrollView->getContentSize().height) / 2.0f));
|
||||
scrollView->setScrollBarWidth(4);
|
||||
scrollView->setTouchEnabled(false);
|
||||
scrollView->setScrollBarPositionFromCorner(Vec2(2, 2));
|
||||
scrollView->setScrollBarColor(Color3B::WHITE);
|
||||
_uiLayer->addChild(scrollView);
|
||||
|
||||
ImageView* imageView = ImageView::create("cocosui/ccicon.png");
|
||||
|
||||
float innerWidth = scrollView->getContentSize().width;
|
||||
float innerHeight = scrollView->getContentSize().height + imageView->getContentSize().height;
|
||||
|
||||
scrollView->setInnerContainerSize(Size(innerWidth, innerHeight));
|
||||
|
||||
Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
|
||||
button->setPosition(Vec2(innerWidth / 2.0f, scrollView->getInnerContainerSize().height - button->getContentSize().height / 2.0f));
|
||||
scrollView->addChild(button);
|
||||
|
||||
Button* titleButton = Button::create("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png");
|
||||
titleButton->setTitleText("Title Button");
|
||||
titleButton->setPosition(Vec2(innerWidth / 2.0f, button->getBottomBoundary() - button->getContentSize().height));
|
||||
scrollView->addChild(titleButton);
|
||||
|
||||
Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png");
|
||||
button_scale9->setScale9Enabled(true);
|
||||
button_scale9->setContentSize(Size(100.0f, button_scale9->getVirtualRendererSize().height));
|
||||
button_scale9->setPosition(Vec2(innerWidth / 2.0f, titleButton->getBottomBoundary() - titleButton->getContentSize().height));
|
||||
scrollView->addChild(button_scale9);
|
||||
|
||||
imageView->setPosition(Vec2(innerWidth / 2.0f, imageView->getContentSize().height / 2.0f));
|
||||
scrollView->addChild(imageView);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -127,4 +127,17 @@ protected:
|
|||
cocos2d::ui::Text* _displayValueLabel;
|
||||
};
|
||||
|
||||
class UIScrollViewDisableTest : public UIScene
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(UIScrollViewDisableTest);
|
||||
|
||||
UIScrollViewDisableTest();
|
||||
~UIScrollViewDisableTest();
|
||||
virtual bool init() override;
|
||||
|
||||
protected:
|
||||
|
||||
cocos2d::ui::Text* _displayValueLabel;
|
||||
};
|
||||
#endif /* defined(__TestCpp__UIScrollViewTest__) */
|
||||
|
|
|
@ -22,7 +22,15 @@ bool UITextAtlasTest::init()
|
|||
_uiLayer->addChild(alert);
|
||||
|
||||
// Create the text atlas
|
||||
TextAtlas* textAtlas = TextAtlas::create("1234567890", "cocosui/labelatlas.png", 17, 22, "0");
|
||||
TextAtlas* textAtlas = nullptr;
|
||||
if (Director::getInstance()->getWinSizeInPixels().height > 320.f)
|
||||
{
|
||||
textAtlas = TextAtlas::create("1234567890", "cocosui/labelatlas.png", 34, 44, "0");
|
||||
}
|
||||
else
|
||||
{
|
||||
textAtlas = TextAtlas::create("1234567890", "cocosui/labelatlas.png", 17, 22, "0");
|
||||
}
|
||||
textAtlas->setPosition(Vec2((widgetSize.width) / 2, widgetSize.height / 2.0f));
|
||||
_uiLayer->addChild(textAtlas);
|
||||
|
||||
|
|
|
@ -11,6 +11,9 @@ USING_NS_CC;
|
|||
#define LOG_INDENTATION " "
|
||||
#define LOG_TAG "[TestController]"
|
||||
|
||||
static void initCrashCatch();
|
||||
static void disableCrashCatch();
|
||||
|
||||
class RootTests : public TestList
|
||||
{
|
||||
public:
|
||||
|
@ -374,16 +377,14 @@ bool TestController::checkTest(TestCase* testCase)
|
|||
|
||||
void TestController::handleCrash()
|
||||
{
|
||||
disableCrashCatch();
|
||||
|
||||
logEx("%sCatch an crash event", LOG_TAG);
|
||||
|
||||
if (!_stopAutoTest)
|
||||
{
|
||||
stopAutoTest();
|
||||
}
|
||||
|
||||
#if CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_LINUX
|
||||
exit(1);
|
||||
#endif
|
||||
}
|
||||
|
||||
void TestController::onEnterBackground()
|
||||
|
@ -423,8 +424,6 @@ void TestController::logEx(const char * format, ...)
|
|||
|
||||
static TestController* s_testController = nullptr;
|
||||
|
||||
static void initCrashCatch();
|
||||
|
||||
TestController* TestController::getInstance()
|
||||
{
|
||||
if (s_testController == nullptr)
|
||||
|
@ -445,6 +444,8 @@ void TestController::destroyInstance()
|
|||
delete s_testController;
|
||||
s_testController = nullptr;
|
||||
}
|
||||
|
||||
disableCrashCatch();
|
||||
}
|
||||
|
||||
bool TestController::blockTouchBegan(Touch* touch, Event* event)
|
||||
|
@ -470,6 +471,10 @@ static void initCrashCatch()
|
|||
{
|
||||
SetUnhandledExceptionFilter(windowExceptionFilter);
|
||||
}
|
||||
static void disableCrashCatch()
|
||||
{
|
||||
SetUnhandledExceptionFilter(UnhandledExceptionFilter);
|
||||
}
|
||||
|
||||
#elif CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
|
||||
|
||||
|
@ -506,16 +511,28 @@ static void signalHandler(int sig)
|
|||
|
||||
static void initCrashCatch()
|
||||
{
|
||||
for (auto sig : s_fatal_signals) {
|
||||
for (auto sig : s_fatal_signals)
|
||||
{
|
||||
signal(sig, signalHandler);
|
||||
}
|
||||
}
|
||||
|
||||
static void disableCrashCatch()
|
||||
{
|
||||
for (auto sig : s_fatal_signals)
|
||||
{
|
||||
signal(sig, SIG_DFL);
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static void initCrashCatch()
|
||||
{
|
||||
}
|
||||
|
||||
static void disableCrashCatch()
|
||||
{
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Binary file not shown.
|
@ -25,7 +25,17 @@
|
|||
"web_cfg": {
|
||||
"project_path": "",
|
||||
"run_root_dir": "../../",
|
||||
"sub_url": "/tests/js-tests/"
|
||||
"sub_url": "/tests/js-tests/",
|
||||
"copy_resources": [
|
||||
{
|
||||
"from": "../cpp-tests/Resources/",
|
||||
"to": "res/"
|
||||
},
|
||||
{
|
||||
"from": "resjs",
|
||||
"to": "res/"
|
||||
}
|
||||
]
|
||||
},
|
||||
"linux_cfg": {
|
||||
"project_path": "project/proj.linux",
|
||||
|
|
|
@ -45,7 +45,7 @@ var EditBoxTestLayer = cc.Layer.extend({
|
|||
this._box1.setDelegate(this);
|
||||
this.addChild(this._box1);
|
||||
|
||||
this._box2 = new cc.EditBox(cc.size(130, 40), new cc.Scale9Sprite("extensions/green_edit.png"));
|
||||
this._box2 = new cc.EditBox(cc.size(130, 50), new cc.Scale9Sprite("extensions/green_edit.png"));
|
||||
this._box2.setString("EditBox Sample");
|
||||
this._box2.x = 220;
|
||||
this._box2.y = 190;
|
||||
|
@ -56,7 +56,7 @@ var EditBoxTestLayer = cc.Layer.extend({
|
|||
this._box2.setDelegate(this);
|
||||
this.addChild(this._box2);
|
||||
|
||||
this._box3 = new cc.EditBox(cc.size(65, 40), new cc.Scale9Sprite("extensions/orange_edit.png"));
|
||||
this._box3 = new cc.EditBox(cc.size(65, 50), new cc.Scale9Sprite("extensions/orange_edit.png"));
|
||||
this._box3.setString("Image");
|
||||
this._box3.x = 220;
|
||||
this._box3.y = 250;
|
||||
|
@ -64,7 +64,7 @@ var EditBoxTestLayer = cc.Layer.extend({
|
|||
this._box3.setDelegate(this);
|
||||
this.addChild(this._box3);
|
||||
|
||||
this._box4 = new cc.EditBox(cc.size(180, 40), new cc.Scale9Sprite("extensions/yellow_edit.png"));
|
||||
this._box4 = new cc.EditBox(cc.size(180, 50), new cc.Scale9Sprite("extensions/yellow_edit.png"));
|
||||
this._box4.setPlaceholderFontColor(cc.color(255, 0, 0));
|
||||
this._box4.setPlaceHolder("Tooltip:");
|
||||
this._box4.x = 40;
|
||||
|
@ -125,4 +125,4 @@ var runEditBoxTest = function () {
|
|||
var pLayer = new EditBoxTestLayer();
|
||||
pScene.addChild(pLayer);
|
||||
cc.director.runScene(pScene);
|
||||
};
|
||||
};
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
var UIButtonTest = UIScene.extend({
|
||||
var UIButtonTest = UIMainLayer.extend({
|
||||
init: function () {
|
||||
if (this._super()) {
|
||||
//init text
|
||||
|
@ -68,7 +68,7 @@ var UIButtonTest = UIScene.extend({
|
|||
}
|
||||
}
|
||||
});
|
||||
var UIButtonTest_Scale9 = UIScene.extend({
|
||||
var UIButtonTest_Scale9 = UIMainLayer.extend({
|
||||
init: function () {
|
||||
if (this._super()) {
|
||||
//init text
|
||||
|
@ -112,7 +112,7 @@ var UIButtonTest_Scale9 = UIScene.extend({
|
|||
}
|
||||
});
|
||||
|
||||
var UIButtonTest_PressedAction = UIScene.extend({
|
||||
var UIButtonTest_PressedAction = UIMainLayer.extend({
|
||||
init: function () {
|
||||
if (this._super()) {
|
||||
//init text
|
||||
|
@ -154,7 +154,7 @@ var UIButtonTest_PressedAction = UIScene.extend({
|
|||
}
|
||||
});
|
||||
|
||||
var UIButtonTest_Title = UIScene.extend({
|
||||
var UIButtonTest_Title = UIMainLayer.extend({
|
||||
init: function () {
|
||||
if (this._super()) {
|
||||
var widgetSize = this._widget.getContentSize();
|
||||
|
@ -197,7 +197,7 @@ var UIButtonTest_Title = UIScene.extend({
|
|||
}
|
||||
});
|
||||
|
||||
var UIButtonTestRemoveSelf = UIScene.extend({
|
||||
var UIButtonTestRemoveSelf = UIMainLayer.extend({
|
||||
init: function () {
|
||||
if (this._super()) {
|
||||
//init text
|
||||
|
@ -254,7 +254,7 @@ var UIButtonTestRemoveSelf = UIScene.extend({
|
|||
}
|
||||
});
|
||||
|
||||
var UIButtonTestSwitchScale9 = UIScene.extend({
|
||||
var UIButtonTestSwitchScale9 = UIMainLayer.extend({
|
||||
init: function(){
|
||||
if (this._super()){
|
||||
var widgetSize = this._widget.getContentSize();
|
||||
|
@ -303,7 +303,7 @@ var UIButtonTestSwitchScale9 = UIScene.extend({
|
|||
}
|
||||
});
|
||||
|
||||
var UIButtonTestZoomScale = UIScene.extend({
|
||||
var UIButtonTestZoomScale = UIMainLayer.extend({
|
||||
init: function(){
|
||||
if (this._super()) {
|
||||
var widgetSize = this._widget.getContentSize();
|
||||
|
@ -347,7 +347,7 @@ var UIButtonTestZoomScale = UIScene.extend({
|
|||
}
|
||||
});
|
||||
|
||||
var UIButtonTextOnly = UIScene.extend({
|
||||
var UIButtonTextOnly = UIMainLayer.extend({
|
||||
init: function(){
|
||||
if (this._super()) {
|
||||
// Add a label in which the button events will be displayed
|
||||
|
@ -372,7 +372,7 @@ var UIButtonTextOnly = UIScene.extend({
|
|||
}
|
||||
});
|
||||
|
||||
var UIButtonIgnoreContentSizeTest = UIScene.extend({
|
||||
var UIButtonIgnoreContentSizeTest = UIMainLayer.extend({
|
||||
init: function(){
|
||||
if (this._super()) {
|
||||
var widgetSize = this._widget.getContentSize();
|
||||
|
@ -415,7 +415,7 @@ var UIButtonIgnoreContentSizeTest = UIScene.extend({
|
|||
}
|
||||
});
|
||||
|
||||
var UIButtonTitleEffectTest = UIScene.extend({
|
||||
var UIButtonTitleEffectTest = UIMainLayer.extend({
|
||||
init: function(){
|
||||
if (this._super()) {
|
||||
var widgetSize = this._widget.getContentSize();
|
||||
|
@ -450,7 +450,7 @@ var UIButtonTitleEffectTest = UIScene.extend({
|
|||
}
|
||||
});
|
||||
|
||||
var UIButtonFlipTest = UIScene.extend({
|
||||
var UIButtonFlipTest = UIMainLayer.extend({
|
||||
init: function(){
|
||||
if (this._super()) {
|
||||
|
||||
|
@ -489,7 +489,7 @@ var UIButtonFlipTest = UIScene.extend({
|
|||
}
|
||||
});
|
||||
|
||||
var UIButtonNormalDefaultTest = UIScene.extend({
|
||||
var UIButtonNormalDefaultTest = UIMainLayer.extend({
|
||||
init: function(){
|
||||
if (this._super()) {
|
||||
var widgetSize = this._widget.getContentSize();
|
||||
|
@ -526,7 +526,7 @@ var UIButtonNormalDefaultTest = UIScene.extend({
|
|||
}
|
||||
});
|
||||
|
||||
var UIButtonDisableDefaultTest = UIScene.extend({
|
||||
var UIButtonDisableDefaultTest = UIMainLayer.extend({
|
||||
init: function(){
|
||||
if (this._super()) {
|
||||
var widgetSize = this._widget.getContentSize();
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
var UICheckBoxTest = UIScene.extend({
|
||||
var UICheckBoxTest = UIMainLayer.extend({
|
||||
init: function () {
|
||||
if (this._super()) {
|
||||
//init text
|
||||
|
@ -65,7 +65,7 @@ var UICheckBoxTest = UIScene.extend({
|
|||
});
|
||||
|
||||
//2015-01-14
|
||||
var UICheckBoxDefaultBehaviorTest = UIScene.extend({
|
||||
var UICheckBoxDefaultBehaviorTest = UIMainLayer.extend({
|
||||
|
||||
init: function(){
|
||||
if(this._super()){
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
var UIFocusTestBase = UIScene.extend({
|
||||
var UIFocusTestBase = UIMainLayer.extend({
|
||||
_dpadMenu: null,
|
||||
_firstFocusedWidget: null,
|
||||
_eventListener:null,
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
var UIImageViewTest = UIScene.extend({
|
||||
var UIImageViewTest = UIMainLayer.extend({
|
||||
init: function () {
|
||||
if (this._super()) {
|
||||
//init text
|
||||
|
@ -43,7 +43,7 @@ var UIImageViewTest = UIScene.extend({
|
|||
}
|
||||
});
|
||||
|
||||
var UIImageViewTest_Scale9 = UIScene.extend({
|
||||
var UIImageViewTest_Scale9 = UIMainLayer.extend({
|
||||
init: function () {
|
||||
if (this._super()) {
|
||||
var widgetSize = this._widget.getContentSize();
|
||||
|
@ -67,7 +67,7 @@ var UIImageViewTest_Scale9 = UIScene.extend({
|
|||
});
|
||||
|
||||
//2015-01-14
|
||||
var UIImageViewTest_ContentSize = UIScene.extend({
|
||||
var UIImageViewTest_ContentSize = UIMainLayer.extend({
|
||||
init: function(){
|
||||
if (this._super()) {
|
||||
var widgetSize = this._widget.getContentSize();
|
||||
|
@ -127,7 +127,7 @@ var UIImageViewTest_ContentSize = UIScene.extend({
|
|||
});
|
||||
|
||||
//2015-01-14
|
||||
var UIImageViewFlipTest = UIScene.extend({
|
||||
var UIImageViewFlipTest = UIMainLayer.extend({
|
||||
init: function(){
|
||||
if (this._super()) {
|
||||
cc.spriteFrameCache.addSpriteFrames("Images/blocks9ss.plist");
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
****************************************************************************/
|
||||
|
||||
|
||||
var UILabelAtlasTest = UIScene.extend({
|
||||
var UILabelAtlasTest = UIMainLayer.extend({
|
||||
init: function () {
|
||||
if (this._super()) {
|
||||
//init text
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
****************************************************************************/
|
||||
|
||||
|
||||
var UILabelBMFontTest = UIScene.extend({
|
||||
var UILabelBMFontTest = UIMainLayer.extend({
|
||||
init: function () {
|
||||
if (this._super()) {
|
||||
//init text
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
****************************************************************************/
|
||||
|
||||
|
||||
var UILabelTest = UIScene.extend({
|
||||
var UILabelTest = UIMainLayer.extend({
|
||||
init: function () {
|
||||
if (this._super()) {
|
||||
//init text
|
||||
|
@ -47,7 +47,7 @@ var UILabelTest = UIScene.extend({
|
|||
}
|
||||
});
|
||||
|
||||
var UILabelTest_LineWrap = UIScene.extend({
|
||||
var UILabelTest_LineWrap = UIMainLayer.extend({
|
||||
init: function () {
|
||||
if (this._super()) {
|
||||
var widgetSize = this._widget.getContentSize();
|
||||
|
@ -75,7 +75,7 @@ var UILabelTest_LineWrap = UIScene.extend({
|
|||
});
|
||||
|
||||
|
||||
var UILabelTest_TTF = UIScene.extend({
|
||||
var UILabelTest_TTF = UIMainLayer.extend({
|
||||
init: function () {
|
||||
if (this._super()) {
|
||||
//init text
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
var UILayoutTestBase = UIScene.extend({
|
||||
var UILayoutTestBase = UIMainLayer.extend({
|
||||
layout: null,
|
||||
button: null,
|
||||
textButton: null,
|
||||
|
@ -239,7 +239,7 @@ var UILayoutTest_Layout_Relative = UILayoutTestBase.extend({
|
|||
}
|
||||
});
|
||||
|
||||
var UILayoutTest_Layout_Relative_Align_Parent = UIScene.extend({
|
||||
var UILayoutTest_Layout_Relative_Align_Parent = UIMainLayer.extend({
|
||||
init: function(){
|
||||
if (this._super()) {
|
||||
var widgetSize = this._widget.getContentSize();
|
||||
|
@ -337,7 +337,7 @@ var UILayoutTest_Layout_Relative_Align_Parent = UIScene.extend({
|
|||
}
|
||||
});
|
||||
|
||||
var UILayoutTest_Layout_Relative_Location = UIScene.extend({
|
||||
var UILayoutTest_Layout_Relative_Location = UIMainLayer.extend({
|
||||
init: function(){
|
||||
if (this._super()) {
|
||||
var widgetSize = this._widget.getContentSize();
|
||||
|
@ -406,7 +406,7 @@ var UILayoutTest_Layout_Relative_Location = UIScene.extend({
|
|||
}
|
||||
});
|
||||
|
||||
var UILayoutComponentTest = UIScene.extend({
|
||||
var UILayoutComponentTest = UIMainLayer.extend({
|
||||
_baseLayer: null,
|
||||
init: function(){
|
||||
if (this._super()) {
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
var UIListViewTest_Vertical = UIScene.extend({
|
||||
var UIListViewTest_Vertical = UIMainLayer.extend({
|
||||
init: function () {
|
||||
if (this._super()) {
|
||||
var widgetSize = this._widget.getContentSize();
|
||||
|
@ -156,7 +156,7 @@ var UIListViewTest_Vertical = UIScene.extend({
|
|||
}
|
||||
});
|
||||
|
||||
var UIListViewTest_Horizontal = UIScene.extend({
|
||||
var UIListViewTest_Horizontal = UIMainLayer.extend({
|
||||
_array: null,
|
||||
init: function () {
|
||||
if (this._super()) {
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
var UILoadingBarTest = UIScene.extend({
|
||||
var UILoadingBarTest = UIMainLayer.extend({
|
||||
_count: 0,
|
||||
_loadingBar:null,
|
||||
ctor: function () {
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
var UIWidgetAddNodeTest = UIScene.extend({
|
||||
var UIWidgetAddNodeTest = UIMainLayer.extend({
|
||||
init: function () {
|
||||
if (this._super()) {
|
||||
var widgetSize = this._widget.getContentSize();
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
var UIPageViewTest = UIScene.extend({
|
||||
var UIPageViewTest = UIMainLayer.extend({
|
||||
init: function () {
|
||||
if (this._super()) {
|
||||
var widgetSize = this._widget.getContentSize();
|
||||
|
@ -89,7 +89,7 @@ var UIPageViewTest = UIScene.extend({
|
|||
});
|
||||
|
||||
//2015-01-14
|
||||
var UIPageViewButtonTest = UIScene.extend({
|
||||
var UIPageViewButtonTest = UIMainLayer.extend({
|
||||
init: function(){
|
||||
if (this._super()){
|
||||
var widgetSize = this._widget.getContentSize();
|
||||
|
@ -165,7 +165,7 @@ var UIPageViewButtonTest = UIScene.extend({
|
|||
});
|
||||
|
||||
//2015-01-14
|
||||
var UIPageViewCustomScrollThreshold = UIScene.extend({
|
||||
var UIPageViewCustomScrollThreshold = UIMainLayer.extend({
|
||||
init: function(){
|
||||
if (this._super()){
|
||||
var widgetSize = this._widget.getContentSize();
|
||||
|
@ -240,7 +240,7 @@ var UIPageViewCustomScrollThreshold = UIScene.extend({
|
|||
});
|
||||
|
||||
//2015-01-14
|
||||
var UIPageViewTouchPropagationTest = UIScene.extend({
|
||||
var UIPageViewTouchPropagationTest = UIMainLayer.extend({
|
||||
init: function(){
|
||||
if (this._super()){
|
||||
var widgetSize = this._widget.getContentSize();
|
||||
|
@ -396,7 +396,7 @@ var UIPageViewTouchPropagationTest = UIScene.extend({
|
|||
});
|
||||
|
||||
//2015-01-14
|
||||
var UIPageViewDynamicAddAndRemoveTest = UIScene.extend({
|
||||
var UIPageViewDynamicAddAndRemoveTest = UIMainLayer.extend({
|
||||
init: function(){
|
||||
var self = this;
|
||||
if (this._super()){
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue