Mousewheel_plusplus

details / code
// file: mousewheel_plusplus.pde
// system win 7 processing 3.4
// by KLL
// mouseWheel ++
// "Scrollitis", a operational concept study
// idea is to multiplex the mouseWheel use
// by mixing it with several keypressed
// so the combination is a multi NonGUI slider input
String[] helplines =  {
  "mousewheel plus plus:"
  , "* normal scroll UP DOWN"
  , "+ wheel pressed: fast scroll UP DOWN"
  , "+ key [y]: object Y size"
  , "+ key [x]: object X size"
  , "+ key [w]: object border stroke"
  , "+ key [r]: rotate"
  , "+ key [o]: 0 ellipse, 1 rectangle, 2 triangle"
  , "colors:"
  , "+ key [b]: background"
  , "+ key [f]: fill"
  , "+ key [s]: stroke"
  , " any more ideas?"
};


float e_posX=250, e_posY=250, e_radiusx=100, e_radiusy=100, rot = 0;
int   bg_col = 100,e_fillcol=40,e_strokecol=70;
color bg,e_fill,e_stroke;
int   e_strokeweight = 10, e_objectTyp = 0;

//_______________________________________________
void setup() {
  size(500, 500);
  colorMode(HSB, 100, 100, 100);
  bg = color(bg_col, 100, 100);
  e_fill = color(e_fillcol,100,100);
  e_stroke = color(e_strokecol,100,100);
}
//_______________________________________________
void draw() {
  background(bg);
  draw_help();
  translate(width/2,height/2);
  rotate(rot);
  translate(-width/2,-height/2);  
  fill(e_fill);
  stroke(e_stroke);
  strokeWeight(abs(e_strokeweight));
  switch(e_objectTyp) {
  case 0: 
    ellipse(e_posX, e_posY, e_radiusx, e_radiusy);
    break;
  case 1:
    rectMode(CENTER);
    rect(e_posX, e_posY, e_radiusx, e_radiusy);
    break;
  case 2: 
    triangle(e_posX-e_radiusx/2, e_posY-e_radiusy/2, e_posX, e_posY+e_radiusy/2,e_posX+e_radiusx/2, e_posY-e_radiusy/2);
    break;
  default: println("wrong"); break;
  }  
  if ( mousePresent ) text("π",width-20,height-10);            // do not click on this!
}

//_______________________________________________
// mouse all over
boolean mousePresent = false;  
void mouseExited()  {  mousePresent = false;             }
void mouseEntered() {  if (focused) mousePresent = true; }
void mousePressed() {  show_help = true; startT = millis();   }
void mouseWheel(MouseEvent event) {
  float e = event.getCount();
  if ( mousePressed && mouseButton == CENTER )  e_posY += 10*e; // fast action:     scroll Y position
  else if ( !keyPressed )                       e_posY += e;    // default action:  scroll Y position
  if ( keyPressed && key == 'y' ) e_radiusy += e;               // [y]              stretch Y
  if ( keyPressed && key == 'x' ) e_radiusx += e;               // [x]              stretch X
  if ( keyPressed && key == 'w' ) e_strokeweight += e;          // [w]              strokeWeight
  if ( keyPressed && key == 'r' ) rot += 3*e*TWO_PI/360;                     // [r]             rotate
  if ( keyPressed && key == 'o' ) {    
    e_objectTyp += e;
    e_objectTyp = constrain(e_objectTyp, 0, 2); }               // [o] object typ
  if ( keyPressed && key == 'b' ) { 
    bg_col += 2*e;
    bg_col = constrain(bg_col, 0, 100);
    bg = color(bg_col,100,100); }                               // [b] background color
  if ( keyPressed && key == 'f' ) { 
    e_fillcol += 2*e;
    e_fillcol = constrain(e_fillcol, 0, 100);
    e_fill = color(e_fillcol,100,100); }                        // [f] fill color
  if ( keyPressed && key == 's' ) { 
    e_strokecol += 2*e;
    e_strokecol = constrain(e_strokecol, 0, 100);
    e_stroke = color(e_strokecol,100,100);  }                   // [s] stroke color
}
// help text show on mouse click and timeout
boolean show_help = true;
long startT, actionT=10000;   // use basic millis timer
//_______________________________________________
void my_timer() {
  if ( millis() > startT + actionT ) {
    show_help = false;                        // timeout, was set true by mouse click
  }
}
//_______________________________________________
void draw_help() {
  my_timer();
  if (show_help) {
    fill(0, 100, 0,70);
    noStroke();
    rectMode(0);
    rect(0, 0, 250, 200);
    fill(22,100,100);  // yellow
    int posl=10, dposl = 15;
    for ( int i =0; i < helplines.length; i++ ) text(helplines[i], 10, posl + i*dposl);
  }
} // end

You could change +x and +y to +Strg+X and +Strg+Y and use +x and +y to change the position. (Strg == Ctrl)

thanks,

  • -a- yes even i live thailand and use thai /US keyboard i remember Strg=Ctrl

  • -b- that leads to Ctrl y and Ctrl x are handy on QWERTZ keyboard,
    Ctrl y not so easy on QWERTY

  • -c- actually ±Y position i have in default scroll
    with fast scroll ( wheel pressed ( not so easy ))
    ( what translates to X if rotated 90deg. ) anyhow
    i need to think about that 3 things,

    • position xy
    • size xy
    • default scroll do what?
  • sorry, ideal would be to have NO double key press concept.
    but [ctrl/strg][alt][shift/umsch] alone with scroll wheel might be also useful
    i need to test.

  • other problem is the full color space, if RGB or HSB, need 3 slider
    ( times 3 jobs: background, stroke and fill )
    now only one, i choose HSB Hue
    but that also might be only possible with two keys.

now that all is just a other approach to the multiple set point operator input question
( like from @bam ) where i usually do the

button ask number
import javax.swing.JOptionPane;

int N = 0, Y = 69;
float A, B, C, D = 0.0;

color B_border  = color(255);            // white
color B_fillG   = color(0, 255, 0);      // green
color B_fillB   = color(0, 0, 255);      // blue
color B_fillY   = color(255, 255, 0);    // yellow
color B_text    = color(255, 0, 0);      // red
int   B_textsize=15;

//_________________________________________________________________ Button Menu
void show_Parameter_Buttonmenu() {
  textAlign(CENTER);
  textSize(15);
  strokeWeight(1);
  stroke(255);                                                                      // white
  line(480, 0, 480, 384);                                                           // for button area

  //show_button(int xpos, int ypos, int xwide, int ywide, String Btxt, color border, color filler, color texter)
  show_button(485, 5,   73, 20, "A:"+A, B_border, B_fillG, B_text );
  show_button(485, 30,  73, 20, "B:"+B, B_border, B_fillG, B_text );
  show_button(485, 55,  73, 20, "C:"+C, B_border, B_fillG, B_text );
  show_button(485, 80,  73, 20, "D:"+D, B_border, B_fillG, B_text );
  show_button(485, 105, 73, 20, "N:"+N, B_border, B_fillB, B_text );
  show_button(485, 130, 73, Y, "dY:"+Y, B_border, B_fillY, B_text );
}

//_________________________________________________________________ SETUP
void setup() {
  size(562, 340);
}

//_________________________________________________________________ DRAW
void draw() {
  background(200);   
  ambient(80);   //lights();                                   // static settings
  textAlign(LEFT);
  textSize(20);
  text("Z = "+A+" + "+B+" * X + "+C+" * XX + "+D+" * XXX ", 20, 25);                // float
  text("N = "+N, 20, 45);                                                           // int
  show_Parameter_Buttonmenu();
}



//_________________________________________________________________ diag print only
void mouseReleased() {
  if (mouseButton == LEFT) { 
    print("LEFT: "); 
    if (overRect(485, 5, 73, 20))     A = askF("A", A);
    if (overRect(485, 30, 73, 20))    B = askF("B", B);
    if (overRect(485, 55, 73, 20))    C = askF("C", C);
    if (overRect(485, 80, 73, 20))    D = askF("D", D);
    if (overRect(485, 105, 73, 20))   N = askI("N", N);
    if (overRect(485, 130, 73, Y))   Y = askI("dY", Y);
  }
  if (mouseButton == RIGHT) { 
    print("RIGHT: ");
  }
  if (mouseButton == CENTER) { 
    print("WHEEL: ");
  }
}

// tab common

// for button menu ask setpoint input
//_________________________________________________________________ askI  call: A = askI("A",A);
int askI(String ask, int I) {
  String r = JOptionPane.showInputDialog(null, "new Setpoint for "+ask+" (now "+I+" )", "Input (INT)", JOptionPane.QUESTION_MESSAGE);
  if (r == null ) { 
    print(" NULL "); 
    r = str(I);
  }                           // handle CANCEL
  try { 
    I = Integer.parseInt(r);
  } 
  catch(NumberFormatException e) { 
    println("you did not enter a int number!");
  }
  println("new "+ask, I);
  return I;
}




//_________________________________________________________________ askF  call: A = askF("A",A);
float askF(String ask, float F) {
  String r = JOptionPane.showInputDialog(null, "new Setpoint for "+ask+" (now "+F+" )", "Input (FLOAT)", JOptionPane.QUESTION_MESSAGE);
  if (r == null ) { 
    print(" NULL "); 
    r = str(F);
  }                           // handle CANCEL
  try { 
    F = Float.parseFloat(r);
  } 
  catch(NumberFormatException e) { 
    println("you did not enter a int or float number!");
  }
  println("new "+ask, F);
  return F;
}

//_________________________________________________________________ mouse position over rectangle yes/no
boolean overRect(int x, int y, int width, int height) {
  if (mouseX >= x && mouseX <= x+width && 
    mouseY >= y && mouseY <= y+height) {
    return true;
  } else {
    return false;
  }
}


//_________________________________________________________________ show_button
void show_button(int xpos, int ypos, int xwide, int ywide, String Btxt, color border, color filler, color texter) {
  textAlign(CENTER);
  textSize(B_textsize);
  strokeWeight(2);                                                               // Button border width
  stroke(border);                                                                // Button border color
  fill(filler);                                                                  // Button fill color
  rect(xpos, ypos, xwide, ywide);                                                // Button rectangle
  fill(texter);                                                                  // text color
  text(Btxt, xpos + xwide/2, ypos+ywide/2+B_textsize/2);                         // some pix too low
  noStroke();
}

thing, but that is much more complicated,
while this here ( mousewheel + key multiplex ) is just one line per set point, like

if ( keyPressed && key == 'w' ) e_strokeweight += e;          // [w]

possibly add a range check / constrain

Well, you could use modes, like pressing only h changes to hsb mode or r to rgb mode, and then depending on the mode you can change either hue saturation and brightness with h+whell, s +…and so on, or if mode is rgb you could then switch to r+wheel = red and so on. Same would be possible for position and size, that by pressing first p sets position mode, or s sets size mode, or similar and then x+wheel changes position or size depending on mode.


3 slider move ( Y, X, Rotate )
3 slider object size ( Y, X, Stroke )
1 slider object select list ( example ellipse/rectangle/triangle )
9 slider HSB fill / stroke / background ( using like [b] hue [B] sat [Alt][b] brt )

code
// file: mousewheel_plusplus.pde
// system win 7 processing 3.4
// by KLL
// v0.1  https://discourse.processing.org/t/mousewheel-plusplus/5839
// v0.2  help default and timer   --> blog
// v0.3  π was rotating
// v0.4  Lexyth / move X missing! use CTRL scroll
// v0.5  full HSB colors by [b],[B],[Alt][b] [f]...[s]... --> blog

// mouseWheel ++
// "Scrollitis", a operational concept study
// idea is to multiplex the mouseWheel use
// by mixing it with several keypressed
// so the combination is a multi NonGUI slider input
String[] helplines =  {
  "MouseWheel Plus Plus:"
  , "* normal scroll UP DOWN"
  , "+ wheel pressed: fast scroll UP DOWN"
  , "+ CTRL scroll LEFT RIGHT"
  , "+ key [y]: object Y size"
  , "+ key [x]: object X size"
  , "+ key [w]: object border stroke"
  , "+ key [r]: rotate"
  , "+ key [o]: 0 ellipse, 1 rectangle, 2 triangle"
  , "colors: HSB hue, SAT, [Alt]bright "
  , "+ key [b],[B],[Alt][b] backg"
  , "+ key [f],[F],[Alt][f] fill"
  , "+ key [s],[S],[Alt][s] stroke"
//  , " any more ideas?"
};


float e_posX=250, e_posY=250, e_radiusx=100, e_radiusy=100, rot = 0;
int   bg_HSBhue = 100,e_fillHSBhue=40,e_strokeHSBhue=70;
int   bg_HSBsat = 100,e_fillHSBsat=100,e_strokeHSBsat=100;
int   bg_HSBbrt = 100,e_fillHSBbrt=100,e_strokeHSBbrt=100;
color bg,e_fill,e_stroke;
int   e_strokeweight = 10, e_objectTyp = 0;
// key and mouse all over
boolean altKey = false, ctrlKey = false, shiftKey = false;
boolean mousePresent = false;
// help text show ( at start), on mouse click with timeout
boolean show_help = true;
long startT, actionT=10000;   // use basic millis timer
int posl=10, dposl = 15;

//_______________________________________________
void setup() {
  size(500, 500);
  colorMode(HSB, 100, 100, 100);
  bg = color(bg_HSBhue,bg_HSBsat,bg_HSBbrt);
  e_fill = color(e_fillHSBhue,e_fillHSBsat,e_fillHSBbrt);
  e_stroke = color(e_strokeHSBhue,e_strokeHSBsat,e_strokeHSBbrt);
}
//_______________________________________________
void draw() {
  background(bg);
  draw_help();
  translate(width/2,height/2);
  rotate(rot);
  translate(-width/2,-height/2);  
  fill(e_fill);
  stroke(e_stroke);
  strokeWeight(abs(e_strokeweight));
  switch(e_objectTyp) {
  case 0: 
    ellipse(e_posX, e_posY, e_radiusx, e_radiusy);
    break;
  case 1:
    rectMode(CENTER);
    rect(e_posX, e_posY, e_radiusx, e_radiusy);
    break;
  case 2: 
    triangle(e_posX-e_radiusx/2, e_posY-e_radiusy/2, e_posX, e_posY+e_radiusy/2,e_posX+e_radiusx/2, e_posY-e_radiusy/2);
    break;
  default: println("wrong"); break;
  }  
}

//_______________________________________________
void mouseExited()  {  mousePresent = false;                }
void mouseEntered() {  if (focused) mousePresent = true;    }
void mousePressed() {  if ( mouseButton == LEFT ) { show_help = true; startT = millis(); }}
void mouseWheel(MouseEvent event) {
  float e = event.getCount();
  if ( mousePressed && mouseButton == CENTER )  e_posY += 10*e;       // fast action:     scroll Y position
  else if ( !keyPressed )                       e_posY += e;          // default action:  scroll Y position
  else if ( keyPressed && keyCode == CONTROL )  e_posX += e;          // [CTRL]           scroll X position
  if ( keyPressed && key == 'y' ) e_radiusy += e;                     // [y]              stretch Y
  if ( keyPressed && key == 'x' ) e_radiusx += e;                     // [x]              stretch X
  if ( keyPressed && key == 'w' ) e_strokeweight += e;                // [w]              strokeWeight
  if ( keyPressed && key == 'r' ) rot += 3*e*TWO_PI/360;              // [r]              rotate
  if ( keyPressed && key == 'o' ) {    
    e_objectTyp += e;
    e_objectTyp = constrain(e_objectTyp, 0, 2); }                     // [o]              object typ circle rect triangle
  if ( keyPressed && key == 'b' && !altKey ) { 
    bg_HSBhue += 2*e;
    bg_HSBhue = constrain(bg_HSBhue, 0, 100);
    bg = color(bg_HSBhue,bg_HSBsat,bg_HSBbrt);  }                     // [b] background hue color
  if ( keyPressed && key == 'B' ) { 
    bg_HSBsat += 2*e;
    bg_HSBsat = constrain(bg_HSBsat, 0, 100);
    bg = color(bg_HSBhue,bg_HSBsat,bg_HSBbrt);  }                     // [B] ([Shift][b] or [Capslock][b]) background saturation
  if ( keyPressed && key == 'b' && altKey) { 
    bg_HSBbrt += 2*e;
    bg_HSBbrt = constrain(bg_HSBbrt, 0, 100);
    bg = color(bg_HSBhue,bg_HSBsat,bg_HSBbrt);  }                     // [Alt][b] background brt
  if ( keyPressed && key == 'f' && !altKey ) { 
    e_fillHSBhue += 2*e;
    e_fillHSBhue = constrain(e_fillHSBhue, 0, 100);
    e_fill = color(e_fillHSBhue,e_fillHSBsat,e_fillHSBbrt); }          // [f] fill hue color
  if ( keyPressed && key == 'F' ) { 
    e_fillHSBsat += 2*e;
    e_fillHSBsat = constrain(e_fillHSBsat, 0, 100);
    e_fill = color(e_fillHSBhue,e_fillHSBsat,e_fillHSBbrt); }          // [F]  ([Shift][f] or [Capslock][f]) fill saturation
  if ( keyPressed && key == 'f' && altKey ) { 
    e_fillHSBbrt += 2*e;
    e_fillHSBbrt = constrain(e_fillHSBbrt, 0, 100);
    e_fill = color(e_fillHSBhue,e_fillHSBsat,e_fillHSBbrt); }          // [Alt][f] fill brt
  if ( keyPressed && key == 's' && !altKey ) { 
    e_strokeHSBhue += 2*e;
    e_strokeHSBhue = constrain(e_strokeHSBhue, 0, 100);
    e_stroke = color(e_strokeHSBhue,e_strokeHSBsat,e_strokeHSBbrt); }   // [s] stroke hue color
  if ( keyPressed && key == 'S' ) { 
    e_strokeHSBsat += 2*e;
    e_strokeHSBsat = constrain(e_strokeHSBsat, 0, 100);
    e_stroke = color(e_strokeHSBhue,e_strokeHSBsat,e_strokeHSBbrt); }   // [S]  ([Shift][s] or [Capslock][s]) stroke saturation
  if ( keyPressed && key == 's' && altKey ) { 
    e_strokeHSBbrt += 2*e;
    e_strokeHSBbrt = constrain(e_strokeHSBbrt, 0, 100);
    e_stroke = color(e_strokeHSBhue,e_strokeHSBsat,e_strokeHSBbrt); }   // [Alt][s] stroke brt
}
//_______________________________________________
void my_timer() {
  if ( millis() > startT + actionT ) show_help = false;           // timeout, was set true by mouse click
}
//_______________________________________________
void draw_help() {
  my_timer();
  if (show_help) {
    fill(0, 100, 0,70);
    noStroke();
    rectMode(0);
    rect(0, 0, 270, 200);
    fill(22,100,100);  // yellow
    for ( int i =0; i < helplines.length; i++ ) text(helplines[i], 10, posl + i*dposl);
  }
 if ( mousePresent ) { fill(0); text("π",width-20,height-10); }  // do not click on this!
 if ( keyPressed && (key == 'b' || key == 'B' )) { fill(0); text(" bg color("+bg_HSBhue+","+bg_HSBsat+","+bg_HSBbrt+")",150, posl+10*dposl); }
 if ( keyPressed && (key == 'f' || key == 'F' )) { fill(0); text(" fill color("+e_fillHSBhue+","+e_fillHSBsat+","+e_fillHSBbrt+")",150, posl+11*dposl); }
 if ( keyPressed && (key == 's' || key == 'S' )) { fill(0); text(" stroke color("+e_strokeHSBhue+","+e_strokeHSBsat+","+e_strokeHSBbrt+")",150, posl+12*dposl); }
} // end

void keyPressed () {
  if (key == CODED) {
    if      (keyCode == ALT)     altKey   = true;
    else if (keyCode == SHIFT)   shiftKey = true;
    else if (keyCode == CONTROL) ctrlKey  = true;
  }
}

void keyReleased() {
  if ((keyCode >= '0' && keyCode <= '9') || // digit
    (keyCode >= 'A' && keyCode <= 'Z') || // upper-case letter
    (keyCode >= 'a' && keyCode <= 'z')) { // lower-case letter
    if (altKey) {
      //println("ALT " + char (keyCode)+" "+keyCode);
      altKey = false;
    } else if (ctrlKey) {
      //println("CTRL " + char (keyCode)+" "+keyCode);
      ctrlKey = false;
    } else if (shiftKey) {
      //println("SHIFT " + char (keyCode)+" "+keyCode);
      shiftKey = false;
    } //else println("KEY = "+ key+" "+keyCode);
  }
}

get newest version at my blog