EDA_ITEM* GERBVIEW_SELECTION_TOOL::disambiguationMenu( GERBER_COLLECTOR* aCollector ) { EDA_ITEM* current = NULL; KIGFX::VIEW_GROUP highlightGroup; CONTEXT_MENU menu; highlightGroup.SetLayer( LAYER_GP_OVERLAY ); getView()->Add( &highlightGroup ); int limit = std::min( 10, aCollector->GetCount() ); for( int i = 0; i < limit; ++i ) { wxString text; EDA_ITEM* item = ( *aCollector )[i]; text = item->GetSelectMenuText(); menu.Add( text, i + 1 ); } menu.SetTitle( _( "Clarify selection" ) ); menu.DisplayTitle( true ); SetContextMenu( &menu, CMENU_NOW ); while( OPT_TOOL_EVENT evt = Wait() ) { if( evt->Action() == TA_CONTEXT_MENU_UPDATE ) { if( current ) { current->ClearBrightened(); getView()->Hide( current, false ); highlightGroup.Remove( current ); getView()->MarkTargetDirty( KIGFX::TARGET_OVERLAY ); } int id = *evt->GetCommandId(); // User has pointed an item, so show it in a different way if( id > 0 && id <= limit ) { current = ( *aCollector )[id - 1]; current->SetBrightened(); getView()->Hide( current, true ); highlightGroup.Add( current ); getView()->MarkTargetDirty( KIGFX::TARGET_OVERLAY ); } else { current = NULL; } } else if( evt->Action() == TA_CONTEXT_MENU_CHOICE ) { OPT<int> id = evt->GetCommandId(); // User has selected an item, so this one will be returned if( id && ( *id > 0 ) ) current = ( *aCollector )[*id - 1]; else current = NULL; break; } } if( current && current->IsBrightened() ) { current->ClearBrightened(); getView()->Hide( current, false ); getView()->MarkTargetDirty( KIGFX::TARGET_OVERLAY ); } getView()->Remove( &highlightGroup ); return current; }
BOARD_ITEM* SELECTION_TOOL::disambiguationMenu( GENERAL_COLLECTOR* aCollector ) { BOARD_ITEM* current = NULL; boost::shared_ptr<BRIGHT_BOX> brightBox; CONTEXT_MENU menu; int limit = std::min( 10, aCollector->GetCount() ); for( int i = 0; i < limit; ++i ) { wxString text; BOARD_ITEM* item = ( *aCollector )[i]; text = item->GetSelectMenuText(); menu.Add( text, i + 1 ); } menu.SetTitle( _( "Clarify selection" ) ); SetContextMenu( &menu, CMENU_NOW ); while( OPT_TOOL_EVENT evt = Wait() ) { if( evt->Action() == TA_CONTEXT_MENU_UPDATE ) { if( current ) current->ClearBrightened(); int id = *evt->GetCommandId(); // User has pointed an item, so show it in a different way if( id > 0 && id <= limit ) { current = ( *aCollector )[id - 1]; current->SetBrightened(); } else { current = NULL; } } else if( evt->Action() == TA_CONTEXT_MENU_CHOICE ) { boost::optional<int> id = evt->GetCommandId(); // User has selected an item, so this one will be returned if( id && ( *id > 0 ) ) current = ( *aCollector )[*id - 1]; break; } // Draw a mark to show which item is available to be selected if( current && current->IsBrightened() ) { brightBox.reset( new BRIGHT_BOX( current ) ); getView()->Add( brightBox.get() ); // BRIGHT_BOX is removed from view on destruction } } return current; }
BOARD_ITEM* SELECTION_TOOL::disambiguationMenu( GENERAL_COLLECTOR* aCollector ) { BOARD_ITEM* current = NULL; BRIGHT_BOX brightBox; CONTEXT_MENU menu; getView()->Add( &brightBox ); int limit = std::min( 10, aCollector->GetCount() ); for( int i = 0; i < limit; ++i ) { wxString text; BOARD_ITEM* item = ( *aCollector )[i]; text = item->GetSelectMenuText(); menu.Add( text, i + 1 ); } menu.SetTitle( _( "Clarify selection" ) ); SetContextMenu( &menu, CMENU_NOW ); while( OPT_TOOL_EVENT evt = Wait() ) { if( evt->Action() == TA_CONTEXT_MENU_UPDATE ) { if( current ) current->ClearBrightened(); int id = *evt->GetCommandId(); // User has pointed an item, so show it in a different way if( id > 0 && id <= limit ) { current = ( *aCollector )[id - 1]; current->SetBrightened(); } else { current = NULL; } } else if( evt->Action() == TA_CONTEXT_MENU_CHOICE ) { boost::optional<int> id = evt->GetCommandId(); // User has selected an item, so this one will be returned if( id && ( *id > 0 ) ) current = ( *aCollector )[*id - 1]; else current = NULL; break; } // Draw a mark to show which item is available to be selected if( current && current->IsBrightened() ) { brightBox.SetItem( current ); getView()->SetVisible( &brightBox, true ); // getView()->Hide( &brightBox, false ); getView()->Update( &brightBox, KIGFX::GEOMETRY ); getView()->MarkTargetDirty( KIGFX::TARGET_OVERLAY ); } } getView()->Remove( &brightBox ); return current; }