[pitivi] move_scale_overlay: Use box design for handles



commit e67e712bd0fe791db7eef6fe47852604af636c0e
Author: Diego Garcia Gangl <dnicolas gmail com>
Date:   Fri Apr 19 21:29:35 2019 -0300

    move_scale_overlay: Use box design for handles

 pitivi/viewer/move_scale_overlay.py | 72 ++++++++++++++++---------------------
 1 file changed, 30 insertions(+), 42 deletions(-)
---
diff --git a/pitivi/viewer/move_scale_overlay.py b/pitivi/viewer/move_scale_overlay.py
index 72040e06..18d95d82 100644
--- a/pitivi/viewer/move_scale_overlay.py
+++ b/pitivi/viewer/move_scale_overlay.py
@@ -17,7 +17,6 @@
 # Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 # Boston, MA 02110-1301, USA.
 from collections import OrderedDict
-from math import pi
 
 import cairo
 import numpy
@@ -36,9 +35,8 @@ class Edge:
 
 
 class Handle:
-    GLOW = 0.9
-    INITIAL_RADIUS = 15
-    MINIMAL_RADIUS = 5
+    INITIAL_SIZE = 30
+    MINIMAL_SIZE = 10
     CURSORS = {
         (Edge.top, Edge.left): "nw-resize",
         (Edge.bottom, Edge.left): "sw-resize",
@@ -51,7 +49,7 @@ class Handle:
     }
 
     def __init__(self, overlay):
-        self.__radius = Handle.INITIAL_RADIUS
+        self.__size = Handle.INITIAL_SIZE
         self.__clicked = False
         self.__window_position = numpy.array([0, 0])
         self.__translation = numpy.array([0, 0])
@@ -102,7 +100,7 @@ class Handle:
         return cursor_position
 
     def _get_normalized_minimal_size(self):
-        return 4 * Handle.MINIMAL_RADIUS / self._overlay.stack.window_size
+        return 2 * Handle.MINIMAL_SIZE / self._overlay.stack.window_size
 
     def get_window_position(self):
         return self.__window_position.tolist()
@@ -155,7 +153,7 @@ class Handle:
             return
 
         distance = numpy.linalg.norm(self.__window_position - cursor_pos)
-        if distance < self.__radius:
+        if distance < self.__size / 2:
             self.hovered = True
             self._overlay.stack.set_cursor(Handle.CURSORS[self.placement])
         else:
@@ -177,46 +175,36 @@ class Handle:
         self._opposite_position = None
         self._opposite_to_handle = None
 
-    def restrict_radius_to_size(self, size):
-        if size < Handle.INITIAL_RADIUS * 5:
-            radius = size / 5
-            if radius < Handle.MINIMAL_RADIUS:
-                radius = Handle.MINIMAL_RADIUS
-            self.__radius = radius
+    def restrict_size(self, size):
+        if size < Handle.INITIAL_SIZE * 5:
+            self.__size = max(Handle.MINIMAL_SIZE, size / 5)
         else:
-            self.__radius = Handle.INITIAL_RADIUS
+            self.__size = Handle.INITIAL_SIZE
 
     def reset_size(self):
-        self.__radius = Handle.INITIAL_RADIUS
+        self.__size = Handle.INITIAL_SIZE
 
     def draw(self, cr):
-        if self.__clicked:
-            outer_color = .2
-            glow_radius = 1.08
-        elif self.hovered:
-            outer_color = .8
-            glow_radius = 1.08
-        else:
-            outer_color = .5
-            glow_radius = 1.01
-
-        cr.set_source_rgba(Handle.GLOW, Handle.GLOW, Handle.GLOW, 0.9)
-        x, y = self.get_window_position()
-        cr.arc(x, y, self.__radius * glow_radius, 0, 2 * pi)
-        cr.fill()
-
-        from_point = (x, y - self.__radius)
-        to_point = (x, y + self.__radius)
-        linear = cairo.LinearGradient(*(from_point + to_point))
-        linear.add_color_stop_rgba(0.00, outer_color, outer_color, outer_color, 1)
-        linear.add_color_stop_rgba(0.55, .1, .1, .1, 1)
-        linear.add_color_stop_rgba(0.65, .1, .1, .1, 1)
-        linear.add_color_stop_rgba(1.00, outer_color, outer_color, outer_color, 1)
-
-        cr.set_source(linear)
+        src_x, src_y = self.get_window_position()
+        x = src_x - (self.__size / 2)
+        y = src_y - (self.__size / 2)
+
+        if self.hovered:
+            cr.set_source_rgba(1, 1, 1, 0.25)
+            cr.rectangle(x, y, self.__size, self.__size)
+            cr.fill()
+
+        # Black outline around the boxes
+        cr.set_source_rgb(0, 0, 0)
+        cr.set_line_width(3)
+        cr.rectangle(x, y, self.__size, self.__size)
+        cr.stroke()
 
-        cr.arc(x, y, self.__radius * .9, 0, 2 * pi)
-        cr.fill()
+        # Inner white line
+        cr.set_source_rgb(1, 1, 1)
+        cr.set_line_width(1)
+        cr.rectangle(x, y, self.__size, self.__size)
+        cr.stroke()
 
 
 class CornerHandle(Handle):
@@ -430,7 +418,7 @@ class MoveScaleOverlay(Overlay):
         smaller_size = numpy.amin(size)
 
         for handle in self.handles.values():
-            handle.restrict_radius_to_size(smaller_size)
+            handle.restrict_size(smaller_size)
 
     def __update_edges_from_corners(self):
         half_w = numpy.array([self.__get_width() * 0.5, 0])


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]