mirror of https://github.com/axmolengine/axmol.git
issue #2790: Menu::itemForTouch —> Menu::getItemForTouch. Array* —> ValueArray.
This commit is contained in:
parent
f01f56113c
commit
5c60f66c63
|
@ -30,7 +30,6 @@ THE SOFTWARE.
|
|||
#include "CCInteger.h"
|
||||
#include "CCEventListenerTouch.h"
|
||||
|
||||
|
||||
#include <vector>
|
||||
#include <stdarg.h>
|
||||
|
||||
|
@ -38,18 +37,6 @@ using namespace std;
|
|||
|
||||
NS_CC_BEGIN
|
||||
|
||||
static std::vector<unsigned int> ccarray_to_std_vector(Array* pArray)
|
||||
{
|
||||
std::vector<unsigned int> ret;
|
||||
Object* pObj;
|
||||
CCARRAY_FOREACH(pArray, pObj)
|
||||
{
|
||||
Integer* pInteger = static_cast<Integer*>(pObj);
|
||||
ret.push_back((unsigned int)pInteger->getValue());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
enum
|
||||
{
|
||||
kDefaultPadding = 5,
|
||||
|
@ -238,7 +225,7 @@ bool Menu::onTouchBegan(Touch* touch, Event* event)
|
|||
}
|
||||
}
|
||||
|
||||
_selectedItem = this->itemForTouch(touch);
|
||||
_selectedItem = this->getItemForTouch(touch);
|
||||
if (_selectedItem)
|
||||
{
|
||||
_state = Menu::State::TRACKING_TOUCH;
|
||||
|
@ -278,7 +265,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->itemForTouch(touch);
|
||||
MenuItem *currentItem = this->getItemForTouch(touch);
|
||||
if (currentItem != _selectedItem)
|
||||
{
|
||||
if (_selectedItem)
|
||||
|
@ -360,31 +347,29 @@ void Menu::alignItemsInColumns(int columns, ...)
|
|||
void Menu::alignItemsInColumns(int columns, va_list args)
|
||||
{
|
||||
CCASSERT(columns >= 0, "Columns must be >= 0");
|
||||
Array* rows = Array::create();
|
||||
ValueArray rows;
|
||||
while (columns)
|
||||
{
|
||||
rows->addObject(Integer::create(columns));
|
||||
rows.push_back(Value(columns));
|
||||
columns = va_arg(args, int);
|
||||
}
|
||||
alignItemsInColumnsWithArray(rows);
|
||||
}
|
||||
|
||||
void Menu::alignItemsInColumnsWithArray(Array* rowsArray)
|
||||
void Menu::alignItemsInColumnsWithArray(const ValueArray& rows)
|
||||
{
|
||||
vector<unsigned int> rows = ccarray_to_std_vector(rowsArray);
|
||||
|
||||
int height = -5;
|
||||
unsigned int row = 0;
|
||||
unsigned int rowHeight = 0;
|
||||
unsigned int columnsOccupied = 0;
|
||||
unsigned int rowColumns;
|
||||
int row = 0;
|
||||
int rowHeight = 0;
|
||||
int columnsOccupied = 0;
|
||||
int rowColumns = 0;
|
||||
|
||||
_children.forEach([&](Node* child){
|
||||
if (child)
|
||||
{
|
||||
CCASSERT(row < rows.size(), "");
|
||||
|
||||
rowColumns = rows[row];
|
||||
rowColumns = rows[row].asInt();
|
||||
// can not have zero columns on a row
|
||||
CCASSERT(rowColumns, "");
|
||||
|
||||
|
@ -422,7 +407,7 @@ void Menu::alignItemsInColumnsWithArray(Array* rowsArray)
|
|||
{
|
||||
if (rowColumns == 0)
|
||||
{
|
||||
rowColumns = rows[row];
|
||||
rowColumns = rows[row].asInt();
|
||||
w = winSize.width / (1 + rowColumns);
|
||||
x = w;
|
||||
}
|
||||
|
@ -462,28 +447,26 @@ void Menu::alignItemsInRows(int rows, ...)
|
|||
|
||||
void Menu::alignItemsInRows(int rows, va_list args)
|
||||
{
|
||||
Array* pArray = Array::create();
|
||||
ValueArray array;
|
||||
while (rows)
|
||||
{
|
||||
pArray->addObject(Integer::create(rows));
|
||||
array.push_back(Value(rows));
|
||||
rows = va_arg(args, int);
|
||||
}
|
||||
alignItemsInRowsWithArray(pArray);
|
||||
alignItemsInRowsWithArray(array);
|
||||
}
|
||||
|
||||
void Menu::alignItemsInRowsWithArray(Array* columnArray)
|
||||
void Menu::alignItemsInRowsWithArray(const ValueArray& columns)
|
||||
{
|
||||
vector<unsigned int> columns = ccarray_to_std_vector(columnArray);
|
||||
|
||||
vector<unsigned int> columnWidths;
|
||||
vector<unsigned int> columnHeights;
|
||||
vector<int> columnWidths;
|
||||
vector<int> columnHeights;
|
||||
|
||||
int width = -10;
|
||||
int columnHeight = -5;
|
||||
unsigned int column = 0;
|
||||
unsigned int columnWidth = 0;
|
||||
unsigned int rowsOccupied = 0;
|
||||
unsigned int columnRows;
|
||||
int column = 0;
|
||||
int columnWidth = 0;
|
||||
int rowsOccupied = 0;
|
||||
int columnRows;
|
||||
|
||||
_children.forEach([&](Node* child){
|
||||
if (child)
|
||||
|
@ -491,7 +474,7 @@ void Menu::alignItemsInRowsWithArray(Array* columnArray)
|
|||
// check if too many menu items for the amount of rows/columns
|
||||
CCASSERT(column < columns.size(), "");
|
||||
|
||||
columnRows = columns[column];
|
||||
columnRows = columns[column].asInt();
|
||||
// can't have zero rows on a column
|
||||
CCASSERT(columnRows, "");
|
||||
|
||||
|
@ -532,7 +515,7 @@ void Menu::alignItemsInRowsWithArray(Array* columnArray)
|
|||
{
|
||||
if (columnRows == 0)
|
||||
{
|
||||
columnRows = columns[column];
|
||||
columnRows = columns[column].asInt();
|
||||
y = (float) columnHeights[column];
|
||||
}
|
||||
|
||||
|
@ -558,7 +541,7 @@ void Menu::alignItemsInRowsWithArray(Array* columnArray)
|
|||
});
|
||||
}
|
||||
|
||||
MenuItem* Menu::itemForTouch(Touch *touch)
|
||||
MenuItem* Menu::getItemForTouch(Touch *touch)
|
||||
{
|
||||
Point touchLocation = touch->getLocation();
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@ THE SOFTWARE.
|
|||
#include "CCLayer.h"
|
||||
#include "CCVector.h"
|
||||
#include "CCEventTouch.h"
|
||||
#include "CCValue.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -91,12 +92,12 @@ public:
|
|||
/** align items in rows of columns */
|
||||
void alignItemsInColumns(int columns, ...) CC_REQUIRES_NULL_TERMINATION;
|
||||
void alignItemsInColumns(int columns, va_list args);
|
||||
void alignItemsInColumnsWithArray(Array* rows);
|
||||
void alignItemsInColumnsWithArray(const ValueArray& rows);
|
||||
|
||||
/** align items in columns of rows */
|
||||
void alignItemsInRows(int rows, ...) CC_REQUIRES_NULL_TERMINATION;
|
||||
void alignItemsInRows(int rows, va_list args);
|
||||
void alignItemsInRowsWithArray(Array* columns);
|
||||
void alignItemsInRowsWithArray(const ValueArray& columns);
|
||||
|
||||
virtual bool isEnabled() const { return _enabled; }
|
||||
virtual void setEnabled(bool value) { _enabled = value; };
|
||||
|
@ -134,7 +135,7 @@ protected:
|
|||
/** whether or not the menu will receive events */
|
||||
bool _enabled;
|
||||
|
||||
MenuItem* itemForTouch(Touch * touch);
|
||||
MenuItem* getItemForTouch(Touch * touch);
|
||||
State _state;
|
||||
MenuItem *_selectedItem;
|
||||
|
||||
|
|
Loading…
Reference in New Issue