Files
RP412/MUNGA_L4/L4MFDVIEW.h
T
CydandClaude Fable 5 16ce4dfbea Exploded view remembers where you drag its windows
Ported from BT411's BT_GLASS_LAYOUT (29c502d).

The exploded view's panes are draggable desktop windows, but the
arrangement is recomputed on every launch, so dragging one somewhere
useful never survived the menu-race-menu loop.

RP412MFDLAYOUT persists it to mfd_layout.cfg beside bindings.txt:

  off / 0 / unset   computed arrangement only, no file (default)
  load / restore    restore saved positions at startup, never write
  save / adjust     restore, then rewrite on each finished drag
                    (WM_EXITSIZEMOVE) and on teardown

One "<title>=x,y,w,h" line per pane. Position is restored and the size
read and discarded: a pane's size follows its content and its button
banks, so letting an old size back in would misshape it after any
geometry change - and this port has changed that geometry twice already.

Load runs after the computed arrangement rather than instead of it, so a
pane the file does not mention simply keeps its computed spot. Only the
exploded view registers: the composited cockpit's panes are chrome-less
children with nothing to drag, so they have no position worth keeping.

RP412 needs no equivalent of BT411's "restored" flag. Its re-snap is
LayoutCockpit on WM_SIZE, which only runs in cockpit mode, so nothing
comes back later to overwrite a hand-placed window.

Verified by round trip: dragged Map to 777,333 in save mode, the file
took all six panes, and a fresh launch in load mode put it physically
back at 777,333. The harness also resized the window while moving it,
which incidentally proved the saved size really is ignored - the pane
came back correctly sized from a cfg that recorded 136x39.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-29 08:28:44 -05:00

197 lines
5.3 KiB
C++

#pragma once
#include "..\munga\style.h"
//########################################################################
//############################ MFDSplitView ##############################
//########################################################################
//
// One desktop window showing a single cockpit display, used by SVGA16's
// split mode (L4MFDSPLIT=1). The pod hardware packed the five monochrome
// MFDs into the color channels of two video outputs and mounted the map
// display rotated; on a desktop each display gets its own window instead.
//
// Each window also carries its display's physical button bank, exactly
// as mounted in the pod (geometry per vRIO's CockpitLayout):
// - MFDs: a 4x2 cluster - 4 red buttons above the glass, 4 below,
// RIO addresses descending from the cluster anchor (top-left = hi).
// - The map ("secondary screen"): 6 amber buttons down each side -
// Secondary 0x10-0x15 on the left, Screen 0x18-0x1D on the right
// (the remaining column addresses are Tesla relays, not buttons).
// Buttons light from the lamp state the game commands (via PadRIO) and
// press/release RIO units with the mouse.
//
// SVGA16 fills Pixels() (32bpp top-down, sourceWidth x sourceHeight as
// passed - already swapped by the caller for the rotated map) and calls
// Repaint(). Closing a view window just hides it.
//
class MFDSplitView
{
public:
enum ButtonStyle
{
NoButtons = 0,
MFDStrips, // 4 above + 4 below, addresses descend from anchorA
SideColumns // 6 per side; anchorA = left base, anchorB = right base
};
// With a parent, the view is created as a chrome-less child window
// inside the single cockpit window (x/y in parent client coords);
// without one it is its own draggable desktop window.
MFDSplitView(
const char *title,
int source_width,
int source_height,
int display_width,
int display_height,
int x,
int y,
ButtonStyle button_style = NoButtons,
int anchorA = 0,
int anchorB = 0,
void *parent = 0
);
int
ClientWidth() const
{ return clientWidth; }
int
ClientHeight() const
{ return clientHeight; }
// Move the pane (child mode: parent client coords). Panes overlap
// the viewscreen like the pod's bezels, so exact placement happens
// after construction from the measured client sizes.
void
SetPosition(int x, int y);
// Re-scale the glass (cockpit resized): the source buffer is
// unchanged, only the destination size and the button geometry
// derived from it.
void
Resize(int display_width, int display_height);
// Take the pane off screen. Used for the Winners Circle, which wants
// the whole viewscreen: the panes overlap it like the pod's bezels,
// so hiding them uncovers the full canvas underneath.
void
Hide();
// caption and HWND, for the sticky-placement file
const char *
Title() const
{ return paneTitle; }
void *
Window()
{ return window; }
~MFDSplitView();
Logical
TestInstance() const;
unsigned long *
Pixels()
{ return pixels; }
void
Repaint();
// Window-procedure callbacks (public for the registered WndProc)
void
Paint();
void
MouseDown(int x, int y);
void
MouseUp();
protected:
void
LayoutButtons(
ButtonStyle button_style,
int anchorA,
int anchorB,
int display_width,
int display_height,
int *client_width,
int *client_height
);
struct ScreenButton
{
int unit;
int x, y, w, h;
int amber; // 0 = red family, 1 = amber family
};
enum { maxButtons = 20 };
void
*window; // HWND
void
*blitHeader; // BITMAPINFOHEADER for StretchDIBits
unsigned long
*pixels;
int
sourceWidth,
sourceHeight;
int
displayX, displayY,
displayW, displayH;
int
clientWidth, clientHeight;
ScreenButton
buttons[maxButtons];
int
buttonCount;
int
pressedIndex;
// kept so the bank can be rebuilt when the cockpit re-scales
ButtonStyle
buttonStyle;
int
buttonAnchorA,
buttonAnchorB;
// the window caption, and the key this pane is saved under
const char
*paneTitle;
// True for a pane of its own on the desktop (the exploded view); the
// composited cockpit's panes are chrome-less children and cannot be
// dragged, so there is nothing to remember for them.
Logical
ownWindow;
};
//########################################################################
// Sticky window placement for the exploded view (L4MFDSPLIT=2).
//
// Those panes are draggable desktop windows, but the arrangement is
// recomputed on every launch, so dragging one somewhere useful never
// survived the menu-race-menu loop. RP412MFDLAYOUT persists it to
// mfd_layout.cfg beside bindings.txt:
//
// off / 0 / unset computed arrangement only, no file (default)
// load / restore restore saved positions at startup, never write
// save / adjust restore, then rewrite on each finished drag and
// on teardown - the round trip
//
// One "<title>=x,y,w,h" line per pane. Position is restored and size
// ignored: a pane's size follows its content and its button banks, so an
// old w,h from a different build must not distort it.
//
// Ported from BT411's BT_GLASS_LAYOUT.
//########################################################################
// Apply saved positions over the computed ones. Call after the panes are
// built and placed.
void
MFDSplitView_LoadLayout();
// Write every open pane's position. No-op unless the mode is save.
void
MFDSplitView_SaveLayout();