#include #include #include //globalis valtozok a rajzolo felulethez SDL_Window *window; SDL_Renderer *canvas; class Shape { private: int x,y; unsigned color; public: Shape(int x, int y, unsigned color):x(x),y(y),color(color){} virtual ~Shape(){} virtual void draw() const =0; unsigned getColor()const{return color;} int getx()const{return x;} int gety()const{return y;} }; class Rect : public Shape { private: int w,h; public: Rect(int x, int y, unsigned color, int w, int h):Shape(x,y,color),w(w),h(h){} void draw() const{rectangleColor(canvas,getx(),gety(),getx()+w,gety()+h,getColor());} int getw()const {return w;} int geth()const {return h;} }; class OpaqueRect : public Rect { private: unsigned fill; public: OpaqueRect(int x, int y, unsigned color, int w, int h, unsigned fill):Rect(x,y,color,w,h),fill(fill){} void draw() const{boxColor(canvas,getx()+1,gety()+1,getx()+getw()-2,gety()+geth()-2,fill); Rect::draw();} }; class Poly : public Shape { private: struct Point{int x,y;} *p; int n; public: Poly(int x, int y, unsigned color):Shape(x,y,color), p(NULL), n(0){} ~Poly(){delete[] p;} void draw() const{ int xx=getx(),yy=gety(); for(int i=0;iadd_pt(150,250);p->add_pt(130,220);s[1]=p; s[2]=new OpaqueRect(200,100,0xffffffff,100,250,0xff8080ff);//x,y,c,w,h,f for(int i=0;i<3;++i) s[i]->draw(); // vegul, update renderer :) SDL_RenderPresent(canvas); loop(); for(int i=0;i<3;++i) delete s[i]; return 0; } void sdl_init(char const *felirat, int szeles, int magas, SDL_Window **pwindow, SDL_Renderer **prenderer) { if (SDL_Init(SDL_INIT_EVERYTHING) < 0) { SDL_Log("Nem indithato az SDL: %s", SDL_GetError()); exit(1); } SDL_Window *window = SDL_CreateWindow(felirat, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, szeles, magas, 0); if (window == NULL) { SDL_Log("Nem hozhato letre az ablak: %s", SDL_GetError()); exit(1); } SDL_Renderer *canvas = SDL_CreateRenderer(window, -1, SDL_RENDERER_SOFTWARE); if (canvas == NULL) { SDL_Log("Nem hozhato letre a megjelenito: %s", SDL_GetError()); exit(1); } SDL_RenderClear(canvas); *pwindow = window; *prenderer = canvas; } void loop(){ bool done=false; while(!done) { // esemenyek SDL_Event event; SDL_WaitEvent(&event); switch (event.type) { // ablak X case SDL_QUIT: done = true; break; // gombnyomas case SDL_KEYDOWN: // exit ha ESCAPE lenyomva if (event.key.keysym.sym == SDLK_ESCAPE) done = true; break; } // switch } // eseményhurok }