mouseWheel on g4p window

Hi guys, I would translate a g4p label on g4p further window but i can’t do it. If I use the translate(x,y) function on main window it work fine but in another g4p window it doesn’t.
The function mouseWheel works only when the mouse is over the main window, my intent is to translate the label on window1.

This is the minimal code:

import g4p_controls.*;

GWindow window1;
GLabel label2; 

float ty = 0.0; // offset of Y axis traslation

 // -------------------------------------------------------
 
public void setup() {
  size(800, 600); // main window

  // create further window
  window1 = GWindow.getWindow(this, "Window title", 0, 0, 800, 600, JAVA2D);
  window1.noLoop();
  window1.setActionOnClose(G4P.KEEP_OPEN);
  window1.addDrawHandler(this, "win_draw1");
  window1.loop();

  // create the label that i wont to traslate
  label2 = new GLabel(window1, 80, 100, 80, 20);
  label2.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
  label2.setText("My label 2");
  label2.setOpaque(true);
} // end setup

 // -------------------------------------------------------

public void draw() {
  background(80);
  translate(0, ty); // affect in main window
  window1.background(60);
  window1.translate(0, ty); // affect in window1
} // end draw

 // -------------------------------------------------------

void mouseWheel(MouseEvent event) {
  ty = ty + event.getCount(); // amount of traslating
  println("ty: " + ty);
} // end mouseWheel

Thank’s in advance for those who help me…

1 Like

sorry, i just want show a other example, where
@quark solved my 2 window question,
and based on this i added 2 slider where mouse wheel works,
incl separate event handlers.
hope you can use any of this.

// https://discourse.processing.org/t/mousewheel-on-g4p-window/8134
// https://discourse.processing.org/t/solved-g4p-options-in-second-window-problem/4552/3


import g4p_controls.*;
GOption option0, option1;
GOption woption0, woption1;
GCustomSlider sdr;
GCustomSlider wsdr;

GWindow[] window;

public void setup() {
  size(200, 100);
  createGUI();
  createWindows();
}

public void draw() {
  background(100, 100, 200);
}

public void createGUI() {
  int posX = 40, posY =20, dposY = 20;
  GToggleGroup tg = new GToggleGroup();

  option0 = new GOption(this, posX, posY+0*dposY, 80, 24, "A");
  option0.setTextAlign(null, GAlign.BOTTOM);

  option1 = new GOption(this, posX, posY+1*dposY, 80, 24, "B");
  option1.setTextAlign(null, GAlign.BOTTOM);

  tg.addControls(option0, option1);  // Group the option buttons
  option1.setSelected(true);   // Must set one of the options true

  option0.addEventHandler(this, "option_clicked");
  option1.addEventHandler(this, "option_clicked");
  
  
  sdr = new GCustomSlider(this, 70, 50, 100, 50, null);  
  // show          opaque  ticks value limits
  sdr.setShowDecor(false, true, true, true);
  sdr.setNbrTicks(5);
  sdr.setLimits(40, -100, 100);
  sdr.addEventHandler(this, "sdr_moved");
}

public void option_clicked(GOption source, GEvent event) { 
  if (source == option0) { 
    println("option0");
  } //option1.setSelected(false);
  if (source == option1) { 
    println("option1");
  } //option0.setSelected(false);
} 

public void win_option_clicked(GOption source, GEvent event) { 
  if (source == woption0) { 
    println("woption0");
  } //option1.setSelected(false);
  if (source == woption1) { 
    println("woption1");
  } //option0.setSelected(false);
} 

//_______________________________________________________________________
public void createWindows() {

  window = new GWindow[1];
  //  for (int i = 0; i < 1; i++) {
  //    window[i] = GWindow.getWindow(this, " ", 70+i*220, 160+i*50, 400, 400, JAVA2D);
  //  }
  // menu window config
  window[0] = GWindow.getWindow(this, "window2", 70, 160, 200, 100, JAVA2D);
  window[0].setActionOnClose(G4P.CLOSE_WINDOW);
  //window[0].addOnCloseHandler(this, "windowClosing");
  //window[0].addData(new MyWinData());
  window[0].addDrawHandler(this, "windowDraw");
  //window[0].addMouseHandler(this, "windowMouse");
  //window[0].addKeyHandler(this, "windowKey");

  int posX = 40, posY =20, dposY = 20;
  GToggleGroup wtg = new GToggleGroup();

  woption0 = new GOption(window[0], posX, posY+0*dposY, 80, 24, "wA");
  woption0.setTextAlign(null, GAlign.BOTTOM);

  woption1 = new GOption(window[0], posX, posY+1*dposY, 80, 24, "wB");
  woption1.setTextAlign(null, GAlign.BOTTOM);

  wtg.addControls(woption0, woption1);   // Group the option buttons

  woption1.setSelected(true); // Must set one of the options true

  woption0.addEventHandler(this, "win_option_clicked");
  woption1.addEventHandler(this, "win_option_clicked");
  
  wsdr = new GCustomSlider(window[0], 70, 50, 100, 50, null);  
  // show          opaque  ticks value limits
  wsdr.setShowDecor(false, true, true, true);
  wsdr.setNbrTicks(5);
  wsdr.setLimits(40, -100, 100);
  wsdr.addEventHandler(this, "wsdr_moved");

}

public void sdr_moved(GCustomSlider slider, GEvent event) { 
  if (slider == sdr) println("sdr integer value:" + slider.getValueI() + " float value:" + slider.getValueF());
}

public void wsdr_moved(GCustomSlider slider, GEvent event) { 
  if (slider == wsdr) println("wsdr integer value:" + slider.getValueI() + " float value:" + slider.getValueF());
}

//_______________________________________________________________________
synchronized public void windowDraw(PApplet appc, GWinData data) {
  // MyWinData data2 = (MyWinData)data;
  appc.background(200, 200, 0);
}

better help might come from quark.

2 Likes

Thank’s a lot! Now I’m going to studing it… :+1: