DermaScale libraryclient
Part of Active UI
Scales the stock Derma interface with the screen resolution. Garry's Mod sizes its panels
and fonts in raw pixels that were designed for 1080p, so on a 4K screen the spawn menu,
the tool menu, context menus, windows and dialogs come out tiny. The panels of Flux itself
already scale through math.scale and the theme fonts, so this library does the same for
the built-in controls at the framework level:
DermaScale.scalescales a size designed for 1080p (DermaScale.factoris the ratio of the screen height to 1080, never below 1, so nothing changes at 1080p or below).- The built-in fonts ('DermaDefault', 'DermaDefaultBold', 'DermaLarge', 'Default',
'Trebuchet18', 'Trebuchet24', 'HudHintTextLarge', 'HudHintTextSmall', 'CenterPrintText',
'DebugFixed', 'DebugFixedSmall', 'BudgetLabel', 'ChatFont' and the spawn menu's
'ContentHeader') are created again at the scaled size from the
CreateFontshook, with the families and weights of Garry's Mod's own definitions, so they follow the same rebuilds as the Flux fonts (load, schema load and resolution change). - The sizes that the stock panel classes hardcode in their
Init,PerformLayoutand setup methods are patched on the class tables:DermaScale.afterwraps a method and re-applies the scaled sizes once the original has run,DermaScale.replaceswaps a method whose body mixes sizes with other logic for a scaled copy. Classes registered later (or registered again) are patched from a wrapper aroundvgui.Register. Only the stock classes listed in this file are touched; a panel that derives from one of them gets the scaled base once, from the base classInit, and its own code keeps usingmath.scaleas before. Nothing multipliesSetSizeglobally. - The modal dialogs
Derma_Message,Derma_QueryandDerma_StringRequestare replaced with scaled copies, and the menu bar of the spawn menu (menubarmodule) is sized again whenever it is attached to a menu. - When the resolution changes the spawn menu is rebuilt, since its panels were sized for the previous one.
- The light background that the creation menu sets on its spawn list tree is cleared, so that the tree is painted by the dark skin like every other one.
Summary
Functions
fixup runs after the original.menubar module when the gamemode loads and kept for good) and its buttons for the current screen.Functions
Wraps a method of a stock panel class so that fixup runs after the original. The fixup
re-applies the sizes that the original sets, scaled. The class is patched now if it is
registered and again whenever it is registered.
DermaScale.after('DButton', 'Init', function(panel)
panel:SetTall(DermaScale.scale(22))
end)
Parameters
- class_name String name of the panel class
- method String name of the method
- fixup function(panel, result, ...) called after the original with the panel, the value the original returned and the arguments of the call
Applies every patch registered for a class. Called when the class is registered.
Parameters
- class_name String name of the panel class
Creates the built-in fonts again at the scaled size. Does nothing at 1080p or below unless the fonts have been scaled before (after a change of the resolution), so that the original engine fonts stay untouched on screens that do not need scaling.
Returns the factor by which the stock Derma interface is scaled: the ratio of the screen height to 1080, never below 1 so that screens of 1080p or less keep their native sizes.
Returns
- Number
Returns the definitions of the built-in fonts that are recreated at a scaled size, keyed by name, at their 1080p sizes. They mirror lua/derma/init.lua, the sandbox gamemode and resource/ClientScheme.res (the 1080p variant of fonts that depend on the resolution).
Returns
- Map font name → font data for surface.CreateFont
Returns the original of a patched method or global function.
Parameters
- key String 'ClassName:Method' or '_G.function_name'
Returns
- function
Replaces a method of a stock panel class with a scaled copy.
Parameters
- class_name String name of the panel class
- method String name of the method
- fn function the new method
Replaces a global function with a scaled copy, remembering the original.
Parameters
- name String name of the global function
- fn function the new function
Scales a size designed for a 1080p screen to the current screen, rounding down. Returns the size unchanged at 1080p or below, and anything that is not a number as is.
Parameters
- size Number size at 1080p
Returns
- Number scaled size