add shortcuts, node text font attributes

This commit is contained in:
2019-12-02 17:10:08 +01:00
parent baec98835a
commit aac280f48a
8 changed files with 80 additions and 18 deletions

View File

@@ -4,12 +4,12 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>
<layout id="item">
<border color="1 0 0 1" dir="row">
<border dir="row" pad="5">
<node grow="1">
<text id="descr" font-size="30">New File</text>
<text id="descr" size="20">New File</text>
</node>
<node width="100">
<text id="shortcut" font-size="30">Ctrl + N</text>
<node width="200" margin="0 5 0 0">
<text id="shortcut" size="20" weight="black">Ctrl + N</text>
</node>
</border>
</layout>

View File

@@ -226,6 +226,9 @@
<icon icon="resultset_next" width="20"/>
</button-custom>
</border>
<button-custom id="shortcuts" height="40" align="center" color=".2" pad="0 0 0 10" dir="row">
<text id="menu-label" text="Shortcuts" margin="0 0 0 5"/>
</button-custom>
<button-custom id="clear-grids" height="40" align="center" color=".2" pad="0 0 0 10" dir="row">
<icon icon="bin" width="20"/>
<text text="Clear Guides" margin="0 0 0 5"/>
@@ -234,10 +237,6 @@
<icon icon="arrow_rotate_clockwise" width="20"/>
<text id="menu-label" text="Reset Camera" margin="0 0 0 5"/>
</button-custom>
<button-custom id="shortcuts" height="40" align="center" color=".2" pad="0 0 0 10" dir="row">
<icon icon="arrow_rotate_clockwise" width="20"/>
<text id="menu-label" text="Shortcuts" margin="0 0 0 5"/>
</button-custom>
<button-custom os="ios" id="sonarpen" height="40" align="center" color=".2" pad="0 0 0 10" dir="row">
<icon icon="pencil" width="20"/>
<text id="menu-label" text="Start SonarPen" margin="0 0 0 5"/>

View File

@@ -862,15 +862,17 @@ void App::dialog_whatsnew(bool force_show)
});
whatsnew->add_button("Reload", 120, [this, whatsnew](Node*) {
whatsnew->reload();
});
});
whatsnew->add_button("Read Later", 120, [this, whatsnew](Node*) {
Settings::unset("whatsnew-id");
Settings::save();
whatsnew->destroy();
});
});
whatsnew->add_button("Close", 100, [this, whatsnew](Node*) {
Settings::set<Serializer::Integer>("whatsnew-id", whatsnew->m_page_id);
Settings::save();
whatsnew->destroy();
});
});
if (force_show)
layout[main_id]->add_child(whatsnew);
}

View File

@@ -1,3 +1,5 @@
#define CASE(K,V) case K: return V;
#if __APPLE__
enum {
kVK_ANSI_A = 0x00,
kVK_ANSI_S = 0x01,
@@ -119,10 +121,8 @@ enum {
kKey convert_key(int key)
{
#define CASE(K,V) case K: return V;
switch(key)
{
#ifdef __APPLE__
CASE(kVK_ANSI_A, kKey::KeyA);
CASE(kVK_ANSI_S, kKey::KeyS);
CASE(kVK_ANSI_D, kKey::KeyD);
@@ -235,7 +235,20 @@ kKey convert_key(int key)
CASE(kVK_RightArrow, kKey::Unknown);
CASE(kVK_DownArrow, kKey::Unknown);
CASE(kVK_UpArrow, kKey::Unknown);
#elif defined(_WIN32)
default:
return kKey::Unknown;
}
}
#elif __WIN__
kKey convert_key(int key)
{
static auto KL = GetKeyboardLayout(0);
if (key == (VkKeyScanA('[') & 0xFF))
return kKey::KeyBracketLeft;
if (key == (VkKeyScanA(']') & 0xFF))
return kKey::KeyBracketRight;
switch(key)
{
CASE(VK_LBUTTON, kKey::Unknown);
CASE(VK_RBUTTON, kKey::Unknown);
CASE(VK_CANCEL, kKey::Unknown);
@@ -432,7 +445,15 @@ kKey convert_key(int key)
CASE(VK_NONAME, kKey::Unknown);
CASE(VK_PA1, kKey::Unknown);
CASE(VK_OEM_CLEAR, kKey::Unknown);
#elif defined(__ANDROID__)
default:
return kKey::Unknown;
}
}
#elif __ANDROID__
kKey convert_key(int key)
{
switch (key)
{
CASE(AKEYCODE_UNKNOWN, kKey::Unknown);
CASE(AKEYCODE_SOFT_LEFT, kKey::Unknown);
CASE(AKEYCODE_SOFT_RIGHT, kKey::Unknown);
@@ -656,7 +677,15 @@ kKey convert_key(int key)
CASE(AKEYCODE_BRIGHTNESS_DOWN, kKey::Unknown);
CASE(AKEYCODE_BRIGHTNESS_UP, kKey::Unknown);
CASE(AKEYCODE_MEDIA_AUDIO_TRACK, kKey::Unknown);
default:
return kKey::Unknown;
}
}
#elif __WEB__
kKey convert_key(int key)
{
switch (key)
{
CASE(GLFW_KEY_UNKNOWN, kKey::Unknown);
CASE(GLFW_KEY_SPACE, kKey::KeySpacebar);
CASE(GLFW_KEY_APOSTROPHE, kKey::Unknown);
@@ -778,8 +807,18 @@ kKey convert_key(int key)
CASE(GLFW_KEY_RIGHT_ALT, kKey::Unknown);
CASE(GLFW_KEY_RIGHT_SUPER, kKey::Unknown);
CASE(GLFW_KEY_MENU, kKey::Unknown);
#endif
default:
default:
return kKey::Unknown;
}
}
//#elif __XXX__
//kKey convert_key(int key)
//{
// switch (key)
// {
// default:
// return kKey::Unknown;
// }
//}
#endif
#undef CASE

View File

@@ -22,7 +22,12 @@ void NodeShortcuts::init_controls()
m_btn_close->on_click = [this](Node*) {
destroy();
};
add_shortcut("New File", "Ctrl+N");
add_shortcut("Quick switch to Erase", "Hold E");
add_shortcut("Brush Size Keyboard", "[ and ]");
add_shortcut("Brush Size", "Alt + Right Mouse Button");
add_shortcut("Color picker", "Alt + Left Mouse Button");
add_shortcut("Zoom", "Ctrl + Right Mouse Button");
//add_shortcut("", "");
}
void NodeShortcuts::add_shortcut(const std::string& descr, const std::string& shortcut) noexcept
@@ -30,6 +35,7 @@ void NodeShortcuts::add_shortcut(const std::string& descr, const std::string& sh
auto item = m_content->add_child<NodeShortcutsItem>();
item->set_descr(descr);
item->set_shortcut(shortcut);
item->m_color = glm::vec4(glm::vec3(m_content->get_child_index(item) % 2 == 0 ? .1f : .0f), 1);
}
//////////////////////////////////////////////////////////////////////////

View File

@@ -60,6 +60,7 @@ void NodeText::set_font_size(int size)
void NodeText::parse_attributes(kAttribute ka, const tinyxml2::XMLAttribute* attr)
{
Node::parse_attributes(ka, attr);
std::string id = attr->Name();
switch (ka)
{
case kAttribute::Multiline:
@@ -106,6 +107,12 @@ void NodeText::parse_attributes(kAttribute ka, const tinyxml2::XMLAttribute* att
default:
break;
}
if (id == "size")
m_font_size = attr->IntValue();
else if (id == "weight")
m_font_weight = attr->Value();
else if (id == "italic")
m_font_italic = attr->BoolValue();
}
void NodeText::set_text(const std::string& s)

View File

@@ -456,6 +456,11 @@ public:
{
return has(key) ? std::dynamic_pointer_cast<T>(props.at(key)) : nullptr;
}
void unset(const std::string& key)
{
if (has(key))
props.erase(key);
}
template<typename T> std::shared_ptr<T> set(const std::string& key, const T value)
{
if (auto ptr = get<T>(key))

View File

@@ -17,6 +17,10 @@ public:
{
I.Descriptor::set(key, value);
}
static void unset(const std::string& key)
{
I.Descriptor::unset(key);
}
template <typename T>
static std::shared_ptr<T> get(const std::string& key)
{