Merge branch 'develop' of https://github.com/cocos2d/cocos2d-x into develop

This commit is contained in:
yuye.liu 2013-09-24 16:19:44 +08:00
commit 52559bc099
33 changed files with 476 additions and 616 deletions

View File

@ -596,6 +596,9 @@ Retired Core Developers:
michaelcontento
[Android] use onWindowFocusChanged(bool) instead of onResume()/onPause()
Prevent nullptr access in AssetsManager
[Android] re-introduce Cocos2dxHelper.runOnGLThread(Runnable)
[Android] added EGL_RENDERABLE_TYPE to OpenGL attributes
bmanGH
Use gl caching functions in TexturePVR::createGLTexture()

View File

@ -1,3 +1,10 @@
cocos2d-x-3.0alpha1 @??? 2013
[all platforms]
[FIX] Texture: use CCLOG to log when a texture is being decoded in software
[Android]
[FIX] Added EGL_RENDERABLE_TYPE to OpenGL attributes
[NEW] Added Cocos2dxHelper.runOnGLThread(Runnable) again
cocos2d-x-3.0alpha0 @Sep.19 2013
[all platforms]
[FIX] TargetAction::reverse() works as expected

View File

@ -1 +1 @@
2abd573d3cb41c16925cbdf14bd55be5f97d88a4
c1187b92c8c7120b1c2f73b08c8e26530ac1e812

View File

@ -44,7 +44,7 @@ Configuration::Configuration()
: _maxTextureSize(0)
, _maxModelviewStackDepth(0)
, _supportsPVRTC(false)
, _supportsETC(false)
, _supportsETC1(false)
, _supportsS3TC(false)
, _supportsATITC(false)
, _supportsNPOT(false)
@ -128,8 +128,8 @@ void Configuration::gatherGPUInfo()
_valueDict->setObject(Integer::create((int)_maxSamplesAllowed), "gl.max_samples_allowed");
#endif
_supportsETC = checkForGLExtension("GL_OES_compressed_ETC1_RGB8_texture");
_valueDict->setObject(Bool::create(_supportsETC), "gl.supports_ETC");
_supportsETC1 = checkForGLExtension("GL_OES_compressed_ETC1_RGB8_texture");
_valueDict->setObject(Bool::create(_supportsETC1), "gl.supports_ETC1");
_supportsS3TC = checkForGLExtension("GL_EXT_texture_compression_s3tc");
_valueDict->setObject(Bool::create(_supportsS3TC), "gl.supports_S3TC");
@ -231,7 +231,7 @@ bool Configuration::supportsETC() const
{
//GL_ETC1_RGB8_OES is not defined in old opengl version
#ifdef GL_ETC1_RGB8_OES
return _supportsETC;
return _supportsETC1;
#else
return false;
#endif

View File

@ -152,7 +152,7 @@ protected:
GLint _maxTextureSize;
GLint _maxModelviewStackDepth;
bool _supportsPVRTC;
bool _supportsETC;
bool _supportsETC1;
bool _supportsS3TC;
bool _supportsATITC;
bool _supportsNPOT;

View File

@ -59,7 +59,7 @@ class KeypadDispatcher;
class Accelerometer;
/**
@brief Class that creates and handle the main Window and manages how
@brief Class that creates and handles the main Window and manages how
and when to execute the Scenes.
The Director is also responsible for:
@ -117,7 +117,7 @@ public:
// attribute
/** Get current running Scene. Director can only run one Scene at the time */
/** Get current running Scene. Director can only run one Scene at a time */
inline Scene* getRunningScene() { return _runningScene; }
/** Get the FPS value */
@ -178,7 +178,7 @@ public:
Node* getNotificationNode();
void setNotificationNode(Node *node);
/** Director delegate. It shall implemente the DirectorDelegate protocol
/** Director delegate. It shall implement the DirectorDelegate protocol
@since v0.99.5
* @js NA
* @lua NA
@ -240,20 +240,20 @@ public:
*/
void pushScene(Scene *scene);
/** Pops out a scene from the queue.
/** Pops out a scene from the stack.
* This scene will replace the running one.
* The running scene will be deleted. If there are no more scenes in the stack the execution is terminated.
* ONLY call it if there is a running scene.
*/
void popScene();
/** Pops out all scenes from the queue until the root scene in the queue.
/** Pops out all scenes from the stack until the root scene in the queue.
* This scene will replace the running one.
* Internally it will call `popToSceneStackLevel(1)`
*/
void popToRootScene();
/** Pops out all scenes from the queue until it reaches `level`.
/** Pops out all scenes from the stack until it reaches `level`.
If level is 0, it will end the director.
If level is 1, it will pop all scenes until it reaches to root scene.
If level is <= than the current stack level, it won't do anything.
@ -301,7 +301,7 @@ public:
// Memory Helper
/** Removes cached all cocos2d cached data.
/** Removes all cocos2d cached data.
It will purge the TextureCache, SpriteFrameCache, LabelBMFont cache
@since v0.99.3
*/

View File

@ -619,7 +619,7 @@ public:
* node->setPosition(0,0);
* }
* @endcode
* This sample code traverses all children nodes, and set theie position to (0,0)
* This sample code traverses all children nodes, and set their position to (0,0)
*
* @return An array of children
*/

View File

@ -223,7 +223,7 @@ class CC_DLL LabelProtocol
{
public:
/**
* Sets a new label using an string
* Sets a new label using a string
*
* @param label A null terminated string
* @js NA

View File

@ -39,7 +39,7 @@ NS_CC_BEGIN
/** @brief Scene is a subclass of Node that is used only as an abstract concept.
Scene and Node are almost identical with the difference that Scene has it's
Scene and Node are almost identical with the difference that Scene has its
anchor point (by default) at the center of the screen.
For the moment Scene has no other logic than that, but in future releases it might have

View File

@ -1443,6 +1443,8 @@ bool Image::initWithETCData(const unsigned char * data, int dataLen)
}
else
{
CCLOG("cocos2d: Hardware ETC1 decoder not present. Using software decoder");
//if it is not gles or device do not support ETC, decode texture by software
int bytePerPixel = 3;
unsigned int stride = _width * bytePerPixel;
@ -1533,8 +1535,6 @@ bool Image::initWithS3TCData(const unsigned char * data, int dataLen)
if (Configuration::getInstance()->supportsS3TC())
{ //decode texture throught hardware
CCLOG("this is s3tc H decode");
if (FOURCC_DXT1 == header->ddsd.DUMMYUNIONNAMEN4.ddpfPixelFormat.fourCC)
{
_renderFormat = Texture2D::PixelFormat::S3TC_DXT1;
@ -1553,6 +1553,9 @@ bool Image::initWithS3TCData(const unsigned char * data, int dataLen)
}
else
{ //if it is not gles or device do not support S3TC, decode texture by software
CCLOG("cocos2d: Hardware S3TC decoder not present. Using software decoder");
int bytePerPixel = 4;
unsigned int stride = width * bytePerPixel;
_renderFormat = Texture2D::PixelFormat::RGBA8888;
@ -1682,6 +1685,8 @@ bool Image::initWithATITCData(const unsigned char *data, int dataLen)
{
/* if it is not gles or device do not support ATITC, decode texture by software */
CCLOG("cocos2d: Hardware ATITC decoder not present. Using software decoder");
int bytePerPixel = 4;
unsigned int stride = width * bytePerPixel;
_renderFormat = Texture2D::PixelFormat::RGBA8888;

View File

@ -23,8 +23,10 @@ THE SOFTWARE.
****************************************************************************/
package org.cocos2dx.lib;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.io.UnsupportedEncodingException;
import java.util.Locale;
import java.lang.Runnable;
import android.app.Activity;
import android.app.AlertDialog;
@ -44,6 +46,7 @@ public class Cocos2dxHelper {
// Constants
// ===========================================================
private static final String PREFS_NAME = "Cocos2dxPrefsFile";
private static final int RUNNABLES_PER_FRAME = 5;
// ===========================================================
// Fields
@ -57,7 +60,8 @@ public class Cocos2dxHelper {
private static String sFileDirectory;
private static Activity sActivity = null;
private static Cocos2dxHelperListener sCocos2dxHelperListener;
private static ConcurrentLinkedQueue<Runnable> jobs = new ConcurrentLinkedQueue<Runnable>();
/**
* Optional meta-that can be in the manifest for this component, specifying
* the name of the native shared library to load. If not specified,
@ -70,6 +74,20 @@ public class Cocos2dxHelper {
// Constructors
// ===========================================================
public static void dispatchPendingRunnables() {
for (int i = RUNNABLES_PER_FRAME; i > 0; i--) {
Runnable job = jobs.poll();
if (job == null) {
return;
}
job.run();
}
}
public static void runOnGLThread(final Runnable r) {
jobs.add(r);
}
public static void init(final Activity activity) {
final ApplicationInfo applicationInfo = activity.getApplicationInfo();

View File

@ -254,13 +254,13 @@ namespace cocos2d {
}
JNIEnv *pEnv = JniHelper::getEnv();
if (!env) {
if (!pEnv) {
return NULL;
}
const char* chars = env->GetStringUTFChars(jstr, NULL);
const char* chars = pEnv->GetStringUTFChars(jstr, NULL);
std::string ret(chars);
env->ReleaseStringUTFChars(jstr, chars);
pEnv->ReleaseStringUTFChars(jstr, chars);
return ret;
}

View File

@ -150,6 +150,7 @@ static cocos_dimensions engine_init_display(struct engine* engine) {
*/
const EGLint attribs[] = {
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL_BLUE_SIZE, 5,
EGL_GREEN_SIZE, 6,
EGL_RED_SIZE, 5,
@ -211,6 +212,30 @@ static cocos_dimensions engine_init_display(struct engine* engine) {
return r;
}
/**
* Invoke the dispatching of the next bunch of Runnables in the Java-Land
*/
static void dispatch_pending_runnables() {
static cocos2d::JniMethodInfo info;
static bool initialized = false;
if (!initialized) {
initialized = cocos2d::JniHelper::getStaticMethodInfo(
info,
"org/cocos2dx/lib/Cocos2dxHelper",
"dispatchPendingRunnables",
"()V"
);
if (!initialized) {
LOGW("Unable to dispatch pending Runnables!");
return;
}
}
info.env->CallStaticVoidMethod(info.classID, info.methodID);
}
/**
* Just the current frame in the display.
*/
@ -225,6 +250,7 @@ static void engine_draw_frame(struct engine* engine) {
return;
}
dispatch_pending_runnables();
cocos2d::Director::getInstance()->mainLoop();
LOG_RENDER_DEBUG("engine_draw_frame : just called cocos' mainLoop()");

View File

@ -63,7 +63,6 @@ CocoStudio/Components/CCInputDelegate.cpp \
CocoStudio/GUI/BaseClasses/UIRootWidget.cpp \
CocoStudio/GUI/BaseClasses/UIWidget.cpp \
CocoStudio/GUI/Layouts/Layout.cpp \
CocoStudio/GUI/Layouts/LayoutExecutant.cpp \
CocoStudio/GUI/Layouts/LayoutParameter.cpp \
CocoStudio/GUI/Layouts/UILayoutDefine.cpp \
CocoStudio/GUI/System/CocosGUI.cpp \

View File

@ -628,7 +628,7 @@ void AssetsManager::Helper::handleUpdateSucceed(Message *msg)
CCLOG("can not remove downloaded zip file %s", zipfileName.c_str());
}
if (manager) manager->_delegate->onSuccess();
if (manager->_delegate) manager->_delegate->onSuccess();
}
AssetsManager* AssetsManager::create(const char* packageUrl, const char* versionFileUrl, const char* storagePath, ErrorCallback errorCallback, ProgressCallback progressCallback, SuccessCallback successCallback )

View File

@ -24,6 +24,7 @@
#include "Layout.h"
#include "../System/UILayer.h"
#include "../System/UIHelper.h"
#include "../../../GUI/CCControlExtension/CCScale9Sprite.h"
NS_CC_EXT_BEGIN
@ -32,7 +33,6 @@ NS_CC_EXT_BEGIN
Layout::Layout():
_clippingEnabled(false),
_layoutExecutant(NULL),
_backGroundScale9Enabled(false),
_backGroundImage(NULL),
_backGroundImageFileName(""),
@ -46,14 +46,14 @@ _gStartColor(Color3B::WHITE),
_gEndColor(Color3B::WHITE),
_alongVector(Point(0.0f, -1.0f)),
_cOpacity(255),
_backGroundImageTextureSize(Size::ZERO)
_backGroundImageTextureSize(Size::ZERO),
_layoutType(LAYOUT_ABSOLUTE)
{
_widgetType = WidgetTypeContainer;
}
Layout::~Layout()
{
CC_SAFE_RELEASE_NULL(_layoutExecutant);
}
Layout* Layout::create()
@ -90,22 +90,6 @@ bool Layout::init()
return true;
}
void Layout::setLayoutExecutant(LayoutExecutant *exe)
{
if (_layoutExecutant)
{
CC_SAFE_RELEASE_NULL(_layoutExecutant);
}
_layoutExecutant = exe;
_layoutExecutant->setLayout(this);
CC_SAFE_RETAIN(_layoutExecutant);
}
LayoutExecutant* Layout::getLayoutExecutant() const
{
return _layoutExecutant;
}
void Layout::initRenderer()
{
_renderer = RectClippingNode::create();
@ -136,10 +120,7 @@ void Layout::setClippingEnabled(bool able)
void Layout::onSizeChanged()
{
DYNAMIC_CAST_CLIPPINGLAYER->setClippingSize(_size);
if (_layoutExecutant)
{
_layoutExecutant->doLayout();
}
doLayout();
if (_backGroundImage)
{
_backGroundImage->setPosition(Point(_size.width/2.0f, _size.height/2.0f));
@ -425,6 +406,283 @@ const Size& Layout::getContentSize() const
return _renderer->getContentSize();
}
void Layout::setLayoutType(LayoutType type)
{
_layoutType = type;
}
LayoutType Layout::getLayoutType() const
{
return _layoutType;
}
void Layout::doLayout()
{
switch (_layoutType)
{
case LAYOUT_ABSOLUTE:
break;
case LAYOUT_LINEAR_VERTICAL:
{
ccArray* layoutChildrenArray = getChildren()->data;
int length = layoutChildrenArray->num;
Size layoutSize = getSize();
float topBoundary = layoutSize.height;
for (int i=0; i<length; ++i)
{
UIWidget* child = dynamic_cast<UIWidget*>(layoutChildrenArray->arr[i]);
LinearLayoutParameter* layoutParameter = dynamic_cast<LinearLayoutParameter*>(child->getLayoutParameter());
if (layoutParameter)
{
WidgetType childType = child->getWidgetType();
UILinearGravity childGravity = layoutParameter->getGravity();
Point ap = child->getAnchorPoint();
Size cs = child->getSize();
float finalPosX = childType == WidgetTypeWidget ? ap.x * cs.width : 0.0f;
float finalPosY = childType == WidgetTypeWidget ? topBoundary - ((1.0f-ap.y) * cs.height) : topBoundary - cs.height;
switch (childGravity)
{
case LINEAR_GRAVITY_NONE:
case LINEAR_GRAVITY_LEFT:
break;
case LINEAR_GRAVITY_RIGHT:
finalPosX = childType == WidgetTypeWidget ? layoutSize.width - ((1.0f - ap.x) * cs.width) : layoutSize.width - cs.width;
break;
case LINEAR_GRAVITY_CENTER_HORIZONTAL:
finalPosX = childType == WidgetTypeWidget ? layoutSize.width / 2.0f - cs.width * (0.5f-ap.x) : (layoutSize.width - cs.width) * 0.5f;
break;
default:
break;
}
UIMargin mg = layoutParameter->getMargin();
finalPosX += mg.left;
finalPosY -= mg.top;
child->setPosition(Point(finalPosX, finalPosY));
topBoundary = child->getBottomInParent() - mg.bottom;
}
}
break;
}
case LAYOUT_LINEAR_HORIZONTAL:
{
ccArray* layoutChildrenArray = getChildren()->data;
int length = layoutChildrenArray->num;
Size layoutSize = getSize();
float leftBoundary = 0.0f;
for (int i=0; i<length; ++i)
{
UIWidget* child = dynamic_cast<UIWidget*>(layoutChildrenArray->arr[i]);
LinearLayoutParameter* layoutParameter = dynamic_cast<LinearLayoutParameter*>(child->getLayoutParameter());
if (layoutParameter)
{
WidgetType childType = child->getWidgetType();
UILinearGravity childGravity = layoutParameter->getGravity();
Point ap = child->getAnchorPoint();
Size cs = child->getSize();
float finalPosX = childType == WidgetTypeWidget ? leftBoundary + (ap.x * cs.width) : leftBoundary;
float finalPosY = childType == WidgetTypeWidget ? layoutSize.height - (1.0f - ap.y) * cs.height : layoutSize.height - cs.height;
switch (childGravity)
{
case LINEAR_GRAVITY_NONE:
case LINEAR_GRAVITY_TOP:
break;
case LINEAR_GRAVITY_BOTTOM:
finalPosY = childType == WidgetTypeWidget ? ap.y * cs.height : 0.0f;
break;
case LINEAR_GRAVITY_CENTER_VERTICAL:
finalPosY = childType == WidgetTypeWidget ? layoutSize.height/2.0f - cs.height * (0.5f - ap.y) : (layoutSize.height - cs.height) * 0.5f;
break;
default:
break;
}
UIMargin mg = layoutParameter->getMargin();
finalPosX += mg.left;
finalPosY -= mg.top;
child->setPosition(Point(finalPosX, finalPosY));
leftBoundary = child->getRightInParent() + mg.right;
}
}
break;
}
case LAYOUT_RELATIVE:
{
ccArray* layoutChildrenArray = getChildren()->data;
int length = layoutChildrenArray->num;
Size layoutSize = getSize();
for (int i=0; i<length; i++)
{
UIWidget* child = dynamic_cast<UIWidget*>(layoutChildrenArray->arr[i]);
WidgetType childType = child->getWidgetType();
Point ap = child->getAnchorPoint();
Size cs = child->getSize();
RelativeLayoutParameter* layoutParameter = dynamic_cast<RelativeLayoutParameter*>(child->getLayoutParameter());
if (layoutParameter)
{
float finalPosX = childType == WidgetTypeWidget ? ap.x * cs.width : 0.0f;
float finalPosY = childType == WidgetTypeWidget ? layoutSize.height - ((1.0f - ap.y) * cs.height) : layoutSize.height - cs.height;
UIRelativeAlign align = layoutParameter->getAlign();
const char* relativeName = layoutParameter->getRelativeToWidgetName();
UIWidget* relativeWidget = NULL;
if (relativeName && strcmp(relativeName, ""))
{
relativeWidget = CCUIHELPER->seekWidgetByRelativeName(this, relativeName);
}
switch (align)
{
case RELATIVE_ALIGN_NONE:
break;
case RELATIVE_ALIGN_PARENT_LEFT:
break;
case RELATIVE_ALIGN_PARENT_TOP:
break;
case RELATIVE_ALIGN_PARENT_RIGHT:
finalPosX = childType == WidgetTypeWidget ? layoutSize.width - ((1.0f - ap.x) * cs.width) : layoutSize.width - cs.width;
break;
case RELATIVE_ALIGN_PARENT_BOTTOM:
finalPosY = childType == WidgetTypeWidget ? ap.y * cs.height : 0.0f;
break;
case RELATIVE_CENTER_IN_PARENT:
finalPosX = childType == WidgetTypeWidget ? layoutSize.width * 0.5f - cs.width * (0.5f - ap.x) : (layoutSize.width - cs.width) * 0.5f;
finalPosY = childType == WidgetTypeWidget ? layoutSize.height * 0.5f - cs.height * (0.5f - ap.y) : (layoutSize.height - cs.height) * 0.5f;
break;
case RELATIVE_CENTER_HORIZONTAL:
finalPosX = childType == WidgetTypeWidget ? layoutSize.width * 0.5f - cs.width * (0.5f - ap.x) : (layoutSize.width - cs.width) * 0.5f;
break;
case RELATIVE_CENTER_VERTICAL:
finalPosY = childType == WidgetTypeWidget ? layoutSize.height * 0.5f - cs.height * (0.5f - ap.y) : (layoutSize.height - cs.height) * 0.5f;
break;
case RELATIVE_LOCATION_LEFT_OF_TOPALIGN:
if (relativeWidget)
{
float locationTop = relativeWidget->getTopInParent();
float locationRight = relativeWidget->getLeftInParent();
finalPosY = childType == WidgetTypeWidget ? locationTop - ap.y * cs.height : locationTop - cs.height;
finalPosX = childType == WidgetTypeWidget ? locationRight - (1.0f - ap.x) * cs.width : locationRight - cs.width;
}
break;
case RELATIVE_LOCATION_LEFT_OF_CENTER:
break;
case RELATIVE_LOCATION_LEFT_OF_BOTTOMALIGN:
if (relativeWidget)
{
float locationRight = relativeWidget->getLeftInParent();
float locationBottom = relativeWidget->getBottomInParent();
finalPosY = childType == WidgetTypeWidget ? locationBottom + ap.y * cs.height : locationBottom;
finalPosX = childType == WidgetTypeWidget ? locationRight - (1.0f - ap.x) * cs.width : locationRight - cs.width;
}
break;
case RELATIVE_LOCATION_RIGHT_OF_TOPALIGN:
if (relativeWidget)
{
float locationTop = relativeWidget->getTopInParent();
float locationLeft = relativeWidget->getRightInParent();
finalPosY = childType == WidgetTypeWidget ? locationTop - ap.y * cs.height : locationTop - cs.height;
finalPosX = childType == WidgetTypeWidget ? locationLeft + ap.x * cs.width : locationLeft;
}
break;
case RELATIVE_LOCATION_RIGHT_OF_CENTER:
break;
case RELATIVE_LOCATION_RIGHT_OF_BOTTOMALIGN:
if (relativeWidget)
{
float locationLeft = relativeWidget->getRightInParent();
float locationBottom = relativeWidget->getBottomInParent();
finalPosY = childType == WidgetTypeWidget ? locationBottom + ap.y * cs.height : locationBottom;
finalPosX = childType == WidgetTypeWidget ? locationLeft + ap.x * cs.width : locationLeft;
}
break;
case RELATIVE_LOCATION_ABOVE_LEFTALIGN:
if (relativeWidget)
{
float locationBottom = relativeWidget->getTopInParent();
float locationLeft = relativeWidget->getLeftInParent();
finalPosY = childType == WidgetTypeWidget ? locationBottom + ap.y * cs.height : locationBottom;
finalPosX = childType == WidgetTypeWidget ? locationLeft + ap.x * cs.width : locationLeft;
}
break;
case RELATIVE_LOCATION_ABOVE_CENTER:
break;
case RELATIVE_LOCATION_ABOVE_RIGHTALIGN:
if (relativeWidget)
{
float locationBottom = relativeWidget->getTopInParent();
float locationRight = relativeWidget->getRightInParent();
finalPosY = childType == WidgetTypeWidget ? locationBottom + ap.y * cs.height : locationBottom;
finalPosX = childType == WidgetTypeWidget ? locationRight - (1.0f - ap.x) * cs.width : locationRight - cs.width;
}
break;
case RELATIVE_LOCATION_BELOW_LEFTALIGN:
if (relativeWidget)
{
float locationTop = relativeWidget->getBottomInParent();
float locationLeft = relativeWidget->getLeftInParent();
finalPosY = childType == WidgetTypeWidget ? locationTop - (1.0f - ap.y) * cs.height : locationTop - cs.height;
finalPosX = childType == WidgetTypeWidget ? locationLeft + ap.x * cs.width : locationLeft;
}
break;
case RELATIVE_LOCATION_BELOW_CENTER:
break;
case RELATIVE_LOCATION_BELOW_RIGHTALIGN:
if (relativeWidget)
{
float locationTop = relativeWidget->getBottomInParent();
float locationRight = relativeWidget->getRightInParent();
finalPosY = childType == WidgetTypeWidget ? locationTop - (1.0f - ap.y) * cs.height : locationTop - cs.height;
finalPosX = childType == WidgetTypeWidget ? locationRight - (1.0f - ap.x) * cs.width : locationRight - cs.width;
}
break;
default:
break;
}
UIMargin relativeWidgetMargin;
UIMargin mg;
if (relativeWidget)
{
relativeWidgetMargin = relativeWidget->getLayoutParameter()->getMargin();
mg = child->getLayoutParameter()->getMargin();
}
//handle margin
switch (align)
{
case RELATIVE_LOCATION_ABOVE_LEFTALIGN:
case RELATIVE_LOCATION_ABOVE_RIGHTALIGN:
case RELATIVE_LOCATION_ABOVE_CENTER:
finalPosY += relativeWidgetMargin.top;
finalPosY += mg.bottom;
break;
case RELATIVE_LOCATION_BELOW_LEFTALIGN:
case RELATIVE_LOCATION_BELOW_RIGHTALIGN:
case RELATIVE_LOCATION_BELOW_CENTER:
finalPosY -= relativeWidgetMargin.bottom;
finalPosY -= mg.top;
break;
case RELATIVE_LOCATION_LEFT_OF_TOPALIGN:
case RELATIVE_LOCATION_LEFT_OF_BOTTOMALIGN:
case RELATIVE_LOCATION_LEFT_OF_CENTER:
finalPosX -= relativeWidgetMargin.left;
finalPosX -= mg.right;
break;
case RELATIVE_LOCATION_RIGHT_OF_TOPALIGN:
case RELATIVE_LOCATION_RIGHT_OF_BOTTOMALIGN:
case RELATIVE_LOCATION_RIGHT_OF_CENTER:
finalPosX += relativeWidgetMargin.right;
finalPosX += mg.left;
break;
default:
break;
}
child->setPosition(Point(finalPosX, finalPosY));
}
}
break;
}
default:
break;
}
}
const char* Layout::getDescription() const
{
return "Layout";

View File

@ -26,7 +26,6 @@
#define __LAYOUT_H__
#include "../BaseClasses/UIWidget.h"
#include "LayoutExecutant.h"
NS_CC_EXT_BEGIN
@ -37,6 +36,14 @@ typedef enum
LAYOUT_COLOR_GRADIENT
}LayoutBackGroundColorType;
typedef enum
{
LAYOUT_ABSOLUTE,
LAYOUT_LINEAR_VERTICAL,
LAYOUT_LINEAR_HORIZONTAL,
LAYOUT_RELATIVE
}LayoutType;
class Layout : public UIWidget
{
public:
@ -55,24 +62,6 @@ public:
*/
static Layout* create();
/**
* Sets a LayoutExecutant for doing layout.
*
* @see LayoutExecutant
*
* @param LayoutExecutant pointer.
*/
virtual void setLayoutExecutant(LayoutExecutant* exe);
/**
* Gets the LayoutExecutant of Layout
*
* @see LayoutExecutant
*
* @return LayoutExecutant pointer.
*/
virtual LayoutExecutant* getLayoutExecutant() const;
//override "hitTest" method of widget.
virtual bool hitTest(const Point &pt);
@ -178,6 +167,26 @@ public:
* Content size is widget's texture size.
*/
virtual const Size& getContentSize() const;
/**
* Sets LayoutType.
*
* @see LayoutType
*
* @param LayoutType
*/
virtual void setLayoutType(LayoutType type);
/**
* Gets LayoutType.
*
* @see LayoutType
*
* @return LayoutType
*/
virtual LayoutType getLayoutType() const;
virtual void doLayout();
/**
* Returns the "class name" of widget.
@ -197,7 +206,6 @@ protected:
void addBackGroundImage();
protected:
bool _clippingEnabled;
LayoutExecutant* _layoutExecutant;
//background
bool _backGroundScale9Enabled;
@ -214,6 +222,7 @@ protected:
Point _alongVector;
int _cOpacity;
Size _backGroundImageTextureSize;
LayoutType _layoutType;
};
class RectClippingNode : public ClippingNode

View File

@ -1,342 +0,0 @@
/****************************************************************************
Copyright (c) 2013 cocos2d-x.org
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.
****************************************************************************/
#include "LayoutExecutant.h"
#include "Layout.h"
#include "../System/UIHelper.h"
NS_CC_EXT_BEGIN
void LayoutExecutant::setLayout(Layout *layout)
{
_layout = layout;
}
Layout* LayoutExecutant::getLayout() const
{
return _layout;
}
LinearVerticalLayoutExecutant* LinearVerticalLayoutExecutant::create()
{
LinearVerticalLayoutExecutant* executant = new LinearVerticalLayoutExecutant();
if (executant)
{
executant->autorelease();
return executant;
}
CC_SAFE_DELETE(executant);
return NULL;
}
LinearHorizontalLayoutExecutant* LinearHorizontalLayoutExecutant::create()
{
LinearHorizontalLayoutExecutant* executant = new LinearHorizontalLayoutExecutant();
if (executant)
{
executant->autorelease();
return executant;
}
CC_SAFE_DELETE(executant);
return NULL;
}
RelativeLayoutExecutant* RelativeLayoutExecutant::create()
{
RelativeLayoutExecutant* executant = new RelativeLayoutExecutant();
if (executant)
{
executant->autorelease();
return executant;
}
CC_SAFE_DELETE(executant);
return NULL;
}
void LinearVerticalLayoutExecutant::doLayout()
{
if (_layout)
{
ccArray* layoutChildrenArray = _layout->getChildren()->data;
int length = layoutChildrenArray->num;
Size layoutSize = _layout->getSize();
float topBoundary = layoutSize.height;
for (int i=0; i<length; ++i)
{
UIWidget* child = dynamic_cast<UIWidget*>(layoutChildrenArray->arr[i]);
LinearLayoutParameter* layoutParameter = dynamic_cast<LinearLayoutParameter*>(child->getLayoutParameter());
if (layoutParameter)
{
WidgetType childType = child->getWidgetType();
UILinearGravity childGravity = layoutParameter->getGravity();
Point ap = child->getAnchorPoint();
Size cs = child->getSize();
float finalPosX = childType == WidgetTypeWidget ? ap.x * cs.width : 0.0f;
float finalPosY = childType == WidgetTypeWidget ? topBoundary - ((1.0f-ap.y) * cs.height) : topBoundary - cs.height;
switch (childGravity)
{
case LINEAR_GRAVITY_NONE:
case LINEAR_GRAVITY_LEFT:
break;
case LINEAR_GRAVITY_RIGHT:
finalPosX = childType == WidgetTypeWidget ? layoutSize.width - ((1.0f - ap.x) * cs.width) : layoutSize.width - cs.width;
break;
case LINEAR_GRAVITY_CENTER_HORIZONTAL:
finalPosX = childType == WidgetTypeWidget ? layoutSize.width / 2.0f - cs.width * (0.5f-ap.x) : (layoutSize.width - cs.width) * 0.5f;
break;
default:
break;
}
UIMargin mg = layoutParameter->getMargin();
finalPosX += mg.left;
finalPosY -= mg.top;
child->setPosition(Point(finalPosX, finalPosY));
topBoundary = child->getBottomInParent() - mg.bottom;
}
}
}
}
void LinearHorizontalLayoutExecutant::doLayout()
{
if (_layout)
{
ccArray* layoutChildrenArray = _layout->getChildren()->data;
int length = layoutChildrenArray->num;
Size layoutSize = _layout->getSize();
float leftBoundary = 0.0f;
for (int i=0; i<length; ++i)
{
UIWidget* child = dynamic_cast<UIWidget*>(layoutChildrenArray->arr[i]);
LinearLayoutParameter* layoutParameter = dynamic_cast<LinearLayoutParameter*>(child->getLayoutParameter());
if (layoutParameter)
{
WidgetType childType = child->getWidgetType();
UILinearGravity childGravity = layoutParameter->getGravity();
Point ap = child->getAnchorPoint();
Size cs = child->getSize();
float finalPosX = childType == WidgetTypeWidget ? leftBoundary + (ap.x * cs.width) : leftBoundary;
float finalPosY = childType == WidgetTypeWidget ? layoutSize.height - (1.0f - ap.y) * cs.height : layoutSize.height - cs.height;
switch (childGravity)
{
case LINEAR_GRAVITY_NONE:
case LINEAR_GRAVITY_TOP:
break;
case LINEAR_GRAVITY_BOTTOM:
finalPosY = childType == WidgetTypeWidget ? ap.y * cs.height : 0.0f;
break;
case LINEAR_GRAVITY_CENTER_VERTICAL:
finalPosY = childType == WidgetTypeWidget ? layoutSize.height/2.0f - cs.height * (0.5f - ap.y) : (layoutSize.height - cs.height) * 0.5f;
break;
default:
break;
}
UIMargin mg = layoutParameter->getMargin();
finalPosX += mg.left;
finalPosY -= mg.top;
child->setPosition(Point(finalPosX, finalPosY));
leftBoundary = child->getRightInParent() + mg.right;
}
}
}
}
void RelativeLayoutExecutant::doLayout()
{
if (_layout)
{
ccArray* layoutChildrenArray = _layout->getChildren()->data;
int length = layoutChildrenArray->num;
Size layoutSize = _layout->getSize();
for (int i=0; i<length; i++)
{
UIWidget* child = dynamic_cast<UIWidget*>(layoutChildrenArray->arr[i]);
WidgetType childType = child->getWidgetType();
Point ap = child->getAnchorPoint();
Size cs = child->getSize();
RelativeLayoutParameter* layoutParameter = dynamic_cast<RelativeLayoutParameter*>(child->getLayoutParameter());
if (layoutParameter)
{
float finalPosX = childType == WidgetTypeWidget ? ap.x * cs.width : 0.0f;
float finalPosY = childType == WidgetTypeWidget ? layoutSize.height - ((1.0f - ap.y) * cs.height) : layoutSize.height - cs.height;
UIRelativeAlign align = layoutParameter->getAlign();
const char* relativeName = layoutParameter->getRelativeToWidgetName();
UIWidget* relativeWidget = NULL;
if (relativeName && strcmp(relativeName, ""))
{
relativeWidget = CCUIHELPER->seekWidgetByRelativeName(_layout, relativeName);
}
switch (align)
{
case RELATIVE_ALIGN_NONE:
break;
case RELATIVE_ALIGN_PARENT_LEFT:
break;
case RELATIVE_ALIGN_PARENT_TOP:
break;
case RELATIVE_ALIGN_PARENT_RIGHT:
finalPosX = childType == WidgetTypeWidget ? layoutSize.width - ((1.0f - ap.x) * cs.width) : layoutSize.width - cs.width;
break;
case RELATIVE_ALIGN_PARENT_BOTTOM:
finalPosY = childType == WidgetTypeWidget ? ap.y * cs.height : 0.0f;
break;
case RELATIVE_CENTER_IN_PARENT:
finalPosX = childType == WidgetTypeWidget ? layoutSize.width * 0.5f - cs.width * (0.5f - ap.x) : (layoutSize.width - cs.width) * 0.5f;
finalPosY = childType == WidgetTypeWidget ? layoutSize.height * 0.5f - cs.height * (0.5f - ap.y) : (layoutSize.height - cs.height) * 0.5f;
break;
case RELATIVE_CENTER_HORIZONTAL:
finalPosX = childType == WidgetTypeWidget ? layoutSize.width * 0.5f - cs.width * (0.5f - ap.x) : (layoutSize.width - cs.width) * 0.5f;
break;
case RELATIVE_CENTER_VERTICAL:
finalPosY = childType == WidgetTypeWidget ? layoutSize.height * 0.5f - cs.height * (0.5f - ap.y) : (layoutSize.height - cs.height) * 0.5f;
break;
case RELATIVE_LOCATION_LEFT_OF_TOPALIGN:
if (relativeWidget)
{
float locationTop = relativeWidget->getTopInParent();
float locationRight = relativeWidget->getLeftInParent();
finalPosY = childType == WidgetTypeWidget ? locationTop - ap.y * cs.height : locationTop - cs.height;
finalPosX = childType == WidgetTypeWidget ? locationRight - (1.0f - ap.x) * cs.width : locationRight - cs.width;
}
break;
case RELATIVE_LOCATION_LEFT_OF_CENTER:
break;
case RELATIVE_LOCATION_LEFT_OF_BOTTOMALIGN:
if (relativeWidget)
{
float locationRight = relativeWidget->getLeftInParent();
float locationBottom = relativeWidget->getBottomInParent();
finalPosY = childType == WidgetTypeWidget ? locationBottom + ap.y * cs.height : locationBottom;
finalPosX = childType == WidgetTypeWidget ? locationRight - (1.0f - ap.x) * cs.width : locationRight - cs.width;
}
break;
case RELATIVE_LOCATION_RIGHT_OF_TOPALIGN:
if (relativeWidget)
{
float locationTop = relativeWidget->getTopInParent();
float locationLeft = relativeWidget->getRightInParent();
finalPosY = childType == WidgetTypeWidget ? locationTop - ap.y * cs.height : locationTop - cs.height;
finalPosX = childType == WidgetTypeWidget ? locationLeft + ap.x * cs.width : locationLeft;
}
break;
case RELATIVE_LOCATION_RIGHT_OF_CENTER:
break;
case RELATIVE_LOCATION_RIGHT_OF_BOTTOMALIGN:
if (relativeWidget)
{
float locationLeft = relativeWidget->getRightInParent();
float locationBottom = relativeWidget->getBottomInParent();
finalPosY = childType == WidgetTypeWidget ? locationBottom + ap.y * cs.height : locationBottom;
finalPosX = childType == WidgetTypeWidget ? locationLeft + ap.x * cs.width : locationLeft;
}
break;
case RELATIVE_LOCATION_ABOVE_LEFTALIGN:
if (relativeWidget)
{
float locationBottom = relativeWidget->getTopInParent();
float locationLeft = relativeWidget->getLeftInParent();
finalPosY = childType == WidgetTypeWidget ? locationBottom + ap.y * cs.height : locationBottom;
finalPosX = childType == WidgetTypeWidget ? locationLeft + ap.x * cs.width : locationLeft;
}
break;
case RELATIVE_LOCATION_ABOVE_CENTER:
break;
case RELATIVE_LOCATION_ABOVE_RIGHTALIGN:
if (relativeWidget)
{
float locationBottom = relativeWidget->getTopInParent();
float locationRight = relativeWidget->getRightInParent();
finalPosY = childType == WidgetTypeWidget ? locationBottom + ap.y * cs.height : locationBottom;
finalPosX = childType == WidgetTypeWidget ? locationRight - (1.0f - ap.x) * cs.width : locationRight - cs.width;
}
break;
case RELATIVE_LOCATION_BELOW_LEFTALIGN:
if (relativeWidget)
{
float locationTop = relativeWidget->getBottomInParent();
float locationLeft = relativeWidget->getLeftInParent();
finalPosY = childType == WidgetTypeWidget ? locationTop - (1.0f - ap.y) * cs.height : locationTop - cs.height;
finalPosX = childType == WidgetTypeWidget ? locationLeft + ap.x * cs.width : locationLeft;
}
break;
case RELATIVE_LOCATION_BELOW_CENTER:
break;
case RELATIVE_LOCATION_BELOW_RIGHTALIGN:
if (relativeWidget)
{
float locationTop = relativeWidget->getBottomInParent();
float locationRight = relativeWidget->getRightInParent();
finalPosY = childType == WidgetTypeWidget ? locationTop - (1.0f - ap.y) * cs.height : locationTop - cs.height;
finalPosX = childType == WidgetTypeWidget ? locationRight - (1.0f - ap.x) * cs.width : locationRight - cs.width;
}
break;
default:
break;
}
UIMargin relativeWidgetMargin;
UIMargin mg;
if (relativeWidget)
{
relativeWidgetMargin = relativeWidget->getLayoutParameter()->getMargin();
mg = child->getLayoutParameter()->getMargin();
}
//handle margin
switch (align)
{
case RELATIVE_LOCATION_ABOVE_LEFTALIGN:
case RELATIVE_LOCATION_ABOVE_RIGHTALIGN:
case RELATIVE_LOCATION_ABOVE_CENTER:
finalPosY += relativeWidgetMargin.top;
finalPosY += mg.bottom;
break;
case RELATIVE_LOCATION_BELOW_LEFTALIGN:
case RELATIVE_LOCATION_BELOW_RIGHTALIGN:
case RELATIVE_LOCATION_BELOW_CENTER:
finalPosY -= relativeWidgetMargin.bottom;
finalPosY -= mg.top;
break;
case RELATIVE_LOCATION_LEFT_OF_TOPALIGN:
case RELATIVE_LOCATION_LEFT_OF_BOTTOMALIGN:
case RELATIVE_LOCATION_LEFT_OF_CENTER:
finalPosX -= relativeWidgetMargin.left;
finalPosX -= mg.right;
break;
case RELATIVE_LOCATION_RIGHT_OF_TOPALIGN:
case RELATIVE_LOCATION_RIGHT_OF_BOTTOMALIGN:
case RELATIVE_LOCATION_RIGHT_OF_CENTER:
finalPosX += relativeWidgetMargin.right;
finalPosX += mg.left;
break;
default:
break;
}
child->setPosition(Point(finalPosX, finalPosY));
}
}
}
}
NS_CC_EXT_END

View File

@ -1,158 +0,0 @@
/****************************************************************************
Copyright (c) 2013 cocos2d-x.org
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.
****************************************************************************/
#ifndef __LAYOUTEXECUTANT_H__
#define __LAYOUTEXECUTANT_H__
#include "LayoutParameter.h"
NS_CC_EXT_BEGIN
typedef enum
{
LAYOUT_DEFAULT,
LAYOUT_LINEAR_VERTICAL,
LAYOUT_LINEAR_HORIZONTAL,
LAYOUT_RELATIVE
}LayoutType;
class Layout;
class LayoutExecutant : public Object
{
public:
/**
* Default constructor
*/
LayoutExecutant() : _layout(NULL){_layoutType = LAYOUT_DEFAULT;};
/**
* Default destructor
*/
virtual ~LayoutExecutant(){_layout = NULL;};
/**
* To do layout. Need to be overrided.
*/
virtual void doLayout()=0;
/**
* Gets LayoutType.
*
* @see LayoutType
*
* @return LayoutType
*/
LayoutType getLayoutType(){return _layoutType;};
/**
* Binding a Layout to LayoutExecutant.
*
* @param Layout
*/
void setLayout(Layout* layout);
/**
* Gets the Layout of LayoutExecutant.
*
* @return Layout
*/
Layout* getLayout() const;
protected:
LayoutType _layoutType;
Layout* _layout;
};
class LinearVerticalLayoutExecutant : public LayoutExecutant
{
public:
/**
* Default constructor
*/
LinearVerticalLayoutExecutant(){_layoutType = LAYOUT_LINEAR_VERTICAL;};
/**
* Default destructor
*/
virtual ~LinearVerticalLayoutExecutant(){};
/**
* Allocates and initializes.
* @return A initialized LayoutExecutant which is marked as "autorelease".
*/
static LinearVerticalLayoutExecutant* create();
//To do layout.
virtual void doLayout();
};
class LinearHorizontalLayoutExecutant : public LayoutExecutant
{
public:
/**
* Default constructor
*/
LinearHorizontalLayoutExecutant(){_layoutType = LAYOUT_LINEAR_HORIZONTAL;};
/**
* Default destructor
*/
virtual ~LinearHorizontalLayoutExecutant(){};
/**
* Allocates and initializes.
* @return A initialized LayoutExecutant which is marked as "autorelease".
*/
static LinearHorizontalLayoutExecutant* create();
//To do layout.
virtual void doLayout();
};
class RelativeLayoutExecutant : public LayoutExecutant
{
public:
/**
* Default constructor
*/
RelativeLayoutExecutant(){_layoutType = LAYOUT_RELATIVE;};
/**
* Default destructor
*/
virtual ~RelativeLayoutExecutant(){};
/**
* Allocates and initializes.
* @return A initialized LayoutExecutant which is marked as "autorelease".
*/
static RelativeLayoutExecutant* create();
//To do layout.
virtual void doLayout();
};
NS_CC_EXT_END
#endif /* defined(__LayoutExecutant__) */

View File

@ -51,11 +51,7 @@ void LayoutParameter::setMargin(const UIMargin &margin)
Layout* containerParent = dynamic_cast<Layout*>(parent);
if (containerParent)
{
LayoutExecutant* exe = containerParent->getLayoutExecutant();
if (exe)
{
exe->doLayout();
}
containerParent->doLayout();
}
}
}
@ -95,10 +91,9 @@ void LinearLayoutParameter::setGravity(UILinearGravity gravity)
Layout* containerParent = dynamic_cast<Layout*>(parent);
if (containerParent)
{
LayoutExecutant* exe = containerParent->getLayoutExecutant();
if (exe && (exe->getLayoutType() == LAYOUT_LINEAR_HORIZONTAL || exe->getLayoutType() == LAYOUT_LINEAR_VERTICAL))
if ((containerParent->getLayoutType() == LAYOUT_LINEAR_HORIZONTAL || containerParent->getLayoutType() == LAYOUT_LINEAR_VERTICAL))
{
exe->doLayout();
containerParent->doLayout();
}
}
}
@ -134,10 +129,9 @@ void RelativeLayoutParameter::setAlign(UIRelativeAlign align)
Layout* containerParent = dynamic_cast<Layout*>(parent);
if (containerParent)
{
LayoutExecutant* exe = containerParent->getLayoutExecutant();
if (exe && (exe->getLayoutType() == LAYOUT_RELATIVE))
if ((containerParent->getLayoutType() == LAYOUT_RELATIVE))
{
exe->doLayout();
containerParent->doLayout();
}
}
}
@ -161,10 +155,9 @@ void RelativeLayoutParameter::setRelativeToWidgetName(const char *name)
Layout* containerParent = dynamic_cast<Layout*>(parent);
if (containerParent)
{
LayoutExecutant* exe = containerParent->getLayoutExecutant();
if (exe && (exe->getLayoutType() == LAYOUT_RELATIVE))
if ((containerParent->getLayoutType() == LAYOUT_RELATIVE))
{
exe->doLayout();
containerParent->doLayout();
}
}
}
@ -188,10 +181,9 @@ void RelativeLayoutParameter::setRelativeName(const char* name)
Layout* containerParent = dynamic_cast<Layout*>(parent);
if (containerParent)
{
LayoutExecutant* exe = containerParent->getLayoutExecutant();
if (exe && (exe->getLayoutType() == LAYOUT_RELATIVE))
if ((containerParent->getLayoutType() == LAYOUT_RELATIVE))
{
exe->doLayout();
containerParent->doLayout();
}
}
}

View File

@ -45,7 +45,6 @@
#include "UIHelper.h"
#include "../../Reader/CCSGUIReader.h"
#include "UILayer.h"
#include "../Layouts/LayoutExecutant.h"
NS_CC_EXT_BEGIN
const char* CocosGUIVersion();

View File

@ -1244,6 +1244,21 @@ Layout* UIDragPanel::getInnerContainer()
return _innerContainer;
}
void UIDragPanel::setLayoutType(LayoutType type)
{
_innerContainer->setLayoutType(type);
}
LayoutType UIDragPanel::getLayoutType() const
{
return _innerContainer->getLayoutType();
}
void UIDragPanel::doLayout()
{
_innerContainer->doLayout();
}
const char* UIDragPanel::getDescription() const
{
return "DragPanel";

View File

@ -191,6 +191,26 @@ public:
*/
Layout* getInnerContainer();
/**
* Sets LayoutType.
*
* @see LayoutType
*
* @param LayoutType
*/
virtual void setLayoutType(LayoutType type);
/**
* Gets LayoutType.
*
* @see LayoutType
*
* @return LayoutType
*/
virtual LayoutType getLayoutType() const;
virtual void doLayout();
/**
* Returns the "class name" of widget.
*/

View File

@ -139,6 +139,8 @@ public:
/**/
virtual void update(float dt);
virtual void doLayout(){};
/**
* Returns the "class name" of widget.
*/

View File

@ -138,6 +138,8 @@ public:
//override "update" method of widget.
virtual void update(float dt);
virtual void doLayout(){};
/**
* Returns the "class name" of widget.

View File

@ -664,14 +664,19 @@ Layout* UIScrollView::getInnerContainer()
return _innerContainer;
}
void UIScrollView::setLayoutExecutant(LayoutExecutant *exe)
void UIScrollView::setLayoutType(LayoutType type)
{
_innerContainer->setLayoutExecutant(exe);
_innerContainer->setLayoutType(type);
}
LayoutExecutant* UIScrollView::getLayoutExecutant() const
LayoutType UIScrollView::getLayoutType() const
{
return _innerContainer->getLayoutExecutant();
return _innerContainer->getLayoutType();
}
void UIScrollView::doLayout()
{
_innerContainer->doLayout();
}
const char* UIScrollView::getDescription() const

View File

@ -135,13 +135,7 @@ public:
* Add call back function called scrollview event triggered
*/
void addEventListener(Object* target, SEL_ScrollViewEvent selector);
//override "setLayoutExecutant" method of widget.
virtual void setLayoutExecutant(LayoutExecutant* exe);
//override "getLayoutExecutant" method of widget.
virtual LayoutExecutant* getLayoutExecutant() const;
//override "addChild" method of widget.
virtual bool addChild(UIWidget* widget);
@ -171,6 +165,26 @@ public:
virtual void update(float dt);
/**
* Sets LayoutType.
*
* @see LayoutType
*
* @param LayoutType
*/
virtual void setLayoutType(LayoutType type);
/**
* Gets LayoutType.
*
* @see LayoutType
*
* @return LayoutType
*/
virtual LayoutType getLayoutType() const;
virtual void doLayout();
/**
* Returns the "class name" of widget.
*/

View File

@ -86,7 +86,6 @@ SOURCES = ../CCBReader/CCBFileLoader.cpp \
../CocoStudio/GUI/BaseClasses/UIRootWidget.cpp \
../CocoStudio/GUI/BaseClasses/UIWidget.cpp \
../CocoStudio/GUI/Layouts/Layout.cpp \
../CocoStudio/GUI/Layouts/LayoutExecutant.cpp \
../CocoStudio/GUI/Layouts/LayoutParameter.cpp \
../CocoStudio/GUI/Layouts/UILayoutDefine.cpp \
../CocoStudio/GUI/System/CocosGUI.cpp \

View File

@ -84,7 +84,6 @@ SOURCES = ../CCBReader/CCBFileLoader.cpp \
../CocoStudio/GUI/BaseClasses/UIRootWidget.cpp \
../CocoStudio/GUI/BaseClasses/UIWidget.cpp \
../CocoStudio/GUI/Layouts/Layout.cpp \
../CocoStudio/GUI/Layouts/LayoutExecutant.cpp \
../CocoStudio/GUI/Layouts/LayoutParameter.cpp \
../CocoStudio/GUI/Layouts/UILayoutDefine.cpp \
../CocoStudio/GUI/System/CocosGUI.cpp \

View File

@ -71,7 +71,6 @@ EXTENSIONS_SOURCES = ../CCBReader/CCBFileLoader.cpp \
../CocoStudio/GUI/BaseClasses/UIRootWidget.cpp \
../CocoStudio/GUI/BaseClasses/UIWidget.cpp \
../CocoStudio/GUI/Layouts/Layout.cpp \
../CocoStudio/GUI/Layouts/LayoutExecutant.cpp \
../CocoStudio/GUI/Layouts/LayoutParameter.cpp \
../CocoStudio/GUI/Layouts/UILayoutDefine.cpp \
../CocoStudio/GUI/System/CocosGUI.cpp \

View File

@ -149,7 +149,6 @@
<ClCompile Include="..\CocoStudio\GUI\BaseClasses\UIRootWidget.cpp" />
<ClCompile Include="..\CocoStudio\GUI\BaseClasses\UIWidget.cpp" />
<ClCompile Include="..\CocoStudio\GUI\Layouts\Layout.cpp" />
<ClCompile Include="..\CocoStudio\GUI\Layouts\LayoutExecutant.cpp" />
<ClCompile Include="..\CocoStudio\GUI\Layouts\LayoutParameter.cpp" />
<ClCompile Include="..\CocoStudio\GUI\Layouts\UILayoutDefine.cpp" />
<ClCompile Include="..\CocoStudio\GUI\System\CocosGUI.cpp" />
@ -284,7 +283,6 @@
<ClInclude Include="..\CocoStudio\GUI\BaseClasses\UIRootWidget.h" />
<ClInclude Include="..\CocoStudio\GUI\BaseClasses\UIWidget.h" />
<ClInclude Include="..\CocoStudio\GUI\Layouts\Layout.h" />
<ClInclude Include="..\CocoStudio\GUI\Layouts\LayoutExecutant.h" />
<ClInclude Include="..\CocoStudio\GUI\Layouts\LayoutParameter.h" />
<ClInclude Include="..\CocoStudio\GUI\Layouts\UILayoutDefine.h" />
<ClInclude Include="..\CocoStudio\GUI\System\CocosGUI.h" />

View File

@ -436,9 +436,6 @@
<ClCompile Include="..\CocoStudio\GUI\Layouts\Layout.cpp">
<Filter>CocoStudio\GUI\Layouts</Filter>
</ClCompile>
<ClCompile Include="..\CocoStudio\GUI\Layouts\LayoutExecutant.cpp">
<Filter>CocoStudio\GUI\Layouts</Filter>
</ClCompile>
<ClCompile Include="..\CocoStudio\GUI\Layouts\LayoutParameter.cpp">
<Filter>CocoStudio\GUI\Layouts</Filter>
</ClCompile>
@ -950,9 +947,6 @@
<ClInclude Include="..\CocoStudio\GUI\Layouts\Layout.h">
<Filter>CocoStudio\GUI\Layouts</Filter>
</ClInclude>
<ClInclude Include="..\CocoStudio\GUI\Layouts\LayoutExecutant.h">
<Filter>CocoStudio\GUI\Layouts</Filter>
</ClInclude>
<ClInclude Include="..\CocoStudio\GUI\Layouts\LayoutParameter.h">
<Filter>CocoStudio\GUI\Layouts</Filter>
</ClInclude>

View File

@ -362,6 +362,7 @@ bool UIPanelTest_Layout_Linear_Vertical::init()
// Create the layout
Layout* layout = Layout::create();
layout->setLayoutType(LAYOUT_LINEAR_VERTICAL);
layout->setSize(Size(280, 150));
Size backgroundSize = background->getSize();
layout->setPosition(Point((widgetSize.width - backgroundSize.width) / 2 +
@ -407,9 +408,7 @@ bool UIPanelTest_Layout_Linear_Vertical::init()
lp3->setMargin(UIMargin(0, 10, 0, 10));
LinearVerticalLayoutExecutant* exe = LinearVerticalLayoutExecutant::create();
layout->setLayoutExecutant(exe);
exe->doLayout();
layout->doLayout();
return true;
}
@ -446,6 +445,7 @@ bool UIPanelTest_Layout_Linear_Horizontal::init()
// Create the layout
Layout* layout = Layout::create();
layout->setLayoutType(LAYOUT_LINEAR_HORIZONTAL);
layout->setClippingEnabled(true);
layout->setSize(Size(280, 150));
Size backgroundSize = background->getSize();
@ -491,9 +491,7 @@ bool UIPanelTest_Layout_Linear_Horizontal::init()
lp3->setMargin(UIMargin(0, 10, 0, 10));
LinearHorizontalLayoutExecutant* exe = LinearHorizontalLayoutExecutant::create();
layout->setLayoutExecutant(exe);
exe->doLayout();
layout->doLayout();
return true;
}
@ -530,6 +528,7 @@ bool UIPanelTest_Layout_Relative::init()
// Create the layout
Layout* layout = Layout::create();
layout->setLayoutType(LAYOUT_RELATIVE);
layout->setSize(Size(280, 150));
layout->setBackGroundColorType(LAYOUT_COLOR_SOLID);
layout->setBackGroundColor(Color3B::GREEN);
@ -574,9 +573,7 @@ bool UIPanelTest_Layout_Relative::init()
rp3->setAlign(RELATIVE_ALIGN_PARENT_RIGHT);
RelativeLayoutExecutant* exe = RelativeLayoutExecutant::create();
layout->setLayoutExecutant(exe);
exe->doLayout();
layout->doLayout();
return true;
}