Compare: a drag whose moves the window didn't see is still a drag; SUMMIT_SHOT dev hook for screenshots
Found live on the VM: the drag ended as a click (back to picking). SUMMIT_SHOT=<prefix> plus a <prefix>.req file makes the window write the frame it is about to show (the shared, composited llvmpipe display gave out-of-order window captures).
This commit is contained in:
1 parent
893cc9e7d5
commit
8cece32e50
3 files changed
+38
-3
No files matched your search
@@ -1023,7 +1023,11 @@ class Live:
|
||||
self.move_to(cx - (x - x0) / (z * w), cy - (y - y0) / (z * h), p) # the scene follows the hand
|
||||
return True
|
||||
|
||||
def release(self) -> bool:
|
||||
def release(self, x: float | None = None, y: float | None = None, w: int = 0, h: int = 0) -> bool:
|
||||
"""The mouse let go (at (x, y) of a w x h picture, if known: a drag whose moves weren't all seen still
|
||||
counts as a drag)."""
|
||||
if self._drag is not None and self._drag[0] == "pan" and x is not None:
|
||||
self.move(x, y, w, h)
|
||||
d, self._drag = self._drag, None
|
||||
if d is None:
|
||||
return False
|
||||
|
||||
+26
-2
@@ -970,8 +970,9 @@ class GLWindowSink:
|
||||
if action == glfw.RELEASE: # the end of a drag (the overlay by its title, a slider, the scrollbar)
|
||||
if self._cmp is not None:
|
||||
self._cmp["drag"] = False # (Compare's divider)
|
||||
if self.compare is not None:
|
||||
self.compare.release() # (Same area: a click without a drag goes back to picking)
|
||||
if self.compare is not None: # (Same area: a click without a drag goes back to picking)
|
||||
at = self._compare_xy() if self.compare.dragging else None
|
||||
self.compare.release(*at) if at is not None else self.compare.release()
|
||||
self._menu_move = None
|
||||
self.menu.release()
|
||||
return
|
||||
@@ -1154,8 +1155,31 @@ class GLWindowSink:
|
||||
self.dx.present(self.settings.vsync, tear=self._may_tear())
|
||||
_say_if_slow("DXGI Present", t0)
|
||||
else:
|
||||
self._dev_shot()
|
||||
self.glfw.swap_buffers(self.win)
|
||||
|
||||
def _dev_shot(self) -> None:
|
||||
"""For screenshots (devtools): with SUMMIT_SHOT=<prefix> set, a file <prefix>.req holding a name makes this
|
||||
frame, exactly as about to be shown, go to <prefix>-<name>.png (then the .req file is removed)."""
|
||||
prefix = os.environ.get("SUMMIT_SHOT")
|
||||
if not prefix or not os.path.exists(prefix + ".req"):
|
||||
return
|
||||
try:
|
||||
with open(prefix + ".req", encoding="utf-8") as f:
|
||||
name = f.read().strip() or "shot"
|
||||
GL = self.GL
|
||||
fw, fh = self.glfw.get_framebuffer_size(self.win)
|
||||
GL.glBindFramebuffer(GL.GL_READ_FRAMEBUFFER, 0)
|
||||
GL.glReadBuffer(GL.GL_BACK)
|
||||
GL.glPixelStorei(GL.GL_PACK_ALIGNMENT, 1)
|
||||
data = GL.glReadPixels(0, 0, fw, fh, GL.GL_BGR, GL.GL_UNSIGNED_BYTE)
|
||||
img = np.frombuffer(data, np.uint8).reshape(fh, fw, 3)[::-1]
|
||||
cv2.imwrite(f"{prefix}-{name}.png", img)
|
||||
os.remove(prefix + ".req")
|
||||
except Exception as e: # noqa: BLE001 - a devtool: never in the way of the picture
|
||||
print(f"[display] SUMMIT_SHOT failed: {e}")
|
||||
os.environ.pop("SUMMIT_SHOT", None)
|
||||
|
||||
# ---- settings ------------------------------------------------------------
|
||||
def allowed(self, key: str, value) -> bool:
|
||||
if key == "scaler":
|
||||
|
||||
@@ -146,6 +146,13 @@ def test_the_mouse_picks_pans_and_zooms():
|
||||
assert live.plan().picking
|
||||
|
||||
|
||||
def test_a_drag_whose_moves_were_missed_is_still_a_drag():
|
||||
st, live = live_with(compare_layout="grid", compare_cell="1", compare_zoom=2)
|
||||
live.press(400, 300, 1920, 1080)
|
||||
live.release(100, 200, 1920, 1080) # (the window saw no motion in between)
|
||||
assert st.compare_cell == "free" and live.plan().area.cx > 0.25
|
||||
|
||||
|
||||
def test_the_inset_map_moves_the_box():
|
||||
st, live = live_with(compare_layout="grid", compare_cell="1", compare_zoom=4)
|
||||
ix0, iy0, ix1, iy1 = C.inset_rect(1920, 1080)
|
||||
|
||||
Reference in new issue
Block a user