1 /* 2 * Copyright (c) 2010, 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.gtk; 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 import com.sun.glass.ui.Screen; 34 35 final class GtkRobot extends GlassRobot { 36 37 @Override 38 public void create() { 39 // no-op 40 } 41 42 @Override 43 public void destroy() { 44 // no-op 45 } 46 47 @Override 48 public void keyPress(KeyCode code) { 49 Application.checkEventThread(); 50 _keyPress(code.getCode()); 51 } 52 53 protected native void _keyPress(int code); 54 55 @Override 56 public void keyRelease(KeyCode code) { 57 Application.checkEventThread(); 58 _keyRelease(code.getCode()); 59 } 60 61 protected native void _keyRelease(int code); 62 63 public native void _mouseMove(int x, int y); 64 65 @Override 66 public void mouseMove(double x, double y) { 67 Application.checkEventThread(); 68 _mouseMove((int) x, (int) y); 69 } 70 71 @Override 72 public void mousePress(MouseButton... buttons) { 73 Application.checkEventThread(); 74 _mousePress(GlassRobot.convertToRobotMouseButton(buttons)); 75 } 76 77 protected native void _mousePress(int button); 78 79 @Override 80 public void mouseRelease(MouseButton... buttons) { 81 Application.checkEventThread(); 82 _mouseRelease(GlassRobot.convertToRobotMouseButton(buttons)); 83 } 84 85 protected native void _mouseRelease(int buttons); 86 87 @Override 88 public void mouseWheel(int wheelAmt) { 89 Application.checkEventThread(); 90 _mouseWheel(wheelAmt); 91 } 92 93 protected native void _mouseWheel(int wheelAmt); 94 95 @Override 96 public double getMouseX() { 97 Application.checkEventThread(); 98 return _getMouseX(); 99 } 100 101 protected native int _getMouseX(); 102 103 @Override 104 public double getMouseY() { 105 Application.checkEventThread(); 106 return _getMouseY(); 107 } 108 109 protected native int _getMouseY(); 110 111 @Override 112 public Color getPixelColor(double x, double y) { 113 Application.checkEventThread(); 114 Screen mainScreen = Screen.getMainScreen(); 115 x = (int) Math.floor((x + 0.5) * mainScreen.getPlatformScaleX()); 116 y = (int) Math.floor((y + 0.5) * mainScreen.getPlatformScaleY()); 117 int[] result = new int[1]; 118 _getScreenCapture((int) x, (int) y, 1, 1, result); 119 return GlassRobot.convertFromIntArgb(result[0]); 120 } 121 122 protected native void _getScreenCapture(int x, int y, int width, int height, int[] data); 123 124 @Override 125 public void getScreenCapture(int x, int y, int width, int height, int[] data, boolean scaleToFit) { 126 Application.checkEventThread(); 127 _getScreenCapture(x, y, width, height, data); 128 } 129 }