summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2013-12-13 16:41:11 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2013-12-13 16:41:39 +0900
commit9af1bc3d05f40a6471d6df5235f26ee205f1204c (patch)
tree7a98bff78bbeb8397f07b8a96ebe336436f78d9b
parent25f543de6e6d71b43a242870ff644c0de829e51b (diff)
Add load, save, flip buttons and fix text position
-rw-r--r--main.c120
1 files changed, 97 insertions, 23 deletions
diff --git a/main.c b/main.c
index 3c30dfa..345c138 100644
--- a/main.c
+++ b/main.c
@@ -14,6 +14,7 @@
14#define PANE_H_LEFT 80 14#define PANE_H_LEFT 80
15 15
16const char *AUTOSAVE_CONFIG = "/tmp/text_styles.cfg"; 16const char *AUTOSAVE_CONFIG = "/tmp/text_styles.cfg";
17const char *home = NULL;
17 18
18#ifndef _ 19#ifndef _
19#define _(a) a 20#define _(a) a
@@ -26,7 +27,7 @@ const char *AUTOSAVE_CONFIG = "/tmp/text_styles.cfg";
26#endif 27#endif
27 28
28 29
29#define IMAGE_COUNT 2 30#define IMAGE_COUNT 3
30 31
31Eo *styleentry = NULL; 32Eo *styleentry = NULL;
32Eo *textview = NULL; 33Eo *textview = NULL;
@@ -118,7 +119,7 @@ _duplicate_br_newline(const char *str)
118} 119}
119 120
120static void 121static void
121_config_reload(void) 122_config_reload(const char *path)
122{ 123{
123 Eet_File *ef; 124 Eet_File *ef;
124 Eina_Bool b = EINA_TRUE; 125 Eina_Bool b = EINA_TRUE;
@@ -126,7 +127,7 @@ _config_reload(void)
126 int size = 0; 127 int size = 0;
127 char *utf8; 128 char *utf8;
128 129
129 ef = eet_open(AUTOSAVE_CONFIG, EET_FILE_MODE_READ); 130 ef = eet_open(path, EET_FILE_MODE_READ);
130 if (!ef) return; 131 if (!ef) return;
131 132
132 // Images 133 // Images
@@ -189,14 +190,14 @@ _config_reload(void)
189} 190}
190 191
191static Eina_Bool 192static Eina_Bool
192_config_save(void) 193_config_save(const char *path)
193{ 194{
194 Eet_File *ef; 195 Eet_File *ef;
195 Eina_Bool ok = EINA_TRUE; 196 Eina_Bool ok = EINA_TRUE;
196 char *utf8; 197 char *utf8;
197 Eina_Bool b; 198 Eina_Bool b;
198 199
199 ef = eet_open(AUTOSAVE_CONFIG, EET_FILE_MODE_WRITE); 200 ef = eet_open(path, EET_FILE_MODE_WRITE);
200 if (!ef) return EINA_FALSE; 201 if (!ef) return EINA_FALSE;
201 202
202 // NOTE: We could be cleaner and use eet_data_write, 203 // NOTE: We could be cleaner and use eet_data_write,
@@ -251,8 +252,8 @@ _config_save(void)
251} 252}
252 253
253static void 254static void
254_file_chosen_cb(void *data, 255_image_file_chosen_cb(void *data, Evas_Object *obj EINA_UNUSED,
255 Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) 256 void *event_info EINA_UNUSED)
256{ 257{
257 int k = (int) (intptr_t) data; 258 int k = (int) (intptr_t) data;
258 Eina_Stringshare *path = event_info; 259 Eina_Stringshare *path = event_info;
@@ -445,6 +446,30 @@ _reset_click_cb(void *data EINA_UNUSED,
445 _image_set(k, NULL); 446 _image_set(k, NULL);
446} 447}
447 448
449static void
450_flip_click_cb(void *data EINA_UNUSED,
451 Evas_Object *obj EINA_UNUSED,
452 void *event_info EINA_UNUSED)
453{
454 elm_flip_go(frameflip, ELM_FLIP_CUBE_LEFT);
455}
456
457static void
458_load_file_chosen_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
459 void *event_info EINA_UNUSED)
460{
461 Eina_Stringshare *path = event_info;
462 if (path && *path) _config_reload(path);
463}
464
465static void
466_save_file_chosen_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
467 void *event_info EINA_UNUSED)
468{
469 Eina_Stringshare *path = event_info;
470 if (path && *path) _config_save(path);
471}
472
448static Eina_Bool 473static Eina_Bool
449_entry_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, 474_entry_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
450 Evas_Object *src EINA_UNUSED, 475 Evas_Object *src EINA_UNUSED,
@@ -495,10 +520,13 @@ _panes_key_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
495EAPI_MAIN int 520EAPI_MAIN int
496elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED) 521elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
497{ 522{
498 Eo *win, *panes, *panes2, *vbox, *o, *hbox, *vb, *flip; 523 Eo *win, *panes, *panes2, *vbox, *o, *vb, *flip;
499 Eina_Bool ok; 524 Eina_Bool ok;
500 Evas *evas; 525 Evas *evas;
501 526
527 home = getenv("HOME");
528 if (!home) home = "/";
529
502 // window 530 // window
503 elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED); 531 elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
504 win = elm_win_util_standard_add("text-styles", "Text Style Tester"); 532 win = elm_win_util_standard_add("text-styles", "Text Style Tester");
@@ -533,7 +561,7 @@ elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
533 evas_object_show(flip); 561 evas_object_show(flip);
534 evas_object_size_hint_weight_set(flip, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); 562 evas_object_size_hint_weight_set(flip, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
535 evas_object_size_hint_align_set(flip, EVAS_HINT_FILL, EVAS_HINT_FILL); 563 evas_object_size_hint_align_set(flip, EVAS_HINT_FILL, EVAS_HINT_FILL);
536 elm_flip_interaction_set(flip, ELM_FLIP_INTERACTION_ROTATE); 564 elm_flip_interaction_set(flip, ELM_FLIP_INTERACTION_CUBE);
537 elm_flip_interaction_direction_hitsize_set(flip, ELM_FLIP_DIRECTION_LEFT, -1.0); 565 elm_flip_interaction_direction_hitsize_set(flip, ELM_FLIP_DIRECTION_LEFT, -1.0);
538 elm_flip_interaction_direction_hitsize_set(flip, ELM_FLIP_DIRECTION_RIGHT, -1.0); 566 elm_flip_interaction_direction_hitsize_set(flip, ELM_FLIP_DIRECTION_RIGHT, -1.0);
539 elm_flip_interaction_direction_enabled_set(flip, ELM_FLIP_DIRECTION_LEFT, EINA_TRUE); 567 elm_flip_interaction_direction_enabled_set(flip, ELM_FLIP_DIRECTION_LEFT, EINA_TRUE);
@@ -563,15 +591,24 @@ elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
563 elm_object_part_content_set(fr, "default", panes2); 591 elm_object_part_content_set(fr, "default", panes2);
564 592
565 // Evas_Object_Text 593 // Evas_Object_Text
594 vbox = elm_box_add(fr);
595 elm_box_horizontal_set(vbox, EINA_FALSE);
596 evas_object_size_hint_weight_set(vbox, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
597 evas_object_size_hint_align_set(vbox, EVAS_HINT_FILL, EVAS_HINT_FILL);
598 evas_object_show(vbox);
599 elm_object_part_content_set(panes2, "left", vbox);
600
566 o = evas_object_text_add(fr); 601 o = evas_object_text_add(fr);
567 evas_object_show(o); 602 evas_object_show(o);
568 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); 603 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
569 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL); 604 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
570 evas_object_text_font_set(o, FONT_NAME, FONT_SIZE); 605 evas_object_text_font_set(o, FONT_NAME, FONT_SIZE);
571 evas_object_size_hint_align_set(o, 0.0, 0.0); 606 evas_object_size_hint_align_set(o, 0.0, 0.0);
572 elm_object_part_content_set(panes2, "left", o); 607 elm_box_pack_start(vbox, o);
573 textview = o; 608 textview = o;
574 609
610 _spacer_add(vbox);
611
575 // Vbox with: string + edit entries 612 // Vbox with: string + edit entries
576 vbox = elm_box_add(fr); 613 vbox = elm_box_add(fr);
577 elm_box_horizontal_set(vbox, EINA_FALSE); 614 elm_box_horizontal_set(vbox, EINA_FALSE);
@@ -618,7 +655,7 @@ elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
618 else elm_object_event_callback_add(o, _panes_key_cb, NULL); 655 else elm_object_event_callback_add(o, _panes_key_cb, NULL);
619 656
620 // Bottom: font size, padding info 657 // Bottom: font size, padding info
621 hbox = elm_box_add(vbox); 658 Eo *hbox = elm_box_add(vbox);
622 evas_object_show(hbox); 659 evas_object_show(hbox);
623 elm_box_pack_end(vbox, hbox); 660 elm_box_pack_end(vbox, hbox);
624 elm_box_horizontal_set(hbox, EINA_TRUE); 661 elm_box_horizontal_set(hbox, EINA_TRUE);
@@ -759,7 +796,8 @@ elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
759 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); 796 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
760 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL); 797 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
761 elm_fileselector_button_is_save_set(o, EINA_FALSE); 798 elm_fileselector_button_is_save_set(o, EINA_FALSE);
762 evas_object_smart_callback_add(o, "file,chosen", _file_chosen_cb, (void*)(intptr_t)k); 799 elm_fileselector_button_path_set(o, home);
800 evas_object_smart_callback_add(o, "file,chosen", _image_file_chosen_cb, (void*)(intptr_t)k);
763 elm_table_pack(tbl, o, 0, 0, 1, 1); 801 elm_table_pack(tbl, o, 0, 0, 1, 1);
764 fsbuttons[k] = o; 802 fsbuttons[k] = o;
765 803
@@ -778,40 +816,76 @@ elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
778 816
779 // Reset & Quit: Bottom of the proxy bar 817 // Reset & Quit: Bottom of the proxy bar
780 { 818 {
781 hbox = elm_box_add(vb); 819 Eo *tbl = elm_table_add(vb);
782 evas_object_show(hbox); 820 evas_object_size_hint_weight_set(tbl, EVAS_HINT_EXPAND, 0);
783 elm_box_horizontal_set(hbox, EINA_TRUE); 821 evas_object_size_hint_align_set(tbl, EVAS_HINT_FILL, EVAS_HINT_FILL);
784 elm_box_pack_end(vb, hbox); 822 evas_object_show(tbl);
823 elm_box_pack_end(vb, tbl);
824
825 // Flip button
826 o = elm_button_add(tbl);
827 evas_object_show(o);
828 elm_object_text_set(o, _("Switch mode"));
829 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
830 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
831 evas_object_smart_callback_add(o, "clicked", _flip_click_cb, NULL);
832 elm_table_pack(tbl, o, 0, 0, 2, 1);
785 833
786 // Reset button 834 // Reset button
787 o = elm_button_add(hbox); 835 o = elm_button_add(tbl);
788 evas_object_show(o); 836 evas_object_show(o);
789 elm_box_pack_end(hbox, o);
790 elm_object_text_set(o, _("Reset images")); 837 elm_object_text_set(o, _("Reset images"));
838 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
839 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
791 evas_object_smart_callback_add(o, "clicked", _reset_click_cb, NULL); 840 evas_object_smart_callback_add(o, "clicked", _reset_click_cb, NULL);
841 elm_table_pack(tbl, o, 0, 2, 1, 1);
792 842
793 // Quit button 843 // Quit button
794 o = elm_button_add(hbox); 844 o = elm_button_add(tbl);
795 evas_object_show(o); 845 evas_object_show(o);
796 elm_box_pack_end(hbox, o);
797 elm_object_text_set(o, _("Quit")); 846 elm_object_text_set(o, _("Quit"));
847 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
848 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
798 evas_object_smart_callback_add(o, "clicked", _quit_click_cb, NULL); 849 evas_object_smart_callback_add(o, "clicked", _quit_click_cb, NULL);
850 elm_table_pack(tbl, o, 1, 2, 1, 1);
851
852 // Save button
853 o = elm_fileselector_button_add(tbl);
854 evas_object_show(o);
855 elm_object_text_set(o, "Save...");
856 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
857 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
858 elm_fileselector_button_is_save_set(o, EINA_TRUE);
859 elm_fileselector_button_path_set(o, home);
860 evas_object_smart_callback_add(o, "file,chosen", _save_file_chosen_cb, NULL);
861 elm_table_pack(tbl, o, 0, 1, 1, 1);
862
863 // Load button
864 o = elm_fileselector_button_add(tbl);
865 evas_object_show(o);
866 elm_object_text_set(o, "Load...");
867 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
868 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
869 elm_fileselector_button_is_save_set(o, EINA_FALSE);
870 elm_fileselector_button_path_set(o, home);
871 evas_object_smart_callback_add(o, "file,chosen", _load_file_chosen_cb, NULL);
872 elm_table_pack(tbl, o, 1, 1, 1, 1);
799 } 873 }
800 874
801 // Reload config 875 // Reload config
802 _config_reload(); 876 _config_reload(AUTOSAVE_CONFIG);
803 877
804 // Apply default style 878 // Apply default style
805 _style_apply(); 879 _style_apply();
806 880
807#ifndef HAS_FILTER_CHAIN 881#ifndef HAS_FILTER_CHAIN
808 elm_object_tooltip_text_set(flip, "Program was compiled WITHOUT filter support!"); 882 elm_object_tooltip_text_set(flip, _("Program was compiled WITHOUT filter support!"));
809#endif 883#endif
810 884
811 elm_run(); 885 elm_run();
812 886
813 // Save config 887 // Save config
814 _config_save(); 888 _config_save(AUTOSAVE_CONFIG);
815 elm_shutdown(); 889 elm_shutdown();
816 890
817 return 0; 891 return 0;