diff options
author | Kai Huuhko <kai.huuhko@gmail.com> | 2015-03-08 23:48:21 +0200 |
---|---|---|
committer | Kai Huuhko <kai.huuhko@gmail.com> | 2015-03-08 23:48:21 +0200 |
commit | 3dd81c4f604bb6ce141016f6c95e2359cdf592d5 (patch) | |
tree | 4252bb970d07da6fc23a40812961d9f6676e9161 | |
parent | 9e86901b0d9abd4b8824e347ee5fd773b36aa88e (diff) |
Evas.SmartObject: Switch to using C implementation of ClippedSO
-rw-r--r-- | doc/evas/class-smart.rst | 5 | ||||
-rw-r--r-- | efl/evas/efl.evas_object_smart.pxi | 121 | ||||
-rw-r--r-- | include/efl.evas.pxd | 1 |
3 files changed, 20 insertions, 107 deletions
diff --git a/doc/evas/class-smart.rst b/doc/evas/class-smart.rst index 33b247e..0ccc600 100644 --- a/doc/evas/class-smart.rst +++ b/doc/evas/class-smart.rst | |||
@@ -9,8 +9,3 @@ | |||
9 | =================================== | 9 | =================================== |
10 | 10 | ||
11 | .. autoclass:: efl.evas.SmartObject | 11 | .. autoclass:: efl.evas.SmartObject |
12 | |||
13 | :class:`efl.evas.ClippedSmartObject` Class | ||
14 | ========================================== | ||
15 | |||
16 | .. autoclass:: efl.evas.ClippedSmartObject | ||
diff --git a/efl/evas/efl.evas_object_smart.pxi b/efl/evas/efl.evas_object_smart.pxi index d204a2a..4e4ccb4 100644 --- a/efl/evas/efl.evas_object_smart.pxi +++ b/efl/evas/efl.evas_object_smart.pxi | |||
@@ -362,7 +362,7 @@ cdef class Smart: | |||
362 | 362 | ||
363 | cdef Evas_Smart *cls | 363 | cdef Evas_Smart *cls |
364 | 364 | ||
365 | def __cinit__(self): | 365 | def __cinit__(self, clipped=False): |
366 | cdef Evas_Smart_Class *cls_def | 366 | cdef Evas_Smart_Class *cls_def |
367 | 367 | ||
368 | cls_def = <Evas_Smart_Class*>PyMem_Malloc(sizeof(Evas_Smart_Class)) | 368 | cls_def = <Evas_Smart_Class*>PyMem_Malloc(sizeof(Evas_Smart_Class)) |
@@ -374,18 +374,23 @@ cdef class Smart: | |||
374 | 374 | ||
375 | cls_def.name = name | 375 | cls_def.name = name |
376 | cls_def.version = EVAS_SMART_CLASS_VERSION | 376 | cls_def.version = EVAS_SMART_CLASS_VERSION |
377 | cls_def.add = NULL # use python constructor | 377 | |
378 | cls_def.delete = _smart_object_delete | 378 | if clipped: |
379 | cls_def.move = _smart_object_move | 379 | evas_object_smart_clipped_smart_set(cls_def) |
380 | cls_def.resize = _smart_object_resize | 380 | else: |
381 | cls_def.show = _smart_object_show | 381 | cls_def.add = NULL # use python constructor |
382 | cls_def.hide = _smart_object_hide | 382 | cls_def.delete = _smart_object_delete |
383 | cls_def.color_set = _smart_object_color_set | 383 | cls_def.move = _smart_object_move |
384 | cls_def.clip_set = _smart_object_clip_set | 384 | cls_def.resize = _smart_object_resize |
385 | cls_def.clip_unset = _smart_object_clip_unset | 385 | cls_def.show = _smart_object_show |
386 | cls_def.calculate = _smart_object_calculate | 386 | cls_def.hide = _smart_object_hide |
387 | cls_def.member_add = _smart_object_member_add | 387 | cls_def.color_set = _smart_object_color_set |
388 | cls_def.member_del = _smart_object_member_del | 388 | cls_def.clip_set = _smart_object_clip_set |
389 | cls_def.clip_unset = _smart_object_clip_unset | ||
390 | cls_def.calculate = _smart_object_calculate | ||
391 | cls_def.member_add = _smart_object_member_add | ||
392 | cls_def.member_del = _smart_object_member_del | ||
393 | |||
389 | cls_def.parent = NULL | 394 | cls_def.parent = NULL |
390 | cls_def.callbacks = NULL | 395 | cls_def.callbacks = NULL |
391 | cls_def.interfaces = NULL | 396 | cls_def.interfaces = NULL |
@@ -396,6 +401,7 @@ cdef class Smart: | |||
396 | 401 | ||
397 | def delete(self): | 402 | def delete(self): |
398 | evas_smart_free(self.cls) | 403 | evas_smart_free(self.cls) |
404 | self.cls = NULL | ||
399 | Py_DECREF(self) | 405 | Py_DECREF(self) |
400 | 406 | ||
401 | @staticmethod | 407 | @staticmethod |
@@ -808,92 +814,3 @@ cdef class SmartObject(Object): | |||
808 | evas_object_smart_calculate(self.obj) | 814 | evas_object_smart_calculate(self.obj) |
809 | 815 | ||
810 | _object_mapping_register("Evas_Smart", SmartObject) | 816 | _object_mapping_register("Evas_Smart", SmartObject) |
811 | |||
812 | |||
813 | cdef class ClippedSmartObject(SmartObject): | ||
814 | """SmartObject subclass that automatically handles an internal clipper. | ||
815 | |||
816 | This class is optimized for the recommended SmartObject usage of | ||
817 | having an internal clipper, with all member objects clipped to it and | ||
818 | operations like :py:func:`hide()`, :py:func:`show()`, :py:func:`color_set()`, :py:func:`clip_set()` and | ||
819 | :py:func:`clip_unset()` operating on it. | ||
820 | |||
821 | This internal clipper size is huge by default (and not the same as the | ||
822 | object size), this means that you should clip this object to another | ||
823 | object clipper to get its contents restricted. This is the default | ||
824 | because many times what we want are contents that can overflow SmartObject | ||
825 | boundaries (ie: members with animations coming in from outside). | ||
826 | |||
827 | :ivar clipper: the internal object used for clipping. You shouldn't | ||
828 | mess with it. | ||
829 | |||
830 | :todo: remove current code and wrap C version (now it's in evas). | ||
831 | |||
832 | :param canvas: Evas canvas for this object | ||
833 | :type canvas: Canvas | ||
834 | :keyword size: Width and height | ||
835 | :type size: tuple of ints | ||
836 | :keyword pos: X and Y | ||
837 | :type pos: tuple of ints | ||
838 | :keyword geometry: X, Y, width, height | ||
839 | :type geometry: tuple of ints | ||
840 | :keyword color: R, G, B, A | ||
841 | :type color: tuple of ints | ||
842 | :keyword name: Object name | ||
843 | :type name: string | ||
844 | :keyword file: File name | ||
845 | :type file: string | ||
846 | |||
847 | """ | ||
848 | def __init__(self, Canvas canvas not None, **kargs): | ||
849 | if type(self) is ClippedSmartObject: | ||
850 | raise TypeError("Must not instantiate ClippedSmartObject, but " | ||
851 | "subclasses") | ||
852 | SmartObject.__init__(self, canvas, **kargs) | ||
853 | if self.clipper is None: | ||
854 | self.clipper = Rectangle(canvas) | ||
855 | evas_object_move(self.clipper.obj, -100000, -100000) | ||
856 | evas_object_resize(self.clipper.obj, 200000, 200000) | ||
857 | evas_object_static_clip_set(self.clipper.obj, 1) | ||
858 | evas_object_pass_events_set(self.clipper.obj, 1) | ||
859 | evas_object_smart_member_add(self.clipper.obj, self.obj) | ||
860 | |||
861 | def member_add(self, Object child): | ||
862 | """Set an evas object as a member of this object, already clipping.""" | ||
863 | if self.clipper is None or self.clipper is child: | ||
864 | return | ||
865 | evas_object_clip_set(child.obj, self.clipper.obj) | ||
866 | if evas_object_visible_get(self.obj): | ||
867 | evas_object_show(self.clipper.obj) | ||
868 | |||
869 | def member_del(self, Object child): | ||
870 | """Removes a member object from a smart object, already unsets its clip.""" | ||
871 | if self.clipper is child: | ||
872 | return | ||
873 | evas_object_clip_unset(child.obj) | ||
874 | if evas_object_clipees_get(self.clipper.obj) == NULL: | ||
875 | evas_object_hide(self.clipper.obj) | ||
876 | |||
877 | def show(self): | ||
878 | """Default implementation that acts on the the clipper.""" | ||
879 | if evas_object_clipees_get(self.clipper.obj) != NULL: | ||
880 | evas_object_show(self.clipper.obj) | ||
881 | |||
882 | def hide(self): | ||
883 | """Default implementation that acts on the the clipper.""" | ||
884 | evas_object_hide(self.clipper.obj) | ||
885 | |||
886 | def color_set(self, int r, int g, int b, int a): | ||
887 | """Default implementation that acts on the the clipper.""" | ||
888 | evas_object_color_set(self.clipper.obj, r, g, b, a) | ||
889 | |||
890 | def clip_set(self, Object clip): | ||
891 | """Default implementation that acts on the the clipper.""" | ||
892 | evas_object_clip_set(self.clipper.obj, clip.obj) | ||
893 | |||
894 | def clip_unset(self): | ||
895 | """Default implementation that acts on the the clipper.""" | ||
896 | evas_object_clip_unset(self.clipper.obj) | ||
897 | |||
898 | _object_mapping_register("Evas_Smart_Clipped", ClippedSmartObject) | ||
899 | |||
diff --git a/include/efl.evas.pxd b/include/efl.evas.pxd index fcd7890..b92591b 100644 --- a/include/efl.evas.pxd +++ b/include/efl.evas.pxd | |||
@@ -806,6 +806,7 @@ cdef extern from "Evas.h": | |||
806 | void evas_object_smart_calculate(Evas_Object *obj) | 806 | void evas_object_smart_calculate(Evas_Object *obj) |
807 | void evas_object_smart_move_children_relative(Evas_Object *obj, int dx, int dy) | 807 | void evas_object_smart_move_children_relative(Evas_Object *obj, int dx, int dy) |
808 | Eina_Iterator *evas_object_smart_iterator_new(const Evas_Object_Smart *obj) | 808 | Eina_Iterator *evas_object_smart_iterator_new(const Evas_Object_Smart *obj) |
809 | void evas_object_smart_clipped_smart_set(Evas_Smart_Class *sc) | ||
809 | 810 | ||
810 | 811 | ||
811 | #################################################################### | 812 | #################################################################### |