/** ** Replace a group of selected units by an other group of units. ** ** @param units Array of units to be selected. ** @param count Number of units in array to be selected. */ static void ChangeSelectedUnits(CUnit **units, unsigned int count) { Assert(count <= MaxSelectable); if (count == 1 && units[0]->Type->ClicksToExplode && !units[0]->Type->IsNotSelectable) { HandleSuicideClick(*units[0]); if (!units[0]->IsAlive()) { NetworkSendSelection(units, count); return ; } } UnSelectAll(); NetworkSendSelection(units, count); for (unsigned int i = 0; i < count; ++i) { CUnit &unit = *units[i]; if (!unit.Removed && !unit.TeamSelected && !unit.Type->IsNotSelectable) { Selected.push_back(&unit); unit.Selected = 1; if (count > 1) { unit.LastGroup = GroupId; } } } }
/** ** Select units from group of a particular unit. ** Doesn't change the selection if the group has no unit, ** or the unit doesn't belong to any group. ** ** @param unit unit belonging to the group to be selected. ** ** @return 0 if the unit doesn't belong to a group, ** or the number of units in the group. */ int SelectGroupFromUnit(CUnit &unit) { if (!unit.LastGroup) { // belongs to no group return 0; } UnSelectAll(); return AddGroupFromUnitToSelection(unit); }
void AttributeSubject::Notify() { // Call the base class's Notify method. Subject::Notify(); // Now that all the Obsevrers have been called, unselect all the // attributes. UnSelectAll(); }
/** ** Restore selection. */ void RestoreSelection() { UnSelectAll(); for (int i = 0; i < PlayerMax; ++i) { TeamSelected[i] = _TeamSelected[i]; for (size_t j = 0; j != _TeamSelected[i].size(); ++j) { TeamSelected[i][j]->TeamSelected |= (1 << i); } } Selected = _Selected; for (size_t i = 0; i != _Selected.size(); ++i) { Selected[i]->Selected = 1; } }
/** ** Restore selection. */ void RestoreSelection() { UnSelectAll(); for (int i = 0; i < PlayerMax; ++i) { TeamNumSelected[i] = _TeamNumSelected[i]; for (int j = 0; j < _TeamNumSelected[i]; ++j) { TeamSelected[i][j] = _TeamSelected[i][j]; TeamSelected[i][j]->TeamSelected |= (1 << i); } } NumSelected = _NumSelected; for (int j = 0; j < _NumSelected; ++j) { Selected[j] = _Selected[j]; Selected[j]->Selected = 1; } }
/** ** Replace a group of selected units by an other group of units. ** ** @param units Array of units to be selected. ** @param count Number of units in array to be selected. */ static void ChangeSelectedUnits(CUnit **units, unsigned int count) { Assert(count <= MaxSelectable); if (count == 1 && units[0]->Type->ClicksToExplode && !units[0]->Type->BoolFlag[ISNOTSELECTABLE_INDEX].value) { HandleSuicideClick(*units[0]); if (!units[0]->IsAlive()) { NetworkSendSelection(units, count); return ; } } //Wyrmgus start bool suitable_selectee = false; for (unsigned int i = 0; i < count; ++i) { CUnit &unit = *units[i]; if (!unit.Removed && !unit.TeamSelected && !unit.Type->BoolFlag[ISNOTSELECTABLE_INDEX].value && unit.IsAlive()) { suitable_selectee = true; } } if (!suitable_selectee) { return; } //Wyrmgus end UnSelectAll(); NetworkSendSelection(units, count); for (unsigned int i = 0; i < count; ++i) { CUnit &unit = *units[i]; if (!unit.Removed && !unit.TeamSelected && !unit.Type->BoolFlag[ISNOTSELECTABLE_INDEX].value && unit.IsAlive()) { Selected.push_back(&unit); unit.Selected = 1; if (count > 1) { unit.LastGroup = GroupId; } } } }
/** ** Select units from a particular type and belonging to the local player. ** ** The base is included in the selection and defines ** the type of the other units to be selected. ** ** @param base Select all units of same type. ** ** @return Number of units found, 0 means selection unchanged ** ** FIXME: 0 can't happen. Maybe when scripting will use it? ** ** FIXME: should always select the nearest 9 units to the base! */ int SelectUnitsByType(CUnit &base) { const CUnitType &type = *base.Type; const CViewport *vp = UI.MouseViewport; Assert(UI.MouseViewport); if (type.ClicksToExplode) { HandleSuicideClick(base); } // if unit is a cadaver or hidden (not on map) // no unit can be selected. if (base.Removed || base.IsAlive() == false) { return 0; } if (type.IsNotSelectable && GameRunning) { return 0; } if (base.TeamSelected) { // Somebody else onteam has this unit return 0; } UnSelectAll(); Selected.push_back(&base); base.Selected = 1; // if unit isn't belonging to the player or allied player, or is a static unit // (like a building), only 1 unit can be selected at the same time. if (!CanSelectMultipleUnits(*base.Player) || !type.SelectableByRectangle) { return Selected.size(); } // // Search for other visible units of the same type // std::vector<CUnit *> table; // select all visible units. // StephanR: should be (MapX,MapY,MapX+MapWidth-1,MapY+MapHeight-1) ??? /* FIXME: this should probably be cleaner implemented if SelectUnitsByType() * took parameters of the selection rectangle as arguments */ const Vec2i offset(1, 1); const Vec2i minPos = vp->MapPos - offset; const Vec2i vpSize(vp->MapWidth, vp->MapHeight); const Vec2i maxPos = vp->MapPos + vpSize + offset; Select(minPos, maxPos, table, HasSameTypeAs(type)); // FIXME: peon/peasant with gold/wood & co are considered from // different type... idem for tankers for (size_t i = 0; i != table.size(); ++i) { CUnit &unit = *table[i]; if (!CanSelectMultipleUnits(*unit.Player)) { continue; } if (unit.IsUnusable()) { // guess SelectUnits doesn't check this continue; } if (&unit == &base) { // no need to have the same unit twice :) continue; } if (unit.TeamSelected) { // Somebody else onteam has this unit continue; } Selected.push_back(&unit); unit.Selected = 1; if (Selected.size() == MaxSelectable) { break; } } if (Selected.size() > 1) { for (size_t i = 0; i != Selected.size(); ++i) { Selected[i]->LastGroup = GroupId; } } NetworkSendSelection(&Selected[0], Selected.size()); return Selected.size(); }
/** ** Unselect all currently selected units. */ static void UiUnselectAll() { UnSelectAll(); NetworkSendSelection((CUnit **)NULL, 0); SelectionChanged(); }
/** ** Handle keys in command mode. ** ** @param key Key scancode. ** @return True, if key is handles; otherwise false. */ local int CommandKey(int key) { switch( key ) { case '\r': KeyState=KeyStateInput; Input[0]='\0'; InputIndex=0; ShowInput(); return 1; case '^': UnSelectAll(); break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': if( KeyModifiers&ModifierControl ) { // dirty atoi version :) SetGroup(Selected,NumSelected,key-48); } else { SelectGroup(key-48); } UpdateBottomPanel(); MustRedraw|=RedrawCursor|RedrawMap|RedrawPanels; break; #if 0 IfDebug( case '0': ++ThisPlayer; if( ThisPlayer==&Players[PlayerMax] ) { ThisPlayer=&Players[0]; } MustRedraw=RedrawEverything; break; case '1': --ThisPlayer; if( ThisPlayer<&Players[0] ) { ThisPlayer=&Players[PlayerMax-1]; } MustRedraw=RedrawEverything; break; ); #endif case KeyCodePause: case 'P': // If pause-key didn't work if(GamePaused) { GamePaused=0; SetStatusLine("Game Resumed"); } else { GamePaused=1; SetStatusLine("Game Paused"); } break; case KeyCodeF10: InterfaceState=IfaceStateMenu; GamePaused=1; SetStatusLine("Game Paused"); ProcessMenu(MENU_GAME); break; case '+': VideoSyncSpeed+=10; InitVideoSync(); SetStatusLine("Faster"); break; case '-': VideoSyncSpeed-=10; InitVideoSync(); SetStatusLine("Slower"); break; case 'S': // SMALL s is needed for panel SaveAll(); break; case 'c': if( NumSelected==1 ) { MapCenter(Selected[0]->X,Selected[0]->Y); } break; // TAB toggles minimap. // FIXME: more... case '\t': DebugLevel1("TAB\n"); MinimapWithTerrain^=1; MustRedraw|=RedrawMinimap; break; // FIXME: shift+TAB case 'q': Exit(0); case KeyCodeUp: if( MapY ) { if( KeyModifiers&ModifierControl ) { if( MapY<MapHeight/2 ) { MapY=0; } else { MapY-=MapHeight/2; } } else { --MapY; } MustRedraw|=RedrawMaps|RedrawMinimapCursor; } break; case KeyCodeDown: if( MapY<TheMap.Height-MapHeight ) { if( KeyModifiers&ModifierControl ) { if( MapY<TheMap.Height-MapHeight-MapHeight/2 ) { MapY+=MapHeight/2; } else { MapY=TheMap.Height-MapHeight; } } else { ++MapY; } MustRedraw|=RedrawMaps|RedrawMinimapCursor; } break; case KeyCodeLeft: if( MapX ) { if( KeyModifiers&ModifierControl ) { if( MapX<MapWidth/2 ) { MapX=0; } else { MapX-=MapWidth/2; } } else { --MapX; } MustRedraw|=RedrawMaps|RedrawMinimapCursor; } break; case KeyCodeRight: if( MapX<TheMap.Width-MapWidth ) { if( KeyModifiers&ModifierControl ) { if( MapX<TheMap.Width-MapWidth-MapWidth/2 ) { MapX+=MapWidth/2; } else { MapX=TheMap.Width-MapWidth; } } else { ++MapX; } MustRedraw|=RedrawMaps|RedrawMinimapCursor; } break; default: DebugLevel3("Key %d\n",key); return 0; }
MriWatcherGUI::MriWatcherGUI(QWidget *parent) { setupUi(this); installEventFilter(this); setAcceptDrops(true); connect(g_loadimg, SIGNAL( clicked() ), this, SLOT( LoadImg() ) ); connect(g_loadoverlay, SIGNAL( clicked() ), this, SLOT( LoadOverlay() ) ); connect(g_loadimg2, SIGNAL( clicked() ), this, SLOT( LoadImg2() ) ); connect(g_reset_view, SIGNAL( clicked() ), this, SLOT( ResetView() ) ); connect(g_screenshot, SIGNAL( clicked() ), this, SLOT( ScreenShot() ) ); connect(g_combine, SIGNAL( clicked() ), this, SLOT( Combine() ) ); connect(g_help, SIGNAL( clicked() ), this, SLOT( Help() ) ); connect(g_xview, SIGNAL( toggled(bool) ), this, SLOT( ChangeView() ) ); connect(g_yview, SIGNAL( toggled(bool) ), this, SLOT( ChangeView() ) ); connect(g_zview, SIGNAL( toggled(bool) ), this, SLOT( ChangeView() ) ); connect(g_slice_slider, SIGNAL( sliderMoved(int) ), this, SLOT( ChangeSlice(int) ) ); // connect(g_slice_slider, SIGNAL( valueChanged(int) ), this, SLOT( ChangeSlice(int) )); connect(g_overlay_alpha_slider, SIGNAL( valueChanged(int) ), this, SLOT( ChangeOverlayAlpha(int) ) ); connect(g_draw_name, SIGNAL( stateChanged(int) ), this, SLOT( DrawImageName(int) ) ); connect(g_draw_info, SIGNAL( stateChanged(int) ), this, SLOT( DrawImageInfo(int) ) ); connect(g_draw_position, SIGNAL( stateChanged(int) ), this, SLOT( DrawImagePosition(int) ) ); connect(g_draw_intensity, SIGNAL( stateChanged(int) ), this, SLOT( DrawImageIntensity(int) ) ); connect(g_overlayzero, SIGNAL( stateChanged(int) ), this, SLOT( ChangeOverlayZero() ) ); connect(g_intensity_min_slider, SIGNAL( valueChanged(int) ), this, SLOT( ChangeIntensityMin(int) ) ); connect(g_intensity_max_slider, SIGNAL( valueChanged(int) ), this, SLOT( ChangeIntensityMax(int) ) ); connect(g_blending_mode, SIGNAL( stateChanged(int) ), this, SLOT( SetBlendingMode() ) ); connect(g_alpha, SIGNAL( valueChanged(int) ), this, SLOT( ChangeImageAlpha(int) ) ); connect(g_viewall, SIGNAL( toggled(bool) ), this, SLOT( ViewOptions() ) ); connect(g_viewcolumn, SIGNAL( toggled(bool) ), this, SLOT( ViewOptions() ) ); // connect(g_nbcolumn, SIGNAL( returnPressed() ), this, SLOT( ViewOptions() ) ); connect(g_nbcolumn, SIGNAL( valueChanged(int) ), this, SLOT( ChangeColumn() )); connect(g_overlaymin, SIGNAL( returnPressed() ), this, SLOT( ChangeOverlayMinMax() ) ); connect(g_overlaymax, SIGNAL( returnPressed() ), this, SLOT( ChangeOverlayMinMax() ) ); m_direction = 0; m_numberofimages = 0; m_maxsize[0] = 0; m_maxsize[1] = 0; m_maxsize[2] = 0; m_imagemin = 999999; m_imagemax = 0; m_keyalt = false; m_keyctrl = false; // multiselection m_overlaymin = 0; m_overlaymax = 0; m_imagemanager.ChangeAlpha(100); g_slice_slider->setEnabled(false); g_overlay_alpha_slider->setEnabled(false); g_intensity_min_slider->setMinimum(0); g_intensity_max_slider->setMinimum(0); g_intensity_min_slider->setMaximum(static_cast<int>(MAX_PERCENTAGE) ); g_intensity_max_slider->setMaximum(static_cast<int>(MAX_PERCENTAGE) ); g_intensity_min_slider->setValue(0); g_intensity_max_slider->setValue(static_cast<int>(MAX_PERCENTAGE) ); m_frame = new MriWatcherFrame(g_scrollArea); connect(m_frame, SIGNAL( UnSelectAll() ), this, SLOT( UnSelectAll() ) ); connect(m_frame, SIGNAL( GetFiles(const QString &) ), this, SLOT( LoadFile(const QString &) ) ); // m_imageframelayout = new ImageFrameLayout(); // QBoxLayout* gm = new QVBoxLayout(m_frame); m_imageframelayout = new ImageFrameLayout(); // g_scrollArea->setLayout(m_imageframelayout); g_scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); g_scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); // g_scrollArea->verticalScrollBar()->setRange(); g_scrollArea->setWidget(m_frame); m_frame->setLayout(m_imageframelayout); g_name_version->setText(QString("MriWatcher") + " " + MriWatcher_VERSION); g_tips->setText( "\nQuick Tips:\n- Left mouse drag: Move image\n- Right mouse drag: Zoom in/out\n- Middle mouse: Pick one voxel\n- Control + mouse: Pick images\n- Shift + mouse: Global operatation\n- Left or right key: Switch order\n- Delete key: Remove image"); /* imageLabel = new QLabel; imageLabel->setBackgroundRole(QPalette::Base); imageLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); imageLabel->setScaledContents(true); g_scrollArea->setBackgroundRole(QPalette::Dark); g_scrollArea->setWidget(imageLabel); */ }