bindEventListeners method

  1. @override
void bindEventListeners()
override

Binds all the eventListeners All the events should be converted to Event and sent to the onEvent method This method needs to be implemented in subclasses

Implementation

@override
void bindEventListeners() {
  eventListeners.addAll([
    canvas.onMouseMove.listen((event) {
      prevMousePosition = mousePosition.copy();

      var mouseCoords = getMouseScreenPosition(event.page);
      mousePosition = getCoordinates(mouseCoords.x, mouseCoords.y);

      createMouseMovedEvent();

      if (isDragging) {
        dragCurrentPosition = mousePosition;
        createMouseDraggedEvent();
      }
    }),
    canvas.onMouseDown.listen((event) {
      prevMousePosition = mousePosition.copy();

      var mouseCoords = getMouseScreenPosition(event.page);
      mousePosition = getCoordinates(mouseCoords.x, mouseCoords.y);

      mouseButton = MouseButton(event.button);

      createMousePressedEvent();

      isDragging = true;
      dragStartPosition = mousePosition.copy();
      dragCurrentPosition = mousePosition.copy();
    }),
    canvas.onMouseUp.listen((event) {
      prevMousePosition = mousePosition.copy();

      var mouseCoords = getMouseScreenPosition(event.page);
      mousePosition = getCoordinates(mouseCoords.x, mouseCoords.y);

      mouseButton = MouseButton(event.button);

      createMouseReleasedEvent();
      isDragging = false;
    }),
  ]);
}