Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 24.37 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #include<SDL2/SDL.h>
  3. #include<SDL2/SDL_image.h>
  4. #include<SDL2/SDL_ttf.h>
  5.  
  6.  
  7. const int SCREEN_WIDTH = 400;
  8. const int SCREEN_HEIGHT = 400;
  9. int Font_WIDTH = 30;
  10. int day, month, year;
  11. char date[50];
  12.  
  13.  
  14.  
  15.  
  16.  
  17. class LTexture
  18. {
  19.  
  20. public:
  21.  
  22.     LTexture();
  23.     ~LTexture();
  24.     bool loadFromFile(std::string path);
  25.  
  26. #if defined(_SDL_TTF_H) || defined(SDL_TTF_H)
  27.     bool loadFromRenderedText( std::string textureText, SDL_Color textColor );
  28. #endif
  29.  
  30.     void free();
  31.     void setColor(Uint8 red, Uint8 green, Uint8 blue);
  32.     void setBlendMode(SDL_BlendMode blending);
  33.     void setAlpha(Uint8 alpha);
  34.     void render(int x, int y, SDL_Rect* clip = NULL, double angle = 0.0, SDL_Point* center = NULL, SDL_RendererFlip flip = SDL_FLIP_NONE );
  35.     int getWidth();
  36.     int getHeight();
  37.  
  38. private:
  39.     SDL_Texture* mTexture;
  40.     int mWidth;
  41.     int mHeight;
  42.  
  43. };
  44.  
  45.  
  46. LTexture gDotTexture;
  47.  
  48. class Dot
  49. {
  50. public:
  51.     //The dimensions of the dot
  52.     static const int DOT_WIDTH = 20;
  53.     static const int DOT_HEIGHT = 20;
  54.  
  55.     //Maximum axis velocity of the dot
  56.     static const int DOT_VEL = 10;
  57.  
  58.     //Initializes the variables
  59.     Dot();
  60.  
  61.     //Takes key presses and adjusts the dot's velocity
  62.     void handleEvent( SDL_Event& e );
  63.  
  64.     //Moves the dot
  65.     void move();
  66.  
  67.     //Shows the dot on the screen
  68.     void render();
  69.  
  70. private:
  71.     //The X and Y offsets of the dot
  72.     int mPosX, mPosY;
  73.  
  74.     //The velocity of the dot
  75.     int mVelX, mVelY;
  76. };
  77.  
  78. Dot::Dot()
  79. {
  80.     //Initialize the offsets
  81.     mPosX = 0;
  82.     mPosY = 0;
  83.  
  84.     //Initialize the velocity
  85.     mVelX = 0;
  86.     mVelY = 0;
  87. }
  88.  
  89.  
  90.  
  91. bool init();
  92. bool loadMedia();
  93. void close();
  94.  
  95. SDL_Window* main_window = NULL;
  96. SDL_Renderer* main_renderer = NULL;
  97. TTF_Font* main_font=NULL;
  98. LTexture mainTextTexture[50];
  99. LTexture Ltemp;
  100. LTexture indi;
  101. LTexture header;
  102.  
  103. LTexture::LTexture()
  104. {
  105.     mTexture = NULL;
  106.     mWidth = 0;
  107.     mHeight = 0;
  108. }
  109.  
  110. LTexture::~LTexture()
  111. {
  112.     free();
  113. }
  114.  
  115. bool LTexture::loadFromFile(std:: string path)
  116. {
  117.     free();
  118.     SDL_Texture* newTexture = NULL;
  119.     SDL_Surface* loadedSurface = IMG_Load(path.c_str());
  120.     if(loadedSurface==NULL)
  121.     {
  122.         printf( "Unable to load image %s! SDL_image Error: %s\n", path.c_str(), IMG_GetError() );
  123.     }
  124.     else
  125.     {
  126.         SDL_SetColorKey(loadedSurface, SDL_TRUE, SDL_MapRGB(loadedSurface->format, 0, 0xFF, 0xFF));
  127.         newTexture = SDL_CreateTextureFromSurface(main_renderer, loadedSurface);
  128.         if( newTexture == NULL )  printf( "Unable to create texture from %s! SDL Error: %s\n", path.c_str(), SDL_GetError() );
  129.  
  130.         else
  131.         {
  132.             mWidth = loadedSurface->w;
  133.             mHeight = loadedSurface->h;
  134.         }
  135.         SDL_FreeSurface(loadedSurface);
  136.     }
  137.     mTexture = newTexture;
  138.     return mTexture !=NULL;
  139. }
  140.  
  141.  
  142. #if defined(_SDL_TTF_H) || defined(SDL_TTF_H)
  143. bool LTexture::loadFromRenderedText(std::string textureText, SDL_Color textColor)
  144. {
  145.  
  146.     free();
  147.  
  148.     SDL_Surface* textSurface = TTF_RenderText_Solid(main_font, textureText.c_str(), textColor);
  149.     if( textSurface == NULL ) printf( "Unable to render text surface! SDL_ttf Error: %s\n", TTF_GetError() );
  150.     else
  151.     {
  152.         mTexture = SDL_CreateTextureFromSurface(main_renderer, textSurface);
  153.         if(mTexture == NULL)    printf( "Unable to create texture from rendered text! SDL Error: %s\n", SDL_GetError() );
  154.         else
  155.         {
  156.             mWidth = textSurface->w;
  157.             mHeight = textSurface->h;
  158.         }
  159.         SDL_FreeSurface(textSurface);
  160.     }
  161.     return mTexture!=NULL;
  162. }
  163.  
  164. #endif
  165.  
  166. void LTexture::free()
  167. {
  168.     if(mTexture!=NULL)
  169.     {
  170.         SDL_DestroyTexture(mTexture);
  171.         mTexture = NULL;
  172.         mWidth = 0;
  173.         mHeight = 0;
  174.     }
  175. }
  176.  
  177.  
  178.  
  179.  
  180. void LTexture::setColor(Uint8 red, Uint8 green, Uint8 blue)
  181. {
  182.     SDL_SetTextureColorMod(mTexture, red, green, blue);
  183.  
  184. }
  185.  
  186. void LTexture::setBlendMode(SDL_BlendMode blending)
  187. {
  188.     SDL_SetTextureBlendMode(mTexture, blending);
  189. }
  190.  
  191. void LTexture::setAlpha(Uint8 alpha)
  192. {
  193.     SDL_SetTextureAlphaMod(mTexture, alpha);
  194. }
  195.  
  196. void LTexture::render(int x, int y, SDL_Rect* clip, double angle, SDL_Point* center, SDL_RendererFlip flip)
  197. {
  198.     SDL_Rect renderQuad = {x,y,mWidth,mHeight};
  199.     if(clip!=NULL)
  200.     {
  201.         renderQuad.w = clip->w;
  202.         renderQuad.h = clip->h;
  203.     }
  204.     SDL_RenderCopyEx(main_renderer, mTexture, clip, &renderQuad, angle, center, flip);
  205. }
  206.  
  207.  
  208. int LTexture::getWidth()
  209. {
  210.     return mWidth;
  211. }
  212.  
  213. int LTexture::getHeight()
  214. {
  215.     return mHeight;
  216. }
  217.  
  218. bool init()
  219. {
  220.     bool success = true;
  221.     if( SDL_Init( SDL_INIT_VIDEO ) < 0 )
  222.     {
  223.         printf( "SDL could not initialize! SDL Error: %s\n", SDL_GetError() );
  224.         success = false;
  225.     }
  226.     else
  227.     {
  228.         if(!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY,"1")) printf("Warning: Linear texture filtering not enabled!" );
  229.         main_window = SDL_CreateWindow("PASA",0,0,SCREEN_WIDTH,SCREEN_HEIGHT,SDL_WINDOW_SHOWN);
  230.         if(main_window==NULL)
  231.         {
  232.             printf( "Window could not be created! SDL Error: %s\n", SDL_GetError() );
  233.             success = false;
  234.         }
  235.         else
  236.         {
  237.             main_renderer = SDL_CreateRenderer(main_window,-1,SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
  238.             if( main_renderer == NULL )
  239.             {
  240.                 printf( "Renderer could not be created! SDL Error: %s\n", SDL_GetError() );
  241.                 success = false;
  242.             }
  243.             else
  244.             {
  245.                 SDL_SetRenderDrawColor(main_renderer, 0xFF,0xFF,0xFF,0xFF);
  246.                 int imgFlags = IMG_INIT_PNG;
  247.                 if(!(IMG_Init(imgFlags)&imgFlags))
  248.                 {
  249.                     printf( "SDL_image could not initialize! SDL_image Error: %s\n", IMG_GetError() );
  250.                     success = false;
  251.                 }
  252.                 if( TTF_Init() == -1 )
  253.                 {
  254.                     printf( "SDL_ttf could not initialize! SDL_ttf Error: %s\n", TTF_GetError() );
  255.                     success = false;
  256.                 }
  257.             }
  258.         }
  259.     }
  260.     return success;
  261. }
  262.  
  263. bool loadMedia()
  264. {
  265.     bool success = true;
  266.  
  267.     main_font = TTF_OpenFont("boy.ttf", Font_WIDTH);
  268.     if(main_font==NULL)
  269.     {
  270.         printf( "Failed to load font! SDL_ttf Error: %s\n", TTF_GetError() );
  271.         success = false;
  272.     }
  273.     else
  274.     {
  275.         SDL_Color hColor = {0xD3,0xFF,0xCE};
  276.         if(!header.loadFromRenderedText(date,hColor))
  277.         {
  278.             printf( "Failed to render text texture!\n" );
  279.             success = false;
  280.         }
  281.     }
  282.     //Load dot texture
  283.     if( !gDotTexture.loadFromFile( "indi.png" ) )
  284.     {
  285.         printf( "Failed to load dot texture!\n" );
  286.         success = false;
  287.     }
  288.  
  289.     return success;
  290. }
  291.  
  292. void close()
  293. {
  294.     for(int i=0; i<50; i++)
  295.     {
  296.         mainTextTexture[i].free();
  297.     }
  298.     gDotTexture.free();
  299.     header.free();
  300.     TTF_CloseFont(main_font);
  301.     main_font = NULL;
  302.     SDL_DestroyRenderer(main_renderer);
  303.     main_renderer = NULL;
  304.     SDL_DestroyWindow(main_window);
  305.  
  306.     main_window = NULL;
  307.     TTF_Quit();
  308.     IMG_Quit();
  309.     SDL_Quit();
  310. }
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336. int main(int argn, char* args[])
  337. {
  338.  
  339.     int i = 0,z=0,p=0,q,count=0,x=0,current_line=0,c=0,total_line=0,flag=0,backspace_check=0,length,side_count=0;
  340.     int left_sign=0,tchar[i]={0},indi_xpos,indi_xpos_width[1000],final_indi_xpos,huda,left_check,middle_backspace=0;
  341.     char s[1001000],v[100][2002],ctemp[1000],char_temp,stemp[1000];
  342.  
  343.  
  344.     // printf("ENTER DATE. In format 11 10 2019!\n");
  345.     // scanf("%d %d %d", &day, &month, &year);
  346.     // if(month==1) sprintf(date, "%d th January, %d", day, year);
  347.     // else if(month==2) sprintf(date, "%d th February, %d", day, year);
  348.     // else if(month==3) sprintf(date, "%d th March, %d", day, year);
  349.     // else if(month==4) sprintf(date, "%d th April, %d", day, year);
  350.     // else if(month==5) sprintf(date, "%d th May, %d", day, year);
  351.     // else if(month==6) sprintf(date, "%d th June, %d", day, year);
  352.     // else if(month==7) sprintf(date, "%d th July, %d", day, year);
  353.     // else if(month==8) sprintf(date, "%d th August, %d", day, year);
  354.     // else if(month==9) sprintf(date, "%d th September, %d", day, year);
  355.     // else if(month==10) sprintf(date, "%d th October, %d", day, year);
  356.     // else if(month==11) sprintf(date, "%d th Novermber, %d", day, year);
  357.     sprintf(date, "%d th December, %d", day, year);
  358.  
  359.  
  360.     if(!init()) printf("Failed to initialize/n");
  361.     else
  362.     {
  363.         if(!loadMedia()) printf("Failed to load media\n");
  364.         else
  365.         {
  366.  
  367.             bool quit = false;
  368.             SDL_Event e;
  369.             SDL_Color textColor = {0xFF,0xFF,0xFF};
  370.             std::string inputText[50];
  371.             std::string copyText[50];
  372.             std::string sh;
  373.             //for(int k=0; k<50; k++) inputText[k] = "";
  374.             Dot dot;
  375.             SDL_StartTextInput();
  376.             while(!quit)
  377.             {
  378.                 bool renderText = false;
  379.  
  380.                 while(SDL_PollEvent(&e)!=0)
  381.                 {
  382.                    
  383.  
  384.                     if(e.type == SDL_QUIT) quit = true;
  385.  
  386.  
  387.                     else if(e.type == SDL_KEYDOWN)
  388.                     {
  389.                        
  390.  
  391.                         huda=1;
  392.  
  393.  
  394.                         //backspace key
  395.  
  396.  
  397.  
  398.  
  399.  
  400.                         if( e.key.keysym.sym == SDLK_BACKSPACE )
  401.                         {
  402.                             if(left_sign<1)
  403.                             {
  404.  
  405.                                 i=current_line;
  406.  
  407.  
  408.  
  409.  
  410.                                 //backspace main part
  411.  
  412.  
  413.  
  414.                                 if(inputText[i].length()==0&&current_line!=0)
  415.                                 {
  416.  
  417.                                  
  418.                                     //majher ekta line kaatle
  419.  
  420.  
  421.                                     if(current_line<total_line)
  422.                                     {
  423.                                       for(int a=0;a<total_line-current_line;a++)
  424.                                       {
  425.                                         sh=inputText[i+a];
  426.                                         inputText[i+a]=inputText[i+1+a];
  427.                                         inputText[i+1+a]=sh;
  428.                                         mainTextTexture[i+a].loadFromRenderedText( inputText[i+a].c_str(), textColor );
  429.                                       }
  430.                                     }
  431.  
  432.                                     if(total_line>0)total_line--;
  433.                                     current_line--;
  434.                                     i=current_line;
  435.                                     left_sign=0;
  436.                                    
  437.  
  438.  
  439.  
  440.                                     if(mainTextTexture[i].getWidth()>=SCREEN_WIDTH-100&&total_line>0) inputText[i].pop_back();
  441.                                     renderText = false;
  442.                                     mainTextTexture[i].loadFromRenderedText( inputText[i].c_str(), textColor );
  443.                                 }
  444.  
  445.                                 //first line zodi delete dite thaki
  446.  
  447.                                 else if(inputText[i].length()==0&&current_line==0)
  448.                                 {
  449.                                      if(current_line<total_line)
  450.                                     {
  451.                                       for(int a=0;a<total_line;a++)
  452.                                       {
  453.                                         sh=inputText[i+a];
  454.                                         inputText[i+a]=inputText[i+1+a];
  455.                                         inputText[i+1+a]=sh;
  456.                                         mainTextTexture[i+a].loadFromRenderedText( inputText[i+a].c_str(), textColor );
  457.                                       }
  458.                                     }
  459.  
  460.                                     if(total_line>0)total_line--;
  461.                                     current_line=0;
  462.                                     i=current_line;
  463.                                     left_sign=0;
  464.                                    
  465.                                     left_sign=strlen(inputText[i].c_str());
  466.                                 }
  467.  
  468.  
  469.  
  470.  
  471.  
  472.  
  473.  
  474.                                 else if(inputText[i].length() > 0)
  475.                                 {
  476.                                     inputText[i].pop_back();
  477.                                     renderText = true;
  478.                                 }
  479.                             }
  480.                             else
  481.                                 {
  482.                                     middle_backspace=1;
  483.                                     renderText=true;
  484.                                 }
  485.                         }
  486.  
  487.  
  488.  
  489.  
  490.  
  491.                         //Up key
  492.  
  493.  
  494.  
  495.                         else if( e.key.keysym.sym == SDLK_UP )
  496.                         {
  497.                            
  498.                          
  499.  
  500.                             if(current_line>0)
  501.                            
  502.                           {
  503.                             left_sign=0;
  504.                             if(mainTextTexture[i-1].getWidth()>=SCREEN_WIDTH-100)backspace_check=1;
  505.                             current_line--;
  506.                             i=current_line;
  507.                             renderText=true;
  508.  
  509.                           }
  510.                             else
  511.                             {
  512.                                 i=0;
  513.                                 renderText = true;
  514.                             }
  515.                         }
  516.  
  517.  
  518.  
  519.  
  520.  
  521.  
  522.                         //down key
  523.  
  524.  
  525.  
  526.                         else if( e.key.keysym.sym == SDLK_DOWN &&inputText[i].length()>0)
  527.                         {
  528.                            
  529.                             if(current_line<total_line)
  530.                             {
  531.                                 left_sign=0;
  532.                                 if(mainTextTexture[i+1].getWidth()>=SCREEN_WIDTH-100)backspace_check=1;
  533.                                 x--;
  534.                                 current_line++;
  535.                                 i=current_line;
  536.                                
  537.                             }
  538.  
  539.  
  540.  
  541.                             renderText = true;
  542.                         }
  543.                            
  544.  
  545.  
  546.  
  547.  
  548.                                 //right key
  549.  
  550.                         else if( e.key.keysym.sym == SDLK_RIGHT &&side_count<length)
  551.                         {
  552.                            
  553.                           if(left_sign>0)left_sign--;
  554.                         }
  555.  
  556.  
  557.  
  558.  
  559.  
  560.                             //left key
  561.                           else if( e.key.keysym.sym == SDLK_LEFT )
  562.                         {
  563.  
  564.                             //left overflow check
  565.                             if(mainTextTexture[i].getWidth()>=SCREEN_WIDTH-100)
  566.                             {
  567.                                 backspace_check=1;
  568.                                 left_check=1;
  569.                             }
  570.                            
  571.                             if(indi_xpos>0)
  572.                             {
  573.                             if(left_sign==0)left_sign+=1;
  574.                             else
  575.                                 left_sign++;
  576.                             }
  577.                         }
  578.  
  579.  
  580.  
  581.  
  582.                         //enter key
  583.  
  584.  
  585.  
  586.                         if( e.key.keysym.sym == SDLK_RETURN)
  587.                         {
  588.                             current_line++;
  589.                             total_line++;
  590.                             left_sign=0;
  591.                          
  592.  
  593.                             i=current_line;
  594.                            //jani na jhamela badhle dekhbo c++;
  595.                             if(inputText[i-1].length()==0)flag=1;
  596.                             //mainTextTexture[i].loadFromRenderedText( inputText[i].c_str(), textColor );
  597.  
  598.  
  599.                             renderText = false;
  600.                         }
  601.  
  602.  
  603.  
  604.  
  605.  
  606.                         //newline
  607.  
  608.  
  609.  
  610.  
  611.  
  612.                         int width = mainTextTexture[i].getWidth();
  613.                         if(width >= SCREEN_WIDTH-100)
  614.                         {
  615.                            if(backspace_check!=1)
  616.                            {
  617.  
  618.                             current_line++;
  619.                             i=current_line;
  620.                             total_line++;
  621.                            }
  622.                            else
  623.                             backspace_check=0;
  624.  
  625.                             renderText = true;
  626.                         }
  627.  
  628.                         //copy something
  629.  
  630.                         else if( e.key.keysym.sym == SDLK_c && SDL_GetModState() & KMOD_CTRL )
  631.                         {
  632.                             for(int ba=0; ba<=i; ba++)
  633.                             {
  634.                                 strcat(s,inputText[ba].c_str());
  635.                                 if(ba!=i)strcat(s,"\n");
  636.  
  637.  
  638.  
  639.                             }
  640.                             SDL_SetClipboardText(s);
  641.                             s[0]=0;
  642.                         }
  643.  
  644.                         //paste something
  645.  
  646.  
  647.                         else if( e.key.keysym.sym == SDLK_v && SDL_GetModState() & KMOD_CTRL )
  648.                         {
  649.  
  650.  
  651.  
  652.                             inputText[i] = inputText[i]+SDL_GetClipboardText();
  653.                             // int l=strlen(inputText[i].c_str());
  654.  
  655.                             // if(l*Font_WIDTH>=SCREEN_WIDTH-100)
  656.                             // {
  657.  
  658.                             // for(int j=0;j<l;j++)s[j]=SDL_GetClipboardText()[j];
  659.  
  660.                             //   for(p=0;p<100;p++)
  661.                             //   {
  662.                             //     for(q=0;q<2*(SCREEN_WIDTH-100)/Font_WIDTH;q++)
  663.                             //     {
  664.                             //       if(count>=l)
  665.                             //       {
  666.                             //         break;
  667.                             //           x=1;
  668.                             //       }
  669.  
  670.                             //       if(s[count]=='\n')break;
  671.  
  672.                             //       else
  673.                             //       {
  674.                             //         v[p][q]=s[count];
  675.                             //       }
  676.                             //       count++;
  677.                             //     }
  678.                             //     if(x==1)
  679.                             //     {
  680.                             //       break;
  681.                             //     }
  682.                             //     i++;
  683.  
  684.                             //       mainTextTexture[i].loadFromRenderedText( v[p], textColor );
  685.                             //         SDL_SetRenderDrawColor( main_renderer, 0x00, 0x00, 0x00, 0xFF );
  686.                             //      SDL_RenderClear( main_renderer );
  687.                             //      header.render( 0,0);
  688.                             //    for(int j=0; j<=i; j++ )  mainTextTexture[j].render( 0, j*50+ 50 );
  689.  
  690.                             //     SDL_RenderPresent( main_renderer );
  691.  
  692.                             //   }
  693.  
  694.                             //   count=0;
  695.                             //    renderText = false;
  696.                             //  }
  697.                             //  else
  698.                             renderText = true;
  699.                             z=1;
  700.  
  701.  
  702.                         }
  703.  
  704.  
  705.  
  706.                     }
  707.  
  708.  
  709.  
  710.  
  711.  
  712.  
  713.                     else if( e.type == SDL_TEXTINPUT )
  714.                     {
  715.                         if( !( SDL_GetModState() & KMOD_CTRL && ( e.text.text[ 0 ] == 'c' || e.text.text[ 0 ] == 'C' || e.text.text[ 0 ] == 'v' || e.text.text[ 0 ] == 'V' ) ) )
  716.                         {
  717.                             inputText[i] += e.text.text;
  718.                             renderText = true;
  719.                         }
  720.                     }
  721.  
  722.  
  723.  
  724.  
  725.  
  726.  
  727.                         //indicator
  728.  
  729.                        // printf("%c\n",inputText[i].c_str()[0] );
  730.  
  731.                         length=strlen(inputText[i].c_str());
  732.                         indi_xpos=length-left_sign;
  733.                         if(indi_xpos<0)indi_xpos=0;
  734.                  
  735.                        
  736.                         for(int as=0;as<=length;as++)
  737.                         {
  738.                             if(as<indi_xpos)ctemp[as]=inputText[i].c_str()[as];
  739.                             stemp[as]=inputText[i].c_str()[as];
  740.  
  741.  
  742.                         }
  743.                         stemp[length+1]=0;
  744.                         ctemp[indi_xpos]=0;
  745.                         if(indi_xpos!=0)
  746.                         {
  747.                             Ltemp.loadFromRenderedText( ctemp, textColor );
  748.                             final_indi_xpos=Ltemp.getWidth();
  749.                         }
  750.                         else
  751.                             final_indi_xpos=0;
  752.  
  753.                         if(huda==1)
  754.                         {
  755.                             printf("%d %d %d\n",length,indi_xpos,final_indi_xpos );
  756.                             huda=0;
  757.                         }
  758.  
  759.  
  760.                  
  761.                   }
  762.  
  763.                
  764.  
  765.                     if( renderText )
  766.                     {
  767.  
  768.                         if( inputText[i] != "" )
  769.                         {
  770.                             // //longer than window_width string
  771.                             //  if(x!=0)
  772.                             // {
  773.                             //   x=0;
  774.  
  775.                             //     mainTextTexture[i].loadFromRenderedText( v[p], textColor );
  776.  
  777.                             // }
  778.                             //printf("%s\n",stemp);
  779.  
  780.  
  781.                             //majhkhane kichu likhle
  782.  
  783.                             if(left_sign>=1&&mainTextTexture[i].getWidth()<SCREEN_WIDTH-100)
  784.                             {
  785.                                 if(middle_backspace==0)
  786.                                 {
  787.                                     for(int zx=length-1;zx>indi_xpos-1;zx--)
  788.                                     {
  789.                                         char_temp=stemp[zx];
  790.                                         stemp[zx]=stemp[zx-1];
  791.                                         stemp[zx-1]=char_temp;
  792.                                    
  793.  
  794.                                     }
  795.                                        
  796.                                      
  797.                                 }
  798.                                 else
  799.                                 {
  800.                                    
  801.                                     for(int zx=indi_xpos-1;zx<length-1;zx++)
  802.                                     {
  803.                                         char_temp=stemp[zx];
  804.                                         stemp[zx]=stemp[zx+1];
  805.                                         stemp[zx+1]=char_temp;
  806.                                    
  807.  
  808.                                     }
  809.  
  810.                                 }
  811.                                 for(int qw=0;qw<=length;qw++)inputText[i].pop_back();
  812.                             }
  813.  
  814.  
  815.                             inputText[i]=stemp;
  816.                             if(middle_backspace!=0)
  817.                             {
  818.                                 middle_backspace=0;
  819.                                 inputText[i].pop_back();
  820.  
  821.                             }
  822.                             //printf("%d\n",total_line);
  823.  
  824.  
  825.  
  826.                             mainTextTexture[i].loadFromRenderedText( inputText[i].c_str(), textColor );
  827.                             //copy paste
  828.                             if(z==1)
  829.                             {
  830.                                 i++;
  831.                                 current_line++;
  832.                                 total_line++;
  833.                                 z=0;
  834.                             }
  835.  
  836.  
  837.                         }
  838.  
  839.                         else
  840.                         {
  841.                             mainTextTexture[i].loadFromRenderedText( " ", textColor );
  842.                         }
  843.                     }
  844.  
  845.  
  846.  
  847.                     //enter dile space nibe
  848.  
  849.                     if(flag==1)
  850.                     {
  851.                         flag=0;
  852.                         inputText[i-1] +="@";
  853.                         mainTextTexture[i-1].loadFromRenderedText( "@", textColor );
  854.                     }
  855.                
  856.  
  857.                     SDL_SetRenderDrawColor( main_renderer, 0x00, 0x00, 0x00, 0xFF );
  858.                     SDL_RenderClear( main_renderer );
  859.                  
  860.                         //for blinking indicaotr
  861.                         c++;
  862.                         if(c%60>=25)
  863.                         gDotTexture.render( final_indi_xpos,current_line*50+50);
  864.                         if(c>60)c=0;
  865.                    
  866.                
  867.                     header.render( 0,0);
  868.                     for(int j=0; j<=total_line; j++ )   mainTextTexture[j].render( 0, j*50+ 50 );
  869.  
  870.                     SDL_RenderPresent( main_renderer );
  871.                
  872.  
  873.  
  874.             }
  875.             SDL_StopTextInput();
  876.  
  877.         }
  878.     }
  879.     close();
  880.     return 0;
  881. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement