You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.3 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "SDL.h"
  2. #include "SDL_image.h"
  3. #include "tile.h"
  4. Tile::Tile(int x, int y, int zoom): zoom(zoom), x(x), y(y), surface(NULL), state(EMPTY){};
  5. bool Tile::loaded(){
  6. return !!surface;
  7. }
  8. void Tile::queue(){
  9. state = QUEUED;
  10. }
  11. void Tile::load(char *memory, int size){
  12. SDL_Surface *img = IMG_Load_RW(SDL_RWFromMem(memory, size), 1);
  13. surface = img;
  14. //surface = SDL_DisplayFormat(img);
  15. //SDL_FreeSurface(img);
  16. state = LOADED;
  17. }
  18. std::string Tile::url(){
  19. char url[4096];
  20. //snprintf(url, sizeof url, "http://a.tile.openstreetmap.org/%i/%i/%i.png", zoom, x, y);
  21. //snprintf(url, sizeof url, "http://a.tile.stamen.com/toner/%i/%i/%i.png", zoom, x, y);
  22. snprintf(url, sizeof url, "http://mts0.google.com/vt/hl=en&src=api&x=%i&s=&y=%i&z=%i", x, y, zoom);
  23. //snprintf(url, sizeof url, "http://a.www.toolserver.org/tiles/bw-mapnik/%i/%i/%i.png", zoom, x, y);
  24. return std::string(url);
  25. }
  26. void Tile::render(SDL_Surface *screen, int offsetx, int offsety){
  27. SDL_Rect dest = {x * TILESIZE - offsetx, y * TILESIZE - offsety, TILESIZE, TILESIZE};
  28. while(dest.x <= -TILESIZE){
  29. dest.x += (1 << zoom) * TILESIZE;
  30. }
  31. if(surface){
  32. //printf("render: (%i, %i, %i) => (%i, %i)\n", x, y, zoom, dest.x, dest.y);
  33. SDL_BlitSurface(surface, NULL, screen, &dest);
  34. }else{
  35. SDL_FillRect(screen, &dest, SDL_MapRGB(screen->format, 255, 255, 255));
  36. }
  37. }