Skip to content

核心概念

MGFX 是 immediate renderer。UI 代码负责 layout、input、focus、animation state 和 hit testing;MGFX 只绘制每帧传入的明确参数。

选择运行时

项目入口API 风格
普通 Garry's Mod addonlua-mgfx/ addonMGFX.RoundedBoxEx(...)
Lux 项目@lux/mgfx packagemgfx.api.roundedBoxEx(...)

两套函数行为等价。GLua 在 MGFX 上使用 PascalCase;Lux 在 mgfx.api 下使用 lowerCamelCase。

Frame Scope

lua
function PANEL:Paint(w, h)
    MGFX.StartPanel(self, w, h)
    MGFX.RoundedBox(0, 0, w, h, 8, Color(20, 24, 32, 230))
    MGFX.EndPanel()
end
lux
import * as mgfx from "@lux/mgfx"

fn PANEL:Paint(w, h) {
  local draw = mgfx.api
  draw.startPanel(self, w, h)
  draw.roundedBox(0, 0, w, h, 8, Color(20, 24, 32, 230))
  draw.endPanel();
}

StartPanel 建立 panel-local 坐标系;StartScreen 建立 HUDPaint/overlay 使用的 screen-space 坐标系。每个 start 必须在同一次绘制中配对对应的 end。

文字和 clip command 可能延迟到 EndPanel / EndScreen flush,因此需要覆盖在形状上方的文字应在形状之后提交。

NameNameEx

text
Name(...)    参数简短,适合简单、稳定的热路径调用
NameEx(...)  使用 style table,适合高级效果和可读参数

需要 shadowouterGlowbackdroppatternmaskfitcroptransform 或 per-corner radius/cuts 时使用 Ex

选择 API

需求推荐 API
Panel、button、rowRoundedBox / RoundedBoxEx
切角 HUD cardChamferBoxEx
Badge、arrow、凸形状RegularPolyExDiamondExCaretExPolyEx
Avatar、icon、item artImageExIconExMask
Health、ammo、loading barProgressBarExSegmentBarEx
圆形 meter、radial menuRingExArcExSectorEx
普通文字Text 或原生 GMod text
shader 特效文字TextExTextBoxEx
Gradient 与 patternLinearGradientRadialGradientEllipticalRadialGradientWornPattern

Style Table

lua
MGFX.RoundedBoxEx(x, y, w, h, {
    radius = 10,
    fill = Color(18, 24, 32, 220),
    stroke = Color(255, 255, 255, 32),
    strokeWidth = 1,
})
lux
import * as mgfx from "@lux/mgfx"

mgfx.api.roundedBoxEx(x, y, w, h, {
  radius = 10,
  fill = Color(18, 24, 32, 220),
  stroke = Color(255, 255, 255, 32),
  strokeWidth = 1,
});

所有绘制状态都是显式参数;MGFX 没有全局 fill/stroke 状态。短签名的 stroke 顺序固定为 fill, stroke, strokeWidthstroke == nilstrokeWidth == nilstrokeWidth <= 0 表示没有 stroke。

文字路径

普通 label、table row、player name、chat text 和快速变化的 counter 应使用原生 text 或 Text。只有需要 gradient fill、stroke、glow、shadow、weight bias 或 text box composition 时才使用 TextEx

Guide 与 Reference 的边界

概念和配方放在本指南;准确签名、参数、默认值、返回值和 caveat 放在 API 参考