chore: Refactor clipboard functions to use namespace aliases

This commit is contained in:
scawful
2024-08-14 00:11:18 -04:00
parent 6ba3c0fc84
commit 731b8f1c75
8 changed files with 38 additions and 10 deletions

View File

@@ -3,6 +3,14 @@
#include <cstdint> #include <cstdint>
#include <vector> #include <vector>
namespace yaze {
namespace app {
namespace core {
void CopyImageToClipboard(const std::vector<uint8_t>& data) {} void CopyImageToClipboard(const std::vector<uint8_t>& data) {}
void GetImageFromClipboard(std::vector<uint8_t>& data, int& width, void GetImageFromClipboard(std::vector<uint8_t>& data, int& width,
int& height) {} int& height) {}
} // namespace core
} // namespace app
} // namespace yaze

View File

@@ -4,7 +4,15 @@
#include <cstdint> #include <cstdint>
#include <vector> #include <vector>
namespace yaze {
namespace app {
namespace core {
void CopyImageToClipboard(const std::vector<uint8_t> &data); void CopyImageToClipboard(const std::vector<uint8_t> &data);
void GetImageFromClipboard(std::vector<uint8_t> &data, int &width, int &height); void GetImageFromClipboard(std::vector<uint8_t> &data, int &width, int &height);
#endif // YAZE_APP_CORE_PLATFORM_CLIPBOARD_H } // namespace core
} // namespace app
} // namespace yaze
#endif // YAZE_APP_CORE_PLATFORM_CLIPBOARD_H

View File

@@ -6,7 +6,7 @@
#ifdef TARGET_OS_MAC #ifdef TARGET_OS_MAC
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
void CopyImageToClipboard(const std::vector<uint8_t>& pngData) { void yaze::app::core::CopyImageToClipboard(const std::vector<uint8_t>& pngData) {
NSData* data = [NSData dataWithBytes:pngData.data() length:pngData.size()]; NSData* data = [NSData dataWithBytes:pngData.data() length:pngData.size()];
NSImage* image = [[NSImage alloc] initWithData:data]; NSImage* image = [[NSImage alloc] initWithData:data];
@@ -15,7 +15,7 @@ void CopyImageToClipboard(const std::vector<uint8_t>& pngData) {
[pasteboard writeObjects:@[ image ]]; [pasteboard writeObjects:@[ image ]];
} }
void GetImageFromClipboard(std::vector<uint8_t>& pixel_data, int& width, int& height) { void yaze::app::core::GetImageFromClipboard(std::vector<uint8_t>& pixel_data, int& width, int& height) {
NSPasteboard* pasteboard = [NSPasteboard generalPasteboard]; NSPasteboard* pasteboard = [NSPasteboard generalPasteboard];
NSArray* classArray = [NSArray arrayWithObject:[NSImage class]]; NSArray* classArray = [NSArray arrayWithObject:[NSImage class]];
NSDictionary* options = [NSDictionary dictionary]; NSDictionary* options = [NSDictionary dictionary];

View File

@@ -1,6 +1,16 @@
#ifndef YAZE_APP_CORE_PLATFORM_FILE_PATH_H #ifndef YAZE_APP_CORE_PLATFORM_FILE_PATH_H
#define YAZE_APP_CORE_PLATFORM_FILE_PATH_H #define YAZE_APP_CORE_PLATFORM_FILE_PATH_H
#include <string>
namespace yaze {
namespace app {
namespace core {
std::string GetBundleResourcePath(); std::string GetBundleResourcePath();
}
} // namespace app
} // namespace yaze
#endif // YAZE_APP_CORE_PLATFORM_FILE_PATH_H #endif // YAZE_APP_CORE_PLATFORM_FILE_PATH_H

View File

@@ -1,3 +1,5 @@
#include "file_path.h"
#include <iostream> #include <iostream>
#include <string> #include <string>
@@ -6,14 +8,14 @@
#include <TargetConditionals.h> #include <TargetConditionals.h>
#if TARGET_IPHONE_SIMULATOR == 1 || TARGET_OS_IPHONE == 1 #if TARGET_IPHONE_SIMULATOR == 1 || TARGET_OS_IPHONE == 1
std::string GetBundleResourcePath() { std::string yaze::app::core::GetBundleResourcePath() {
NSBundle* bundle = [NSBundle mainBundle]; NSBundle* bundle = [NSBundle mainBundle];
NSString* resourceDirectoryPath = [bundle bundlePath]; NSString* resourceDirectoryPath = [bundle bundlePath];
NSString* path = [resourceDirectoryPath stringByAppendingString:@"/"]; NSString* path = [resourceDirectoryPath stringByAppendingString:@"/"];
return [path UTF8String]; return [path UTF8String];
} }
#elif TARGET_OS_MAC == 1 #elif TARGET_OS_MAC == 1
std::string GetBundleResourcePath() { std::string yaze::app::core::GetBundleResourcePath() {
NSBundle* bundle = [NSBundle mainBundle]; NSBundle* bundle = [NSBundle mainBundle];
NSString* resourceDirectoryPath = [bundle bundlePath]; NSString* resourceDirectoryPath = [bundle bundlePath];
NSString* path = [resourceDirectoryPath stringByAppendingString:@"/"]; NSString* path = [resourceDirectoryPath stringByAppendingString:@"/"];

View File

@@ -130,7 +130,7 @@ void GraphicsEditor::DrawGfxEditToolset() {
if (Button(ICON_MD_CONTENT_COPY)) { if (Button(ICON_MD_CONTENT_COPY)) {
std::vector<uint8_t> png_data = std::vector<uint8_t> png_data =
rom()->gfx_sheets().at(current_sheet_).GetPngData(); rom()->gfx_sheets().at(current_sheet_).GetPngData();
CopyImageToClipboard(png_data); core::CopyImageToClipboard(png_data);
} }
HOVER_HINT("Copy to Clipboard"); HOVER_HINT("Copy to Clipboard");
@@ -138,7 +138,7 @@ void GraphicsEditor::DrawGfxEditToolset() {
if (Button(ICON_MD_CONTENT_PASTE)) { if (Button(ICON_MD_CONTENT_PASTE)) {
std::vector<uint8_t> png_data; std::vector<uint8_t> png_data;
int width, height; int width, height;
GetImageFromClipboard(png_data, width, height); core::GetImageFromClipboard(png_data, width, height);
if (png_data.size() > 0) { if (png_data.size() > 0) {
rom() rom()
->mutable_gfx_sheets() ->mutable_gfx_sheets()

View File

@@ -230,7 +230,7 @@ absl::Status OverworldEditor::DrawToolset() {
std::vector<uint8_t> png_data; std::vector<uint8_t> png_data;
if (gfx::ConvertSurfaceToPNG(maps_bmp_[current_map_].surface(), if (gfx::ConvertSurfaceToPNG(maps_bmp_[current_map_].surface(),
png_data)) { png_data)) {
CopyImageToClipboard(png_data); core::CopyImageToClipboard(png_data);
} else { } else {
status_ = absl::InternalError( status_ = absl::InternalError(
"Failed to convert overworld map surface to PNG"); "Failed to convert overworld map surface to PNG");

View File

@@ -594,7 +594,7 @@ std::string LoadFile(const std::string& filename) {
#ifdef __APPLE__ #ifdef __APPLE__
#if TARGET_OS_IOS == 1 #if TARGET_OS_IOS == 1
const std::string kBundlePath = GetBundleResourcePath(); const std::string kBundlePath = core::GetBundleResourcePath();
std::ifstream file(kBundlePath + filename); std::ifstream file(kBundlePath + filename);
#else #else
std::ifstream file(kPath + filename); std::ifstream file(kPath + filename);