static void cbAddCategory(char* s) { categories = realloc(categories, (++nCategories) * sizeof(struct ictCategory)); categories[nCategories - 1].name = calloc(strlen(s)+1, sizeof(char)); strcpy(categories[nCategories - 1].name, s); categories[nCategories - 1].chkboxes = NULL; categories[nCategories - 1].nChkboxes = 0; updateMainWin(); // display new category }
static void cbDelChkbox(char* s) { if (s[0] == 'y' && CPOS.relChkboxIdx != -1) { memmove(CCAT.chkboxes + CPOS.relChkboxIdx, CCAT.chkboxes + CPOS.relChkboxIdx + 1, (CCAT.nChkboxes - CPOS.relChkboxIdx - 1) * sizeof(char*)); --CCAT.nChkboxes; CCAT.chkboxes = realloc(CCAT.chkboxes, CCAT.nChkboxes * sizeof(char*)); if (cposIdx > 0) --cposIdx; } wclear(mainWin); updateMainWin(); }
static void cbDelCategory(char* s) { if (s[0] == 'y' && nCategories > 0) { memmove(categories + CPOS.categoryIdx, categories + CPOS.categoryIdx + 1, (nCategories - CPOS.categoryIdx - 1) * sizeof(struct ictCategory)); --nCategories; categories = realloc(categories, nCategories * sizeof(struct ictCategory)); if (cposIdx > 0) --cposIdx; } wclear(mainWin); updateMainWin(); }
void MGuiFileBrowser::selectFile(unsigned int id) { unsigned int fSize = m_files.size(); if(id < fSize) { const char * name = m_files[id].c_str(); if(id == 0) // go up in the hierarchy { char filename[256]; getGlobalFilename(filename, m_currentDirectory.getSafeString(), "../"); m_currentDirectory.set(filename); updateMainWin(); } else if(strlen(name) > 0) { bool isDir = (name[0] == '/'); if(isDir) name = name+1; char filename[256]; getGlobalFilename(filename, m_currentDirectory.getSafeString(), name); if(isDir) // navigate { m_currentDirectory.set(filename); updateMainWin(); } else { m_currentFile.set(name); } } } }
void MGuiFileBrowser::open(const char * startDirectory, const char * startFile, const char * okName, void (* pointerEvent)(MGuiFileBrowser * fileBrowser, MGUI_FILE_BROWSER_EVENT_TYPE event)) { bool forceRoot = true; m_pointerEvent = pointerEvent; m_headWin->setVisible(true); m_dirWin->setVisible(true); m_fileWin->setVisible(true); m_mainWin->setVisible(true); if(startDirectory) { if(isDirectory(startDirectory)) { m_currentDirectory.set(startDirectory); forceRoot = false; } } if(startFile) m_currentFile.set(startFile); if(okName) m_okButton->setText(okName); if(forceRoot && m_currentDirectory.getData()) { if(isDirectory(m_currentDirectory.getData())) { forceRoot = false; } } if(forceRoot) { #ifdef _WIN32 m_currentDirectory.set("C:\\"); #else m_currentDirectory.set("/"); #endif } updateMainWin(); }
void MGuiFileBrowser::resize(const MVector2 & position, const MVector2 & scale) { m_headWin->setPosition(position); m_headWin->setScale(MVector2(scale.x, m_fileButtonsHeight*2 + m_margin*3)); m_dirWin->setPosition(position + MVector2(m_margin)); m_dirWin->setScale(MVector2(scale.x - m_fileButtonsWidth - m_margin*3, m_fileButtonsHeight)); m_fileWin->setPosition(position + MVector2(m_margin) + MVector2(0, m_fileButtonsHeight + m_margin)); m_fileWin->setScale(MVector2(scale.x - m_fileButtonsWidth - m_margin*3, m_fileButtonsHeight)); m_mainWin->setPosition(position + MVector2(0, m_headWin->getScale().y)); m_mainWin->setScale(MVector2(scale.x, scale.y - m_headWin->getScale().y)); m_okButton->setXPosition(m_dirWin->getScale().x + m_margin*2); m_cancelButton->setXPosition(m_dirWin->getScale().x + m_margin*2); if(m_mainWin->isVisible()) updateMainWin(); }
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; } } }
static void cbAddChkbox(char* s) { CCAT.chkboxes = realloc(CCAT.chkboxes, (++CCAT.nChkboxes) * sizeof(char*)); CCAT.chkboxes[CCAT.nChkboxes - 1] = calloc(strlen(s)+1, sizeof(char)); strcpy(CCAT.chkboxes[CCAT.nChkboxes - 1], s); updateMainWin(); // display new checkbox }