mirror of
https://github.com/aseprite/aseprite.git
synced 2025-02-11 09:40:42 +00:00
Copy hex text to native clipboard when copy colors from the palette (fix #4289)
This commit is contained in:
parent
e47448ca24
commit
40863a3a5e
@ -1,5 +1,5 @@
|
|||||||
// Aseprite
|
// Aseprite
|
||||||
// Copyright (C) 2019-2023 Igara Studio S.A.
|
// Copyright (C) 2019-2024 Igara Studio S.A.
|
||||||
// Copyright (C) 2001-2018 David Capello
|
// Copyright (C) 2001-2018 David Capello
|
||||||
//
|
//
|
||||||
// This program is distributed under the terms of
|
// This program is distributed under the terms of
|
||||||
@ -227,7 +227,8 @@ void Clipboard::setData(Image* image,
|
|||||||
else
|
else
|
||||||
m_data->image.reset(image);
|
m_data->image.reset(image);
|
||||||
|
|
||||||
if (set_native_clipboard) {
|
if (set_native_clipboard &&
|
||||||
|
use_native_clipboard()) {
|
||||||
// Copy tilemap to the native clipboard
|
// Copy tilemap to the native clipboard
|
||||||
if (isTilemap) {
|
if (isTilemap) {
|
||||||
ASSERT(tileset);
|
ASSERT(tileset);
|
||||||
@ -242,7 +243,6 @@ void Clipboard::setData(Image* image,
|
|||||||
image->setMaskColor(-1);
|
image->setMaskColor(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (use_native_clipboard())
|
|
||||||
setNativeBitmap(image, mask, palette);
|
setNativeBitmap(image, mask, palette);
|
||||||
|
|
||||||
if (image && !image_source_is_transparent)
|
if (image && !image_source_is_transparent)
|
||||||
@ -456,8 +456,13 @@ void Clipboard::copyPalette(const Palette* palette,
|
|||||||
nullptr,
|
nullptr,
|
||||||
new Palette(*palette),
|
new Palette(*palette),
|
||||||
nullptr,
|
nullptr,
|
||||||
true, // set native clipboard
|
false, // Don't touch the native clipboard now
|
||||||
false);
|
false);
|
||||||
|
|
||||||
|
// Here is where we copy the palette as text (hex format)
|
||||||
|
if (use_native_clipboard())
|
||||||
|
setNativePalette(palette, picks);
|
||||||
|
|
||||||
m_data->picks = picks;
|
m_data->picks = picks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// Aseprite
|
// Aseprite
|
||||||
// Copyright (C) 2019-2023 Igara Studio S.A.
|
// Copyright (C) 2019-2024 Igara Studio S.A.
|
||||||
// Copyright (C) 2001-2018 David Capello
|
// Copyright (C) 2001-2018 David Capello
|
||||||
//
|
//
|
||||||
// This program is distributed under the terms of
|
// This program is distributed under the terms of
|
||||||
@ -114,6 +114,9 @@ namespace app {
|
|||||||
doc::Tileset** tileset);
|
doc::Tileset** tileset);
|
||||||
bool getNativeBitmapSize(gfx::Size* size);
|
bool getNativeBitmapSize(gfx::Size* size);
|
||||||
|
|
||||||
|
bool setNativePalette(const doc::Palette* palette,
|
||||||
|
const doc::PalettePicks& picks);
|
||||||
|
|
||||||
struct Data;
|
struct Data;
|
||||||
std::unique_ptr<Data> m_data;
|
std::unique_ptr<Data> m_data;
|
||||||
};
|
};
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// Aseprite
|
// Aseprite
|
||||||
// Copyright (C) 2020-2022 Igara Studio S.A.
|
// Copyright (C) 2020-2024 Igara Studio S.A.
|
||||||
// Copyright (C) 2016-2018 David Capello
|
// Copyright (C) 2016-2018 David Capello
|
||||||
//
|
//
|
||||||
// This program is distributed under the terms of
|
// This program is distributed under the terms of
|
||||||
@ -15,6 +15,7 @@
|
|||||||
#include "base/serialization.h"
|
#include "base/serialization.h"
|
||||||
#include "clip/clip.h"
|
#include "clip/clip.h"
|
||||||
#include "doc/color_scales.h"
|
#include "doc/color_scales.h"
|
||||||
|
#include "doc/file/hex_file.h"
|
||||||
#include "doc/image.h"
|
#include "doc/image.h"
|
||||||
#include "doc/image_impl.h"
|
#include "doc/image_impl.h"
|
||||||
#include "doc/image_io.h"
|
#include "doc/image_io.h"
|
||||||
@ -27,6 +28,7 @@
|
|||||||
#include "ui/alert.h"
|
#include "ui/alert.h"
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace app {
|
namespace app {
|
||||||
@ -332,4 +334,26 @@ bool Clipboard::getNativeBitmapSize(gfx::Size* size)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Clipboard::setNativePalette(const doc::Palette* palette,
|
||||||
|
const doc::PalettePicks& picks)
|
||||||
|
{
|
||||||
|
clip::lock l(native_window_handle());
|
||||||
|
if (!l.locked())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
l.clear();
|
||||||
|
|
||||||
|
// Save the palette in hex format as text
|
||||||
|
std::stringstream os;
|
||||||
|
doc::file::save_hex_file(
|
||||||
|
palette, &picks,
|
||||||
|
true, // include '#' on each line
|
||||||
|
false, // don't include a EOL char at the end (so we can copy one color without \n chars)
|
||||||
|
os);
|
||||||
|
|
||||||
|
std::string value = os.str();
|
||||||
|
l.set_data(clip::text_format(), value.c_str(), value.size());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace app
|
} // namespace app
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// Aseprite Document Library
|
// Aseprite Document Library
|
||||||
// Copyright (c) 2022 Igara Studio S.A.
|
// Copyright (c) 2022-2024 Igara Studio S.A.
|
||||||
// Copyright (c) 2016-2018 David Capello
|
// Copyright (c) 2016-2018 David Capello
|
||||||
//
|
//
|
||||||
// This file is released under the terms of the MIT license.
|
// This file is released under the terms of the MIT license.
|
||||||
@ -9,10 +9,13 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "doc/file/hex_file.h"
|
||||||
|
|
||||||
#include "base/fstream_path.h"
|
#include "base/fstream_path.h"
|
||||||
#include "base/hex.h"
|
#include "base/hex.h"
|
||||||
#include "base/trim_string.h"
|
#include "base/trim_string.h"
|
||||||
#include "doc/palette.h"
|
#include "doc/palette.h"
|
||||||
|
#include "doc/palette_picks.h"
|
||||||
|
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
@ -71,17 +74,47 @@ std::unique_ptr<Palette> load_hex_file(const char *filename)
|
|||||||
bool save_hex_file(const Palette *pal, const char *filename)
|
bool save_hex_file(const Palette *pal, const char *filename)
|
||||||
{
|
{
|
||||||
std::ofstream f(FSTREAM_PATH(filename));
|
std::ofstream f(FSTREAM_PATH(filename));
|
||||||
if (f.bad()) return false;
|
if (f.bad())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
save_hex_file(pal, nullptr,
|
||||||
|
false, // don't include '#' per line
|
||||||
|
true, // include a EOL char at the end
|
||||||
|
f);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void save_hex_file(const Palette* pal,
|
||||||
|
const PalettePicks* picks,
|
||||||
|
const bool include_hash_char,
|
||||||
|
const bool final_eol,
|
||||||
|
std::ostream& f)
|
||||||
|
{
|
||||||
|
bool first = true;
|
||||||
|
|
||||||
f << std::hex << std::setfill('0');
|
f << std::hex << std::setfill('0');
|
||||||
for (int i=0; i<pal->size(); ++i) {
|
for (int i=0; i<pal->size(); ++i) {
|
||||||
uint32_t col = pal->getEntry(i);
|
if (picks && !(*picks)[i])
|
||||||
f << std::setw(2) << ((int)rgba_getr(col))
|
continue;
|
||||||
<< std::setw(2) << ((int)rgba_getg(col))
|
|
||||||
<< std::setw(2) << ((int)rgba_getb(col)) << "\n";
|
if (!final_eol) {
|
||||||
|
if (first)
|
||||||
|
first = false;
|
||||||
|
else
|
||||||
|
f << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
uint32_t col = pal->getEntry(i);
|
||||||
|
if (include_hash_char)
|
||||||
|
f << '#';
|
||||||
|
f << std::setw(2) << ((int)rgba_getr(col))
|
||||||
|
<< std::setw(2) << ((int)rgba_getg(col))
|
||||||
|
<< std::setw(2) << ((int)rgba_getb(col));
|
||||||
|
|
||||||
|
|
||||||
|
if (final_eol)
|
||||||
|
f << "\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace file
|
} // namespace file
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// Aseprite Document Library
|
// Aseprite Document Library
|
||||||
// Copyright (c) 2022 Igara Studio S.A.
|
// Copyright (c) 2022-2024 Igara Studio S.A.
|
||||||
// Copyright (c) 2016 David Capello
|
// Copyright (c) 2016 David Capello
|
||||||
//
|
//
|
||||||
// This file is released under the terms of the MIT license.
|
// This file is released under the terms of the MIT license.
|
||||||
@ -9,16 +9,23 @@
|
|||||||
#define DOC_FILE_HEX_FILE_H_INCLUDED
|
#define DOC_FILE_HEX_FILE_H_INCLUDED
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <iosfwd>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
namespace doc {
|
namespace doc {
|
||||||
|
|
||||||
class Palette;
|
class Palette;
|
||||||
|
class PalettePicks;
|
||||||
|
|
||||||
namespace file {
|
namespace file {
|
||||||
|
|
||||||
std::unique_ptr<Palette> load_hex_file(const char* filename);
|
std::unique_ptr<Palette> load_hex_file(const char* filename);
|
||||||
bool save_hex_file(const Palette* pal, const char* filename);
|
bool save_hex_file(const Palette* pal, const char* filename);
|
||||||
|
void save_hex_file(const Palette* palette,
|
||||||
|
const PalettePicks* picks,
|
||||||
|
const bool include_hash_char,
|
||||||
|
const bool final_eol,
|
||||||
|
std::ostream& f);
|
||||||
|
|
||||||
} // namespace file
|
} // namespace file
|
||||||
} // namespace doc
|
} // namespace doc
|
||||||
|
Loading…
x
Reference in New Issue
Block a user