Skip to content

C++ Mode v0.4.8

Choose a tag to compare

@pepc84 pepc84 released this 14 Aug 04:31
· 12 commits to main since this release

MouseEvent and KeyEvent support

Mouse and keyboard callbacks now accept an optional event object — matching Java Processing's API exactly. Both zero-arg and event-arg overloads are supported simultaneously:

void mousePressed() { /* old style still works */ }
void mousePressed(MouseEvent e) {
  println(e.getButton(), e.isShiftDown(), e.getX(), e.getY());
}

void keyPressed(KeyEvent e) {
  println(e.getKey(), e.isControlDown(), e.getAction());
}

void mouseWheel(MouseEvent e) {
  println(e.getCount()); // scroll steps
}

Available on all callbacks: mousePressed, mouseReleased, mouseClicked, mouseMoved, mouseDragged, mouseWheel, keyPressed, keyReleased, keyTyped.

Both MouseEvent and KeyEvent expose the full Java Processing method set: getX(), getY(), getButton(), getCount(), getAction(), isShiftDown(), isControlDown(), isAltDown(), isMetaDown(), getKey(), getKeyCode().

Parser fixes

  • ArrayList<T> and other template types at top level — fixed a bug where trailing-declarator detection consumed the next top-level declaration, causing ArrayList<Ball> balls; after a class body to produce a false parse error
  • Comparison vs template ambiguityneighbours < 2 || neighbours > 3 no longer triggers a false "unexpected token" error; integer literals and comparison-chained identifiers after < are now correctly identified as comparisons, not template argument lists
  • union supportunion is now fully parsed and emitted alongside struct and class
  • Anonymous structs and unionsstruct { float x, y; } pos; works at top level and inside class bodies
  • Trailing declaratorsclass Foo { ... } *ptr, instance; is fully supported

Linter improvements

The live error underline (linter) now uses the same ClassHoister pass as the real build, so:

  • User-defined classes defined after setup()/draw() are correctly hoisted and visible to the rest of the sketch
  • Class methods that call Processing API functions (fill, ellipse, etc.) no longer produce false "cannot call member function without object" underlines
  • Static member definitions (int Counter::count = 0;) are correctly placed at file scope, not inside the sketch struct
  • The linter _PSketch proxy struct now matches the real generated struct, so width, height, mouseX, mouseY etc. are accessible inside hoisted user classes

Engine fixes

  • PVector constructors now accept proxy types (the width/height proxy structs), so PVector(width, height - 20) inside a user-defined class works correctly
  • All Processing API template functions (fill, stroke, ellipse, rect, etc.) now accept proxy types via is_convertible_v instead of is_arithmetic_v
  • fullScreen(int mode) implementation was missing — calling it caused a linker error
  • line(A, B, C, D) 4-arg template declaration was missing its template<> prefix