Switch knob: scanline model from 42 measured sizes
Integer radius (h-1)//2 with fixed sub-pixel offsets, 4 sub-rows x 1/8 px spans, 1/32 coverage in linear light; closer to the simulator than the previous distance model on the knob test page. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0138a0ba56
commit
922ca21f0f
3 files changed
+35
-4
No files matched your search
+1
-1
@@ -94,7 +94,7 @@ byte for byte, or a file written by nxhmi was opened in the Editor and showed th
|
|||||||
| Item | Notes |
|
| Item | Notes |
|
||||||
|---|---|
|
|---|---|
|
||||||
| Other display series | Discovery / Enhanced / Edge not sampled; only Basic + Intelligent templates |
|
| Other display series | Discovery / Enhanced / Edge not sampled; only Basic + Intelligent templates |
|
||||||
| Display direction | byte 12 decoded and written (`new_project(portrait=...)`); picture order verified for all four (format 4); font glyph order for 90° only |
|
| Display direction | byte 12 decoded and written (`new_project(portrait=...)`); picture order verified for all four (format 4); font glyph order verified for 0° and 90° |
|
||||||
| Some header fields | main.HMI bytes 8, 13, 36, 0x41; page header 21/23; entry bytes 25-27 |
|
| Some header fields | main.HMI bytes 8, 13, 36, 0x41; page header 21/23; entry bytes 25-27 |
|
||||||
| Font name shown in the Editor's Fonts panel | cosmetic, generated fonts show an odd label |
|
| Font name shown in the Editor's Fonts panel | cosmetic, generated fonts show an odd label |
|
||||||
| Media resources | video / audio / Gmov files themselves (not just the components) |
|
| Media resources | video / audio / Gmov files themselves (not just the components) |
|
||||||
|
|||||||
+6
-1
@@ -47,7 +47,7 @@ TextSelects, several of each other type):
|
|||||||
| FileBrowser | 100 % | frame and fill; the file list only exists at run time |
|
| FileBrowser | 100 % | frame and fill; the file list only exists at run time |
|
||||||
| ExPicture, video, audio, Gmov, FileStream | nothing drawn (same as the simulator) | they show content only once a file is loaded |
|
| ExPicture, video, audio, Gmov, FileStream | nothing drawn (same as the simulator) | they show content only once a file is loaded |
|
||||||
| ComboBox | ~99 % | structure exact; anti-aliased corners and arrow approximate |
|
| ComboBox | ~99 % | structure exact; anti-aliased corners and arrow approximate |
|
||||||
| Switch | ~88-97 % | structure exact; anti-aliased knob and track edges approximate |
|
| Switch | ~88-97 % | structure exact; anti-aliased knob and track edges approximate (see below) |
|
||||||
|
|
||||||
## Rules learned from the Editor
|
## Rules learned from the Editor
|
||||||
|
|
||||||
@@ -70,6 +70,11 @@ TextSelects, several of each other type):
|
|||||||
`[h, w)` (off) or `[0, w-h)` (on). ComboBox: text placed by `xcen`/`ycen` over the whole box,
|
`[h, w)` (off) or `[0, w-h)` (on). ComboBox: text placed by `xcen`/`ycen` over the whole box,
|
||||||
`pco3` arrow `wid` px wide 4.5 px from the right edge. Corner radius for both: `dis * h // 200`,
|
`pco3` arrow `wid` px wide 4.5 px from the right edge. Corner radius for both: `dis * h // 200`,
|
||||||
square below 3 px; rounded shapes are inset half a pixel (outer ring 50 %, blended linearly).
|
square below 3 px; rounded shapes are inset half a pixel (outer ring 50 %, blended linearly).
|
||||||
|
- Switch knob (measured on 42 sizes): radius `r = (h-1)//2` with fixed sub-pixel offsets, edge
|
||||||
|
coverage in steps of exactly 1/32 blended in linear light; the top row always holds a single
|
||||||
|
1/4-row span, so it is a scanline rasteriser (4 sub-rows x 1/8 px). The best model found
|
||||||
|
(centre `r + 0.625, r + 0.25`, radius `r - 0.25`, span ends rounded to 1/8) gets most edge pixels
|
||||||
|
exact but the span widths curve more sharply than a circle, so the real routine is still open.
|
||||||
- Intelligent pictures with alpha (format 4, 7-bit alpha `a`): 8-bit alpha is `2*a` (127 = 255),
|
- Intelligent pictures with alpha (format 4, 7-bit alpha `a`): 8-bit alpha is `2*a` (127 = 255),
|
||||||
blended as `bg + round((src - bg) * alpha / 255)` per channel. Exact against the Intelligent
|
blended as `bg + round((src - bg) * alpha / 255)` per channel. Exact against the Intelligent
|
||||||
simulator (342 samples). The Editor *canvas* blends slightly differently (up to 3 levels off at
|
simulator (342 samples). The Editor *canvas* blends slightly differently (up to 3 levels off at
|
||||||
|
|||||||
+28
-2
@@ -624,6 +624,31 @@ class Renderer:
|
|||||||
self._aa_fill(img, (int(cx - r) - 1, int(cy - r) - 1, int(cx + r) + 2, int(cy + r) + 2), col,
|
self._aa_fill(img, (int(cx - r) - 1, int(cy - r) - 1, int(cx + r) + 2, int(cy + r) + 2), col,
|
||||||
lambda px, py: math.hypot(px - cx, py - cy) - r, gamma=True)
|
lambda px, py: math.hypot(px - cx, py - cy) - r, gamma=True)
|
||||||
|
|
||||||
|
def _scan_disc(self, img, cx, cy, R, col):
|
||||||
|
"""Filled circle the way the Intelligent simulator's switch knob looks: 4 sub-rows per pixel
|
||||||
|
row, each a span with ends rounded to 1/8 px, so coverage comes in steps of 1/32, blended
|
||||||
|
in linear light. Closest model found (most edge pixels exact, the rest a few levels off)."""
|
||||||
|
px = img.load()
|
||||||
|
W, H = img.size
|
||||||
|
for yy in range(max(0, int(cy - R) - 1), min(H, int(cy + R) + 2)):
|
||||||
|
cov = {}
|
||||||
|
for j in range(4):
|
||||||
|
d = R * R - (yy + j / 4 - cy) ** 2
|
||||||
|
if d <= 0:
|
||||||
|
continue
|
||||||
|
hw = math.sqrt(d)
|
||||||
|
l, r = round((cx - hw) * 8) / 8, round((cx + hw) * 8) / 8
|
||||||
|
for xx in range(int(math.floor(l)), int(math.ceil(r))):
|
||||||
|
o = min(xx + 1, r) - max(xx, l)
|
||||||
|
if o > 0:
|
||||||
|
cov[xx] = cov.get(xx, 0) + round(o * 8)
|
||||||
|
for xx, k in cov.items():
|
||||||
|
if 0 <= xx < W:
|
||||||
|
if k >= 32:
|
||||||
|
px[xx, yy] = col
|
||||||
|
else:
|
||||||
|
px[xx, yy] = tuple(_enc(_lin(f) * k / 32 + _lin(b) * (1 - k / 32)) for f, b in zip(col, px[xx, yy][:3]))
|
||||||
|
|
||||||
def switch(self, img, c):
|
def switch(self, img, c):
|
||||||
"""Switch: rounded track (corner radius dis % of h/2) in bco / bco2 (on), knob pco / pco2
|
"""Switch: rounded track (corner radius dis % of h/2) in bco / bco2 (on), knob pco / pco2
|
||||||
on the left (off) or right (on), text (txt "off/on") in pco1 centred on the free side."""
|
on the left (off) or right (on), text (txt "off/on") in pco1 centred on the free side."""
|
||||||
@@ -631,8 +656,9 @@ class Renderer:
|
|||||||
on = bool(c.get("val"))
|
on = bool(c.get("val"))
|
||||||
r = _radius(c, h)
|
r = _radius(c, h)
|
||||||
self._round_rect(img, x, y, w, h, r, self.rgb((c.get("bco2") if on else c.get("bco")) or 0))
|
self._round_rect(img, x, y, w, h, r, self.rgb((c.get("bco2") if on else c.get("bco")) or 0))
|
||||||
kx = x + (w - h / 2 + 0.5625 if on else h / 2 - 0.4375)
|
r = (h - 1) // 2 # knob: integer radius, fixed sub-pixel offsets
|
||||||
self._disc(img, kx, y + h / 2 - 0.8125, h / 2 - 1.3125, self.rgb((c.get("pco2") if on else c.get("pco")) or 0))
|
kx = x + (w - r - 0.625 if on else r + 0.625)
|
||||||
|
self._scan_disc(img, kx, y + r + 0.25, r - 0.25, self.rgb((c.get("pco2") if on else c.get("pco")) or 0))
|
||||||
parts = (c.get("txt") or "").split("/")
|
parts = (c.get("txt") or "").split("/")
|
||||||
label = (parts[1] if len(parts) > 1 else "") if on else parts[0]
|
label = (parts[1] if len(parts) > 1 else "") if on else parts[0]
|
||||||
tx, tw = (x, w - h) if on else (x + h, w - h)
|
tx, tw = (x, w - h) if on else (x + h, w - h)
|
||||||
|
|||||||
Reference in new issue
Block a user