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

Problem with dynamically created Zones #196

Closed Tettsch closed 10 years ago

Tettsch commented 10 years ago

Hello, I am a little bit stuck by working with the SMT library. I tried to create a menu, which is dynamically built depending on how much menu entries there are. The problem is, I don't want to write a touch- and drawmethod for every menu entry (which also breaks the dynamic-menu-approach). Instead I wanted to write a global touch-listener that listens to all touchevents and than goes through a list of zone-objects and decides what to do. Is that a good approach? Or how should I do it? And how could that be done?

Edit: Is it even possible to write an Object that extends Zone and gets rid of the "nameDraw" methods?

regards, Tettsch

kiwistrongis commented 10 years ago

Hi there,

I'm actually in the process of writing a tutorial on extending the Zone class. It's not done yet, but if you give me a day, I can send you a link to the in-progress version. In the meantime, have a look at this sketch for and example of extending Zone: https://github.com/kiwistrongis/SMT/blob/working/examples/Advanced/Java/Java.pde

Tettsch commented 10 years ago

Hi, thank you for your fast reply! A link to the in-progess version would help as the link you posted does. Thanks so far.

Tettsch commented 10 years ago

I finally made it work. Although your example did not work for me. In the version of SMT I have touchDown(Touch touch) is not implemented in Zone. There is touchDownImpl(Touch touch) but renaming does not work either. Nonetheless here is my sketch working so far:

import vialab.SMT.*;
Custom custom;
Touch first = null;
void setup(){
  size(600, 800, SMT.RENDERER);
  SMT.init(this, TouchSource.AUTOMATIC);
  custom = new Custom("test", 100, 100, 60, 60);
  SMT.add(custom);

}
 void draw(){
  background(0);
  }
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 draw(){
    fill(255, 0, 0);
    rect(0, 0, width,height);
    fill(255);
    textSize(30);
    text("1", 0, 0);;
  }

  @Override 
  void touch(){
    rst();
  }
  @Override
  void touchUpImpl(Touch touch){
    if( this.getNumTouches() == 0)
    println("touch up");
  }
}
kiwistrongis commented 10 years ago

Okay, yeah, in that version of SMT you really shouldn't override touch() or draw() because those are the functions that invoke the real draw methods. Override touchImpl() and drawImpl() instead.

kiwistrongis commented 10 years ago

Okay, I just updated the beta version of our website. Here's the tutorial I mentioned: http://kalev.io/smt/tutorial/java.php. Specifically, you probably want to see the legacy section. Let me know if you have any feedback on that tutorial. Unless you have other questions, I'm going to close this issue.

Tettsch commented 10 years ago

Thanks, I have no comments on the tutorial so far. At least it is understandble for me. :+1: So no further questions.