35 lines
2.2 KiB
Python
35 lines
2.2 KiB
Python
"""Execute panel-only scaling with viewport and DPI boundaries."""
|
|
from policy_harness import ROOT, body, run
|
|
source=body(ROOT/'addons/core/Scripts/Game/ERR/00_Core/ERR_AdminMenuView.c','static void FitPanel(')
|
|
source=source.replace('Widget root','Widget* root').replace('ScaleWidget scale = ScaleWidget.Cast(root.FindAnyWidget("PanelScale"));','ScaleWidget* scale = root->FindAnyWidget("PanelScale");')
|
|
source=source.replace('GetGame().','GetGame()->').replace('GetWorkspace().','GetWorkspace()->').replace('root.','root->').replace('scale.','scale->').replace('Math.','Math::')
|
|
run(r'''
|
|
#include <algorithm>
|
|
#include <cassert>
|
|
#include <cmath>
|
|
struct ScaleWidget {float scale=1;int writes=0;float GetScale(){return scale;}void SetScale(float v){scale=v;writes++;}};
|
|
struct Widget {float width=1920,height=1080;ScaleWidget panel;bool present=true;ScaleWidget* FindAnyWidget(const char*){return present?&panel:nullptr;}void GetScreenSize(float& w,float& h){w=width;h=height;}};
|
|
struct Workspace {float factor=1;float DPIScale(float x){return x*factor;}} workspace;
|
|
struct Game {Workspace* GetWorkspace(){return &workspace;}} game;
|
|
Game* GetGame(){return &game;}
|
|
namespace Math {float Min(float a,float b){return std::min(a,b);}float AbsFloat(float v){return std::abs(v);}}
|
|
'''+source+r'''
|
|
int main(){
|
|
Widget root;FitPanel(nullptr);FitPanel(&root);assert(root.panel.scale==1 && root.panel.writes==0);
|
|
for(float dpi:{.75f,1.f,1.25f,1.5f,2.f}) {
|
|
workspace.factor=dpi;FitPanel(&root);
|
|
assert(root.panel.scale<=1 && root.panel.scale>0);
|
|
assert(1220*dpi*root.panel.scale<=root.width*.96f+.1f);
|
|
assert(760*dpi*root.panel.scale<=root.height*.96f+.1f);
|
|
int writes=root.panel.writes;FitPanel(&root);assert(root.panel.writes==writes);
|
|
assert(workspace.factor==dpi);
|
|
}
|
|
root.width=800;root.height=600;FitPanel(&root);
|
|
assert(1220*workspace.factor*root.panel.scale<=768.1f);
|
|
root.width=3840;root.height=2160;workspace.factor=1;FitPanel(&root);assert(root.panel.scale==1);
|
|
root.height=0;int writes=root.panel.writes;FitPanel(&root);assert(root.panel.writes==writes);
|
|
root.present=false;FitPanel(&root);assert(root.panel.writes==writes);
|
|
}
|
|
''')
|
|
print('PASS: panel fits narrow/large-DPI viewports, restores requested size, avoids repeated writes and preserves user DPI')
|