From b6d6cecfb71a99652a37336585051c9aac96a68b Mon Sep 17 00:00:00 2001 From: Taylor Bockman Date: Mon, 3 Feb 2020 22:11:06 -0800 Subject: [PATCH] Make window DPI aware, need to restart on application on the window you wish to run for it to work right now --- .DS_Store | Bin 0 -> 6148 bytes main_window.py | 11 ++++++----- voronoiview.py | 6 +++++- voronoiview.ui | 12 +++++++++--- voronoiview/ui/mode_handlers.py | 5 +++-- voronoiview/ui/opengl_widget.py | 25 +++++++++++-------------- voronoiview_ui.py | 5 +++-- 7 files changed, 37 insertions(+), 27 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..a21852bfd99d2d696abf2a4c3eb0deb203bf64d7 GIT binary patch literal 6148 zcmeHK%Sr<=6g|-{s+Cef(B&-MSa9uTEG^sZf)ZZ&)mD;`?q~OOnTj6(q)8v9uDZcAJ$kC)&Nh8ACWm^y^b@S z;wWU9ZGIZc8CI3?9o%BfjB|^9B&^jX{~|ZYxQ27IaEK;Oh;{bV&oN$dW8A_6M|O`X zGf8bkA7g???4i&4jJ-@ai%G7Z_gp`VXY>K)IhN>>?Y&yeDq01ZOKt@VGm=Y{!@M%9fV;UQ zZ`-a=(QiOjB0F+Es{N1xJhR2h6^B}?0;+&2@TGu!A0oP7>@js{KOHRW6@XY`vo+S` z&w_9wkFm$pA>Yu9qY@p}_$!8Sbhbx6F7}u@baWVh`7l1S@i!D>v$OxmhQq`TwNwRE zflz@}_gItjzqS1SACmM*6;K8Kl>(;Jyl6H!C4aUqOis?)h<-^IlepBOrLgeFv8~8a dyhFFfcac - + 0 0 + + + 833 + 656 + + - 900 - 16777215 + 833 + 656 diff --git a/voronoiview/ui/mode_handlers.py b/voronoiview/ui/mode_handlers.py index b43c1d1..78e5763 100644 --- a/voronoiview/ui/mode_handlers.py +++ b/voronoiview/ui/mode_handlers.py @@ -106,7 +106,8 @@ def _handle_add_point(ctx, event): try: # No attribute at the moment, default point color is Color.GREY. - PointManager.point_set.add_point(event.x(), event.y(), Color.GREY) + PointManager.point_set.add_point(event.x() * ctx.devicePixelRatio(), + event.y() * ctx.devicePixelRatio(), Color.GREY) except ExceededWindowBoundsError: # The user tried to place a point whos edges would be # on the outside of the window. We will just ignore it. @@ -359,7 +360,7 @@ def _handle_voronoi(ctx, _): point_arr = [point.array for point in points] - PointManager.voronoi_results = Voronoi(point_arr) + PointManager.voronoi_results = Voronoi(point_arr, qhull_options='Qbb Qz Qx Qi Qc QJ') ctx.opengl_widget.update() ctx.voronoi_solved = True diff --git a/voronoiview/ui/opengl_widget.py b/voronoiview/ui/opengl_widget.py index db9ddc2..a1d758c 100644 --- a/voronoiview/ui/opengl_widget.py +++ b/voronoiview/ui/opengl_widget.py @@ -13,22 +13,18 @@ It should be split up into a few more separate files eventually... Probably even into it's own module folder. """ -import math -from typing import List - from OpenGL.GL import (glBegin, glClearColor, glColor3f, glColor4f, glEnable, glEnd, GL_LINES, GL_LINE_LOOP, GL_LINE_SMOOTH, GL_POINTS, glPointSize, glVertex3f, glViewport) -from voronoiview.colors import Color, COLOR_TO_RGBA -from voronoiview.exceptions import (handle_exceptions, - InvalidStateError) +from voronoiview.colors import (Color, COLOR_TO_RGBA) + +from voronoiview.exceptions import InvalidStateError from voronoiview.mode import Mode from voronoiview.point_manager import PointManager # Constants set based on the size of the window. -__BOTTOM_LEFT = (0, 0) __WIDTH = None __HEIGHT = None @@ -147,9 +143,10 @@ def resize_gl(w, h): """ global __WIDTH global __HEIGHT + global __current_context - __WIDTH = __current_context.opengl_widget.width() - __HEIGHT = __current_context.opengl_widget.height() + __WIDTH = __current_context.opengl_widget.width() * __current_context.devicePixelRatio() + __HEIGHT = __current_context.opengl_widget.height() * __current_context.devicePixelRatio() def viewport_width(): @@ -160,7 +157,6 @@ def viewport_height(): return __HEIGHT -@handle_exceptions def paint_gl(): """ Stock PaintGL function from OpenGL that switches @@ -410,15 +406,16 @@ def draw_voronoi_diagram(): color = COLOR_TO_RGBA[Color.BLACK] - for region_indices in results.regions: - # The region index is out of bounds - if -1 in region_indices: - continue + print(results.regions) + for region_indices in results.regions: glBegin(GL_LINE_LOOP) for idx in region_indices: vertex = vertices[idx] + if -1 in region_indices: + continue + glColor3f(color[0], color[1], color[2]) glVertex3f(__clamp_x(vertex[0]), __clamp_y(vertex[1]), diff --git a/voronoiview_ui.py b/voronoiview_ui.py index 9eee756..92ac26d 100644 --- a/voronoiview_ui.py +++ b/voronoiview_ui.py @@ -26,12 +26,13 @@ class Ui_MainWindow(object): self.horizontalLayout = QtWidgets.QHBoxLayout(self.centralwidget) self.horizontalLayout.setObjectName("horizontalLayout") self.opengl_widget = QtWidgets.QOpenGLWidget(self.centralwidget) - sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Preferred) + sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.opengl_widget.sizePolicy().hasHeightForWidth()) self.opengl_widget.setSizePolicy(sizePolicy) - self.opengl_widget.setMaximumSize(QtCore.QSize(900, 16777215)) + self.opengl_widget.setMinimumSize(QtCore.QSize(833, 656)) + self.opengl_widget.setMaximumSize(QtCore.QSize(833, 656)) self.opengl_widget.setObjectName("opengl_widget") self.horizontalLayout.addWidget(self.opengl_widget) self.verticalLayout = QtWidgets.QVBoxLayout()