Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 24.84 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( "white_nigga.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 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[100]={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.                              
  406.  
  407.  
  408.  
  409.  
  410.                                 //backspace main part
  411.  
  412.  
  413.  
  414.                                 if(inputText[current_line].length()==0&&current_line!=0)
  415.                                 {
  416.  
  417.                                  
  418.                                     //majher ekta line kaatle
  419.  
  420.                                     printf("%d %d\n",current_line,total_line );
  421.                                     if(current_line<total_line)
  422.                                     {
  423.                                       for(int a=0;a<total_line-current_line;a++)
  424.                                       {
  425.                                         sh=inputText[current_line+a];
  426.                                         inputText[current_line+a]=inputText[current_line+1+a];
  427.                                         inputText[current_line+1+a]=sh;
  428.                                         mainTextTexture[current_line+a].loadFromRenderedText( inputText[current_line+a].c_str(), textColor );
  429.                                       }
  430.                                     }
  431.  
  432.                                     if(total_line>0)total_line--;
  433.                                     current_line--;
  434.                                  
  435.                                     left_sign=0;
  436.                                    
  437.                                    
  438.  
  439.  
  440.                                     if(mainTextTexture[current_line].getWidth()>=SCREEN_WIDTH-100&&total_line>=0) inputText[current_line].pop_back();
  441.                                     renderText = false;
  442.                                     mainTextTexture[current_line].loadFromRenderedText( inputText[current_line].c_str(), textColor );
  443.                                 }
  444.  
  445.                                 //first line zodi delete dite thaki
  446.  
  447.                                 else if(inputText[current_line].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[current_line+a];
  454.                                         inputText[current_line+a]=inputText[current_line+1+a];
  455.                                         inputText[current_line+1+a]=sh;
  456.                                         mainTextTexture[current_line+a].loadFromRenderedText( inputText[current_line+a].c_str(), textColor );
  457.                                       }
  458.                                     }
  459.  
  460.                                     if(total_line>0)total_line--;
  461.                                     current_line=0;
  462.                                    
  463.                                     left_sign=0;
  464.                                    
  465.                                     left_sign=strlen(inputText[current_line].c_str());
  466.                                 }
  467.  
  468.  
  469.  
  470.  
  471.  
  472.  
  473.  
  474.                                 else if(inputText[current_line].length() > 0)
  475.                                 {
  476.                                     inputText[current_line].pop_back();
  477.                                     renderText = true;
  478.                                 }
  479.                             }
  480.  
  481.                             else
  482.                                 {
  483.                                     middle_backspace=1;
  484.                                     renderText=true;
  485.                                 }
  486.                                 // printf("%d\n",left_sign );
  487.                         }
  488.  
  489.  
  490.  
  491.  
  492.  
  493.                         //Up key
  494.  
  495.  
  496.  
  497.                         else if( e.key.keysym.sym == SDLK_UP )
  498.                         {
  499.                            
  500.                          
  501.  
  502.                             if(current_line>0)
  503.                            
  504.                           {
  505.                             left_sign=0;
  506.                             if(mainTextTexture[current_line-1].getWidth()>=SCREEN_WIDTH-100)backspace_check=1;
  507.                             current_line--;
  508.                      
  509.                             renderText=true;
  510.  
  511.                           }
  512.                             else
  513.                             {
  514.                                 current_line=0;
  515.                                 renderText = true;
  516.                             }
  517.                         }
  518.  
  519.  
  520.  
  521.  
  522.  
  523.  
  524.                         //down key
  525.  
  526.  
  527.  
  528.                         else if( e.key.keysym.sym == SDLK_DOWN &&inputText[current_line].length()>0)
  529.                         {
  530.                            
  531.                             if(current_line<total_line)
  532.                             {
  533.                                 left_sign=0;
  534.                                 if(mainTextTexture[current_line+1].getWidth()>=SCREEN_WIDTH-100)backspace_check=1;
  535.                                 x--;
  536.                                 current_line++;
  537.                    
  538.                                
  539.                             }
  540.  
  541.  
  542.  
  543.                             renderText = true;
  544.                         }
  545.                            
  546.  
  547.  
  548.  
  549.  
  550.                                 //right key
  551.  
  552.                         else if( e.key.keysym.sym == SDLK_RIGHT &&side_count<length)
  553.                         {
  554.                            
  555.                           if(left_sign>0)left_sign--;
  556.                         }
  557.  
  558.  
  559.  
  560.  
  561.  
  562.                             //left key
  563.                           else if( e.key.keysym.sym == SDLK_LEFT )
  564.                         {
  565.  
  566.                             //left overflow check
  567.                             if(mainTextTexture[current_line].getWidth()>=SCREEN_WIDTH-100)
  568.                             {
  569.                                 backspace_check=1;
  570.                                 left_check=1;
  571.                             }
  572.                            
  573.                             if(indi_xpos>0)
  574.                             {
  575.                             if(left_sign==0)left_sign+=1;
  576.                             else
  577.                                 left_sign++;
  578.                             }
  579.                         }
  580.  
  581.  
  582.  
  583.  
  584.                         //enter key
  585.  
  586.  
  587.  
  588.                         if( e.key.keysym.sym == SDLK_RETURN)
  589.                         {
  590.                             current_line++;
  591.                             total_line++;
  592.                             left_sign=0;
  593.                          
  594.  
  595.                  
  596.                            //jani na jhamela badhle dekhbo c++;
  597.                             if(inputText[current_line-1].length()==0)flag=1;
  598.                             //mainTextTexture[i].loadFromRenderedText( inputText[i].c_str(), textColor );
  599.  
  600.  
  601.                             renderText = false;
  602.                         }
  603.  
  604.  
  605.  
  606.  
  607.  
  608.                         //newline
  609.  
  610.  
  611.  
  612.  
  613.  
  614.                         int width = mainTextTexture[current_line].getWidth();
  615.                         if(width >= SCREEN_WIDTH-100)
  616.                         {
  617.                            if(backspace_check!=1)
  618.                            {
  619.  
  620.                             current_line++;
  621.              
  622.                             total_line++;
  623.                            }
  624.                            else
  625.                             backspace_check=0;
  626.  
  627.                             renderText = true;
  628.                         }
  629.  
  630.                         //copy something
  631.  
  632.                         else if( e.key.keysym.sym == SDLK_c && SDL_GetModState() & KMOD_CTRL )
  633.                         {
  634.                             for(int ba=0; ba<=current_line; ba++)
  635.                             {
  636.                                 strcat(s,inputText[ba].c_str());
  637.                                 if(ba!=current_line)strcat(s,"\n");
  638.  
  639.  
  640.  
  641.                             }
  642.                             SDL_SetClipboardText(s);
  643.                             s[0]=0;
  644.                         }
  645.  
  646.                         //paste something
  647.  
  648.  
  649.                         else if( e.key.keysym.sym == SDLK_v && SDL_GetModState() & KMOD_CTRL )
  650.                         {
  651.  
  652.  
  653.  
  654.                             inputText[current_line] = inputText[current_line]+SDL_GetClipboardText();
  655.                             // int l=strlen(inputText[i].c_str());
  656.  
  657.                             // if(l*Font_WIDTH>=SCREEN_WIDTH-100)
  658.                             // {
  659.  
  660.                             // for(int j=0;j<l;j++)s[j]=SDL_GetClipboardText()[j];
  661.  
  662.                             //   for(p=0;p<100;p++)
  663.                             //   {
  664.                             //     for(q=0;q<2*(SCREEN_WIDTH-100)/Font_WIDTH;q++)
  665.                             //     {
  666.                             //       if(count>=l)
  667.                             //       {
  668.                             //         break;
  669.                             //           x=1;
  670.                             //       }
  671.  
  672.                             //       if(s[count]=='\n')break;
  673.  
  674.                             //       else
  675.                             //       {
  676.                             //         v[p][q]=s[count];
  677.                             //       }
  678.                             //       count++;
  679.                             //     }
  680.                             //     if(x==1)
  681.                             //     {
  682.                             //       break;
  683.                             //     }
  684.                             //     i++;
  685.  
  686.                             //       mainTextTexture[i].loadFromRenderedText( v[p], textColor );
  687.                             //         SDL_SetRenderDrawColor( main_renderer, 0x00, 0x00, 0x00, 0xFF );
  688.                             //      SDL_RenderClear( main_renderer );
  689.                             //      header.render( 0,0);
  690.                             //    for(int j=0; j<=i; j++ )  mainTextTexture[j].render( 0, j*50+ 50 );
  691.  
  692.                             //     SDL_RenderPresent( main_renderer );
  693.  
  694.                             //   }
  695.  
  696.                             //   count=0;
  697.                             //    renderText = false;
  698.                             //  }
  699.                             //  else
  700.                             renderText = true;
  701.                             z=1;
  702.  
  703.  
  704.                         }
  705.  
  706.  
  707.  
  708.                     }
  709.  
  710.  
  711.  
  712.  
  713.  
  714.  
  715.                     else if( e.type == SDL_TEXTINPUT )
  716.                     {
  717.                         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' ) ) )
  718.                         {
  719.                             inputText[current_line] += e.text.text;
  720.                             renderText = true;
  721.                         }
  722.                     }
  723.  
  724.  
  725.  
  726.  
  727.  
  728.  
  729.                         //indicator
  730.  
  731.                        // printf("%c\n",inputText[i].c_str()[0] );
  732.  
  733.                         length=strlen(inputText[current_line].c_str());
  734.                         indi_xpos=length-left_sign;
  735.                         if(indi_xpos<0)indi_xpos=0;
  736.                  
  737.                        
  738.                         for(int as=0;as<=length;as++)
  739.                         {
  740.                             if(as<indi_xpos)ctemp[as]=inputText[current_line].c_str()[as];
  741.                             stemp[as]=inputText[current_line].c_str()[as];
  742.  
  743.  
  744.                         }
  745.                         stemp[length+1]=0;
  746.                         ctemp[indi_xpos]=0;
  747.                         if(indi_xpos!=0)
  748.                         {
  749.                             Ltemp.loadFromRenderedText( ctemp, textColor );
  750.                             final_indi_xpos=Ltemp.getWidth();
  751.                         }
  752.                         else
  753.                             final_indi_xpos=0;
  754.  
  755.                         if(huda==1)
  756.                         {
  757.                             printf("%d %d %d\n",length,indi_xpos,final_indi_xpos );
  758.                             huda=0;
  759.                         }
  760.  
  761.  
  762.                  
  763.                   }
  764.  
  765.                
  766.  
  767.                     if( renderText )
  768.                     {
  769.  
  770.                         if( inputText[current_line] != "" )
  771.                         {
  772.                             // //longer than window_width string
  773.                             //  if(x!=0)
  774.                             // {
  775.                             //   x=0;
  776.  
  777.                             //     mainTextTexture[i].loadFromRenderedText( v[p], textColor );
  778.  
  779.                             // }
  780.                             //printf("%s\n",stemp);
  781.  
  782.  
  783.                             //majhkhane kichu likhle
  784.  
  785.                             if(left_sign>=1&&mainTextTexture[current_line].getWidth()<SCREEN_WIDTH-100)
  786.                             {
  787.                                 if(middle_backspace==0)
  788.                                 {
  789.                                     for(int zx=length-1;zx>indi_xpos-1;zx--)
  790.                                     {
  791.                                         char_temp=stemp[zx];
  792.                                         stemp[zx]=stemp[zx-1];
  793.                                         stemp[zx-1]=char_temp;
  794.                                    
  795.  
  796.                                     }
  797.                                        
  798.                                      
  799.                                 }
  800.                                 else
  801.                                 {
  802.                                    
  803.                                     for(int zx=indi_xpos-1;zx<length-1;zx++)
  804.                                     {
  805.                                         char_temp=stemp[zx];
  806.                                         stemp[zx]=stemp[zx+1];
  807.                                         stemp[zx+1]=char_temp;
  808.                                    
  809.  
  810.                                     }
  811.  
  812.                                 }
  813.                                 for(int qw=0;qw<=length;qw++)inputText[current_line].pop_back();
  814.                             }
  815.  
  816.  
  817.                             inputText[current_line]=stemp;
  818.                             if(middle_backspace!=0)
  819.                             {
  820.                                 middle_backspace=0;
  821.                                 inputText[current_line].pop_back();
  822.  
  823.                             }
  824.                             //printf("%d\n",total_line);
  825.  
  826.  
  827.  
  828.                             mainTextTexture[current_line].loadFromRenderedText( inputText[current_line].c_str(), textColor );
  829.                             //copy paste
  830.                             if(z==1)
  831.                             {
  832.                                 current_line++;
  833.                                 total_line++;
  834.                                 z=0;
  835.                             }
  836.  
  837.  
  838.                         }
  839.  
  840.                         else
  841.                         {
  842.                             mainTextTexture[current_line].loadFromRenderedText( " ", textColor );
  843.                         }
  844.                     }
  845.  
  846.  
  847.  
  848.                     //enter dile space nibe
  849.  
  850.                     if(flag==1)
  851.                     {
  852.                         flag=0;
  853.                         inputText[current_line-1] +="@";
  854.                         mainTextTexture[current_line-1].loadFromRenderedText( "@", textColor );
  855.                     }
  856.                
  857.  
  858.                     SDL_SetRenderDrawColor( main_renderer, 0x00, 0x00, 0x00, 0xFF );
  859.                     SDL_RenderClear( main_renderer );
  860.                  
  861.                         //for blinking indicaotr
  862.                         c++;
  863.                         if(c%60>=25)
  864.                         gDotTexture.render( final_indi_xpos,current_line*50+50);
  865.                         if(c>60)c=0;
  866.                    
  867.                
  868.                     header.render( 0,0);
  869.                     for(int j=0; j<=total_line; j++ )   mainTextTexture[j].render( 0, j*50+ 50 );
  870.  
  871.                     SDL_RenderPresent( main_renderer );
  872.                
  873.  
  874.  
  875.             }
  876.             SDL_StopTextInput();
  877.  
  878.         }
  879.     }
  880.     close();
  881.     return 0;
  882. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement