processing.event.MouseEvent Java Examples

The following examples show how to use processing.event.MouseEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ProcessingTouchEvents.java    From Circle-Synth with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Mouse event listener
 * @param event MouseEvent
 */
public void mouseEvent(MouseEvent event) {

	switch (event.getAction()) {

	case MouseEvent.PRESS:
		mX = event.getX();
		mY = event.getY();
		touchDown(mX, mY);

		break;

	case MouseEvent.RELEASE:
		mX = event.getX();
		mY = event.getY();
		touchUp(mX, mY);
	}
}
 
Example #2
Source File: MapViewTileRenderer.java    From constellation with Apache License 2.0 6 votes vote down vote up
/**
 * Update the zoom level of the map based on the given set of markers.
 *
 * @param event the mouse event which caused the zoom
 * @param markers the markers to zoom to
 */
private void handleMouseZoom(final MouseEvent event, final Set<ConstellationAbstractMarker> markers) {
    assert !SwingUtilities.isEventDispatchThread();

    if (markers == null) {
        return;
    }

    // the zoomAndPanToFit method is known to break for any of the following locations
    final List<Location> breakingLocations = new ArrayList<>();
    breakingLocations.add(new Location(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY));
    breakingLocations.add(new Location(Float.POSITIVE_INFINITY, Float.NEGATIVE_INFINITY));
    breakingLocations.add(new Location(Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY));
    breakingLocations.add(new Location(Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY));

    final List<Location> locations = markers.stream()
            .map(marker -> marker.getLocation())
            .filter(location -> !breakingLocations.contains(location))
            .collect(Collectors.toList());

    if (!locations.isEmpty()) {
        map.zoomAndPanToFit(locations);
    }
}
 
Example #3
Source File: MapViewTileRenderer.java    From constellation with Apache License 2.0 6 votes vote down vote up
@Override
public void mousePressed(final MouseEvent event) {
    assert !SwingUtilities.isEventDispatchThread();

    if (event.getButton() == PConstants.CENTER || event.getButton() == PConstants.LEFT) {
        // zoom to box
        boxOriginX = event.getX();
        boxOriginY = event.getY();
    } else if (event.getButton() == PConstants.RIGHT && event.getCount() == 2) {
        dispatcher.register(map, ZoomMapEvent.TYPE_ZOOM, map.getId());
        // Pan + Zoom (order is important)
        final PanMapEvent panMapEvent = new PanMapEvent(this, map.getId());
        final Location location = map.getLocation(mouseX, mouseY);
        panMapEvent.setToLocation(location);
        dispatcher.fireMapEvent(panMapEvent);
        final ZoomMapEvent zoomMapEvent = new ZoomMapEvent(this, map.getId(), ZoomMapEvent.ZOOM_BY_LEVEL, 1);
        zoomMapEvent.setTransformationCenterLocation(location);
        dispatcher.fireMapEvent(zoomMapEvent);
        dispatcher.unregister(map, ZoomMapEvent.TYPE_ZOOM, map.getId());
    }

    overlays.forEach(overlay -> overlay.mousePressed(event));
}
 
Example #4
Source File: MapViewTileRenderer.java    From constellation with Apache License 2.0 6 votes vote down vote up
@Override
public void mouseMoved(final MouseEvent event) {
    assert !SwingUtilities.isEventDispatchThread();

    synchronized (LOCK) {
        map.getMarkers().forEach(marker -> {
            ((ConstellationAbstractMarker) marker).setHighlighted(false);
        });

        map.getHitMarkers(mouseX, mouseY).forEach(hitMarker -> {
            ((ConstellationAbstractMarker) hitMarker).setHighlighted(true);
        });
    }

    overlays.forEach(overlay -> overlay.mouseMoved(event));
}
 
Example #5
Source File: MapViewTileRenderer.java    From constellation with Apache License 2.0 6 votes vote down vote up
@Override
public void mouseClicked(final MouseEvent event) {
    assert !SwingUtilities.isEventDispatchThread();

    final List<ConstellationAbstractMarker> hitMarkers;
    synchronized (LOCK) {
        hitMarkers = map.getHitMarkers(mouseX, mouseY)
                .stream().map(marker -> (ConstellationAbstractMarker) marker).collect(Collectors.toList());
    }

    if (event.getButton() == PConstants.LEFT) {
        // select markers
        if (event.getCount() == 2) {
            handleMouseSelection(event, new HashSet<>());
        } else if (!hitMarkers.isEmpty()) {
            handleMouseSelection(event, new HashSet<>(hitMarkers));
        }
    }

    overlays.forEach(overlay -> overlay.mouseClicked(event));
}
 
Example #6
Source File: PScene.java    From Project-16x16 with GNU General Public License v3.0 6 votes vote down vote up
/**
 * This method is <b>Public</b> only to enable binding to a parent PApplet.
 * <p>
 * You can <b>ignore this method</b> since the parent sketch will call it
 * automatically when it detects a mouse event (provided register() has been
 * called).
 */
public final void mouseEvent(MouseEvent e) {
	switch (e.getAction()) {
		case MouseEvent.PRESS :
			mousePressed(e);
			break;
		case MouseEvent.RELEASE :
			mouseReleased(e);
			break;
		case MouseEvent.CLICK :
			mouseClicked(e);
			break;
		case MouseEvent.WHEEL :
			mouseWheel(e);
			break;
		case MouseEvent.DRAG :
			mouseDragged(e);
			break;
		default :
			break;
	}
}
 
Example #7
Source File: DwColorPicker.java    From PixelFlow with MIT License 6 votes vote down vote up
public void mouseEvent(MouseEvent me) {
  int mx_global = me.getX();
  int my_global = me.getY();
  int mx = mx_global - cp_x;
  int my = my_global - cp_y;
  
  if(me.getAction() == MouseEvent.PRESS){
    SELECTION_ACTIVE = inside(mx, my);
    cb_mouseEvent(me);
  }
  if(me.getAction() == MouseEvent.RELEASE){
    SELECTION_ACTIVE = false;
    cb_mouseEvent(me);
  }
  
  if(SELECTION_ACTIVE){
    selectColorByCoords(mx, my);
    LAST_USED = this;
    cb_mouseEvent(me);
  }

}
 
Example #8
Source File: BaseSavedQuadUI.java    From haxademic with MIT License 6 votes vote down vote up
public void checkMouseDragPoint(MouseEvent event) {
	switch (event.getAction()) {
	case MouseEvent.PRESS:
		break;
	case MouseEvent.RELEASE:
		if(SELECTED_POINT != null) save();
		SELECTED_POINT = null;
		break;
	case MouseEvent.MOVE:
		checkMouseHoverPoint();
		break;
	case MouseEvent.DRAG:
		if( SELECTED_POINT != null ) {
			SELECTED_POINT.setLocation( mousePoint );
			updateCenter();
		}
		break;
	}
}
 
Example #9
Source File: BaseSavedQuadUI.java    From haxademic with MIT License 6 votes vote down vote up
public void checkMouseDragQuad(MouseEvent event) {
	switch (event.getAction()) {
	case MouseEvent.PRESS:
		if(isHovered == true && SELECTED_POINT == null) {
			DRAGGING_QUAD = this;
			mouseDragged.setLocation(mousePoint.x, mousePoint.y);
			updateCenter();
		}
		break;
	case MouseEvent.RELEASE:
		if(DRAGGING_QUAD != null) save();
		DRAGGING_QUAD = null;
		break;
	case MouseEvent.DRAG:
		if(DRAGGING_QUAD == this) {
			mouseDragged.setLocation(mousePoint.x - mouseDragged.x, mousePoint.y - mouseDragged.y);
			for( int i=0; i < points.length; i++ ) {
				points[i].translate(mouseDragged.x, mouseDragged.y);
			}
			mouseDragged.setLocation(mousePoint.x, mousePoint.y);
			updateCenter();
		}
		break;
	}
}
 
Example #10
Source File: SavedPointUI.java    From haxademic with MIT License 6 votes vote down vote up
public void checkMouseDrag(MouseEvent event) {
	switch (event.getAction()) {
	case MouseEvent.PRESS:
		if(isHovered == true) {
			DRAGGING_POINT = this;
		}
		break;
	case MouseEvent.DRAG:
		if(DRAGGING_POINT == this) {
			position.set(mousePoint.x, mousePoint.y);
		}
		break;
	case MouseEvent.RELEASE:
		if(DRAGGING_POINT == this) save();
		DRAGGING_POINT = null;
		break;
	}
}
 
Example #11
Source File: MouseShutdown.java    From haxademic with MIT License 6 votes vote down vote up
public void mouseEvent(MouseEvent event) {
  // int x = event.getX();
  // int y = event.getY();

  switch (event.getAction()) {
    case MouseEvent.PRESS:
      break;
    case MouseEvent.RELEASE:
      break;
    case MouseEvent.CLICK:
    	click();
      break;
    case MouseEvent.DRAG:
      break;
    case MouseEvent.MOVE:
      break;
  }
}
 
Example #12
Source File: UIButton.java    From haxademic with MIT License 6 votes vote down vote up
public void mouseEvent(MouseEvent event) {
	if(!isActive()) return;
	
	int mouseX = event.getX();
	int mouseY = event.getY();

	switch (event.getAction()) {
		case MouseEvent.PRESS:
			pressed = rect.contains(mouseX, mouseY);
			break;
		case MouseEvent.RELEASE:
			if(pressed && over) click();
			pressed = false;
			break;
		case MouseEvent.MOVE:
			over = rect.contains(mouseX, mouseY);
			break;
		case MouseEvent.DRAG:
			over = rect.contains(mouseX, mouseY);
			break;
	}
}
 
Example #13
Source File: UISlider.java    From haxademic with MIT License 6 votes vote down vote up
public void mouseEvent(MouseEvent event) {
	if(isActive() == false) return;
	// collision detection
	mousePoint.setLocation(event.getX(), event.getY());
	switch (event.getAction()) {
	case MouseEvent.PRESS:
		if(uiRect.contains(mousePoint)) mousePressed = true;
		break;
	case MouseEvent.RELEASE:
		if(mousePressed) {
			mousePressed = false;
			if(saves) PrefToText.setValue(id, value);
		}
		break;
	case MouseEvent.MOVE:
		mouseHovered = uiRect.contains(mousePoint);
		break;
	case MouseEvent.DRAG:
		if(mousePressed) {
			float deltaX = (P.p.mouseX - P.p.pmouseX) * dragStep;
			value += deltaX;
			value = P.constrain(value, valueMin, valueMax);
		}
		break;
	}
}
 
Example #14
Source File: SavedPointUI.java    From haxademic with MIT License 5 votes vote down vote up
public void checkHover(MouseEvent event) {
	switch (event.getAction()) {
	case MouseEvent.MOVE:
		isHovered = (position.dist( mousePoint ) < mouseActiveDist);
		if(active && !isHovered) active = false;
		break;
	}
}
 
Example #15
Source File: DMXEditor.java    From haxademic with MIT License 5 votes vote down vote up
public void checkMouseDragPoint(MouseEvent event) {
	boolean createDragMode = P.store.getBoolean(DRAG_CREATE_MODE);
	switch (event.getAction()) {
	case MouseEvent.PRESS:
		if(createDragMode && isHoveringPoint() == false) {
			// check points to see if one is hovered. cancel if so
			points.add(newPoint());
			draggingNewPoint = true;
		}
		break;
	case MouseEvent.RELEASE:
		// create a 2nd point on release
		if(createDragMode && draggingNewPoint) {
			points.add(newPoint());
			draggingNewPoint = false;
			lights.add(new LightBar(dmxUniverseDefault, dmxMode, points.get(points.size() - 2).position(), points.get(points.size() - 1).position())); // add last 2 points PVectors to new LightFixture
		}
		break;
	case MouseEvent.MOVE:
		// set hovered point as active
		boolean foundOne = false;
		for (int i = 0; i < points.size(); i++) {
			if(points.get(i).isHovered()) {
				pointIndex = i;
				foundOne = true;
			}
		}
		if(foundOne == false) pointIndex = -1;
		setActivePoint();
		break;
	case MouseEvent.DRAG:
		// if creating a new line, draw line from first point
		break;
	}
}
 
Example #16
Source File: UITextInput.java    From haxademic with MIT License 5 votes vote down vote up
public void mouseEvent(MouseEvent event) {
	if(active == false) return;
	int mouseX = event.getX();
	int mouseY = event.getY();
	
	switch (event.getAction()) {
	case MouseEvent.PRESS:
		pressed = rect.contains(mouseX,  mouseY);
		// if no textinputs are clicked, clear out ACTIVE_INPUT
		break;
	case MouseEvent.RELEASE:
		pressed = false;
		focused = rect.contains(mouseX, mouseY);
		ACTIVE_INPUT = null;
		if(focused) {
			SystemUtil.setTimeout(activeTimeout, 10);
		} else {
			if(saves) PrefToText.setValue(id, value);
		}
		break;
	case MouseEvent.MOVE:
		over = rect.contains(mouseX,  mouseY);
		break;
	case MouseEvent.DRAG:
		break;
	}
}
 
Example #17
Source File: OverviewOverlay.java    From constellation with Apache License 2.0 5 votes vote down vote up
@Override
public void mouseDragged(final MouseEvent event) {
    if (viewport.isDragging) {
        viewport.x = renderer.mouseX - deltaX;
        viewport.y = renderer.mouseY - deltaY;

        viewport.update(0);
    }
}
 
Example #18
Source File: OverviewOverlay.java    From constellation with Apache License 2.0 5 votes vote down vote up
@Override
public void mousePressed(final MouseEvent event) {
    if (viewport.isOver(renderer.mouseX, renderer.mouseY)) {
        active = true;
        viewport.isDragging = true;
        deltaX = renderer.mouseX - viewport.x;
        deltaY = renderer.mouseY - viewport.y;
    }
}
 
Example #19
Source File: SavedRectangle.java    From haxademic with MIT License 5 votes vote down vote up
public void mouseEvent(MouseEvent event) {
	switch (event.getAction()) {
		case MouseEvent.PRESS:
			mouseStartPoint.setLocation( event.getX() + rectOffset.x, event.getY() + rectOffset.y );
			if(rectangle.contains(mouseStartPoint) && SavedRectangle.curDragging == null) {
				isDragging = true;
				SavedRectangle.curDragging = this;
				float cornerClickDist = (float) mouseStartPoint.distance(rectangle.x + rectangle.width, rectangle.y + rectangle.height);
				if(cornerClickDist < 15) {
					isResizing = true;
				} 
				rectangleMove = new Rectangle(rectangle); // build temp rectangle for moving
			}
			break;
		case MouseEvent.RELEASE:
			if(isDragging == true) {
				updateRectangle(rectangleMove);
				SavedRectangle.curDragging = null;
				rectangleMove = null;
				isDragging = false;
				isResizing = false;
			}
			break;
		case MouseEvent.MOVE:
			break;
		case MouseEvent.DRAG:
			if(isDragging == true) {
				mouseMovePoint.setLocation( event.getX() + rectOffset.x, event.getY() + rectOffset.y );
				int mouseDeltaX = mouseMovePoint.x - mouseStartPoint.x;
				int mouseDeltaY = mouseMovePoint.y - mouseStartPoint.y;
				if(isResizing == false) {
					rectangleMove.setLocation(rectangle.x + mouseDeltaX, rectangle.y + mouseDeltaY );
				} else {
					rectangleMove.setSize(rectangle.width + mouseDeltaX, rectangle.height + mouseDeltaY );
				}
			}
			break;
	}
}
 
Example #20
Source File: SavedPointUI.java    From haxademic with MIT License 5 votes vote down vote up
public void mouseEvent(MouseEvent event) {
	resetInteractionTimeout();
	mousePoint.set( event.getX(), event.getY() );
	checkHover(event);
	if(active == false) return;
	checkMouseDrag(event);
}
 
Example #21
Source File: BaseSavedQuadUI.java    From haxademic with MIT License 5 votes vote down vote up
public void checkHoverQuad(MouseEvent event) {
	switch (event.getAction()) {
	case MouseEvent.MOVE:
		isHovered = inside(mousePoint, points);
		break;
	}
}
 
Example #22
Source File: GameplayScene.java    From Project-16x16 with GNU General Public License v3.0 5 votes vote down vote up
public void mouseWheel(MouseEvent event) {
	if (event.isShiftDown()) {
	} else {
		if (tool == Tools.INVENTORY) {
			scrollBar.mouseWheel(event);
			scroll_inventory = (int) PApplet.map(scrollBar.barLocation, 1, 0,
					-getInventorySize() + applet.height - 8, 0);
		}
	}
}
 
Example #23
Source File: BaseSavedQuadUI.java    From haxademic with MIT License 5 votes vote down vote up
public void mouseEvent(MouseEvent event) {
	mousePoint.setLocation( event.getX(), event.getY() );
	checkHoverQuad(event);
	if(active == false) return;
	resetInteractionTimeout();
	checkMouseDragPoint(event);
	checkMouseDragQuad(event);
}
 
Example #24
Source File: GameplayScene.java    From Project-16x16 with GNU General Public License v3.0 5 votes vote down vote up
@Override
void mouseDragged(MouseEvent e) {
	if (e.getButton() == PConstants.CENTER && tool == Tools.MODIFY) { // pan on MMB; TODO fix when zoom != 1.00
		applet.camera.setCameraPositionNoLerp(
				PVector.add(origPos, PVector.sub(mouseDown, applet.getMouseCoordScreen())));
	}
}
 
Example #25
Source File: GameplayScene.java    From Project-16x16 with GNU General Public License v3.0 5 votes vote down vote up
@Override
void mouseReleased(MouseEvent e) {
	switch (e.getButton()) {
		case LEFT :
			break;
		case RIGHT :
			selectionBox = null;
			break;
		default :
			break;
	}
}
 
Example #26
Source File: ToolsOverlay.java    From constellation with Apache License 2.0 5 votes vote down vote up
@Override
public void mouseMoved(final MouseEvent event) {

    // update measure line
    if (measureActive && !measureFinished) {
        measureDeltaX = event.getX();
        measureDeltaY = event.getY();
    }

    // update draw line
    if (drawActive) {
        drawDeltaX = event.getX();
        drawDeltaY = event.getY();
    }
}
 
Example #27
Source File: GameplayScene.java    From Project-16x16 with GNU General Public License v3.0 5 votes vote down vote up
@Override
void mousePressed(MouseEvent e) {
	origPos = applet.camera.getPosition(); // used for camera panning
	mouseDown = applet.getMouseCoordScreen();
	switch (e.getButton()) {
		case LEFT :
			boolean overAny = false;
			for (EditableObject o : objects) {
				if (o.isFocused()) {
					o.focus(); // refocus multi-select objects (edit offset)
				}
				if (o.mouseHover()) {
					o.focus();
					overAny = true;
				}
			}
			if (!overAny) { // if not over any, deselect all
				objects.forEach(o -> o.unFocus());
			}
			break;
		case RIGHT :
			if (tool == Tools.MODIFY) {
				selectionBox = new SelectionBox(mouseDown);
			}
			break;
		default :
			break;
	}
}
 
Example #28
Source File: MapLayer.java    From constellation with Apache License 2.0 5 votes vote down vote up
public void mouseReleased(final MouseEvent event) {
    if (mouseIsDragging && event.getButton() == PConstants.RIGHT) {
        layer = null;
        mouseIsDragging = false;
        mouseIsReleased = true;
        releaseTime = renderer.millis();
    }
}
 
Example #29
Source File: MapLayer.java    From constellation with Apache License 2.0 5 votes vote down vote up
public void mouseWheel(final MouseEvent event) {
    if (!mouseIsDragging && event.getCount() != 0) {
        layer = null;
        mouseIsScrolling = true;
        scrollTime = renderer.millis();
    }
}
 
Example #30
Source File: SideScroller.java    From Project-16x16 with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Handles scrolling events.
 */
@Override
public void mouseWheel(MouseEvent event) {
	game.mouseWheel(event);
	if(game.isZoomable()) {
		if (event.getCount() == -1) { // for development
			camera.zoomIn(0.02f);
		} else {
			camera.zoomOut(0.02f);
		}
	}
}