void Sprite::refreshRotoZoom() { if(rotAngle != rotAngleAnt || zoomAnt != zoom) { if(textureRotoZoomed != NULL) { SDL_FreeSurface(textureRotoZoomed); } textureRotoZoomed = rotozoomSurface(texture, rotAngle, zoom, 0); rotAngleAnt = rotAngle; zoomAnt = zoom; } }
void Game::OnRender() { CSurface::OnDraw(Surf_Display, Screen, 0, 0); // Disegna lo sfondo // Disegno la nave, scegliendo lo sprite in base allo stato del motore if(player_ship->engine_on){ CSurface::OnDraw(Surf_Display, rotozoomSurface(player_ship->sprite1,(double)player_ship->angle+90,1,1), player_ship->position_x, player_ship->position_y); // Disegna la nave } else{ CSurface::OnDraw(Surf_Display, rotozoomSurface(player_ship->sprite,(double)player_ship->angle+90,1,1), player_ship->position_x, player_ship->position_y); } CSurface::OnDraw(Surf_Display, Terrain, 0, 0); // Disegna il terreno SDL_BlitSurface(this->text, NULL, Surf_Display, NULL); SDL_Flip(Surf_Display); // TEST: save surface to memory and then draw it... if (Reset) { CSurface::OnDraw(Surf_Display, Screen, 0, 0); // Disegna lo sfondo // Disegno la nave, scegliendo lo sprite in base allo stato del motore if(player_ship->engine_on){ CSurface::OnDraw(Surf_Display, rotozoomSurface(player_ship->sprite1,(double)player_ship->angle+90,1,1), player_ship->position_x, player_ship->position_y); // Disegna la nave } else{ CSurface::OnDraw(Surf_Display, rotozoomSurface(player_ship->sprite,(double)player_ship->angle+90,1,1), player_ship->position_x, player_ship->position_y); } CSurface::OnDraw(Surf_Display, Terrain, 0, 0); // Disegna il terreno SDL_BlitSurface(this->text, NULL, Surf_Display, NULL); SDL_Flip(Surf_Display); // TEST: save surface to memory and then draw it... sleep(2); Reset = false; } }
void Frame::draw(Sint16 x, Sint16 y, double angle) const { SDL_Surface* tmp = rotozoomSurface(surface, angle, 1, 1); Sint16 zero = 0; Uint16 uzero = 0; Uint16 w = tmp->w; Uint16 h = tmp->h; SDL_Rect src = { zero, zero, w, h }; SDL_Rect dest = {x, y, uzero, uzero }; SDL_BlitSurface(tmp, &src, screen, &dest); SDL_FreeSurface( tmp ); }
Frame* FrameFactory::getFrame(const std::string& name, const int num, const float scale, const int numFrames, const Uint16 width, const Uint16 height, const Uint16 srcX, const Uint16 srcY) { std::stringstream sstm; float realScale = roundf(scale*10.0)/10.0; sstm << name << num << "sc" << realScale; std::string fmName = sstm.str(); bool debug = false; if(debug) std::cout << "Getting frame: " << fmName << " => "; std::map<std::string, Frame*>::const_iterator pos = frames.find(fmName); if ( pos == frames.end() ) { if(debug) std::cout << "Making its frame" << std::endl; SDL_Surface * surface; SDL_Surface * tmp = IOManager::getInstance().loadAndSet( jgdata.getStr(name+".file"), jgdata.getBool(name+".transparency")); float newScale = 1.0f; if(scale != 1){ double oldW = tmp->w; double newW = numFrames*ceil((oldW*realScale-0.5)/numFrames); newScale = newW/oldW; surface = rotozoomSurface(tmp, 0, newScale, SMOOTHING_ON); SDL_FreeSurface(tmp); } else { surface = tmp; } surfaces[fmName] = surface; Frame * const frame =new Frame(surface, width*newScale, height*newScale, srcX*newScale, srcY*newScale); frames[fmName] = frame; return frame; } else { if(debug) std::cout << "Returning previously made frame" << std::endl; return pos->second; } }
void KissPictureBox::rotate_zoom(double dRotation, double dZoom) { SDL_Surface* sfChanged = rotozoomSurface(this->sfImage, dRotation, dZoom, SMOOTHING_ON); if(this->sfImage->flags & SDL_SRCCOLORKEY) { Uint32 colorkey = this->sfImage->format->colorkey; SDL_SetColorKey(sfChanged, SDL_SRCCOLORKEY, colorkey); } this->closeImage(); this->sfImage = sfChanged; }
//旋转缩放 void Sprite::SetAngleZoom( double angle, double zoom ) { if( m_spr ) { SDL_Surface* obj = m_spr; m_spr = rotozoomSurface( m_spr, angle, zoom, 1 ); SDL_FreeSurface( obj ); } }
Drawable::Drawable(SDL_Surface* screen, std::string imageloc) : m_screen(screen), m_center(0, 0) { loadSurface(imageloc); m_drawablezoomsurf = rotozoomSurface(m_drawablesurf, 0.0, 1, 1); m_pos.w = m_drawablezoomsurf->w; m_pos.h = m_drawablezoomsurf->h; setTopLeftPos(); }
void rotate_surface(SDL_Surface *picture, double angle) { SDL_Surface *rotation = NULL; rotation = rotozoomSurface(picture, angle, 1.0, 0); new(picture); SDL_BlitSurface(rotation, NULL, picture, NULL); SDL_FreeSurface(rotation); SDL_Flip(picture); //correction rotation noir??? }
void Frame::draw(Sint16 x, Sint16 y, double angle) const { SDL_Surface* tmp = rotozoomSurface(surface, angle, 1, 1); Sint16 zero = 0; Uint16 width = tmp->w; Uint16 height = tmp->h; SDL_Rect src = { zero, zero, width, height }; x -= Viewport::getInstance().X(); y -= Viewport::getInstance().Y(); SDL_Rect dest = {x, y, 0, 0 }; SDL_BlitSurface(tmp, &src, screen, &dest); SDL_FreeSurface( tmp ); }
void Sprite::transform(){ //Clean memory for(int i=0;i<transformed_image_list.size();++i){ SDL_FreeSurface(transformed_image_list.at(i)); } transformed_image_list.clear(); //Make the new rotated sprite for(int i=0;i<image_list.size();++i){ transformed_image_list.push_back(rotozoomSurface(image_list.at(i),this->getAngle(),1,SMOOTHING_OFF)); } }
void factoroids_intro(void) { static SDL_Surface* IMG_factors; static SDL_Surface* IMG_fractions; SDL_Rect rect; IMG_factors = rotozoomSurface(images[IMG_FACTOROIDS], 0, zoom, 1); IMG_fractions = rotozoomSurface(images[IMG_FACTORS], 0, zoom, 1); factoroids_draw_bkgr(); if(FF_game == FACTOROIDS_GAME) { rect.x = (screen->w/2) - (IMG_factors->w/2); rect.y = (screen->h)/7; SDL_BlitSurface(IMG_factors, NULL, screen, &rect); factoroids_show_message(_("To win, you must destroy all the asteroids.\n" "Turn: arrow keys or mouse movement.\n" "Thrust: up arrow or right mouse button.\n" "Shoot: [Enter], [Space], or left mouse button.\n" "Switch Prime Number Gun: [D], [F], or mouse scroll wheel.\n" "Activate Powerup: [Shift].\n" "Shoot the rocks with their prime factors until they are all destroyed.")); SDL_BlitSurface(IMG_asteroids1[3],NULL,screen,&rect); } else if (FF_game == FRACTIONS_GAME) { rect.x = (screen->w/2)-(IMG_fractions->w/2); rect.y = (screen->h)/7; SDL_BlitSurface(IMG_fractions,NULL,screen,&rect); factoroids_show_message(_("FRACTIONS: to win, you need destroy all the asteroids. " "Use the arrow keys to turn or go forward. Aim at an asteroid, " "type a number that can simplify the fraction, and press space or return " "to split it. Destroy fractions that can not be further simplified in a single shot!")); } SDL_FreeSurface(IMG_factors); SDL_FreeSurface(IMG_fractions); }
void ImageObject::SetAngle(float angle) { ang = angle; if(processedSurface != NULL) { SDL_FreeSurface(processedSurface); processedSurface = NULL; } processedSurface = rotozoomSurface(imageSurface, ang, scale, 1); position.w = processedSurface->w; position.h = processedSurface->h; }
void ImageObject::SetScale(float sca) { scale = sca; if(processedSurface != NULL) { SDL_FreeSurface(processedSurface); processedSurface = NULL; } processedSurface = rotozoomSurface(imageSurface, ang, scale, 0); position.w = processedSurface->w; position.h = processedSurface->h; }
void Sprite::zoom(float ratio) { if(ratio == 1.0) return; int size = m_Sprites.size(); for(unsigned int i=0; i<size; i++) { SDL_Surface * sur = rotozoomSurface(m_Sprites[i].get(), 0, ratio, 0); m_Sprites.push_back( new SDL_SurfacePtr(sur) ); } m_Sprites.erase( m_Sprites.begin(), m_Sprites.begin() + size ); }
void drawScreen(SDL_Surface *image, int value, int prevValue, double scale, const SDL_VideoInfo *videoInfo) { SDL_Surface *screen = NULL; SDL_Surface *rot = NULL; if (value != image->h) { if (prevValue != image->h) { screen = SDL_SetVideoMode((image->h)*scale, (image->w)*scale, videoInfo->vfmt->BitsPerPixel, SDL_SWSURFACE|SDL_DOUBLEBUF); } rot = rotozoomSurface( image, 270, scale, SMOOTHING_ON ); } if (value == image->h) { if (prevValue != image->h) { screen = SDL_SetVideoMode((image->w)*scale, (image->h)*scale, videoInfo->vfmt->BitsPerPixel, SDL_SWSURFACE|SDL_DOUBLEBUF); } rot = rotozoomSurface( image, 0, scale, SMOOTHING_ON ); } if (!image) { fprintf(stderr, "IMG_LoadBMP_RW failed - %s\n", IMG_GetError()); SDL_Quit(); //return 1; } SDL_BlitSurface(rot, NULL, screen, 0); SDL_Flip(screen); SDL_FreeSurface(rot); //return screen; }
SDL_Surface* getRotatedOptimized(SDL_Surface* surface, float angle) { #if IS_SDL_GFX_ROTOZOOM_SURFACE_90_DEGREES_AVAILABLE // use rotateSurface90Degrees() only when its available (SDL_gfx 2.0.17 or higher) double turns; if(fabs(modf(angle / M_PI_2, &turns)) <= epsilon_ratio // angle sufficiently close to pi/2 multiples and surface->format->BitsPerPixel == 32) // rotateSurface90Degrees only supports 32bit RGBA/ABGR // use optimized 90-degree rotations return rotateSurface90Degrees(surface, (int) -turns); else // use standard rotation function #endif return rotozoomSurface(surface, angle*toDegree, 1.0, SMOOTHING_OFF); }
struct image* image_new_rotation(struct image *img,int rotation) { struct image *img_rot; img_rot = (struct image *)malloc(sizeof(struct image)); // rotation SDL_Surface *priv = rotozoomSurface(img->priv, rotation, 1.0,1); img_rot ->width = priv->w; img_rot ->height = priv->h; img_rot ->pitch = priv->pitch; img_rot ->channels = priv->format->BytesPerPixel; img_rot ->pixels = priv->pixels; img_rot ->priv = priv; return img_rot; }
/** Rotates input surface and each rotation stores into the returned array. */ void Gfx::createRotated(SDL_Surface* input, SDL_Surface* output[], int rotNum){ SDL_Surface* temp; SDL_Rect tempClip; tempClip.w = input->w * 3 / 2; tempClip.h = input->h * 3 / 2; tempClip.x = 0; tempClip.y = 0; for (int i = 0; i < rotNum; i++){ temp = rotozoomSurface(input, 360-i*(360/rotNum), 1, 1); tempClip.x = (temp->w - tempClip.w) / 2 + 1; tempClip.y = (temp->h - tempClip.h) / 2 + 1; output[i] = crop(temp, &tempClip); } }
int main(int argc, char **argv) { SDL_Init(SDL_INIT_VIDEO); const int width = 400; const int height = 200 * (numSprites + 1) / 2; screen = SDL_SetVideoMode(width, height, 32, SDL_SWSURFACE); SDL_Rect rect = { 0, 0, width, height }; SDL_FillRect(screen, &rect, SDL_MapRGBA(screen->format, 0, 0, 0, 0xff)); sprite[0] = IMG_Load("screenshot.png"); sprite[1] = SDL_CreateRGBSurface(SDL_SWSURFACE, 100, 100, 32, 0xFF000000, 0xFF0000, 0xFF00, 0xFF); SDL_FillRect(sprite[1], 0, 0xA0A0A0A0); sprite[2] = zoomSurface(sprite[0], 0.5, 0.5, SMOOTHING_ON); sprite[3] = zoomSurface(sprite[1], 0.5, 0.5, SMOOTHING_ON); sprite[4] = rotozoomSurface(sprite[0], -20, 0.3, SMOOTHING_ON); sprite[5] = rotozoomSurface(sprite[1], 20, 1, SMOOTHING_ON); sprite[6] = zoomSurface(sprite[0], -0.5, 0.5, SMOOTHING_ON); sprite[7] = zoomSurface(sprite[0], -0.5, -0.5, SMOOTHING_ON); sprite[8] = rotozoomSurface(sprite[1], 0, 0.5, SMOOTHING_ON); mainloop(); #ifndef __EMSCRIPTEN__ SDL_Event evt; SDL_SaveBMP(screen, "native_output.bmp"); while (1) { if (SDL_PollEvent(&evt) != 0 && evt.type == SDL_QUIT) break; //mainloop(); SDL_Delay(33); } #endif SDL_Quit(); return 1; }
void Sprite::renderSprite() { getScreenXY(_point); #if defined(SDL_VIDEO) && defined(SW_RENDER) SDL_Rect rect_src; rect_src.x = _rendering_rect.x; rect_src.y = _rendering_rect.y; rect_src.w = width; rect_src.h = height; SDL_Rect rect_dst; rect_dst.x = _point.x; rect_dst.y = _point.y; if((angle == 0) || (_bakedRotation > 0)) SDL_BlitSurface(_pixels->data[0], &rect_src, Globals::_buffer, &rect_dst); else { SDL_Surface *tmp_surface; tmp_surface = rotozoomSurface(_pixels->data[0], angle, 1, 0); SDL_BlitSurface(tmp_surface, 0, Globals::_buffer, &rect_dst); SDL_FreeSurface(tmp_surface); } #elif defined(HW_RENDER) && !defined(VBO) if(!_pixels->animated) glBindTexture( GL_TEXTURE_2D, _pixels->data[0]); else glBindTexture( GL_TEXTURE_2D, _pixels->data[_caf]); glTranslated(_point.x, _point.y, 0.0f); glBegin( GL_QUADS ); { glTexCoord2f(0.0f, 0.0f); glVertex2f(0.f,0.0f); glTexCoord2f(1.0f,0.0f); glVertex2f(width,0.0f); glTexCoord2f(1.0f, 1.0f); glVertex2f(width, height); glTexCoord2f(0.0f, 1.0f); glVertex2f(0.0f,height); } glEnd(); #endif }
void Arrow::rotateToMouse() { //// // Position and rotate arrow Vector v(_pos.x, _pos.y); // Add 90 to the angle so we are working in line with the bottom axis double ang = v.angleSeparating(_mouse_pos) + 90; // Ensure angle is not out of bounds. What, no max/min-function? ang = (ang < MIN_ANGLE) ? MIN_ANGLE : ((ang > MAX_ANGLE) ? MAX_ANGLE : ang); _current_ball->_vel.angle(-ang); // Remove the 90 again to rotate correctly _angle = ang - 90; SDL_FreeSurface(_image); _image = rotozoomSurface(_origin, _angle, 1, 1); // Adjust position to center _rect = _image->clip_rect; _rect.x = _pos.x - _image->clip_rect.w / 2; _rect.y = _pos.y - _image->clip_rect.h / 2; //// // Position balls Vector ballpos(0, 40); ballpos.angle(-(_angle + 90)); _current_ball->xPos(_game->size()->w / 2 - BALL_WIDTH / 2 - _pos.w / 2 + ballpos.x()); _current_ball->yPos(_game->size()->h - BALL_HEIGHT + ballpos.y()); // Queue balls int i = 0; for ( ball_queue::iterator iter = _queue.begin(); iter != _queue.end(); iter++, i++ ) { Ball *ball = (*iter); int w = ball->size()->w; ball->xPos((w * ARROW_QUEUE_SIZE + 10) - i * w); ball->yPos(_game->size()->h - w - 10); } }
void Image::draw_rotated(float x, float y, float ax, float ay, float angle) { if(checkInit()==false) throw Exception("Fatal error: attempt to use GameEngine library without initialization!"); rotozoom_surface = rotozoomSurface(implementation->sdlSurface, angle*toDegree, 1, 0); int w1 = implementation->sdlSurface->w, h1 = implementation->sdlSurface->h, w2 = rotozoom_surface->w, h2 = rotozoom_surface->h; int ax2 = w2/2 + (ax - w1/2)*cos(angle) - (ay - h1/2)*sin(angle); int ay2 = h2/2 + (ay - h1/2)*cos(angle) - (ax - w1/2)*sin(angle); dstrect.x = x-ax2; dstrect.y = y-ay2; SDL_BlitSurface(rotozoom_surface, null, GameEngine::display->implementation->sdlDisplaySurface, &dstrect); SDL_FreeSurface(rotozoom_surface); }
void rotbmp_layer_update_func (Layer* me,GContext* ctx) { GPoint topOffset=getTopOffset (); setTopOffset(GPoint(0,0)); GRect rect=GRect(0,0,me->frame.size.w,me->frame.size.h); RotBitmapLayer* bitmapLayer=(RotBitmapLayer*)me; SDL_Surface* bitmap=createSurface(bitmapLayer->bitmap->bounds.size.w,bitmapLayer->bitmap->bounds.size.h); SDL_FillRect(bitmap,0,0); graphics_context_set_compositing_mode (ctx,GCompOpAssign); graphics_draw_bitmap_in_rect_to (ctx,bitmapLayer->bitmap,rect,bitmap); double angle=(double)bitmapLayer->rotation/TRIG_MAX_ANGLE*360.0; SDL_Surface* rotated=rotozoomSurface(bitmap,-angle,1.0,SMOOTHING_OFF); SDL_FreeSurface(bitmap); GPoint offset=getPivotRotationOffset(bitmapLayer->bitmap->bounds.size,GSize(rotated->w,rotated->h),bitmapLayer->src_ic,angle); setTopOffset(topOffset); graphics_context_set_compositing_mode (ctx,bitmapLayer->compositing_mode); graphics_draw_surface_in_rect (ctx,rotated,GRect(bitmapLayer->dest_ic.x-offset.x,bitmapLayer->dest_ic.y-offset.y,rotated->w,rotated->h)); SDL_FreeSurface(rotated); }
void mvt_tank(SDL_Renderer *ren, int x, int y, int orientation, int i){ int angles[] ={0,45,90,-45,0,135,-90,-135,180}; SDL_Texture *texture = NULL; SDL_Surface *t = NULL; if(i==1){ t = IMG_Load("IMG/tank1.png"); }else{ t = IMG_Load("IMG/ennemie1.png"); } SDL_Surface *Tank = rotozoomSurface(t,angles[orientation-1], 1, 1); texture = SDL_CreateTextureFromSurface(ren, Tank); SDL_FreeSurface(t); SDL_FreeSurface(Tank); SDL_Rect dst; dst.x = x; dst.y = y; SDL_QueryTexture(texture, NULL, NULL, &dst.w, &dst.h); SDL_RenderCopy(ren, texture, NULL, &dst); SDL_DestroyTexture(texture); }
static PyObject* _gfx_rotozoom (PyObject *self, PyObject *args) { SDL_Surface *orig, *result; PyObject *surface, *retval, *aa = NULL; double angle, zoom; int smooth = 0; if (!PyArg_ParseTuple (args, "Odd|O:rotozoom", &surface, &angle, &zoom, &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 = rotozoomSurface (orig, angle, zoom, smooth); if (!result) { PyErr_SetString (PyExc_PyGameError, SDL_GetError ()); return NULL; } retval = PySDLSurface_NewFromSDLSurface (result); if (!retval) { SDL_FreeSurface (result); return NULL; } return retval; }
bool imagem::desenha_rotacionado(int x, int y, long rotacao ) { if(!egl_init) return false; if( (index < 0) && (!falha) ) return false; if(falha) { egl_texto(falha_str,x,y,255,0,0); return false; } SDL_Surface *imgrot = rotozoomSurface(bmp[curr],(double)rotacao,1,0); int deltah = (imgrot->h - bmp[curr]->h); int deltaw = (imgrot->w - bmp[curr]->w); x = x - deltaw/2; y = y - deltah/2; pos.x = x; pos.y = y; SDL_BlitSurface(imgrot,NULL,tela,&pos); SDL_FreeSurface(imgrot); tempo--; if(!tempo) { curr++; tempo = vel; if(curr > index) { curr = 0; return false; } } return true; }
void Tiles::tileView() { copySurface( 0, 0, screen, tempScreen, &screen->clip_rect, false ); SDL_FillRect( tileSelectScreen, &tileSelectScreen->clip_rect, SDL_MapRGB( tileSelectScreen->format, 0x00, 0x00, 0x00 ) ); int tX = 20, tY = 20; SDL_Rect tempPos[100]; for( int n = 0 ; n <= totalTiles ; n++ ) { tempPos[n] = tPos[n]; tempPos[n].x *= 3; tempPos[n].y *= 3; tempPos[n].w *= 3; tempPos[n].h *= 3; lPos[n] = tPos[n]; lPos[n].w *= 3; lPos[n].h *= 3; lPos[n].x = tX; lPos[n].y = tY; largeTiles = rotozoomSurface( tiles, 0, 3, 0 ); copySurface( tX, tY, largeTiles, tileSelectScreen, &tempPos[n], false ); copySurface( 0, 0, tileSelectScreen, screen, &screen->clip_rect, true ); tX += ( 20 + lPos[n].w ); if( tX > (SCREEN_WIDTH - lPos[n].w - 20) ) { tX = 20; tY += 20 + lPos[n].w; } } }
void super_blit(SuperBlitable *superb, SDL_Surface *dest, int x, int y, int angle) { SDL_Surface *s_final; Uint32 curr_spec = get_spec(); if ((superb->last_spec != curr_spec) || \ (superb->curr_flag != SB_CF_NORMAL)) { SDL_Surface *s_n_spec; Uint8 sr, sg, sb; SDL_GetRGB(curr_spec, get_spec_fmt(), &sr, &sg, &sb); SDL_FreeSurface(superb->curr); superb->curr = SDL_DisplayFormatAlpha(superb->orig); s_n_spec = SDL_ConvertSurface(superb->spec, superb->spec->format, 0); change_style(s_n_spec, SDL_MapRGB(s_n_spec->format, sr, sg, sb)); change_spec(superb->curr, s_n_spec); set_alpha_channel(superb->curr, superb->alph); SDL_FreeSurface(s_n_spec); superb->curr_flag = SB_CF_NORMAL; } s_final = rotozoomSurface(superb->curr, angle, 1, 0); center_blit(s_final, dest, x, y); SDL_FreeSurface(s_final); }
int main(int argc, char* argv[]) { SDL_Surface *screen = NULL; SDL_Surface *image = NULL; SDL_Surface *rot = NULL; SDL_RWops *rw = NULL; const SDL_VideoInfo *videoInfo = NULL; FILE* file; FILE* newFile; double scale; char buffer[256]; int value; int prevValue; /*-----------------------------------------------------------------*/ if (SDL_Init(SDL_INIT_EVERYTHING) < 0) { fprintf(stderr, "SDL_Init failed - %s\n", SDL_GetError()); return 1; } /*-----------------------------------------------------------------*/ videoInfo = SDL_GetVideoInfo(); if (videoInfo == 0) { fprintf(stderr, "SDL_GetVideoInfo failed - %s\n", SDL_GetError()); SDL_Quit(); return 1; } /*-----------------------------------------------------------------*/ if((file = popen("adb shell \"screencap -p | busybox uuencode -\" | uudecode","r"))==NULL) { fprintf(stderr, "can't open dump.png\n"); return 0; } rw = SDL_RWFromFP(file, 0); close(file); image = IMG_LoadPNG_RW(rw); SDL_FreeRW(rw); //scale = (image->h)/(videoInfo->current_h); scale = 0.5; /*-----------------------------------------------------------------*/ screen = SDL_SetVideoMode((image->w)*scale, (image->h)*scale, videoInfo->vfmt->BitsPerPixel, SDL_SWSURFACE|SDL_DOUBLEBUF); if (!screen) { fprintf(stderr, "SetVideoMode failed - %s\n", SDL_GetError()); SDL_FreeSurface(image); SDL_Quit(); return 1; } rot = rotozoomSurface( image, 0, scale, SMOOTHING_ON ); if (!image) { fprintf(stderr, "IMG_LoadBMP_RW failed - %s\n", IMG_GetError()); SDL_Quit(); return 1; } SDL_BlitSurface(rot, 0, screen, 0); SDL_Flip(screen); SDL_FreeSurface(rot); SDL_FreeSurface(image); /*-----------------------------------------------------------------*/ while(1){ if((file = popen("adb shell dumpsys window | grep cur= | awk -F cur= '{print $NF}' | awk -F ' ' '{print $1}' | awk -F 'x' '{print $NF}'", "r"))==NULL) { fprintf(stderr, "can't get size\n"); return 0; } while(fgets(buffer, sizeof(buffer), file) != 0) { value = atoi(buffer); } pclose(file); if((file = popen("adb shell \"screencap -p | busybox uuencode -\" | uudecode","r"))==NULL) { fprintf(stderr, "can't open dump.png\n"); return 0; } rw = SDL_RWFromFP(file, 0); close(file); image = IMG_LoadPNG_RW(rw); SDL_FreeRW(rw); if (value != image->h) { if (prevValue != image->h) { screen = SDL_SetVideoMode((image->h)*scale, (image->w)*scale, videoInfo->vfmt->BitsPerPixel, SDL_SWSURFACE|SDL_DOUBLEBUF); } rot = rotozoomSurface( image, 270, scale, SMOOTHING_ON ); } if (value == image->h) { if (prevValue != image->h) { screen = SDL_SetVideoMode((image->w)*scale, (image->h)*scale, videoInfo->vfmt->BitsPerPixel, SDL_SWSURFACE|SDL_DOUBLEBUF); } rot = rotozoomSurface( image, 0, scale, SMOOTHING_ON ); } if (!image) { fprintf(stderr, "IMG_LoadBMP_RW failed - %s\n", IMG_GetError()); SDL_Quit(); return 1; } SDL_FreeSurface(image); SDL_BlitSurface(rot, NULL, screen, 0); SDL_Flip(screen); SDL_FreeSurface(rot); prevValue = value; } //SDL_Delay(5000); SDL_Quit(); return 0; }
void CLasagneEntity::Render( SDL_Surface *screen ) { if (!m_visible) return; if (!IsOnScreen()) return; if (m_noofFramesX + m_noofFramesY == 0) { // draw the entity in its 3d position SDL_Rect rcRect; rcRect.x = static_cast<Sint16>(m_screenPosition.x()); rcRect.y = static_cast<Sint16>(m_screenPosition.y()); SDL_BlitSurface(m_image, NULL, screen, &rcRect); } else { int xOffset = m_currentFrame; int yOffset = 0; while (xOffset > m_noofFramesX - 1) { yOffset++; xOffset -= m_noofFramesX; } // update aniamtion if (SDL_GetTicks() - m_lastFrameTime > m_fps) { m_lastFrameTime = SDL_GetTicks(); m_currentFrame++; if (m_currentAnimation.length() == 0) { if (m_currentFrame >= (m_noofFramesX * m_noofFramesY)) m_currentFrame = 0; } else { const AnimationData &animData = m_animation[m_currentAnimation]; IVec2 frames = animData.frames; if (m_currentFrame >= frames.y()) { if (animData.loop) m_currentFrame = frames.x(); else m_currentFrame = frames.y() - 1; } } } const int pixelOffset = ((m_image->w * m_frameSize.h) * yOffset) + (m_frameSize.w * xOffset); SDL_PixelFormat *const fmt = m_image->format; SDL_Surface *const frame = SDL_CreateRGBSurfaceFrom( (void*)((unsigned int*)m_image->pixels + pixelOffset), m_frameSize.w, m_frameSize.h, fmt->BitsPerPixel, m_image->pitch, fmt->Rmask, fmt->Gmask, fmt->Bmask, fmt->Amask ); SDL_Surface *rotateFrame = rotozoomSurface(frame, m_rotation, 1, 0); SDL_Rect rcRect; rcRect.x = static_cast<Sint16>(m_screenPosition.x()); rcRect.y = static_cast<Sint16>(m_screenPosition.y()); SDL_BlitSurface(rotateFrame, NULL, screen, &rcRect); SDL_FreeSurface(frame); SDL_FreeSurface(rotateFrame); } }