Automated DPI scaling system (DPIAware.pbi)

Share your advanced PureBasic knowledge/code with the community.
User avatar
chi
Addict
Addict
Posts: 1034
Joined: Sat May 05, 2007 5:31 pm
Location: Linz, Austria

Automated DPI scaling system (DPIAware.pbi)

Post by chi »

I needed a reliable DPI-Aware system without having to re-adjust the size and position of every control in existing projects...

Code: Select all

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; DPIAware.pbi ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Info      : Automated DPI scaling system. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Version   : 1.3 (2017/06/13) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Purebasic : 5.40+ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; System    : Windows (tested on 2k, XP, 7, 8.1, 10) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Processor : x86, x64 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Encoding  : Ascii, Unicode ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Author    : chi ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; License   : Donationware (https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=1900506) ;;;;;;;;;;;;;
;;; Copyright : ©2017 Lunamedia.at ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;{; Tips & Tricks ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;×) Use IncludeFile "DPIAware.pbi" in your project and you're mostly done... ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;×) Use dpi_DebugUIscale() with the Debugger enabled to simulate a certain UI scale (min=100%, max=500%). Some fonts ;;
  ;;; are bound to your actual screen scale and can't be changed on the fly, though (Menu, ToolBar, CalendarGadget, ...);
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;×) DPIAware.pbi works with or without a DPI modified manifest and is also fully RTL compatible. ;;;;;;;;;;;;;;;;;;;;;;
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;×) Use additional flags (#PB_x_DPIAware) for calculations using PB commands and the regular ones if you deal with API.
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;×) The ToolBar is now DPI compatible and scales accordingly. Use ToolBarImageButton()'s additional flags to either ;;;
  ;;; stretch the ToolBar image (#PB_ToolBar_Image_Stretch, needs a ToolBar created with #PB_ToolBar_Large) or just ;;;;;
  ;;; center the image without any scaling (#PB_ToolBar_Image_Center = default). ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;×) Due to rounding operations there is a slight chance for UI misalignment... Just deal with it :) ;;;;;;;;;;;;;;;;;;;
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;×) If you improve/change/fix the source, please let me know! If you use following code in your project, free or ;;;;;;
  ;;; commercial, a donation would be nice (but not mandatory). Thank you for any amount you feel comfortable to donate ;
;};;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;{; ChangeLog ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;+) Version 1.3 (2017/06/13) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;;;×) Added [, fixedHeight=0]) parameter to CreateToolBar(). 0 = auto., values >= 24 sets the ToolBarButton height ;;;
  ;;;;;;; in pixel (only with #PB_ToolBar_Large). ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;;;×) Fixed dpi_DebugUIscale() not working properly if "Windows XP style DPI scaling" was enabled. ;;;;;;;;;;;;;;;;;;;
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;+) Version 1.2 (2017/06/12) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;;;×) Fixed dpi_DebugUIscale() not working on Windows XP. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;+) Version 1.1 (2017/06/11) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;;;×) Fixed LoadFont() for Windows XP and below. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;;;×) Fixed LoadFont() not scaling properly after another LoadFont() call. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;;;×) Fixed ToolBarStandardButton() bug by adding #PB_ToolBar_StandardButton to the CreateToolBar() flags. ;;;;;;;;;;;
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;+) Version 1.0 (2017/06/10) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;;;×) Initial release ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;};;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

EnableExplicit

Global dpi_ScaleHorz.f
Global dpi_ScaleVert.f
Global dpi_XPstyleDPI.b

CompilerIf #PB_Compiler_Debugger
  Global dpi_SysScale.f
CompilerEndIf


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;{ INIT
  
  Procedure _dpi_Init(Scale=0)
    Protected lf.LOGFONT, _dpi_DC, _dpi_FontName$, _dpi_FontHeight, _dpi_FontStyle, _dpi_FontId
    _dpi_DC = GetDC_(0)
    If Scale = 0
      dpi_ScaleHorz = GetDeviceCaps_(_dpi_DC, #LOGPIXELSX) / 96.0
      dpi_ScaleVert = GetDeviceCaps_(_dpi_DC, #LOGPIXELSY) / 96.0
      Scale = 100
    Else
      CompilerIf #PB_Compiler_Debugger
        dpi_SysScale = GetDeviceCaps_(_dpi_DC, #LOGPIXELSX) / 96.0
      CompilerEndIf
      dpi_ScaleHorz = Scale / 100.0
      dpi_ScaleVert = Scale / 100.0
    EndIf
    GetObject_(GetStockObject_(#DEFAULT_GUI_FONT), SizeOf(LOGFONT), @lf)
    _dpi_FontName$ = PeekS(@lf\lfFaceName[0])
    If lf\lfHeight < 0
      _dpi_FontHeight = -lf\lfHeight * 72.0 / GetDeviceCaps_(_dpi_DC, #LOGPIXELSY)
    Else
      _dpi_FontHeight = 8
    EndIf
    ReleaseDC_(0, _dpi_DC)
    _dpi_FontStyle = #PB_Font_HighQuality
    If OSVersion() < #PB_OS_Windows_Vista
      CompilerIf #PB_Compiler_Debugger
        _dpi_FontId = LoadFont(#PB_Any, _dpi_FontName$, Round(_dpi_FontHeight * dpi_ScaleVert, #PB_Round_Down), _dpi_FontStyle)
      CompilerElse
        _dpi_FontId = LoadFont(#PB_Any, _dpi_FontName$, _dpi_FontHeight, _dpi_FontStyle)
      CompilerEndIf
    Else
      If dpi_ScaleVert >= 1.25 And dpi_XPstyleDPI And Scale = 100
        _dpi_FontId = LoadFont(#PB_Any, _dpi_FontName$, _dpi_FontHeight , _dpi_FontStyle)
      Else
        CompilerIf #PB_Compiler_Debugger
          Protected _dpi_ScaleDebug.f = dpi_ScaleVert / dpi_SysScale
          If dpi_XPstyleDPI
            Select _dpi_ScaleDebug * 100
              Case 83
                _dpi_ScaleDebug = 0.9
              Case 100
                _dpi_ScaleDebug = 1.0
              Case 120
                _dpi_ScaleDebug = 1.25
              Case 160
                _dpi_ScaleDebug = 1.6
              Case 200
                _dpi_ScaleDebug = 2.0
            EndSelect
          Else
            _dpi_ScaleDebug = dpi_ScaleVert
          EndIf
          _dpi_FontId = LoadFont(#PB_Any, _dpi_FontName$, Round(_dpi_FontHeight * _dpi_ScaleDebug, #PB_Round_Down), _dpi_FontStyle)
        CompilerElse
          _dpi_FontId = LoadFont(#PB_Any, _dpi_FontName$, Round(_dpi_FontHeight * dpi_ScaleVert, #PB_Round_Down), _dpi_FontStyle)
        CompilerEndIf
      EndIf
    EndIf
    SetGadgetFont(#PB_Default, FontID(_dpi_FontId))
  EndProcedure
  
  Procedure _dpi_IsProcessDPIAware() : EndProcedure
  Prototype _dpi_IsProcessDPIAware()
  Procedure _dpi_SetProcessDPIAware(): EndProcedure
  Prototype _dpi_SetProcessDPIAware()
  
  Define user32 = OpenLibrary(#PB_Any, "user32.dll")
  If user32
    Define _dpi_IsProcessDPIAware_._dpi_IsProcessDPIAware = GetFunction(user32, "IsProcessDPIAware")
    If _dpi_IsProcessDPIAware_ = 0 : _dpi_IsProcessDPIAware_ = @_dpi_IsProcessDPIAware() : EndIf
    Define _dpi_SetProcessDPIAware_._dpi_SetProcessDPIAware = GetFunction(user32, "SetProcessDPIAware")
    If _dpi_SetProcessDPIAware_ = 0 : _dpi_SetProcessDPIAware_ = @_dpi_SetProcessDPIAware() : EndIf
    If _dpi_IsProcessDPIAware_() = #False
      _dpi_SetProcessDPIAware_()
      dpi_XPstyleDPI = #False
    Else
      dpi_XPstyleDPI = #True
    EndIf
    _dpi_Init()
    CloseLibrary(user32)
  EndIf
  
;}

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Macro dpi_CalcHorz(h) : Round(h * dpi_ScaleHorz, #PB_Round_Down) : EndMacro
Macro dpi_CalcVert(v) : Round(v * dpi_ScaleVert, #PB_Round_Down) : EndMacro

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Import ""
  PB_Object_EnumerateStart(obj)
  PB_Object_EnumerateNext(obj, *id)
  PB_Object_EnumerateAbort(obj)
  PB_Image_Objects
EndImport

Procedure _dpi_ImageIDtoImageNr(ImageID)
  Protected ImageNr
  PB_Object_EnumerateStart(PB_Image_Objects)
  While PB_Object_EnumerateNext(PB_Image_Objects, @ImageNr)
    If ImageID = ImageID(ImageNr)
      PB_Object_EnumerateAbort(PB_Image_Objects)
      ProcedureReturn ImageNr
    EndIf
  Wend
EndProcedure

Procedure dpi_DebugUIscale(percent=100)
  CompilerIf #PB_Compiler_Debugger
    Select Abs(percent)
        Case 000 To 100 : percent = 100
        Case 101 To 125 : percent = 125
        Case 126 To 150 : percent = 150
        Case 151 To 175 : percent = 175
        Case 176 To 200 : percent = 200
        Case 201 To 250 : percent = 250
        Case 251 To 300 : percent = 300
        Case 301 To 400 : percent = 400
        Default         : percent = 500
    EndSelect
    _dpi_Init(percent)
  CompilerEndIf
EndProcedure

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;{ ENUM
  
  Enumeration
    ; MenuHeight()
    #PB_Menu_Height_DPIAware = 0
    #PB_Menu_Height = 1
    
    ; WindowWidth() & WindowHeight()
    #PB_Window_InnerCoordinate_DPIAware = -1
    #PB_Window_FrameCoordinate_DPIAware = -2
    
    ; CreateToolBar()
    #PB_ToolBar_StandardButton = 16
    
    ; ToolBarHeight()
    #PB_ToolBar_Height_DPIAware = 0
    #PB_ToolBar_Height = 1
    
    ; ToolBarImageButton()
    #PB_ToolBar_Image_Stretch = 2
    #PB_ToolBar_Image_Center = 3
    
    ; StatusBarHeight()
    #PB_StatusBar_Height_DPIAware = 0
    #PB_StatusBar_Height = 1
    
    ; GadgetWidth() & GadgetHeight()
    #PB_Gadget_ActualSize_DPIAware = -2
    #PB_Gadget_RequiredSize_DPIAware = -1
    
    ; GadgetX() & GadgetY()
    #PB_Gadget_ContainerCoordinate_DPIAware = -3
    #PB_Gadget_WindowCoordinate_DPIAware = -1
  EndEnumeration
  
;}

;{ FONT
  
  Procedure _dpi_LoadFont(id, name$, height, style)
    If (dpi_ScaleVert >= 1.25 And dpi_XPstyleDPI) Or OSVersion() < #PB_OS_Windows_Vista
      CompilerIf #PB_Compiler_Debugger
        Protected _dpi_ScaleDebug.f = dpi_ScaleVert / dpi_SysScale
        If dpi_XPstyleDPI
          Select _dpi_ScaleDebug * 100
            Case 83
              _dpi_ScaleDebug = 0.9
            Case 100
              _dpi_ScaleDebug = 1.0
            Case 120
              _dpi_ScaleDebug = 1.25
            Case 133
              _dpi_ScaleDebug = 1.3
            Case 160
              _dpi_ScaleDebug = 1.6
            Case 200
              _dpi_ScaleDebug = 2.0
            Case 333
              _dpi_ScaleDebug = 3.2
          EndSelect
        Else
          _dpi_ScaleDebug = dpi_ScaleVert
        EndIf
        ProcedureReturn LoadFont(id, name$, height * _dpi_ScaleDebug, style)
      CompilerElse
        ProcedureReturn LoadFont(id, name$, height, style)
      CompilerEndIf
    Else
      CompilerIf #PB_Compiler_Debugger
        If dpi_XPstyleDPI
          ProcedureReturn LoadFont(id, name$, height / dpi_SysScale, style)
        Else
          ProcedureReturn LoadFont(id, name$, dpi_CalcVert(height), style)
        EndIf
      CompilerElse
        ProcedureReturn LoadFont(id, name$, dpi_CalcVert(height), style)
      CompilerEndIf
    EndIf
  EndProcedure
  Macro LoadFont(id, name, height, style=0)
    _dpi_LoadFont(id, name, height, style)
  EndMacro
  
;}

;{ MENU
  
  Procedure _dpi_MenuHeight(flags)
    Select flags
      Case #PB_Menu_Height_DPIAware
        ProcedureReturn Round(MenuHeight() / dpi_ScaleVert, #PB_Round_Up)
      Default
        ProcedureReturn MenuHeight()
    EndSelect
  EndProcedure
  Macro MenuHeight(flags=#PB_Menu_Height_DPIAware)
    _dpi_MenuHeight(flags)
  EndMacro
  
;}

;{ WINDOW
  
  Procedure _dpi_OpenWindow(id, x, y, w, h, title$, flags, parentId)
    ProcedureReturn OpenWindow(id, x, y, dpi_CalcHorz(w), dpi_CalcVert(h), title$, flags, parentId)
  EndProcedure
  Macro OpenWindow(id, x, y, w, h, title, flags=0, parentId=0)
    _dpi_OpenWindow(id, x, y, w, h, title, flags, parentId)
  EndMacro
  
  Procedure _dpi_ResizeWindow(id, x, y, w, h)
    If x <> #PB_Ignore : x = dpi_CalcHorz(x) : EndIf
    If y <> #PB_Ignore : y = dpi_CalcVert(y) : EndIf
    If w <> #PB_Ignore : w = dpi_CalcHorz(w) : EndIf
    If h <> #PB_Ignore : h = dpi_CalcVert(h) : EndIf
    ProcedureReturn ResizeWindow(id, x, y, w, h)
  EndProcedure
  Macro ResizeWindow(id, x, y, w, h)
    _dpi_ResizeWindow(id, x, y, w, h)
  EndMacro
  
  Procedure _dpi_WindowBounds(id, minW, minH, maxW, maxH)
    If minW <> #PB_Ignore And minW <> #PB_Default : minW = dpi_CalcHorz(minW) : EndIf
    If minH <> #PB_Ignore And minH <> #PB_Default : minH = dpi_CalcVert(minH) : EndIf
    If maxW <> #PB_Ignore And maxW <> #PB_Default : maxW = dpi_CalcHorz(maxW) : EndIf
    If maxH <> #PB_Ignore And maxH <> #PB_Default : maxH = dpi_CalcVert(maxH) : EndIf
    ProcedureReturn WindowBounds(id, minW, minH, maxW, maxH)
  EndProcedure
  Macro WindowBounds(id, minW, minH, maxW, maxH)
    _dpi_WindowBounds(id, minW, minH, maxW, maxH)
  EndMacro
  
  Procedure _dpi_WindowHeight(id, flags)
    Select flags
      Case #PB_Window_InnerCoordinate_DPIAware
        flags + 2
        ProcedureReturn Round(WindowHeight(id, flags) / dpi_ScaleVert, #PB_Round_Up)
      Case #PB_Window_FrameCoordinate_DPIAware
        flags + 2
        ProcedureReturn Round(WindowHeight(id, #PB_Window_InnerCoordinate) / dpi_ScaleVert, #PB_Round_Up) + (WindowHeight(id, #PB_Window_FrameCoordinate) - WindowHeight(id, #PB_Window_InnerCoordinate))
      Default
        ProcedureReturn WindowHeight(id, flags)
    EndSelect
  EndProcedure
  Macro WindowHeight(id, flags=#PB_Window_InnerCoordinate_DPIAware)
    _dpi_WindowHeight(id, flags)
  EndMacro
  
  Procedure _dpi_WindowWidth(id, flags)
    Select flags
      Case #PB_Window_InnerCoordinate_DPIAware
        flags + 2
        ProcedureReturn Round(WindowWidth(id, flags) / dpi_ScaleHorz, #PB_Round_Up)
      Case #PB_Window_FrameCoordinate_DPIAware
        flags + 2
        ProcedureReturn Round(WindowWidth(id, #PB_Window_InnerCoordinate) / dpi_ScaleHorz, #PB_Round_Up) + (WindowWidth(id, #PB_Window_FrameCoordinate) - WindowWidth(id, #PB_Window_InnerCoordinate))
      Default
        ProcedureReturn WindowWidth(id, flags)
    EndSelect
  EndProcedure
  Macro WindowWidth(id, flags=#PB_Window_InnerCoordinate_DPIAware)
    _dpi_WindowWidth(id, flags)
  EndMacro
  
;}

;{ TOOLBAR
  
  Define _dpi_ToolBar_PixelSize, _dpi_ToolBar_Layout, _dpi_ToolBar_StandardButton
  
  CompilerIf Not Defined(PB_ToolBar_Small, #PB_Constant)
    #PB_ToolBar_Small      = 1
    #PB_ToolBar_Large      = 2
    #PB_ToolBar_Text       = 4
    #PB_ToolBar_InlineText = 8
  CompilerEndIf
  
  Procedure _dpi_CreateToolBar(id, winId, flags, fixedHeight)
    Shared _dpi_ToolBar_PixelSize, _dpi_ToolBar_Layout, _dpi_ToolBar_StandardButton
    If flags & #PB_ToolBar_StandardButton
      flags & ~#PB_ToolBar_StandardButton
      _dpi_ToolBar_StandardButton = #True
    Else
      _dpi_ToolBar_StandardButton = #False
    EndIf
    CompilerIf #PB_Compiler_Version >= 560
      Protected ret = CreateToolBar(id, winId, flags)
    CompilerElse
      Protected ret = CreateToolBar(id, winId)
    CompilerEndIf
    If ret
      If id = #PB_Any : id = ret : EndIf
      Protected gdi32 = OpenLibrary(#PB_Any, "gdi32.dll")
      If gdi32
        Protected tmpDC = GetDC_(winId)
        _dpi_ToolBar_Layout = CallFunction(gdi32, "GetLayout", tmpDC)
        ReleaseDC_(winId, tmpDC)
        CloseLibrary(gdi32)
      EndIf
      If flags & #PB_ToolBar_Large = #PB_ToolBar_Large
        If fixedHeight = 0
          _dpi_ToolBar_PixelSize = 24
        Else
          _dpi_ToolBar_PixelSize = (fixedHeight-6) / dpi_ScaleVert
        EndIf
      Else
        _dpi_ToolBar_PixelSize = 16
      EndIf
      If _dpi_ToolBar_StandardButton = 0
        ImageList_SetIconSize_(SendMessage_(ToolBarID(id), #TB_GETIMAGELIST, 0, 0), dpi_CalcHorz(_dpi_ToolBar_PixelSize), dpi_CalcVert(_dpi_ToolBar_PixelSize))
      EndIf
    EndIf
    ProcedureReturn ret
  EndProcedure
  Macro CreateToolBar(id, winId, flags=#PB_ToolBar_Small, fixedHeight=0)
    _dpi_CreateToolBar(id, winId, flags, fixedHeight)
  EndMacro
  
  Procedure _dpi_ToolBarHeight(id, flags)
    Select flags
      Case #PB_ToolBar_Height_DPIAware
        ProcedureReturn Round(ToolBarHeight(id) / dpi_ScaleVert, #PB_Round_Up)
      Default
        ProcedureReturn ToolBarHeight(id)
    EndSelect
  EndProcedure
  Macro ToolBarHeight(id, flags=#PB_ToolBar_Height_DPIAware)
    _dpi_ToolBarHeight(id, flags)
  EndMacro
  
  Procedure _dpi_ToolBarImageButton(id, imgId, mode, text$, flag)
    Shared _dpi_ToolBar_PixelSize, _dpi_ToolBar_Layout, _dpi_ToolBar_StandardButton
    If imgId <> 0 And _dpi_ToolBar_StandardButton = 0
      Protected tmpImg = CreateImage(#PB_Any, dpi_CalcHorz(_dpi_ToolBar_PixelSize), dpi_CalcVert(_dpi_ToolBar_PixelSize), 32, #PB_Image_Transparent)
      Protected tmpImgNr = _dpi_ImageIDtoImageNr(imgId)
      If flag = #PB_ToolBar_Image_Stretch
        If dpi_CalcVert(_dpi_ToolBar_PixelSize) >= 24
          If ImageWidth(tmpImg) >= 32
            ResizeImage(tmpImgNr, ImageWidth(tmpImg) * 0.54, ImageHeight(tmpImg) * 0.54, #PB_Image_Raw)
          EndIf
        EndIf
      EndIf
      Protected hdc = StartDrawing(ImageOutput(tmpImg))
      DrawingMode(#PB_2DDrawing_AlphaBlend)
      DrawImage(ImageID(tmpImgNr), (OutputWidth() - ImageWidth(tmpImgNr)) * 0.5, (OutputHeight() - ImageHeight(tmpImgNr)) * 0.5)
      If _dpi_ToolBar_Layout
        StretchBlt_(hdc, OutputWidth(), 0, -OutputWidth(), OutputHeight(), hdc, 0, 0, OutputWidth(), OutputHeight(), #SRCCOPY)
      EndIf
      :StopDrawing()
      FreeImage(tmpImgNr)
      CompilerIf #PB_Compiler_Version >= 560
        ProcedureReturn ToolBarImageButton(id, ImageID(tmpImg), mode, text$)
      CompilerElse
        ProcedureReturn ToolBarImageButton(id, ImageID(tmpImg), mode)
      CompilerEndIf
    EndIf
    CompilerIf #PB_Compiler_Version >= 560
      ProcedureReturn ToolBarImageButton(id, imgId, mode, text$)
    CompilerElse
      ProcedureReturn ToolBarImageButton(id, imgId, mode)
    CompilerEndIf
  EndProcedure
  Macro ToolBarImageButton(id, imgId, mode=#PB_ToolBar_Normal, text=#Null$, flag=#PB_ToolBar_Image_Center)
    _dpi_ToolBarImageButton(id, imgId, mode, text, flag)
  EndMacro
  
  Procedure _dpi_ToolBarStandardButton(id, btnIco, mode, text$)
    CompilerIf #PB_Compiler_Version >= 560
      ProcedureReturn ToolBarStandardButton(id, btnIco, mode, text$)
    CompilerElse
      ProcedureReturn ToolBarStandardButton(id, btnIco, mode)
    CompilerEndIf
  EndProcedure
  Macro ToolBarStandardButton(id, btnIco, mode=#PB_ToolBar_Normal, text=#Null$)
    _dpi_ToolBarStandardButton(id, btnIco, mode, text)
  EndMacro
  
;}

;{ STATUSBAR
  
  Procedure _dpi_AddStatusBarField(width)
    If width <> #PB_Ignore : width = dpi_CalcHorz(width) : EndIf
    ProcedureReturn AddStatusBarField(width)
  EndProcedure
  Macro AddStatusBarField(width)
    _dpi_AddStatusBarField(width)
  EndMacro
  
  Procedure _dpi_CreateStatusBar(id, winId)
    Protected ret = CreateStatusBar(id, winId)
    CompilerIf #PB_Compiler_Debugger
      If ret
        If id = #PB_Any : id = ret : EndIf
        SendMessage_(StatusBarID(id), #SB_SETMINHEIGHT, dpi_CalcVert(StatusBarHeight(id) / 1.3), 0)
        SendMessage_(StatusBarID(id), #WM_SIZE, 0, 0)
        ;Protected ncm.NONCLIENTMETRICS\cbSize = SizeOf(NONCLIENTMETRICS)
        ;SystemParametersInfo_(#SPI_GETNONCLIENTMETRICS, SizeOf(NONCLIENTMETRICS), @ncm, 0)
        ;Protected _dpi_StatusBarFontName$ = PeekS(@ncm\lfStatusFont\lfFaceName[0])
        ;Protected _dpi_StatusBarFontHeight = (-ncm\lfStatusFont\lfHeight * 72.0) / (dpi_ScaleVert * 96.0)
        ;SendMessage_(StatusBarID(id), #WM_SETFONT, FontID(LoadFont(#PB_Any, _dpi_StatusBarFontName$, _dpi_StatusBarFontHeight * dpi_ScaleVert)), 0)
      EndIf
    CompilerEndIf
    ProcedureReturn ret
  EndProcedure
  Macro CreateStatusBar(id, winId)
    _dpi_CreateStatusBar(id, winId)
  EndMacro
  
  Procedure _dpi_StatusBarHeight(id, flags)
    Select flags
      Case #PB_StatusBar_Height_DPIAware
        ProcedureReturn Round(StatusBarHeight(id) / dpi_ScaleVert, #PB_Round_Up)
      Default
        ProcedureReturn StatusBarHeight(id)
    EndSelect
  EndProcedure
  Macro StatusBarHeight(id, flags=#PB_StatusBar_Height_DPIAware)
    _dpi_StatusBarHeight(id, flags)
  EndMacro
  
;}

;{ CONTROLS
  
  Procedure _dpi_AddGadgetColumn(id, pos, title$, cWidth)
    ProcedureReturn AddGadgetColumn(id, pos, title$, dpi_CalcHorz(cWidth))
  EndProcedure
  Macro AddGadgetColumn(id, pos, title, cWidth)
    _dpi_AddGadgetColumn(id, pos, title, cWidth)
  EndMacro
  
  Procedure _dpi_ButtonGadget(id, x, y, w, h, text$, flags)
    ProcedureReturn ButtonGadget(id, dpi_CalcHorz(x), dpi_CalcVert(y), dpi_CalcHorz(w), dpi_CalcVert(h), text$, flags)
  EndProcedure
  Macro ButtonGadget(id, x, y, w, h, text, flags=0)
    _dpi_ButtonGadget(id, x, y, w, h, text, flags)
  EndMacro
  
  Procedure _dpi_ButtonImageGadget(id, x, y, w, h, imageId, flags)
    ProcedureReturn ButtonImageGadget(id, dpi_CalcHorz(x), dpi_CalcVert(y), dpi_CalcHorz(w), dpi_CalcVert(h), imageId, flags)
  EndProcedure
  Macro ButtonImageGadget(id, x, y, w, h, imageId, flags=0)
    _dpi_ButtonImageGadget(id, x, y, w, h, imageId, flags)
  EndMacro
  
  Procedure _dpi_CalendarGadget(id, x, y, w, h, date, flags)
    ProcedureReturn CalendarGadget(id, dpi_CalcHorz(x), dpi_CalcVert(y), dpi_CalcHorz(w), dpi_CalcVert(h), date, flags)
  EndProcedure
  Macro CalendarGadget(id, x, y, w, h, date=0, flags=0)
    _dpi_CalendarGadget(id, x, y, w, h, date, flags)
  EndMacro
  
  Procedure _dpi_CanvasGadget(id, x, y, w, h, flags)
    ProcedureReturn CanvasGadget(id, dpi_CalcHorz(x), dpi_CalcVert(y), dpi_CalcHorz(w), dpi_CalcVert(h), flags)
  EndProcedure
  Macro CanvasGadget(id, x, y, w, h, flags=0)
    _dpi_CanvasGadget(id, x, y, w, h, flags)
  EndMacro
  
  Procedure _dpi_CheckBoxGadget(id, x, y, w, h, text$, flags)
    ProcedureReturn CheckBoxGadget(id, dpi_CalcHorz(x), dpi_CalcVert(y), dpi_CalcHorz(w), dpi_CalcVert(h), text$, flags)
  EndProcedure
  Macro CheckBoxGadget(id, x, y, w, h, text, flags=0)
    _dpi_CheckBoxGadget(id, x, y, w, h, text, flags)
  EndMacro
  
  Procedure _dpi_ComboBoxGadget(id, x, y, w, h, flags)
    ProcedureReturn ComboBoxGadget(id, dpi_CalcHorz(x), dpi_CalcVert(y), dpi_CalcHorz(w), dpi_CalcVert(h), flags)
  EndProcedure
  Macro ComboBoxGadget(id, x, y, w, h, flags=0)
    _dpi_ComboBoxGadget(id, x, y, w, h, flags)
  EndMacro
  
  Procedure _dpi_ContainerGadget(id, x, y, w, h, flags)
    ProcedureReturn ContainerGadget(id, dpi_CalcHorz(x), dpi_CalcVert(y), dpi_CalcHorz(w), dpi_CalcVert(h), flags)
  EndProcedure
  Macro ContainerGadget(id, x, y, w, h, flags=0)
    _dpi_ContainerGadget(id, x, y, w, h, flags)
  EndMacro
  
  Procedure _dpi_DateGadget(id, x, y, w, h, mask$, date, flags)
    ProcedureReturn DateGadget(id, dpi_CalcHorz(x), dpi_CalcVert(y), dpi_CalcHorz(w), dpi_CalcVert(h), mask$, date, flags)
  EndProcedure
  Macro DateGadget(id, x, y, w, h, mask=#Null$, date=0, flags=0)
    _dpi_DateGadget(id, x, y, w, h, mask, date, flags)
  EndMacro
  
  Procedure _dpi_EditorGadget(id, x, y, w, h, flags)
    ProcedureReturn EditorGadget(id, dpi_CalcHorz(x), dpi_CalcVert(y), dpi_CalcHorz(w), dpi_CalcVert(h), flags)
  EndProcedure
  Macro EditorGadget(id, x, y, w, h, flags=0)
    _dpi_EditorGadget(id, x, y, w, h, flags)
  EndMacro
  
  Procedure _dpi_ExplorerComboGadget(id, x, y, w, h, dir$, flags)
    ProcedureReturn ExplorerComboGadget(id, dpi_CalcHorz(x), dpi_CalcVert(y), dpi_CalcHorz(w), dpi_CalcVert(h), dir$, flags)
  EndProcedure
  Macro ExplorerComboGadget(id, x, y, w, h, dir, flags=0)
    _dpi_ExplorerComboGadget(id, x, y, w, h, dir, flags)
  EndMacro
  
  Procedure _dpi_ExplorerListGadget(id, x, y, w, h, dir$, flags)
    ProcedureReturn ExplorerListGadget(id, dpi_CalcHorz(x), dpi_CalcVert(y), dpi_CalcHorz(w), dpi_CalcVert(h), dir$, flags)
  EndProcedure
  Macro ExplorerListGadget(id, x, y, w, h, dir, flags=0)
    _dpi_ExplorerListGadget(id, x, y, w, h, dir, flags)
  EndMacro
  
  Procedure _dpi_ExplorerTreeGadget(id, x, y, w, h, dir$, flags)
    ProcedureReturn ExplorerTreeGadget(id, dpi_CalcHorz(x), dpi_CalcVert(y), dpi_CalcHorz(w), dpi_CalcVert(h), dir$, flags)
  EndProcedure
  Macro ExplorerTreeGadget(id, x, y, w, h, dir, flags=0)
    _dpi_ExplorerTreeGadget(id, x, y, w, h, dir, flags)
  EndMacro
  
  Procedure _dpi_FrameGadget(id, x, y, w, h, text$, flags)
    ProcedureReturn FrameGadget(id, dpi_CalcHorz(x), dpi_CalcVert(y), dpi_CalcHorz(w), dpi_CalcVert(h), text$, flags)
  EndProcedure
  Macro FrameGadget(id, x, y, w, h, text, flags=0)
    _dpi_FrameGadget(id, x, y, w, h, text, flags)
  EndMacro
  
  Procedure _dpi_GadgetHeight(id, flags)
    Select flags
      Case #PB_Gadget_ActualSize_DPIAware, #PB_Gadget_RequiredSize_DPIAware
        flags + 2
        ProcedureReturn Round(GadgetHeight(id, flags) / dpi_ScaleVert, #PB_Round_Up)
      Default
        ProcedureReturn GadgetHeight(id, flags)
    EndSelect
  EndProcedure
  Macro GadgetHeight(id, flags=#PB_Gadget_ActualSize_DPIAware)
    _dpi_GadgetHeight(id, flags)
  EndMacro
  
  Procedure _dpi_GadgetWidth(id, flags)
    Select flags
      Case #PB_Gadget_ActualSize_DPIAware, #PB_Gadget_RequiredSize_DPIAware
        flags + 2
        ProcedureReturn Round(GadgetWidth(id, flags) / dpi_ScaleHorz, #PB_Round_Up)
      Default
        ProcedureReturn GadgetWidth(id, flags)
    EndSelect
  EndProcedure
  Macro GadgetWidth(id, flags=#PB_Gadget_ActualSize_DPIAware)
    _dpi_GadgetWidth(id, flags)
  EndMacro
  
  Procedure __GadgetX(id, flags)
    ;;; fix: GadgetX() returning wrong values if the UI layout is RightToLeft oriented
    Protected gRect.RECT
    GetWindowRect_(GadgetID(id), gRect.RECT)
    Select flags
      Case #PB_Gadget_ContainerCoordinate
        MapWindowPoints_(0, GetAncestor_(GadgetID(id), #GA_PARENT), gRect, 2)
      Case #PB_Gadget_WindowCoordinate
        MapWindowPoints_(0, GetAncestor_(GadgetID(id), #GA_ROOT), gRect, 2)
    EndSelect
    ProcedureReturn gRect\left
  EndProcedure
  Macro _GadgetX(id, flags=#PB_Gadget_ContainerCoordinate)
    __GadgetX(id, flags)
  EndMacro
  
  Procedure __GadgetY(id, flags)
    ;;; fix: GadgetY() returning wrong values if the UI layout is RightToLeft oriented
    Protected gRect.RECT
    GetWindowRect_(GadgetID(id), gRect.RECT)
    Select flags
      Case #PB_Gadget_ContainerCoordinate
        MapWindowPoints_(0, GetAncestor_(GadgetID(id), #GA_PARENT), gRect, 2)
      Case #PB_Gadget_WindowCoordinate
        MapWindowPoints_(0, GetAncestor_(GadgetID(id), #GA_ROOT), gRect, 2)
    EndSelect
    ProcedureReturn gRect\top
  EndProcedure
  Macro _GadgetY(id, flags=#PB_Gadget_ContainerCoordinate)
    __GadgetY(id, flags)
  EndMacro
  
  Procedure _dpi_GadgetX(id, flags)
    Select flags
      Case #PB_Gadget_ContainerCoordinate_DPIAware, #PB_Gadget_WindowCoordinate_DPIAware
        flags + 3
        ProcedureReturn Round(_GadgetX(id, flags) / dpi_ScaleHorz, #PB_Round_Up)
      Default
        ProcedureReturn _GadgetX(id, flags)
    EndSelect
  EndProcedure
  Macro GadgetX(id, flags=#PB_Gadget_ContainerCoordinate_DPIAware)
    _dpi_GadgetX(id, flags)
  EndMacro
  
  Procedure _dpi_GadgetY(id, flags)
    Select flags
      Case #PB_Gadget_ContainerCoordinate_DPIAware, #PB_Gadget_WindowCoordinate_DPIAware
        flags + 3
        ProcedureReturn Round(_GadgetY(id, flags) / dpi_ScaleVert, #PB_Round_Up)
      Default
        ProcedureReturn _GadgetY(id, flags)
    EndSelect
  EndProcedure
  Macro GadgetY(id, flags=#PB_Gadget_ContainerCoordinate_DPIAware)
    _dpi_GadgetY(id, flags)
  EndMacro
  
  Procedure _dpi_HyperLinkGadget(id, x, y, w, h, text$, color, flags)
    ProcedureReturn HyperLinkGadget(id, dpi_CalcHorz(x), dpi_CalcVert(y), dpi_CalcHorz(w), dpi_CalcVert(h), text$, color, flags)
  EndProcedure
  Macro HyperLinkGadget(id, x, y, w, h, text, color, flags=0)
    _dpi_HyperLinkGadget(id, x, y, w, h, text, color, flags)
  EndMacro
  
  Procedure _dpi_IPAddressGadget(id, x, y, w, h)
    ProcedureReturn IPAddressGadget(id, dpi_CalcHorz(x), dpi_CalcVert(y), dpi_CalcHorz(w), dpi_CalcVert(h))
  EndProcedure
  Macro IPAddressGadget(id, x, y, w, h)
    _dpi_IPAddressGadget(id, x, y, w, h)
  EndMacro
  
  Procedure _dpi_ImageGadget(id, x, y, w, h, ImageId, flags)
    ProcedureReturn ImageGadget(id, dpi_CalcHorz(x), dpi_CalcVert(y), dpi_CalcHorz(w), dpi_CalcVert(h), ImageId, flags)
  EndProcedure
  Macro ImageGadget(id, x, y, w, h, ImageId, flags=0)
    _dpi_ImageGadget(id, x, y, w, h, ImageId, flags)
  EndMacro
  
  Procedure _dpi_ListIconGadget(id, x, y, w, h, title$, cWidth, flags)
    ProcedureReturn ListIconGadget(id, dpi_CalcHorz(x), dpi_CalcVert(y), dpi_CalcHorz(w), dpi_CalcVert(h), title$, dpi_CalcHorz(cWidth), flags)
  EndProcedure
  Macro ListIconGadget(id, x, y, w, h, title, cWidth, flags=0)
    _dpi_ListIconGadget(id, x, y, w, h, title, cWidth, flags)
  EndMacro
  
  Procedure _dpi_ListViewGadget(id, x, y, w, h, flags)
    ProcedureReturn ListViewGadget(id, dpi_CalcHorz(x), dpi_CalcVert(y), dpi_CalcHorz(w), dpi_CalcVert(h), flags)
  EndProcedure
  Macro ListViewGadget(id, x, y, w, h, flags=0)
    _dpi_ListViewGadget(id, x, y, w, h, flags)
  EndMacro
  
  Procedure _dpi_MDIGadget(id, x, y, w, h, submenu, firstitem, flags)
    ProcedureReturn MDIGadget(id, dpi_CalcHorz(x), dpi_CalcVert(y), dpi_CalcHorz(w), dpi_CalcVert(h), submenu, firstitem, flags)
  EndProcedure
  Macro MDIGadget(id, x, y, w, h, submenu, firstitem, flags=0)
    _dpi_MDIGadget(id, x, y, w, h, submenu, firstitem, flags)
  EndMacro
  
  Procedure _dpi_OpenGLGadget(id, x, y, w, h, flags)
    ProcedureReturn OpenGLGadget(id, dpi_CalcHorz(x), dpi_CalcVert(y), dpi_CalcHorz(w), dpi_CalcVert(h), flags)
  EndProcedure
  Macro OpenGLGadget(id, x, y, w, h, flags=0)
    _dpi_OpenGLGadget(id, x, y, w, h, flags)
  EndMacro
  
  Procedure _dpi_OptionGadget(id, x, y, w, h, text$)
    ProcedureReturn OptionGadget(id, dpi_CalcHorz(x), dpi_CalcVert(y), dpi_CalcHorz(w), dpi_CalcVert(h), text$)
  EndProcedure
  Macro OptionGadget(id, x, y, w, h, text)
    _dpi_OptionGadget(id, x, y, w, h, text)
  EndMacro
  
  Procedure _dpi_PanelGadget(id, x, y, w, h)
    ProcedureReturn PanelGadget(id, dpi_CalcHorz(x), dpi_CalcVert(y), dpi_CalcHorz(w), dpi_CalcVert(h))
  EndProcedure
  Macro PanelGadget(id, x, y, w, h)
    _dpi_PanelGadget(id, x, y, w, h)
  EndMacro
  
  Procedure _dpi_ProgressBarGadget(id, x, y, w, h, min, max, flags)
    ProcedureReturn ProgressBarGadget(id, dpi_CalcHorz(x), dpi_CalcVert(y), dpi_CalcHorz(w), dpi_CalcVert(h), min, max, flags)
  EndProcedure
  Macro ProgressBarGadget(id, x, y, w, h, min, max, flags=0)
    _dpi_ProgressBarGadget(id, x, y, w, h, min, max, flags)
  EndMacro
  
  Procedure _dpi_ResizeGadget(id, x, y, w, h)
    If x <> #PB_Ignore : x = dpi_CalcHorz(x) : EndIf
    If y <> #PB_Ignore : y = dpi_CalcVert(y) : EndIf
    If w <> #PB_Ignore : w = dpi_CalcHorz(w) : EndIf
    If h <> #PB_Ignore : h = dpi_CalcVert(h) : EndIf
    ProcedureReturn ResizeGadget(id, x, y, w, h)
  EndProcedure
  Macro ResizeGadget(id, x, y, w, h)
    _dpi_ResizeGadget(id, x, y, w, h)
  EndMacro
  
  Procedure _dpi_ScrollAreaGadget(id, x, y, w, h, sw, sh, scrstep, flags)
    ProcedureReturn ScrollAreaGadget(id, dpi_CalcHorz(x), dpi_CalcVert(y), dpi_CalcHorz(w), dpi_CalcVert(h), dpi_CalcHorz(sw), dpi_CalcVert(sh), scrstep, flags)
  EndProcedure
  Macro ScrollAreaGadget(id, x, y, w, h, sw, sh, scrstep=30, flags=0)
    _dpi_ScrollAreaGadget(id, x, y, w, h, sw, sh, dpi_CalcHorz(scrstep), flags)
  EndMacro
  
  Procedure _dpi_ScrollBarGadget(id, x, y, w, h, min, max, lenght, flags)
    ProcedureReturn ScrollBarGadget(id, dpi_CalcHorz(x), dpi_CalcVert(y), dpi_CalcHorz(w), dpi_CalcVert(h), min, max, lenght, flags)
  EndProcedure
  Macro ScrollBarGadget(id, x, y, w, h, min, max, lenght, flags=0)
    _dpi_ScrollBarGadget(id, x, y, w, h, min, max, lenght, flags)
  EndMacro
  
  Procedure _dpi_ShortcutGadget(id, x, y, w, h, shortcut)
    ProcedureReturn ShortcutGadget(id, dpi_CalcHorz(x), dpi_CalcVert(y), dpi_CalcHorz(w), dpi_CalcVert(h), shortcut)
  EndProcedure
  Macro ShortcutGadget(id, x, y, w, h, shortcut)
    _dpi_ShortcutGadget(id, x, y, w, h, shortcut)
  EndMacro
  
  Procedure _dpi_SpinGadget(id, x, y, w, h, min, max, flags)
    ProcedureReturn SpinGadget(id, dpi_CalcHorz(x), dpi_CalcVert(y), dpi_CalcHorz(w), dpi_CalcVert(h), min, max, flags)
  EndProcedure
  Macro SpinGadget(id, x, y, w, h, min, max, flags=0)
    _dpi_SpinGadget(id, x, y, w, h, min, max, flags)
  EndMacro
  
  Procedure _dpi_SplitterGadget(id, x, y, w, h, gad1, gad2, flags)
    ProcedureReturn SplitterGadget(id, dpi_CalcHorz(x), dpi_CalcVert(y), dpi_CalcHorz(w), dpi_CalcVert(h), gad1, gad2, flags)
  EndProcedure
  Macro SplitterGadget(id, x, y, w, h, gad1, gad2, flags=0)
    _dpi_SplitterGadget(id, x, y, w, h, gad1, gad2, flags)
  EndMacro
  
  Procedure _dpi_StringGadget(id, x, y, w, h, text$, flags)
    ProcedureReturn StringGadget(id, dpi_CalcHorz(x), dpi_CalcVert(y), dpi_CalcHorz(w), dpi_CalcVert(h), text$, flags)
  EndProcedure
  Macro StringGadget(id, x, y, w, h, text, flags=0)
    _dpi_StringGadget(id, x, y, w, h, text, flags)
  EndMacro
  
  Procedure _dpi_TextGadget(id, x, y, w, h, text$, flags)
    ProcedureReturn TextGadget(id, dpi_CalcHorz(x), dpi_CalcVert(y), dpi_CalcHorz(w), dpi_CalcVert(h), text$, flags)
  EndProcedure
  Macro TextGadget(id, x, y, w, h, text, flags=0)
    _dpi_TextGadget(id, x, y, w, h, text, flags)
  EndMacro
  
  Procedure _dpi_TrackBarGadget(id, x, y, w, h, min, max, flags)
    ProcedureReturn TrackBarGadget(id, dpi_CalcHorz(x), dpi_CalcVert(y), dpi_CalcHorz(w), dpi_CalcVert(h), min, max, flags)
  EndProcedure
  Macro TrackBarGadget(id, x, y, w, h, min, max, flags=0)
    _dpi_TrackBarGadget(id, x, y, w, h, min, max, flags)
  EndMacro
  
  Procedure _dpi_TreeGadget(id, x, y, w, h, flags)
    ProcedureReturn TreeGadget(id, dpi_CalcHorz(x), dpi_CalcVert(y), dpi_CalcHorz(w), dpi_CalcVert(h), flags)
  EndProcedure
  Macro TreeGadget(id, x, y, w, h, flags=0)
    _dpi_TreeGadget(id, x, y, w, h, flags)
  EndMacro
  
  Procedure _dpi_WebGadget(id, x, y, w, h, url$)
    ProcedureReturn WebGadget(id, dpi_CalcHorz(x), dpi_CalcVert(y), dpi_CalcHorz(w), dpi_CalcVert(h), url$)
  EndProcedure
  Macro WebGadget(id, x, y, w, h, url)
    _dpi_WebGadget(id, x, y, w, h, url)
  EndMacro
  
;}

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

DisableExplicit

;{ DEMO
  
  CompilerIf #PB_Compiler_IsMainFile
    
    UsePNGImageDecoder()
    
    DataSection
      tb_new:   : IncludeBinary #PB_Compiler_Home + "Examples\Sources\Data\ToolBar\new.png"
      tb_open:  : IncludeBinary #PB_Compiler_Home + "Examples\Sources\Data\ToolBar\open.png"
      tb_save:  : IncludeBinary #PB_Compiler_Home + "Examples\Sources\Data\ToolBar\save.png"
      tb_help:  : IncludeBinary #PB_Compiler_Home + "Examples\Sources\Data\ToolBar\find.png"
      tb_about: : IncludeBinary #PB_Compiler_Home + "Examples\Sources\Data\ToolBar\paste.png"
    EndDataSection
    
    Global gWidth  = 76
    Global gHeight = 31
    Global gOffset = 4
    
    Procedure WindowResize()
      ResizeGadget(0, gOffset, gOffset + ToolBarHeight(0), #PB_Ignore, #PB_Ignore)
      ResizeGadget(1, WindowWidth(0) - gWidth - gOffset, gOffset + ToolBarHeight(0), #PB_Ignore, #PB_Ignore)
      ResizeGadget(2, WindowWidth(0) - gWidth - gOffset, WindowHeight(0) - gHeight - gOffset - StatusBarHeight(0) - MenuHeight(), #PB_Ignore, #PB_Ignore)
      ResizeGadget(3, gOffset, WindowHeight(0) - gHeight - gOffset - StatusBarHeight(0) - MenuHeight(), #PB_Ignore, #PB_Ignore)
      ResizeGadget(4, #PB_Ignore, #PB_Ignore, GadgetWidth(4, #PB_Gadget_RequiredSize_DPIAware), GadgetHeight(4, #PB_Gadget_RequiredSize_DPIAware))
      ResizeGadget(5, GadgetX(1) - GadgetWidth(5, #PB_Gadget_RequiredSize_DPIAware), #PB_Ignore, GadgetWidth(5, #PB_Gadget_RequiredSize_DPIAware), GadgetHeight(5, #PB_Gadget_RequiredSize_DPIAware))
      ResizeGadget(6, GadgetX(0) + GadgetWidth(0), GadgetY(0) + GadgetHeight(0) + GadgetHeight(5) + 1, GadgetX(1) - GadgetX(0) - GadgetWidth(0), GadgetY(3) - (GadgetY(0) + GadgetHeight(0) + GadgetHeight(4)) - 1)
    EndProcedure
    
    dpi_DebugUIscale(150)
    
    ;SetProcessDefaultLayout_(1)
    
    ;SetGadgetFont(#PB_Default, FontID(LoadFont(#PB_Any, "MS Shell Dlg 2", 8)))
    
    OpenWindow(0, 0, 0, 395, 275, "DPIAware.pbi   Scale: " + Str(dpi_ScaleHorz * 100) +  "%   DPI: " + Str(dpi_ScaleHorz * 96) + "  ", #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget|#PB_Window_ScreenCentered|#PB_Window_Invisible)
    SetWindowLongPtr_(WindowID(0), #GWL_STYLE, GetWindowLongPtr_(WindowID(0), #GWL_STYLE)|#WS_CLIPCHILDREN)
    WindowBounds(0, 395, 275, #PB_Ignore, #PB_Ignore)
    
    If CreateImageMenu(0, WindowID(0))
      MenuTitle(" File  ")
      MenuItem(1, "New " + Chr(9), ImageID(CatchImage(#PB_Any, ?tb_new)))
      MenuItem(2, "Open... " + Chr(9), ImageID(CatchImage(#PB_Any, ?tb_open)))
      MenuItem(3, "Save " + Chr(9), ImageID(CatchImage(#PB_Any, ?tb_save)))
      MenuBar()
      MenuItem(4, "Quit " + Chr(9))
      MenuTitle(" Help  ")
      MenuItem(5, "Help... " + Chr(9), ImageID(CatchImage(#PB_Any, ?tb_help)))
      MenuBar()
      MenuItem(6, "About " + Chr(9), ImageID(CatchImage(#PB_Any, ?tb_about)))
    EndIf
    
    If CreateToolBar(0, WindowID(0), #PB_ToolBar_Large|#PB_ToolBar_Text|#PB_ToolBar_InlineText, 34);[, fixedHeight]) 0 = auto., 24, ... (only with #PB_ToolBar_Large)
      SetWindowLongPtr_(ToolBarID(0), #GWL_STYLE, GetWindowLongPtr_(ToolBarID(0), #GWL_STYLE)|#WS_CLIPSIBLINGS|#CCS_NODIVIDER|#WS_BORDER)
      SetWindowPos_(ToolBarID(0), 0, 0, 0, 0, 0, #SWP_NOSIZE|#SWP_NOMOVE|#SWP_NOZORDER|#SWP_FRAMECHANGED)
      ToolBarImageButton(0, ImageID(CatchImage(#PB_Any, ?tb_new)), #PB_ToolBar_Normal, "New ", #PB_ToolBar_Image_Stretch)
      ToolBarImageButton(1, ImageID(CatchImage(#PB_Any, ?tb_open)), #PB_ToolBar_Normal, "Open... ", #PB_ToolBar_Image_Stretch)
      ToolBarImageButton(2, ImageID(CatchImage(#PB_Any, ?tb_save)), #PB_ToolBar_Normal, "Save ", #PB_ToolBar_Image_Stretch)
      ToolBarSeparator()
      ToolBarImageButton(3, ImageID(CatchImage(#PB_Any, ?tb_help)), #PB_ToolBar_Normal, "Help... ", #PB_ToolBar_Image_Stretch)
      ToolBarImageButton(4, ImageID(CatchImage(#PB_Any, ?tb_about)), #PB_ToolBar_Normal, "About ", #PB_ToolBar_Image_Stretch)
      CompilerIf #PB_Compiler_Version < 560
        ToolBarToolTip(0, 0, "New")
        ToolBarToolTip(0, 1, "Open...")
        ToolBarToolTip(0, 2, "Save")
        ToolBarToolTip(0, 3, "Help...")
        ToolBarToolTip(0, 4, "About")
      CompilerEndIf
    EndIf
    
    CreateStatusBar(0, WindowID(0))
    AddStatusBarField(gWidth + gOffset * 2)
    AddStatusBarField(#PB_Ignore)
    StatusBarText(0, 0, " Field 1 ")
    StatusBarText(0, 1, " Field 2 ")
    
    ButtonGadget(0, gOffset, gOffset + ToolBarHeight(0), gWidth, gHeight, " Button 1")
    ButtonGadget(1, WindowWidth(0) - gWidth - gOffset, gOffset + ToolBarHeight(0), gWidth, gHeight, " Button 2")
    ButtonGadget(2, WindowWidth(0) - gWidth - gOffset, WindowHeight(0) - gHeight - gOffset - StatusBarHeight(0), gWidth, gHeight, " Button 3")
    ButtonGadget(3, gOffset, WindowHeight(0) - gHeight - gOffset - StatusBarHeight(0), gWidth, gHeight, " Button 4")
    
    TextGadget(4, GadgetX(0) + GadgetWidth(0), GadgetY(0) + GadgetHeight(0), 100, 100, " Text 1 ") : SetGadgetColor(4, #PB_Gadget_BackColor, #Gray)
    ResizeGadget(4, #PB_Ignore, #PB_Ignore, GadgetWidth(4, #PB_Gadget_RequiredSize_DPIAware), GadgetHeight(4, #PB_Gadget_RequiredSize_DPIAware))
    
    TextGadget(5, 0, GadgetY(1) + GadgetHeight(1), 100, 100, " Text 2 ") : SetGadgetColor(5, #PB_Gadget_BackColor, #Gray)
    ResizeGadget(5, GadgetX(1) - GadgetWidth(5, #PB_Gadget_RequiredSize_DPIAware), #PB_Ignore, GadgetWidth(5, #PB_Gadget_RequiredSize_DPIAware), GadgetHeight(5, #PB_Gadget_RequiredSize_DPIAware))
    
    EditorGadget(6, GadgetX(0) + GadgetWidth(0), GadgetY(0) + GadgetHeight(0) + GadgetHeight(5) + 1, GadgetX(1) - GadgetX(0) - GadgetWidth(0), GadgetY(3) - (GadgetY(0) + GadgetHeight(0) + GadgetHeight(4)) - 1)
    SetGadgetText(6, "Scale: " + Str(dpi_ScaleHorz * 100) +  "%,  DPI: " + Str(dpi_ScaleHorz * 96) + Chr(10) + "XPstyleDPIscaling: " + dpi_XPstyleDPI)
    
    BindEvent(#PB_Event_SizeWindow, @WindowResize())
    HideWindow(0, 0)
    
    While WaitWindowEvent() ! #PB_Event_CloseWindow : Wend
    
  CompilerEndIf
  
;}


Last edited by chi on Tue Jun 13, 2017 8:06 am, edited 7 times in total.
Et cetera is my worst enemy
User avatar
chi
Addict
Addict
Posts: 1034
Joined: Sat May 05, 2007 5:31 pm
Location: Linz, Austria

Re: Automated DPI scaling system (DPIAware.pbi)

Post by chi »

Updated to Version 1.1
Et cetera is my worst enemy
User avatar
chi
Addict
Addict
Posts: 1034
Joined: Sat May 05, 2007 5:31 pm
Location: Linz, Austria

Re: Automated DPI scaling system (DPIAware.pbi)

Post by chi »

Updated to Version 1.2
Et cetera is my worst enemy
User avatar
Kukulkan
Addict
Addict
Posts: 1352
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

Re: Automated DPI scaling system (DPIAware.pbi)

Post by Kukulkan »

Hi Chi,

this is great, but Windows only, right? So sad that Fred is not adding it native...
User avatar
chi
Addict
Addict
Posts: 1034
Joined: Sat May 05, 2007 5:31 pm
Location: Linz, Austria

Re: Automated DPI scaling system (DPIAware.pbi)

Post by chi »

Yup, Windows only for now... It's a start ;)
Et cetera is my worst enemy
User avatar
chi
Addict
Addict
Posts: 1034
Joined: Sat May 05, 2007 5:31 pm
Location: Linz, Austria

Re: Automated DPI scaling system (DPIAware.pbi)

Post by chi »

Updated to Version 1.3
Et cetera is my worst enemy
DarkDragon
Addict
Addict
Posts: 2228
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Re: Automated DPI scaling system (DPIAware.pbi)

Post by DarkDragon »

Good start! Shouldn't it also include a system font size? I mean the user can usually change the size of texts system wide, can't (s)he? What happens if the Window is moved to another display with different DPI?
bye,
Daniel
User avatar
chi
Addict
Addict
Posts: 1034
Joined: Sat May 05, 2007 5:31 pm
Location: Linz, Austria

Re: Automated DPI scaling system (DPIAware.pbi)

Post by chi »

Shouldn't it also include a system font size? I mean the user can usually change the size of texts system wide, can't (s)he?
So that we can change the size of the menu/toolbar font in debug mode too? Don't know if I understand...
What happens if the Window is moved to another display with different DPI?
Already working on Per-Monitor DPI introduced in Win8.1 and thinking about to include Per-Monitor v2 (Win10) as well.
Et cetera is my worst enemy
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Re: Automated DPI scaling system (DPIAware.pbi)

Post by Fluid Byte »

Not enough semicolons for me
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
User avatar
chi
Addict
Addict
Posts: 1034
Joined: Sat May 05, 2007 5:31 pm
Location: Linz, Austria

Re: Automated DPI scaling system (DPIAware.pbi)

Post by chi »

Fluid Byte wrote:Not enough semicolons for me
Then I'm deeply sorry to inform you that I have changed the semicolons to slashes in the next version... Enjoy 'em as long as they're fresh ;)

Sneak Peek:

Code: Select all

;////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
;////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
;// DPIAware.pbi ////////////////////////////////////////////////////////////////////////////////////////////////////////
;////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Et cetera is my worst enemy
DarkDragon
Addict
Addict
Posts: 2228
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Re: Automated DPI scaling system (DPIAware.pbi)

Post by DarkDragon »

chi wrote:
Shouldn't it also include a system font size? I mean the user can usually change the size of texts system wide, can't (s)he?
So that we can change the size of the menu/toolbar font in debug mode too? Don't know if I understand...
I've just checked it, it seems windows does this automatically. On android there is a difference between DP and SP unit. I wanted to ask whether you've respected the system wide font scaling in your calculations, but I tested it on Windows and it seems windows scaled everything itself.
bye,
Daniel
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4749
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Automated DPI scaling system (DPIAware.pbi)

Post by Fangbeast »

chi wrote:
Fluid Byte wrote:Not enough semicolons for me
Then I'm deeply sorry to inform you that I have changed the semicolons to slashes in the next version... Enjoy 'em as long as they're fresh ;)

Sneak Peek:

Code: Select all

;////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
;////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
;// DPIAware.pbi ////////////////////////////////////////////////////////////////////////////////////////////////////////
;////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/me falls off the chair laughing and hopes that devious Bericko didn't see him.
Amateur Radio, D-STAR/VK3HAF
User avatar
chi
Addict
Addict
Posts: 1034
Joined: Sat May 05, 2007 5:31 pm
Location: Linz, Austria

Re: Automated DPI scaling system (DPIAware.pbi)

Post by chi »

DarkDragon wrote:I've just checked it, it seems windows does this automatically. On android there is a difference between DP and SP unit. I wanted to ask whether you've respected the system wide font scaling in your calculations, but I tested it on Windows and it seems windows scaled everything itself.
No such thing on Windows. We just need to retrieve the systems default font (always 96 DPI) and multiply it with our scaling factor (e.g. 96 DPI font height = 8, 144 DPI font height = 8*144/96 = 12)
Et cetera is my worst enemy
DarkDragon
Addict
Addict
Posts: 2228
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Re: Automated DPI scaling system (DPIAware.pbi)

Post by DarkDragon »

chi wrote:
DarkDragon wrote:I've just checked it, it seems windows does this automatically. On android there is a difference between DP and SP unit. I wanted to ask whether you've respected the system wide font scaling in your calculations, but I tested it on Windows and it seems windows scaled everything itself.
No such thing on Windows. We just need to retrieve the systems default font (always 96 DPI) and multiply it with our scaling factor (e.g. 96 DPI font height = 8, 144 DPI font height = 8*144/96 = 12)
96 DPI is not the font size, it is the display's physical dots per inch. However on other operating systems you also have to respect a font size, e.g. if you are not able to see well, you still want the text to be displayed with 96DPI, but bigger. Windows however just scales the whole image somehow and it becomes blurry.
bye,
Daniel
User avatar
chi
Addict
Addict
Posts: 1034
Joined: Sat May 05, 2007 5:31 pm
Location: Linz, Austria

Re: Automated DPI scaling system (DPIAware.pbi)

Post by chi »

96 DPI is not the font size, it is the display's physical dots per inch.
Duh! :?
However on other operating systems you also have to respect a font size, e.g. if you are not able to see well, you still want the text to be displayed with 96DPI, but bigger. Windows however just scales the whole image somehow and it becomes blurry.
If you don't specify a different font at the beginning of you PB app, you'll use the default font "MS Shell Dlg" with a height of 8 (on a 96 DPI system). If you then switch your system to 150% (144 DPI) and you didn't set your app DPI-Aware, you'll end up with a blurry scaled image. However, if you set your app DPI-Aware and handle some internal calculations (like DPIAware.pbi does), not only the UI elements are scaled, but also the font size will be scaled and rendered 150% bigger (height 12). The font is crisp... :D. And if you do specify a different font, the size of that font will be scaled accordingly too. How much different is it handled on other OS? I'm just familiar with Windows ^^
Et cetera is my worst enemy
Post Reply