All Downloads are FREE. Search and download functionalities are using the official Maven repository.

playn.flash.FlashPointer Maven / Gradle / Ivy

The newest version!
/**
 * Copyright 2010 The PlayN Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package playn.flash;

import flash.events.MouseEvent;
import flash.display.Sprite;

import playn.core.Events;
import playn.core.PlayN;
import playn.core.PointerImpl;

class FlashPointer extends PointerImpl {

  private boolean mouseDown;

  FlashPointer() {
    // Mouse handlers.
    FlashPlatform.captureEvent(Sprite.MOUSEDOWN, new EventHandler() {
      @Override
      public void handleEvent(MouseEvent nativeEvent) {
        mouseDown = true;
        if (onPointerStart(toEvent(nativeEvent), false))
          nativeEvent.preventDefault();
      }
    });
    FlashPlatform.captureEvent(Sprite.MOUSEUP, new EventHandler() {
      @Override
      public void handleEvent(MouseEvent nativeEvent) {
        mouseDown = false;
        if (onPointerEnd(toEvent(nativeEvent), false))
          nativeEvent.preventDefault();
      }
    });
    FlashPlatform.captureEvent(Sprite.MOUSEMOVE, new EventHandler() {
      @Override
      public void handleEvent(MouseEvent nativeEvent) {
        if (mouseDown && onPointerDrag(toEvent(nativeEvent), false))
          nativeEvent.preventDefault();
      }
    });
  }

  protected static Event.Impl toEvent(MouseEvent event) {
    return new Event.Impl(
      new Events.Flags.Impl(), PlayN.currentTime(), event.getStageX(), event.getStageY(), false);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy