void cPopMenu::drawItems() { // Ñ»·»æÖÆitemÎÄ×Ö£¬Óö¼û selected ÎÄ×Ö¾ÍÏÈ»æÖÆÑ¡ÔñÌõ for( size_t i = 0; i < _items.size(); ++i ) { s16 itemX = _position.x + _itemTopLeftPoint.x; s16 itemY = _position.y + i * _itemHeight + _itemTopLeftPoint.y; if( _selectedItemIndex == (s16)i ) { s16 barX = _position.x + _barLeft; s16 barY = itemY - 2; gdi().setPenColor( _barColor, _engine ); gdi().fillRect( _barColor, _barColor, barX, barY, barWidth(), _itemHeight, _engine ); gdi().setPenColor( _textHighLightColor, _engine ); } else { gdi().setPenColor( _textColor, _engine ); } gdi().textOut( itemX, itemY, _items[i].c_str(), _engine ); } }
QSize VanishingScrollBar::sizeHint() const { constexpr int side = 2 * barMargin() + barWidth(); return QSize(side, side); }
u32 cPopMenu::itemBelowPoint( const cPoint & pt ) { cPoint menuPos(position().x + _barLeft, position().y + _itemTopLeftPoint.y - 2); cSize menuSize(barWidth(), _itemHeight * _items.size()); cRect rect(menuPos, menuPos + menuSize); if( rect.surrounds( pt ) ) { u32 item = (pt.y - menuPos.y ) / _itemHeight; if( item > _items.size() - 1) item = _items.size() - 1; return item; } return (u32)-1; }