summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2020-02-15 14:36:09 +0000
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2020-02-15 14:36:09 +0000
commitf02cb1cb0dbb3e269430a1d65784a14b9cf636e8 (patch)
treeb156d05acfed44de68500a570658782ff758244b
parent6a0de945e00938f86c5224bf4f2fb5e8a526b3b3 (diff)
edje player - make it more useful with padding option
so you can see the overflow outside and edje object, add padding as an option to move the obj inside the win. this means also nuking the over-engineered box stacking thing... :)
-rw-r--r--src/bin/edje/edje_player.c174
1 files changed, 75 insertions, 99 deletions
diff --git a/src/bin/edje/edje_player.c b/src/bin/edje/edje_player.c
index cacfdf2974..d54dea9ed5 100644
--- a/src/bin/edje/edje_player.c
+++ b/src/bin/edje/edje_player.c
@@ -31,12 +31,16 @@ struct opts
31 Eina_Bool print; 31 Eina_Bool print;
32 Eina_Bool slave_mode; 32 Eina_Bool slave_mode;
33 double scale; 33 double scale;
34 int pad;
34 char *title; 35 char *title;
35}; 36};
36 37
37static Eina_Bool _edje_load_or_show_error(Evas_Object *edje, const char *file, const char *group); 38static Eina_Bool _edje_load_or_show_error(Evas_Object *edje, const char *file, const char *group);
38 39
39static Ecore_Evas *win; 40static Ecore_Evas *win;
41static Evas *evas;
42static Evas_Object *bg, *bg2 = NULL, *edje;
43static struct opts opts;
40 44
41static void 45static void
42_win_title_set(const char *group, const char *file) 46_win_title_set(const char *group, const char *file)
@@ -754,71 +758,37 @@ _print_message(void *data EINA_UNUSED, Evas_Object *edje EINA_UNUSED, Edje_Messa
754} 758}
755 759
756static void 760static void
757_reset_size_hints(void *data, Evas *e EINA_UNUSED, Evas_Object *stack, void *event_info EINA_UNUSED) 761_key_down(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info)
758{
759 Evas_Coord minw, minh;
760 Evas_Object *edje = data;
761
762 edje_object_size_min_get(edje, &minw, &minh);
763 if ((minw <= 0) && (minh <= 0))
764 edje_object_size_min_calc(edje, &minw, &minh);
765
766 evas_object_size_hint_min_set(stack, minw, minh);
767}
768
769static void
770_key_down(void *data, Evas *e EINA_UNUSED, Evas_Object *stack EINA_UNUSED, void *event_info)
771{ 762{
772 Evas_Event_Key_Down *ev = event_info; 763 Evas_Event_Key_Down *ev = event_info;
773 struct opts *opts = data;
774 764
775 if ((!strcmp(ev->keyname, "equal")) || 765 if ((!strcmp(ev->keyname, "equal")) ||
776 (!strcmp(ev->keyname, "plus"))) 766 (!strcmp(ev->keyname, "plus")))
777 opts->scale += 0.1; 767 opts.scale += 0.1;
778 else if ((!strcmp(ev->keyname, "minus")) || 768 else if ((!strcmp(ev->keyname, "minus")) ||
779 (!strcmp(ev->keyname, "underscore"))) 769 (!strcmp(ev->keyname, "underscore")))
780 opts->scale -= 0.1; 770 opts.scale -= 0.1;
781 else if ((!strcmp(ev->keyname, "0"))) 771 else if ((!strcmp(ev->keyname, "0")))
782 opts->scale = 1.0; 772 opts.scale = 1.0;
783 if (opts->scale < 0.1) opts->scale = 0.1; 773 if (opts.scale < 0.1) opts.scale = 0.1;
784 else if (opts->scale > 10.0) 774 else if (opts.scale > 10.0)
785 opts->scale = 1.0; 775 opts.scale = 10.0;
786 edje_scale_set(opts->scale); 776 edje_scale_set(opts.scale);
787}
788
789static Evas_Object *
790_create_stack(Evas *evas, const struct opts *opts)
791{
792 Evas_Object *stack = evas_object_box_add(evas);
793 if (!stack)
794 {
795 fputs("ERROR: could not create object stack (box).\n", stderr);
796 return NULL;
797 }
798 evas_object_box_layout_set(stack, evas_object_box_layout_stack, NULL, NULL);
799 evas_object_resize(stack, opts->size.w, opts->size.h);
800 evas_object_size_hint_weight_set(stack, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
801 evas_object_size_hint_align_set(stack, EVAS_HINT_FILL, EVAS_HINT_FILL);
802 evas_object_show(stack);
803 return stack;
804} 777}
805 778
806static Evas_Object * 779static Evas_Object *
807_create_bg(Evas *evas, const struct opts *opts) 780_create_bg(void)
808{ 781{
809 const unsigned char *color = opts->color; 782 const unsigned char *color = opts.color;
810 Evas_Object *bg = evas_object_rectangle_add(evas); 783 Evas_Object *o = evas_object_rectangle_add(evas);
811 if (!bg) 784 if (!o)
812 { 785 {
813 fputs("ERROR: could not create background.\n", stderr); 786 fputs("ERROR: could not create background.\n", stderr);
814 return NULL; 787 return NULL;
815 } 788 }
816 evas_object_resize(bg, opts->size.w, opts->size.h); 789 evas_object_color_set(o, color[0], color[1], color[2], 255);
817 evas_object_color_set(bg, color[0], color[1], color[2], 255); 790 evas_object_show(o);
818 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); 791 return o;
819 evas_object_size_hint_align_set(bg, EVAS_HINT_FILL, EVAS_HINT_FILL);
820 evas_object_show(bg);
821 return bg;
822} 792}
823 793
824static void 794static void
@@ -827,7 +797,6 @@ _edje_reload(void *data EINA_UNUSED, Evas_Object *obj, const char *emission EINA
827 const char *file; 797 const char *file;
828 const char *group; 798 const char *group;
829 edje_object_signal_callback_del(obj, "edje,change,file", "edje", _edje_reload); 799 edje_object_signal_callback_del(obj, "edje,change,file", "edje", _edje_reload);
830
831 edje_object_file_get(obj, &file, &group); 800 edje_object_file_get(obj, &file, &group);
832 _edje_load_or_show_error(obj, file, group); 801 _edje_load_or_show_error(obj, file, group);
833} 802}
@@ -899,73 +868,73 @@ _edje_load_or_show_error(Evas_Object *edje, const char *file, const char *group)
899} 868}
900 869
901static Evas_Object * 870static Evas_Object *
902_create_edje(Evas *evas, const struct opts *opts) 871_create_edje(void)
903{ 872{
904 Evas_Coord minw, minh, maxw, maxh; 873 Evas_Coord minw, minh, maxw, maxh;
905 Evas_Object *edje = edje_object_add(evas); 874 Evas_Object *o = edje_object_add(evas);
906 if (!edje) 875 if (!o)
907 { 876 {
908 fputs("ERROR: could not create edje.\n", stderr); 877 fputs("ERROR: could not create edje.\n", stderr);
909 return NULL; 878 return NULL;
910 } 879 }
911 880
912 if (opts->group) 881 if (opts.group)
913 { 882 {
914 if (!_edje_load_or_show_error(edje, opts->file, opts->group)) 883 if (!_edje_load_or_show_error(o, opts.file, opts.group))
915 { 884 {
916 evas_object_del(edje); 885 evas_object_del(edje);
917 return NULL; 886 return NULL;
918 } 887 }
919 if (!opts->title) _win_title_set(opts->group, opts->file); 888 if (!opts.title) _win_title_set(opts.group, opts.file);
920 } 889 }
921 else 890 else
922 { 891 {
923 if (edje_file_group_exists(opts->file, "main")) 892 if (edje_file_group_exists(opts.file, "main"))
924 { 893 {
925 if (!_edje_load_or_show_error(edje, opts->file, "main")) 894 if (!_edje_load_or_show_error(o, opts.file, "main"))
926 { 895 {
927 evas_object_del(edje); 896 evas_object_del(edje);
928 return NULL; 897 return NULL;
929 } 898 }
930 if (!opts->title) _win_title_set("main", opts->file); 899 if (!opts.title) _win_title_set("main", opts.file);
931 } 900 }
932 else 901 else
933 { 902 {
934 Eina_List *groups = edje_file_collection_list(opts->file); 903 Eina_List *groups = edje_file_collection_list(opts.file);
935 const char *group; 904 const char *group;
936 if (!groups) 905 if (!groups)
937 { 906 {
938 fprintf(stderr, "ERROR: file '%s' has no groups!\n", 907 fprintf(stderr, "ERROR: file '%s' has no groups!\n",
939 opts->file); 908 opts.file);
940 evas_object_del(edje); 909 evas_object_del(edje);
941 return NULL; 910 return NULL;
942 } 911 }
943 group = groups->data; 912 group = groups->data;
944 if (!_edje_load_or_show_error(edje, opts->file, group)) 913 if (!_edje_load_or_show_error(o, opts.file, group))
945 { 914 {
946 edje_file_collection_list_free(groups); 915 edje_file_collection_list_free(groups);
947 evas_object_del(edje); 916 evas_object_del(edje);
948 return NULL; 917 return NULL;
949 } 918 }
950 if (!opts->title) _win_title_set(group, opts->file); 919 if (!opts.title) _win_title_set(group, opts.file);
951 edje_file_collection_list_free(groups); 920 edje_file_collection_list_free(groups);
952 } 921 }
953 } 922 }
954 evas_object_smart_callback_add(edje, "circular,dependency", _edje_circul, opts->group); 923 evas_object_smart_callback_add(o, "circular,dependency", _edje_circul, opts.group);
955 924
956 edje_object_size_max_get(edje, &maxw, &maxh); 925 edje_object_size_max_get(o, &maxw, &maxh);
957 edje_object_size_min_get(edje, &minw, &minh); 926 edje_object_size_min_get(o, &minw, &minh);
958 if ((minw <= 0) && (minh <= 0)) 927 if ((minw <= 0) && (minh <= 0))
959 edje_object_size_min_calc(edje, &minw, &minh); 928 edje_object_size_min_calc(o, &minw, &minh);
960 929
961 evas_object_size_hint_max_set(edje, maxw, maxh); 930 ecore_evas_size_max_set(win,
962 evas_object_size_hint_min_set(edje, minw, minh); 931 maxw > 0 ? (maxw + opts.pad * 2) : 0,
932 maxh > 0 ? (maxh + opts.pad * 2) : 0);
933 ecore_evas_size_min_set(win, (minw + opts.pad * 2), (minh + opts.pad * 2));
963 934
964 evas_object_size_hint_weight_set(edje, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); 935 evas_object_show(o);
965 evas_object_size_hint_align_set(edje, EVAS_HINT_FILL, EVAS_HINT_FILL);
966 evas_object_show(edje);
967 936
968 return edje; 937 return o;
969} 938}
970 939
971static unsigned char 940static unsigned char
@@ -988,6 +957,18 @@ _cb_delete(EINA_UNUSED Ecore_Evas *ee)
988 ecore_main_loop_quit(); 957 ecore_main_loop_quit();
989} 958}
990 959
960static void
961_cb_resize(Ecore_Evas *ee)
962{
963 int w, h;
964 ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
965 evas_object_move(edje, opts.pad, opts.pad);
966 evas_object_resize(edje, w - (opts.pad * 2), h - (opts.pad * 2));
967 evas_object_move(bg, opts.pad, opts.pad);
968 evas_object_resize(bg, w - (opts.pad * 2), h - (opts.pad * 2));
969 if (bg2) evas_object_resize(bg2, w, h);
970}
971
991const Ecore_Getopt optdesc = { 972const Ecore_Getopt optdesc = {
992 "edje_player", 973 "edje_player",
993 "%prog [options] <filename.edj>", 974 "%prog [options] <filename.edj>",
@@ -1010,8 +991,8 @@ const Ecore_Getopt optdesc = {
1010 ('Z', "size", "size to use in wxh form.", "WxH", 991 ('Z', "size", "size to use in wxh form.", "WxH",
1011 ecore_getopt_callback_size_parse, NULL), 992 ecore_getopt_callback_size_parse, NULL),
1012 ECORE_GETOPT_CALLBACK_ARGS 993 ECORE_GETOPT_CALLBACK_ARGS
1013 ('c', "bg-color", "Color of the background (if not shaped or alpha)", 994 ('c', "bg-color", "Color of the background (if not shaped or alpha) e.g. 255,150,50",
1014 "RRGGBB", _parse_color, NULL), 995 "R,G,B", _parse_color, NULL),
1015 ECORE_GETOPT_STORE_TRUE 996 ECORE_GETOPT_STORE_TRUE
1016 ('b', "borderless", "Display window without border."), 997 ('b', "borderless", "Display window without border."),
1017 ECORE_GETOPT_STORE_TRUE 998 ECORE_GETOPT_STORE_TRUE
@@ -1029,6 +1010,8 @@ const Ecore_Getopt optdesc = {
1029 ('S', "slave-mode", "Listen for commands on stdin"), 1010 ('S', "slave-mode", "Listen for commands on stdin"),
1030 ECORE_GETOPT_STORE_DOUBLE 1011 ECORE_GETOPT_STORE_DOUBLE
1031 ('z', "scale", "Set scale factor"), 1012 ('z', "scale", "Set scale factor"),
1013 ECORE_GETOPT_STORE_INT
1014 ('P', "pad", "Set pixel padding around object"),
1032 ECORE_GETOPT_LICENSE('L', "license"), 1015 ECORE_GETOPT_LICENSE('L', "license"),
1033 ECORE_GETOPT_COPYRIGHT('C', "copyright"), 1016 ECORE_GETOPT_COPYRIGHT('C', "copyright"),
1034 ECORE_GETOPT_VERSION('V', "version"), 1017 ECORE_GETOPT_VERSION('V', "version"),
@@ -1040,9 +1023,6 @@ const Ecore_Getopt optdesc = {
1040int 1023int
1041main(int argc, char **argv) 1024main(int argc, char **argv)
1042{ 1025{
1043 Evas *evas;
1044 Evas_Object *stack, *edje;
1045 struct opts opts;
1046 Eina_Bool quit_option = EINA_FALSE; 1026 Eina_Bool quit_option = EINA_FALSE;
1047 int args; 1027 int args;
1048 Eina_List *groups; 1028 Eina_List *groups;
@@ -1063,6 +1043,7 @@ main(int argc, char **argv)
1063 ECORE_GETOPT_VALUE_BOOL(opts.print), 1043 ECORE_GETOPT_VALUE_BOOL(opts.print),
1064 ECORE_GETOPT_VALUE_BOOL(opts.slave_mode), 1044 ECORE_GETOPT_VALUE_BOOL(opts.slave_mode),
1065 ECORE_GETOPT_VALUE_DOUBLE(opts.scale), 1045 ECORE_GETOPT_VALUE_DOUBLE(opts.scale),
1046 ECORE_GETOPT_VALUE_INT(opts.pad),
1066 ECORE_GETOPT_VALUE_BOOL(quit_option), 1047 ECORE_GETOPT_VALUE_BOOL(quit_option),
1067 ECORE_GETOPT_VALUE_BOOL(quit_option), 1048 ECORE_GETOPT_VALUE_BOOL(quit_option),
1068 ECORE_GETOPT_VALUE_BOOL(quit_option), 1049 ECORE_GETOPT_VALUE_BOOL(quit_option),
@@ -1160,37 +1141,32 @@ main(int argc, char **argv)
1160 1141
1161 ecore_evas_callback_delete_request_set(win, _cb_delete); 1142 ecore_evas_callback_delete_request_set(win, _cb_delete);
1162 evas = ecore_evas_get(win); 1143 evas = ecore_evas_get(win);
1163 stack = _create_stack(evas, &opts);
1164 if (!stack)
1165 {
1166 goto free_ecore_evas;
1167 }
1168
1169 ecore_evas_object_associate(win, stack, ECORE_EVAS_OBJECT_ASSOCIATE_BASE);
1170 1144
1171 if (opts.alpha) 1145 if (opts.alpha)
1172 ecore_evas_alpha_set(win, EINA_TRUE); 1146 ecore_evas_alpha_set(win, EINA_TRUE);
1173 else if (opts.shaped) 1147 else if (opts.shaped)
1174 ecore_evas_shaped_set(win, EINA_TRUE); 1148 ecore_evas_shaped_set(win, EINA_TRUE);
1175 else
1176 {
1177 Evas_Object *bg = _create_bg(evas, &opts);
1178 if (bg) evas_object_box_append(stack, bg);
1179 }
1180 1149
1181 edje = _create_edje(evas, &opts); 1150 if (opts.pad > 0)
1182 if (edje)
1183 evas_object_box_append(stack, edje);
1184 else
1185 { 1151 {
1186 goto free_ecore_evas; 1152 bg2 = evas_object_rectangle_add(evas);
1153 evas_object_resize(bg2, opts.size.w, opts.size.h);
1154 if (opts.alpha)
1155 evas_object_color_set(bg2, 0, 0, 0, 64);
1156 else
1157 evas_object_color_set(bg2, 64, 64, 64, 255);
1158 evas_object_show(bg2);
1187 } 1159 }
1160 bg = _create_bg();
1161
1162 edje = _create_edje();
1163 if (!edje) goto free_ecore_evas;
1188 1164
1189 evas_object_focus_set(stack, EINA_TRUE); 1165 ecore_evas_callback_resize_set(win, _cb_resize);
1190 evas_object_event_callback_add(stack, EVAS_CALLBACK_KEY_DOWN, 1166 _cb_resize(win);
1167 evas_object_focus_set(bg, EINA_TRUE);
1168 evas_object_event_callback_add(bg, EVAS_CALLBACK_KEY_DOWN,
1191 _key_down, &opts); 1169 _key_down, &opts);
1192 evas_object_event_callback_add(stack, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1193 _reset_size_hints, edje);
1194 1170
1195 if (opts.print) 1171 if (opts.print)
1196 { 1172 {