[prev in list] [next in list] [prev in thread] [next in thread] 

List:       enlightenment-svn
Subject:    E SVN: tiago trunk/editje/editje
From:       "Enlightenment SVN" <no-reply () enlightenment ! org>
Date:       2010-11-30 16:09:15
Message-ID: 20101130160915.87E6210B01BA () e2 ! enlightenment ! org
[Download RAW message or body]

Log:
Initial support to key modifier.
  
  Added use for control and shift modifiers in part handlers.
  Shift work with aspect and Control use steps. In part move, shift
  restrict moviment in 0, 45, 90,... degrees.

Author:       tiago
Date:         2010-11-30 08:09:13 -0800 (Tue, 30 Nov 2010)
New Revision: 55089
Trac:         http://trac.enlightenment.org/e/changeset/55089

Modified:
  trunk/editje/editje/desktop_handler.py trunk/editje/editje/desktop_part_handlers.py 

Modified: trunk/editje/editje/desktop_handler.py
===================================================================
--- trunk/editje/editje/desktop_handler.py	2010-11-30 15:37:20 UTC (rev 55088)
+++ trunk/editje/editje/desktop_handler.py	2010-11-30 16:09:13 UTC (rev 55089)
@@ -42,6 +42,9 @@
         self._operation_stack_cb = op_stack_cb
         self._edit_grp = editable_grp
 
+        self.modifier_ctrl = False
+        self.modifier_shift = False
+
     @evas.decorators.del_callback
     def _on_del(self):
         if self._move_animator is not None:
@@ -54,6 +57,8 @@
         self._start = event.position.output.xy
         self._last = self._start
         self._move_animator = ecore.animator_add(self.__move_animator_do)
+        self._modifier_control = event.modifier_is_set("Control")
+        self._modifier_shift = event.modifier_is_set("Shift")
         self.down(*event.position.output)
         self.on_mouse_up_add(self.__mouse_up_cb)
 
@@ -61,6 +66,9 @@
         return
 
     def __move_animator_do(self):
+        self._modifier_control = self.evas.key_modifier_is_set("Control")
+        self._modifier_shift = self.evas.key_modifier_is_set("Shift")
+
         cur = self.evas.pointer_output_xy_get()
         if cur == self._last:
             return True
@@ -79,6 +87,10 @@
 
     def __mouse_up_cb(self, obj, event):
         self.on_mouse_up_del(self.__mouse_up_cb)
+
+        self._modifier_control = event.modifier_is_set("Control")
+        self._modifier_shift = event.modifier_is_set("Shift")
+
         sx, sy, sw, sh = self._desktop_scroller.region_get()
         dw = event.position.output[0] - self._start[0]
         dw += sx - self._start_region[0]

Modified: trunk/editje/editje/desktop_part_handlers.py
===================================================================
--- trunk/editje/editje/desktop_part_handlers.py	2010-11-30 15:37:20 UTC (rev 55088)
+++ trunk/editje/editje/desktop_part_handlers.py	2010-11-30 16:09:13 UTC (rev 55089)
@@ -15,12 +15,13 @@
 # You should have received a copy of the GNU Lesser General Public
 # License along with Editje. If not, see <http://www.gnu.org/licenses/>.
 
+import math
+
 from desktop_handler import Handler
 from desktop_part_listener import PartListener
 from operation import Operation
 from elementary import cursors
 
-
 class PartHandler(Handler, PartListener):
     def __init__(self, editable_grp, desktop_scroller, theme_file,
                  rel1_move_offset_inform_cb=None,
@@ -56,7 +57,13 @@
         self._edit_grp.part.name = part
         self._edit_grp.part.state.name = state
 
+    def _modifier_ctrl_adjust(self, dw, dh):
+        if self._modifier_control:
+            dw = (dw / 10) * 10
+            dh = (dh / 10) * 10
+        return (dw, dh)
 
+
 class PartHandler_Move(PartHandler):
     cursor = cursors.ELM_CURSOR_FLEUR
 
@@ -70,23 +77,42 @@
             op_stack_cb, group)
         self.size = (10, 10)
 
+    def _modifier_shift_adjust(self, dw, dh):
+        if self._modifier_shift:
+            angle = math.atan2(dh, dw)
+            sin = abs(math.sin(angle))
+            sin45 = math.sin(math.radians(45))
+            adjust = int(round(math.degrees(angle) / 45)) % 2
+
+            if sin > sin45:
+                dw = math.copysign(dh * adjust, dw)
+            else:
+                dh = math.copysign(dw * adjust, dh)
+
+        return (dw, dh)
+
     def part_move(self, obj):
         self.center = obj.center
         self.show()
 
     def move(self, dw, dh, part_name=None, state_name=None,
              anim=None, time=None):
+
         if part_name and state_name:
             self._context_recall(part_name, state_name, anim, time)
 
         if self._part:
             x, y, w, h = self._geometry
+            dw, dh = self._modifier_ctrl_adjust(dw, dh)
+            dw, dh = self._modifier_shift_adjust(dw, dh)
             self._part.pos = (x + dw, y + dh)
 
     def up(self, dw, dh):
         if not self._part:
             return
 
+        dw, dh = self._modifier_ctrl_adjust(dw, dh)
+        dw, dh = self._modifier_shift_adjust(dw, dh)
         if (dw, dh) != (0, 0):
             op = Operation("part moving")
 
@@ -124,12 +150,14 @@
 
         if self._part:
             x, y, w, h = self._geometry
+            dw, dh = self._modifier_ctrl_adjust(dw, dh)
             self._part.geometry = (x, y + dh, w, h - dh)
 
     def up(self, dw, dh):
         if not self._part:
             return
 
+        dw, dh = self._modifier_ctrl_adjust(dw, dh)
         if dh != 0:
             op = Operation("part resizing (from top)")
 
@@ -150,6 +178,18 @@
 class PartHandler_TL(PartHandler):
     cursor = cursors.ELM_CURSOR_TOP_LEFT_CORNER
 
+    def _modifier_shift_adjust(self, dw, dh):
+        if self._modifier_shift:
+            x, y, w, h = self._geometry
+            aspect = float(w)/h
+            temp_dw = int(dh * aspect)
+            if temp_dw < dw:
+                dh = int(dw / aspect)
+                dw = int(dh * aspect)
+            else:
+                dw = temp_dw
+        return (dw, dh)
+
     def part_move(self, obj):
         self.show()
         self.bottom_right = obj.top_left
@@ -161,12 +201,16 @@
 
         if self._part:
             x, y, w, h = self._geometry
+            dw, dh = self._modifier_ctrl_adjust(dw, dh)
+            dw, dh = self._modifier_shift_adjust(dw, dh)
             self._part.geometry = (x + dw, y + dh, w - dw, h - dh)
 
     def up(self, dw, dh):
         if not self._part:
             return
 
+        dw, dh = self._modifier_ctrl_adjust(dw, dh)
+        dw, dh = self._modifier_shift_adjust(dw, dh)
         if (dw, dh) != (0, 0):
             op = Operation("part resizing (from top-left)")
 
@@ -187,6 +231,20 @@
 class PartHandler_TR(PartHandler):
     cursor = cursors.ELM_CURSOR_TOP_RIGHT_CORNER
 
+    def _modifier_shift_adjust(self, dw, dh):
+        if self._modifier_shift:
+            dh = - dh
+            x, y, w, h = self._geometry
+            aspect = float(w)/h
+            temp_dw = int(dh * aspect)
+            if temp_dw > dw:
+                dh = int(dw / aspect)
+                dw = int(dh * aspect)
+            else:
+                dw = temp_dw
+            dh = - dh
+        return (dw, dh)
+
     def part_move(self, obj):
         self.show()
         self.bottom_left = obj.top_right
@@ -198,12 +256,16 @@
 
         if self._part:
             x, y, w, h = self._geometry
+            dw, dh = self._modifier_ctrl_adjust(dw, dh)
+            dw, dh = self._modifier_shift_adjust(dw, dh)
             self._part.geometry = (x, y + dh, w + dw, h - dh)
 
     def up(self, dw, dh):
         if not self._part:
             return
 
+        dw, dh = self._modifier_ctrl_adjust(dw, dh)
+        dw, dh = self._modifier_shift_adjust(dw, dh)
         if (dw, dh) != (0, 0):
             op = Operation("part resizing (from top-left)")
 
@@ -241,12 +303,14 @@
 
         if self._part:
             x, y, w, h = self._geometry
+            dw, dh = self._modifier_ctrl_adjust(dw, dh)
             self._part.geometry = (x, y, w, h + dh)
 
     def up(self, dw, dh):
         if not self._part:
             return
 
+        dw, dh = self._modifier_ctrl_adjust(dw, dh)
         if dh != 0:
             op = Operation("part resizing (from bottom)")
 
@@ -267,6 +331,18 @@
 class PartHandler_BR(PartHandler):
     cursor = cursors.ELM_CURSOR_BOTTOM_RIGHT_CORNER
 
+    def _modifier_shift_adjust(self, dw, dh):
+        if self._modifier_shift:
+            x, y, w, h = self._geometry
+            aspect = float(w)/h
+            temp_dw = int(dh * aspect)
+            if temp_dw > dw:
+                dh = int(dw / aspect)
+                dw = int(dh * aspect)
+            else:
+                dw = temp_dw
+        return (dw, dh)
+
     def part_move(self, obj):
         self.show()
         self.top_left = obj.bottom_right
@@ -278,12 +354,16 @@
 
         if self._part:
             x, y, w, h = self._geometry
+            dw, dh = self._modifier_ctrl_adjust(dw, dh)
+            dw, dh = self._modifier_shift_adjust(dw, dh)
             self._part.geometry = (x, y, w + dw, h + dh)
 
     def up(self, dw, dh):
         if not self._part:
             return
 
+        dw, dh = self._modifier_ctrl_adjust(dw, dh)
+        dw, dh = self._modifier_shift_adjust(dw, dh)
         if (dw, dh) != (0, 0):
             op = Operation("part resizing (from bottom-right)")
 
@@ -304,6 +384,20 @@
 class PartHandler_BL(PartHandler):
     cursor = cursors.ELM_CURSOR_BOTTOM_LEFT_CORNER
 
+    def _modifier_shift_adjust(self, dw, dh):
+        if self._modifier_shift:
+            dw = - dw
+            x, y, w, h = self._geometry
+            aspect = float(w)/h
+            temp_dw = int(dh * aspect)
+            if temp_dw > dw:
+                dh = int(dw / aspect)
+                dw = int(dh * aspect)
+            else:
+                dw = temp_dw
+            dw = - dw
+        return (dw, dh)
+
     def part_move(self, obj):
         self.show()
         self.top_right = obj.bottom_left
@@ -315,12 +409,16 @@
 
         if self._part:
             x, y, w, h = self._geometry
+            dw, dh = self._modifier_ctrl_adjust(dw, dh)
+            dw, dh = self._modifier_shift_adjust(dw, dh)
             self._part.geometry = (x + dw, y, w - dw, h + dh)
 
     def up(self, dw, dh):
         if not self._part:
             return
 
+        dw, dh = self._modifier_ctrl_adjust(dw, dh)
+        dw, dh = self._modifier_shift_adjust(dw, dh)
         if (dw, dh) != (0, 0):
             op = Operation("part resizing (from bottom-left)")
 
@@ -358,12 +456,14 @@
 
         if self._part:
             x, y, w, h = self._geometry
+            dw, dh = self._modifier_ctrl_adjust(dw, dh)
             self._part.geometry = (x + dw, y, w - dw, h)
 
     def up(self, dw, dh):
         if not self._part:
             return
 
+        dw, dh = self._modifier_ctrl_adjust(dw, dh)
         if dw != 0:
             op = Operation("part resizing (from left)")
 
@@ -398,12 +498,14 @@
 
         if self._part:
             x, y, w, h = self._geometry
+            dw, dh = self._modifier_ctrl_adjust(dw, dh)
             self._part.geometry = (x, y, w + dw, h)
 
     def up(self, dw, dh):
         if not self._part:
             return
 
+        dw, dh = self._modifier_ctrl_adjust(dw, dh)
         if dw != 0:
             op = Operation("part resizing (from right)")
 


------------------------------------------------------------------------------
Increase Visibility of Your 3D Game App & Earn a Chance To Win $500!
Tap into the largest installed PC base & get more eyes on your game by
optimizing for Intel(R) Graphics Technology. Get started today with the
Intel(R) Software Partner Program. Five $500 cash prizes are up for grabs.
http://p.sf.net/sfu/intelisp-dev2dev
_______________________________________________
enlightenment-svn mailing list
enlightenment-svn@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-svn
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic