TreeViewItem* TreeView::getInsertPosition (int& x, int& y, int& insertIndex, const StringArray& files, const String& sourceDescription, Component* sourceComponent) const throw() { insertIndex = 0; TreeViewItem* item = getItemAt (y); if (item == 0) return 0; Rectangle<int> itemPos (item->getItemPosition (true)); insertIndex = item->getIndexInParent(); const int oldY = y; y = itemPos.getY(); if (item->getNumSubItems() == 0 || ! item->isOpen()) { if (files.size() > 0 ? item->isInterestedInFileDrag (files) : item->isInterestedInDragSource (sourceDescription, sourceComponent)) { // Check if we're trying to drag into an empty group item.. if (oldY > itemPos.getY() + itemPos.getHeight() / 4 && oldY < itemPos.getBottom() - itemPos.getHeight() / 4) { insertIndex = 0; x = itemPos.getX() + getIndentSize(); y = itemPos.getBottom(); return item; } } } if (oldY > itemPos.getCentreY()) { y += item->getItemHeight(); while (item->isLastOfSiblings() && item->parentItem != 0 && item->parentItem->parentItem != 0) { if (x > itemPos.getX()) break; item = item->parentItem; itemPos = item->getItemPosition (true); insertIndex = item->getIndexInParent(); } ++insertIndex; } x = itemPos.getX(); return item->parentItem; }
bool comboUC::setItemIndex(controlUC* pControl, int iIndex) { int iOrginIndex = getItemIndex(pControl); if( iOrginIndex == -1 ) return false; if( iOrginIndex == iIndex ) return true; IListItemUC* pSelectedListItem = NULL; if( m_iCurSel >= 0 ) pSelectedListItem = static_cast<IListItemUC*>(getItemAt(m_iCurSel)->getInterface(L"IListItem")); if( !containerUC::setItemIndex(pControl, iIndex) ) return false; int iMinIndex = min(iOrginIndex, iIndex); int iMaxIndex = max(iOrginIndex, iIndex); for(int i = iMinIndex; i < iMaxIndex + 1; ++i) { controlUC* p = getItemAt(i); IListItemUC* pListItem = static_cast<IListItemUC*>(p->getInterface(L"IListItem")); if( pListItem != NULL ) { pListItem->setIndex(i); } } if( m_iCurSel >= 0 && pSelectedListItem != NULL ) m_iCurSel = pSelectedListItem->getIndex(); return true; }
void insertItemAt(int idx, char content[]) { item* pItem = getNewItem(content); if(idx <= 0){ pItem->next = first; first->prev = pItem; first = pItem; return; } if(idx >= dequeueSize()){ addItem(content); return; } item* pBefore = getItemAt(idx-1); item* pAfter = getItemAt(idx); pBefore->next = pItem; pItem->prev = pBefore; pItem->next = pAfter; pAfter->prev = pItem; };
bool comboUC::removeAt(int iIndex) { if (!containerUC::removeAt(iIndex)) return false; for(int i = iIndex; i < getCount(); ++i) { controlUC* p = getItemAt(i); IListItemUC* pListItem = static_cast<IListItemUC*>(p->getInterface(L"IListItem")); if( pListItem != NULL ) pListItem->setIndex(i); } if( iIndex == m_iCurSel && m_iCurSel >= 0 ) { int iSel = m_iCurSel; m_iCurSel = -1; selectItem(findSelectable(iSel, false)); } else if( iIndex < m_iCurSel ) m_iCurSel -= 1; return true; }
void MenuBarComponent::mouseMove (const MouseEvent& e) { const MouseEvent e2 (e.getEventRelativeTo (this)); if (lastMousePos != e2.getPosition()) { if (currentPopupIndex >= 0) { const int item = getItemAt (e2.getPosition()); if (item >= 0) showMenu (item); } else { updateItemUnderMouse (e2.getPosition()); } lastMousePos = e2.getPosition(); } }
bool comboUC::addAt(controlUC* pControl, int iIndex) { if (!containerUC::addAt(pControl, iIndex)) return false; // The list items should know about us IListItemUC* pListItem = static_cast<IListItemUC*>(pControl->getInterface(L"IListItem")); if( pListItem != NULL ) { pListItem->setOwner(this); pListItem->setIndex(iIndex); } for(int i = iIndex + 1; i < getCount(); ++i) { controlUC* p = getItemAt(i); pListItem = static_cast<IListItemUC*>(p->getInterface(L"IListItem")); if( pListItem != NULL ) { pListItem->setIndex(i); } } if( m_iCurSel >= iIndex ) m_iCurSel += 1; return true; }
void MenuBarComponent::mouseMove (const MouseEvent& e) { const MouseEvent e2 (e.getEventRelativeTo (this)); if (lastMouseX != e2.x || lastMouseY != e2.y) { if (currentPopupIndex >= 0) { const int item = getItemAt (e2.x, e2.y); if (item >= 0) showMenu (item); } else { updateItemUnderMouse (e2.x, e2.y); } lastMouseX = e2.x; lastMouseY = e2.y; } }
InventoryItem* Inventory::findFirstBlockingItem( size_t inventoryPosX, size_t inventoryPosY, size_t itemSizeX, size_t itemSizeY ) { size_t inventoryMaxX = inventoryPosX + itemSizeX - 1; size_t inventoryMaxY = inventoryPosY + itemSizeY - 1; assert( (inventoryMaxX < sizeX) && (inventoryMaxY < sizeY) ); for( size_t curX=inventoryPosX; curX<=inventoryMaxX; ++curX ) { for( size_t curY=inventoryPosY; curY<=inventoryMaxY; ++curY ) { if( slotUsed[ curX ][ curY ] ) { InventoryItem* curBlockinItemFound = getItemAt( curX, curY ); return curBlockinItemFound; } } } return NULL; }
Widget* MenuControl::_getItemAt(size_t _index) { return getItemAt(_index); }
//! Get selected item (nullptr if none selected) ItemType getItemSelected() { return getIndexSelected() != ITEM_NONE ? getItemAt(getIndexSelected()) : nullptr; }
void MenuBarComponent::updateItemUnderMouse (const Point<int>& p) { setItemUnderMouse (getItemAt (p)); }
TabItem* TabControl::getItemSelected() { return getIndexSelected() != ITEM_NONE ? getItemAt(getIndexSelected()) : nullptr; }
void MenuBarComponent::updateItemUnderMouse (int x, int y) { setItemUnderMouse (getItemAt (x, y)); }
char* getContentAt(int idx) { item* pItem = getItemAt(idx); if(pItem == NULL) return NULL; else return pItem->content; };
void PopUpMenu::paintComponent( const agui::PaintEvent &paintEvent ) { int totalHeight = 0; agui::Color regularColor = agui::Color( getFontColor().getR(),getFontColor().getG(),getFontColor().getB(),getOpacity()); agui::Color disabledColor = agui::Color( getDisabledFontColor().getR(),getDisabledFontColor().getG(), getDisabledFontColor().getB(),getOpacity()); for(int i = 0; i < getLength(); ++i) { int w = 0; agui::PopUpMenuItem* item = getItemAt(i); if(i == getSelectedIndex() && item->getItemType() != agui::PopUpMenuItem::SEPARATOR) { paintEvent.graphics()->drawNinePatchImage( m_highlightImg,agui::Point(0,totalHeight), agui::Dimension(getInnerWidth(),getItemHeight()),getOpacity()); } //draw the icon if(isShowingIcon()) { if(item->getIcon()) { paintEvent.graphics()-> drawImage(item->getIcon(),getIconPosition(i,totalHeight),getOpacity()); } w += getIconWidth(); } if(item->isSeparator()) { paintEvent.graphics()->drawLine( agui::Point(w,totalHeight + (getItemHeight(item) / 2)), agui::Point(getInnerWidth(),totalHeight + (getItemHeight(item) / 2)), agui::Color(90,90,90)); paintEvent.graphics()->drawLine( agui::Point(w,totalHeight + (getItemHeight(item) / 2) + 1), agui::Point(getInnerWidth(),totalHeight + (getItemHeight(item) / 2) + 1), agui::Color(200,200,200)); } w += getStartTextGap(); agui::Color* fontColor = item->isEnabled() ? ®ularColor : &disabledColor; paintEvent.graphics()->drawText(agui::Point(w,getTextCenter() + totalHeight), item->getText().c_str(), *fontColor, getFont()); w+= getMiddleTextGap(); agui::Point shortcutPoint = alignString(item->getShortcutText(),agui::ALIGN_MIDDLE_RIGHT); shortcutPoint.setX(shortcutPoint.getX() - getEndTextGap()); shortcutPoint.setY(getTextCenter() + totalHeight); paintEvent.graphics()->drawText(shortcutPoint, item->getShortcutText().c_str(),*fontColor, getFont()); if(item->isSubMenu()) { paintEvent.graphics()->drawImage(m_subArrowImg, createAlignedPosition(agui::ALIGN_MIDDLE_CENTER, agui::Rectangle(getInnerWidth() - getEndTextGap(), totalHeight,getEndTextGap(),getItemHeight()), agui::Dimension(m_subArrowImg->getWidth(),m_subArrowImg->getHeight())), getOpacity()); } totalHeight += getItemHeight(item); } }