[pitivi] guidelines: Pixel perfect lines
- From: Alexandru Băluț <alexbalut src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pitivi] guidelines: Pixel perfect lines
- Date: Tue, 12 May 2020 06:27:50 +0000 (UTC)
commit a8bb1603073e87733e770307bc05f46e92a8938a
Author: Alexandru Băluț <alexandru balut gmail com>
Date: Fri May 8 22:19:01 2020 +0200
guidelines: Pixel perfect lines
pitivi/utils/misc.py | 9 +++++++--
pitivi/viewer/guidelines.py | 23 +++++++++++++++--------
tests/test_utils_misc.py | 31 +++++++++++++++++++++++++++++++
3 files changed, 53 insertions(+), 10 deletions(-)
---
diff --git a/pitivi/utils/misc.py b/pitivi/utils/misc.py
index 84e29a50..27b875f6 100644
--- a/pitivi/utils/misc.py
+++ b/pitivi/utils/misc.py
@@ -25,8 +25,8 @@ from urllib.parse import urlparse
from urllib.parse import urlsplit
from gi.repository import GdkPixbuf
-from gi.repository import GLib
from gi.repository import GES
+from gi.repository import GLib
from gi.repository import Gst
from gi.repository import Gtk
@@ -230,6 +230,10 @@ def quantize(value, interval):
return (value // interval) * interval
+def round05(value):
+ return (2 * value) // 2 + 0.5
+
+
def show_user_manual(page=None):
"""Displays the user manual.
@@ -460,6 +464,7 @@ def video_info_get_natural_height(video_info):
return video_info.get_height()
+
def asset_get_duration(asset):
assert isinstance(asset, GES.UriClipAsset)
@@ -470,4 +475,4 @@ def asset_get_duration(asset):
if res:
return duration
- return asset.get_duration()
\ No newline at end of file
+ return asset.get_duration()
diff --git a/pitivi/viewer/guidelines.py b/pitivi/viewer/guidelines.py
index f5dcefd3..bb5ef409 100644
--- a/pitivi/viewer/guidelines.py
+++ b/pitivi/viewer/guidelines.py
@@ -21,6 +21,7 @@ from gettext import gettext as _
from gi.repository import Gtk
+from pitivi.utils.misc import round05
from pitivi.utils.ui import SPACING
@@ -30,17 +31,23 @@ class Guideline(Enum):
@staticmethod
def __three_by_three_draw_func(cr, width, height):
for i in range(1, 3):
- cr.move_to(i * width / 3, 0)
- cr.line_to(i * width / 3, height)
- cr.move_to(0, i * height / 3)
- cr.line_to(width, i * height / 3)
+ x = round05(i * width / 3)
+ cr.move_to(x, 0)
+ cr.line_to(x, height)
+
+ y = round05(i * height / 3)
+ cr.move_to(0, y)
+ cr.line_to(width, y)
@staticmethod
def __vertical_horizontal_center_draw_func(cr, width, height):
- cr.move_to(width / 2, 0)
- cr.line_to(width / 2, height)
- cr.move_to(0, height / 2)
- cr.line_to(width, height / 2)
+ x = round05(width / 2)
+ cr.move_to(x, 0)
+ cr.line_to(x, height)
+
+ y = round05(height / 2)
+ cr.move_to(0, y)
+ cr.line_to(width, y)
@staticmethod
def __diagonals_draw_func(cr, width, height):
diff --git a/tests/test_utils_misc.py b/tests/test_utils_misc.py
new file mode 100644
index 00000000..99a19a1b
--- /dev/null
+++ b/tests/test_utils_misc.py
@@ -0,0 +1,31 @@
+# -*- coding: utf-8 -*-
+# Pitivi video editor
+# Copyright (c) 2020, Alexandru Băluț <alexandru balut gmail com>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this program; if not, see <http://www.gnu.org/licenses/>.
+from pitivi.utils.misc import round05
+from tests import common
+
+
+class TestMisc(common.TestCase):
+
+ def test_round05(self):
+ self.assertEqual(round05(0), 0.5)
+ self.assertEqual(round05(0.999), 0.5)
+
+ self.assertEqual(round05(1), 1.5)
+ self.assertEqual(round05(1.999), 1.5)
+
+ self.assertEqual(round05(2), 2.5)
+ self.assertEqual(round05(2.999), 2.5)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]