Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make windows resizable #57

Merged
merged 2 commits into from
Aug 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion yt_idv/cameras/base_camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ class BaseCamera(traitlets.HasTraits):
fov = traitlets.Float(45.0)
near_plane = traitlets.Float(0.001)
far_plane = traitlets.Float(20.0)
aspect_ratio = traitlets.Float(8.0 / 6.0)
aspect_ratio = traitlets.Float(
1.0
) # This was 8.0/6.0 for a long time. I don't know why.

projection_matrix = traittypes.Array(np.zeros((4, 4))).valid(
ndarray_shape(4, 4), ndarray_ro()
Expand Down Expand Up @@ -83,6 +85,9 @@ def compute_matrices(self, change=None):
with self.hold_traits(self._compute_matrices):
pass

def _update_matrices(self):
pass

def update_orientation(self, start_x, start_y, end_x, end_y):
"""Change camera orientation matrix using delta of mouse's cursor position

Expand Down
11 changes: 10 additions & 1 deletion yt_idv/rendering_contexts/pyglet_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ def __init__(
double_buffer=True,
depth_size=24,
)
super().__init__(width, height, config=config, visible=visible, caption=title)
super().__init__(
width, height, config=config, visible=visible, caption=title, resizable=True
)
if position is None:
self.center_window()
else:
Expand Down Expand Up @@ -76,6 +78,13 @@ def on_draw(self):
self.switch_to()
self.gui.render(self.scene)

def on_resize(self, width, height):
super().on_resize(width, height)
self.scene.reset_framebuffers()
self.scene.camera.aspect_ratio = width / height
self.scene.camera._update_matrices()
self._do_update = True

def set_position(self, xpos, ypos):
if xpos < 0 or ypos < 0:
raise RuntimeError
Expand Down
4 changes: 4 additions & 0 deletions yt_idv/scene_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ def __iter__(self):
elements = self.components + self.annotations
yield from sorted(elements, key=lambda a: a.priority)

def reset_framebuffers(self):
for c in self:
c.fb = Framebuffer()

def render(self):
"""
Render the scene into its local framebuffer.
Expand Down