button.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  1. /*************************************************************************/
  2. /* button.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "button.h"
  31. #include "core/string/translation.h"
  32. #include "servers/rendering_server.h"
  33. Size2 Button::get_minimum_size() const {
  34. Size2 minsize = text_buf->get_size();
  35. if (clip_text) {
  36. minsize.width = 0;
  37. }
  38. if (!expand_icon) {
  39. Ref<Texture2D> _icon;
  40. if (icon.is_null() && has_theme_icon(SNAME("icon"))) {
  41. _icon = Control::get_theme_icon(SNAME("icon"));
  42. } else {
  43. _icon = icon;
  44. }
  45. if (!_icon.is_null()) {
  46. minsize.height = MAX(minsize.height, _icon->get_height());
  47. if (icon_align != ALIGN_CENTER) {
  48. minsize.width += _icon->get_width();
  49. if (xl_text != "") {
  50. minsize.width += get_theme_constant(SNAME("hseparation"));
  51. }
  52. } else {
  53. minsize.width = MAX(minsize.width, _icon->get_width());
  54. }
  55. }
  56. }
  57. Ref<Font> font = get_theme_font(SNAME("font"));
  58. float font_height = font->get_height(get_theme_font_size(SNAME("font_size")));
  59. minsize.height = MAX(font_height, minsize.height);
  60. return get_theme_stylebox(SNAME("normal"))->get_minimum_size() + minsize;
  61. }
  62. void Button::_set_internal_margin(Side p_side, float p_value) {
  63. _internal_margin[p_side] = p_value;
  64. }
  65. void Button::_notification(int p_what) {
  66. switch (p_what) {
  67. case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: {
  68. update();
  69. } break;
  70. case NOTIFICATION_TRANSLATION_CHANGED: {
  71. xl_text = atr(text);
  72. _shape();
  73. minimum_size_changed();
  74. update();
  75. } break;
  76. case NOTIFICATION_THEME_CHANGED: {
  77. _shape();
  78. minimum_size_changed();
  79. update();
  80. } break;
  81. case NOTIFICATION_DRAW: {
  82. RID ci = get_canvas_item();
  83. Size2 size = get_size();
  84. Color color;
  85. Color color_icon(1, 1, 1, 1);
  86. Ref<StyleBox> style = get_theme_stylebox(SNAME("normal"));
  87. bool rtl = is_layout_rtl();
  88. switch (get_draw_mode()) {
  89. case DRAW_NORMAL: {
  90. if (rtl && has_theme_stylebox(SNAME("normal_mirrored"))) {
  91. style = get_theme_stylebox(SNAME("normal_mirrored"));
  92. } else {
  93. style = get_theme_stylebox(SNAME("normal"));
  94. }
  95. if (!flat) {
  96. style->draw(ci, Rect2(Point2(0, 0), size));
  97. }
  98. // Focus colors only take precedence over normal state.
  99. if (has_focus()) {
  100. color = get_theme_color(SNAME("font_focus_color"));
  101. if (has_theme_color(SNAME("icon_focus_color"))) {
  102. color_icon = get_theme_color(SNAME("icon_focus_color"));
  103. }
  104. } else {
  105. color = get_theme_color(SNAME("font_color"));
  106. if (has_theme_color(SNAME("icon_normal_color"))) {
  107. color_icon = get_theme_color(SNAME("icon_normal_color"));
  108. }
  109. }
  110. } break;
  111. case DRAW_HOVER_PRESSED: {
  112. if (has_theme_stylebox(SNAME("hover_pressed")) && has_theme_stylebox_override("hover_pressed")) {
  113. if (rtl && has_theme_stylebox(SNAME("hover_pressed_mirrored"))) {
  114. style = get_theme_stylebox(SNAME("hover_pressed_mirrored"));
  115. } else {
  116. style = get_theme_stylebox(SNAME("hover_pressed"));
  117. }
  118. if (!flat) {
  119. style->draw(ci, Rect2(Point2(0, 0), size));
  120. }
  121. if (has_theme_color(SNAME("font_hover_pressed_color"))) {
  122. color = get_theme_color(SNAME("font_hover_pressed_color"));
  123. } else {
  124. color = get_theme_color(SNAME("font_color"));
  125. }
  126. if (has_theme_color(SNAME("icon_hover_pressed_color"))) {
  127. color_icon = get_theme_color(SNAME("icon_hover_pressed_color"));
  128. }
  129. break;
  130. }
  131. [[fallthrough]];
  132. }
  133. case DRAW_PRESSED: {
  134. if (rtl && has_theme_stylebox(SNAME("pressed_mirrored"))) {
  135. style = get_theme_stylebox(SNAME("pressed_mirrored"));
  136. } else {
  137. style = get_theme_stylebox(SNAME("pressed"));
  138. }
  139. if (!flat) {
  140. style->draw(ci, Rect2(Point2(0, 0), size));
  141. }
  142. if (has_theme_color(SNAME("font_pressed_color"))) {
  143. color = get_theme_color(SNAME("font_pressed_color"));
  144. } else {
  145. color = get_theme_color(SNAME("font_color"));
  146. }
  147. if (has_theme_color(SNAME("icon_pressed_color"))) {
  148. color_icon = get_theme_color(SNAME("icon_pressed_color"));
  149. }
  150. } break;
  151. case DRAW_HOVER: {
  152. if (rtl && has_theme_stylebox(SNAME("hover_mirrored"))) {
  153. style = get_theme_stylebox(SNAME("hover_mirrored"));
  154. } else {
  155. style = get_theme_stylebox(SNAME("hover"));
  156. }
  157. if (!flat) {
  158. style->draw(ci, Rect2(Point2(0, 0), size));
  159. }
  160. color = get_theme_color(SNAME("font_hover_color"));
  161. if (has_theme_color(SNAME("icon_hover_color"))) {
  162. color_icon = get_theme_color(SNAME("icon_hover_color"));
  163. }
  164. } break;
  165. case DRAW_DISABLED: {
  166. if (rtl && has_theme_stylebox(SNAME("disabled_mirrored"))) {
  167. style = get_theme_stylebox(SNAME("disabled_mirrored"));
  168. } else {
  169. style = get_theme_stylebox(SNAME("disabled"));
  170. }
  171. if (!flat) {
  172. style->draw(ci, Rect2(Point2(0, 0), size));
  173. }
  174. color = get_theme_color(SNAME("font_disabled_color"));
  175. if (has_theme_color(SNAME("icon_disabled_color"))) {
  176. color_icon = get_theme_color(SNAME("icon_disabled_color"));
  177. }
  178. } break;
  179. }
  180. if (has_focus()) {
  181. Ref<StyleBox> style2 = get_theme_stylebox(SNAME("focus"));
  182. style2->draw(ci, Rect2(Point2(), size));
  183. }
  184. Ref<Texture2D> _icon;
  185. if (icon.is_null() && has_theme_icon(SNAME("icon"))) {
  186. _icon = Control::get_theme_icon(SNAME("icon"));
  187. } else {
  188. _icon = icon;
  189. }
  190. Rect2 icon_region = Rect2();
  191. TextAlign icon_align_rtl_checked = icon_align;
  192. TextAlign align_rtl_checked = align;
  193. // Swap icon and text alignment sides if right-to-left layout is set.
  194. if (rtl) {
  195. if (icon_align == ALIGN_RIGHT) {
  196. icon_align_rtl_checked = ALIGN_LEFT;
  197. } else if (icon_align == ALIGN_LEFT) {
  198. icon_align_rtl_checked = ALIGN_RIGHT;
  199. }
  200. if (align == ALIGN_RIGHT) {
  201. align_rtl_checked = ALIGN_LEFT;
  202. } else if (align == ALIGN_LEFT) {
  203. align_rtl_checked = ALIGN_RIGHT;
  204. }
  205. }
  206. if (!_icon.is_null()) {
  207. int valign = size.height - style->get_minimum_size().y;
  208. if (is_disabled()) {
  209. color_icon.a = 0.4;
  210. }
  211. float icon_ofs_region = 0.0;
  212. Point2 style_offset;
  213. Size2 icon_size = _icon->get_size();
  214. if (icon_align_rtl_checked == ALIGN_LEFT) {
  215. style_offset.x = style->get_margin(SIDE_LEFT);
  216. if (_internal_margin[SIDE_LEFT] > 0) {
  217. icon_ofs_region = _internal_margin[SIDE_LEFT] + get_theme_constant(SNAME("hseparation"));
  218. }
  219. } else if (icon_align_rtl_checked == ALIGN_CENTER) {
  220. style_offset.x = 0.0;
  221. } else if (icon_align_rtl_checked == ALIGN_RIGHT) {
  222. style_offset.x = -style->get_margin(SIDE_RIGHT);
  223. if (_internal_margin[SIDE_RIGHT] > 0) {
  224. icon_ofs_region = -_internal_margin[SIDE_RIGHT] - get_theme_constant(SNAME("hseparation"));
  225. }
  226. }
  227. style_offset.y = style->get_margin(SIDE_TOP);
  228. if (expand_icon) {
  229. Size2 _size = get_size() - style->get_offset() * 2;
  230. _size.width -= get_theme_constant(SNAME("hseparation")) + icon_ofs_region;
  231. if (!clip_text && icon_align_rtl_checked != ALIGN_CENTER) {
  232. _size.width -= text_buf->get_size().width;
  233. }
  234. float icon_width = _icon->get_width() * _size.height / _icon->get_height();
  235. float icon_height = _size.height;
  236. if (icon_width > _size.width) {
  237. icon_width = _size.width;
  238. icon_height = _icon->get_height() * icon_width / _icon->get_width();
  239. }
  240. icon_size = Size2(icon_width, icon_height);
  241. }
  242. if (icon_align_rtl_checked == ALIGN_LEFT) {
  243. icon_region = Rect2(style_offset + Point2(icon_ofs_region, Math::floor((valign - icon_size.y) * 0.5)), icon_size);
  244. } else if (icon_align_rtl_checked == ALIGN_CENTER) {
  245. icon_region = Rect2(style_offset + Point2(icon_ofs_region + Math::floor((size.x - icon_size.x) * 0.5), Math::floor((valign - icon_size.y) * 0.5)), icon_size);
  246. } else {
  247. icon_region = Rect2(style_offset + Point2(icon_ofs_region + size.x - icon_size.x, Math::floor((valign - icon_size.y) * 0.5)), icon_size);
  248. }
  249. if (icon_region.size.width > 0) {
  250. draw_texture_rect_region(_icon, icon_region, Rect2(Point2(), _icon->get_size()), color_icon);
  251. }
  252. }
  253. Point2 icon_ofs = !_icon.is_null() ? Point2(icon_region.size.width + get_theme_constant(SNAME("hseparation")), 0) : Point2();
  254. if (align_rtl_checked == ALIGN_CENTER && icon_align_rtl_checked == ALIGN_CENTER) {
  255. icon_ofs.x = 0.0;
  256. }
  257. int text_clip = size.width - style->get_minimum_size().width - icon_ofs.width;
  258. text_buf->set_width(clip_text ? text_clip : -1);
  259. int text_width = clip_text ? MIN(text_clip, text_buf->get_size().x) : text_buf->get_size().x;
  260. if (_internal_margin[SIDE_LEFT] > 0) {
  261. text_clip -= _internal_margin[SIDE_LEFT] + get_theme_constant(SNAME("hseparation"));
  262. }
  263. if (_internal_margin[SIDE_RIGHT] > 0) {
  264. text_clip -= _internal_margin[SIDE_RIGHT] + get_theme_constant(SNAME("hseparation"));
  265. }
  266. Point2 text_ofs = (size - style->get_minimum_size() - icon_ofs - text_buf->get_size() - Point2(_internal_margin[SIDE_RIGHT] - _internal_margin[SIDE_LEFT], 0)) / 2.0;
  267. switch (align_rtl_checked) {
  268. case ALIGN_LEFT: {
  269. if (icon_align_rtl_checked != ALIGN_LEFT) {
  270. icon_ofs.x = 0.0;
  271. }
  272. if (_internal_margin[SIDE_LEFT] > 0) {
  273. text_ofs.x = style->get_margin(SIDE_LEFT) + icon_ofs.x + _internal_margin[SIDE_LEFT] + get_theme_constant(SNAME("hseparation"));
  274. } else {
  275. text_ofs.x = style->get_margin(SIDE_LEFT) + icon_ofs.x;
  276. }
  277. text_ofs.y += style->get_offset().y;
  278. } break;
  279. case ALIGN_CENTER: {
  280. if (text_ofs.x < 0) {
  281. text_ofs.x = 0;
  282. }
  283. if (icon_align_rtl_checked == ALIGN_LEFT) {
  284. text_ofs += icon_ofs;
  285. }
  286. text_ofs += style->get_offset();
  287. } break;
  288. case ALIGN_RIGHT: {
  289. if (_internal_margin[SIDE_RIGHT] > 0) {
  290. text_ofs.x = size.x - style->get_margin(SIDE_RIGHT) - text_width - _internal_margin[SIDE_RIGHT] - get_theme_constant(SNAME("hseparation"));
  291. } else {
  292. text_ofs.x = size.x - style->get_margin(SIDE_RIGHT) - text_width;
  293. }
  294. text_ofs.y += style->get_offset().y;
  295. if (icon_align_rtl_checked == ALIGN_RIGHT) {
  296. text_ofs.x -= icon_ofs.x;
  297. }
  298. } break;
  299. }
  300. Color font_outline_color = get_theme_color(SNAME("font_outline_color"));
  301. int outline_size = get_theme_constant(SNAME("outline_size"));
  302. if (outline_size > 0 && font_outline_color.a > 0) {
  303. text_buf->draw_outline(ci, text_ofs, outline_size, font_outline_color);
  304. }
  305. text_buf->draw(ci, text_ofs, color);
  306. } break;
  307. }
  308. }
  309. void Button::_shape() {
  310. Ref<Font> font = get_theme_font(SNAME("font"));
  311. int font_size = get_theme_font_size(SNAME("font_size"));
  312. text_buf->clear();
  313. if (text_direction == Control::TEXT_DIRECTION_INHERITED) {
  314. text_buf->set_direction(is_layout_rtl() ? TextServer::DIRECTION_RTL : TextServer::DIRECTION_LTR);
  315. } else {
  316. text_buf->set_direction((TextServer::Direction)text_direction);
  317. }
  318. text_buf->add_string(xl_text, font, font_size, opentype_features, (language != "") ? language : TranslationServer::get_singleton()->get_tool_locale());
  319. }
  320. void Button::set_text(const String &p_text) {
  321. if (text != p_text) {
  322. text = p_text;
  323. xl_text = atr(text);
  324. _shape();
  325. update();
  326. minimum_size_changed();
  327. }
  328. }
  329. String Button::get_text() const {
  330. return text;
  331. }
  332. void Button::set_text_direction(Control::TextDirection p_text_direction) {
  333. ERR_FAIL_COND((int)p_text_direction < -1 || (int)p_text_direction > 3);
  334. if (text_direction != p_text_direction) {
  335. text_direction = p_text_direction;
  336. _shape();
  337. update();
  338. }
  339. }
  340. Control::TextDirection Button::get_text_direction() const {
  341. return text_direction;
  342. }
  343. void Button::clear_opentype_features() {
  344. opentype_features.clear();
  345. _shape();
  346. update();
  347. }
  348. void Button::set_opentype_feature(const String &p_name, int p_value) {
  349. int32_t tag = TS->name_to_tag(p_name);
  350. if (!opentype_features.has(tag) || (int)opentype_features[tag] != p_value) {
  351. opentype_features[tag] = p_value;
  352. _shape();
  353. update();
  354. }
  355. }
  356. int Button::get_opentype_feature(const String &p_name) const {
  357. int32_t tag = TS->name_to_tag(p_name);
  358. if (!opentype_features.has(tag)) {
  359. return -1;
  360. }
  361. return opentype_features[tag];
  362. }
  363. void Button::set_language(const String &p_language) {
  364. if (language != p_language) {
  365. language = p_language;
  366. _shape();
  367. update();
  368. }
  369. }
  370. String Button::get_language() const {
  371. return language;
  372. }
  373. void Button::set_icon(const Ref<Texture2D> &p_icon) {
  374. if (icon != p_icon) {
  375. icon = p_icon;
  376. update();
  377. minimum_size_changed();
  378. }
  379. }
  380. Ref<Texture2D> Button::get_icon() const {
  381. return icon;
  382. }
  383. void Button::set_expand_icon(bool p_enabled) {
  384. if (expand_icon != p_enabled) {
  385. expand_icon = p_enabled;
  386. update();
  387. minimum_size_changed();
  388. }
  389. }
  390. bool Button::is_expand_icon() const {
  391. return expand_icon;
  392. }
  393. void Button::set_flat(bool p_enabled) {
  394. if (flat != p_enabled) {
  395. flat = p_enabled;
  396. update();
  397. }
  398. }
  399. bool Button::is_flat() const {
  400. return flat;
  401. }
  402. void Button::set_clip_text(bool p_enabled) {
  403. if (clip_text != p_enabled) {
  404. clip_text = p_enabled;
  405. update();
  406. minimum_size_changed();
  407. }
  408. }
  409. bool Button::get_clip_text() const {
  410. return clip_text;
  411. }
  412. void Button::set_text_align(TextAlign p_align) {
  413. if (align != p_align) {
  414. align = p_align;
  415. update();
  416. }
  417. }
  418. Button::TextAlign Button::get_text_align() const {
  419. return align;
  420. }
  421. void Button::set_icon_align(TextAlign p_align) {
  422. icon_align = p_align;
  423. minimum_size_changed();
  424. update();
  425. }
  426. Button::TextAlign Button::get_icon_align() const {
  427. return icon_align;
  428. }
  429. bool Button::_set(const StringName &p_name, const Variant &p_value) {
  430. String str = p_name;
  431. if (str.begins_with("opentype_features/")) {
  432. String name = str.get_slicec('/', 1);
  433. int32_t tag = TS->name_to_tag(name);
  434. double value = p_value;
  435. if (value == -1) {
  436. if (opentype_features.has(tag)) {
  437. opentype_features.erase(tag);
  438. _shape();
  439. update();
  440. }
  441. } else {
  442. if ((double)opentype_features[tag] != value) {
  443. opentype_features[tag] = value;
  444. _shape();
  445. update();
  446. }
  447. }
  448. notify_property_list_changed();
  449. return true;
  450. }
  451. return false;
  452. }
  453. bool Button::_get(const StringName &p_name, Variant &r_ret) const {
  454. String str = p_name;
  455. if (str.begins_with("opentype_features/")) {
  456. String name = str.get_slicec('/', 1);
  457. int32_t tag = TS->name_to_tag(name);
  458. if (opentype_features.has(tag)) {
  459. r_ret = opentype_features[tag];
  460. return true;
  461. } else {
  462. r_ret = -1;
  463. return true;
  464. }
  465. }
  466. return false;
  467. }
  468. void Button::_get_property_list(List<PropertyInfo> *p_list) const {
  469. for (const Variant *ftr = opentype_features.next(nullptr); ftr != nullptr; ftr = opentype_features.next(ftr)) {
  470. String name = TS->tag_to_name(*ftr);
  471. p_list->push_back(PropertyInfo(Variant::FLOAT, "opentype_features/" + name));
  472. }
  473. p_list->push_back(PropertyInfo(Variant::NIL, "opentype_features/_new", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR));
  474. }
  475. void Button::_bind_methods() {
  476. ClassDB::bind_method(D_METHOD("set_text", "text"), &Button::set_text);
  477. ClassDB::bind_method(D_METHOD("get_text"), &Button::get_text);
  478. ClassDB::bind_method(D_METHOD("set_text_direction", "direction"), &Button::set_text_direction);
  479. ClassDB::bind_method(D_METHOD("get_text_direction"), &Button::get_text_direction);
  480. ClassDB::bind_method(D_METHOD("set_opentype_feature", "tag", "value"), &Button::set_opentype_feature);
  481. ClassDB::bind_method(D_METHOD("get_opentype_feature", "tag"), &Button::get_opentype_feature);
  482. ClassDB::bind_method(D_METHOD("clear_opentype_features"), &Button::clear_opentype_features);
  483. ClassDB::bind_method(D_METHOD("set_language", "language"), &Button::set_language);
  484. ClassDB::bind_method(D_METHOD("get_language"), &Button::get_language);
  485. ClassDB::bind_method(D_METHOD("set_button_icon", "texture"), &Button::set_icon);
  486. ClassDB::bind_method(D_METHOD("get_button_icon"), &Button::get_icon);
  487. ClassDB::bind_method(D_METHOD("set_flat", "enabled"), &Button::set_flat);
  488. ClassDB::bind_method(D_METHOD("is_flat"), &Button::is_flat);
  489. ClassDB::bind_method(D_METHOD("set_clip_text", "enabled"), &Button::set_clip_text);
  490. ClassDB::bind_method(D_METHOD("get_clip_text"), &Button::get_clip_text);
  491. ClassDB::bind_method(D_METHOD("set_text_align", "align"), &Button::set_text_align);
  492. ClassDB::bind_method(D_METHOD("get_text_align"), &Button::get_text_align);
  493. ClassDB::bind_method(D_METHOD("set_icon_align", "icon_align"), &Button::set_icon_align);
  494. ClassDB::bind_method(D_METHOD("get_icon_align"), &Button::get_icon_align);
  495. ClassDB::bind_method(D_METHOD("set_expand_icon", "enabled"), &Button::set_expand_icon);
  496. ClassDB::bind_method(D_METHOD("is_expand_icon"), &Button::is_expand_icon);
  497. BIND_ENUM_CONSTANT(ALIGN_LEFT);
  498. BIND_ENUM_CONSTANT(ALIGN_CENTER);
  499. BIND_ENUM_CONSTANT(ALIGN_RIGHT);
  500. ADD_PROPERTY(PropertyInfo(Variant::STRING, "text", PROPERTY_HINT_MULTILINE_TEXT, "", PROPERTY_USAGE_DEFAULT_INTL), "set_text", "get_text");
  501. ADD_PROPERTY(PropertyInfo(Variant::INT, "text_direction", PROPERTY_HINT_ENUM, "Auto,Left-to-Right,Right-to-Left,Inherited"), "set_text_direction", "get_text_direction");
  502. ADD_PROPERTY(PropertyInfo(Variant::STRING, "language"), "set_language", "get_language");
  503. ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "icon", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_button_icon", "get_button_icon");
  504. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "flat"), "set_flat", "is_flat");
  505. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "clip_text"), "set_clip_text", "get_clip_text");
  506. ADD_PROPERTY(PropertyInfo(Variant::INT, "align", PROPERTY_HINT_ENUM, "Left,Center,Right"), "set_text_align", "get_text_align");
  507. ADD_PROPERTY(PropertyInfo(Variant::INT, "icon_align", PROPERTY_HINT_ENUM, "Left,Center,Right"), "set_icon_align", "get_icon_align");
  508. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "expand_icon"), "set_expand_icon", "is_expand_icon");
  509. }
  510. Button::Button(const String &p_text) {
  511. text_buf.instantiate();
  512. text_buf->set_flags(TextServer::BREAK_MANDATORY);
  513. set_mouse_filter(MOUSE_FILTER_STOP);
  514. set_text(p_text);
  515. }
  516. Button::~Button() {
  517. }