2016-06-18 12:46:12 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* link_button.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 12:16:55 +00:00
|
|
|
/* https://godotengine.org */
|
2016-06-18 12:46:12 +00:00
|
|
|
/*************************************************************************/
|
2018-01-01 13:40:08 +00:00
|
|
|
/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
|
2016-06-18 12:46:12 +00: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. */
|
|
|
|
/*************************************************************************/
|
2018-01-04 23:50:27 +00:00
|
|
|
|
2016-03-04 14:09:45 +00:00
|
|
|
#include "link_button.h"
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void LinkButton::set_text(const String &p_text) {
|
2016-03-04 14:09:45 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
text = p_text;
|
2016-03-04 14:09:45 +00:00
|
|
|
update();
|
|
|
|
minimum_size_changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
String LinkButton::get_text() const {
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LinkButton::set_underline_mode(UnderlineMode p_underline_mode) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
underline_mode = p_underline_mode;
|
2016-03-04 14:09:45 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
LinkButton::UnderlineMode LinkButton::get_underline_mode() const {
|
|
|
|
|
|
|
|
return underline_mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
Size2 LinkButton::get_minimum_size() const {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
return get_font("font")->get_string_size(text);
|
2016-03-04 14:09:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void LinkButton::_notification(int p_what) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
switch (p_what) {
|
2016-03-04 14:09:45 +00:00
|
|
|
|
|
|
|
case NOTIFICATION_DRAW: {
|
|
|
|
|
|
|
|
RID ci = get_canvas_item();
|
2017-03-05 15:44:50 +00:00
|
|
|
Size2 size = get_size();
|
2016-03-04 14:09:45 +00:00
|
|
|
Color color;
|
2017-03-05 15:44:50 +00:00
|
|
|
bool do_underline = false;
|
2016-03-04 14:09:45 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
switch (get_draw_mode()) {
|
2016-03-04 14:09:45 +00:00
|
|
|
|
|
|
|
case DRAW_NORMAL: {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
color = get_color("font_color");
|
|
|
|
do_underline = underline_mode == UNDERLINE_MODE_ALWAYS;
|
2016-03-04 14:09:45 +00:00
|
|
|
} break;
|
|
|
|
case DRAW_PRESSED: {
|
|
|
|
|
|
|
|
if (has_color("font_color_pressed"))
|
2017-03-05 15:44:50 +00:00
|
|
|
color = get_color("font_color_pressed");
|
2016-03-04 14:09:45 +00:00
|
|
|
else
|
2017-03-05 15:44:50 +00:00
|
|
|
color = get_color("font_color");
|
2016-03-04 14:09:45 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
do_underline = underline_mode != UNDERLINE_MODE_NEVER;
|
2016-03-04 14:09:45 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case DRAW_HOVER: {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
color = get_color("font_color_hover");
|
|
|
|
do_underline = underline_mode != UNDERLINE_MODE_NEVER;
|
2016-03-04 14:09:45 +00:00
|
|
|
|
|
|
|
} break;
|
Fix warning about functions defined but not used [-Wunused-function]
Fixes the following GCC 5 warnings:
```
core/io/zip_io.h:128:26: warning: 'zlib_filefunc_def zipio_create_io_from_file(FileAccess**)' defined but not used [-Wunused-function]
core/script_debugger_remote.cpp:110:17: warning: 'ObjectID safe_get_instance_id(const Variant&)' defined but not used [-Wunused-function]
drivers/unix/socket_helpers.h:103:12: warning: 'int _socket_create(IP::Type&, int, int)' defined but not used [-Wunused-function]
drivers/unix/socket_helpers.h:45:15: warning: 'size_t _set_sockaddr(sockaddr_storage*, const IP_Address&, int, IP::Type)' defined but not used [-Wunused-function]
drivers/unix/socket_helpers.h:76:15: warning: 'size_t _set_listen_sockaddr(sockaddr_storage*, int, IP::Type, IP_Address)' defined but not used [-Wunused-function]
editor/editor_fonts.cpp:40:24: warning: 'Ref<BitmapFont> make_font(int, int, int, int, const int*, const Ref<Texture>&)' defined but not used [-Wunused-function]
editor/editor_themes.cpp:85:26: warning: 'Ref<StyleBoxFlat> change_border_color(Ref<StyleBoxFlat>, Color)' defined but not used [-Wunused-function]
editor/import/editor_import_collada.cpp:493:13: warning: 'void _generate_normals(const PoolVector<int>&, const PoolVector<Vector3>&, PoolVector<Vector3>&)' defined but not used [-Wunused-function]
editor/import/editor_import_collada.cpp:524:13: warning: 'void _generate_tangents_and_binormals(const PoolVector<int>&, const PoolVector<Vector3>&, const PoolVector<Vector3>&, const PoolVector<Vector3>&, PoolVector<float>&)' defined but not used [-Wunused-function]
editor/pvrtc_compress.cpp:118:13: warning: 'void _compress_etc(Image*)' defined but not used [-Wunused-function]
modules/etc/image_etc.cpp:89:13: warning: 'void _decompress_etc1(Image*)' defined but not used [-Wunused-function]
modules/etc/image_etc.cpp:93:13: warning: 'void _decompress_etc2(Image*)' defined but not used [-Wunused-function]
modules/gdscript/editor/gdscript_highlighter.cpp:46:13: warning: 'bool _is_whitespace(CharType)' defined but not used [-Wunused-function]
scene/2d/cpu_particles_2d.cpp:510:14: warning: 'float rand_from_seed_m1_p1(uint32_t&)' defined but not used [-Wunused-function]
scene/3d/cpu_particles.cpp:474:14: warning: 'float rand_from_seed_m1_p1(uint32_t&)' defined but not used [-Wunused-function]
scene/resources/default_theme/default_theme.cpp:123:20: warning: 'Ref<Shader> make_shader(const char*, const char*, const char*)' defined but not used [-Wunused-function]
scene/resources/default_theme/default_theme.cpp:130:24: warning: 'Ref<BitmapFont> make_font(int, int, int, int, const int*, const Ref<Texture>&)' defined but not used [-Wunused-function]
```
Had to split `core/io/zip_io.h` into header and .cpp file without 'static' keyword.
Not fixed yet (static definition in header used in some files but not all):
```
modules/websocket/lws_helper.h:111:13: warning: 'void _lws_make_protocols(void*, int (*)(lws*, lws_callback_reasons, void*, void*, size_t), PoolVector<String>, _LWSRef**)' defined but not used [-Wunused-function]
```
Also fixed a couple other warnings missed in previous commits.
2018-09-28 19:57:30 +00:00
|
|
|
case DRAW_HOVER_PRESSED: break; // Not used in this class
|
2016-03-04 14:09:45 +00:00
|
|
|
case DRAW_DISABLED: {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
color = get_color("font_color_disabled");
|
|
|
|
do_underline = underline_mode == UNDERLINE_MODE_ALWAYS;
|
2016-03-04 14:09:45 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (has_focus()) {
|
|
|
|
|
|
|
|
Ref<StyleBox> style = get_stylebox("focus");
|
2017-03-05 15:44:50 +00:00
|
|
|
style->draw(ci, Rect2(Point2(), size));
|
2016-03-04 14:09:45 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Ref<Font> font = get_font("font");
|
2016-03-04 14:09:45 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
draw_string(font, Vector2(0, font->get_ascent()), text, color);
|
2016-03-04 14:09:45 +00:00
|
|
|
|
|
|
|
if (do_underline) {
|
|
|
|
int underline_spacing = get_constant("underline_spacing");
|
|
|
|
int width = font->get_string_size(text).width;
|
2017-03-05 15:44:50 +00:00
|
|
|
int y = font->get_ascent() + underline_spacing;
|
2016-03-04 14:09:45 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
draw_line(Vector2(0, y), Vector2(width, y), color);
|
2016-03-04 14:09:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LinkButton::_bind_methods() {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_text", "text"), &LinkButton::set_text);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_text"), &LinkButton::get_text);
|
2016-03-04 14:09:45 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_underline_mode", "underline_mode"), &LinkButton::set_underline_mode);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_underline_mode"), &LinkButton::get_underline_mode);
|
2016-03-04 14:09:45 +00:00
|
|
|
|
2017-08-20 15:45:01 +00:00
|
|
|
BIND_ENUM_CONSTANT(UNDERLINE_MODE_ALWAYS);
|
|
|
|
BIND_ENUM_CONSTANT(UNDERLINE_MODE_ON_HOVER);
|
|
|
|
BIND_ENUM_CONSTANT(UNDERLINE_MODE_NEVER);
|
2016-03-04 14:09:45 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ADD_PROPERTYNZ(PropertyInfo(Variant::STRING, "text"), "set_text", "get_text");
|
|
|
|
ADD_PROPERTYNZ(PropertyInfo(Variant::INT, "underline", PROPERTY_HINT_ENUM, "Always,On Hover,Never"), "set_underline_mode", "get_underline_mode");
|
2016-03-04 14:09:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
LinkButton::LinkButton() {
|
2017-03-05 15:44:50 +00:00
|
|
|
underline_mode = UNDERLINE_MODE_ALWAYS;
|
2016-04-12 16:25:17 +00:00
|
|
|
set_enabled_focus_mode(FOCUS_NONE);
|
2016-03-04 14:09:45 +00:00
|
|
|
set_default_cursor_shape(CURSOR_POINTING_HAND);
|
|
|
|
}
|