Skip to content

Commit

Permalink
screenshot: add screenshot taken event
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam- committed Oct 14, 2023
1 parent 4ed62fc commit ad703f7
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2023, Adam <[email protected]>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.client.events;

import java.awt.image.BufferedImage;
import java.io.File;
import lombok.Value;

/**
* Event fired when a screenshot is taken
*/
@Value
public class ScreenshotTaken
{
/**
* Path to where the screenshot is stored
*/
File path;
/**
* The screenshot
*/
BufferedImage screenshot;
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
import net.runelite.client.Notifier;
import static net.runelite.client.RuneLite.SCREENSHOT_DIR;
import net.runelite.client.config.RuneScapeProfileType;
import net.runelite.client.eventbus.EventBus;
import net.runelite.client.events.ScreenshotTaken;
import net.runelite.client.ui.ClientUI;
import net.runelite.client.ui.DrawManager;

Expand All @@ -68,6 +70,7 @@ public class ImageCapture
private final ClientUI clientUi;
private final DrawManager drawManager;
private final ScheduledExecutorService executor;
private final EventBus eventBus;

/**
* Take a screenshot and save it
Expand Down Expand Up @@ -200,9 +203,10 @@ public void saveScreenshot(

fileName += (fileName.isEmpty() ? "" : " ") + format(new Date());

File screenshotFile;
try
{
File screenshotFile = new File(playerFolder, fileName + ".png");
screenshotFile = new File(playerFolder, fileName + ".png");

// To make sure that screenshots don't get overwritten, check if file exists,
// and if it does create file with same name and suffix.
Expand Down Expand Up @@ -233,7 +237,14 @@ else if (notify)
catch (IOException ex)
{
log.error("error writing screenshot", ex);
return;
}

ScreenshotTaken screenshotTaken = new ScreenshotTaken(
screenshotFile,
screenshot
);
eventBus.post(screenshotTaken);
}

/**
Expand Down

0 comments on commit ad703f7

Please sign in to comment.