summaryrefslogtreecommitdiff
path: root/scene/gui
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2016-03-04 11:09:45 -0300
committerJuan Linietsky <reduzio@gmail.com>2016-03-04 11:10:48 -0300
commit5a9b18b665b250b54c0d8eb80354dc08e363377c (patch)
treef9680072f12800b2ae85090562fb3d7062ea59b2 /scene/gui
parent3fc80f65cd26122fed771a149c2e583a8139e4ce (diff)
-Work on addon editor plugin (disabled by default)
-New HTTPRequest node, to make HTTP requests simpler.
Diffstat (limited to 'scene/gui')
-rw-r--r--scene/gui/link_button.cpp124
-rw-r--r--scene/gui/link_button.h40
2 files changed, 164 insertions, 0 deletions
diff --git a/scene/gui/link_button.cpp b/scene/gui/link_button.cpp
new file mode 100644
index 0000000000..007d0a709e
--- /dev/null
+++ b/scene/gui/link_button.cpp
@@ -0,0 +1,124 @@
+#include "link_button.h"
+
+
+void LinkButton::set_text(const String& p_text) {
+
+ text=p_text;
+ update();
+ minimum_size_changed();
+}
+
+String LinkButton::get_text() const {
+ return text;
+}
+
+void LinkButton::set_underline_mode(UnderlineMode p_underline_mode) {
+
+ underline_mode=p_underline_mode;
+ update();
+}
+
+LinkButton::UnderlineMode LinkButton::get_underline_mode() const {
+
+ return underline_mode;
+}
+
+
+Size2 LinkButton::get_minimum_size() const {
+
+ return get_font("font")->get_string_size( text );
+}
+
+
+
+void LinkButton::_notification(int p_what) {
+
+ switch( p_what ) {
+
+ case NOTIFICATION_DRAW: {
+
+
+ RID ci = get_canvas_item();
+ Size2 size=get_size();
+ Color color;
+ bool do_underline=false;
+
+ //print_line(get_text()+": "+itos(is_flat())+" hover "+itos(get_draw_mode()));
+
+ switch( get_draw_mode() ) {
+
+ case DRAW_NORMAL: {
+
+ color=get_color("font_color");
+ do_underline=underline_mode==UNDERLINE_MODE_ALWAYS;
+ } break;
+ case DRAW_PRESSED: {
+
+ if (has_color("font_color_pressed"))
+ color=get_color("font_color_pressed");
+ else
+ color=get_color("font_color");
+
+ do_underline=true;
+
+ } break;
+ case DRAW_HOVER: {
+
+ color=get_color("font_color_hover");
+ do_underline=true;
+
+ } break;
+ case DRAW_DISABLED: {
+
+ color=get_color("font_color_disabled");
+ do_underline=underline_mode==UNDERLINE_MODE_ALWAYS;
+
+ } break;
+ }
+
+ if (has_focus()) {
+
+ Ref<StyleBox> style = get_stylebox("focus");
+ style->draw(ci,Rect2(Point2(),size));
+ }
+
+ Ref<Font> font=get_font("font");
+
+ draw_string(font,Vector2(0,font->get_ascent()),text,color);
+
+
+
+ if (do_underline) {
+ int underline_spacing = get_constant("underline_spacing");
+ int width = font->get_string_size(text).width;
+ int y = font->get_ascent()+underline_spacing;
+
+ draw_line(Vector2(0,y),Vector2(width,y),color);
+ }
+
+ } break;
+ }
+}
+
+void LinkButton::_bind_methods() {
+
+ ObjectTypeDB::bind_method(_MD("set_text","text"),&LinkButton::set_text);
+ ObjectTypeDB::bind_method(_MD("get_text"),&LinkButton::get_text);
+
+ ObjectTypeDB::bind_method(_MD("set_underline_mode","underline_mode"),&LinkButton::set_underline_mode);
+ ObjectTypeDB::bind_method(_MD("get_underline_mode"),&LinkButton::get_underline_mode);
+
+
+ BIND_CONSTANT( UNDERLINE_MODE_ALWAYS );
+ BIND_CONSTANT( UNDERLINE_MODE_ON_HOVER );
+
+ ADD_PROPERTYNZ(PropertyInfo(Variant::STRING,"text"), _SCS("set_text"), _SCS("get_text"));
+ ADD_PROPERTYNZ(PropertyInfo(Variant::INT,"underline",PROPERTY_HINT_ENUM,"Always,On Hover"), _SCS("set_underline_mode"), _SCS("get_underline_mode"));
+
+}
+
+LinkButton::LinkButton() {
+ underline_mode=UNDERLINE_MODE_ALWAYS;
+ set_focus_mode(FOCUS_NONE);
+ set_default_cursor_shape(CURSOR_POINTING_HAND);
+}
diff --git a/scene/gui/link_button.h b/scene/gui/link_button.h
new file mode 100644
index 0000000000..d218482337
--- /dev/null
+++ b/scene/gui/link_button.h
@@ -0,0 +1,40 @@
+#ifndef LINKBUTTON_H
+#define LINKBUTTON_H
+
+
+#include "scene/gui/base_button.h"
+#include "scene/resources/bit_mask.h"
+
+class LinkButton : public BaseButton {
+
+ OBJ_TYPE( LinkButton, BaseButton );
+public:
+
+ enum UnderlineMode {
+ UNDERLINE_MODE_ALWAYS,
+ UNDERLINE_MODE_ON_HOVER
+ };
+private:
+ String text;
+ UnderlineMode underline_mode;
+
+protected:
+
+ virtual Size2 get_minimum_size() const;
+ void _notification(int p_what);
+ static void _bind_methods();
+
+public:
+
+ void set_text(const String& p_text);
+ String get_text() const;
+
+ void set_underline_mode(UnderlineMode p_underline_mode);
+ UnderlineMode get_underline_mode() const;
+
+ LinkButton();
+};
+
+VARIANT_ENUM_CAST( LinkButton::UnderlineMode );
+
+#endif // LINKBUTTON_H