commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] [gnuradio] 61/101: grc: gtk3: draw ports before blocks


From: git
Subject: [Commit-gnuradio] [gnuradio] 61/101: grc: gtk3: draw ports before blocks and simplyfied draw code
Date: Thu, 16 Mar 2017 14:58:07 +0000 (UTC)

This is an automated email from the git hooks/post-receive script.

jcorgan pushed a commit to branch python3
in repository gnuradio.

commit ab8ceb0c223c6521b112668df4580e93027e38e0
Author: Sebastian Koslowski <address@hidden>
Date:   Sat Jul 30 14:31:05 2016 +0200

    grc: gtk3: draw ports before blocks and simplyfied draw code
---
 grc/gui/Block.py      | 23 ++++++++++++----------
 grc/gui/Connection.py | 26 ++++++++++++++-----------
 grc/gui/Element.py    | 54 +++++++++++++--------------------------------------
 grc/gui/Port.py       | 16 +++++++++------
 4 files changed, 52 insertions(+), 67 deletions(-)

diff --git a/grc/gui/Block.py b/grc/gui/Block.py
index d1f67d6..6503994 100644
--- a/grc/gui/Block.py
+++ b/grc/gui/Block.py
@@ -107,12 +107,10 @@ class Block(CoreBlock, Element):
 
     def create_shapes(self):
         """Update the block, parameters, and ports when a change occurs."""
-        self.clear()
-
         if self.is_horizontal():
-            self.areas.append([0, 0, self.width, self.height])
+            self.area = [0, 0, self.width, self.height]
         elif self.is_vertical():
-            self.areas.append([0, 0, self.height, self.width])
+            self.area = [0, 0, self.height, self.width]
 
         bussified = self.current_bus_structure['source'], 
self.current_bus_structure['sink']
         for ports, has_busses in zip((self.active_sources, self.active_sinks), 
bussified):
@@ -241,19 +239,24 @@ class Block(CoreBlock, Element):
         else:
             self._comment_layout = None
 
-    def draw(self, widget, cr, border_color=None, bg_color=None):
+    def draw(self, widget, cr):
         """
         Draw the signal block with label and inputs/outputs.
         """
-        bg_color = self._bg_color
         border_color = Colors.HIGHLIGHT_COLOR if self.highlighted else 
self._border_color
-        # draw main block
-        Element.draw(self, widget, cr, border_color, bg_color)
-        for port in self.active_ports():
+        cr.translate(*self.coordinate)
+
+        for port in self.active_ports():  # ports first
             cr.save()
-            port.draw(widget, cr, border_color, bg_color)
+            port.draw(widget, cr, border_color)
             cr.restore()
 
+        cr.rectangle(*self.area)
+        cr.set_source_rgb(*self._bg_color)
+        cr.fill_preserve()
+        cr.set_source_rgb(*border_color)
+        cr.stroke()
+
         # title and params label
         if self.is_vertical():
             cr.rotate(-math.pi / 2)
diff --git a/grc/gui/Connection.py b/grc/gui/Connection.py
index 1c00845..b1ae32d 100644
--- a/grc/gui/Connection.py
+++ b/grc/gui/Connection.py
@@ -104,7 +104,6 @@ class Connection(Element, _Connection):
 
     def _update_after_move(self):
         """Calculate coordinates."""
-        self.clear()
         source = self.source_port
         sink = self.sink_port
         source_dir = source.get_connector_direction()
@@ -136,7 +135,7 @@ class Connection(Element, _Connection):
                 points, alt = alt, points
             # create 3-line connector
             i1, i2 = points
-            self.lines.append([p0, p1, i1, i2, p2, p3])
+            self.line = [p0, p1, i1, i2, p2, p3]
         else:
             # 2 possible points to create a right-angled connector
             point, alt = [(x1, y2), (x2, y1)]
@@ -150,7 +149,7 @@ class Connection(Element, _Connection):
             if Utils.get_angle_from_coordinates(point, p1) == source_dir:
                 point, alt = alt, point
             # create right-angled connector
-            self.lines.append([p0, p1, point, p2, p3])
+            self.line = [p0, p1, point, p2, p3]
 
     def draw(self, widget, cr, border_color=None, bg_color=None):
         """
@@ -169,22 +168,27 @@ class Connection(Element, _Connection):
             self._sink_coor = sink.parent_block.coordinate
             self._source_coor = source.parent_block.coordinate
         # draw
-        color1, color2 = (
+        color1, color2, arrow_color = (
             Colors.HIGHLIGHT_COLOR if self.highlighted else
             Colors.CONNECTION_DISABLED_COLOR if not self.enabled else
-            color for color in (self._color, self._color2))
+            color for color in (self._color, self._color2, self._arrow_color))
 
-        Element.draw(self, widget, cr, color1, 
Colors.FLOWGRAPH_BACKGROUND_COLOR)
+        cr.translate(*self.coordinate)
+        for point in self.line:
+            cr.line_to(*point)
+        cr.set_source_rgb(*color1)
+        cr.stroke_preserve()
 
         if color1 != color2:
             cr.save()
-            x_pos, y_pos = self.coordinate
-            cr.translate(-x_pos, -y_pos)
             cr.set_dash([5.0, 5.0], 5.0)
-            Element.draw(self, widget, cr, color2, 
Colors.FLOWGRAPH_BACKGROUND_COLOR)
+            cr.set_source_rgb(*color2)
+            cr.stroke()
             cr.restore()
-        # draw arrow on sink port
-        cr.set_source_rgb(*self._arrow_color)
+        else:
+            cr.new_path()
+
+        cr.set_source_rgb(*arrow_color)
         cr.move_to(*self._arrow[0])
         cr.line_to(*self._arrow[1])
         cr.line_to(*self._arrow[2])
diff --git a/grc/gui/Element.py b/grc/gui/Element.py
index cdbf548..30bc640 100644
--- a/grc/gui/Element.py
+++ b/grc/gui/Element.py
@@ -45,13 +45,8 @@ class Element(object):
         self.rotation = 0
         self.highlighted = False
 
-        self.areas = []
-        self.lines = []
-
-    def clear(self):
-        """Empty the lines and areas."""
-        del self.areas[:]
-        del self.lines[:]
+        self.area = []
+        self.line = []
 
     def is_horizontal(self, rotation=None):
         """
@@ -94,34 +89,11 @@ class Element(object):
         Create shapes (if applicable) and call on all children.
         Call this base method before creating shapes in the element.
         """
-        self.clear()
         for child in self.get_children():
             child.create_shapes()
 
-    def draw(self, widget, cr, border_color, bg_color):
-        """
-        Draw in the given window.
-
-        Args:
-            widget:
-            cr:
-            border_color: the color for lines and rectangle borders
-            bg_color: the color for the inside of the rectangle
-        """
-        cr.translate(*self.coordinate)
-        for area in self.areas:
-            cr.set_source_rgb(*bg_color)
-            cr.rectangle(*area)
-            cr.fill()
-            cr.set_source_rgb(*border_color)
-            cr.rectangle(*area)
-            cr.stroke()
-
-        cr.set_source_rgb(*border_color)
-        for line in self.lines:
-            for point in line:
-                cr.line_to(*point)
-            cr.stroke()
+    def draw(self, widget, cr):
+        raise NotImplementedError()
 
     def rotate(self, rotation):
         """
@@ -168,7 +140,8 @@ class Element(object):
         if coor_m:
             x_m, y_m = [a - b for a, b in zip(coor_m, self.coordinate)]
             # handle rectangular areas
-            for x1, y1, w, h in self.areas:
+            if self.area:
+                x1, y1, w, h = self.area
                 if (
                     in_between(x1,     x, x_m) and in_between(y1,     y, y_m) 
or
                     in_between(x1 + w, x, x_m) and in_between(y1,     y, y_m) 
or
@@ -177,9 +150,9 @@ class Element(object):
                 ):
                     return self
             # handle horizontal or vertical lines
-            for line in self.lines:
-                last_point = line[0]
-                for x2, y2 in line[1:]:
+            elif self.line:
+                last_point = self.line[0]
+                for x2, y2 in self.line[1:]:
                     (x1, y1), last_point = last_point, (x2, y2)
                     if (
                         in_between(x1, x, x_m) and in_between(y1, y, y_m) or
@@ -189,13 +162,14 @@ class Element(object):
             return None
         else:
             # handle rectangular areas
-            for x1, y1, w, h in self.areas:
+            if self.area:
+                x1, y1, w, h = self.area
                 if in_between(x, x1, x1+w) and in_between(y, y1, y1+h):
                     return self
             # handle horizontal or vertical lines
-            for line in self.lines:
-                last_point = line[0]
-                for x2, y2 in line[1:]:
+            elif self.line:
+                last_point = self.line[0]
+                for x2, y2 in self.line[1:]:
                     (x1, y1), last_point = last_point, (x2, y2)
                     if x1 == x2:
                         x1, x2 = x1 - LINE_SELECT_SENSITIVITY, x2 + 
LINE_SELECT_SENSITIVITY
diff --git a/grc/gui/Port.py b/grc/gui/Port.py
index 6776963..5e7d9ca 100644
--- a/grc/gui/Port.py
+++ b/grc/gui/Port.py
@@ -78,12 +78,10 @@ class Port(_Port, Element):
 
     def create_shapes(self):
         """Create new areas and labels for the port."""
-        self.clear()
-
         if self.is_horizontal():
-            self.areas.append([0, 0, self.width, self.height])
+            self.area = [0, 0, self.width, self.height]
         elif self.is_vertical():
-            self.areas.append([0, 0, self.height, self.width])
+            self.area = [0, 0, self.height, self.width]
 
         self._connector_coordinate = {
             0:   (self.width, self.height / 2),
@@ -116,12 +114,18 @@ class Port(_Port, Element):
             self._label_layout_offsets[1] += Constants.PORT_EXTRA_BUS_HEIGHT / 
2
         self.height += self.height % 2  # uneven height
 
-    def draw(self, widget, cr, border_color, bg_color):
+    def draw(self, widget, cr, border_color):
         """
         Draw the socket with a label.
         """
         cr.set_line_width(self._line_width_factor * cr.get_line_width())
-        Element.draw(self, widget, cr, border_color, self._bg_color)
+        cr.translate(*self.coordinate)
+
+        cr.rectangle(*self.area)
+        cr.set_source_rgb(*self._bg_color)
+        cr.fill_preserve()
+        cr.set_source_rgb(*border_color)
+        cr.stroke()
 
         if not self._show_label:
             return  # this port is folded (no label)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]