private bool touchBegan(CCMenuItem touchedItem) { if (_state != kCCMenuState.Waiting || !_visible || !_enabled) { return(false); } for (CCNode c = this.parent; c != null; c = c.parent) { if (c.visible == false) { return(false); } } _selectedItem = touchedItem; if (_selectedItem != null) { _selectedItem.selected(); _state = kCCMenuState.TrackingTouch; return(true); } return(false); }
/** align items vertically with padding * @since v0.7.2 */ public void alignItemsVerticallyWithPadding(float padding) { float height = -padding; var enumerator = _children.GetEnumerator(); while (enumerator.MoveNext()) { CCNode child = enumerator.Current; CCMenuItem item = child as CCMenuItem; if (item != null) { height += item.contentSize.y * item.scaleY + padding; } } float y = height / 2.0f; enumerator = _children.GetEnumerator(); while (enumerator.MoveNext()) { CCNode child = enumerator.Current; CCMenuItem item = child as CCMenuItem; if (item != null) { Vector2 itemSize = item.contentSize; item.position = new Vector2(0, y - itemSize.y * item.scaleY / 2.0f); y -= itemSize.y * item.scaleY + padding; } } }
public override bool ccMouseDown(NSEvent theEvent) { Vector2 touchLocation = theEvent.mouseLocation; CCMenuItem touchedItem = itemForTouch(touchLocation); return(touchBegan(touchedItem)); }
/** align items horizontally with padding * @since v0.7.2 */ public void alignItemsHorizontallyWithPadding(float padding) { float width = -padding; var enumerator = _children.GetEnumerator(); while (enumerator.MoveNext()) { CCNode child = enumerator.Current; CCMenuItem item = child as CCMenuItem; if (item != null) { width += item.contentSize.x * item.scaleX + padding; } } float x = -width / 2.0f; enumerator = _children.GetEnumerator(); while (enumerator.MoveNext()) { CCNode child = enumerator.Current; CCMenuItem item = child as CCMenuItem; if (item != null) { Vector2 itemSize = item.contentSize; item.position = new Vector2(x + itemSize.x * item.scaleX / 2.0f, 0); x += itemSize.x * item.scaleX + padding; } } }
protected virtual void initWithArray(List<CCMenuItem> arrayOfItems){ this.touchPriority = kCCMenuHandlerPriority; this.touchMode = kCCTouchesMode.OneByOne; this.isTouchEnabled = true; _enabled = true; // by default, menu in the center of the screen Vector2 s = CCDirector.sharedDirector.winSize; this.ignoreAnchorPointForPosition = true; _anchorPoint = new Vector2(0.5f, 0.5f); this.contentSize = s; this.position = s / 2; int z=0; if(arrayOfItems!=null){ var enumerator = arrayOfItems.GetEnumerator(); while (enumerator.MoveNext()) { CCMenuItem item = enumerator.Current; addChild(item, z); z++; } } _selectedItem = null; _state = kCCMenuState.Waiting; // enable cascade color and opacity on menus this.cascadeColorEnabled = true; this.cascadeOpacityEnabled = true; }
public override void ccTouchMoved(UITouch touch) { Vector2 touchLocation = touch.location; CCMenuItem touchedItem = itemForTouch(touchLocation); touchMoved(touchedItem); }
public override bool ccTouchBegan(UITouch touch) { Vector2 touchLocation = touch.location; CCMenuItem touchedItem = itemForTouch(touchLocation); return(touchBegan(touchedItem)); }
public override bool ccMouseDragged(NSEvent theEvent) { Vector2 touchLocation = theEvent.mouseLocation; CCMenuItem touchedItem = itemForTouch(touchLocation); touchMoved(touchedItem); return(false); }
public override void onExit() { if (_state == kCCMenuState.TrackingTouch) { _selectedItem.unselected(); _state = kCCMenuState.Waiting; _selectedItem = null; } base.onExit(); }
void initWithItems(CCMenuItem[] arrayOfItems, CCMenuItemDelegate block) { base.initWithBlock(block); this.subItems = new List <CCMenuItem>(new List <CCMenuItem>(arrayOfItems)); _currentItem = null; _selectedIndex = int.MaxValue; this.selectedIndex = 0; this.cascadeColorEnabled = true; this.cascadeOpacityEnabled = true; }
void initWithItems(CCMenuItem[] arrayOfItems, CCMenuItemDelegate block) { base.initWithBlock (block); this.subItems = new List<CCMenuItem>(new List<CCMenuItem>(arrayOfItems)); _currentItem = null; _selectedIndex = int.MaxValue; this.selectedIndex = 0; this.cascadeColorEnabled = true; this.cascadeOpacityEnabled = true; }
private void touchMoved(CCMenuItem touchedItem) { // NSUtils.Assert(_state == kCCMenuState.TrackingTouch, "[Menu ccTouchMoved] -- invalid state"); if (_state != kCCMenuState.TrackingTouch) { return; } if (touchedItem != _selectedItem) { _selectedItem.unselected(); _selectedItem = touchedItem; _selectedItem.selected(); } }
protected virtual void initWithArray(List <CCMenuItem> arrayOfItems) { this.nameInHierarchy = "menu"; this.touchPriority = kCCMenuHandlerPriority; this.touchMode = kCCTouchesMode.OneByOne; this.isTouchEnabled = true; this.isMouseEnabled = true; this.mousePriority = this.touchPriority; _enabled = true; // by default, menu in the center of the screen Vector2 s = CCDirector.sharedDirector.winSize; this.ignoreAnchorPointForPosition = true; _anchorPoint = new Vector2(0.5f, 0.5f); this.contentSize = s; this.position = s / 2; int z = 0; if (arrayOfItems != null) { var enumerator = arrayOfItems.GetEnumerator(); while (enumerator.MoveNext()) { CCMenuItem item = enumerator.Current; addChild(item, z); z++; } } _selectedItem = null; _state = kCCMenuState.Waiting; // enable cascade color and opacity on menus this.cascadeColorEnabled = true; this.cascadeOpacityEnabled = true; }
CCMenuItem itemForTouch(Vector2 touchLocation) { // touchLocation = CCDirector.sharedDirector.convertToGL(touchLocation); var enumerator = _children.GetEnumerator(); while (enumerator.MoveNext()) { CCMenuItem item = (CCMenuItem)enumerator.Current; // ignore invisible and disabled items: issue #779, #866 if (item.visible && item.isEnabled) { Vector2 local = item.convertToNodeSpace(touchLocation); Rect r = item.activeArea; if (r.Contains(local)) { return(item); } } } return(null); }
public override bool ccTouchBegan (UITouch touch) { if( _state != kCCMenuState.Waiting || !_visible || ! _enabled) return false; for( CCNode c = this.parent; c != null; c = c.parent ) if( c.visible == false ) return false; _selectedItem = itemForTouch(touch); if( _selectedItem!=null ) { _selectedItem.selected(); _state = kCCMenuState.TrackingTouch; return true; } return false; }
void alignItemsInRowsWithArray(int[] columns) { List <int> columnWidths = new List <int> (); List <int> columnHeights = new List <int> (); int width = -10, columnHeight = -5; int column = 0, columnWidth = 0, rowsOccupied = 0, columnRows; var enumerator = _children.GetEnumerator(); while (enumerator.MoveNext()) { CCMenuItem item = (CCMenuItem)enumerator.Current; NSUtils.Assert(column < columns.Length, "Too many menu items for the amount of rows/columns."); columnRows = columns[column]; NSUtils.Assert(columnRows != 0, "Can't have zero rows on a column"); Vector2 itemSize = item.contentSize; columnWidth = Mathf.RoundToInt(Mathf.Max(columnWidth, itemSize.x)); columnHeight += Mathf.RoundToInt(itemSize.y + 5); ++rowsOccupied; if (rowsOccupied >= columnRows) { columnWidths.Add(columnWidth); columnHeights.Add(columnHeight); width += columnWidth + 10; rowsOccupied = 0; columnWidth = 0; columnHeight = -5; ++column; } } NSUtils.Assert(rowsOccupied == 0, "Too many rows/columns for available menu items."); Vector2 winSize = CCDirector.sharedDirector.winSize; column = 0; columnWidth = 0; columnRows = 0; float x = -width / 2, y = 0; enumerator = _children.GetEnumerator(); while (enumerator.MoveNext()) { CCMenuItem item = (CCMenuItem)enumerator.Current; if (columnRows == 0) { columnRows = columns[column]; y = (columnHeights[column] + winSize.y) / 2; } Vector2 itemSize = item.contentSize; columnWidth = Mathf.RoundToInt(Mathf.Max(columnWidth, itemSize.x)); item.position = new Vector2(x + columnWidths[column] / 2, y - winSize.y / 2); y -= itemSize.y + 10; ++rowsOccupied; if (rowsOccupied >= columnRows) { x += columnWidth + 5; rowsOccupied = 0; columnRows = 0; columnWidth = 0; ++column; } } }
public void alignItemsInColumnsWithArray(int[] rows) { int height = -5; int row = 0, rowHeight = 0, columnsOccupied = 0, rowColumns; var enumerator = _children.GetEnumerator(); while (enumerator.MoveNext()) { CCMenuItem item = (CCMenuItem)enumerator.Current; NSUtils.Assert(row < rows.Length, "Too many menu items for the amount of rows/columns."); rowColumns = rows[row]; NSUtils.Assert(rowColumns != 0, "Can't have zero columns on a row"); rowHeight = Mathf.RoundToInt(Mathf.Max(rowHeight, item.contentSize.y)); ++columnsOccupied; if (columnsOccupied >= rowColumns) { height += rowHeight + 5; columnsOccupied = 0; rowHeight = 0; ++row; } } NSUtils.Assert(columnsOccupied == 0, "Too many rows/columns for available menu items."); Vector2 winSize = CCDirector.sharedDirector.winSize; row = 0; rowHeight = 0; rowColumns = 0; float w = 0, x = 0, y = height / 2; enumerator = _children.GetEnumerator(); while (enumerator.MoveNext()) { CCMenuItem item = (CCMenuItem)enumerator.Current; if (rowColumns == 0) { rowColumns = rows[row]; w = winSize.x / (1 + rowColumns); x = w; } Vector2 itemSize = item.contentSize; rowHeight = Mathf.RoundToInt(Mathf.Max(rowHeight, itemSize.y)); item.position = new Vector2(x - winSize.x / 2, y - itemSize.y / 2); x += w; ++columnsOccupied; if (columnsOccupied >= rowColumns) { y -= rowHeight + 5; columnsOccupied = 0; rowColumns = 0; rowHeight = 0; ++row; } } }
public override void onExit () { if(_state == kCCMenuState.TrackingTouch) { _selectedItem.unselected(); _state = kCCMenuState.Waiting; _selectedItem = null; } base.onExit (); }
public override void ccTouchMoved (UITouch touch) { NSUtils.Assert(_state == kCCMenuState.TrackingTouch, "[Menu ccTouchMoved] -- invalid state"); CCMenuItem currentItem = itemForTouch(touch); if (currentItem != _selectedItem) { _selectedItem.unselected(); _selectedItem = currentItem; _selectedItem.selected(); } }