Jump to content

Converting GUIs to support DPI scaling


Recommended Posts

I use SetSoundDevice to control my audio devices but the UI was either
 

blurry like this:

Spoiler


 rnNBPZO.png

or unusable like this:

Spoiler

WUiAUX4.png


so I made this horrible thing to add scaling to the GUI:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Change2CUI=y
#AutoIt3Wrapper_Res_HiDpi=y
#AutoIt3Wrapper_AU3Check_Parameters=-w 3 -w 4 -w 5
#AutoIt3Wrapper_Run_Au3Stripper=y
#Au3Stripper_Parameters=/sf /sv /rm
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <File.au3>

;~ _convertGUI("")
If $CmdLine[0] <> 0 Then _convertGUI($CmdLine[1])
Func _convertGUI($sFilePath)
    If $sFilePath <> "" Then
        Local $aArray = FileReadToArray($sFilePath)
    Else
        ;TEST DATA
        Local $aArray[6] = ['$H_Res_Language = GUICtrlCreateProgress(5, 120, 210 + 25, 480, 20, BitOR($GUI_SS_DEFAULT_COMBO, $CBS_SIMPLE)) ; $CBS_DROPDOWNLIST)', _
                'Local $h_Ok = GUICtrlCreateButton("Ok", 72, 224, 81, 33, 0)', _
                'GUICreate($Warning_TiTle, 700, 310, -1, -1, $WS_SIZEBOX + $WS_SYSMENU + $WS_MINIMIZEBOX)', _
                'GUICtrlCreateLabel("Output type: ", 30, 130, 65, 20) ;, $SS_RIGHT)', _
                '$H_FieldNameEdit = GUICtrlCreateEdit($INP_FieldNameEdit, 100,260+25, 500, 150 - 25) ;comment', 'Local $H_CANCEL = GUICtrlCreateGraphic("Cancel", 224, 224, 97, 33, 0)']
    EndIf

    Local $hTimer = TimerInit(), $iGUIElementCount = 0, $sResult = "", $sFileName = "", $sDrive = "", $sDir = "", $sExtension = ""
    If @Compiled Then
        _PathSplit($sFilePath, $sDrive, $sDir, $sFileName, $sExtension)
        $sFileName = StringRegExpReplace($sFilePath, "^.*\\", "")
    EndIf

    For $i = 0 To (UBound($aArray) - 1)
        If StringRegExp($aArray[$i], "GUICtrlCreate|GUICreate") Then
            $sResult = _splitComma($aArray[$i])
            If Not @error Then $aArray[$i] = $sResult
            $iGUIElementCount += 1
        EndIf
    Next

    ConsoleWrite("t = " & TimerDiff($hTimer) & " GUI elements = " & $iGUIElementCount & " lines = " & (UBound($aArray) - 1) & @CRLF)

    If $sFileName <> "" Then
        Local $hFile = FileOpen("edited." & $sFileName, 2)
        _FileWriteFromArray("edited." & $sFileName, $aArray)
        FileClose($hFile)
    EndIf

    Exit
EndFunc   ;==>_convertGUI


Func _splitComma($sString)
    Local $sSplitResult = "", $sTrimmedR = "", $sTrimmedL = ""
    Local $aSplit = StringSplit($sString, ',')
    If Not @error Then
        $sTrimmedR = ""
        $sTrimmedL = ""
        For $j = 1 To $aSplit[0]

            If StringRegExp($aSplit[1], "(?:.GUICtrlCreateGraphic|GUICtrlCreateProgress|GUICtrlCreateSlider|GUICtrlCreateTab|GUICtrlCreateTreeView)") Then
                If $j = 1 Then
                    While StringLeft($aSplit[$j], 1) <> '('
                        $sTrimmedL &= StringLeft($aSplit[$j], 1)
                        $aSplit[$j] = StringTrimLeft($aSplit[$j], 1)
                    WEnd
                    $aSplit[$j] = StringTrimLeft($aSplit[$j], 1)
                EndIf
            EndIf

            If $j = $aSplit[0] Then
                While StringRight($aSplit[$j], 1) <> ')'
                    $sTrimmedR &= StringRight($aSplit[$j], 1)
                    $aSplit[$j] = StringTrimRight($aSplit[$j], 1)
                WEnd
                $aSplit[$j] = StringTrimRight($aSplit[$j], 1)
            EndIf

            If StringRegExp($aSplit[$j], "[0-9]") And $aSplit[$j] <> -1 And $aSplit[$j] <> 0 And $aSplit[$j] <> 1 And Not StringInStr($aSplit[$j], ')') Then
                If StringRegExp($aSplit[$j], "\-|\+") Then ;put parenthesis around + or -
                    $aSplit[$j] = '(' & $aSplit[$j] & ")*$g_DPI"
                Else
                    $aSplit[$j] = $aSplit[$j] & "*$g_DPI"
                EndIf
            EndIf

            If $j < $aSplit[0] Then
                $sSplitResult &= $aSplit[$j] & ','
            ElseIf $j = $aSplit[0] Then
                $sSplitResult &= $aSplit[$j] & ')'
            Else
                $sSplitResult &= $aSplit[$j]
            EndIf

        Next

        If $sTrimmedR <> "" Then $sSplitResult &= StringReverse($sTrimmedR)
        If $sTrimmedL <> "" Then $sSplitResult = $sTrimmedL & '(' & $sSplitResult

    Else
        SetError(1)
        Return
    EndIf

    ConsoleWrite($sSplitResult & @CRLF)
    Return $sSplitResult

EndFunc   ;==>_splitComma


And now it looks good: 

Spoiler

OkTONha.png

but it doesn't work on everything, for example the "GUICtrlCreateLabel("Output type: ", 30, 130, 65, 20) ;, $SS_RIGHT)" (from the autoit3wrapper gui)
because the comment contains a parenthesis and it would break completely if there were variables as parameters..
Is there some kind of parser around that I could use instead or maybe someone who has already done something like this?

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By NassauSky
      Hi all,
      The more projects I work on, the harder it is to find old scripts I created with certain techniques in them. I'd like to leave this here for others to get an idea from and it will be available now by keyword searching in this forum.
      This project needed an evenly distributed button grid setup on a touch screen with half decent sized buttons and spacing so the user would be less likely to press the key beside it. Here is one quick example to give anyone an idea of a way to handle it.
      #include <GUIConstants.au3> GUICreate("Button Grid", 1080, 100) ; will create a dialog box that when displayed is centered GUISetState(@SW_SHOW) ; will display an empty dialog box ;--Create and Position Controls Dim $btnActivated[1][2] ;Col 1 is button id, Col 2 is True/False used in 1 example as depressed Dim $btnArray[100][2] ;Col 1 is button id, Col 2 is True/False used in 1 example as depressed $num = 0 $btnActivated[0][0] = GUICtrlCreateButton("Activated", 0, 0, 100, 100) ;x,y,w,h $btnActivated[0][1] = True GUICtrlSetBkColor(-1,0x00ff00) GUICtrlSetColor(-1,0x005500) GUICtrlSetFont(-1,14) For $Y = 0 To 1 For $X = 0 To 7 ConsoleWrite( ($X * 100) + ($X*20) + 120 & @CRLF) If $Y=0 Then $btnArray[$num][0] = GUICtrlCreateButton($num + 1, ($X * 100) + ($X*20) + 120, 0, 100, 40) ;x,y,w,h Else $btnArray[$num][0] = GUICtrlCreateButton($num + 1, ($X * 100) + ($X*20) + 120, ($Y * 40) + $Y*20, 100, 40) ;x,y,w,h EndIf GUICtrlSetBkColor($btnArray[$num][0], 0xFFFFFF) $num += 1 Next Next ;--Set Button Names GUICtrlSetData($btnArray[0][0],"Autoit") GUICtrlSetData($btnArray[1][0],"Is") GUICtrlSetData($btnArray[2][0],"Cool") ; Run the GUI until the dialog is closed While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE ExitLoop Case $btnActivated[0][0] $btnActivated[0][1] = NOT $btnActivated[0][1] If $btnActivated[0][1] Then GUICtrlSetBkColor($btnActivated[0][0],0x00ff00) GUICtrlSetColor($btnActivated[0][0],0x005500) GUICtrlSetData($btnActivated[0][0],"Activated") GUICtrlSetFont($btnActivated[0][0],14) Else GUICtrlSetBkColor($btnActivated[0][0],0xFF9999) GUICtrlSetColor($btnActivated[0][0],0x550000) GUICtrlSetData($btnActivated[0][0],"DeActivated") GUICtrlSetFont($btnActivated[0][0],13) EndIf Case $btnArray[0][0] If $btnActivated[0][1] Then MsgBox(0,"Notice","Btn1",1) EndIf Case $btnArray[1][0] If $btnActivated[0][1] Then MsgBox(0,"Notice","Btn2",1) EndIf Case $btnArray[2][0] If $btnActivated[0][1] Then MsgBox(0,"Notice","Btn3",1) EndIf EndSwitch WEnd I couldn't find one of my old projects that broke the button array into more columns that included the actual button name in the field. Feel free to share your own or share a more flexible version of this simple example.

    • By It_is_me_Me
      I am making some GUI with combobox for the Baudrates communications and I listed 9600, 57600, 115200. 
      I wrote the code to be defaulted to 57600 like this:
      GUICtrlSetData($comboBox_opticalBaudRate, "9600|57600|115200", "57600")
      But I wanted the GUI to remember the last item the user picks so the baudrates will NOT be defaulted to 57600.
      Example, I pick 9600 as my baudrates, then I close the GUI, after opening it, it always prompt 57600 since that is what I did in my code. But I want that if I choose 9600 and close the GUI, opening it again will show 9600 now instead of 57600.
      Is there a way to do it in GUI setting?
       
      Thanks.
    • By ashraful089
      #include <ButtonConstants.au3>
      #include <ComboConstants.au3>
      #include <GUIConstantsEx.au3>
      #include <WindowsConstants.au3>
      #Region ### START Koda GUI section ### Form=C:\Users\Engr. Ashraful\Videos\koda_1.7.3.0\Forms\ProgramPlayer\FormProgamToOpen.kxf
      $FormInput = GUICreate("Input", 302, 205, 454, 285)
      $Resolution = GUICtrlCreateCombo("Resolution", 80, 24, 145, 25)
      GUICtrlSetData(-1, "1920|VM1920|1366")
      $ComboProgramType = GUICtrlCreateCombo("Program Type Selection", 80, 64, 145, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
      GUICtrlSetData(-1, "Multimedia|Official|Design|Web")
      $ButtonEnter = GUICtrlCreateButton("Enter", 104, 104, 75, 25)
      GUISetState(@SW_SHOW)
      #EndRegion ### END Koda GUI section ###
      While 1
          $nMsg = GUIGetMsg()
          Switch $nMsg
              Case $GUI_EVENT_CLOSE
                  Exit
          EndSwitch
      WEnd
       
      please help me to read combo box input and use the value for another function/ work
       
    • By Aapjuh
      Hi,
      I am having a problem properly saving the Width of a resizable Gui.
      When a user resizes the Gui it gets saved in an ini when the Gui closes to then restore the new Width upon reopening the app.
      with GUICreate("myGui",300,200,Default,Default,$WS_SIZEBOX)
      WinGetPos($hGUI) returns 314, and WinGetClientSize($hGUI) returns 298
      when its then saved in the ini the gui keeps expanding or shrinking every time its opened by +14 or -2
      I figure it has to do with borders etc, but i also guess borders depend on the window theme and whatnot or is user specific, so i can't just do $GuiWidth = $GetGuiWidth[arr] -14 or +2 right?

      is there a proper way of doing this?
      Thanks in advance,
      Aapjuh
    • By mLipok
      In the display settings, in the advanced settings on the General tab is more or less the setting:    The translation from GOOGLE: "If the resolution makes items are too small to achieve visual comfort, you can to offset this effect increase the resolution dpi. To change only the font size, click Cancel and go to the Appearance tab."    EDIT: Here there is a possibility to choose: Default size 96 dpi  Big size 120 dpi    When I Change this option to 120 dpi, this causes display problems with elements such as Button. The problem is manifested by the fact that the text does not fit within the limits set by the size of the button.  Of course, if you set 96 dpi, the text looks normal.    Does anyone know a solution to this problem.    I note that the solution like this:  GUICtrlSetResizing(-1, $GUI_DOCKALL) unfortunately does not help.
       
        mLipok
×
×
  • Create New...