This commit is contained in:
minggo 2011-06-22 17:00:11 +08:00
commit 71c13b34bf
15 changed files with 30 additions and 1105 deletions

View File

@ -3,7 +3,7 @@
package="org.cocos2dx.application"
android:versionCode="1"
android:versionName="1.0">
<application android:label="@string/app_name" android:debuggable="true">
<application android:label="@string/app_name" android:debuggable="true" android:icon="@drawable/icon">
<activity android:name=".ApplicationDemo"
android:label="@string/app_name"
android:screenOrientation="landscape"

View File

@ -10,13 +10,17 @@ package org.cocos2dx.application;
public final class R {
public static final class attr {
}
public static final class drawable {
public static final int icon=0x7f020000;
}
public static final class id {
public static final int helloworld_gl_surfaceview=0x7f040000;
public static final int helloworld_gl_surfaceview=0x7f050001;
public static final int textField=0x7f050000;
}
public static final class layout {
public static final int helloworld_demo=0x7f020000;
public static final int helloworld_demo=0x7f030000;
}
public static final class string {
public static final int app_name=0x7f030000;
public static final int app_name=0x7f040000;
}
}

View File

@ -2,7 +2,8 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
android:orientation="vertical" android:layout_gravity="bottom">
<EditText android:id="@+id/textField" android:layout_height="wrap_content" android:layout_weight="0" android:layout_width="fill_parent"></EditText>
<org.cocos2dx.lib.Cocos2dxGLSurfaceView
android:id="@+id/helloworld_gl_surfaceview"

View File

@ -1,13 +1,13 @@
package org.cocos2dx.application;
import org.cocos2dx.lib.Cocos2dxActivity;
import org.cocos2dx.lib.Cocos2dxGLSurfaceView;
import org.cocos2dx.application.R;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.widget.EditText;
public class ApplicationDemo extends Cocos2dxActivity{
private Cocos2dxGLSurfaceView mGLView;
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
@ -17,6 +17,7 @@ public class ApplicationDemo extends Cocos2dxActivity{
setContentView(R.layout.helloworld_demo);
mGLView = (Cocos2dxGLSurfaceView) findViewById(R.id.helloworld_gl_surfaceview);
mGLView.setTextField((EditText)findViewById(R.id.textField));
// Get the size of the mGLView after the layout happens
mGLView.post(new Runnable() {
@ -40,8 +41,6 @@ public class ApplicationDemo extends Cocos2dxActivity{
super.onResume();
mGLView.onResume();
}
private GLSurfaceView mGLView;
static {
System.loadLibrary("helloworld");

View File

@ -195,6 +195,7 @@ public class Cocos2dxGLSurfaceView extends GLSurfaceView {
linearParams.height = 0;
mTextField.setLayoutParams(linearParams);
mTextField.setOnEditorActionListener(textInputWraper);
this.requestFocus();
}
}

View File

@ -1,43 +0,0 @@
#ifndef _CONTROL_DEFINE_H_
#define _CONTROL_DEFINE_H_
namespace NdCxControl
{
typedef enum
{
PARENT_CENTER,
VERTICAL_TOP,
VERTICAL_BOTTOM,
HORIZONTAL_LEFT,
HORIZONTAL_RIGHT,
ABS_WITH_PIXEL,
ABS_WITH_PERCENT,
REF_PREV_X_INC,
REF_PREV_X_DEC,
REF_PREV_Y_INC,
REF_PREV_Y_DEC,
REL_FLOW
} LAYOUT_TYPE;
typedef struct
{
LAYOUT_TYPE t;
union
{
float pixel_val;
float percent_val;
} val;
} LayoutParamVal;
typedef struct
{
LayoutParamVal val_x;
LayoutParamVal val_y;
float padding;
bool wrap;
} LayoutParam;
}
#endif

View File

@ -1,513 +0,0 @@
#include "../effects/CCGrid.h"
#include "NdCxList.h"
namespace NdCxControl
{
#define FLOAT_EQUAL(x,y) (fabs((x)-(y)) < 0.0001f)
NdCxList::NdCxList(float row_height, ccColor4B bg_color, CCSize size)
: sel_item_(NULL)
, row_height_(row_height)
, old_y_(0.f)
, min_y_(0.f)
, max_y_(0.f)
, touch_began_y_(0.f)
, touch_ended_y_(0.f)
, snap_flag_(false)
, list_state_(LS_WAITING)
, item_click_listener_(NULL)
{
if (size.width <= 0 || size.height <= 0)
{
size = CCDirector::sharedDirector()->getWinSize();
}
initWithColorWidthHeight(bg_color, size.width, size.height);
inner_panel_ = CCLayer::node();
inner_panel_->setPosition(CCPointZero);
inner_panel_->setContentSize(size);
CCLayerColor::addChild(inner_panel_);
line_color_ = ccc3(0xBD, 0xBD, 0xBD);
sel_item_end_color_ = ccc3(0, 0xFF, 0xFF);
sel_item_start_color_ = ccc3(0xFF, 0xFF, 0);
}
NdCxList::~NdCxList(void)
{
inner_panel_->removeAllChildrenWithCleanup(true);
}
int NdCxList::addChild(NdCxListItem *item, bool scroll_to_view)
{
inner_panel_->addChild(item);
item->release();
CCArray *children = inner_panel_->getChildren();
int item_count = children->count();
if (1 == item_count)
{
item->setDrawTopLine(true);
}
CCSize panel_size = inner_panel_->getContentSize();
item->setLineColor(line_color_);
item->setSelectedColor(sel_item_start_color_, sel_item_end_color_);
item->initWithWidthHeight(panel_size.width, row_height_);
item->requestLayout();
// 计算位置item的高度可能在调用requestLayout后有所变化
float item_y_pos = 0.f;
CCSize item_size = item->getContentSize();
if (item_count > 1)
{
CCNode *last_child = (CCNode *)children->objectAtIndex(item_count - 2);
item_y_pos = last_child->getPosition().y - item_size.height;
}
else
{
item_y_pos = panel_size.height - item_size.height;
}
item->setPosition(CCPointMake(0, item_y_pos));
float total_height = 0.f;
for (int i = 0; i < (int)children->count(); ++i)
{
total_height += ((CCNode *)children->objectAtIndex(i))->getContentSize().height;
}
if (total_height > panel_size.height)
{
max_y_ = total_height - panel_size.height;
}
else
{
max_y_ = 0;
}
int rst = children->count() - 1;
if (scroll_to_view && (rst + 1) * row_height_ > panel_size.height)
{
doFitPos(max_y_);
}
return rst;
}
NdCxListItem *NdCxList::getChild(int row_index)
{
return (NdCxListItem *)inner_panel_->getChildren()->objectAtIndex(row_index);
}
void NdCxList::clear(void)
{
inner_panel_->removeAllChildrenWithCleanup(true);
sel_item_ = NULL;
old_y_ = 0.f;
min_y_ = 0.f;
max_y_ = 0.f;
touch_began_y_ = 0.f;
touch_ended_y_ = 0.f;
snap_flag_ = false;
list_state_ = LS_WAITING;
inner_panel_->setPosition(CCPointZero);
}
void NdCxList::onEnter(void)
{
setIsTouchEnabled(true);
CCLayerColor::onEnter();
}
void NdCxList::onExit(void)
{
setIsTouchEnabled(false);
CCLayerColor::onExit();
}
void NdCxList::registerWithTouchDispatcher()
{
CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this, INT_MIN+9999, false);
}
bool NdCxList::ccTouchBegan(CCTouch* touch, CCEvent* event)
{
if (!containsTouchLocation(touch) || !getIsVisible())
{
return false;
}
CCArray *children = inner_panel_->getChildren();
if (LS_WAITING != list_state_ || !m_bIsVisible || !children)
{
return false;
}
list_state_ = LS_TRACKINGTOUCH;
CCPoint touchPoint = touch->locationInView(touch->view());
old_y_ = inner_panel_->getPosition().y;
touch_began_y_ = touch_ended_y_ = CCDirector::sharedDirector()->convertToGL(touchPoint).y;
snap_flag_ = true;
NdCxListItem *sel_item = itemForTouch(touch);
if (sel_item && sel_item != sel_item_)
{
sel_item->selected();
if (sel_item_)
{
sel_item_->unselected();
}
}
sel_item_ = sel_item;
//CCTime::gettimeofdayCocos2d(&touch_began_time_, NULL);
touch_began_time_ = clock();
return true;
}
void NdCxList::doFitPos(float y_pos)
{
inner_panel_->stopAllActions();
CCMoveTo *move_to = new CCMoveTo();
move_to->initWithDuration(0.66f, CCPointMake(0, y_pos));
CCEaseExponentialOut *ease_action = new CCEaseExponentialOut();
ease_action->initWithAction(move_to);
move_to->release();
inner_panel_->runAction(ease_action);
ease_action->release();
}
void NdCxList::ccTouchEnded(CCTouch* touch, CCEvent* event)
{
if (LS_TRACKINGTOUCH != list_state_)
{
return;
}
if (sel_item_)
{
if (FLOAT_EQUAL(touch_began_y_, touch_ended_y_))
{
if (item_click_listener_)
{
item_click_listener_->onClick(
inner_panel_->getChildren()->indexOfObject(sel_item_), sel_item_);
}
#ifdef ENABLE_LUA
else if (m_scriptSeletor.size())
{
CCLuaScriptModule::sharedLuaScriptModule()->executeListItem(m_scriptSeletor,
inner_panel_->getChildren()->indexOfObject(sel_item_), sel_item_);
}
#endif
onItemClick(inner_panel_->getChildren()->indexOfObject(sel_item_), sel_item_);
}
}
// 如果超出范围,则反弹回去。
CCPoint pos = inner_panel_->getPosition();
if (FLOAT_EQUAL(min_y_, max_y_))
{
if (!FLOAT_EQUAL(pos.y, 0.f))
{
doFitPos(0.f);
}
}
else
{
if (pos.y < min_y_)
{
doFitPos(min_y_);
}
else if (pos.y > max_y_)
{
doFitPos(max_y_);
}
else
{
if (!FLOAT_EQUAL(touch_began_y_, touch_ended_y_))
{
float acce_val = 0.f;
float fit_pos = inner_panel_->getPosition().y;
float abs_distance = fabs(touch_ended_y_ - touch_began_y_);
/*cc_timeval end_time, sub_time;
CCTime::gettimeofdayCocos2d(&end_time, NULL);
CCTime::timersubCocos2d(&sub_time, &touch_began_time_, &end_time);
int time_consume = sub_time.tv_sec * 1000 + sub_time.tv_usec/1000;*/
int time_consume = clock() - touch_began_time_;
if (time_consume < 400 && abs_distance > row_height_)
{
acce_val = (abs_distance / row_height_) * 3.f * row_height_;
}
else
{
acce_val = float((int)row_height_ / 3);
}
// 向下拖拽
if (touch_began_y_ > touch_ended_y_)
{
fit_pos -= acce_val;
if (fit_pos < min_y_)
{
fit_pos = min_y_;
}
}
else
{
fit_pos += acce_val;
if (fit_pos > max_y_)
{
fit_pos = max_y_;
}
}
doFitPos(fit_pos);
}
}
}
list_state_ = LS_WAITING;
}
void NdCxList::ccTouchCancelled(CCTouch *touch, CCEvent *event)
{
list_state_ = LS_WAITING;
}
void NdCxList::ccTouchMoved(CCTouch* touch, CCEvent* event)
{
if (LS_TRACKINGTOUCH != list_state_)
{
return;
}
CCPoint touchPoint = touch->locationInView(touch->view());
touchPoint = CCDirector::sharedDirector()->convertToGL(touchPoint);
touch_ended_y_ = touchPoint.y;
if (snap_flag_ && fabs(touch_ended_y_ - touch_began_y_) < 15.f)
{
return;
}
snap_flag_ = false;
inner_panel_->setPosition(CCPointMake(inner_panel_->getPosition().x,
old_y_ + (touch_ended_y_ - touch_began_y_)));
}
void NdCxList::destroy(void)
{
release();
}
void NdCxList::keep(void)
{
retain();
}
NdCxListItem* NdCxList::itemForTouch(CCTouch * touch)
{
CCArray *children = inner_panel_->getChildren();
if (!children || !children->count())
{
return NULL;
}
CCPoint touch_loc = touch->locationInView(touch->view());
touch_loc = CCDirector::sharedDirector()->convertToGL(touch_loc);
CCPoint local_loc = inner_panel_->convertToNodeSpace(touch_loc);
for (int i = 0, l = (int)children->count(); i != l; ++i)
{
CCNode *node = (CCNode *)children->objectAtIndex(i);
if (CCRect::CCRectContainsPoint(node->boundingBox(), local_loc))
{
return (NdCxListItem*)node;
}
}
return NULL;
}
void NdCxList::selectChild(int row_index)
{
CCArray *children = inner_panel_->getChildren();
if (!children || !children->count() || row_index < 0 || row_index >= (int)children->count())
{
return;
}
NdCxListItem *sel_item = (NdCxListItem *)children->objectAtIndex(row_index);
if (sel_item != sel_item_)
{
sel_item->selected();
if (sel_item_)
{
sel_item_->unselected();
}
sel_item_ = sel_item;
CCSize panel_size = inner_panel_->getContentSize();
CCArray *children = inner_panel_->getChildren();
float inc_height = 0.f;
for (int i = 0; i <= row_index; ++i)
{
inc_height += ((CCNode *)children->objectAtIndex(i))->getContentSize().height;
}
if (inc_height > panel_size.height)
{
doFitPos(inc_height - panel_size.height);
}
}
}
NdCxListItem *NdCxList::getSelectedChild(void)
{
return sel_item_;
}
void NdCxList::setLineColor(ccColor3B &color)
{
line_color_ = color;
}
void NdCxList::setSelectedItemColor(ccColor3B &start_color, ccColor3B &end_color)
{
sel_item_start_color_ = start_color;
sel_item_end_color_ = end_color;
}
int NdCxList::getChildCount(void)
{
CCArray *children = inner_panel_->getChildren();
if (!children)
{
return 0;
}
else
{
return children->count();
}
}
void NdCxList::setRowHeight(float height)
{
row_height_ = height;
}
float NdCxList::getRowHeight(void)
{
return row_height_;
}
void NdCxList::registerItemClickListener(NdCxListItemClickListener *listener)
{
item_click_listener_ = listener;
}
void NdCxList::unregisterItemClickListener(void)
{
item_click_listener_ = NULL;
#ifdef ENABLE_LUA
m_scriptSeletor.clear();
#endif
}
#ifdef ENABLE_LUA
void NdCxList::registerItemClickListener(const char* szSeletor)
{
if (szSeletor)
{
m_scriptSeletor = szSeletor;
}
else
{
CCLog("registerItemClickListener Error szSelector == null");
}
}
#endif
void NdCxList::visit(void)
{
// quick return if not visible
if (!m_bIsVisible)
{
return;
}
glPushMatrix();
/*if (m_pGrid && m_pGrid->isActive())
{
m_pGrid->beforeDraw();
this->transformAncestors();
}*/
this->transform();
CCNode* pNode = NULL;
unsigned int i = 0;
if(m_pChildren && m_pChildren->count() > 0)
{
// draw children zOrder < 0
ccArray *arrayData = m_pChildren->data;
for( ; i < arrayData->num; i++ )
{
pNode = (CCNode*) arrayData->arr[i];
if ( pNode && pNode->getZOrder() < 0 )
{
pNode->visit();
}
else
{
break;
}
}
}
// self draw
this->draw();
// 左下角世界坐标
CCPoint world_pt = convertToWorldSpace(CCPointZero);
CCPoint ui_pt = CCDirector::sharedDirector()->convertToUI(world_pt);
CCPoint gl_pt = CCDirector::sharedDirector()->convertToGL(ui_pt);
glEnable(GL_SCISSOR_TEST);
glScissor((GLsizei)gl_pt.x, (GLsizei)gl_pt.y, (GLsizei)m_tContentSize.width, (GLsizei)m_tContentSize.height);
// draw children zOrder >= 0
if (m_pChildren && m_pChildren->count() > 0)
{
ccArray *arrayData = m_pChildren->data;
for( ; i < arrayData->num; i++ )
{
pNode = (CCNode*) arrayData->arr[i];
if (pNode)
{
pNode->visit();
}
}
}
glDisable(GL_SCISSOR_TEST);
glPopMatrix();
}
}

View File

@ -1,109 +0,0 @@
#ifndef __NDCX_LIST_H__
#define __NDCX_LIST_H__
#include <time.h>
#include "../platform/platform.h"
#include "NdCxListItem.h"
#include <vector>
using namespace cocos2d;
namespace NdCxControl
{
class NdCxListItem;
typedef enum
{
LS_WAITING,
LS_TRACKINGTOUCH,
} LIST_STATE;
struct NdCxListItemClickListener
{
virtual void onClick(int index, NdCxListItem *item) = 0;
};
class NdCxList : public CCLayerColor
{
public:
NdCxList(float row_height,
ccColor4B bg_color,
CCSize size);
virtual ~NdCxList(void);
public:
int addChild(NdCxListItem *item, bool scroll_to_view);
NdCxListItem *getChild(int row_index);
void clear(void);
void selectChild(int row_index);
NdCxListItem *getSelectedChild(void);
void setLineColor(ccColor3B &color);
void setSelectedItemColor(ccColor3B &start_color, ccColor3B &end_color);
int getChildCount(void);
// ±ØÐëÔÚÌí¼Óitem֮ǰµ÷ÓÃ
void setRowHeight(float height);
float getRowHeight(void);
public:
virtual void onEnter(void);
virtual void onExit(void);
virtual void registerWithTouchDispatcher(void);
virtual bool ccTouchBegan(CCTouch* touch, CCEvent* event);
virtual void ccTouchEnded(CCTouch* touch, CCEvent* event);
virtual void ccTouchCancelled(CCTouch *touch, CCEvent* event);
virtual void ccTouchMoved(CCTouch* touch, CCEvent* event);
virtual void destroy(void);
virtual void keep(void);
virtual void registerItemClickListener(NdCxListItemClickListener *listener);
virtual void unregisterItemClickListener(void);
#ifdef ENABLE_LUA
virtual void registerItemClickListener(const char* szSeletor);
#endif
protected:
virtual void onItemClick(int index, NdCxListItem *item) {}
virtual void visit(void);
private:
NdCxListItem *itemForTouch(CCTouch * touch);
void doLayout(void);
void doFitPos(float y_pos);
CCRect rect(void)
{
CCSize s = getContentSize();
return CCRectMake(-s.width / 2, -s.height / 2, s.width, s.height);
}
bool containsTouchLocation(CCTouch* touch)
{
return CCRect::CCRectContainsPoint(rect(), convertTouchToNodeSpaceAR(touch));
}
private:
NdCxListItem *sel_item_;
float row_height_;
LIST_STATE list_state_;
CCLayer *inner_panel_;
float touch_began_y_;
float touch_ended_y_;
float old_y_;
float min_y_;
float max_y_;
bool snap_flag_;
//cc_timeval touch_began_time_;
clock_t touch_began_time_;
ccColor3B line_color_;
ccColor3B sel_item_start_color_;
ccColor3B sel_item_end_color_;
NdCxListItemClickListener *item_click_listener_;
#ifdef ENABLE_LUA
std::string m_scriptSeletor;
#endif
};
}
#endif

View File

@ -1,363 +0,0 @@
#include "NdCxListItem.h"
namespace NdCxControl
{
NdCxListItem::NdCxListItem(void)
: selected_(false)
, draw_top_line_(false)
, draw_bottom_line_(true)
, horizontal_margin_(10.f)
, vertical_margin_(10.f)
{
}
NdCxListItem::~NdCxListItem(void)
{
}
void NdCxListItem::updateColor(void)
{
const unsigned int l = sizeof(m_pSquareColors) / sizeof(m_pSquareColors[0]);
if (selected_)
{
ccColor3B color = sel_item_start_color_;
const unsigned int half = l / 2;
for (unsigned int i=0; i < l; ++i)
{
if (i >= half)
{
color = sel_item_end_color_;
}
if (i % 4 == 0)
m_pSquareColors[i] = color.r;
else if (i % 4 == 1)
m_pSquareColors[i] = color.g;
else if (i % 4 ==2)
m_pSquareColors[i] = color.b;
else
m_pSquareColors[i] = m_cOpacity;
}
}
else
{
for( unsigned int i=0; i < 4; i++ )
{
m_pSquareColors[i * 4] = m_tColor.r;
m_pSquareColors[i * 4 + 1] = m_tColor.g;
m_pSquareColors[i * 4 + 2] = m_tColor.b;
m_pSquareColors[i * 4 + 3] = m_cOpacity;
}
}
}
void NdCxListItem::draw(void)
{
updateColor();
CCSize size = getContentSize();
if (selected_)
{
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisable(GL_TEXTURE_2D);
glShadeModel(GL_SMOOTH);
glVertexPointer(2, GL_FLOAT, 0, m_pSquareVertices);
glColorPointer(4, GL_UNSIGNED_BYTE, 0, m_pSquareColors);
bool newBlend = false;
if( m_tBlendFunc.src != CC_BLEND_SRC || m_tBlendFunc.dst != CC_BLEND_DST ) {
newBlend = true;
glBlendFunc(m_tBlendFunc.src, m_tBlendFunc.dst);
}
else if( m_cOpacity != 255 ) {
newBlend = true;
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
if( newBlend )
glBlendFunc(CC_BLEND_SRC, CC_BLEND_DST);
// restore default GL state
glShadeModel(GL_FLAT);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnable(GL_TEXTURE_2D);
}
else
{
CCLayerColor::draw();
}
glDisable(GL_LINE_SMOOTH);
if (draw_top_line_)
{
glLineWidth(1.0f);
glColor4ub(line_color_.r, line_color_.g, line_color_.b, 0xFF);
ccDrawLine(CCPointMake(0, size.height-0.5f), CCPointMake(size.width, size.height-0.5f));
}
if (draw_bottom_line_)
{
glLineWidth(1.0f);
glColor4ub(line_color_.r, line_color_.g, line_color_.b, 0xFF);
ccDrawLine(CCPointMake(0, 0.5f), CCPointMake(size.width, 0.5f));
}
}
CCRect NdCxListItem::rect(void)
{
return CCRectMake( m_tPosition.x - m_tContentSize.width * m_tAnchorPoint.x,
m_tPosition.y - m_tContentSize.height * m_tAnchorPoint.y,
m_tContentSize.width, m_tContentSize.height);
}
void NdCxListItem::selected(void)
{
selected_ = true;
}
void NdCxListItem::unselected(void)
{
selected_ = false;
}
void NdCxListItem::setItemColor(const ccColor3B &color)
{
setColor(color);
}
void NdCxListItem::setMargin(CCSize margin)
{
horizontal_margin_ = margin.width;
vertical_margin_ = margin.height;
}
CCSize NdCxListItem::getMargin(void)
{
return CCSizeMake(horizontal_margin_, vertical_margin_);
}
void NdCxListItem::addChild(NdCxListItemChild *child, const LayoutParam &layout)
{
addChild(child, layout, 0);
}
void NdCxListItem::addChild(NdCxListItemChild *child, const LayoutParam &layout, int tag)
{
layout_info_.insert(std::make_pair(child, layout));
child->setIsRelativeAnchorPoint(false);
CCLayerColor::addChild(child, 0, tag);
child->release();
}
NdCxListItemChild *NdCxListItem::getChildByTag(int tag)
{
return (NdCxListItemChild *)CCLayerColor::getChildByTag(tag);
}
void NdCxListItem::requestLayout(void)
{
if (m_pChildren && m_pChildren->count() > 0)
{
CCPoint child_pos;
CCSize size = getContentSize();
CCPoint curr_pos;
CCPoint prev_pos;
float vertical_height = size.height;
bool height_changed = false;
for (int i = 0, l = m_pChildren->count(); i < l; ++i)
{
CCNode *it = (CCNode *)m_pChildren->objectAtIndex(i);
if (!(it))
{
break;
}
CCSize child_size = (*(it)).getContentSize();
child_size.width *= (*(it)).getScaleX();
child_size.height *= (*(it)).getScaleY();
std::map<CCNode *, LayoutParam>::iterator pos = layout_info_.find(it);
CCAssert(layout_info_.end() != pos, "!!");
LayoutParam *lp = &pos->second;
switch ((*lp).val_x.t)
{
case PARENT_CENTER:
child_pos.x = (size.width - child_size.width) / 2;
break;
case HORIZONTAL_LEFT:
child_pos.x = horizontal_margin_;
break;
case HORIZONTAL_RIGHT:
child_pos.x = size.width - child_size.width - horizontal_margin_;
break;
case ABS_WITH_PIXEL:
child_pos.x = (float)(*lp).val_x.val.pixel_val;
break;
case ABS_WITH_PERCENT:
child_pos.x = horizontal_margin_ + (*lp).val_x.val.percent_val * (size.width - 2*horizontal_margin_);
break;
case REF_PREV_X_INC:
{
child_pos.x = prev_pos.x + (*lp).padding;
break;
}
case REF_PREV_X_DEC:
{
child_pos.x = prev_pos.x - (*lp).padding;
break;
}
case REL_FLOW:
child_pos.x = curr_pos.x + (*lp).padding;
break;
}
if (!(*lp).wrap)
{
curr_pos.x = child_pos.x + child_size.width;
}
switch ((*lp).val_y.t)
{
case PARENT_CENTER:
{
if (child_size.height > vertical_height - 2*vertical_margin_)
{
vertical_height += child_size.height - (vertical_height - 2*vertical_margin_);
height_changed = true;
}
child_pos.y = (vertical_height - child_size.height)*0.5f;
break;
}
case VERTICAL_TOP:
{
if (child_size.height > vertical_height - 2*vertical_margin_)
{
vertical_height += child_size.height - (vertical_height - 2*vertical_margin_);
height_changed = true;
}
child_pos.y = vertical_height - (child_size.height + vertical_margin_);
break;
}
case VERTICAL_BOTTOM:
{
if (child_size.height > vertical_height - 2*vertical_margin_)
{
vertical_height += child_size.height - (vertical_height - 2*vertical_margin_);
height_changed = true;
}
child_pos.y = vertical_margin_;
break;
}
case ABS_WITH_PIXEL:
{
child_pos.y = (float)(*lp).val_y.val.pixel_val;
if (child_pos.y + child_size.height > vertical_height - vertical_margin_)
{
vertical_height = child_pos.y + child_size.height + vertical_margin_;
height_changed = true;
}
break;
}
case ABS_WITH_PERCENT:
{
child_pos.y = (*lp).val_y.val.percent_val * (vertical_height - 2*vertical_margin_);
if (child_pos.y + child_size.height > vertical_height - vertical_margin_)
{
vertical_height = child_pos.y + child_size.height + vertical_margin_;
height_changed = true;
}
break;
}
case REF_PREV_Y_INC:
{
child_pos.y = prev_pos.y + (*lp).padding;
if (child_pos.y + child_size.height > + vertical_height - vertical_margin_)
{
vertical_height = child_pos.y + child_size.height + vertical_margin_;
height_changed = true;
}
break;
}
case REF_PREV_Y_DEC:
{
child_pos.y = prev_pos.y - (child_size.height + (*lp).padding);
if (child_pos.y < vertical_margin_)
{
vertical_height += vertical_margin_-child_pos.y + vertical_margin_;
child_pos.y = vertical_margin_;
height_changed = true;
}
break;
}
case REL_FLOW:
{
child_pos.y = curr_pos.y + (*lp).padding;
if (child_pos.y + child_size.height > vertical_height - vertical_margin_)
{
vertical_height = curr_pos.y + child_size.height + vertical_margin_;
height_changed = true;
}
break;
}
curr_pos.y = child_pos.y + child_size.height;
}
prev_pos = child_pos;
(*it).setPosition(child_pos);
}
setContentSize(CCSizeMake(size.width, vertical_height));
if (height_changed)
{
requestLayout();
}
}
}
NdCxListItem *NdCxListItem::itemWithColor(const ccColor3B &color)
{
NdCxListItem *pRet = new NdCxListItem();
pRet->setOpacity(255);
pRet->setColor(color);
return pRet;
}
bool NdCxListItem::initWithWidthHeight(GLfloat width, GLfloat height)
{
ccColor3B color = getColor();
ccColor4B cl4b = { color.r, color.g, color.b, getOpacity() };
return CCLayerColor::initWithColorWidthHeight(cl4b, width, height);
}
void NdCxListItem::setLineColor(const ccColor3B &color)
{
line_color_ = color;
}
void NdCxListItem::setSelectedColor(const ccColor3B &start_color, const ccColor3B &end_color)
{
sel_item_start_color_ = start_color;
sel_item_end_color_ = end_color;
}
}

View File

@ -1,60 +0,0 @@
#ifndef __NDCX_LIST_ITEM_H_
#define __NDCX_LIST_ITEM_H_
#include "ControlDefine.h"
#include "cocos2d.h"
using namespace cocos2d;
namespace NdCxControl {
#define NdCxListItemChild CCNode
class NdCxListItem : public CCLayerColor
{
friend class NdCxList;
protected:
NdCxListItem(void);
virtual ~NdCxListItem(void);
public:
static NdCxListItem *itemWithColor(const ccColor3B &color);
CCRect rect(void);
void selected(void);
void unselected(void);
void setItemColor(const ccColor3B &color);
void setMargin(CCSize margin);
CCSize getMargin(void);
public:
void addChild(NdCxListItemChild *child, const LayoutParam &layout);
void addChild(NdCxListItemChild *child, const LayoutParam &layout, int tag);
NdCxListItemChild *getChildByTag(int tag);
void setDrawTopLine(bool value) { draw_top_line_ = value; }
void setDrawBottomLine(bool value) { draw_bottom_line_ = value; }
protected:
bool initWithWidthHeight(GLfloat width, GLfloat height);
void requestLayout(void);
void setLineColor(const ccColor3B &color);
void setSelectedColor(const ccColor3B &start_color, const ccColor3B &end_color);
void updateColor(void);
virtual void draw(void);
private:
bool selected_;
ccColor3B line_color_;
ccColor3B sel_item_start_color_;
ccColor3B sel_item_end_color_;
bool draw_top_line_;
bool draw_bottom_line_;
std::map<CCNode *, LayoutParam> layout_info_;
float horizontal_margin_;
float vertical_margin_;
};
}
#endif

View File

@ -3,8 +3,7 @@
package="org.cocos2dx.tests"
android:versionCode="1"
android:versionName="1.0">
<application android:label="@string/app_name"
android:debuggable="true">
<application android:label="@string/app_name" android:debuggable="true" android:icon="@drawable/icon">
<activity android:name=".TestsDemo"
android:label="@string/app_name"
android:screenOrientation="landscape"

View File

@ -10,14 +10,17 @@ package org.cocos2dx.tests;
public final class R {
public static final class attr {
}
public static final class drawable {
public static final int icon=0x7f020000;
}
public static final class id {
public static final int test_demo_gl_surfaceview=0x7f040001;
public static final int textField=0x7f040000;
public static final int test_demo_gl_surfaceview=0x7f050001;
public static final int textField=0x7f050000;
}
public static final class layout {
public static final int test_demo=0x7f020000;
public static final int test_demo=0x7f030000;
}
public static final class string {
public static final int app_name=0x7f030000;
public static final int app_name=0x7f040000;
}
}

View File

@ -94,6 +94,11 @@ public class Cocos2dxActivity extends Activity{
};
}
public static String getCurrentLanguage() {
String languageName = java.util.Locale.getDefault().getLanguage();
return languageName;
}
public static void showMessageBox(String title, String message){
Message msg = new Message();
msg.what = HANDLER_SHOW_DIALOG;

View File

@ -195,6 +195,7 @@ public class Cocos2dxGLSurfaceView extends GLSurfaceView {
linearParams.height = 0;
mTextField.setLayoutParams(linearParams);
mTextField.setOnEditorActionListener(textInputWraper);
this.requestFocus();
}
}

View File

@ -1 +1 @@
48f35704d729bc41b654ea769f25ab616fd74e2c
c5fe5c3cfe6e071c8107a4694e285fa651fae4b9