Add PNG support for clipboard operations
- Implemented conditional compilation for image copy and retrieval functions in clipboard.cc, clipboard.h, and clipboard.mm, enabling PNG support when YAZE_LIB_PNG is defined. - Updated graphics_editor.cc and overworld_editor.cc to handle PNG data copying to the clipboard, including error handling for cases when PNG support is disabled. - Enhanced user feedback by providing alternative actions when PNG export is unavailable, improving overall user experience.
This commit is contained in:
@@ -6,9 +6,11 @@
|
||||
namespace yaze {
|
||||
namespace core {
|
||||
|
||||
#if YAZE_LIB_PNG == 1
|
||||
void CopyImageToClipboard(const std::vector<uint8_t>& data) {}
|
||||
void GetImageFromClipboard(std::vector<uint8_t>& data, int& width,
|
||||
int& height) {}
|
||||
#endif
|
||||
|
||||
} // namespace core
|
||||
} // namespace yaze
|
||||
@@ -7,8 +7,10 @@
|
||||
namespace yaze {
|
||||
namespace core {
|
||||
|
||||
#if YAZE_LIB_PNG == 1
|
||||
void CopyImageToClipboard(const std::vector<uint8_t> &data);
|
||||
void GetImageFromClipboard(std::vector<uint8_t> &data, int &width, int &height);
|
||||
#endif
|
||||
|
||||
} // namespace core
|
||||
} // namespace yaze
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#ifdef TARGET_OS_MAC
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
#if YAZE_LIB_PNG == 1
|
||||
void yaze::core::CopyImageToClipboard(const std::vector<uint8_t>& pngData) {
|
||||
NSData* data = [NSData dataWithBytes:pngData.data() length:pngData.size()];
|
||||
NSImage* image = [[NSImage alloc] initWithData:data];
|
||||
@@ -41,5 +42,6 @@ void yaze::core::GetImageFromClipboard(std::vector<uint8_t>& pixel_data, int& wi
|
||||
CGContextDrawImage(context, CGRectMake(0, 0, width, height), cgImage);
|
||||
CGContextRelease(context);
|
||||
}
|
||||
#endif // YAZE_LIB_PNG
|
||||
|
||||
#endif
|
||||
#endif // TARGET_OS_MAC
|
||||
|
||||
@@ -121,9 +121,14 @@ void GraphicsEditor::DrawGfxEditToolset() {
|
||||
|
||||
TableNextColumn();
|
||||
if (Button(ICON_MD_CONTENT_COPY)) {
|
||||
#if YAZE_LIB_PNG == 1
|
||||
std::vector<uint8_t> png_data =
|
||||
gfx::Arena::Get().gfx_sheets().at(current_sheet_).GetPngData();
|
||||
core::CopyImageToClipboard(png_data);
|
||||
#else
|
||||
// PNG support disabled - show message or alternative action
|
||||
status_ = absl::UnimplementedError("PNG export not available in this build");
|
||||
#endif
|
||||
}
|
||||
HOVER_HINT("Copy to Clipboard");
|
||||
|
||||
|
||||
@@ -142,14 +142,17 @@ void OverworldEditor::Initialize() {
|
||||
});
|
||||
gui::AddTableColumn(toolset_table_, "##CopyMap", [&]() {
|
||||
if (Button(ICON_MD_CONTENT_COPY)) {
|
||||
std::vector<uint8_t> png_data;
|
||||
png_data = maps_bmp_[current_map_].GetPngData();
|
||||
#if YAZE_LIB_PNG == 1
|
||||
std::vector<uint8_t> png_data = maps_bmp_[current_map_].GetPngData();
|
||||
if (png_data.size() > 0) {
|
||||
core::CopyImageToClipboard(png_data);
|
||||
} else {
|
||||
status_ = absl::InternalError(
|
||||
"Failed to convert overworld map surface to PNG");
|
||||
}
|
||||
#else
|
||||
status_ = absl::UnimplementedError("PNG export not available in this build");
|
||||
#endif
|
||||
}
|
||||
HOVER_HINT("Copy Map to Clipboard");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user