mirror of
https://github.com/aseprite/aseprite.git
synced 2025-04-10 21:44:22 +00:00
Add color field to doc::UserData
This commit is contained in:
parent
594892f5ef
commit
addddf78a5
@ -278,8 +278,14 @@ belongs to that cel, etc.
|
||||
|
||||
DWORD Flags
|
||||
1 = Has text
|
||||
2 = Has color
|
||||
+ If flags has bit 1:
|
||||
STRING Text
|
||||
+ If flags has bit 2:
|
||||
BYTE Color Red (0-255)
|
||||
BYTE Color Green (0-255)
|
||||
BYTE Color Blue (0-255)
|
||||
BYTE Color Alpha (0-255)
|
||||
|
||||
|
||||
Notes
|
||||
|
@ -49,6 +49,7 @@
|
||||
#define ASE_PALETTE_FLAG_HAS_NAME 1
|
||||
|
||||
#define ASE_USER_DATA_FLAG_HAS_TEXT 1
|
||||
#define ASE_USER_DATA_FLAG_HAS_COLOR 2
|
||||
|
||||
namespace app {
|
||||
|
||||
@ -1459,17 +1460,41 @@ static void ase_file_write_frame_tags_chunk(FILE* f, ASE_FrameHeader* frame_head
|
||||
static void ase_file_read_user_data_chunk(FILE* f, UserData* userData)
|
||||
{
|
||||
size_t flags = fgetl(f);
|
||||
|
||||
if (flags & ASE_USER_DATA_FLAG_HAS_TEXT) {
|
||||
std::string text = ase_file_read_string(f);
|
||||
userData->setText(text);
|
||||
}
|
||||
|
||||
if (flags & ASE_USER_DATA_FLAG_HAS_COLOR) {
|
||||
int r = fgetc(f);
|
||||
int g = fgetc(f);
|
||||
int b = fgetc(f);
|
||||
int a = fgetc(f);
|
||||
userData->setColor(doc::rgba(r, g, b, a));
|
||||
}
|
||||
}
|
||||
|
||||
static void ase_file_write_user_data_chunk(FILE* f, ASE_FrameHeader* frame_header, const UserData* userData)
|
||||
{
|
||||
ChunkWriter chunk(f, frame_header, ASE_FILE_CHUNK_USER_DATA);
|
||||
fputl(ASE_USER_DATA_FLAG_HAS_TEXT, f);
|
||||
ase_file_write_string(f, userData->text().c_str());
|
||||
|
||||
int flags = 0;
|
||||
if (!userData->text().empty())
|
||||
flags |= ASE_USER_DATA_FLAG_HAS_TEXT;
|
||||
if (doc::rgba_geta(userData->color()))
|
||||
flags |= ASE_USER_DATA_FLAG_HAS_COLOR;
|
||||
fputl(flags, f);
|
||||
|
||||
if (flags & ASE_USER_DATA_FLAG_HAS_TEXT)
|
||||
ase_file_write_string(f, userData->text().c_str());
|
||||
|
||||
if (flags & ASE_USER_DATA_FLAG_HAS_COLOR) {
|
||||
fputc(doc::rgba_getr(userData->color()), f);
|
||||
fputc(doc::rgba_getg(userData->color()), f);
|
||||
fputc(doc::rgba_getb(userData->color()), f);
|
||||
fputc(doc::rgba_geta(userData->color()), f);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace app
|
||||
|
@ -11,6 +11,8 @@
|
||||
|
||||
#include "app/ui/user_data_popup.h"
|
||||
|
||||
#include "app/color_utils.h"
|
||||
#include "app/ui/color_button.h"
|
||||
#include "doc/user_data.h"
|
||||
|
||||
#include "user_data.xml.h"
|
||||
@ -42,12 +44,28 @@ bool show_user_data_popup(const gfx::Rect& bounds,
|
||||
UserDataPopup window;
|
||||
|
||||
window.text()->setText(userData.text());
|
||||
window.pointAt(TOP, bounds);
|
||||
|
||||
doc::color_t color = userData.color();
|
||||
window.color()->setPixelFormat(IMAGE_RGB);
|
||||
window.color()->setColor(
|
||||
app::Color::fromRgb(doc::rgba_getr(color),
|
||||
doc::rgba_getg(color),
|
||||
doc::rgba_getb(color),
|
||||
doc::rgba_geta(color)));
|
||||
|
||||
window.pointAt(TOP, bounds);
|
||||
window.openWindowInForeground();
|
||||
|
||||
if (userData.text() != window.text()->text()) {
|
||||
app::Color appColor = window.color()->getColor();
|
||||
color = doc::rgba(appColor.getRed(),
|
||||
appColor.getGreen(),
|
||||
appColor.getBlue(),
|
||||
appColor.getAlpha());
|
||||
|
||||
if (userData.text() != window.text()->text() ||
|
||||
userData.color() != color) {
|
||||
userData.setText(window.text()->text());
|
||||
userData.setColor(color);
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
|
@ -8,20 +8,31 @@
|
||||
#define DOC_USER_DATA_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "doc/color.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace doc {
|
||||
|
||||
class UserData {
|
||||
public:
|
||||
UserData() : m_color(0) {
|
||||
}
|
||||
|
||||
size_t size() const { return m_text.size(); }
|
||||
bool isEmpty() const { return m_text.empty(); }
|
||||
bool isEmpty() const {
|
||||
return m_text.empty() && !doc::rgba_geta(m_color);
|
||||
}
|
||||
|
||||
const std::string& text() const { return m_text; }
|
||||
color_t color() const { return m_color; }
|
||||
|
||||
void setText(const std::string& text) { m_text = text; }
|
||||
void setColor(color_t color) { m_color = color; }
|
||||
|
||||
bool operator==(const UserData& other) const {
|
||||
return (m_text == other.m_text);
|
||||
return (m_text == other.m_text &&
|
||||
m_color == other.m_color);
|
||||
}
|
||||
|
||||
bool operator!=(const UserData& other) const {
|
||||
@ -30,6 +41,7 @@ namespace doc {
|
||||
|
||||
private:
|
||||
std::string m_text;
|
||||
color_t m_color;
|
||||
};
|
||||
|
||||
} // namespace doc
|
||||
|
@ -24,12 +24,14 @@ using namespace base::serialization::little_endian;
|
||||
void write_user_data(std::ostream& os, const UserData& userData)
|
||||
{
|
||||
write_string(os, userData.text());
|
||||
write32(os, userData.color());
|
||||
}
|
||||
|
||||
UserData read_user_data(std::istream& is)
|
||||
{
|
||||
UserData userData;
|
||||
userData.setText(read_string(is));
|
||||
userData.setColor(read32(is));
|
||||
return userData;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user