vialab / SMT

Simple Multi-Touch (SMT) Toolkit
http://vialab.science.uoit.ca/smt
GNU General Public License v3.0
43 stars 18 forks source link

Remove an extended zone class #193

Closed Kimaker closed 10 years ago

Kimaker commented 10 years ago

Is it possible to remove an extended zone class from this same zone class? In the touchImpl() of this zone class I made a boolean where if (touch.lenght==3) then SMT.remove(classname).But nothing happens I have this error message "Warning: Removed a Zone that was not a child" . Contrairwise, if I put a SMT.remove() in a keyReleased then there is no problem. I am sure I have passed over something but what? Thank you for your help.

kiwistrongis commented 10 years ago

Um, the warning you're getting happens when there's no zones that match the given name. Also, SMT.remove( String) takes the name of the zone, not its class.

Tettsch commented 10 years ago

Hey, I got the same problem here. I wanted to remove a dynamically created Zone. So I put the remove() into the touchUpImpl() of my custom created zone. The method returns true but in fact nothing happens. Do you have any clues how to solve this problem? For better understanding I will paste the code here, I tried to outline the problem as minimal as possible. Thanks!

import vialab.SMT.*;
import java.util.*;

Custom custom;
static Zone zone;
Touch first = null;
ArrayList<Custom> list;

void setup(){
  list = new ArrayList<Custom>();
  size(800, 600, SMT.RENDERER);
  SMT.init(this, TouchSource.AUTOMATIC);
  zone = new Zone("main", 0, 0, 200, 200);
  SMT.add(zone);

}
 void draw(){
  background(0);
  }
  void drawMain(){
  fill(0,0,155);
  rect(0, 0, 200, 200);
  }
  void touchDownMain(Zone z){
    int i = list.size();
    Integer myInt = new Integer(i); 
    String s = myInt.toString();
    Custom removable = new Custom(s, 50*i, 0, 40, 40);
    list.add(removable);
    zone.add(removable);
  }

public class Custom extends Zone {
  int x;
  int y;
  int width;
  int height;
  String name;
  Custom(String name, int x, int y, int width, int height){
    super(name, x, y, width, height);
    this.name = name;
    this.x = x;
    this.y = y;
    this.width = width;
    this.height = height;

  }
  @Override
  void drawImpl(){
    fill(255, 0, 0);
    rect(0, 0, width,height);
    fill(255);
  }

  @Override 
  void touchImpl(){
    rst();
  }
  @Override
  void touchUpImpl(Touch touch){
     println(remove());
  }
}
kiwistrongis commented 10 years ago

I totally have the solution to your problem :).

  @Override
  void touchUpImpl(Touch touch){
    this.removeFromParent();
  }
}

But it depends on what version of SMT you're on. There's a recent bug that I fixed that made it impossible to remove a zone. If you run into that problem, you can maybe try this build: http://vialab.science.uoit.ca/smt/dl/SMT-4.1b3.zip, but be warned that it's not an official release and not really guaranteed to be stable ( it should be fine though).

Tettsch commented 10 years ago

Thank you very much. I had indeed a buggy version of SMT. :/

kiwistrongis commented 10 years ago

So 4.1b3 fixed the problem for you?

Tettsch commented 10 years ago

Yep, everything works like a charm now. :+1:

kiwistrongis commented 10 years ago

Cool beans. I'll release v4.1b3 officially here on github tomorrowish then.

Tettsch commented 10 years ago

Can't you also contribute the library to the processing libraries in the software itself? (I think most of the users download libraries there). And I hope it is OK if I ask further questions on various topics, because I am using your library for a bigger project right now. ;)

kiwistrongis commented 10 years ago

Dur, I meant v4.1b4, I already released v4.1b3. And yeah, we're actually pretty much ready to release 4.1 completely. I'm just finishing up some work on our website first. You can see a preview here, if you want ;) : http://kalev.io/smt/.

Btw, if you're ever desperate for the latest jar, you can always grab an auto-build here: https://drone.io/github.com/vialab/SMT/files.

And yeah, ask away. You can email me too. We'd be curious to know more about what you're working on.