Guest User

Untitled

a guest
Nov 8th, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.98 KB | None | 0 0
  1. //graphics.c
  2. #include <SDL.h>
  3. #include <SDL_gfxPrimitives.h>
  4. #include <math.h>
  5. #include <SDL_image.h>
  6. #include <SDL_ttf.h>
  7. #include <stdlib.h>
  8. #include <stdbool.h>
  9.  
  10. typedef struct Kerdes
  11. {
  12.     int nehezseg;
  13.     char kerdes[50];
  14.     char A[30];
  15.     char B[30];
  16.     char C[30];
  17.     char D[30];
  18.     char helyes;
  19.     char kategoria[30];
  20. } Kerdes;
  21.  
  22. Kerdes* beolvas()
  23. {
  24.     FILE *fajl;
  25.     fajl=fopen("loim.txt", "r");
  26.  
  27.     Kerdes **tomb=(Kerdes**) malloc(15*sizeof(Kerdes));
  28.  
  29.     char sor[128];
  30.     fgets(sor, 128, fajl);
  31.     //bool megfelelo=false;
  32.     int i;
  33.     for(i=0; i<4; ++i)
  34.     {
  35.         tomb[i]=(Kerdes*) malloc(sizeof(Kerdes));
  36.         sscanf(fgets(sor,255,fajl),"%d\t%[^\t]\t%[^\t]\t%[^\t]\t%[^\t]\t%[^\t]\t%c\t%s", &(tomb[i]->nehezseg), &(tomb[i]->kerdes), &(tomb[i]->A), &(tomb[i]->B), &(tomb[i]->C), &(tomb[i]->D), &(tomb[i]->helyes), &(tomb[i]->kategoria));
  37.         printf(stdout,"%d %s %s", tomb[i]->nehezseg, tomb[i]->kerdes, tomb[i]->A);
  38.     }
  39.  
  40.     return tomb;
  41. }
  42.  
  43. int main(int argc, char *argv[])
  44. {
  45.     SDL_Event ev;
  46.     graphics();
  47.  
  48.     while (SDL_WaitEvent(&ev) && ev.type != SDL_QUIT)
  49.     {
  50.     }
  51.  
  52.     /* varunk a kilepesre */
  53.  
  54.     /* ablak bezarasa */
  55.  
  56.     return 0;
  57. }
  58.  
  59.  
  60. //main.c
  61.  
  62. #include <SDL.h>
  63. #include <SDL_gfxPrimitives.h>
  64. #include <math.h>
  65. #include <SDL_image.h>
  66. #include <SDL_ttf.h>
  67. #include <stdbool.h>
  68. #include <string.h>
  69.  
  70. short int ACx[6]= {67, 92, 317, 343, 311, 97};
  71. short int BDx[6]= {346, 371, 596, 622, 596, 371};
  72.  
  73. short int ABy[6]= {644, 626, 626, 644, 662, 662};
  74. short int CDy[6]= {692, 674, 674, 692, 710, 710};
  75.  
  76. short int Kx[6]= {67, 92, 596, 622, 596, 92};
  77. short int Ky[6]= {584, 556, 556, 584, 612, 612};
  78.  
  79. Uint32 fekete=0x000000FF;
  80. Uint32 sarga=0xe58328FF;
  81. Uint32 kek=0x1613d3FF;
  82. Uint32 zold=0x33cc33FF;
  83.  
  84. typedef struct Kerdes
  85. {
  86.     int nehezseg;
  87.     char kerdes[50];
  88.     char A[30];
  89.     char B[30];
  90.     char C[30];
  91.     char D[30];
  92.     char helyes;
  93.     char kategoria[30];
  94.  
  95.  
  96. } Kerdes;
  97.  
  98. typedef struct Doboz
  99. {
  100.     short int X[6];
  101.     short int Y[6];
  102.     Uint32 szin;
  103.  
  104. } Doboz;
  105.  
  106. void hatter_betolt(SDL_Surface *hova)
  107. {
  108.     SDL_Surface *hatter=IMG_Load("hatter.jpg");
  109.  
  110.     SDL_Rect src= {620, 280, 720, 720};
  111.     SDL_Rect dest= {0, 0, 720, 720};
  112.  
  113.     SDL_BlitSurface(hatter, &src, hova, &dest);
  114.     SDL_FreeSurface(hatter);
  115.  
  116. }
  117.  
  118. void doboz_rajzol(SDL_Surface *hova, short* eredetiX, short *eredetiY, Uint32 *szin)//kék polygon kitöltéséhez feketével generál koordinátákat
  119. {
  120.     filledPolygonColor(hova, eredetiX, eredetiY, 6, szin);
  121.     polygonColor(hova, eredetiX, eredetiY, 6, 0x1613d3FF);
  122.     aapolygonRGBA(hova, eredetiX, eredetiY, 6, 0,0,255,255);
  123.     SDL_Flip(hova);
  124. }
  125.  
  126. void kerdes_kiir(SDL_Surface *hova, Kerdes *kiir)
  127. {
  128.     short int ACx[6]= {67, 92, 317, 343, 311, 97};
  129.     short int BDx[6]= {346, 371, 596, 622, 596, 371};
  130.  
  131.     short int ABy[6]= {644, 626, 626, 644, 662, 662};
  132.     short int CDy[6]= {692, 674, 674, 692, 710, 710};
  133.  
  134.     short int Kx[6]= {67, 92, 596, 622, 596, 92};
  135.     short int Ky[6]= {584, 556, 556, 584, 612, 612};
  136.  
  137.     SDL_Surface *szovegdobozba; //mi kerül a szövegdobozba (6 csúcsú polygon)
  138.  
  139.     SDL_Rect src= {0, 0, 720, 720};
  140.     SDL_Rect dest= {92, 637, 720, 720};
  141.  
  142.     TTF_Font *font;
  143.     SDL_Color feher= {255, 255, 255};
  144.     SDL_Color sarga= {255,153,51};
  145.  
  146.     TTF_Init();
  147.     font=TTF_OpenFont("Arial.ttf", 14);
  148.  
  149.     dest.x=ACx[1];
  150.     dest.y=ABy[0]-7; //vonal közepétől a font magasságának fele
  151.     szovegdobozba = TTF_RenderUTF8_Blended(font, "● A: ", sarga );
  152.     SDL_BlitSurface(szovegdobozba,&src,hova,&dest);
  153.  
  154.     dest.x+=30;
  155.     szovegdobozba = TTF_RenderUTF8_Blended(font, kiir->A, feher );
  156.     fprintf(stdout, "%s", kiir->A);
  157.     SDL_BlitSurface(szovegdobozba,&src,hova,&dest);
  158.  
  159.     dest.x=BDx[1];
  160.     dest.y=ABy[0]-7;
  161.     szovegdobozba = TTF_RenderUTF8_Blended(font, "● B: ", sarga );
  162.     SDL_BlitSurface(szovegdobozba,&src,hova,&dest);
  163.     dest.x+=30;
  164.     szovegdobozba = TTF_RenderUTF8_Blended(font, kiir->B, feher );
  165.     SDL_BlitSurface(szovegdobozba,&src,hova,&dest);
  166.  
  167.     dest.x=ACx[1];
  168.     dest.y=CDy[0]-7;
  169.     szovegdobozba = TTF_RenderUTF8_Blended(font, "● C: ", sarga );
  170.     SDL_BlitSurface(szovegdobozba,&src,hova,&dest);
  171.     dest.x+=30;
  172.     szovegdobozba = TTF_RenderUTF8_Blended(font, kiir->C, feher );
  173.     SDL_BlitSurface(szovegdobozba,&src,hova,&dest);
  174.  
  175.     dest.x=BDx[1];
  176.     dest.y=CDy[0]-7;
  177.  
  178.     szovegdobozba = TTF_RenderUTF8_Blended(font, "● D: ", sarga );
  179.     SDL_BlitSurface(szovegdobozba,&src,hova,&dest);
  180.     dest.x+=30;
  181.     szovegdobozba = TTF_RenderUTF8_Blended(font, kiir->D, feher );
  182.     SDL_BlitSurface(szovegdobozba,&src,hova,&dest);
  183.  
  184.     dest.x=92+(504-strlen(kiir->kerdes)*6.25)/2;
  185.     dest.y=577;
  186.     szovegdobozba=TTF_RenderUTF8_Blended(font, kiir->kerdes, feher);
  187.     SDL_BlitSurface(szovegdobozba,&src,hova,&dest);
  188.  
  189.     SDL_Flip(hova);
  190.  
  191.     free(font);
  192.     free(szovegdobozba);
  193.     free(hova);
  194.  
  195. }
  196.  
  197.  
  198. int graphics(void)
  199. {
  200.     SDL_Surface *screen, *hatter, *szoveg;
  201.     SDL_Event kattintas;
  202.  
  203.     SDL_Init(SDL_INIT_VIDEO | 0x1000000);
  204.     screen = SDL_SetVideoMode(720, 720, 0, SDL_ANYFORMAT); //960 széles lesz később bekerülő oldalsó sáv miatt
  205.  
  206.     Kerdes **kerdestomb;
  207.     kerdestomb=beolvas();
  208.  
  209.     SDL_Rect hova= {0,0,100,12};
  210.     TTF_Font *font;
  211.  
  212.     hatter_betolt(screen);
  213.  
  214.     doboz_rajzol(screen, ACx, ABy, fekete);
  215.     doboz_rajzol(screen, BDx, ABy, fekete);
  216.     doboz_rajzol(screen, ACx, CDy, fekete);
  217.     doboz_rajzol(screen, BDx, CDy, fekete);
  218.     doboz_rajzol(screen, Kx, Ky, fekete);
  219.  
  220.     lineColor(screen, 0, 644, 67, 644, kek);
  221.     lineColor(screen, 0, 584, 67, 584, kek);
  222.     lineColor(screen, 0, 692, 67, 692, kek);
  223.  
  224.     lineColor(screen, 622, 692, 720, 692, kek);
  225.     lineColor(screen, 622, 584, 720, 584, kek);
  226.     lineColor(screen, 622, 644, 720, 644, kek);
  227.  
  228.     kerdes_kiir(screen, kerdestomb[2]);
  229.     //free(kerdestomb);
  230.  
  231.     SDL_WM_SetCaption("Legyen Ön is Milliomos", "Legyen Ön is Milliomos");
  232.  
  233.  
  234.     return 0;
  235. }
Advertisement
Add Comment
Please, Sign In to add comment