Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


How to change the default font size for the hint in trainer?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Razi
Expert Cheater
Reputation: 1

Joined: 17 Jan 2018
Posts: 215

PostPosted: Sun Mar 22, 2026 12:14 am    Post subject: How to change the default font size for the hint in trainer? Reply with quote

How to change the default font size for the hint of all controls in the trainer?
Before creating standalone exe trainer, the hint font size for all controls has a standard size. But after creating standalone exe trainer, the hint font size for all controls becomes significantly larger. Is there any way to fix this?
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 39

Joined: 16 Feb 2017
Posts: 1567

PostPosted: Sun Mar 22, 2026 9:45 am    Post subject: Reply with quote

DPI-Aware Interface Scaling Engine
This script implements a Dual-Layer Scaling System designed to solve common UI distortion issues in standalone trainers. It ensures that the interface remains sharp and proportional across different monitor resolutions and Windows scaling settings (DPI).

Key Features:

Automatic System Scaling (Admin Level):
Detects the user's current monitor DPI at startup and automatically adjusts the form size, control positions, and font sizes using a calculated scaleFactor.
This specifically fixes the "oversized hint" and "misaligned controls" issues common in standalone EXEs.

Manual Font Override (User Level):
Includes an optional function to adjust font sizes independently, allowing users with high-resolution displays or visual impairments to improve readability without breaking the UI layout.

Deep Component Access:
Uses ComponentCount to recursively scale every visual element, including those nested within Panels, GroupBoxes, or other containers.


Code:
-- [[ 1. FORM CREATION - Define in standard 96 DPI units ]]
if myForm then myForm.destroy() end

myForm = createForm()
myForm.Caption = 'AylinCE Smart Trainer'
myForm.Width = 400
myForm.Height = 250
myForm.Position = 'poScreenCenter'

-- Set the baseline for the engine
myForm.DesignTimePPI = 96
-- Get the REAL system DPI (e.g., 96, 120, 144)
local systemDPI = getScreenDPI()
myForm.PixelsPerInch = systemDPI

-- Calculate the multiplier factor
local scaleFactor = systemDPI / 96


-- Example Controls
myLabel = createLabel(myForm)
myLabel.Parent = myForm
myLabel.Caption = 'Global Scale Control [scaleFactor]: '..scaleFactor.." ("..string.format("%.1f", scaleFactor)..")"
myLabel.Left, myLabel.Top = 20, 20
myLabel.Hint = 'This is a hint example that might look large in EXE'
myLabel.ShowHint = true


-- [[ 2. AUTO-SCALING FUNCTION (Admin Level) ]]
-- This function fixes the "Standalone EXE" and "Hint" issues automatically
function applyGlobalScaling(obj, scale)
    if scale == 1 then return end -- No scaling needed for 100% DPI

    -- Scale the Form itself
    obj.Width = obj.Width * scale
    obj.Height = obj.Height * scale

    -- Loop through all components to adjust positions and fonts
    for i = 0, obj.ComponentCount - 1 do
        local c = obj.Component[i]
        local success, _ = pcall(function() return c.Left end)

        if success then
            -- Adjust Coordinates
            c.Left = c.Left * scale
            c.Top = c.Top * scale

            -- Adjust Size (Only if AutoSize is not controlling it)
            local isAuto = false
            pcall(function() isAuto = c.AutoSize end)
            if not isAuto then
                c.Width = c.Width * scale
                c.Height = c.Height * scale
            end

            -- Adjust Font Size (Crucial for readability)
            if c.Font then
                c.Font.Size = math.floor(c.Font.Size * scale)
            end
        end
    end
end

-- [[ 3. OPTIONAL: FONT SIZE OVERRIDE (User Level) ]]
-- This is for users who want even larger text regardless of DPI
function setManualFontSize(targetSize)
    for i = 0, myForm.ComponentCount - 1 do
        local c = myForm.Component[i]
        if c.Font then
            c.Font.Size = targetSize * scaleFactor
        end
    end
end

-- Run the automatic scaling once at startup
applyGlobalScaling(myForm, scaleFactor)

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Razi
Expert Cheater
Reputation: 1

Joined: 17 Jan 2018
Posts: 215

PostPosted: Mon Mar 23, 2026 12:17 pm    Post subject: Reply with quote

Sorry for the late reply. It doesn't look like the problem is with DPI. Here is an example of your code before and after creating the standalone trainer.
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 39

Joined: 16 Feb 2017
Posts: 1567

PostPosted: Tue Mar 24, 2026 10:40 am    Post subject: Reply with quote

DPI Scaling & Custom Tooltip for Cheat Engine Forms:

When designing forms in Cheat Engine, DPI Scaling (125%, 150%, etc.) can often break your UI.
Labels might overlap, or worse, the native Windows Tooltips (Hints) might ignore your form's scaling, appearing either tiny or massive in a standalone EXE.

Step 1:
The Native Solution (fixDPI)
Before trying custom scripts, always use the built-in fixDPI() method.
This tells Cheat Engine to recalculate all positions and font sizes based on the user's current monitor settings.

Usage:
Place this at the very end of your form script:


Code:
myForm.DesignTimePPI = 96 -- The DPI of your monitor during design
myForm.fixDPI()           -- Automatically scales controls and fonts


Step 2:
The "Advanced" Solution (AylinCE Smart Hint Engine Wink )
In many cases, especially in generated EXEs, Windows takes over the "Hint" window management.
It often ignores the CE-Form scaling, resulting in a broken user experience.

If fixDPI() doesn't solve your tooltip issues, use the following Recursive Custom Hint Engine.
It replaces the native Windows tooltip with a fully controlled, DPI-aware Lua Panel that scales perfectly on any screen.

Code:
-- 1. CLEANUP PREVIOUS INSTANCE
if myForm then myForm.destroy() end

-- 2. MAIN FORM INITIALIZATION
myForm = createForm()
myForm.Caption = 'AylinCE Smart Trainer'
myForm.Width = 400
myForm.Height = 270
myForm.Position = 'poScreenCenter'

-- DPI & Scaling Configurations
myForm.DesignTimePPI = 96
local systemDPI = getScreenDPI()
myForm.PixelsPerInch = systemDPI
local scaleFactor = systemDPI / 96


-- 4. EXAMPLE UI CONTROLS (Nested Structure)
local myLabel1 = createLabel(myForm)
myLabel1.Parent = myForm
myLabel1.Caption = 'Global Scale: '..string.format("%.1f", scaleFactor)
myLabel1.Left, myLabel1.Top = 20, 20
myLabel1.Hint = 'This is a high-resolution DPI aware custom hint!'


-- Nested Panel Test (Panel -> Panel -> Label)
local myPnl1 = createPanel(myForm)
myPnl1.Height, myPnl1.Width = 100, 250
myPnl1.Left, myPnl1.Top = 120, 40

local myPnl2 = createPanel(myPnl1)
myPnl2.Height, myPnl2.Width = 40, 180
myPnl2.Left, myPnl2.Top = 40, 10

local myLbl1 = createLabel(myPnl2)
myLbl1.Parent = myPnl2
myLbl1.Caption = "Deep Nested Hint Test 1!"
myLbl1.Left, myLbl1.Top = 20, 10
myLbl1.Hint = "Success! The recursive scan found me deep inside the panels."

-- Nested Panel Test (Panel -> Panel -> Label)
local myPnl3 = createPanel(myForm)
myPnl3.Height, myPnl3.Width = 100, 250
myPnl3.Left, myPnl3.Top = 20, 160

local myPnl4 = createPanel(myPnl3)
myPnl4.Height, myPnl4.Width = 40, 180
myPnl4.Left, myPnl4.Top = 40, 55

local myLbl2 = createLabel(myPnl4)
myLbl2.Parent = myPnl4
myLbl2.Caption = "Deep Nested Hint Test 2!"
myLbl2.Left, myLbl2.Top = 20, 10
myLbl2.Hint = "Success! The recursive scan found me deep inside the panels."

--############################################################################--
--############################################################################--


-- 3. CUSTOM HINT PANEL (Global UI Component)
aylinHint = createPanel(myForm) -- myForm = yourTrainerName (UDF1 or myTrainer etc)
aylinHint.Visible = false
aylinHint.BevelOuter = 'bvNone'
aylinHint.Color = 0x1A1A1A -- Modern dark theme background
aylinHint.AutoSize = true

-- Label inside the Hint Panel
local hintLabel = createLabel(aylinHint)
hintLabel.Name = 'HintText'
hintLabel.Font.Color = 0xDDDDDD -- Soft white text
hintLabel.Font.Size = math.floor(9 * scaleFactor)
hintLabel.Font.Name = 'Segoe UI'
hintLabel.BorderSpacing.Around = math.floor(6 * scaleFactor)
hintLabel.WordWrap = true
hintLabel.Width = math.floor(250 * scaleFactor)

-------------------------------------------------------
-- [[ LOGIC: ABSOLUTE COORDINATE CALCULATOR ]]
-------------------------------------------------------
-- Calculates the real (Form-relative) X and Y regardless of parent layers
function getAbsolutePosition(control)
    local x, y = 0, 0
    local current = control
    -- Loop up through parents until we hit the main Form
    while current and current.ClassName ~= 'TCEForm' and current.ClassName ~= 'TForm' do
        x = x + current.Left
        y = y + current.Top
        current = current.Parent
    end
    return x, y
end

-------------------------------------------------------
-- [[ LOGIC: RECURSIVE HINT INJECTOR ]]
-------------------------------------------------------
-- Recursively scans every container to find and hook labels/buttons with hints
function injectAylinHints(container)
    local ratio = getScreenDPI() / 96

    for i = 0, container.ControlCount - 1 do
        local c = container.getControl(i)

        -- 1. If this is a container (Panel, GroupBox etc.), dive deeper
        if c.ControlCount and c.ControlCount > 0 then
            injectAylinHints(c)
        end

        -- 2. If the control has a Hint, disable Windows default and hook custom UI
        if c.Hint and c.Hint ~= "" then
            c.ShowHint = false -- Suppress native Windows tooltip

            c.OnMouseEnter = function(sender)
                hintLabel.Caption = sender.Hint

                -- Calculate the "Anchored" position
                local absX, absY = getAbsolutePosition(sender)
                local targetX = absX
                local targetY = absY + sender.Height + math.floor(4 * ratio)

                -- BOUNDARY CHECK: Ensure hint stays inside the form
                if (targetX + aylinHint.Width) > myForm.Width then
                    targetX = myForm.Width - aylinHint.Width - 10
                end
                if (targetY + aylinHint.Height) > myForm.Height then
                    targetY = absY - aylinHint.Height - 5 -- Flip to show above the control
                end

                -- Apply coordinates and show
                aylinHint.Left = targetX
                aylinHint.Top = targetY
                aylinHint.Visible = true
                aylinHint.bringToFront()
            end

            c.OnMouseLeave = function()
                aylinHint.Visible = false
            end
        end
    end
end

-- [[ START SYSTEM ]]
injectAylinHints(myForm) -- myForm = yourTrainerName (UDF1 or myTrainer etc)

myForm.fixDPI() -- Ensure the rest of the form is also scaled

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Razi
Expert Cheater
Reputation: 1

Joined: 17 Jan 2018
Posts: 215

PostPosted: Wed Mar 25, 2026 5:16 pm    Post subject: Reply with quote

AylinCE wrote:
Place this at the very end of your form script:
Code:
myForm.DesignTimePPI = 96 -- The DPI of your monitor during design
myForm.fixDPI()           -- Automatically scales controls and fonts

It didn't help. It makes the hint smaller before creating the trainer, but does not change the size of the hint in the standalone trainer.

AylinCE wrote:
The "Advanced" Solution (AylinCE Smart Hint Engine Wink )
In many cases, especially in generated EXEs, Windows takes over the "Hint" window management.
It replaces the native Windows tooltip with a fully controlled, DPI-aware Lua Panel that scales perfectly on any screen.

Thanks for the example.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites