diff options
| author | Tim Keller <tjkeller.xyz> | 2025-05-10 16:26:33 -0500 |
|---|---|---|
| committer | Tim Keller <tjkeller.xyz> | 2025-05-10 16:26:33 -0500 |
| commit | 3aed05a6cb265e4f60a17f87eb368fb33c93a562 (patch) | |
| tree | 678661df04e9ae66ee7e4636d396bde8171cf2d3 /window.py | |
| parent | b823139687f3c55dd3695e11a0cf8f9693524e9b (diff) | |
| download | immich-frame-3aed05a6cb265e4f60a17f87eb368fb33c93a562.tar.xz immich-frame-3aed05a6cb265e4f60a17f87eb368fb33c93a562.zip | |
cleanup some
Diffstat (limited to 'window.py')
| -rw-r--r-- | window.py | 51 |
1 files changed, 23 insertions, 28 deletions
@@ -15,8 +15,8 @@ class PixDisplay: self.textures = [] self.current_texture_index = 0 self.renderer = None - self.window_width = 0 - self.window_height = 0 + self.win_w = 0 + self.win_h = 0 self.max_framerate = 30 self.display_duration = 2.0 @@ -32,13 +32,16 @@ class PixDisplay: self.frame_time = int(1000 / 60) # In ms @property + def prev_texture_index(self): return self.current_texture_index - 1 + + @property def next_texture_index(self): return (self.current_texture_index + 1) % len(self.textures) @property - def texture_current(self): return self.textures[self.current_texture_index] + def tex(self): return self.textures[self.current_texture_index] @property - def texture_next(self): return self.textures[self.next_texture_index] + def tex_next(self): return self.textures[self.next_texture_index] # Main display function def display(self): @@ -48,46 +51,38 @@ class PixDisplay: delta_time = current_time - self.last_time self.last_time = current_time + # Draw black window if no textures are available if not self.textures: - glClearColor(0.0, 0.0, 0.0, 1.0) # Set the background color to black + glClearColor(0.0, 0.0, 0.0, 1.0) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glutSwapBuffers() return # Ensure textures are initialized - self.texture_current.gl_init() - self.texture_next.gl_init() + self.tex.gl_init() + self.tex_next.gl_init() # Progress image time self.image_time += delta_time # Get window size - window_width, window_height = glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT) - - if self.image_time < self.display_duration: - if window_width != self.window_width or window_height != self.window_height: - self.window_width, self.window_height = window_width, window_height - - glClearColor(0.0, 0.0, 0.0, 1.0) # Set the background color to black - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) - - self.renderer.draw_static(self.texture_current, self.window_width, self.window_height, 1) - - glutSwapBuffers() + old_win_w, old_win_h = self.win_w, self.win_h + self.win_w, self.win_h = glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT) + + # Draw static image except during a transition + if self.image_time <= self.display_duration: + # Avoid redraw unless window size has changed + if self.win_w != old_win_w or self.win_h != old_win_h: + self.renderer.draw_static(self.tex, self.win_w, self.win_h, 1) return - self.window_width, self.window_height = window_width, window_height - - glClearColor(0.0, 0.0, 0.0, 1.0) # Set the background color to black - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) - - # DRAW + # Draw transition transition_time = self.image_time - self.display_duration - complete = self.renderer.draw_transition(self.texture_current, self.texture_next, self.window_width, self.window_height, delta_time, transition_time, self.transition_duration) - glutSwapBuffers() + # Draw frame of transition, function will return True if the transition is complete + self.renderer.draw_transition(self.tex, self.tex_next, self.win_w, self.win_h, delta_time, transition_time, self.transition_duration) - if complete: + if transition_time >= self.transition_duration: self.image_time = 0 self.current_texture_index = self.next_texture_index |
