mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-16 04:13:50 +00:00
[steam] Add possibility to take screenshots and add them to the Steam library
Requests: https://community.aseprite.org/t/6067 https://steamcommunity.com/app/431730/discussions/0/1482109512300945388/ https://steamcommunity.com/app/431730/discussions/0/1495615865218665223/ https://steamcommunity.com/app/431730/discussions/0/1708438376933048578/
This commit is contained in:
parent
064482b352
commit
2f472f0760
@ -21,7 +21,6 @@
|
||||
<key command="ExportSpriteSheet" shortcut="Ctrl+E" mac="Cmd+E" />
|
||||
<key command="RepeatLastExport" shortcut="Ctrl+Shift+X" mac="Cmd+Shift+X" />
|
||||
<key command="AdvancedMode" shortcut="Ctrl+F" />
|
||||
<key command="DeveloperConsole" shortcut="F12" />
|
||||
<key command="Exit" win="Ctrl+Q" linux="Ctrl+Q" mac="Cmd+Q" />
|
||||
<key command="Exit" win="Alt+F4" />
|
||||
<key command="Cancel" shortcut="Esc">
|
||||
@ -510,6 +509,9 @@
|
||||
<param name="save" value="true" />
|
||||
<param name="srgb" value="false" />
|
||||
</key>
|
||||
<key command="Screenshot" shortcut="F12">
|
||||
<param name="steam" value="true" />
|
||||
</key>
|
||||
</commands>
|
||||
|
||||
<!-- Keyboard shortcuts to select tools -->
|
||||
|
@ -400,6 +400,7 @@ SavePalette = Save Palette
|
||||
Screenshot = Screenshot
|
||||
Screenshot_Open = Take & Open Screenshot
|
||||
Screenshot_Save = Take & Save Screenshot
|
||||
Screenshot_Steam = Take & Add Screenshot to Steam
|
||||
Screenshot_sRGB = (sRGB Color Profile)
|
||||
Screenshot_DisplayCS = (Display Color Profile)
|
||||
Scroll = Scroll {0}
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2019 Igara Studio S.A.
|
||||
// Copyright (C) 2019-2020 Igara Studio S.A.
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
// the End-User License Agreement for Aseprite.
|
||||
@ -17,15 +17,23 @@
|
||||
#include "app/file/file.h"
|
||||
#include "app/i18n/strings.h"
|
||||
#include "app/resource_finder.h"
|
||||
#include "base/buffer.h"
|
||||
#include "base/fs.h"
|
||||
#include "doc/cel.h"
|
||||
#include "doc/color.h"
|
||||
#include "doc/image_impl.h"
|
||||
#include "doc/layer.h"
|
||||
#include "doc/sprite.h"
|
||||
#include "fmt/format.h"
|
||||
#include "os/display.h"
|
||||
#include "os/surface.h"
|
||||
#include "ui/alert.h"
|
||||
#include "ui/manager.h"
|
||||
#include "ui/scale.h"
|
||||
|
||||
#ifdef ENABLE_STEAM
|
||||
#include "steam/steam.h"
|
||||
#endif
|
||||
|
||||
namespace app {
|
||||
|
||||
@ -34,6 +42,9 @@ using namespace ui;
|
||||
struct ScreenshotParams : public NewParams {
|
||||
Param<bool> save { this, false, "save" };
|
||||
Param<bool> srgb { this, true, "srgb" };
|
||||
#ifdef ENABLE_STEAM
|
||||
Param<bool> steam { this, false, "steam" };
|
||||
#endif
|
||||
};
|
||||
|
||||
class ScreenshotCommand : public CommandWithNewParams<ScreenshotParams> {
|
||||
@ -85,9 +96,11 @@ void ScreenshotCommand::onExecute(Context* ctx)
|
||||
|
||||
doc::Cel* cel = spr->firstLayer()->cel(0);
|
||||
doc::Image* img = cel->image();
|
||||
const int w = img->width();
|
||||
const int h = img->height();
|
||||
|
||||
for (int y=0; y<img->height(); ++y) {
|
||||
for (int x=0; x<img->width(); ++x) {
|
||||
for (int y=0; y<h; ++y) {
|
||||
for (int x=0; x<w; ++x) {
|
||||
gfx::Color c = surface->getPixel(x, y);
|
||||
|
||||
img->putPixel(x, y, doc::rgba(gfx::getr(c),
|
||||
@ -103,6 +116,34 @@ void ScreenshotCommand::onExecute(Context* ctx)
|
||||
if (params().srgb())
|
||||
cmd::convert_color_profile(spr, gfx::ColorSpace::MakeSRGB());
|
||||
|
||||
if (params().steam()) {
|
||||
#ifdef ENABLE_STEAM
|
||||
if (auto steamAPI = steam::SteamAPI::instance()) {
|
||||
// Get image again (cmd::convert_color_profile() might have changed it)
|
||||
img = cel->image();
|
||||
|
||||
const int scale = display->scale();
|
||||
base::buffer rgbBuffer(3*w*h*scale*scale);
|
||||
int c = 0;
|
||||
doc::LockImageBits<RgbTraits> bits(img);
|
||||
for (int y=0; y<h; ++y) {
|
||||
for (int i=0; i<scale; ++i) {
|
||||
for (int x=0; x<w; ++x) {
|
||||
color_t color = get_pixel_fast<RgbTraits>(img, x, y);
|
||||
for (int j=0; j<scale; ++j) {
|
||||
rgbBuffer[c++] = doc::rgba_getr(color);
|
||||
rgbBuffer[c++] = doc::rgba_getg(color);
|
||||
rgbBuffer[c++] = doc::rgba_getb(color);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (steamAPI->writeScreenshot(&rgbBuffer[0], rgbBuffer.size(), w*scale, h*scale))
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if (params().save()) {
|
||||
save_document(ctx, doc.get());
|
||||
}
|
||||
@ -115,7 +156,9 @@ void ScreenshotCommand::onExecute(Context* ctx)
|
||||
std::string ScreenshotCommand::onGetFriendlyName() const
|
||||
{
|
||||
std::string name;
|
||||
if (params().save())
|
||||
if (params().steam())
|
||||
name = Strings::commands_Screenshot_Steam();
|
||||
else if (params().save())
|
||||
name = Strings::commands_Screenshot_Save();
|
||||
else
|
||||
name = Strings::commands_Screenshot_Open();
|
||||
|
@ -1,3 +1,4 @@
|
||||
Copyright (c) 2020 Igara Studio S.A.
|
||||
Copyright (c) 2016 David Capello
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
|
@ -1,4 +1,5 @@
|
||||
// Aseprite Steam Wrapper
|
||||
// Copyright (c) 2020 Igara Studio S.A.
|
||||
// Copyright (c) 2016 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
@ -12,13 +13,22 @@
|
||||
|
||||
#include "base/dll.h"
|
||||
#include "base/fs.h"
|
||||
#include "base/ints.h"
|
||||
#include "base/log.h"
|
||||
#include "base/string.h"
|
||||
|
||||
namespace steam {
|
||||
|
||||
typedef bool (*SteamAPI_Init_Func)();
|
||||
typedef void (*SteamAPI_Shutdown_Func)();
|
||||
typedef uint32_t ScreenshotHandle;
|
||||
typedef void* ISteamScreenshots;
|
||||
|
||||
// Steam main API
|
||||
typedef bool __cdecl (*SteamAPI_Init_Func)();
|
||||
typedef void __cdecl (*SteamAPI_Shutdown_Func)();
|
||||
|
||||
// ISteamScreenshots
|
||||
typedef ISteamScreenshots* __cdecl (*SteamAPI_SteamScreenshots_v003_Func)();
|
||||
typedef ScreenshotHandle __cdecl (*SteamAPI_ISteamScreenshots_WriteScreenshot_Func)(ISteamScreenshots*, void*, uint32_t, int, int);
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifdef _WIN64
|
||||
@ -32,9 +42,11 @@ typedef void (*SteamAPI_Shutdown_Func)();
|
||||
#define STEAM_API_DLL_FILENAME "libsteam_api.so"
|
||||
#endif
|
||||
|
||||
#define GETPROC(name) base::get_dll_proc<name##_Func>(m_steamLib, #name)
|
||||
|
||||
class SteamAPI::Impl {
|
||||
public:
|
||||
Impl() : m_initialized(false) {
|
||||
Impl() {
|
||||
m_steamLib = base::load_dll(
|
||||
base::join_path(base::get_file_path(base::get_app_path()),
|
||||
STEAM_API_DLL_FILENAME));
|
||||
@ -43,18 +55,19 @@ public:
|
||||
return;
|
||||
}
|
||||
|
||||
auto SteamAPI_Init = base::get_dll_proc<SteamAPI_Init_Func>(m_steamLib, "SteamAPI_Init");
|
||||
auto SteamAPI_Init = GETPROC(SteamAPI_Init);
|
||||
if (!SteamAPI_Init) {
|
||||
LOG("STEAM: SteamAPI_Init not found...\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// Call SteamAPI_Init() to connect to Steam
|
||||
if (!SteamAPI_Init()) {
|
||||
LOG("STEAM: Steam is not initialized...\n");
|
||||
return;
|
||||
}
|
||||
|
||||
LOG("STEAM: Steam initialized...\n");
|
||||
LOG("STEAM: Steam initialized\n");
|
||||
m_initialized = true;
|
||||
}
|
||||
|
||||
@ -62,7 +75,7 @@ public:
|
||||
if (!m_steamLib)
|
||||
return;
|
||||
|
||||
auto SteamAPI_Shutdown = base::get_dll_proc<SteamAPI_Shutdown_Func>(m_steamLib, "SteamAPI_Shutdown");
|
||||
auto SteamAPI_Shutdown = GETPROC(SteamAPI_Shutdown);
|
||||
if (SteamAPI_Shutdown) {
|
||||
LOG("STEAM: Steam shutdown...\n");
|
||||
SteamAPI_Shutdown();
|
||||
@ -75,19 +88,55 @@ public:
|
||||
return m_initialized;
|
||||
}
|
||||
|
||||
bool writeScreenshot(void* rgbBuffer,
|
||||
uint32_t sizeInBytes,
|
||||
int width, int height) {
|
||||
if (!m_initialized)
|
||||
return false;
|
||||
|
||||
auto SteamScreenshots = GETPROC(SteamAPI_SteamScreenshots_v003);
|
||||
auto WriteScreenshot = GETPROC(SteamAPI_ISteamScreenshots_WriteScreenshot);
|
||||
if (!SteamScreenshots || !WriteScreenshot) {
|
||||
LOG("STEAM: Error getting Steam Screenshot API functions\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto screenshots = SteamScreenshots();
|
||||
if (!screenshots) {
|
||||
LOG("STEAM: Error getting Steam Screenshot API instance\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
WriteScreenshot(screenshots, rgbBuffer, sizeInBytes, width, height);
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
base::dll m_steamLib;
|
||||
bool m_initialized;
|
||||
bool m_initialized = false;
|
||||
base::dll m_steamLib = nullptr;
|
||||
};
|
||||
|
||||
SteamAPI* g_instance = nullptr;
|
||||
|
||||
// static
|
||||
SteamAPI* SteamAPI::instance()
|
||||
{
|
||||
return g_instance;
|
||||
}
|
||||
|
||||
SteamAPI::SteamAPI()
|
||||
: m_impl(new Impl)
|
||||
{
|
||||
ASSERT(g_instance == nullptr);
|
||||
g_instance = this;
|
||||
}
|
||||
|
||||
SteamAPI::~SteamAPI()
|
||||
{
|
||||
delete m_impl;
|
||||
|
||||
ASSERT(g_instance == this);
|
||||
g_instance = nullptr;
|
||||
}
|
||||
|
||||
bool SteamAPI::initialized() const
|
||||
@ -95,4 +144,11 @@ bool SteamAPI::initialized() const
|
||||
return m_impl->initialized();
|
||||
}
|
||||
|
||||
bool SteamAPI::writeScreenshot(void* rgbBuffer,
|
||||
uint32_t sizeInBytes,
|
||||
int width, int height)
|
||||
{
|
||||
return m_impl->writeScreenshot(rgbBuffer, sizeInBytes, width, height);
|
||||
}
|
||||
|
||||
} // namespace steam
|
||||
|
@ -1,4 +1,5 @@
|
||||
// Aseprite Steam Wrapper
|
||||
// Copyright (c) 2020 Igara Studio S.A.
|
||||
// Copyright (c) 2016 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
@ -12,11 +13,17 @@ namespace steam {
|
||||
|
||||
class SteamAPI {
|
||||
public:
|
||||
static SteamAPI* instance();
|
||||
|
||||
SteamAPI();
|
||||
~SteamAPI();
|
||||
|
||||
bool initialized() const;
|
||||
|
||||
bool writeScreenshot(void* rgbBuffer,
|
||||
uint32_t sizeInBytes,
|
||||
int width, int height);
|
||||
|
||||
private:
|
||||
class Impl;
|
||||
Impl* m_impl;
|
||||
|
Loading…
Reference in New Issue
Block a user