How do I properly extend the Matrix class from controlP5?

I am working hard on an LED sequencer and have gotten it working they way I want with an altered Matrix class and re-compiled controlP5, but it isnt a great way to distribute the project, so I want to understand how to instead extend the Matrix class and add the features I need. I have looked at the example for extending classes with controlP5 but it is only for a generic controller, not for a controlInterface like Matrix. I have done this:

    class ColorMatrix extends Matrix<ColorMatrix> {
        int[][] _myCellColor;

        ColorMatrix(ControlP5 cp5, String theName) {
            super(cp5, theName);
            for (int x = 0; x < _myCellX; x++) {
                for (int y = 0; y < _myCellY; y++) {
                    _myCellColor[x][y] = 0;
                }
            }
        }
//some additional new methods and method overrides
}

and then called it like this:

new ColorMatrix(cp5, "LED_sequence")
    .setPosition(50, 400)
    .setSize(800, 290)
    .setGrid(SEQUENCE_LENGTH, NUMBER_OF_LED)
    .setGap(2, 2)
    .setInterval(200)
    .setMode(ControlP5.MULTIPLES)
    .setColorBackground(color(1,0, .1))
    .setBackground(color(1,0, .3))
    ;

But the compiler returns "The function setPosition(int, int) does not exist." which I assumes means my inheritence is not happening correctly. Appreciate any help!

Answers

  • edited November 2013

    If setPosition() is a ControlP5's method, you can only invoke it if somehow your custom class inherited it from Matrix! :-SS

  • edited December 2013 Answer ✓

    Hi, you can extend a Matrix as shown in the example below.

    import controlP5.*;
    // example for processing 2.x and controlP5 2.0
    
    ControlP5 cp5;
    
    MyMatrix matrix;
    
    void setup() {
      size(400,400);
      cp5 = new ControlP5(this);
    
      matrix = new MyMatrix(cp5,"test");   
      matrix.setPosition(100,100);
    }
    
    void draw() {
      background(0);
    }
    
    void keyPressed() {
      matrix.setCnt(4);
    }
    
    public void test(int theX, int theY) {
      println(theX+" "+theY);
    }
    
    
    class MyMatrix extends Matrix {
    
      MyMatrix(ControlP5 cp5 , String theName) {
        super(cp5, theName);
      }
    
      public void setCnt(int theCnt) {
        cnt = theCnt;
      }
    
    }
    
Sign In or Register to comment.