Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import android.view.MotionEvent;
- import ketai.ui.*;
- boolean firstRun = false;
- aLagarta mag = new aLagarta();
- int numImage = 0;
- int numPage = 1;
- PImage background;
- KetaiGesture gesture;
- boolean reading = false;
- boolean zoom = false;
- boolean isDone = false;
- int numberOfEdition;
- PImage topLogo;
- float sizeWidth;
- float sizeHeight;
- float drawX;
- float drawY;
- SimpleThread thread1;
- void setup() {
- size(displayWidth, displayHeight);
- orientation(LANDSCAPE);
- //println(displayWidth+" "+displayHeight);
- smooth();
- gesture = new KetaiGesture(this);
- sizeWidth = width;
- sizeHeight = height;
- drawX = width/2;
- drawY = height/2;
- thread1 = new SimpleThread(10, "loading");
- thread1.start();
- }
- void draw() {
- if (isDone == true) {
- thread1.quit();
- thread1.stop();
- }
- if (reading == false) {
- if (firstRun == false) {
- mag.update();
- firstRun = true;
- }
- imageMode(CENTER);
- image(background, 394, 260);
- image(topLogo, displayWidth/2, 44);
- imageMode(CENTER);
- if (mag.thumbs.get(numImage).width == 0) {
- }
- else {
- image(mag.thumbs.get(numImage), width/2, height*0.55, round(mag.thumbs.get(numImage).width*0.55), round(mag.thumbs.get(numImage).height*0.55));
- }
- }
- if (reading == true /*&& mag.editionPages.size() != 0*/) {
- imageMode(CENTER);
- if (mag.readingPage.width != 0 && mag.readingPage.width !=-1) {
- image(mag.readingPage, drawX, drawY, round(sizeWidth), round(sizeHeight));
- }
- }
- //delay(1000);
- }
- void onFlick(float x, float y, float px, float py, float v) {
- if (!reading) {
- if (x-px > 0) {
- if (numImage != 0)
- numImage--;
- }
- else if (x-px < 0) {
- if (numImage != mag.thumbs.size()-1)
- numImage++;
- }
- }
- if (reading) {
- if (!zoom) {
- if (x-px > 0) {
- if (numPage != 1) {
- numPage--;
- mag.getPage(numberOfEdition, numPage);
- }
- /*if (mag.editionPages.get(numPage-1) == null)
- mag.getPage(numberOfEdition, numPage);*/
- }
- else if (x-px < 0) {
- numPage++;
- mag.getPage(numberOfEdition, numPage);
- }
- }
- if (zoom) {
- drawX = x-px;
- drawY = y-py;
- }
- }
- }
- void onDoubleTap(float x, float y) {
- if (!reading) {
- if (mag.thumbs.get(numImage).width == 0) {
- }
- else {
- reading = true;
- numberOfEdition = numImage+1;
- mag.getPage(numberOfEdition, 1);
- }
- }
- if (reading) {
- sizeHeight = height;
- sizeWidth = width;
- drawX = width/2;
- drawY = height/2;
- zoom = false;
- }
- }
- void onPinch(float x, float y, float d)
- {
- sizeWidth = constrain(sizeWidth+d, mag.readingPage.width, 1.5*mag.readingPage.width);
- sizeHeight = constrain(sizeHeight+d, mag.readingPage.height, 1.5*mag.readingPage.height);
- zoom = true;
- }
- public boolean surfaceTouchEvent(MotionEvent event) {
- //call to keep mouseX, mouseY, etc updated
- super.surfaceTouchEvent(event);
- //forward event to class for processing
- return gesture.surfaceTouchEvent(event);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement