//=============================================================== vectorField::vectorField() { clearField(); bReset = false; }
int main(int argc, char const *argv[]) { int nField = 1; for (;;) { scanf("%d %d", &n, &m); ((m==0 && n==0) ? exit(0) : 0); // stopping conditionnal statement // initialization loop for (size_t i = 0; i < n; i++) { scanf("%s", field[i]); } clearField(); // replacing all the '.' by '0' // processing loop for (size_t i = 0; i < n; i++) { for (size_t j = 0; j < m; j++) { (field[i][j] == '*' ? setMine(i,j) : 0); } } // display the result displayField(nField); nField++; } return 0; }
void VectorField::update(const ofPixels &pixels, const float maxStrength) { // reset all field vectors to 0. clearField(); // iterate over all possible vector in field. // for (int y = 1; y <= mSubdivision; ++y) { for (int x = 1; x <= mSubdivision; ++x) { // calculate index of vector in field int fieldIndex = (y - 1) * (mSubdivision - 1) + (x - 1); // calculate all pixel locations of subdivisions: center, top, bottom, right and left. int xPos = x * mIncX; int yPos = y * mIncY; int topPos = (y - 1) * mIncY; int bottomPos = (y + 1) * mIncY; int leftPos = (x - 1) * mIncX; int rightPos = (x + 1) * mIncX; // little hack to get values for the last line of pixels bottomPos = (bottomPos == mHeight) ? bottomPos - 1 : bottomPos; // extract value of red channel for all eight surrounding positions // only the red channel is relevant, since the perlin noise shader writes the same value // into all three channels: red, green, blue – hence the grey scale iamge. int nw = pixels[ (topPos * mWidth + leftPos) * pixels.getNumChannels() ]; int n_ = pixels[ (topPos * mWidth + xPos) * pixels.getNumChannels() ]; int ne = pixels[ (topPos * mWidth + rightPos) * pixels.getNumChannels() ]; int _e = pixels[ (yPos * mWidth + rightPos) * pixels.getNumChannels() ]; int se = pixels[ (bottomPos * mWidth + rightPos) * pixels.getNumChannels() ]; int s_ = pixels[ (bottomPos * mWidth + xPos) * pixels.getNumChannels() ]; int sw = pixels[ (bottomPos * mWidth + leftPos) * pixels.getNumChannels() ]; int _w = pixels[ (yPos * mWidth + leftPos) * pixels.getNumChannels() ]; // calcualte the difference between all subdivisions at the top and bottom and to the left and right. float diffX = (nw + _w + sw) - (ne + _e + se); float diffY = (nw + n_ + ne) - (sw + s_ + se); // update field position mField[fieldIndex].x = diffX; mField[fieldIndex].y = diffY; int pixelValue = (int) pixels[(yPos * mWidth + xPos) * pixels.getNumChannels()]; // apply max strength mField[fieldIndex].normalize(); mField[fieldIndex] *= ofMap((float) pixelValue, 0.f, 255.f, 0.f, maxStrength); // store pixel value in z dimension mField[fieldIndex].z = pixelValue; } } }
//----------------------------------------------------------------- void GABot::prepareGame(void) { GAGame = new Game(this, TeamA, TeamB, 1000, 80, 40); TeamA->goals(0); TeamB->goals(0); GAGame->reset(); connect(GAGame, SIGNAL(ballMoved(Coordinate,Coordinate)), this, SLOT(slotBallMoved(Coordinate,Coordinate))); connect(GAGame, SIGNAL(teamAScores()), this,SLOT(slotTeamAScores()) ); connect(GAGame, SIGNAL(teamBScores()), this,SLOT(slotTeamBScores()) ); connect(GAGame, SIGNAL(clearField()), this, SLOT(slotClearField()) ); connect(GAGame, SIGNAL(gameOver()), this, SLOT(slotGameOver()) ); }
MainWindow::MainWindow() { setCaption(tr("GA Bots " VERSION)); initActions(); initMenuBar(); initToolBar(); initStatusBar(); initGABotDoc(); initView(); ViewToolBar->setOn(true); ViewStatusBar->setOn(true); //ViewGame->setOn(true); connect(GABotDoc, SIGNAL(gameReady(bool)), this, SLOT(slotGameReady(bool))); connect(GABotDoc, SIGNAL(teamAScores()), View, SLOT(slotScoreA())); connect(GABotDoc, SIGNAL(teamBScores()), View, SLOT(slotScoreB())); connect(GABotDoc, SIGNAL(clearScores()), View, SLOT(slotClearScores())); connect(GABotDoc, SIGNAL(moveTeamA(Coordinate, Coordinate)), View, SLOT(slotMoveTeamA(Coordinate, Coordinate))); connect(GABotDoc, SIGNAL(moveTeamB(Coordinate, Coordinate)), View, SLOT(slotMoveTeamB(Coordinate, Coordinate))); connect(GABotDoc, SIGNAL(turnTeamA(Coordinate, Direction)), View, SLOT(slotTurnTeamA(Coordinate, Direction))); connect(GABotDoc, SIGNAL(turnTeamB(Coordinate, Direction)), View, SLOT(slotTurnTeamB(Coordinate, Direction))); connect(GABotDoc, SIGNAL(moveBall(Coordinate,Coordinate)), View, SLOT(slotMoveBall(Coordinate,Coordinate))); connect(GoGame, SIGNAL(activated()), this, SLOT(slotGoGame())); connect(GoGame, SIGNAL(activated()), GABotDoc, SLOT(slotStartTimer())); connect(StopGame, SIGNAL(activated()), GABotDoc, SLOT(slotStopTimer())); connect(StopGame, SIGNAL(activated()), this, SLOT(slotStopGame())); connect(View, SIGNAL(valueChanged(int)), this, SLOT(slotTickInterval(int))); connect(GABotDoc, SIGNAL(clearField()), View, SLOT(slotClearField())); connect(ResetScreen, SIGNAL(activated()), View, SLOT(slotClearField())); //not sure if we should clear the field whenever regenerating the team // connect(TeamAGenerate,SIGNAL(activated()), View, SLOT(slotClearField())); // connect(TeamBGenerate,SIGNAL(activated()), View, SLOT(slotClearField())); connect(GABotDoc, SIGNAL(gameOver()), View, SLOT(slotClearField())); connect(GABotDoc, SIGNAL(gameOver()), View, SLOT(slotClearScores())); connect(GABotDoc, SIGNAL(gameOver()), this, SLOT(slotGameOver())); }
CalculatorWidget::CalculatorWidget(QWidget *parent) : QWidget(parent), ui(new Ui::CalculatorWidget) { ui->setupUi(this); digitsSignalMapper = new QSignalMapper(this); connect(ui->button0, SIGNAL(pressed()), digitsSignalMapper, SLOT(map())); digitsSignalMapper->setMapping(ui->button0, 0); connect(ui->button1, SIGNAL(pressed()), digitsSignalMapper, SLOT(map())); digitsSignalMapper->setMapping(ui->button1, 1); connect(ui->button2, SIGNAL(pressed()), digitsSignalMapper, SLOT(map())); digitsSignalMapper->setMapping(ui->button2, 2); connect(ui->button3, SIGNAL(pressed()), digitsSignalMapper, SLOT(map())); digitsSignalMapper->setMapping(ui->button3, 3); connect(ui->button4, SIGNAL(pressed()), digitsSignalMapper, SLOT(map())); digitsSignalMapper->setMapping(ui->button4, 4); connect(ui->button5, SIGNAL(pressed()), digitsSignalMapper, SLOT(map())); digitsSignalMapper->setMapping(ui->button5, 5); connect(ui->button6, SIGNAL(pressed()), digitsSignalMapper, SLOT(map())); digitsSignalMapper->setMapping(ui->button6, 6); connect(ui->button7, SIGNAL(pressed()), digitsSignalMapper, SLOT(map())); digitsSignalMapper->setMapping(ui->button7, 7); connect(ui->button8, SIGNAL(pressed()), digitsSignalMapper, SLOT(map())); digitsSignalMapper->setMapping(ui->button8, 8); connect(ui->button9, SIGNAL(pressed()), digitsSignalMapper, SLOT(map())); digitsSignalMapper->setMapping(ui->button9, 9); connect(digitsSignalMapper, SIGNAL(mapped(int)), this, SLOT(numberPressed(int))); opsSignalMapper = new QSignalMapper(this); connect(ui->buttonSum, SIGNAL(pressed()), opsSignalMapper, SLOT(map())); opsSignalMapper->setMapping(ui->buttonSum, 0); connect(ui->buttonMinus, SIGNAL(pressed()), opsSignalMapper, SLOT(map())); opsSignalMapper->setMapping(ui->buttonMinus, 1); connect(ui->buttonMult, SIGNAL(pressed()), opsSignalMapper, SLOT(map())); opsSignalMapper->setMapping(ui->buttonMult, 2); connect(ui->buttonDiv, SIGNAL(pressed()), opsSignalMapper, SLOT(map())); opsSignalMapper->setMapping(ui->buttonDiv, 3); connect(opsSignalMapper, SIGNAL(mapped(int)), this, SLOT(opPressed(int))); connect(ui->buttonDot, SIGNAL(pressed()), this, SLOT(dotPressed())); connect(ui->buttonEqual, SIGNAL(pressed()), this, SLOT(equalPressed())); connect(ui->strField, SIGNAL(returnPressed()), this, SLOT(clearField())); this->setLayout(ui->gridLayout); // calc = new Calculator<PointerStack<TokenStruct>, PointerStack<double>>; }
/** * Set a method of executable code into a directory object. * * @param entryname The name this is set under * @param methodobj The associated method object. * * @return Nothing. */ RexxInternalObject *DirectoryClass::setMethodRexx(RexxString *entryname, MethodClass *methodobj) { entryname = stringArgument(entryname, "index")->upper(); if (methodobj != OREF_NULL) { // make sure we have a method object for this. The scope is .nil to indicate object scope. methodobj = MethodClass::newMethodObject(entryname, methodobj, (RexxClass *)TheNilObject, "method"); // the unknown method? We keep that in a special place if (entryname->strCompare(GlobalNames::UNKNOWN)) { setField(unknownMethod, methodobj); } else { // create the table if this is the first addition if (methodTable == OREF_NULL) { setField(methodTable, new_string_table()); } // and add the method to the table methodTable->put(methodobj, entryname); } } // no method object given, this is a removal else { // if unknown, remove this from the special place. if (entryname->strCompare(GlobalNames::UNKNOWN)) { clearField(unknownMethod); } else { // remove from the method table if we have one if (methodTable != OREF_NULL) { methodTable->remove(entryname); } } } // since setting a method will also override any contents, we need to // ensure the contents don't have this either. contents->remove(entryname); return OREF_NULL; }
/** * unset a method of executable code into a directory object. * * @param entryname The name this is set under * * @return Nothing. */ RexxInternalObject *DirectoryClass::unsetMethodRexx(RexxString *entryname) { // the entry name is always upper case entryname = stringArgument(entryname, "index")->upper(); // if unknown, remove this from the special place. if (entryname->strCompare(GlobalNames::UNKNOWN)) { clearField(unknownMethod); } else { // remove from the method table if we have one if (methodTable != OREF_NULL) { methodTable->remove(entryname); } } return OREF_NULL; }
void AddCopy::on_createBut_clicked() { Collection *coll = collections[ui->collectionEdit->currentIndex()]; QString startId = ui->startingBarcodeEdit->text(); QString size = ui->numOfCopiesEdit->text(); QString errMess(""); int numOfCreatedCopies = Service::addListOfCopies( &errMess, startId, size, ui->statusEdit->currentIndex(), coll); QString text = QString("New copies are created successfully. " "Number of created copies: %1").arg(numOfCreatedCopies); if (errMess == "") { QMessageBox::information(this, tr("Creating new copies succeeds"), text); clearField(); mainWindow->showMainPage(); } else { QMessageBox::critical(this, tr("Error occurs"), errMess.append("\n").append(text)); } }
//----------------------------------------------------------------- void GABot::slotClearField(void) { emit(clearField()); }
void AddCopy::on_cancelBut_clicked() { mainWindow->showMainPage(); clearField(); }
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { static HDC hdcMem; // offScreen для двойной буфферизации static HBITMAP hbmMem; // тут хранится полное изображение на контексте static HANDLE hOld; // тут старый вид окна static PAINTSTRUCT ps; static HDC hdc; static int gameStat; // Состояние игры. 0 -> идет. 1 -> победа. -1 -> проигрыш static int seconds; // Секунды от страта таймера /// магия static bool newOffScreenDC = true; // Флаг создания нового буффера для двойной буфферизации switch (message) { case WM_PAINT: { RedrawField(hdcMem); hdc = BeginPaint(hWnd, &ps); BitBlt(hdc, 0, 0, SellSize * width, SellSize * height, hdcMem, 0, 0, SRCCOPY); EndPaint(hWnd, &ps); } break; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// case WM_TIMER: { seconds = nextTime(); RedrawField(hdcMem); hdc = GetDC(hWnd); BitBlt(hdc, 0, 0, SellSize * width, SellSize * height, hdcMem, 0, 0, SRCCOPY); ReleaseDC(hWnd, hdc); if (seconds == 0) { KillTimer(hWnd, 1); } } break; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// case WM_LBUTTONUP: { // Определяем ячейку int j = LOWORD(lParam) / SellSize; // j - ячейка по x int i = HIWORD(lParam) / SellSize; // i - ячейка по y if (i >= 0 && j >= 0 && i < height && j < width) // Координаты попадают в поле { field[i][j].value = true; RedrawField(hdcMem); hdc = GetDC(hWnd); BitBlt(hdc, 0, 0, SellSize * width, SellSize * height, hdcMem, 0, 0, SRCCOPY); ReleaseDC(hWnd, hdc); } } break; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// case WM_COMMAND: { if (wParam == ID_OPTIONS) // Открыть дочернее окно с параметрами { EnableWindow(hWndMain, FALSE); // Делаем неактивным главное окно InitOptionWindow(); // Создаем окно. Если надо пересоздать поле CreateField -> true if (CreateField) { KillTimer(hWnd, 1); // Сбрасиваем таймер SetWindowPos(hWnd, HWND_TOP, 0, 0, SellSize * width + sizeOfBorder, SellSize * height + sizeOfMenuBar, SWP_SHOWWINDOW | SWP_NOMOVE); InvalidateRect(hWnd, NULL, FALSE); // Перерисовываем } //SetTimer(hWndMain, 1, 5000, NULL); } else if (wParam == ID_NEW) { KillTimer(hWnd, 1); // Сбрасиваем таймер clearField(); InvalidateRect(hWnd, NULL, FALSE); // Перерисовываем } else if (wParam == ID_START) { SetTimer(hWndMain, 1, 1000, NULL); } } break; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// case WM_SIZE: // При изменении размера создаем off-screen DC { /// эта магия для того чтоб при сворачивании мы заново не рисовали окно а пользовались старой отрисовкой if (wParam == SIZE_MINIMIZED) // Не создаем нового экрана gосле минимизации { newOffScreenDC = false; } else if (wParam == SIZE_RESTORED && newOffScreenDC) { hdc = GetDC(hWnd); hdcMem = CreateCompatibleDC(hdc); hbmMem = CreateCompatibleBitmap(hdc, SellSize * width, SellSize * height); hOld = SelectObject(hdcMem, hbmMem); ReleaseDC(hWnd, hdc); SetBkColor(hdcMem, RGB(249, 128, 182)); // Черный фон newOffScreenDC = true; } else { newOffScreenDC = true; } } break; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// case WM_DESTROY: // При закрытии освобождаем память { SelectObject(hdcMem, hOld); DeleteObject(hbmMem); DeleteDC(hdcMem); PostQuitMessage(0); } break; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
void JobListOnReceiptDialog::on_pushButtonClearField_clicked() { clearField(); }