handleSdlEvent method

  1. @override
void handleSdlEvent(
  1. Event event
)
override

Handle SDL events.

Implementation

@override
void handleSdlEvent(final Event event) {
  if (event is KeyboardEvent &&
      event.repeat == false &&
      event.state == PressedState.pressed &&
      (event.key.modifiers.isEmpty ||
          (event.key.modifiers.length == 1 &&
              event.key.modifiers.contains(KeyMod.num)))) {
    final scanCode = event.key.scancode;
    if (scanCode == upScanCode) {
      up();
    } else if (scanCode == downScanCode) {
      down();
    } else if (scanCode == activateScanCode) {
      activate();
    } else if (scanCode == cancelScanCode) {
      cancel();
    } else {
      super.handleSdlEvent(event);
    }
  } else if (event is ControllerButtonEvent &&
      event.state == PressedState.pressed) {
    final button = event.button;
    if (button == upButton) {
      up();
    } else if (button == downButton) {
      down();
    } else if (button == activateButton) {
      activate();
    } else if (button == cancelButton) {
      cancel();
    } else {
      super.handleSdlEvent(event);
    }
  } else if (event is ControllerAxisEvent) {
    controllerAxisDispatcher.handleAxisValue(
      event.axis,
      event.smallValue,
    );
  } else if (event is TextInputEvent &&
      searchEnabled == true &&
      event.text.isNotEmpty) {
    if ((event.timestamp - searchTime) >= searchInterval) {
      searchString = '';
    }
    searchString += event.text.toLowerCase();
    searchTime = event.timestamp;
    for (var i = 0; i < menuItems.length; i++) {
      final item = menuItems.elementAt(i);
      final text = item.label.text;
      if (text != null && text.toLowerCase().startsWith(searchString)) {
        position = i;
        showCurrentItem();
        break;
      }
    }
  } else {
    super.handleSdlEvent(event);
  }
}