//====================================================================================================================== // exec = //====================================================================================================================== int Application::exec() { while(1) { inputCallback(); processInput(); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(camPos.getX(), camPos.getY(), camPos.getZ(), camPos.getX() - camZ.getX(), camPos.getY() - camZ.getY(), camPos.getZ() - camZ.getZ(), camY.getX(), camY.getY(), camY.getZ()); glClear(GL_COLOR_BUFFER_BIT); glClear(GL_DEPTH_BUFFER_BIT); renderGrid(); mainLoop(); SDL_GL_SwapBuffers(); waitForNextFrame(); } return 0; }
void DoInput (void *pInputState, BOOLEAN resetInput) { if (resetInput) FlushInput (); do { MENU_SOUND_FLAGS soundFlags; Async_process (); TaskSwitch (); UpdateInputState (); #if DEMO_MODE || CREATE_JOURNAL if (ArrowInput != DemoInput) #endif { #if CREATE_JOURNAL JournalInput (InputState); #endif /* CREATE_JOURNAL */ } soundFlags = MenuKeysToSoundFlags (&PulsedInputState); if (MenuSounds && (soundFlags & (sound_0 | sound_1))) { SOUND S; S = MenuSounds; if (soundFlags & sound_1) S = SetAbsSoundIndex (S, MENU_SOUND_SUCCESS); PlaySoundEffect (S, 0, NotPositional (), NULL, 0); } if (inputCallback) inputCallback (); } while (((INPUT_STATE_DESC*)pInputState)->InputFunc (pInputState)); if (resetInput) FlushInput (); }
void interfaceGo(char* viewer) { imgViewer = malloc((strlen(viewer) + 1) * sizeof(char)); strcpy(imgViewer, viewer); const int CTRL_PER_LINE = COLS / CONTROL_LEN; // http://stackoverflow.com/a/2745086/1223693 const int HELP_HEIGHT = (NCONTROLS + CTRL_PER_LINE - 1) / CTRL_PER_LINE + 2; helpWin = newwin(HELP_HEIGHT, COLS, LINES - HELP_HEIGHT, 0); updateHelpWin(); fileWin = newwin(3, COLS, 0, 0); updateFileWin(); mainWin = newwin(LINES - HELP_HEIGHT - 3, COLS, 3, 0); updateMainWin(); updateImage(); char ch; while (1) { ch = getch(); if (gettingInput) { if (ch == '\n') { inputCallback(inputBuf); gettingInput = 0; free(inputBuf); delwin(inputPopup); } else if (ch == '\x07') { // backspace if (strlen(inputBuf) != 0) { inputBuf[strlen(inputBuf) - 1] = '\0'; waddstr(inputPopup, "\b \b"); wrefresh(inputPopup); } } else { inputBufLen = addCh(&inputBuf, ch, inputBufLen); waddch(inputPopup, ch); wrefresh(inputPopup); } } else switch (ch) { case 'A': // add a category getInput(cbAddCategory, "enter category name:"); break; case 'a': getInput(cbAddChkbox, "enter checkbox name:"); break; case 'D': getInput(cbDelCategory, "are you sure? [yn]"); break; case 'd': getInput(cbDelChkbox, "are you sure? [yn]"); break; case 'R': // TODO category rename break; case 'r': // TODO checkbox rename break; // TODO eliminate ugly code repetition in j/k and h/l case 'j': { // category down int y = CPOS.y, x = CPOS.x, newY = -1, newX = -1, newIdx = -1, i; for (i = 0; i < nCpos; ++i) { if ((cursorPositions[i].y > y) && (newIdx == -1 || cursorPositions[i].y < newY || (cursorPositions[i].y == newY && abs(cursorPositions[i].x - x) < abs(newX - x)))) { newY = cursorPositions[i].y; newX = cursorPositions[i].x; newIdx = i; } } if (newIdx != -1) cposIdx = newIdx; updateMainWin(); break; } case 'k': { // category up int y = CPOS.y, x = CPOS.x, newY = -1, newX = -1, newIdx = -1, i; for (i = 0; i < nCpos; ++i) { if ((cursorPositions[i].y < y) && (newIdx == -1 || cursorPositions[i].y > newY || (cursorPositions[i].y == newY && abs(cursorPositions[i].x - x) < abs(newX - x)))) { newY = cursorPositions[i].y; newX = cursorPositions[i].x; newIdx = i; } } if (newIdx != -1) cposIdx = newIdx; updateMainWin(); break; } case 'h': { // checkbox left int y = CPOS.y, x = CPOS.x, newX = -1, newIdx = -1, i; for (i = 0; i < nCpos; ++i) { if (cursorPositions[i].y == y && cursorPositions[i].x < x && (newIdx == -1 || cursorPositions[i].x > newX)) { newX = cursorPositions[i].x; newIdx = i; } } if (newIdx != -1) cposIdx = newIdx; updateMainWin(); break; } case 'l': { // checkbox right int y = CPOS.y, x = CPOS.x, newX = -1, newIdx = -1, i; for (i = 0; i < nCpos; ++i) { if (cursorPositions[i].y == y && cursorPositions[i].x > x && (newIdx == -1 || cursorPositions[i].x < newX)) { newX = cursorPositions[i].x; newIdx = i; } } if (newIdx != -1) cposIdx = newIdx; updateMainWin(); break; } case ' ': // checkbox toggle if (CPOS.chkboxIdx == -1) break; files[fileIdx].data ^= 1 << CPOS.chkboxIdx; updateMainWin(); break; case 'n': // image next if (fileIdx < nFiles - 1) ++fileIdx; updateFileWin(); updateMainWin(); updateImage(); break; case 'p': // image next if (fileIdx > 0) --fileIdx; updateFileWin(); updateMainWin(); updateImage(); break; case 'q': case '\x03': // ctrl+c return; case 'w': case '\x13': // ctrl+s save(); break; } } }