Advertisement
j0h

ttf.h sdl header

j0h
Apr 8th, 2023
773
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.82 KB | None | 0 0
  1. #include <SDL/SDL.h>
  2. #include <SDL/SDL_ttf.h>
  3. #include <string>
  4.  
  5. SDL_Surface* Backbuffer = NULL;
  6. TTF_Font* Font = NULL;
  7. int FontSize=48;  /////dirty hack lol
  8. int FS();
  9. void DrawOutlineText(SDL_Surface* surface, char* string, int x, int y, TTF_Font* font, Uint8 r, Uint8 g, Uint8 b);
  10. void DrawTTFFonts(char * text,int line); //assume everything
  11. //void DrawTTFFonts(SDL_Surface* surface, char* string, int x, int y, TTF_Font* font, Uint8 r, Uint8 g, Uint8 b); //IDK, maybe I can make a better function
  12. //void DrawOutlineText(SDL_Surface* surface, std::string string, int x, int y, TTF_Font* font, Uint8 r, Uint8 g, Uint8 b);
  13. bool ProgramIsRunning();
  14. /*
  15.  *
  16.  #include <string>
  17.  
  18. extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Solid(TTF_Font *font, const char *text, SDL_Color fg);
  19. extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUTF8_Solid(TTF_Font *font, const char *text, SDL_Color fg);
  20. extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUNICODE_Solid(TTF_Font *font, const Uint16 *text, SDL_Color fg);
  21.  
  22. extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Solid(TTF_Font *font, string *text, SDL_Color fg);
  23. extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUTF8_Solid(TTF_Font *font, string *text, SDL_Color fg);
  24. extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUNICODE_Solid(TTF_Font *font, string *text, SDL_Color fg);
  25.  *
  26.  *
  27.  Honestly fixing it is probably a wormhole
  28.  * */
  29. int FS(){
  30.     return FontSize;
  31.     }
  32.  //void DrawTTFFonts(SDL_Surface* surface, std::string, int x, int y, TTF_Font* font, Uint8 r, Uint8 g, Uint8 b);
  33.  void DrawTTFFonts(char * text ,int line){
  34. //track lines, clear screen if flagged, increment line by fontsize+margin
  35. //Font size (FS*lines)+margin>=screenHeight clear screen and keep typing
  36. //add functions for text animation
  37.  printf(" %d\n", line);
  38. int margin=5;
  39. int var= (FS()*line)+margin;
  40. if(line==0){
  41.    DrawOutlineText(Backbuffer, text, 10, 10, Font, 255, 0, 0);
  42. }
  43.      if(line>=1){
  44.              DrawOutlineText(Backbuffer, text, 10, var, Font, 255, 0, 0);
  45.          }
  46.  
  47.          }
  48.  
  49. void DrawOutlineText(SDL_Surface* surface, char* string, int x, int y, TTF_Font* font, Uint8 r, Uint8 g, Uint8 b){
  50. //void DrawOutlineText(SDL_Surface* surface, std::string string, int x, int y, TTF_Font* font, Uint8 r, Uint8 g, Uint8 b){
  51.     SDL_Surface* renderedText = NULL;
  52.  
  53.     SDL_Color color;
  54.  
  55.     color.r = r;
  56.     color.g = g;
  57.     color.b = b;
  58.  
  59.     renderedText = TTF_RenderText_Solid(font, string, color); //needs to be fixed in sdl lib in /usr/local/include/SDL_ttf.h
  60.  
  61.     SDL_Rect pos;
  62.  
  63.     pos.x = x;
  64.     pos.y = y;
  65.  
  66.     SDL_BlitSurface(renderedText, NULL, surface, &pos);
  67.     SDL_FreeSurface(renderedText);
  68. }
  69.  
  70. bool ProgramIsRunning(){
  71.     SDL_Event event;
  72.     bool running = true;
  73.     while(SDL_PollEvent(&event)){
  74.         if(event.type == SDL_QUIT)
  75.             running = false;
  76.     }
  77.     return running;
  78. }
  79.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement