void SDL_Class::screen(int x, int y, std::string const &name, int t) { SDL_Rect pos; SDL_Surface *img; SDL_Surface *img_original; pos.x = x; pos.y = y; img = IMG_Load(name.c_str()); img_original = img; if (img == NULL) { img = SDL_LoadBMP("data/SDL_Features/no-preview.bmp"); if (img == NULL) return ; } else { if (t == 1) img = rotozoomSurfaceXY(img, 0, 0.227, 0.227, 0); else img = rotozoomSurfaceXY(img, 0, 0.21, 0.21, 0); } SDL_BlitSurface(img, NULL, SDL_GetWindowSurface(this->_window), &pos); SDL_FreeSurface(img); SDL_FreeSurface(img_original); }
SDL_Surface* SDL::rotoZoom(SDL_Surface* surface, float angle, float scaleX, float scaleY) { // if (!surface || angle < 0) // return NULL; return (rotozoomSurfaceXY(surface, angle, scaleX, scaleY, SMOOTHING_ON)); }
CAMLprim value ml_rotozoomSurfaceXY(value src,value angle,value zoomx,value zoomy,value smooth) { SDL_Surface *ssur= SDL_SURFACE(src); SDL_Surface *dsur; dsur=rotozoomSurfaceXY(ssur,Double_val(angle),Double_val(zoomx),Double_val(zoomy),Bool_val(smooth)); return ML_SURFACE(dsur); }
int load_background(t_game *game) { SDL_Rect p; SDL_Surface *background; SDL_Surface *bg_image; int width; int height; width = game->size_tile * game->map->x; height = game->size_tile * game->map->y; p.x = 0; p.y = 0; if (!(background = SDL_CreateRGBSurface(SDL_HWSURFACE , width, height, 32, 0, 0, 0, 0))) return (_error(strdup("load_background : CreateRGBSurface"))); if ((bg_image = IMG_Load("images/background.bmp")) == NULL) return (_error(strdup("load_background : IMGLoad"))); if (!(bg_image = rotozoomSurfaceXY(bg_image, 0.0, (double)(width) / BACKGROUND_X, (double)(height) / BACKGROUND_Y, 1))) return (_error(strdup("load_background : rotozoom"))); if (SDL_BlitSurface(bg_image, NULL, background, &p) < 0) return (_error(strdup("load_background : BlitSurface"))); game->background = background; SDL_FreeSurface(bg_image); return (0); }
void CustomTest(SDL_Surface *screen, SDL_Surface *picture, float a, float x, float y){ SDL_Surface *rotozoom_picture; SDL_Rect dest; printf (" Frame: C Rotate: angle=%.2f Zoom: fx=%.2f fy=%.2f \n",a,x,y); HandleEvent(); ClearScreen(screen); if ((rotozoom_picture=rotozoomSurfaceXY (picture, a, x, y, 0))!=NULL) { dest.x = (screen->w - rotozoom_picture->w)/2;; dest.y = (screen->h - rotozoom_picture->h)/2; dest.w = rotozoom_picture->w; dest.h = rotozoom_picture->h; if ( SDL_BlitSurface(rotozoom_picture, NULL, screen, &dest) < 0 ) { fprintf(stderr, "Blit failed: %s\n", SDL_GetError()); return; } SDL_FreeSurface(rotozoom_picture); } /* Display by flipping screens */ SDL_Flip(screen); SDL_Delay(3000); }
int Image::show(SDL_Surface *screen ,int x, int y, int width, int height, double rotation) { int retval; double zoomx = (double) width / (double) imageSheet->w; double zoomy = (double) height / (double) imageSheet->h; box.x = x; box.y = y; SDL_Surface* rotatedSheet = NULL; rotatedSheet = rotozoomSurfaceXY(imageSheet, rotation, zoomx, zoomy, 0); SDL_Rect tmp; tmp.x = box.x + (( width / 2 ) - ( rotatedSheet->w / 2 )); tmp.y = box.y + (( height / 2 ) - ( rotatedSheet->h / 2 )); retval=SDL_BlitSurface( rotatedSheet, NULL, screen, &tmp ); SDL_FreeSurface( rotatedSheet ); return retval; }
void CustomTest(SDL_Surface *screen, SDL_Surface *picture, double a, double x, double y, int smooth){ SDL_Surface *rotozoom_picture; SDL_Rect dest; fprintf(stderr, "%s\n", messageText); printf (" Frame: C Rotate: angle=%.2f Zoom: fx=%.2f fy=%.2f \n",a,x,y); HandleEvent(); ClearScreen(screen); if ((rotozoom_picture=rotozoomSurfaceXY (picture, a, x, y, smooth))!=NULL) { dest.x = (screen->w - rotozoom_picture->w)/2;; dest.y = (screen->h - rotozoom_picture->h)/2; dest.w = rotozoom_picture->w; dest.h = rotozoom_picture->h; if ( SDL_BlitSurface(rotozoom_picture, NULL, screen, &dest) < 0 ) { fprintf(stderr, "Blit failed: %s\n", SDL_GetError()); return; } SDL_FreeSurface(rotozoom_picture); } /* Display by flipping screens */ SDL_Flip(screen); /* Maybe delay */ if (delay>0) { SDL_Delay(delay); } SDL_Delay(1000); }
int load_images(t_game *game) { char *files[NB_IMAGES] = {"images/empty.png", "images/wall.bmp", "images/ladder.png", "images/lgoomba.png", "images/exit.png", "images/empty.png", "images/key.png", "images/lplayer.png", "images/rplayer.png", "images/rgoomba.png"}; int i; double r; game->images[0] = NULL; i = 0; r = (double)(game->size_tile) / SIZE_IMAGE; while (i < NB_IMAGES) { if ((game->images[i] = IMG_Load(files[i])) == NULL) return (_error(strdup("load_images : ImgLoad"))); if (!(game->images[i] = rotozoomSurfaceXY(game->images[i], 0.0, r, r, 1))) return (_error(strdup("load_images : rotozoom"))); i++; } return (0); }
SDL_Surface* TextureDefinition::prepareImage(SDL_Surface* loadedImage) { SDL_Surface* tmp = loadedImage; loadedImage = rotozoomSurfaceXY(tmp, 0, SCALE, SCALE, 0); SDL_FreeSurface(tmp); tmp = loadedImage; loadedImage = SDL_DisplayFormatAlpha(tmp); SDL_FreeSurface(tmp); return loadedImage; }
void ImageView::transform(){ SDL_Surface * new_surface = rotozoomSurfaceXY(img,rotation,scaleX*resizeX,scaleY*resizeY,smothing); if(new_surface == NULL){ throw string("Error in: "+string(__PRETTY_FUNCTION__)+" details:"+SDL_GetError()); } if(surface != NULL && surface != img){ SDL_FreeSurface( surface ); surface = NULL; } surface = new_surface; View::resize(surface->w,surface->h); }
SDL_Surface* TextureDefinition::getTextureImage() { if (this->openImage == NULL) { SDL_Surface* loadedImageTmp = IMG_Load(this->imageSrc.c_str()); if (loadedImageTmp == NULL) { Logs::logErrorMessage( "Unable to load tile texture: " + string(SDL_GetError())); loadedImageTmp = this->getDefaultTextureImage(); } SDL_Surface* loadedImageRot = rotozoomSurfaceXY(loadedImageTmp, 0, SCALE, SCALE, 0); SDL_FreeSurface(loadedImageTmp); SDL_Surface* loadedImage = SDL_DisplayFormatAlpha(loadedImageRot); SDL_FreeSurface(loadedImageRot); this->openImage = loadedImage; } return this->openImage; }
void SDL_Class::map(std::string const &name, int x, int y, float z) { SDL_Rect pos; SDL_Surface *img; SDL_Surface *img_original; (void)z; pos.x = x; pos.y = y; img = SDL_LoadBMP(name.c_str()); img_original = img; if (img == NULL) return ; img = rotozoomSurfaceXY(img, 0, z, z, 0); SDL_BlitSurface(img, NULL, SDL_GetWindowSurface(this->_window), &pos); SDL_FreeSurface(img); SDL_FreeSurface(img_original); }
/*! * @brief 将精灵绘制到屏幕上 * * @param sprite 精灵的指针 */ void Sprite_Apply (const Sprite * sprite) { SDL_Surface * tempSurface = NULL; if (sprite == NULL) return; if (!sprite->visible) return; if (sprite->surface == NULL) return; if (sprite->angle == 0.0 && sprite->zoomX == 1.0 && sprite->zoomY == 1.0) { Graph_ApplySurfaceTo(sprite->x,sprite->y,sprite->surface,screen); } else { int ow = sprite->surface->w,oh = sprite->surface->h,w,h; rotozoomSurfaceSizeXY(ow,oh,sprite->angle,sprite->zoomX,sprite->zoomY,&w,&h); tempSurface = rotozoomSurfaceXY(sprite->surface,sprite->angle, sprite->zoomX,sprite->zoomY,TRUE); Graph_ApplySurfaceTo(sprite->x - (w - ow) / 2,sprite->y - (h - oh) / 2,tempSurface,screen); SDL_FreeSurface(tempSurface); } }
static PyObject* _gfx_rotozoomxy (PyObject *self, PyObject *args) { SDL_Surface *orig, *result; PyObject *surface, *retval, *aa = NULL; double angle, zoomx, zoomy; int smooth = 0; if (!PyArg_ParseTuple (args, "Oddd|O:rotozoom_xy", &surface, &angle, &zoomx, &zoomy, &aa)) return NULL; if (!PySDLSurface_Check (surface)) { PyErr_SetString (PyExc_TypeError, "surface must be a Surface"); return NULL; } orig = ((PySDLSurface*)surface)->surface; if (aa) { smooth = PyObject_IsTrue (aa); if (smooth == -1) return NULL; } result = rotozoomSurfaceXY (orig, angle, zoomx, zoomy, smooth); if (!result) { PyErr_SetString (PyExc_PyGameError, SDL_GetError ()); return NULL; } retval = PySDLSurface_NewFromSDLSurface (result); if (!retval) { SDL_FreeSurface (result); return NULL; } return retval; }
SDL_Surface* EntityViewData::getEntityImage() { if (this->openImage == NULL) { SDL_Surface* loadedImageTmp = IMG_Load(this->entityImage.c_str()); if (loadedImageTmp == NULL) { printf("Unable to load Entity Image. %s\n", SDL_GetError()); unlog.logErrorMessage( string("Unable to load Entity Image.") + string(SDL_GetError())); return NULL; } SDL_Surface* loadedImageRot = rotozoomSurfaceXY(loadedImageTmp, 0, this->scaleWidth, this->scaleHeight, 0); SDL_FreeSurface(loadedImageTmp); SDL_Surface* loadedImage = SDL_DisplayFormatAlpha(loadedImageRot); SDL_FreeSurface(loadedImageRot); this->openImage = loadedImage; } return this->openImage; }
void RotatePicture (SDL_Surface *screen, SDL_Surface *picture, int rotate, int flip, int smooth) { SDL_Surface *rotozoom_picture; SDL_Rect dest; int framecount, framemax, frameinc; double angle, zoomf, zoomfx, zoomfy; fprintf(stderr, "%s\n", messageText); /* Rotate and display the picture */ framemax=4*360; frameinc=1; for (framecount=-360; framecount<framemax; framecount += frameinc) { if ((framecount % 360)==0) frameinc++; HandleEvent(); ClearScreen(screen); zoomf=(float)(framecount+2*360)/(float)framemax; zoomf=1.5*zoomf*zoomf; /* Are we in flipping mode? */ if (flip) { /* Flip X factor */ if (flip & 1) { zoomfx=-zoomf; } else { zoomfx=zoomf; } /* Flip Y factor */ if (flip & 2) { zoomfy=-zoomf; } else { zoomfy=zoomf; } angle=framecount*rotate; if (((framecount % 120)==0) || (delay>0)) { printf (" Frame: %i Rotate: angle=%.2f Zoom: x=%.2f y=%.2f\n",framecount,angle,zoomfx,zoomfy); } if ((rotozoom_picture=rotozoomSurfaceXY (picture, angle, zoomfx, zoomfy, smooth))!=NULL) { dest.x = (screen->w - rotozoom_picture->w)/2;; dest.y = (screen->h - rotozoom_picture->h)/2; dest.w = rotozoom_picture->w; dest.h = rotozoom_picture->h; if ( SDL_BlitSurface(rotozoom_picture, NULL, screen, &dest) < 0 ) { fprintf(stderr, "Blit failed: %s\n", SDL_GetError()); break; } SDL_FreeSurface(rotozoom_picture); } } else { angle=framecount*rotate; if ((framecount % 120)==0) { printf (" Frame: %i Rotate: angle=%.2f Zoom: f=%.2f \n",framecount,angle,zoomf); } if ((rotozoom_picture=rotozoomSurface (picture, angle, zoomf, smooth))!=NULL) { dest.x = (screen->w - rotozoom_picture->w)/2;; dest.y = (screen->h - rotozoom_picture->h)/2; dest.w = rotozoom_picture->w; dest.h = rotozoom_picture->h; if ( SDL_BlitSurface(rotozoom_picture, NULL, screen, &dest) < 0 ) { fprintf(stderr, "Blit failed: %s\n", SDL_GetError()); break; } SDL_FreeSurface(rotozoom_picture); } } stringRGBA(screen, 8, 8, messageText, 255, 255, 255, 255); /* Display by flipping screens */ SDL_Flip(screen); /* Maybe delay */ if (delay>0) { SDL_Delay(delay); } } if (rotate) { /* Final display with angle=0 */ HandleEvent(); ClearScreen(screen); if (flip) { if ((rotozoom_picture=rotozoomSurfaceXY (picture, 0.01, zoomfx, zoomfy, smooth))!=NULL) { dest.x = (screen->w - rotozoom_picture->w)/2;; dest.y = (screen->h - rotozoom_picture->h)/2; dest.w = rotozoom_picture->w; dest.h = rotozoom_picture->h; if ( SDL_BlitSurface(rotozoom_picture, NULL, screen, &dest) < 0 ) { fprintf(stderr, "Blit failed: %s\n", SDL_GetError()); return; } SDL_FreeSurface(rotozoom_picture); } } else { if ((rotozoom_picture=rotozoomSurface (picture, 0.01, zoomf, smooth))!=NULL) { dest.x = (screen->w - rotozoom_picture->w)/2;; dest.y = (screen->h - rotozoom_picture->h)/2; dest.w = rotozoom_picture->w; dest.h = rotozoom_picture->h; if ( SDL_BlitSurface(rotozoom_picture, NULL, screen, &dest) < 0 ) { fprintf(stderr, "Blit failed: %s\n", SDL_GetError()); return; } SDL_FreeSurface(rotozoom_picture); } } stringRGBA(screen, 8, 8, messageText, 255, 255, 255, 255); /* Display by flipping screens */ SDL_Flip(screen); /* Maybe delay */ if (delay>0) { SDL_Delay(delay); } } /* Pause for a sec */ SDL_Delay(1000); }
void Window::drawFHorizontal(SDL_Surface* sprite, unsigned int x, unsigned int y) { SDL_Rect position = {x, y}; SDL_BlitSurface(rotozoomSurfaceXY(sprite, 0, -1, 1, 0), NULL, _screen, &position); }
void Tankas::atnaujinti(int xp, int yp, vector<Kulka*> &kulkos) { if(sprogsta) { Sprogimas(); return; } int dx, dy; dx = X+Tanks->w/2 - xp; dy = Y+Tanks->h/2 - yp; vk = atan2(dx , dy) * 180 / M_PI; pk = vk - kampas + 90; // if( kulkos != NULL ) { int i = 0; while(i < kulkos.size()) { // cout<<"kulkos x"<<kulkos[i]->GetX()<<endl; if( SDL_CollidePixel(rotation, X, Y, kulkos[i]->KPasukta, kulkos[i]->GetX(), kulkos[i]->GetY()) != 0 ) { /*I mane pataike!*/ sprogsta = true; lastW=rotation->w; lastH=rotation->h; cout<<"Pataike!"<<endl; } i++; } } if(senas_kampas!=kampas || senas_kampasP != pk) { SDL_Surface* Tn = new SDL_Surface; //Tanko vamzdis SDL_Surface* ND = new SDL_Surface; //Laikinas sluoksnis SDL_Surface* Tm = new SDL_Surface; //Originaliojo tanko sluoksnio kopija //----------------------------------------------------------------------------- ND = SDL_CreateRGBSurface(SDL_HWSURFACE|SDL_SRCALPHA, Tanks->w, Tanks->h, 32, NULL, NULL, NULL, 0); SDL_BlitSurface(Tanks, NULL, ND, NULL); Uint32 colorkey1 = SDL_MapRGB( Tanks->format, 0, 255, 0 ); SDL_SetColorKey( ND, SDL_SRCCOLORKEY, colorkey1 );//naujai sukurtam sluoksniu nustatom sena color key Tm = SDL_DisplayFormatAlpha( ND ); std::swap(Tm, ND); SDL_FreeSurface(ND); //delete(ND); //----------------------------------------------------------------------------- Tn = rotozoomSurfaceXY(Patranka, pk, 1, 1, 0); SDL_Rect dst = {Tn->w / 2, Tn->h / 2}; dst.x = ( Tanks->w - Tn->w ) / 2; dst.y = ( Tanks->h - Tn->h ) / 2; SDL_BlitSurface(Tn, NULL, Tm, &dst); SDL_FreeSurface(Tn); //delete(Tn); SDL_FreeSurface(rotation); rotation = rotozoomSurface(Tm, kampas, 0.45, 0); SDL_FreeSurface(Tm); //delete(Tm); Uint32 colorkey = SDL_MapRGB( rotation->format, 0, 255, 0 ); SDL_SetColorKey( rotation, SDL_SRCCOLORKEY, colorkey ); SDL_Surface * www = new SDL_Surface; www = SDL_DisplayFormatAlpha(rotation); std::swap(www, rotation); SDL_FreeSurface(www); //delete(www); senas_kampas = kampas; senas_kampasP = pk; } }
SDL_Surface* SDLBase::rotoZoom(SDL_Surface *surface, float angle, float scalex, float scaley) { if((surface != NULL) && (scalex > 0) && (scaley > 0)) { return rotozoomSurfaceXY(surface, (double) angle, (double) scalex, (double) scaley, SMOOTHING_ON); } else return NULL; }