Advertisement
Guest User

Untitled

a guest
May 23rd, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.60 KB | None | 0 0
  1. #include <graphics.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. #define LINHA 40
  6. #define COLUNA 71
  7. #define UP_ARROW 72
  8. #define DOWN_ARROW 80
  9. #define LEFT_ARROW 75
  10. #define RIGHT_ARROW 77
  11. #define ENTER 13
  12. #define BACKSPACE 8
  13. #define MARGEM 10
  14.  
  15.  
  16. int main( )
  17. {
  18.     initwindow(640, 480, "Editor Beta");
  19.     char x[LINHA][COLUNA];
  20.     int tecla;
  21.     int i , j , linha ,  coluna ;
  22.     linha = coluna = 0;
  23.  
  24. for(i=0;i<LINHA;i++)
  25.    for(j=0; j<COLUNA; j++)
  26.    {
  27.     x[i][j]= 0;
  28.    }
  29.    
  30.    
  31.     while(1)
  32.     {
  33.        if(kbhit())
  34.        {
  35.           while((tecla = getch()) != 27)
  36.           {
  37.              switch(tecla)
  38.              {
  39.                 case 0:
  40.                      tecla=getch();
  41.                      switch(tecla)
  42.                      {
  43.                          case UP_ARROW:
  44.                               if(linha>0)
  45.                                linha--;
  46.                               if( x[linha][coluna] != 0 )
  47.                                for( j=0; x[linha][j]!=0;j++ )
  48.                                   coluna = j;
  49.                               break;
  50.                          case DOWN_ARROW:
  51.                               if(linha<40)
  52.                                linha++;
  53.                               break;
  54.                          case RIGHT_ARROW:
  55.                               if(coluna>0)
  56.                                coluna++;
  57.                               break;
  58.                          case LEFT_ARROW:
  59.                               if(coluna>0)
  60.                                coluna--;
  61.                               break;    
  62.                      }
  63.                      break;
  64.                      
  65.                 case ENTER:
  66.                      linha++;
  67.                      coluna=0;
  68.                      break;                  
  69.                
  70.                 case BACKSPACE:
  71.                      if (linha == 0 && coluna == 0)
  72.                         break;
  73.                      else if (linha > 0 && coluna == 0){
  74.                      linha--;
  75.                      for(j=0;x[linha][j]!=0;j++)
  76.                      coluna=j+1;
  77.                      }
  78.                      if(coluna==0)
  79.                      x[linha][coluna]=0;
  80.                      else
  81.                      x[linha][--coluna]=0;
  82.                      
  83.                      swapbuffers();
  84.                      cleardevice();
  85.                      setcolor(WHITE);
  86.                      for(i=0 ; i<=linha ; i++){
  87.                         outtextxy(MARGEM, MARGEM+i*20 , x[i]);        
  88.                         printf("Cursor:%d %d\n", linha , coluna);
  89.                
  90.                      }
  91.                      break;
  92.                
  93.                 default:
  94.                       x[linha][coluna++] = (char) tecla;
  95.                      swapbuffers();
  96.                      cleardevice();
  97.                      setcolor(WHITE);
  98.                      for(i=0 ; i<=linha ; i++){
  99.                         outtextxy(MARGEM, MARGEM+i*20 , x[i]);        
  100.                         printf("Cursor:%d %d\n", linha , coluna);
  101.                
  102.                      }
  103.                      break;
  104.              }
  105.              swapbuffers();
  106.              cleardevice();
  107.              setcolor(WHITE);
  108. //             outtextxy(MARGEM, MARGEM+linha , x[linha]);
  109.              for(i=0 ; i<=linha ; i++){
  110.                 outtextxy(MARGEM, MARGEM+i*20 , x[i]);        
  111.                 printf("Cursor:%d %d\n", linha , coluna);
  112.              }
  113.            
  114.              
  115.        
  116.           }                          
  117.           break;
  118.        }
  119.        
  120.    
  121.     }
  122.    
  123.     return 0;
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement