diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..a21852b Binary files /dev/null and b/.DS_Store differ diff --git a/main_window.py b/main_window.py index 291e9b2..507ef16 100644 --- a/main_window.py +++ b/main_window.py @@ -38,13 +38,14 @@ class MainWindow(QMainWindow, Ui_MainWindow): # Size of point for drawing self._point_size = 8 - # TODO: THESE ARE HARD CODED TO THE CURRENT QT WIDGET SIZES - # FIX THIS PROPERLY WITH A RESIZE EVENT DETECT. + self._viewport_width = self.opengl_widget.width() * self.devicePixelRatio() + self._viewport_height = self.opengl_widget.height() * self.devicePixelRatio() + + print(self.height()) + print(self.width()) + # PointManager is a class that is filled with static methods # designed for managing state. - self._viewport_width = 833 - self._viewport_height = 656 - PointManager.point_set = PointSet(self._point_size, self._viewport_width, self._viewport_height) diff --git a/voronoiview.py b/voronoiview.py index 25f218f..3a4cf12 100644 --- a/voronoiview.py +++ b/voronoiview.py @@ -1,12 +1,16 @@ +import os import sys from PyQt5.QtWidgets import QApplication +from PyQt5.QtCore import Qt from main_window import MainWindow def main(): + os.environ["QT_AUTO_SCREEN_SCALE_FACTOR"] = "1" app = QApplication(sys.argv) + app.setAttribute(Qt.AA_EnableHighDpiScaling) window = MainWindow() window.show() @@ -15,4 +19,4 @@ def main(): if __name__ == '__main__': - main() + main() diff --git a/voronoiview.ui b/voronoiview.ui index ee3c43c..0341be2 100644 --- a/voronoiview.ui +++ b/voronoiview.ui @@ -36,15 +36,21 @@ - + 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()