1 /*
   2  * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package com.sun.glass.ui.win;
  26 
  27 import javafx.scene.input.KeyCode;
  28 import javafx.scene.input.MouseButton;
  29 import javafx.scene.paint.Color;
  30 
  31 import com.sun.glass.ui.Application;
  32 import com.sun.glass.ui.GlassRobot;
  33 
  34 /**
  35  * MS Windows platform implementation class for Robot.
  36  */
  37 final class WinRobot extends GlassRobot {
  38 
  39     @Override
  40     public void create() {
  41         // no-op
  42     }
  43 
  44     @Override
  45     public void destroy() {
  46         // no-op
  47     }
  48 
  49     native protected void _keyPress(int code);
  50     @Override
  51     public void keyPress(KeyCode code) {
  52         Application.checkEventThread();
  53         _keyPress(code.getCode());
  54     }
  55 
  56     native protected void _keyRelease(int code);
  57     @Override
  58     public void keyRelease(KeyCode code) {
  59         Application.checkEventThread();
  60         _keyRelease(code.getCode());
  61     }
  62 
  63 
  64     native protected void _mouseMove(int x, int y);
  65     @Override
  66     public void mouseMove(double x, double y) {
  67         Application.checkEventThread();
  68         _mouseMove((int) x, (int) y);
  69     }
  70 
  71     native protected void _mousePress(int buttons);
  72     @Override
  73     public void mousePress(MouseButton... buttons) {
  74         Application.checkEventThread();
  75         _mousePress(GlassRobot.convertToRobotMouseButton(buttons));
  76     }
  77 
  78     native protected void _mouseRelease(int buttons);
  79     @Override
  80     public void mouseRelease(MouseButton... buttons) {
  81         Application.checkEventThread();
  82         _mouseRelease(GlassRobot.convertToRobotMouseButton(buttons));
  83     }
  84 
  85     native protected void _mouseWheel(int wheelAmt);
  86     @Override
  87     public void mouseWheel(int wheelAmt) {
  88         Application.checkEventThread();
  89         _mouseWheel(wheelAmt);
  90     }
  91 
  92     native protected float _getMouseX();
  93     @Override
  94     public double getMouseX() {
  95         Application.checkEventThread();
  96         return _getMouseX();
  97     }
  98 
  99     native protected float _getMouseY();
 100     @Override
 101     public double getMouseY() {
 102         Application.checkEventThread();
 103         return _getMouseY();
 104     }
 105 
 106     native protected int _getPixelColor(int x, int y);
 107     @Override
 108     public Color getPixelColor(double x, double y) {
 109         Application.checkEventThread();
 110         return GlassRobot.convertFromIntArgb(_getPixelColor((int) x, (int) y));
 111     }
 112 
 113     native protected void _getScreenCapture(int x, int y, int width, int height, int[] data);
 114     @Override
 115     public void getScreenCapture(int x, int y, int width, int height, int[] data, boolean scaleToFit) {
 116         Application.checkEventThread();
 117         _getScreenCapture(x, y, width, height, data);
 118     }
 119 }