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 <vector>
namespace yaze {
namespace app {
namespace core {
void CopyImageToClipboard(const std::vector<uint8_t>& data) {}
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 <vector>
namespace yaze {
namespace app {
namespace core {
void CopyImageToClipboard(const std::vector<uint8_t> &data);
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
#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()];
NSImage* image = [[NSImage alloc] initWithData:data];
@@ -15,7 +15,7 @@ void CopyImageToClipboard(const std::vector<uint8_t>& pngData) {
[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];
NSArray* classArray = [NSArray arrayWithObject:[NSImage class]];
NSDictionary* options = [NSDictionary dictionary];

View File

@@ -1,6 +1,16 @@
#ifndef 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();
}
} // namespace app
} // namespace yaze
#endif // YAZE_APP_CORE_PLATFORM_FILE_PATH_H

View File

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

View File

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

View File

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

View File

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