2020-09-03 19:22:16 +08:00
|
|
|
/*************************************************************************/
|
|
|
|
/* ot_features_plugin.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/*************************************************************************/
|
2022-01-04 04:27:34 +08:00
|
|
|
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
2020-09-03 19:22:16 +08:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
#include "ot_features_plugin.h"
|
|
|
|
|
2022-04-19 18:27:18 +08:00
|
|
|
#include "scene/3d/label_3d.h"
|
2022-04-25 18:14:30 +08:00
|
|
|
#include "scene/resources/primitive_meshes.h"
|
2022-04-19 18:27:18 +08:00
|
|
|
|
2020-09-03 19:22:16 +08:00
|
|
|
void OpenTypeFeaturesEditor::_value_changed(double val) {
|
|
|
|
if (setting) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
emit_changed(get_edited_property(), spin->get_value());
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenTypeFeaturesEditor::update_property() {
|
|
|
|
double val = get_edited_object()->get(get_edited_property());
|
|
|
|
setting = true;
|
|
|
|
spin->set_value(val);
|
|
|
|
setting = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenTypeFeaturesEditor::_notification(int p_what) {
|
2022-02-16 10:44:22 +08:00
|
|
|
switch (p_what) {
|
|
|
|
case NOTIFICATION_ENTER_TREE:
|
|
|
|
case NOTIFICATION_THEME_CHANGED: {
|
|
|
|
Color base = get_theme_color(SNAME("accent_color"), SNAME("Editor"));
|
|
|
|
|
|
|
|
button->set_icon(get_theme_icon(SNAME("Remove"), SNAME("EditorIcons")));
|
|
|
|
button->set_size(get_theme_icon(SNAME("Remove"), SNAME("EditorIcons"))->get_size());
|
2022-03-04 08:19:00 +08:00
|
|
|
spin->add_theme_color_override("label_color", base);
|
2022-02-16 10:44:22 +08:00
|
|
|
} break;
|
2020-09-03 19:22:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenTypeFeaturesEditor::_remove_feature() {
|
|
|
|
get_edited_object()->set(get_edited_property(), -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenTypeFeaturesEditor::_bind_methods() {
|
|
|
|
}
|
|
|
|
|
|
|
|
OpenTypeFeaturesEditor::OpenTypeFeaturesEditor() {
|
|
|
|
HBoxContainer *bc = memnew(HBoxContainer);
|
|
|
|
add_child(bc);
|
|
|
|
|
|
|
|
spin = memnew(EditorSpinSlider);
|
|
|
|
spin->set_flat(true);
|
|
|
|
bc->add_child(spin);
|
|
|
|
add_focusable(spin);
|
|
|
|
spin->connect("value_changed", callable_mp(this, &OpenTypeFeaturesEditor::_value_changed));
|
|
|
|
spin->set_h_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
|
|
|
|
spin->set_min(0);
|
|
|
|
spin->set_max(65536);
|
|
|
|
spin->set_step(1);
|
|
|
|
spin->set_hide_slider(false);
|
|
|
|
spin->set_allow_greater(false);
|
|
|
|
spin->set_allow_lesser(false);
|
|
|
|
|
|
|
|
button = memnew(Button);
|
|
|
|
button->set_tooltip(RTR("Remove feature"));
|
|
|
|
button->set_flat(true);
|
|
|
|
bc->add_child(button);
|
|
|
|
|
|
|
|
button->connect("pressed", callable_mp(this, &OpenTypeFeaturesEditor::_remove_feature));
|
|
|
|
|
|
|
|
setting = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
void OpenTypeFeaturesAdd::_add_feature(int p_option) {
|
2022-03-25 04:22:53 +08:00
|
|
|
edited_object->set("opentype_features/" + TS->tag_to_name(p_option), 1);
|
2020-09-03 19:22:16 +08:00
|
|
|
}
|
|
|
|
|
2022-03-25 04:22:53 +08:00
|
|
|
void OpenTypeFeaturesAdd::_features_menu() {
|
|
|
|
Size2 size = get_size();
|
|
|
|
menu->set_position(get_screen_position() + Size2(0, size.height * get_global_transform().get_scale().y));
|
|
|
|
menu->reset_size();
|
|
|
|
menu->popup();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenTypeFeaturesAdd::setup(Object *p_object) {
|
|
|
|
edited_object = p_object;
|
|
|
|
|
2020-09-03 19:22:16 +08:00
|
|
|
menu->clear();
|
|
|
|
menu_ss->clear();
|
|
|
|
menu_cv->clear();
|
|
|
|
menu_cu->clear();
|
|
|
|
bool have_ss = false;
|
|
|
|
bool have_cv = false;
|
|
|
|
bool have_cu = false;
|
2022-04-19 18:27:18 +08:00
|
|
|
|
|
|
|
Ref<Font> font;
|
|
|
|
|
|
|
|
Control *ctrl = Object::cast_to<Control>(edited_object);
|
|
|
|
if (ctrl != nullptr) {
|
|
|
|
font = ctrl->get_theme_font(SNAME("font"));
|
2022-04-25 18:14:30 +08:00
|
|
|
}
|
|
|
|
Label3D *l3d = Object::cast_to<Label3D>(edited_object);
|
|
|
|
if (l3d != nullptr) {
|
|
|
|
font = l3d->_get_font_or_default();
|
|
|
|
}
|
|
|
|
TextMesh *tm = Object::cast_to<TextMesh>(edited_object);
|
|
|
|
if (tm != nullptr) {
|
|
|
|
font = tm->_get_font_or_default();
|
2022-04-19 18:27:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (font.is_null()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Dictionary features = font->get_feature_list();
|
|
|
|
|
2020-09-03 19:22:16 +08:00
|
|
|
for (const Variant *ftr = features.next(nullptr); ftr != nullptr; ftr = features.next(ftr)) {
|
|
|
|
String ftr_name = TS->tag_to_name(*ftr);
|
|
|
|
if (ftr_name.begins_with("stylistic_set_")) {
|
|
|
|
menu_ss->add_item(ftr_name.capitalize(), (int32_t)*ftr);
|
|
|
|
have_ss = true;
|
|
|
|
} else if (ftr_name.begins_with("character_variant_")) {
|
|
|
|
menu_cv->add_item(ftr_name.capitalize(), (int32_t)*ftr);
|
|
|
|
have_cv = true;
|
|
|
|
} else if (ftr_name.begins_with("custom_")) {
|
|
|
|
menu_cu->add_item(ftr_name.replace("custom_", ""), (int32_t)*ftr);
|
|
|
|
have_cu = true;
|
|
|
|
} else {
|
|
|
|
menu->add_item(ftr_name.capitalize(), (int32_t)*ftr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (have_ss) {
|
|
|
|
menu->add_submenu_item(RTR("Stylistic Sets"), "SSMenu");
|
|
|
|
}
|
|
|
|
if (have_cv) {
|
|
|
|
menu->add_submenu_item(RTR("Character Variants"), "CVMenu");
|
|
|
|
}
|
|
|
|
if (have_cu) {
|
|
|
|
menu->add_submenu_item(RTR("Custom"), "CUMenu");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenTypeFeaturesAdd::_notification(int p_what) {
|
2022-02-16 10:44:22 +08:00
|
|
|
switch (p_what) {
|
|
|
|
case NOTIFICATION_ENTER_TREE: {
|
2022-04-12 18:13:14 +08:00
|
|
|
connect("pressed", callable_mp(this, &OpenTypeFeaturesAdd::_features_menu));
|
|
|
|
[[fallthrough]];
|
|
|
|
}
|
|
|
|
case NOTIFICATION_THEME_CHANGED: {
|
2022-03-25 04:22:53 +08:00
|
|
|
set_icon(get_theme_icon(SNAME("Add"), SNAME("EditorIcons")));
|
2022-02-16 10:44:22 +08:00
|
|
|
} break;
|
2020-09-03 19:22:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenTypeFeaturesAdd::_bind_methods() {
|
|
|
|
}
|
|
|
|
|
|
|
|
OpenTypeFeaturesAdd::OpenTypeFeaturesAdd() {
|
2022-03-25 04:22:53 +08:00
|
|
|
set_text(TTR("Add Feature..."));
|
|
|
|
|
2020-09-03 19:22:16 +08:00
|
|
|
menu = memnew(PopupMenu);
|
|
|
|
add_child(menu);
|
|
|
|
|
|
|
|
menu_cv = memnew(PopupMenu);
|
|
|
|
menu_cv->set_name("CVMenu");
|
|
|
|
menu->add_child(menu_cv);
|
|
|
|
|
|
|
|
menu_ss = memnew(PopupMenu);
|
|
|
|
menu_ss->set_name("SSMenu");
|
|
|
|
menu->add_child(menu_ss);
|
|
|
|
|
|
|
|
menu_cu = memnew(PopupMenu);
|
|
|
|
menu_cu->set_name("CUMenu");
|
|
|
|
menu->add_child(menu_cu);
|
|
|
|
|
|
|
|
menu->connect("id_pressed", callable_mp(this, &OpenTypeFeaturesAdd::_add_feature));
|
|
|
|
menu_cv->connect("id_pressed", callable_mp(this, &OpenTypeFeaturesAdd::_add_feature));
|
|
|
|
menu_ss->connect("id_pressed", callable_mp(this, &OpenTypeFeaturesAdd::_add_feature));
|
|
|
|
menu_cu->connect("id_pressed", callable_mp(this, &OpenTypeFeaturesAdd::_add_feature));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
bool EditorInspectorPluginOpenTypeFeatures::can_handle(Object *p_object) {
|
2022-04-25 18:14:30 +08:00
|
|
|
return (Object::cast_to<Control>(p_object) != nullptr) || (Object::cast_to<Label3D>(p_object) != nullptr) || (Object::cast_to<TextMesh>(p_object) != nullptr);
|
2020-09-03 19:22:16 +08:00
|
|
|
}
|
|
|
|
|
2021-07-01 09:24:34 +08:00
|
|
|
bool EditorInspectorPluginOpenTypeFeatures::parse_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const uint32_t p_usage, const bool p_wide) {
|
2020-09-03 19:22:16 +08:00
|
|
|
if (p_path == "opentype_features/_new") {
|
|
|
|
OpenTypeFeaturesAdd *editor = memnew(OpenTypeFeaturesAdd);
|
2022-03-25 04:22:53 +08:00
|
|
|
editor->setup(p_object);
|
|
|
|
add_custom_control(editor);
|
2020-09-03 19:22:16 +08:00
|
|
|
return true;
|
|
|
|
} else if (p_path.begins_with("opentype_features")) {
|
|
|
|
OpenTypeFeaturesEditor *editor = memnew(OpenTypeFeaturesEditor);
|
|
|
|
add_property_editor(p_path, editor);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
|
2022-01-27 17:36:51 +08:00
|
|
|
OpenTypeFeaturesEditorPlugin::OpenTypeFeaturesEditorPlugin() {
|
2020-09-03 19:22:16 +08:00
|
|
|
Ref<EditorInspectorPluginOpenTypeFeatures> ftr_plugin;
|
2021-06-18 06:03:09 +08:00
|
|
|
ftr_plugin.instantiate();
|
2020-09-03 19:22:16 +08:00
|
|
|
EditorInspector::add_inspector_plugin(ftr_plugin);
|
|
|
|
}
|