Click or drag to resize

GuiScale Class

Component for GUI dialog rescaling, based on the current game's GUI scale setting.
Inheritance Hierarchy
SystemObject
  KSPDev.GUIUtilsGuiScale

Namespace:  KSPDev.GUIUtils
Assembly:  KSPDev_Utils.2.6 (in KSPDev_Utils.2.6.dll) Version: 2.6 for KSP v1
Syntax
C#
public class GuiScale
Request Example View Source

The GuiScale type exposes the following members.

Constructors
  NameDescription
Public methodGuiScale
Creates a scaled skin instance.
Top
Properties
  NameDescription
Public propertypivot
The pivot point to scale the dialog at.
Public propertyscale
The current scale which this control is tracking.
Top
Methods
Fields
  NameDescription
Public fieldscaleIsDirty
Tells if the scale must be recalculated on the next access to scale.
Top
Remarks

The scale is applied to the dialog controls by adjusting GUI.matrix, which is a global variable. It must be restored to the original value before exiting OnGUI, or else the other controls in the game will also be affected.

This control simply magnifies the dialog. The good side of it is that the original code doesn't need to be changed. The bad side is that the low-res graphics (like the controls backgrounds) may not look nice when stretched up.

Examples
GuiScale _guiScale;
Rect _windowRect;

void OnAwake() {
  _guiScale = new GuiScale(getPivotFn: () => new Vector2(_windowRect.x, _windowRect.y));
}

void OnGUI() {
  using (new GuiMatrixScope() {
    _guiSkin.UpdateMatrix();
    _windowRect = GUILayout.Window(GetInstanceID(), _windowRect, WindowFunc, WindowTitle);
  }
}
See Also