McRogueFace/tests/unit/screenshot_transparency_fix_test.py
John McCardle 9f481a2e4a fix: Update test files to use current API patterns
Migrates test suite to current API:
- Frame(x, y, w, h) → Frame(pos=(x, y), size=(w, h))
- Caption("text", x, y) → Caption(pos=(x, y), text="text")
- caption.size → caption.font_size
- Entity(x, y, ...) → Entity((x, y), ...)
- Grid(w, h, ...) → Grid(grid_size=(w, h), ...)
- cell.color → ColorLayer system

Tests now serve as valid API usage examples.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-29 19:47:48 -05:00

77 lines
No EOL
2.9 KiB
Python

#!/usr/bin/env python3
"""Test and workaround for transparent screenshot issue"""
import mcrfpy
from mcrfpy import automation
from datetime import datetime
import sys
def test_transparency_workaround():
"""Create a full-window opaque background to fix transparency"""
print("=== Screenshot Transparency Fix Test ===\n")
# Create a scene
mcrfpy.createScene("opaque_test")
mcrfpy.setScene("opaque_test")
ui = mcrfpy.sceneUI("opaque_test")
# WORKAROUND: Create a full-window opaque frame as the first element
# This acts as an opaque background since the scene clears with transparent
print("Creating full-window opaque background...")
background = mcrfpy.Frame(pos=(0, 0), size=(1024, 768),
fill_color=mcrfpy.Color(50, 50, 50), # Dark gray
outline_color=None,
outline=0.0)
ui.append(background)
print("✓ Added opaque background frame")
# Now add normal content on top
print("\nAdding test content...")
# Red frame
frame1 = mcrfpy.Frame(pos=(100, 100), size=(200, 150),
fill_color=mcrfpy.Color(255, 0, 0),
outline_color=mcrfpy.Color(255, 255, 255),
outline=3.0)
ui.append(frame1)
# Green frame
frame2 = mcrfpy.Frame(pos=(350, 100), size=(200, 150),
fill_color=mcrfpy.Color(0, 255, 0),
outline_color=mcrfpy.Color(0, 0, 0),
outline=3.0)
ui.append(frame2)
# Blue frame
frame3 = mcrfpy.Frame(pos=(100, 300), size=(200, 150),
fill_color=mcrfpy.Color(0, 0, 255),
outline_color=mcrfpy.Color(255, 255, 0),
outline=3.0)
ui.append(frame3)
# Add text
caption = mcrfpy.Caption(pos=(250, 50),
text="OPAQUE BACKGROUND TEST",
fill_color=mcrfpy.Color(255, 255, 255))
caption.font_size = 32
ui.append(caption)
# Take screenshot
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
filename = f"screenshot_opaque_fix_{timestamp}.png"
result = automation.screenshot(filename)
print(f"\nScreenshot taken: {filename}")
print(f"Result: {result}")
print("\n=== Analysis ===")
print("The issue is that PyScene::render() calls clear() without a color parameter.")
print("SFML's default clear color is transparent black (0,0,0,0).")
print("In windowed mode, the window provides an opaque background.")
print("In headless mode, the RenderTexture preserves the transparency.")
print("\nWORKAROUND: Always add a full-window opaque Frame as the first UI element.")
print("FIX: Modify PyScene.cpp and UITestScene.cpp to use clear(sf::Color::Black)")
sys.exit(0)
# Run immediately
test_transparency_workaround()