Add mnemonics attribute for font and styles to enable/disable accelerators underlining

This commit is contained in:
Martín Capello 2022-12-02 15:13:45 -03:00 committed by David Capello
parent 195a8d0e92
commit dded1f6eae
6 changed files with 32 additions and 6 deletions

View File

@ -6,7 +6,7 @@
</authors> </authors>
<fonts> <fonts>
<font id="default" font="Aseprite" /> <font id="default" font="Aseprite" />
<font id="mini" font="Aseprite Mini" /> <font id="mini" font="Aseprite Mini" mnemonics="off" />
</fonts> </fonts>
<dimensions> <dimensions>
<dim id="scrollbar_size" value="12" /> <dim id="scrollbar_size" value="12" />

View File

@ -409,8 +409,11 @@ void SkinTheme::loadXml(BackwardCompatibility* backward)
if (sizeStr) if (sizeStr)
size = std::strtol(sizeStr, nullptr, 10); size = std::strtol(sizeStr, nullptr, 10);
const char* mnemonicsStr = xmlFont->Attribute("mnemonics");
bool mnemonics = mnemonicsStr ? (std::string(mnemonicsStr) != "off") : true;
os::FontRef font = fontData->getFont(size); os::FontRef font = fontData->getFont(size);
m_themeFonts[idStr] = font; m_themeFonts[idStr] = ThemeFont(font, mnemonics);
if (id == "default") if (id == "default")
m_defaultFont = font; m_defaultFont = font;
@ -624,8 +627,16 @@ void SkinTheme::loadXml(BackwardCompatibility* backward)
{ {
const char* fontId = xmlStyle->Attribute("font"); const char* fontId = xmlStyle->Attribute("font");
if (fontId) { if (fontId) {
os::FontRef font = m_themeFonts[fontId]; auto themeFont = m_themeFonts[fontId];
style->setFont(font); style->setFont(themeFont.font());
style->setMnemonics(themeFont.mnemonics());
}
// Override mnemonics value if it is defined for this style.
const char* mnemonicsStr = xmlStyle->Attribute("mnemonics");
if (mnemonicsStr) {
bool mnemonics = mnemonicsStr ? (std::string(mnemonicsStr) != "off") : true;
style->setMnemonics(mnemonics);
} }
} }

View File

@ -34,6 +34,17 @@ namespace app {
class FontData; class FontData;
class ThemeFont {
public:
ThemeFont() {}
ThemeFont(os::FontRef font, bool mnemonics) : m_font(font), m_mnemonics(mnemonics) {}
os::FontRef font() { return m_font; }
bool mnemonics() { return m_mnemonics; }
private:
os::FontRef m_font;
bool m_mnemonics;
};
// This is the GUI theme used by Aseprite (which use images from // This is the GUI theme used by Aseprite (which use images from
// data/skins directory). // data/skins directory).
class SkinTheme : public ui::Theme class SkinTheme : public ui::Theme
@ -161,7 +172,7 @@ namespace app {
std::array<ui::Cursor*, ui::kCursorTypes> m_standardCursors; std::array<ui::Cursor*, ui::kCursorTypes> m_standardCursors;
std::map<std::string, ui::Style*> m_styles; std::map<std::string, ui::Style*> m_styles;
std::map<std::string, FontData*> m_fonts; std::map<std::string, FontData*> m_fonts;
std::map<std::string, os::FontRef> m_themeFonts; std::map<std::string, ThemeFont> m_themeFonts;
os::FontRef m_defaultFont; os::FontRef m_defaultFont;
os::FontRef m_miniFont; os::FontRef m_miniFont;
int m_preferredScreenScaling; int m_preferredScreenScaling;

View File

@ -27,6 +27,7 @@ Style::Style(const Style* base)
, m_border(base ? base->border(): Style::UndefinedBorder()) , m_border(base ? base->border(): Style::UndefinedBorder())
, m_padding(base ? base->padding(): Style::UndefinedBorder()) , m_padding(base ? base->padding(): Style::UndefinedBorder())
, m_font(nullptr) , m_font(nullptr)
, m_mnemonics(base ? base->mnemonics() : true)
{ {
if (base) if (base)
m_layers = base->layers(); m_layers = base->layers();

View File

@ -105,6 +105,7 @@ namespace ui {
const gfx::Border& border() const { return m_border; } const gfx::Border& border() const { return m_border; }
const gfx::Border& padding() const { return m_padding; } const gfx::Border& padding() const { return m_padding; }
os::Font* font() const { return m_font.get(); } os::Font* font() const { return m_font.get(); }
const bool mnemonics() const { return m_mnemonics; }
const Layers& layers() const { return m_layers; } const Layers& layers() const { return m_layers; }
Layers& layers() { return m_layers; } Layers& layers() { return m_layers; }
@ -113,6 +114,7 @@ namespace ui {
void setBorder(const gfx::Border& value) { m_border = value; } void setBorder(const gfx::Border& value) { m_border = value; }
void setPadding(const gfx::Border& value) { m_padding = value; } void setPadding(const gfx::Border& value) { m_padding = value; }
void setFont(const os::FontRef& font); void setFont(const os::FontRef& font);
void setMnemonics(const bool enabled) { m_mnemonics = enabled; }
void addLayer(const Layer& layer); void addLayer(const Layer& layer);
private: private:
@ -123,6 +125,7 @@ namespace ui {
gfx::Border m_border; gfx::Border m_border;
gfx::Border m_padding; gfx::Border m_padding;
os::FontRef m_font; os::FontRef m_font;
bool m_mnemonics;
}; };
} // namespace ui } // namespace ui

View File

@ -464,7 +464,7 @@ void Theme::paintLayer(Graphics* g,
g->drawUIText(text, g->drawUIText(text,
layer.color(), layer.color(),
bgColor, bgColor,
pt, mnemonic); pt, style->mnemonics() ? mnemonic : 0);
} }
if (style->font()) if (style->font())