Skip to content
Snippets Groups Projects
Commit 97cb5b5b authored by pippin's avatar pippin
Browse files

py: add fps overlay mode

parent eec9a27d
Branches
No related tags found
No related merge requests found
...@@ -376,6 +376,7 @@ class SettingsMenu(SimpleMenu): ...@@ -376,6 +376,7 @@ class SettingsMenu(SimpleMenu):
# Actual tunables / settings. # Actual tunables / settings.
onoff_button_swap = OnOffTunable("Swap Buttons", "system.swap_buttons", False) onoff_button_swap = OnOffTunable("Swap Buttons", "system.swap_buttons", False)
onoff_show_fps = OnOffTunable("Show FPS", "system.show_fps", False)
onoff_debug = OnOffTunable("Debug Overlay", "system.debug", False) onoff_debug = OnOffTunable("Debug Overlay", "system.debug", False)
onoff_debug_touch = OnOffTunable("Touch Overlay", "system.debug_touch", False) onoff_debug_touch = OnOffTunable("Touch Overlay", "system.debug_touch", False)
onoff_show_tray = OnOffTunable("Show Icons", "system.show_icons", True) onoff_show_tray = OnOffTunable("Show Icons", "system.show_icons", True)
...@@ -395,6 +396,7 @@ load_save_settings: List[UnaryTunable] = [ ...@@ -395,6 +396,7 @@ load_save_settings: List[UnaryTunable] = [
onoff_debug_touch, onoff_debug_touch,
onoff_wifi, onoff_wifi,
onoff_wifi_preference, onoff_wifi_preference,
onoff_show_fps,
str_wifi_ssid, str_wifi_ssid,
str_wifi_psk, str_wifi_psk,
str_hostname, str_hostname,
...@@ -408,8 +410,9 @@ if TYPE_CHECKING: ...@@ -408,8 +410,9 @@ if TYPE_CHECKING:
settings_menu_structure: "MenuStructure" = [ settings_menu_structure: "MenuStructure" = [
onoff_show_tray, onoff_show_tray,
onoff_button_swap, onoff_button_swap,
onoff_debug, onoff_show_fps,
onoff_debug_touch, # onoff_debug,
# onoff_debug_touch,
onoff_wifi, onoff_wifi,
onoff_wifi_preference, onoff_wifi_preference,
MenuItemAppLaunch(BundleMetadata("/flash/sys/apps/w1f1")), MenuItemAppLaunch(BundleMetadata("/flash/sys/apps/w1f1")),
......
...@@ -6,7 +6,7 @@ for persistent, anchored symbols like charging symbols, toasts, debug overlays, ...@@ -6,7 +6,7 @@ for persistent, anchored symbols like charging symbols, toasts, debug overlays,
etc. etc.
""" """
from st3m import Responder, InputState, Reactor from st3m import Responder, InputState, Reactor, settings
from st3m.goose import Dict, Enum, List, ABCBase, abstractmethod, Optional from st3m.goose import Dict, Enum, List, ABCBase, abstractmethod, Optional
from st3m.utils import tau from st3m.utils import tau
from st3m.ui.view import ViewManager from st3m.ui.view import ViewManager
...@@ -38,7 +38,10 @@ _all_kinds = [ ...@@ -38,7 +38,10 @@ _all_kinds = [
OverlayKind.Toast, OverlayKind.Toast,
] ]
_max_y = 0 _clip_x0 = 120
_clip_x1 = 120
_clip_y0 = 0
_clip_y1 = 0
class Overlay(Responder): class Overlay(Responder):
...@@ -79,15 +82,44 @@ class Compositor(Responder): ...@@ -79,15 +82,44 @@ class Compositor(Responder):
def think(self, ins: InputState, delta_ms: int) -> None: def think(self, ins: InputState, delta_ms: int) -> None:
self.main.think(ins, delta_ms) self.main.think(ins, delta_ms)
if self._frame_skip <= 0: if self._frame_skip <= 0:
if not settings.onoff_show_fps.value:
for overlay in self._enabled_overlays(): for overlay in self._enabled_overlays():
overlay.think(ins, delta_ms) overlay.think(ins, delta_ms)
def draw(self, ctx: Context) -> None: def draw(self, ctx: Context) -> None:
global _max_y global _clip_x0
global _clip_y0
global _clip_x1
global _clip_y1
self.main.draw(ctx) self.main.draw(ctx)
if self._frame_skip <= 0: if self._frame_skip <= 0:
_max_y = 0
octx = sys_display.get_overlay_ctx() octx = sys_display.get_overlay_ctx()
if settings.onoff_show_fps.value:
_clip_x0 = 110
_clip_y1 = 0
_clip_x1 = 130
_clip_y1 = 7
octx.save()
octx.compositing_mode = octx.CLEAR
octx.rectangle(
_clip_x0 - 120,
_clip_y0 - 120,
_clip_x1 - _clip_x0 + 1,
_clip_y1 - _clip_y0 + 1,
).fill()
octx.restore()
octx.gray(1)
octx.font_size = 11
octx.font = "Bold"
octx.move_to(0, -113)
octx.text_align = octx.CENTER
octx.text("{0:.1f}".format(sys_display.fps()))
else:
_clip_x0 = 80
_clip_y0 = 0
_clip_x1 = 160
_clip_y1 = 0
octx.save() octx.save()
octx.compositing_mode = octx.CLEAR octx.compositing_mode = octx.CLEAR
octx.rectangle(-120, -120, 240, 240).fill() octx.rectangle(-120, -120, 240, 240).fill()
...@@ -95,7 +127,7 @@ class Compositor(Responder): ...@@ -95,7 +127,7 @@ class Compositor(Responder):
for overlay in self._enabled_overlays(): for overlay in self._enabled_overlays():
overlay.draw(octx) overlay.draw(octx)
self._frame_skip = 8 self._frame_skip = 8
sys_display.set_overlay_height(_max_y) sys_display.overlay_clip(_clip_x0, _clip_y0, _clip_x1, _clip_y1)
self._frame_skip -= 1 self._frame_skip -= 1
def add_overlay(self, ov: Overlay) -> None: def add_overlay(self, ov: Overlay) -> None:
...@@ -293,10 +325,10 @@ class OverlayVolume(Overlay): ...@@ -293,10 +325,10 @@ class OverlayVolume(Overlay):
self._showing = None self._showing = None
def draw(self, ctx: Context) -> None: def draw(self, ctx: Context) -> None:
global _max_y global _clip_y1
if self._showing is None: if self._showing is None:
return return
_max_y = max(_max_y, 160) _clip_y1 = max(_clip_y1, 161)
opacity = self._showing / 200 opacity = self._showing / 200
opacity = min(opacity, 0.8) opacity = min(opacity, 0.8)
...@@ -485,10 +517,10 @@ class IconTray(Overlay): ...@@ -485,10 +517,10 @@ class IconTray(Overlay):
v.think(ins, delta_ms) v.think(ins, delta_ms)
def draw(self, ctx: Context) -> None: def draw(self, ctx: Context) -> None:
global _max_y global _clip_y1
if len(self.visible) < 1: if len(self.visible) < 1:
return return
_max_y = max(_max_y, 32) _clip_y1 = max(_clip_y1, 32)
width = 0 width = 0
for icon in self.visible: for icon in self.visible:
width += icon.WIDTH width += icon.WIDTH
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment