📄 gui_fps.lua
字号:
-------------------------------------------------------------------------------------------------------------------------------------------------------------------- file: gui_fps.lua-- brief: displays the current frames-per-seconds-- author: Dave Rodgers---- Copyright (C) 2007.-- Licensed under the terms of the GNU GPL, v2 or later.------------------------------------------------------------------------------------------------------------------------------------------------------------------function widget:GetInfo() return { name = "FPS", desc = "Displays the current frames-per-second", author = "trepan", date = "Jan 8, 2007", license = "GNU GPL, v2 or later", layer = 0, enabled = false -- loaded by default? }end----------------------------------------------------------------------------------------------------------------------------------------------------------------include("colors.h.lua")local floor = math.floorlocal vsx, vsy = widgetHandler:GetViewSizes()-- the 'f' suffixes are fractions (and can be nil)local color = { 1.0, 1.0, 0.25 }local xposf = 0.99local xpos = xposf * vsxlocal yposf = 0.032local ypos = yposf * vsylocal sizef = 0.015local size = sizef * vsylocal font = "LuaUI/Fonts/FreeSansBold_14"local font = "LuaUI/Fonts/Abaddon_30"local format = "orn"local fh = (font ~= nil)-------------------------------------------------------------------------------------------------------------------------------------------------------------------- Default GUI override--local defaultFPSUsed = 0function widget:Initialize() defaultFPSUsed = Spring.GetConfigInt("ShowFPS", 1) Spring.SendCommands({"fps 0"})endfunction widget:Shutdown() Spring.SendCommands({"fps " .. defaultFPSUsed})end-------------------------------------------------------------------------------------------------------------------------------------------------------------------- Rendering--function widget:DrawScreen() gl.Color(color) if (fh) then fh = fontHandler.UseFont(font) fontHandler.DisableCache() fontHandler.DrawRight(Spring.GetFPS(), floor(xpos), floor(ypos)) fontHandler.EnableCache() else gl.Text(Spring.GetFPS(), xpos, ypos, size, format) endend-------------------------------------------------------------------------------------------------------------------------------------------------------------------- Geometry Management--local function UpdateGeometry() -- use the fractions if available xpos = (xposf and (xposf * vsx)) or xpos ypos = (yposf and (yposf * vsy)) or ypos size = (sizef and (sizef * vsy)) or size -- negative values reference the right/top edges xpos = (xpos < 0) and (vsx + xpos) or xpos ypos = (ypos < 0) and (vsy + ypos) or yposendUpdateGeometry()function widget:ViewResize(viewSizeX, viewSizeY) vsx = viewSizeX vsy = viewSizeY UpdateGeometry()end-------------------------------------------------------------------------------------------------------------------------------------------------------------------- Configuration routines--local function StoreGeoPair(tbl, fName, fValue, pName, pValue) if (fValue) then tbl[pName] = nil tbl[fName] = fValue else tbl[pName] = pValue tbl[fName] = nil end returnendfunction widget:GetConfigData() local tbl = { color = color, format = format, font = font } StoreGeoPair(tbl, 'xposf', xposf, 'xpos', xpos) StoreGeoPair(tbl, 'yposf', yposf, 'ypos', ypos) StoreGeoPair(tbl, 'sizef', sizef, 'size', size) return tblend---------------------------------------------------------------------------------- returns a fraction,pixel pairlocal function LoadGeoPair(tbl, fName, pName, oldPixelValue) if (tbl[fName]) then return tbl[fName], 1 elseif (tbl[pName]) then return nil, tbl[pName] else return nil, oldPixelValue endendfunction widget:SetConfigData(data) color = data.color or color format = data.format or format font = data.font or font if (font) then fh = fontHandler.UseFont(font) end xposf, xpos = LoadGeoPair(data, 'xposf', 'xpos', xpos) yposf, ypos = LoadGeoPair(data, 'yposf', 'ypos', ypos) sizef, size = LoadGeoPair(data, 'sizef', 'size', size) UpdateGeometry() returnend----------------------------------------------------------------------------------------------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -