Advertisement
Guest User

Untitled

a guest
May 22nd, 2015
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.33 KB | None | 0 0
  1. package com.progrmor.tombstone.screens.screens;
  2.  
  3. import java.io.IOException;
  4. import java.io.InputStream;
  5. import java.nio.ByteBuffer;
  6.  
  7. import com.badlogic.gdx.*;
  8. import com.badlogic.gdx.audio.Sound;
  9. import com.badlogic.gdx.files.FileHandle;
  10. import com.badlogic.gdx.graphics.*;
  11. import com.badlogic.gdx.graphics.g2d.Animation;
  12. import com.badlogic.gdx.graphics.g2d.BitmapFont;
  13. import com.badlogic.gdx.graphics.g2d.Sprite;
  14. import com.badlogic.gdx.graphics.g2d.TextureRegion;
  15. import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
  16. import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter;
  17. import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
  18. import com.badlogic.gdx.input.GestureDetector;
  19. import com.badlogic.gdx.scenes.scene2d.Actor;
  20. import com.badlogic.gdx.scenes.scene2d.InputEvent;
  21. import com.badlogic.gdx.scenes.scene2d.Stage;
  22. import com.badlogic.gdx.scenes.scene2d.ui.Image;
  23. import com.badlogic.gdx.scenes.scene2d.ui.ImageButton;
  24. import com.badlogic.gdx.scenes.scene2d.ui.ImageButton.ImageButtonStyle;
  25. import com.badlogic.gdx.scenes.scene2d.ui.Label;
  26. import com.badlogic.gdx.scenes.scene2d.ui.Skin;
  27. import com.badlogic.gdx.scenes.scene2d.ui.Table;
  28. import com.badlogic.gdx.scenes.scene2d.ui.TextArea;
  29. import com.badlogic.gdx.scenes.scene2d.ui.TextField;
  30. import com.badlogic.gdx.scenes.scene2d.ui.TextField.TextFieldStyle;
  31. import com.badlogic.gdx.scenes.scene2d.utils.*;
  32. import com.badlogic.gdx.utils.ObjectMap;
  33. import com.badlogic.gdx.utils.ScreenUtils;
  34. import com.badlogic.gdx.utils.StreamUtils;
  35. import com.badlogic.gdx.utils.viewport.Viewport;
  36. import com.badlogic.gdx.utils.viewport.StretchViewport;
  37. import com.badlogic.gdx.Input.TextInputListener;
  38. import com.progrmor.tombstone.TombStone;
  39. import com.progrmor.tombstone.helpers.Assets;
  40.  
  41.  
  42.  
  43. import com.progrmor.tombstone.helpers.purchaseInterface;
  44.  
  45. import static com.badlogic.gdx.Gdx.*;
  46.  
  47.  
  48. public class StoneScreen implements Screen, purchaseInterface {
  49.  
  50.     OrthographicCamera camera;
  51.     Viewport view;
  52.     final TombStone game;
  53.     purchaseInterface pInt;
  54.  
  55.  
  56.     Texture arrow, arrowDown,
  57.    
  58.     //TextField´s stuff
  59.     private Stage stageButton;
  60.  
  61.     private Table table;
  62.     private int counter= 1;
  63.     String filePath = files.getLocalStoragePath() + "stoneIMG" + counter + ".png";
  64.    
  65.  
  66.  
  67.     private int  backButtonW = 20;
  68.    
  69.     public Assets assets;
  70.    
  71.  
  72.  
  73.  
  74.  
  75.  
  76.     public StoneScreen(TombStone gam)    {
  77.         this.game = gam;
  78.         this.pInt = game.pi;
  79.         assets = new Assets();
  80.      
  81.         camera = new OrthographicCamera();
  82.         view = new StretchViewport(screenWidth, screenHeight,camera);
  83.         view.apply();
  84.        
  85.         camera.position.set(camera.viewportWidth / 2, camera.viewportHeight / 2, 0);
  86.    
  87.         loadStandard();
  88.  
  89.         stageButton = new Stage(view);
  90.        
  91.  
  92.  
  93.  
  94.     }
  95.  
  96.  
  97.  
  98.     public void loadStandard(){
  99.        
  100.         arrow = assets.manager.get(assets.arrow, Texture.class);
  101.         arrowDown=assets.manager.get(assets.arrowDown, Texture.class);
  102.        
  103.  
  104.     }
  105.  
  106.  
  107.  
  108.  
  109.     @Override
  110.     public void render(float delta) {
  111.         Gdx.gl.glClearColor(0, 0, 0, 0);
  112.         Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
  113.  
  114.  
  115.         game.batch.setProjectionMatrix(camera.combined);
  116.  
  117.         camera.update();
  118.  
  119.  
  120.         stageButton.act(graphics.getDeltaTime());
  121.         stageButton.draw();
  122.  
  123.  
  124.  
  125.     }
  126.  
  127.  
  128.  
  129.     @Override
  130.     public void resize(int width, int height) {
  131.  
  132.  
  133.         stageButton.setViewport(view);
  134.         stageButton.getViewport().update(width, height, true);
  135.        
  136.         camera.update();
  137.  
  138.     }
  139.  
  140.     @Override
  141.     public void show() {
  142.  
  143.         table = new Table();
  144.        
  145.         ImageButtonStyle styleTwo = new ImageButtonStyle();
  146.        
  147.  
  148.         TextureRegionDrawable arrowImage = new TextureRegionDrawable(new TextureRegion(arrowDown));
  149.         TextureRegionDrawable arrowImageDown = new TextureRegionDrawable(new TextureRegion(arrow));
  150.  
  151.         styleTwo.up = skin.newDrawable(skin.newDrawable(arrowImage));
  152.         styleTwo.down = skin.newDrawable(skin.newDrawable(arrowImageDown));
  153.  
  154.  
  155.  
  156.         //Back button
  157.         btnArrow = new ImageButton(styleTwo);
  158.  
  159.         table.add(btnArrow).pad(170).size(130, 130);
  160.         stageButton.addActor(table);
  161.        
  162.        
  163.  
  164.  
  165.         //Backbutton takes us back to mainmenu and saves some prefs.
  166.         btnArrow.addListener(new ChangeListener() {
  167.             //photoshop "save" and "back" on arrow/back image to clarify.
  168.             @Override
  169.             public void changed(ChangeEvent event, Actor actor) {
  170.                 saveScreenshot();
  171.                 sharePhoto();
  172.  
  173.             }
  174.         });
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.     }
  183.  
  184.  
  185.  
  186.     @Override
  187.     public void hide() {
  188.         // TODO Auto-generated method stub
  189.  
  190.     }
  191.  
  192.     @Override
  193.     public void pause() {
  194.         // TODO Auto-generated method stub
  195.  
  196.     }
  197.  
  198.     @Override
  199.     public void resume() {
  200.         // TODO Auto-generated method stub
  201.  
  202.     }
  203.  
  204.     @Override
  205.     public void dispose() {
  206.        
  207.     }
  208.  
  209.  
  210.  
  211.  
  212.     private void saveScreenshot() {
  213.         try{
  214.             FileHandle fh;
  215.             do{
  216.                 fh = new FileHandle(files.getLocalStoragePath() + "screenshot" + ".png");
  217.  
  218.             }while(fh.exists());
  219.  
  220.             Pixmap pixmap = getScreenshot(0, 0, graphics.getWidth(), graphics.getHeight() - 130, true);
  221.             PixmapIO.writePNG(fh, pixmap);
  222.             pixmap.dispose();
  223.             System.out.println(fh.toString());
  224.  
  225.         }catch(Exception e) {
  226.  
  227.         }
  228.     }
  229.     private Pixmap getScreenshot(int x, int y, int w, int h, boolean yDown){
  230.  
  231.         final Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(x, y, w, h);
  232.         w = pixmap.getWidth();
  233.         h = pixmap.getHeight();
  234.         if(yDown) {
  235.             ByteBuffer pixels = pixmap.getPixels();
  236.             int numBytes = w * h * 4;
  237.             byte[] lines = new byte[numBytes];
  238.             int numBytesPerLine = w * 4;
  239.             for (int i = 0; i < h; i++) {
  240.                 pixels.position((h - i - 1) * numBytesPerLine);
  241.                 pixels.get(lines, i * numBytesPerLine, numBytesPerLine);
  242.             }
  243.  
  244.             pixels.clear();
  245.             pixels.put(lines);
  246.         }
  247.         return pixmap;
  248.     }
  249.     @Override
  250.     public void sharePhoto() {
  251.         pInt.sharePhoto();
  252.  
  253.     }
  254.  
  255.  
  256.  
  257. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement