implements PLN-0081 shell hub packet migration
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
use crate::{CrashReport, SystemOS};
|
||||
use prometeu_hal::color::Color;
|
||||
use prometeu_hal::gfx_bridge::GfxBridge;
|
||||
use prometeu_hal::primitives::Rect;
|
||||
use prometeu_hal::{HardwareBridge, InputSignals};
|
||||
use prometeu_hal::{GfxUiCommand, HardwareBridge, InputSignals, ShellUiFramePacket};
|
||||
use prometeu_vm::VirtualMachine;
|
||||
|
||||
const SHELL_A_BUTTON: Rect = Rect { x: 112, y: 108, w: 112, h: 48 };
|
||||
@@ -101,8 +100,6 @@ impl PrometeuHub {
|
||||
os: &mut SystemOS,
|
||||
hw: &mut dyn HardwareBridge,
|
||||
) -> Option<SystemProfileAction> {
|
||||
hw.gfx_mut().clear(Color::INDIGO);
|
||||
|
||||
let in_shell = os.windows().focused_window().is_some();
|
||||
|
||||
if !in_shell {
|
||||
@@ -127,21 +124,23 @@ impl PrometeuHub {
|
||||
let pointer_x = hw.touch().x();
|
||||
let pointer_y = hw.touch().y();
|
||||
|
||||
if os.windows().window_count() == 0 {
|
||||
render_home(hw.gfx_mut(), pointer_x, pointer_y);
|
||||
return;
|
||||
}
|
||||
|
||||
for window in os.windows().windows() {
|
||||
render_shell_window(
|
||||
hw.gfx_mut(),
|
||||
window.viewport,
|
||||
window.color,
|
||||
&window.title,
|
||||
pointer_x,
|
||||
pointer_y,
|
||||
);
|
||||
}
|
||||
let packet = if os.windows().window_count() == 0 {
|
||||
render_home_packet(pointer_x, pointer_y)
|
||||
} else {
|
||||
let mut commands = Vec::new();
|
||||
for window in os.windows().windows() {
|
||||
append_shell_window_commands(
|
||||
&mut commands,
|
||||
window.viewport,
|
||||
window.color,
|
||||
&window.title,
|
||||
pointer_x,
|
||||
pointer_y,
|
||||
);
|
||||
}
|
||||
ShellUiFramePacket::new(commands)
|
||||
};
|
||||
hw.render_shell_ui_packet(&packet);
|
||||
}
|
||||
|
||||
pub fn update_shell_profile(
|
||||
@@ -163,7 +162,7 @@ impl PrometeuHub {
|
||||
}
|
||||
|
||||
self.render(os, hw);
|
||||
hw.gfx_mut().present();
|
||||
hw.present();
|
||||
|
||||
SystemProfileUpdate { crash, action }
|
||||
}
|
||||
@@ -192,15 +191,29 @@ fn activation_input_down(hw: &dyn HardwareBridge) -> bool {
|
||||
hw.touch().f().down || hw.pad().a().down || hw.pad().b().down || hw.pad().start().down
|
||||
}
|
||||
|
||||
fn render_home(gfx: &mut dyn GfxBridge, pointer_x: i32, pointer_y: i32) {
|
||||
gfx.fill_rect(VIEWPORT.x, VIEWPORT.y, VIEWPORT.w, VIEWPORT.h, COLOR_BG);
|
||||
draw_panel(gfx, TITLE_PANEL, COLOR_PANEL_DARK, COLOR_BORDER);
|
||||
draw_buffer_text(gfx, TITLE_PANEL.x + 58, TITLE_PANEL.y + 9, "PROMETEU HUB", COLOR_TEXT);
|
||||
|
||||
draw_panel(gfx, HOME_PANEL, COLOR_PANEL, COLOR_BORDER);
|
||||
draw_buffer_text(gfx, HOME_PANEL.x + 26, HOME_PANEL.y + 22, "Native Shell Apps", COLOR_TEXT);
|
||||
fn render_home_packet(pointer_x: i32, pointer_y: i32) -> ShellUiFramePacket {
|
||||
let mut commands = Vec::new();
|
||||
commands.push(GfxUiCommand::Clear { color: COLOR_BG });
|
||||
fill_rect(&mut commands, VIEWPORT, COLOR_BG);
|
||||
draw_panel(&mut commands, TITLE_PANEL, COLOR_PANEL_DARK, COLOR_BORDER);
|
||||
draw_buffer_text(
|
||||
gfx,
|
||||
&mut commands,
|
||||
TITLE_PANEL.x + 58,
|
||||
TITLE_PANEL.y + 9,
|
||||
"PROMETEU HUB",
|
||||
COLOR_TEXT,
|
||||
);
|
||||
|
||||
draw_panel(&mut commands, HOME_PANEL, COLOR_PANEL, COLOR_BORDER);
|
||||
draw_buffer_text(
|
||||
&mut commands,
|
||||
HOME_PANEL.x + 26,
|
||||
HOME_PANEL.y + 22,
|
||||
"Native Shell Apps",
|
||||
COLOR_TEXT,
|
||||
);
|
||||
draw_buffer_text(
|
||||
&mut commands,
|
||||
HOME_PANEL.x + 26,
|
||||
HOME_PANEL.y + 40,
|
||||
"first retro ui slice",
|
||||
@@ -209,50 +222,105 @@ fn render_home(gfx: &mut dyn GfxBridge, pointer_x: i32, pointer_y: i32) {
|
||||
|
||||
for button in HOME_BUTTONS {
|
||||
let hovered = rect_contains(button.rect, pointer_x, pointer_y);
|
||||
draw_button(gfx, button.rect, button.label, hovered);
|
||||
draw_button(&mut commands, button.rect, button.label, hovered);
|
||||
}
|
||||
|
||||
ShellUiFramePacket::new(commands)
|
||||
}
|
||||
|
||||
fn render_shell_window(
|
||||
gfx: &mut dyn GfxBridge,
|
||||
fn append_shell_window_commands(
|
||||
commands: &mut Vec<GfxUiCommand>,
|
||||
viewport: Rect,
|
||||
color: Color,
|
||||
title: &str,
|
||||
pointer_x: i32,
|
||||
pointer_y: i32,
|
||||
) {
|
||||
gfx.fill_rect(VIEWPORT.x, VIEWPORT.y, VIEWPORT.w, VIEWPORT.h, COLOR_BG);
|
||||
draw_panel(gfx, viewport, COLOR_PANEL_DARK, COLOR_BORDER);
|
||||
gfx.fill_rect(viewport.x + 4, viewport.y + 24, viewport.w - 8, viewport.h - 28, color);
|
||||
draw_buffer_text(gfx, viewport.x + 10, viewport.y + 8, title, COLOR_TEXT);
|
||||
draw_buffer_text(gfx, viewport.x + 18, viewport.y + 44, "native fake shell", COLOR_PANEL_DARK);
|
||||
fill_rect(commands, VIEWPORT, COLOR_BG);
|
||||
draw_panel(commands, viewport, COLOR_PANEL_DARK, COLOR_BORDER);
|
||||
fill_rect(
|
||||
commands,
|
||||
Rect { x: viewport.x + 4, y: viewport.y + 24, w: viewport.w - 8, h: viewport.h - 28 },
|
||||
color,
|
||||
);
|
||||
draw_buffer_text(commands, viewport.x + 10, viewport.y + 8, title, COLOR_TEXT);
|
||||
draw_buffer_text(
|
||||
commands,
|
||||
viewport.x + 18,
|
||||
viewport.y + 44,
|
||||
"native fake shell",
|
||||
COLOR_PANEL_DARK,
|
||||
);
|
||||
|
||||
let close_hovered = rect_contains(CLOSE_BUTTON, pointer_x, pointer_y);
|
||||
let close_fill = if close_hovered { COLOR_HILITE } else { COLOR_BUTTON };
|
||||
gfx.fill_rect(CLOSE_BUTTON.x, CLOSE_BUTTON.y, CLOSE_BUTTON.w, CLOSE_BUTTON.h, close_fill);
|
||||
gfx.draw_rect(CLOSE_BUTTON.x, CLOSE_BUTTON.y, CLOSE_BUTTON.w, CLOSE_BUTTON.h, COLOR_BORDER);
|
||||
draw_buffer_text(gfx, CLOSE_BUTTON.x + 5, CLOSE_BUTTON.y + 4, "x", COLOR_TEXT);
|
||||
fill_rect(commands, CLOSE_BUTTON, close_fill);
|
||||
draw_rect(commands, CLOSE_BUTTON, COLOR_BORDER);
|
||||
draw_buffer_text(commands, CLOSE_BUTTON.x + 5, CLOSE_BUTTON.y + 4, "x", COLOR_TEXT);
|
||||
}
|
||||
|
||||
fn draw_panel(gfx: &mut dyn GfxBridge, rect: Rect, fill: Color, border: Color) {
|
||||
gfx.fill_rect(rect.x, rect.y, rect.w, rect.h, fill);
|
||||
gfx.draw_rect(rect.x, rect.y, rect.w, rect.h, border);
|
||||
gfx.draw_rect(rect.x + 2, rect.y + 2, rect.w - 4, rect.h - 4, COLOR_MUTED);
|
||||
fn fill_rect(commands: &mut Vec<GfxUiCommand>, rect: Rect, color: Color) {
|
||||
commands.push(GfxUiCommand::FillRect { rect, color });
|
||||
}
|
||||
|
||||
fn draw_button(gfx: &mut dyn GfxBridge, rect: Rect, label: &str, hovered: bool) {
|
||||
fn draw_rect(commands: &mut Vec<GfxUiCommand>, rect: Rect, color: Color) {
|
||||
commands.push(GfxUiCommand::DrawLine {
|
||||
x0: rect.x,
|
||||
y0: rect.y,
|
||||
x1: rect.x + rect.w - 1,
|
||||
y1: rect.y,
|
||||
color,
|
||||
});
|
||||
commands.push(GfxUiCommand::DrawLine {
|
||||
x0: rect.x,
|
||||
y0: rect.y + rect.h - 1,
|
||||
x1: rect.x + rect.w - 1,
|
||||
y1: rect.y + rect.h - 1,
|
||||
color,
|
||||
});
|
||||
commands.push(GfxUiCommand::DrawLine {
|
||||
x0: rect.x,
|
||||
y0: rect.y,
|
||||
x1: rect.x,
|
||||
y1: rect.y + rect.h - 1,
|
||||
color,
|
||||
});
|
||||
commands.push(GfxUiCommand::DrawLine {
|
||||
x0: rect.x + rect.w - 1,
|
||||
y0: rect.y,
|
||||
x1: rect.x + rect.w - 1,
|
||||
y1: rect.y + rect.h - 1,
|
||||
color,
|
||||
});
|
||||
}
|
||||
|
||||
fn draw_panel(commands: &mut Vec<GfxUiCommand>, rect: Rect, fill: Color, border: Color) {
|
||||
fill_rect(commands, rect, fill);
|
||||
draw_rect(commands, rect, border);
|
||||
draw_rect(
|
||||
commands,
|
||||
Rect { x: rect.x + 2, y: rect.y + 2, w: rect.w - 4, h: rect.h - 4 },
|
||||
COLOR_MUTED,
|
||||
);
|
||||
}
|
||||
|
||||
fn draw_button(commands: &mut Vec<GfxUiCommand>, rect: Rect, label: &str, hovered: bool) {
|
||||
let fill = if hovered { COLOR_BUTTON_ACTIVE } else { COLOR_BUTTON };
|
||||
let border = if hovered { COLOR_HILITE } else { COLOR_BORDER };
|
||||
gfx.fill_rect(rect.x, rect.y, rect.w, rect.h, fill);
|
||||
gfx.draw_rect(rect.x, rect.y, rect.w, rect.h, border);
|
||||
gfx.draw_rect(rect.x + 3, rect.y + 3, rect.w - 6, rect.h - 6, COLOR_MUTED);
|
||||
gfx.fill_rect(rect.x + 12, rect.y + 12, 16, 24, border);
|
||||
gfx.draw_rect(rect.x + 34, rect.y + 12, 62, 24, COLOR_PANEL_DARK);
|
||||
draw_buffer_text(gfx, rect.x + 40, rect.y + 21, label, COLOR_TEXT);
|
||||
fill_rect(commands, rect, fill);
|
||||
draw_rect(commands, rect, border);
|
||||
draw_rect(
|
||||
commands,
|
||||
Rect { x: rect.x + 3, y: rect.y + 3, w: rect.w - 6, h: rect.h - 6 },
|
||||
COLOR_MUTED,
|
||||
);
|
||||
fill_rect(commands, Rect { x: rect.x + 12, y: rect.y + 12, w: 16, h: 24 }, border);
|
||||
draw_rect(commands, Rect { x: rect.x + 34, y: rect.y + 12, w: 62, h: 24 }, COLOR_PANEL_DARK);
|
||||
draw_buffer_text(commands, rect.x + 40, rect.y + 21, label, COLOR_TEXT);
|
||||
}
|
||||
|
||||
fn draw_buffer_text(gfx: &mut dyn GfxBridge, x: i32, y: i32, text: &str, color: Color) {
|
||||
gfx.draw_text(x, y, text, color);
|
||||
fn draw_buffer_text(commands: &mut Vec<GfxUiCommand>, x: i32, y: i32, text: &str, color: Color) {
|
||||
commands.push(GfxUiCommand::DrawText { x, y, text: text.to_string(), color });
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -321,6 +389,16 @@ mod tests {
|
||||
assert_eq!(HOME_BUTTONS[1].app, NativeShellApp::ShellB);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn home_render_produces_shell_ui_packet_commands() {
|
||||
let packet = render_home_packet(SHELL_A_BUTTON.x, SHELL_A_BUTTON.y);
|
||||
|
||||
assert!(matches!(packet.commands.first(), Some(GfxUiCommand::Clear { .. })));
|
||||
assert!(packet.commands.iter().any(|command| {
|
||||
matches!(command, GfxUiCommand::DrawText { text, .. } if text == "PROMETEU HUB")
|
||||
}));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shell_close_button_sits_inside_shell_frame() {
|
||||
assert!(rect_contains(SHELL_FRAME, CLOSE_BUTTON.x, CLOSE_BUTTON.y));
|
||||
|
||||
Reference in New Issue
Block a user