| 1 |
#include <stdlib.h> |
| 2 |
|
| 3 |
#include <gmodule.h> |
| 4 |
#include <clutter/clutter.h> |
| 5 |
|
| 6 |
#define FONT "Mono Bold 24px" |
| 7 |
|
| 8 |
static const gchar *runes = |
| 9 |
"ᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ᛫ᚠᛁᚱᚪ᛫ᚷᛖᚻᚹᛦᛚᚳᚢᛗ\n" |
| 10 |
"ᛋᚳᛖᚪᛚ᛫ᚦᛖᚪᚻ᛫ᛗᚪᚾᚾᚪ᛫ᚷᛖᚻᚹᛦᛚᚳ᛫ᛗᛁᚳᛚᚢᚾ᛫ᚻᛦᛏ᛫ᛞᚫᛚᚪᚾ\n" |
| 11 |
"ᚷᛁᚠ᛫ᚻᛖ᛫ᚹᛁᛚᛖ᛫ᚠᚩᚱ᛫ᛞᚱᛁᚻᛏᚾᛖ᛫ᛞᚩᛗᛖᛋ᛫ᚻᛚᛇᛏᚪᚾ᛬\n"; |
| 12 |
|
| 13 |
G_MODULE_EXPORT gint |
| 14 |
test_text_main (gint argc, |
| 15 |
gchar **argv) |
| 16 |
{ |
| 17 |
ClutterActor *stage; |
| 18 |
ClutterActor *text, *text2; |
| 19 |
ClutterColor text_color = { 0x33, 0xff, 0x33, 0xff }; |
| 20 |
ClutterColor cursor_color = { 0xff, 0x33, 0x33, 0xff }; |
| 21 |
ClutterTextBuffer *buffer; |
| 22 |
|
| 23 |
if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS) |
| 24 |
return 1; |
| 25 |
|
| 26 |
stage = clutter_stage_new (); |
| 27 |
clutter_stage_set_title (CLUTTER_STAGE (stage), "Text Editing"); |
| 28 |
clutter_actor_set_background_color (stage, CLUTTER_COLOR_Black); |
| 29 |
g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL); |
| 30 |
|
| 31 |
buffer = clutter_text_buffer_new_with_text ("·", -1); |
| 32 |
|
| 33 |
text = clutter_text_new_with_buffer (buffer); |
| 34 |
clutter_text_set_font_name (CLUTTER_TEXT (text), FONT); |
| 35 |
clutter_text_set_color (CLUTTER_TEXT (text), &text_color); |
| 36 |
|
| 37 |
clutter_container_add (CLUTTER_CONTAINER (stage), text, NULL); |
| 38 |
clutter_actor_set_position (text, 40, 30); |
| 39 |
clutter_actor_set_width (text, 1024); |
| 40 |
clutter_text_set_line_wrap (CLUTTER_TEXT (text), TRUE); |
| 41 |
|
| 42 |
clutter_actor_set_reactive (text, TRUE); |
| 43 |
clutter_stage_set_key_focus (CLUTTER_STAGE (stage), text); |
| 44 |
|
| 45 |
clutter_text_set_editable (CLUTTER_TEXT (text), TRUE); |
| 46 |
clutter_text_set_selectable (CLUTTER_TEXT (text), TRUE); |
| 47 |
clutter_text_set_cursor_color (CLUTTER_TEXT (text), &cursor_color); |
| 48 |
clutter_text_set_selected_text_color (CLUTTER_TEXT (text), CLUTTER_COLOR_Blue); |
| 49 |
|
| 50 |
text2 = clutter_text_new_with_buffer (buffer); |
| 51 |
clutter_text_set_color (CLUTTER_TEXT (text2), &text_color); |
| 52 |
clutter_container_add (CLUTTER_CONTAINER (stage), text2, NULL); |
| 53 |
clutter_actor_set_position (text2, 40, 300); |
| 54 |
clutter_actor_set_width (text2, 1024); |
| 55 |
clutter_text_set_line_wrap (CLUTTER_TEXT (text2), TRUE); |
| 56 |
|
| 57 |
clutter_actor_set_reactive (text2, TRUE); |
| 58 |
clutter_text_set_editable (CLUTTER_TEXT (text2), TRUE); |
| 59 |
clutter_text_set_selectable (CLUTTER_TEXT (text2), TRUE); |
| 60 |
clutter_text_set_cursor_color (CLUTTER_TEXT (text2), &cursor_color); |
| 61 |
clutter_text_set_selected_text_color (CLUTTER_TEXT (text2), CLUTTER_COLOR_Green); |
| 62 |
|
| 63 |
if (argv[1]) |
| 64 |
{ |
| 65 |
GError *error = NULL; |
| 66 |
gchar *utf8; |
| 67 |
|
| 68 |
g_file_get_contents (argv[1], &utf8, NULL, &error); |
| 69 |
if (error) |
| 70 |
{ |
| 71 |
utf8 = g_strconcat ("Unable to open '", argv[1], "':\n", |
| 72 |
error->message, |
| 73 |
NULL); |
| 74 |
g_error_free (error); |
| 75 |
} |
| 76 |
|
| 77 |
clutter_text_set_text (CLUTTER_TEXT (text), utf8); |
| 78 |
} |
| 79 |
else |
| 80 |
clutter_text_set_text (CLUTTER_TEXT (text), runes); |
| 81 |
|
| 82 |
clutter_actor_set_size (stage, 1024, 768); |
| 83 |
clutter_actor_show (stage); |
| 84 |
|
| 85 |
clutter_main (); |
| 86 |
|
| 87 |
return EXIT_SUCCESS; |
| 88 |
} |
| 89 |
|
| 90 |
G_MODULE_EXPORT const char * |
| 91 |
test_text_describe (void) |
| 92 |
{ |
| 93 |
return "Multi-line text editing."; |
| 94 |
} |