Touch Controller Internals¶
How a pad is stored, placed on a screen of any shape, drawn in its own touch windows, read as a device, and changed in Arrange.
For the user-facing side see Touch Controller.
| File | Responsibility |
|---|---|
PadForge.App/Services/TouchControllerData.cs |
TouchControllerData, the app-wide settings with their ranges and Normalize(), and TouchControllerPadData with its controls, the pads as PadForge.xml keeps them. The TouchControllerLabels and TouchControllerNewStick enums, saved by name. |
PadForge.App/ViewModels/DashboardViewModel.TouchController.cs |
The settings on the dashboard. EnableTouchController and TouchControllerPadId are the profile's, the rest app-wide. |
PadForge.App/ViewModels/TouchControllerPage.cs |
The page: the status line, the Pads card's rows and pictures, Pad Shown, New Pad, Duplicate, Rename, Remove and each card's Reset All. |
PadForge.App/Common/TouchController/TouchControllerPad.cs |
TouchControllerPad, TouchControllerControl and TouchControllerGrip, and TouchControllerPads, the store: one list under one lock, copies out, events raised outside the lock. |
PadForge.App/Common/TouchController/TouchControllerPadRules.cs |
What a pad holds: 64 controls, names and labels of 40 UTF-16 units cut at a whole character, each kind's slot range, and Clean(), which every save and load goes through. |
PadForge.App/Common/TouchController/TouchControllerStarters.cs |
The four starters, each with a 16:9 and a 9:16 arrangement, every control at least 8 units from the left and right edges. |
PadForge.App/Common/TouchController/PadPlacement.cs |
Where each control goes on a screen: sizes in units of the shorter side, clusters, edge distances, the shrink that fits, Adopt and AutoFit. |
PadForge.App/Common/TouchController/PadScene.cs |
A pad placed on a screen in pixels: each control's rectangle, hit shape and look, and the labels fitted to their controls. |
PadForge.App/Common/TouchController/PadRenderer.cs |
Draws a scene for the overlay, Arrange and the page's pictures. Inside each hit shape it keeps alpha of at least 1, and 0 elsewhere. |
PadForge.App/Common/TouchController/PadLabels.cs |
PadLabels (As Written, None, Follow Mapping) and PadMappingLabels, which reads the first Base row of the controller's mapping that reads each control. |
PadForge.App/Common/TouchController/PadGripMark.cs |
The grip's size and place in each arrangement. |
PadForge.App/Common/TouchController/TouchControllerPadSurface.cs |
The device's surface for a pad: the axes, buttons, hat and touchpad its controls provide. |
PadForge.Engine/Common/TouchControllerDevice.cs |
The device: one product and one instance for every pad, its state written copy-on-write from the touch thread. |
PadForge.App/Common/Input/InputManager.TouchController.cs |
Registers the device with each start of the engine and takes it offline. |
PadForge.App/Common/Input/InputManager.TouchControllerPress.cs |
Press Rumble's pulse, fired on the poll thread. |
PadForge.App/Services/TouchController/TouchControllerService.cs |
The state on the interface thread: on or off, which pad shows, hidden to the grip, arranging, the device's registration, and why nothing shows. |
PadForge.App/Services/TouchController/TouchControllerHosts.cs |
TouchControllerAbsence, TouchControllerStatus and the host interfaces the service drives. |
PadForge.App/Services/TouchController/Overlay/TouchControllerOverlay.cs |
The touch windows on their own thread: one window per cluster, the grip and its menu, fades, exclusive full screen, palms and the mouse. |
PadForge.App/Services/TouchController/Overlay/TouchPlay.cs |
Which touch holds which control, what each control sends, and how each is drawn. |
PadForge.App/Services/TouchController/Overlay/OverlayArt.cs |
Draws the grip and its menu. |
PadForge.App/Services/TouchController/Overlay/OverlayNative.cs |
The Win32 calls and values the touch windows use. |
PadForge.App/Services/TouchController/Overlay/TouchControllerPressFeedback.cs |
Press Sound and Press Rumble. |
PadForge.App/Services/TouchController/TouchControllerArrangeHost.cs |
Opens Arrange on the request's display, saves on Done through the store, and hands back nothing on Cancel. |
PadForge.App/Services/TouchController/TouchControllerArrangeSession.cs |
What a pointer and a key do in Arrange: pick, move, resize, Grid, Add, Remove, the choices, Auto-Fit. |
PadForge.App/Views/TouchControllerArrangeWindow.xaml(.cs) |
Arrange's surface and its panel. |
PadForge.App/Services/InputService.TouchController.cs |
Carries the three macro actions from the engine to the service each UI tick. |
PadForge.App/Views/ExtrasPage.xaml |
The page (TouchControllerPage) and its tile in the On Screen group. |
Storage¶
TouchControllerData is one element of the app settings in PadForge.xml, with the pads under Pads. Each pad keeps an id of 12 hex digits, which a profile names it by (TouchControllerPadId), its name, the shape of each arrangement's screen as width over height (Aspect, Aspect2), its controls and the grip's middle in each arrangement. A control keeps its kind (button, stick, slider, dpad or touch), its box as shares of each screen, its slot code, its label and its kind's choice: Shape (round, pill), StickMode (floating, fixed), DpadWays (8, 4) or TriggerStyle (slide, press). A choice left out plays as a pill, a fixed stick, an eight-way D-pad and a slide trigger.
TouchControllerPadRules.Clean() brings every pad inside the rules on a save and on a load, so a hand-edited pad lands where one made in Arrange would. A word it does not know drops one control or one choice, never the file. A pad with no control it keeps is left out. A loaded pad past 64 controls keeps its first 64, and a save past 64 is refused. A button may carry slots 0 to 21 except 16, the touch area's click. Add offers A through Misc 3, and a pad from the file keeps Misc 4 to Misc 6.
Placement¶
A screen's shorter side is 100 units, and every size is kept in those units, so a stick and a D-pad stay square on any screen. Controls no more than 5 units apart form a cluster. A cluster on the left keeps its distance from the left edge, one on the right from the right edge, and one within 5% of the board's width from the middle stays at the middle. Each keeps its distance from the bottom. Where two clusters would come within 2 units, or one would leave the screen, the whole pad is drawn smaller at the largest size that fits. Grid is 2 units. Arrange sizes a control no smaller than 6 units or 44 pixels, the larger (TouchControllerArrangeSession.LeastSide), and the store keeps any side down to 1 unit, two of the renderer's 0.5-unit strokes (TouchControllerPadRules.MinSideUnits). The 64-control limit is the 6-unit controls, each with its 3-unit hit margin all round, that fit 8 by 8 on a square screen.
A pad keeps an arrangement for a screen held sideways, one for a screen held upright, or both. A screen uses its own when the pad has one and is fitted from the other when not. Adopt makes the fitted arrangement the screen's own on its first edit, and AutoFit gives that up.
The windows¶
Each cluster is one plain Win32 window, with WS_EX_LAYERED, WS_EX_TOPMOST, WS_EX_NOACTIVATE and WS_EX_TOOLWINDOW and never WS_EX_TRANSPARENT. The windows answer WM_MOUSEACTIVATE with MA_NOACTIVATE and WM_POINTERACTIVATE with PA_NOACTIVATE, so the game keeps the focus. Each is drawn through UpdateLayeredWindowIndirect, and Windows hands a touch on a pixel of alpha 0 to the window below. The grip and its menu are two more windows.
Every window lives on one thread with its own message loop. It reads WM_POINTERDOWN, WM_POINTERUPDATE, WM_POINTERUP and WM_POINTERCAPTURECHANGED and answers every pointer message with 0, so no touch becomes a gesture or a mouse click. Press and hold, tap feedback and the touch visuals are off through WM_TABLET_QUERYSYSTEMGESTURESTATUS, the window's tablet property and SetWindowFeedbackSetting. A contact without POINTER_FLAG_CONFIDENCE, from a screen that has marked one, is a palm. Hide From Recordings sets WDA_EXCLUDEFROMCAPTURE.
The thread writes the device's state itself through TouchPlay, so the engine sees a touch on its next pass with no UI timer between. It draws at no more than 60 frames a second, or the display's rate when that is lower. It sleeps in GetMessage while nothing is touched, with one timer at the soonest deadline: the once-a-second check that keeps the windows on top and hears exclusive full screen, a fade, the grip's half-second hold, the menu's five seconds and a touch area's 50 ms click.
When the pad comes down, the thread lets its drawing memory go (PadRenderer.ForgetThreadTargets, OverlayArt.ForgetThreadTargets and the part buffer), and the next Show makes what it draws again. The thread itself lives while PadForge runs.
Play¶
TouchPlay follows RetroArch's overlay rules (input_driver.c): a hit shape wider than the drawing, and a held press tested against a range 6 units wider so a drifting thumb keeps it. The D-pad's diagonals take their share of the circle at RetroArch's default diagonal sensitivity of 80, and its middle is still within 12/90 of its half side. A stick is at full throw at its edge. A slide trigger pulls as far as the thumb travels up from where it landed. A touch area's fingers take the lowest free of five slots, and a second tap within 300 ms clicks it for 50 ms. Up to 32 pointers are followed at once.
The device¶
TouchControllerDevice is one device of the Gamepad kind, vendor 0xBEEF, product 0xCA7D, path overlay://pad, with one instance for every pad, so one assignment and one mapping serve them all. Its surface is exactly the showing pad's controls (SetSurface), so the mapping picker offers only what the pad can send. The service registers it while the switch is on, a pad is chosen and the engine runs, and takes it offline otherwise. Its row stays, as a disconnected device's does. It has no motor and refuses rumble. Press Rumble pulses the rumble devices on the same virtual controller.
The service¶
Every trigger (a setting, the profile, the store, the engine, the display, the grip, a macro) posts one refresh to the interface thread, which reads everything as it stands then. A refresh that changes the pad, the display or what shows lets every control go first. Rename and Remove on the page end an Arrange of that pad as a Cancel (TouchControllerPage.CancelArrangeOf), so Done cannot write the pad back over the change.
A new language rebuilds the page's lists. The Labels, New Sticks and New D-Pads boxes then push -1, which TouchControllerLabelsIndex, TouchControllerNewSticksIndex and TouchControllerNewDpadsIndex read as no choice, so the settings stay.
Last updated for PadForge 6.1.0.