/******************************************************************** * FILE : mybox.c * * functionality : Places a cursor on the monitor and * * allows the user to move the cursor anywhere on * * the monitor. Also allows varying increments of * * movement of the cursor. * ********************************************************************/ #include #include #include #define MAX 512 extern WINDOW *funcwin; extern struct fgread_struct fg_rw; int savetop[MAX], savebot[MAX], saveleft[MAX]; int saveright[MAX]; int topxg_shade[MAX], botxg_shade[MAX]; int leftyg_shade[MAX], rightyg_shade[MAX]; int xlen=50,ylen=50,boxpos_x=200,boxpos_y=200,incrbox=20; /************************************************************* * This function saves the pixels beneath where * * the boxtop will be placed. * *************************************************************/ savebox() { int i,j; j = 0; /* saving the pixels under the top horizontal line */ VIS$READ_HORIZONTAL_LINE (boxpos_x, boxpos_y, xlen, savetop); for ( i = boxpos_x; i<= boxpos_x + xlen; i++) { if (savetop[j] >= 128) topxg_shade[j] = 0; else topxg_shade[j] = 255; j++; } j = 0; /* saving the pixels under the bottom horizontal line */ VIS$READ_HORIZONTAL_LINE (boxpos_x, boxpos_y + ylen, xlen, savebot); for ( i = boxpos_x; i<= boxpos_x + xlen; i++) { if (savebot[j] >= 128) botxg_shade[j] = 0; else botxg_shade[j] = 255; j++; } j = 0; /* saving the pixels under the left vertical line */ VIS$READ_VERTICAL_LINE (boxpos_x, boxpos_y, ylen, saveleft); for ( i = boxpos_y; i<= boxpos_y + ylen; i++) { /*saveleft[j] = VIS$GET_PIXEL(boxpos_x,i); */ if (saveleft[j] >= 128) leftyg_shade[j] = 0; else leftyg_shade[j] = 255; j++; } j = 0; /* saving the pixels under the right vertical line */ VIS$READ_VERTICAL_LINE (boxpos_x + xlen, boxpos_y, ylen, saveright); for ( i = boxpos_y; i<= boxpos_y + ylen; i++) { /*saveright[j] = VIS$GET_PIXEL(boxpos_x + xlen,i); */ if (saveright[j] >= 128) rightyg_shade[j] = 0; else rightyg_shade[j] = 255; j++; } } /*************************************************************** * This function places the cursor on the monitor * ***************************************************************/ putbox() { /* putting top horizontal line down */ VIS$WRITE_HORIZONTAL_LINE(boxpos_x,boxpos_y, xlen, topxg_shade); VIS$WRITE_HORIZONTAL_LINE(boxpos_x,boxpos_y + ylen, xlen, botxg_shade); #ifdef ROGER int i,j; j = 0; /* putting left vertical line down */ for (i = boxpos_y; i <= boxpos_y + ylen; i++) VIS$SET_PIXEL(boxpos_x,i,leftyg_shade[j++]); #endif VIS$WRITE_VERTICAL_LINE(boxpos_x,boxpos_y, ylen, leftyg_shade); VIS$WRITE_VERTICAL_LINE(boxpos_x + xlen,boxpos_y, ylen, rightyg_shade); #ifdef ROGER j = 0; /* putting right vertical line down */ for (i = boxpos_y; i <= boxpos_y + ylen; i++) VIS$SET_PIXEL(boxpos_x + xlen,i,rightyg_shade[j++]); #endif } /* end putbox */ /*************************************************************** * This function places the pixels back where the box was * ***************************************************************/ putboxback() { int i,j; VIS$WRITE_HORIZONTAL_LINE(boxpos_x,boxpos_y, xlen, savetop); VIS$WRITE_HORIZONTAL_LINE(boxpos_x,boxpos_y + ylen, xlen, savebot); VIS$WRITE_VERTICAL_LINE(boxpos_x,boxpos_y, ylen, saveleft); VIS$WRITE_VERTICAL_LINE(boxpos_x + xlen,boxpos_y, ylen, saveright); } /* putboxback */ makethe(choice,length) int choice,length; { switch( choice ) { case 1 : putboxback(); xlen = length; savebox(); putbox(); break; case 2 : putboxback(); ylen = length; savebox(); putbox(); break; case 3 : putboxback(); ylen = length; xlen = length; savebox(); putbox(); break; case 4 : break; } } /***************************************************************** * This function asks for the size of the increment and * * in which direction. * *****************************************************************/ sizeboxmenu() { char temp[5]; int row,choice,i,quit,length; row = 13; quit = 0; mvwprintw(funcwin,15,15,"Change size to how many pixels:"); wrefresh(funcwin); weditstr(funcwin,16,15,temp,6); mvwprintw(funcwin,15,15," "); mvwprintw(funcwin,16,16," "); wrefresh(funcwin); length = atoi(temp); mvwprintw(funcwin,13,15,"in x direction"); mvwprintw(funcwin,14,15,"in y direction"); mvwprintw(funcwin,15,15,"in x and y direction"); mvwprintw(funcwin,16,15,"make no change"); mvwprintw(funcwin,18,10,"Use UP and DOWN arrow keys. SPACE designates choice"); mvwprintw(funcwin,row,10,"==>"); wrefresh(funcwin); do { mvwprintw(funcwin,row,10," "); switch( wgetch(funcwin) ) { case UPC : if (row == 13) row = 16; else row--; break; case DOWNC : if (row == 16) row = 13; else row++; break; case SPACE : choice = row - 12; makethe(choice,length); quit = 1; break; default : break; } mvwprintw(funcwin,row,10,"==>"); wrefresh(funcwin); } while (quit == 0); for(i = 13;i<=18;i++) mvwprintw(funcwin,i,10," "); } /* end of sizeboxmenu */ movesize(incrbox) int *incrbox; { char temp[5]; mvwprintw(funcwin,17,15,"How many pixels?"); wrefresh(funcwin); weditstr(funcwin,18,15,temp,6); mvwprintw(funcwin,17,15," "); mvwprintw(funcwin,18,15," "); wrefresh(funcwin); *incrbox = atoi(temp); } boxstuff() { int j,quit; char c; quit = 0; wclear(funcwin); box(funcwin,VERTCH,HORZCH); savebox(); putbox(); wstandout(funcwin); mvwprintw(funcwin,3,15," BOX FUNCTION MENU "); wstandend(funcwin); mvwprintw(funcwin,6,5,"s... sets number of pixels to move"); mvwprintw(funcwin,7,5,"c... change box size in x or y"); mvwprintw(funcwin,8,5,"p... prints the pixel values "); mvwprintw(funcwin,9,5,"q... quits"); mvwprintw(funcwin,11,9,"Use cursor keys move box."); mvwprintw(funcwin,20,10,"Box at (%d,%d) ",boxpos_x,boxpos_y); wrefresh(funcwin); do { wrefresh(funcwin); c = wgetch(funcwin); switch( c ) { case 'q' : quit = 1; break; case 'p' : print_pixels(); break; case 'c' : sizeboxmenu(); break; case 's' : movesize(&incrbox); break; case DOWNC : putboxback(); boxpos_y = ((boxpos_y + incrbox) % YSIZE); savebox(); putbox(); break; case UPC : putboxback(); boxpos_y = boxpos_y - incrbox; if ( boxpos_y < 0 ) boxpos_y = boxpos_y + YSIZE; /* to wrap around */ savebox(); putbox(); break; case RIGHTC : putboxback(); boxpos_x = ((boxpos_x + incrbox) % XSIZE); savebox(); putbox(); break; case LEFTC : putboxback(); boxpos_x = boxpos_x - incrbox; if ( boxpos_x < 0 ) boxpos_x = boxpos_x + XSIZE; /* to wrap around */ savebox(); putbox(); break; default : break; } mvwprintw(funcwin,20,10,"Box at (%d,%d)",boxpos_x,boxpos_y); wrefresh(funcwin); } while (quit == 0); wclear(funcwin); putboxback(); } print_pixels() { int x,y,j, result; int *values = fg_rw.values; /* makes it faster */ /* RWW */ for ( y = 0; y< ylen; y++) { VIS$READ_HORIZONTAL_LINE (boxpos_x, boxpos_y + y, xlen, values); for (x=0;x