summaryrefslogtreecommitdiff
path: root/src/bin
diff options
context:
space:
mode:
authorYakov Goldberg <yakov.g@samsung.com>2014-12-15 18:36:37 +0200
committerYakov Goldberg <yakov.g@samsung.com>2014-12-15 18:36:37 +0200
commit8700fa0c5aa9de9c28717c234bbb442861ef631e (patch)
tree325ddea2f6dc003d811b8eae0fab6b223eef501a /src/bin
parent1dd8a56f5273734c84c02a9acff6bee1e45cf524 (diff)
Add memento when resizing widgets by dragging markers
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/egui_gui/editor.c130
1 files changed, 115 insertions, 15 deletions
diff --git a/src/bin/egui_gui/editor.c b/src/bin/egui_gui/editor.c
index 2f89c0c..e6d2658 100644
--- a/src/bin/egui_gui/editor.c
+++ b/src/bin/egui_gui/editor.c
@@ -246,7 +246,6 @@ enum
246 eo_do(_m, evas_obj_color_set(0, 255, 0, 255));\ 246 eo_do(_m, evas_obj_color_set(0, 255, 0, 255));\
247 eo_do(_m, evas_obj_size_set(7, 7));\ 247 eo_do(_m, evas_obj_size_set(7, 7));\
248 eo_do(_m, eo_event_callback_add(EVAS_OBJECT_EVENT_MOUSE_DOWN, _marker_mouse_down, (void *) (intptr_t) id)); \ 248 eo_do(_m, eo_event_callback_add(EVAS_OBJECT_EVENT_MOUSE_DOWN, _marker_mouse_down, (void *) (intptr_t) id)); \
249 eo_do(_m, eo_event_callback_add(EVAS_OBJECT_EVENT_MOUSE_UP, _marker_mouse_up, (void *) (intptr_t) id)); \
250 eo_do(_m, eo_event_callback_add(EVAS_OBJECT_EVENT_MOUSE_IN, _marker_mouse_in, (void *) (intptr_t) id)); \ 249 eo_do(_m, eo_event_callback_add(EVAS_OBJECT_EVENT_MOUSE_IN, _marker_mouse_in, (void *) (intptr_t) id)); \
251 eo_do(_m, eo_event_callback_add(EVAS_OBJECT_EVENT_MOUSE_OUT, _marker_mouse_out, (void *) (intptr_t) id)); \ 250 eo_do(_m, eo_event_callback_add(EVAS_OBJECT_EVENT_MOUSE_OUT, _marker_mouse_out, (void *) (intptr_t) id)); \
252 eo_do(evas_object_smart_parent_get(g->main_win->main_box), evas_obj_smart_member_add(_m)); \ 251 eo_do(evas_object_smart_parent_get(g->main_win->main_box), evas_obj_smart_member_add(_m)); \
@@ -686,7 +685,6 @@ _marker_mouse_move(void *data, Eo *marker EINA_UNUSED, const Eo_Event_Descriptio
686 { 685 {
687 Gui_Widget_Property *prop; 686 Gui_Widget_Property *prop;
688 Gui_Value *val; 687 Gui_Value *val;
689
690 prop = wdg_prop_get(wdg, DB_DEF_EVAS_OBJECT_CLASS, SIZE_SET); 688 prop = wdg_prop_get(wdg, DB_DEF_EVAS_OBJECT_CLASS, SIZE_SET);
691 if (!prop) 689 if (!prop)
692 { 690 {
@@ -725,40 +723,142 @@ _marker_mouse_move(void *data, Eo *marker EINA_UNUSED, const Eo_Event_Descriptio
725 Gui_Widget_Property *prop; 723 Gui_Widget_Property *prop;
726 Gui_Value *val; 724 Gui_Value *val;
727 prop = wdg_prop_get(wdg, DB_DEF_EVAS_OBJECT_CLASS, SIZE_SET); 725 prop = wdg_prop_get(wdg, DB_DEF_EVAS_OBJECT_CLASS, SIZE_SET);
728 if (prop) 726 if (!prop)
729 { 727 {
730 val = prop_value_nth_get(prop, 0); 728 Op_Desc *op = db_mro_op_desc_get(wdg_class_name_get(wdg), DB_DEF_EVAS_OBJECT_CLASS, SIZE_SET);
731 gui_value_int_set(val, ow); 729 prop = prop_create_for_op(op);
732 val = prop_value_nth_get(prop, 1); 730 wdg_prop_add((Gui_Widget *) wdg, prop);
733 gui_value_int_set(val, oh);
734 propview_item_update(prop);
735 } 731 }
732 val = prop_value_nth_get(prop, 0);
733 gui_value_int_set(val, ow);
734 val = prop_value_nth_get(prop, 1);
735 gui_value_int_set(val, oh);
736 propview_item_update(prop);
736 737
737 prop = wdg_prop_get(wdg, DB_DEF_EVAS_OBJECT_CLASS, POSITION_SET); 738 prop = wdg_prop_get(wdg, DB_DEF_EVAS_OBJECT_CLASS, POSITION_SET);
738 if (prop) 739 if (!prop)
739 { 740 {
740 val = prop_value_nth_get(prop, 0); 741 Op_Desc *op = db_mro_op_desc_get(wdg_class_name_get(wdg), DB_DEF_EVAS_OBJECT_CLASS, POSITION_SET);
741 gui_value_int_set(val, ox); 742 prop = prop_create_for_op(op);
742 val = prop_value_nth_get(prop, 1); 743 wdg_prop_add((Gui_Widget *) wdg, prop);
743 gui_value_int_set(val, oy);
744 propview_item_update(prop);
745 } 744 }
745 val = prop_value_nth_get(prop, 0);
746 gui_value_int_set(val, ox);
747 val = prop_value_nth_get(prop, 1);
748 gui_value_int_set(val, oy);
749 propview_item_update(prop);
746 } 750 }
747 751
748 return EO_CALLBACK_CONTINUE; 752 return EO_CALLBACK_CONTINUE;
749} 753}
750 754
755/* Struct to save old properties when resizing widgets by dragging marker. */
756typedef struct
757{
758 void *data;
759 Gui_Widget_Property *prop_size;
760 Gui_Widget_Property *prop_pos;
761} _Marker_Move_Data;
762
751static Eina_Bool 763static Eina_Bool
752_marker_mouse_down(void *data, Eo *obj, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED) 764_marker_mouse_down(void *data, Eo *obj, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED)
753{ 765{
766 const Gui_Widget *wdg = _editor_wdg_selected_get();
767 _Marker_Move_Data *_mmd = calloc(1, sizeof(_Marker_Move_Data));
768
769 _mmd->data = data;
770
771 Gui_Widget_Property *prop;
772 prop = wdg_prop_get(wdg, DB_DEF_EVAS_OBJECT_CLASS, SIZE_SET);
773 if (prop)
774 {
775 _mmd->prop_size = prop;
776 prop_ref(prop);
777 wdg_prop_remove((Gui_Widget *) wdg, prop);
778 }
779 if (!IS_MAIN(wdg))
780 {
781 prop = wdg_prop_get(wdg, DB_DEF_EVAS_OBJECT_CLASS, POSITION_SET);
782 if (prop)
783 {
784 _mmd->prop_pos = prop;
785 prop_ref(prop);
786 wdg_prop_remove((Gui_Widget *) wdg, prop);
787 }
788 }
789
754 eo_do(obj, eo_event_callback_add(EVAS_OBJECT_EVENT_MOUSE_MOVE, _marker_mouse_move, data)); 790 eo_do(obj, eo_event_callback_add(EVAS_OBJECT_EVENT_MOUSE_MOVE, _marker_mouse_move, data));
791 eo_do(obj, eo_event_callback_add(EVAS_OBJECT_EVENT_MOUSE_UP, _marker_mouse_up, _mmd));
755 return EO_CALLBACK_CONTINUE; 792 return EO_CALLBACK_CONTINUE;
756} 793}
757 794
758static Eina_Bool 795static Eina_Bool
759_marker_mouse_up(void *data, Eo *obj, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED) 796_marker_mouse_up(void *data, Eo *obj, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED)
760{ 797{
761 eo_do(obj, eo_event_callback_del(EVAS_OBJECT_EVENT_MOUSE_MOVE, _marker_mouse_move, data)); 798 _Marker_Move_Data *_mmd = data;
799 eo_do(obj, eo_event_callback_del(EVAS_OBJECT_EVENT_MOUSE_MOVE, _marker_mouse_move, _mmd->data));
800 eo_do(obj, eo_event_callback_del(EVAS_OBJECT_EVENT_MOUSE_UP, _marker_mouse_up, _mmd));
801
802 const Gui_Widget *wdg = _editor_wdg_selected_get();
803
804 Gui_Widget_Property *prop = wdg_prop_get(wdg, DB_DEF_EVAS_OBJECT_CLASS, SIZE_SET);
805 /* mouse was not moved... */
806 if (!prop)
807 {
808 /*...put old property back. */
809 if (_mmd->prop_size)
810 {
811 wdg_prop_add((Gui_Widget *) wdg, _mmd->prop_size);
812 }
813 goto end;
814 }
815 else
816 {
817 if ((INT_GET(prop_value_nth_get(prop, 0)) == INT_GET(prop_value_nth_get(_mmd->prop_size, 0))) &&
818 (INT_GET(prop_value_nth_get(prop, 1)) == INT_GET(prop_value_nth_get(_mmd->prop_size, 1))))
819 {
820 goto end;
821 }
822 Gui_Memento *memento = NULL;
823 memento = gui_memento_new(wdg_dep_id_get(wdg), MEMENTO_PROPERTY, _mmd->prop_size, prop);
824 gui_context_memento_add(_active_context_get(), memento);
825 }
826
827 /* For non Main widget save position in memento. */
828 if (!IS_MAIN(wdg))
829 {
830 prop = wdg_prop_get(wdg, DB_DEF_EVAS_OBJECT_CLASS, POSITION_SET);
831 if (!prop)
832 {
833 if (_mmd->prop_pos)
834 {
835 wdg_prop_add((Gui_Widget *) wdg, _mmd->prop_pos);
836 }
837 goto end;
838 }
839 else
840 {
841 if ((INT_GET(prop_value_nth_get(prop, 0)) == INT_GET(prop_value_nth_get(_mmd->prop_pos, 0))) &&
842 (INT_GET(prop_value_nth_get(prop, 1)) == INT_GET(prop_value_nth_get(_mmd->prop_pos, 1))))
843 {
844 goto end;
845 }
846 Gui_Memento *memento = NULL;
847 memento = gui_memento_new(wdg_dep_id_get(wdg), MEMENTO_PROPERTY, _mmd->prop_pos, prop);
848 gui_memento_append((Gui_Memento *) gui_context_current_memento_get(_active_context_get()), memento);
849 }
850 }
851
852end:
853 if (_mmd->prop_size)
854 {
855 prop_unref(_mmd->prop_size);
856 }
857 if (_mmd->prop_pos)
858 {
859 prop_unref(_mmd->prop_pos);
860 }
861 free(_mmd);
762 return EO_CALLBACK_CONTINUE; 862 return EO_CALLBACK_CONTINUE;
763} 863}
764 864