mouseScroll method

void mouseScroll(
  1. PointerSignalEvent event, {
  2. required Layer activeLayer,
  3. required int selectedLayerIndex,
})

Handles mouse scroll events.

Implementation

void mouseScroll(
  PointerSignalEvent event, {
  required Layer activeLayer,
  required int selectedLayerIndex,
}) {
  bool shiftDown = HardwareKeyboard.instance.logicalKeysPressed
          .contains(LogicalKeyboardKey.shiftLeft) ||
      HardwareKeyboard.instance.logicalKeysPressed
          .contains(LogicalKeyboardKey.shiftRight);

  if (event is PointerScrollEvent && selectedLayerIndex >= 0) {
    if (shiftDown) {
      if (event.scrollDelta.dy > 0) {
        activeLayer.rotation -= 0.087266;
      } else if (event.scrollDelta.dy < 0) {
        activeLayer.rotation += 0.087266;
      }
    } else {
      double factor = activeLayer is PaintingLayerData
          ? 0.1
          : activeLayer is TextLayerData
              ? 0.15
              : configs.textEditorConfigs.initFontSize / 50;
      if (event.scrollDelta.dy > 0) {
        activeLayer.scale -= factor;
        activeLayer.scale = max(0.1, activeLayer.scale);
      } else if (event.scrollDelta.dy < 0) {
        activeLayer.scale += factor;
      }
    }
    setState(() {});
    onUpdateUI?.call();
  }
}