WINDOW *winputbox(WINDOW *win, int nlines, int ncols) { WINDOW *winp; int cury, curx, begy, begx; getyx(win, cury, curx); getbegyx(win, begy, begx); winp = newwin(nlines, ncols, begy + cury, begx + curx); colorbox(winp, INPUTBOXCOLOR, 1); return winp; }
void startmenu(menu *mp, char *mtitle) { initscr(); incurses = TRUE; initcolor(); wtitl = subwin(stdscr, th, bw, 0, 0); wmain = subwin(stdscr, mh, bw, th, 0); wbody = subwin(stdscr, bh, bw, th + mh, 0); wstat = subwin(stdscr, sh, bw, th + mh + bh, 0); colorbox(wtitl, TITLECOLOR, 0); colorbox(wmain, MAINMENUCOLOR, 0); colorbox(wbody, BODYCOLOR, 0); colorbox(wstat, STATUSCOLOR, 0); if (mtitle) titlemsg(mtitle); cbreak(); /* direct input (no newline required)... */ noecho(); /* ... without echoing */ curs_set(0); /* hide cursor (if possible) */ nodelay(wbody, TRUE); /* don't wait for input... */ halfdelay(10); /* ...well, no more than a second, anyway */ keypad(wbody, TRUE); /* enable cursor keys */ scrollok(wbody, TRUE); /* enable scrolling in main window */ leaveok(stdscr, TRUE); leaveok(wtitl, TRUE); leaveok(wmain, TRUE); leaveok(wstat, TRUE); mainmenu(mp); cleanup(); }
bullcolor::bullcolor(const bullseyeInfo &bi,cv::Mat &rgbImage) :bullseyeInfo(bi) { pixel=cyberalaska::vec3(bi.x,bi.y,0.0); radius=bi.votes/10.0; // very rough estimate of total radius (FIXME: this is crap) // Extract a color box around the center point double cr=radius*0.5; // color detection box radius (pixels) cv::Rect colorbox(bi.x-cr,bi.y-cr,2*cr,2*cr); colorbox &= cv::Rect(0,0,rgbImage.cols,rgbImage.rows); // clip to image dimensions cv::Mat colorimg=rgbImage(colorbox); // Extract the three channels enum {nchan=3}; // number of color channels to convert (B,G,R) cv::Mat channels[nchan]; for (int c=0;c<nchan;c++) { channels[c]=cv::Mat(colorimg.rows,colorimg.cols,CV_8U); } int fromTo[2*nchan]={0,0,1,1,2,2}; cv::mixChannels(&colorimg,1,channels,nchan,fromTo,nchan); // Calculate centers of mass cv::Moments moments[nchan]; // per-channel moments cv::Point_<float> com[nchan]; // center of mass for (int c=0;c<nchan;c++) { moments[c]=cv::moments(channels[c]); com[c]=cv::Point_<float>(moments[c].m00/moments[c].m10,moments[c].m00/moments[c].m01); color[c]=moments[c].m00/(colorbox.width*colorbox.height); } color[3]=0.0; // alpha? // Estimate orientation from channel center of mass differences cv::Point_<float> dirv=com[1]-com[2]; // points from green toward red dir=cyberalaska::vec3(dirv.x,dirv.y,0.0); float dm=length(dir); // magnitude if (dm>0.001) { dir*=1.0/dm; // make it have unit length angle=atan2_deg(dir); confidence=dm*50.0; // <- sets arbitrary scale factor on confidence } else { // direction vector is too short to be correct dir=cyberalaska::vec3(0.0); // make it have zero length angle=-999.0; confidence=0.0; } }
int weditstr(WINDOW *win, char *buf, int field) { char org[MAXSTRLEN], *tp, *bp = buf; bool defdisp = TRUE, stop = FALSE, insert = FALSE; int cury, curx, begy, begx; chtype oldattr; WINDOW *wedit; int c = 0; if ((field >= MAXSTRLEN) || (buf == NULL) || ((int)strlen(buf) > field - 1)) return ERR; strcpy(org, buf); /* save original */ wrefresh(win); getyx(win, cury, curx); getbegyx(win, begy, begx); wedit = subwin(win, 1, field, begy + cury, begx + curx); oldattr = wedit->_attrs; colorbox(wedit, EDITBOXCOLOR, 0); keypad(wedit, TRUE); curs_set(1); while (!stop) { idle(); repainteditbox(wedit, bp - buf, buf); switch (c = wgetch(wedit)) { case ERR: break; case KEY_ESC: strcpy(buf, org); /* restore original */ stop = TRUE; break; case '\n': case KEY_UP: case KEY_DOWN: stop = TRUE; break; case KEY_LEFT: if (bp > buf) bp--; break; case KEY_RIGHT: defdisp = FALSE; if (bp - buf < (int)strlen(buf)) bp++; break; case '\t': /* TAB -- because insert is broken on HPUX */ case KEY_IC: /* enter insert mode */ case KEY_EIC: /* exit insert mode */ defdisp = FALSE; insert = !insert; curs_set(insert ? 2 : 1); break; default: if (c == erasechar()) /* backspace, ^H */ { if (bp > buf) { memmove((void *)(bp - 1), (const void *)bp, strlen(bp) + 1); bp--; } } else if (c == killchar()) /* ^U */ { bp = buf; *bp = '\0'; } else if (c == wordchar()) /* ^W */ { tp = bp; while ((bp > buf) && (*(bp - 1) == ' ')) bp--; while ((bp > buf) && (*(bp - 1) != ' ')) bp--; memmove((void *)bp, (const void *)tp, strlen(tp) + 1); } else if (isprint(c)) { if (defdisp) { bp = buf; *bp = '\0'; defdisp = FALSE; } if (insert) { if ((int)strlen(buf) < field - 1) { memmove((void *)(bp + 1), (const void *)bp, strlen(bp) + 1); *bp++ = c; } } else if (bp - buf < field - 1) { /* append new string terminator */ if (!*bp) bp[1] = '\0'; *bp++ = c; } } } } curs_set(0); wattrset(wedit, oldattr); repainteditbox(wedit, bp - buf, buf); delwin(wedit); return c; }
void domenu(menu *mp) { int y, x, nitems, barlen, mheight, mw, old = -1, cur = 0, cur0; bool stop = FALSE; WINDOW *wmenu; curs_set(0); getmenupos(&y, &x); menudim(mp, &nitems, &barlen); mheight = nitems + 2; mw = barlen + 2; wmenu = newwin(mheight, mw, y, x); colorbox(wmenu, SUBMENUCOLOR, 1); repaintmenu(wmenu, mp); key = ERR; while (!stop && !quit) { if (cur != old) { if (old != -1) mvwaddstr(wmenu, old + 1, 1, prepad(padstr(mp[old].name, barlen - 1), 1)); setcolor(wmenu, SUBMENUREVCOLOR); mvwaddstr(wmenu, cur + 1, 1, prepad(padstr(mp[cur].name, barlen - 1), 1)); setcolor(wmenu, SUBMENUCOLOR); statusmsg(mp[cur].desc); old = cur; wrefresh(wmenu); } switch (key = ((key != ERR) ? key : waitforkey())) { case '\n': /* menu item selected */ touchwin(wbody); wrefresh(wbody); setmenupos(y + 1, x + 1); rmerror(); key = ERR; curs_set(1); (mp[cur].func)(); /* perform function */ curs_set(0); repaintmenu(wmenu, mp); old = -1; break; case KEY_UP: cur = (cur + nitems - 1) % nitems; key = ERR; break; case KEY_DOWN: cur = (cur + 1) % nitems; key = ERR; break; case KEY_ESC: case KEY_LEFT: case KEY_RIGHT: if (key == KEY_ESC) key = ERR; /* return to prev submenu */ stop = TRUE; break; default: cur0 = cur; do { cur = (cur + 1) % nitems; } while ((cur != cur0) && (hotkey(mp[cur].name) != toupper((int)key))); key = (hotkey(mp[cur].name) == toupper((int)key)) ? '\n' : ERR; } } rmerror(); delwin(wmenu); touchwin(wbody); wrefresh(wbody); }