Advertisement
Corosus

Untitled

Mar 27th, 2012
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. SDL_Rect map::clipToViewport(int x, int y, SDL_Rect tclip) {
  2.  
  3.     int xClip = 0;
  4.     int yClip = 0;
  5.     int wClip = 0;
  6.     int hClip = 0;
  7.  
  8.     //SDL_Rect tclip;
  9.     //tclip.x = 0;
  10.     //tclip.y = 0;
  11.     //tclip.w = w;
  12.     //tclip.h = h;
  13.  
  14.     //If this tile is clipping left side x, else right side x
  15.     if (x < this->ViewportInfo.x) {
  16.         xClip = this->ViewportInfo.x - x;
  17.         tclip.x += xClip;
  18.         tclip.w -= xClip;
  19.        
  20.     } else if (x+tclip.w > this->ViewportInfo.x+this->ViewportInfo.width) {
  21.         wClip = (x+tclip.w) - (this->ViewportInfo.x+this->ViewportInfo.width);
  22.         tclip.w -= wClip;
  23.     }
  24.  
  25.     //If this tile is clipping top side y, else bottom side y
  26.     if (y < this->ViewportInfo.y) {
  27.         yClip = this->ViewportInfo.y - y;
  28.         tclip.y += yClip;
  29.         tclip.h -= yClip;
  30.     } else if (y+tclip.h > this->ViewportInfo.y+this->ViewportInfo.height) {
  31.         hClip = (y+tclip.h) - (this->ViewportInfo.y+this->ViewportInfo.height);
  32.         tclip.h -= hClip;
  33.     }
  34.  
  35.     return tclip;
  36.    
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement