Example #1
0
File: FED.C Project: MegaGod/TW
void edit( int ch ) {
	struct viewporttype tmp;
	char key, *buff;

	take_char( ( char ) ch );
	backup_char( );
	getviewsettings( &tmp );
	setviewport( 400, 30, getmaxx( ), getmaxy( ), 1 );
	buff = ( char* ) malloc( imagesize( 0 + align, 0, X*( 2 + WIDTH_X ) + align, Y*( 2 + WIDTH_Y ) ) );
	getimage( 0 + align, 0, X*( 2 + WIDTH_X ) + align, Y*( 2 + WIDTH_Y ), buff );
	draw_char( );
	start_clock( EDIT_FONT );

	while ( ( key = get_pos( &pos_x, &pos_y, X - 1, Y - 1, 1, 1 ) ) != 3 ) {
		switch ( tolower( key ) ) {
		case 1:
			xor_dot( pos_x, pos_y );
			continue;

		case '8':
			pan_up( );
			draw_char( );
			break;

		case '2':
			pan_down( );
			draw_char( );
			break;

		case '4':
			pan_left( );
			draw_char( );
			break;

		case '6':
			pan_right( );
			draw_char( );
			break;

		case 'r':
			insert_row( pos_y );
			draw_char( );
			break;

		case 'c':
			insert_col( pos_x );
			draw_char( );
			break;

		case 'e':
			del_row( pos_y );
			draw_char( );
			break;

		case 'd':
			del_col( pos_x );
			draw_char( );
			break;

		case 'i':
			invert( );
			draw_char( );
			break;

		case 'm':
			mirror( );
			draw_char( );
			break;

		case '.':
			++draw_mode;
			switch ( draw_mode ) {
			case 0:
				break;
			case 1:
				put_dot( pos_x, pos_y );
				edit_font[pos_x][pos_y] = ~0;
				break;
			case 2:
				square( pos_x, pos_y );
				edit_font[pos_x][pos_y] = 0;
				break;
			case 3:
				draw_mode = 0;
			}
			continue;

		case 'u':
			undo( );
			draw_char( );
			goto exit;

		case '?':
			help( );
			break;

		default:
			if ( draw_mode == 1 ) {
				put_dot( pos_x, pos_y );
				edit_font[pos_x][pos_y] = ~0;
			}
			if ( draw_mode == 2 ) {
				square( pos_x, pos_y );
				edit_font[pos_x][pos_y] = 0;
			}

		}
	}
	update_char( ( char ) ch );
exit:
	putimage( 0 + align, 0, buff, COPY_PUT );
	free( buff );
	stop_clock( );
	dispblank( 50, 16, strlen( "Move mode" ), 0 );
	setviewport( tmp.left, tmp.top, tmp.right, tmp.bottom, tmp.clip );
	print_table( which_page( ch ) );
}
Example #2
0
int getstring(char textst[],unsigned x,unsigned y,unsigned maxlen,char attr,strtype mode)
{
 int inkey,key,oldlen,temp;
 char keepchar;
 keepchar = '\0';
 oldlen = strlen(textst);
 dispblank(x,y,maxlen,attr);
 dispstrhgc(textst,x,y,attr);
 waitkbd(x+thaistrlen(textst),y);
 switch(mode) {
 case THAIENG : inkey = readkbd();
                break;
 case NUMBER  :
 case ONEORTWO :
 case ENGLISH : inkey = bioskey(0);
                break;
 case ENGUPCASE : inkey = bioskey(0);
                  key = inkey & 0xff;
                  if ((key >= 'a') && (key <= 'z'))
                    inkey = key - ('a' - 'A');
                  break;
 }
 switch (inkey) {
 case CNTRL_H  :
 case BSKEY    :
 case CNTRL_S  :
 case LEKEY    :
 case CNTRL_M  :
 case RETKEY   : break;
 default       : key = inkey & 0xff;
                 if (mode == NUMBER) {
                   if ((key < '0') || (key > '9')) break;
                 }
                 if (mode == ONEORTWO) {
                   if ((key != '1') && (key != '2')) break;
                 }
                 if ((inkey & 0xff) >= 32) {
                   textst[0] = '\0';
                   dispblank(x,y,maxlen,attr);
                 }
                 break;
 }
 do {
   switch(inkey){
   case CNTRL_M :
   case RETKEY  : return(YES);
   case CNTRL_U : return(NO);              /* Abort */
   case ESCKEY  : return(ESCKEY);
   case UPKEY   : return(UPKEY);
   case DNKEY   : return(DNKEY);
   case CNTRL_H :
   case BSKEY   :
   case LEKEY   :
   case CNTRL_S : temp = strlen(textst);
                   if (temp != 0){
                      if (temp < oldlen)
                         textst[temp] = keepchar;
                      keepchar = textst[temp-1];
                      textst[temp-1] = '\0';
                      dispblank(x,y,maxlen,attr);
                      dispstrhgc(textst,x,y,attr);
                   }
                   break;
   case RIKEY   :
   case CNTRL_D : temp = strlen(textst);
                  if ((temp < oldlen) && (temp < maxlen)){
                     textst[temp] = keepchar;
                     keepchar = textst[temp+1];
                     textst[temp+1] = '\0';
                     dispblank(x,y,maxlen,attr);
                     dispstrhgc(textst,x,y,attr);
                  }
                  break;
   case CNTRL_Y : if (strlen(textst) < oldlen)
                     textst[strlen(textst)] = keepchar;
                  keepchar = textst[0];
                  textst[0] = '\0';
                  dispblank(x,y,maxlen,attr);
                  break;
   case CNTRL_R : if (strlen(textst) < oldlen){
                     textst[strlen(textst)] = keepchar;
                     dispblank(x,y,maxlen,attr);
                     dispstrhgc(textst,x,y,attr);
                  }
                  break;
/*   case F10KEY  : thaimode = !thaimode;
		  writelanguage();
                  break;
*/   default      : inkey = (inkey & 0xff);
                  if (mode == NUMBER) {
                    if ((inkey < '0') || (inkey > '9')) break;
                  }
                  if (mode == ONEORTWO) {
                    if ((inkey != '1') && (inkey != '2')) break;
                  }
                  if (inkey >= 32) {
                    if (strlen(textst) < maxlen) {
                      if (whatlevel(inkey) == MIDDLE) {
                        textst[strlen(textst)+1] = '\0';
                        textst[strlen(textst)] = inkey;
                        oldlen = strlen(textst);
                        dispblank(x,y,maxlen,attr);
                        dispstrhgc(textst,x,y,attr);
                      } else {
                        if ((strlen(textst) != 0) &&
                          (whatlevel(inkey) > whatlevel(textst[strlen(textst)-1])) &&
                          (inkey != HUNAKADMITO)) {
                          textst[strlen(textst)+1] = '\0';
                          textst[strlen(textst)] = inkey;
                          oldlen = strlen(textst);
                          dispblank(x,y,maxlen,attr);
			  dispstrhgc(textst,x,y,attr);
			}
		      }
		  }
		  }
                  break;
   }
   waitkbd(x+thaistrlen(textst),y);
   switch(mode) {
   case THAIENG : inkey = readkbd();
                  break;
   case NUMBER  :
   case ONEORTWO :
   case ENGLISH : inkey = bioskey(0);
                  break;
 case ENGUPCASE : inkey = bioskey(0);
                  key = inkey & 0xff;
                  if ((key >= 'a') && (key <= 'z'))
                    inkey = key - ('a' - 'A');
                  break;
   }
 } while(1);
}