G4P custom sliders

I have just started to experiment with G Custom Sliders. I have found out how to position them, use different skins, change the limits, size etal. But for some reason I can not get a value from the slider. Here is my code.

import g4p_controls.*;

GCustomSlider sdr1;

void setup() {
  size(500, 140); 
  G4P.setSliderFont("Courier", G4P.BOLD, 14); // New for G4P V4.3
  cursor(CROSS);
  //=============================================================
  // Simple default slider,
  // constructor is `Parent applet', the x, y position and length
  sdr1 = new GCustomSlider(this, 20, 20, 400, 75, "red_yellow18px");
  // show          opaque  ticks value limits
  sdr1.setShowDecor(true, true, true, true);
  sdr1.setNbrTicks(11);
  sdr1.setLimits(20, 20, 1000);
}

void draw() {
  background(#FF0000);
}

void handleSliderEvents(GSlider slider) {
  println("Slider Value" + slider.getValueI()+ slider.getValueF());
}

It is basically a pared down version of the example. The event handler never seems to be run. Obviously I’m missing something. I tried to look at the g4p_controls.GCustomSlider Class Reference for information, but do not understand what it is trying to tell me.
What is the event that triggers the handler? The mouse click, stop what??? Thanks for the help Mike.

try
void handleSliderEvents(GSlider slider, GEvent event) {

Peter, thanks for the tip. Can you help me better understand how your sliders work? What are the methods or events I should be looking for? If the mouse is over the image could be one, mouse click is another. If one drags the pointer over the slider without releasing the mouse, does the getvalue change as you drag? Or does the getvalue only change when the mouse is released? Is the getvalue integer or float dependent on the image skin choice? Where is this information? You have some really good items here, but for some reason I can not seem to make them work, at least as far as I can go. Thanks for the help, Mike

Have you looked at the g4p docs Google is your friend.

Alternatively try g4ps examples.

I suggest you look at the G4P guides on my website and the examples that come with G4P. The very first page gives info about how to find stuff about controls by also looking at parent classes.

G4P has two types of event handler by control type and by control. For sliders the slider control type event handler is

void handleSliderEvents(GSlider slider, GEvent event) {
}

This will handle all slider events from all sliders so it you have multiple sliders then you need to test the slider parameter to confirm which slider has fired the event and also test the event type before deciding on what action to take.

Sliders have 5 event types

GEvent.PRESSED
GEvent.RELEASED
GEvent.CLICKED
GEvent.VALUE_CHANGING
GEvent.VALUE_STEADY

For most applications the last two are the most important (personally I have never used the others)

There are some rules governing the sliders you should be aware of

  • getValue() always returns the current slider value based on the thumb position
  • when dragging the slider thumb, the mouse position represents the target value of the slider
  • when no easing is being implied the thumb position will always match the target value (i.e. mouse position)
  • if easing is applied the thumb movement is smoothed so it will not always match the target value - but will always move towards it.

So when you drag the thumb (without easing) then it will fire GEvent.VALUE_STEADY events until you release the mouse button.

When you drag the thumb (with easing) then it will fire GEvent.VALUE_CHANGING until the thumb reaches the target velaue (mouse position) when it will fire a GEvent.VALUE_STEADY event.

Thanks, I have read some of the G4P guides and need to read some more of the suggested Doc’s. I have gotten my code to work. My problem was that I had not established the event handler. I want to test out some of the other controls, I’m sure that armed with this new knowledge my sucess rate should be better. I appreciate the help, Mike.