mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-30 15:32:38 +00:00
Show font name and text preview on each FontItem
This commit is contained in:
parent
2a09990b16
commit
ec5a6fc8b3
@ -47,7 +47,8 @@ class FontItem : public ListItem {
|
|||||||
public:
|
public:
|
||||||
FontItem(const std::string& fn)
|
FontItem(const std::string& fn)
|
||||||
: ListItem(base::get_file_title(fn))
|
: ListItem(base::get_file_title(fn))
|
||||||
, m_filename(fn) {
|
, m_filename(fn)
|
||||||
|
, m_loaded(false) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string& filename() const {
|
const std::string& filename() const {
|
||||||
@ -56,11 +57,9 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void onPaint(PaintEvent& ev) override {
|
void onPaint(PaintEvent& ev) override {
|
||||||
if (!m_image) {
|
ListItem::onPaint(ev);
|
||||||
ListItem::onPaint(ev);
|
|
||||||
}
|
if (m_image) {
|
||||||
else {
|
|
||||||
app::skin::SkinTheme* theme = app::skin::SkinTheme::instance();
|
|
||||||
Graphics* g = ev.getGraphics();
|
Graphics* g = ev.getGraphics();
|
||||||
she::Surface* sur = she::instance()->createRgbaSurface(m_image->width(),
|
she::Surface* sur = she::instance()->createRgbaSurface(m_image->width(),
|
||||||
m_image->height());
|
m_image->height());
|
||||||
@ -69,23 +68,19 @@ private:
|
|||||||
m_image.get(), nullptr, sur,
|
m_image.get(), nullptr, sur,
|
||||||
0, 0, 0, 0, m_image->width(), m_image->height());
|
0, 0, 0, 0, m_image->width(), m_image->height());
|
||||||
|
|
||||||
gfx::Color bg;
|
g->drawRgbaSurface(sur, getTextWidth()+4, 0);
|
||||||
if (isSelected())
|
sur->dispose();
|
||||||
bg = theme->colors.listitemSelectedFace();
|
|
||||||
else
|
|
||||||
bg = theme->colors.listitemNormalFace();
|
|
||||||
|
|
||||||
g->fillRect(bg, getClientBounds());
|
|
||||||
g->drawRgbaSurface(sur, 0, 0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void onPreferredSize(PreferredSizeEvent& ev) override {
|
void onPreferredSize(PreferredSizeEvent& ev) override {
|
||||||
if (m_image)
|
ListItem::onPreferredSize(ev);
|
||||||
ev.setPreferredSize(m_image->width(),
|
if (m_image) {
|
||||||
m_image->height());
|
gfx::Size sz = ev.getPreferredSize();
|
||||||
else
|
ev.setPreferredSize(
|
||||||
ListItem::onPreferredSize(ev);
|
sz.w + 4 + m_image->width(),
|
||||||
|
MAX(sz.h, m_image->height()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void onSelect() override {
|
void onSelect() override {
|
||||||
@ -97,10 +92,11 @@ private:
|
|||||||
gfx::Color color = theme->colors.text();
|
gfx::Color color = theme->colors.text();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
m_loaded = true;
|
||||||
m_image.reset(
|
m_image.reset(
|
||||||
render_text(
|
render_text(
|
||||||
m_filename, 16,
|
m_filename, 16,
|
||||||
getText(),
|
"ABCDEabcde", // TODO custom text
|
||||||
doc::rgba(gfx::getr(color),
|
doc::rgba(gfx::getr(color),
|
||||||
gfx::getg(color),
|
gfx::getg(color),
|
||||||
gfx::getb(color),
|
gfx::getb(color),
|
||||||
@ -111,13 +107,14 @@ private:
|
|||||||
listbox->makeChildVisible(this);
|
listbox->makeChildVisible(this);
|
||||||
}
|
}
|
||||||
catch (const std::exception& ex) {
|
catch (const std::exception& ex) {
|
||||||
Console::showException(ex);
|
// Ignore errors
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
base::UniquePtr<doc::Image> m_image;
|
base::UniquePtr<doc::Image> m_image;
|
||||||
std::string m_filename;
|
std::string m_filename;
|
||||||
|
bool m_loaded;
|
||||||
};
|
};
|
||||||
|
|
||||||
FontPopup::FontPopup()
|
FontPopup::FontPopup()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user