Module ScaleGadgets

Share your advanced PureBasic knowledge/code with the community.
User avatar
mk-soft
Always Here
Always Here
Posts: 5389
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Module ScaleGadgets

Post by mk-soft »

I don't know if my module's tired.

But it is interesting how some microsoft controls like the Combo react to too small sizes.
With MacOS you cannot influence the height of the combo. Under Linux it is.

Under macOS the button size can be arbitrary like with Window.
No matter how big the font is
In Linux, all gadget have a minimum height. The minimum width depending on the text.

As you have shown yourself, you can limit the minimum size of windows, which you should do.

The problem with the lines from the ListIcon only occurs with the ms control listview. But this is gone as soon as the list is filled.
Under macOS these are displayed correctly. Under Linux there are lines only if this was filled.

As you can see, I don't invent a new gadget here, but only calculate the new sizes of the gadgets to be changed.
This can certainly be improved as well, as you suggested limiting the minimum size of the gadgets.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
mk-soft
Always Here
Always Here
Posts: 5389
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Module ScaleGadgets

Post by mk-soft »

Update v0.21
- Added ScaleUnregisterGadget
- Bugfix ResizeGadget

:wink:
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
mk-soft
Always Here
Always Here
Posts: 5389
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Module ScaleGadgets

Post by mk-soft »

Update v0.23
- Change optional parameter from SetScale and SetGadgetScale. Added Optional Scale Factor for Font
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
mk-soft
Always Here
Always Here
Posts: 5389
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Module ScaleGadgets

Post by mk-soft »

Update v0.24
- Some optimization
- Bugfix memory leak
- Reduction of flicker effects on windows

Update v0.25
- Added GetDynamicScaleXY. Returns the current dynamic scaling of ScaleAllGadgets

For example, if you use the GFX_Wizzard_BF gadgets on Windows 7, the flicker effects will have gone back very well.
These problems with the flicker effects don't occur under Windows 10, because internally the update of the control is processed differently.

Tip for update many Gadgets under Windows 7.

1st Disable Redraw from Window ; SendMessage_(WindowID(Window), #WM_SETREDRAW, 0, 0)
2nd Update all gadget
3rd Enable Redraw from Window ; SendMessage_(WindowID(Window), #WM_SETREDRAW, 1, 0)
4th Refresh window ; InvalidateRect_(WindowID(Window), 0, 1)
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
m4u
New User
New User
Posts: 5
Joined: Mon Dec 31, 2018 8:47 am

Re: Module ScaleGadgets

Post by m4u »

Marvelous. Thank you.
User avatar
mk-soft
Always Here
Always Here
Posts: 5389
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Module ScaleGadgets

Post by mk-soft »

Thank m4u

Update v0.26
- Added SetScaleMode(Mode) ; Set mode for result of position and size from windows and gadgets*

* With SetScaleMode determines how the position and large of the window or gadgets the values are returned,
when calling WindowWidth, WindowHeight, GadgetX, etc.

There are three modes:
- #ScaleModeReal: Returns the current real values.
- #ScaleModeScaled (Default): Returns the values on the factor 1.0 independently of the scaling with SetScale.
- #ScaleModeDynamic: Returns the values to the factor 1.0 independent of the scaling with SetScale and when using ScaleAllGadgets.

Thus, new positions and sizes of gadgets can be calculated more easily...

Example

Code: Select all

;-TOP

; Example compiler options 'Enable DPI-Aware'

IncludeFile "Modul_ScaleGadgets.pb"

UseModule ScaleGadgets

Enumeration Window 1
  #Main
EndEnumeration

Enumeration Gadget
  #Editor
  #Container
  #ButtonB0
  #ButtonB1
  #ButtonB2
EndEnumeration

Enumeration MenuItem
  #New
  #Load
  #Save
  #Exit
EndEnumeration

Enumeration StatusBar
  #StatusBar
EndEnumeration

; -----------------------------------------------------------------

Global ExitApplication

Global dpi.f = 1.25 ;DesktopResolutionX()
SetScale(dpi)
;SetScale(1366.0/1920.0, 1.0)
;SetScale(1366.0/1920.0)

; -----------------------------------------------------------------

Procedure GetStatus(Gadget)
  Protected x, y, dx, dy, text.s
  
  SetScaleMode(#ScaleModeReal)
  x = GadgetX(Gadget)
  y = GadgetY(Gadget)
  dx = GadgetWidth(Gadget)
  dy = GadgetHeight(Gadget)
  text = "R = " + Str(x) + "/" + Str(y) + " - " + Str(dx) + "*" + Str(dy)
  StatusBarText(#StatusBar, 1, text)
  SetScaleMode(#ScaleModeScaled)
  x = GadgetX(Gadget)
  y = GadgetY(Gadget)
  dx = GadgetWidth(Gadget)
  dy = GadgetHeight(Gadget)
  text = "S = " + x + "/" + y + " - " + dx + "*" + dy
  StatusBarText(#StatusBar, 2, text)
  SetScaleMode(#ScaleModeDynamic)
  x = GadgetX(Gadget)
  y = GadgetY(Gadget)
  dx = GadgetWidth(Gadget)
  dy = GadgetHeight(Gadget)
  text = "D = " + x + "/" + y + " - " + dx + "*" + dy
  StatusBarText(#StatusBar, 3, text)
EndProcedure

; -----------------------------------------------------------------

Procedure DoSizeWindow()
  ScaleAllGadgets(#Main, MenuHeight() + StatusBarHeight(#StatusBar))
  GetStatus(#Editor)
EndProcedure

; -----------------------------------------------------------------

Procedure OpenMain(x = 10, y = 10, width = 550, height = 415)
  OpenWindow(#Main, x, y, width, height + MenuHeight(), "Example ScaleGadgets DPI", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget)
  
  If CreateMenu(0, WindowID(#Main))
    ; Mac Menu´s
    CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
      MenuItem(#PB_Menu_About, "")
      MenuItem(#PB_Menu_Preferences, "")
      MenuItem(#PB_Menu_Quit, "")
    CompilerEndIf
    MenuTitle("&File")
    MenuItem(#New, "&New")
    MenuItem(#Load, "&Load")
    MenuItem(#Save, "&Save")
    MenuBar()
    MenuItem(#Exit, "&Exit")
  EndIf
  
  CreateStatusBar(#StatusBar, WindowID(#Main))
  AddStatusBarField(180)
  AddStatusBarField(150)
  AddStatusBarField(150)
  AddStatusBarField(150)
  AddStatusBarField(#PB_Ignore)
  
  StatusBarText(#StatusBar, 0, "ScaleGadgets: DPI = " + StrF(DPI *100) + "%")
  
  EditorGadget(#Editor, 
               10, 
               10, 
               WindowWidth(#Main) - 20, 
               WindowHeight(#Main) - MenuHeight() - StatusBarHeight(#StatusBar) - 70)
  SetGadgetText(#Editor, "I like Purebasic!")
  ContainerGadget(#Container, 
                  10, 
                  WindowHeight(#Main) - MenuHeight() - StatusBarHeight(#StatusBar) - 50, 
                  WindowWidth(#Main) - 20, 
                  50, 
                  #PB_Container_Single)
  ButtonGadget(#ButtonB0, 10, 10, 160, 30, "Smaller")
  ButtonGadget(#ButtonB1, 180, 10, 170, 30, "Reset")
  ButtonGadget(#ButtonB2, 360, 10, 160, 30, "Bigger")
  CloseGadgetList()
EndProcedure

Define x, y, dx, dy
Define x1, y1, dx1, dy1

OpenMain()
BindEvent(#PB_Event_SizeWindow, @DoSizeWindow())
GetStatus(#Editor)

SetScaleMode(#ScaleModeDynamic)
x1 = GadgetX(#Editor)
y1 = GadgetY(#Editor)
dx1 = GadgetWidth(#Editor)
dy1 = GadgetHeight(#Editor)

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      ExitApplication = 1
    Case #PB_Event_Gadget
      Select EventGadget()
        Case #ButtonB0
          SetScaleMode(#ScaleModeDynamic)
          x = GadgetX(#Editor) + 10
          y = GadgetY(#Editor) + 5
          dx = GadgetWidth(#Editor) - 20
          dy = GadgetHeight(#Editor) - 10
          ResizeGadget(#Editor, x, y, dx, dy)
          GetStatus(#Editor)
          
        Case #ButtonB1
          SetScaleMode(#ScaleModeDynamic)
          ResizeGadget(#Editor, x1, y1, dx1, dy1)
          GetStatus(#Editor)
          
        Case #ButtonB2
          SetScaleMode(#ScaleModeDynamic)
          x = GadgetX(#Editor) - 10
          y = GadgetY(#Editor) - 5
          dx = GadgetWidth(#Editor) + 20
          dy = GadgetHeight(#Editor) + 10
          ResizeGadget(#Editor, x, y, dx, dy)
          GetStatus(#Editor)
      EndSelect
  EndSelect
Until ExitApplication

End
[/size]
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
mk-soft
Always Here
Always Here
Posts: 5389
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Module ScaleGadgets

Post by mk-soft »

Update v0.27
- Change internal calculation of position and size
- Change size of fonts. Now with X an Y axis
- Added SetScaleFont for added a owner font array with different fonts and size

:wink:
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
mk-soft
Always Here
Always Here
Posts: 5389
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Module ScaleGadgets

Post by mk-soft »

Update v0.28
- Added SetScaleFontCallBack*
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
mk-soft
Always Here
Always Here
Posts: 5389
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Module ScaleGadgets

Post by mk-soft »

Update v0.29
- Added SetScaleFontID
- Change SetScaleFont to SetScaleFontArray
- Added SetScaleFontCallBack*

* With SetScaleFontCallback you can set the font yourself. The gadget number and the current scaling for the width and height are passed.
From this the required font size can be calculated.

The callback must have the following syntax
- MyFontCB(Gadget, ScaleX.d, ScaleY.d)
Last edited by mk-soft on Sun Feb 10, 2019 8:48 pm, edited 1 time in total.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
mk-soft
Always Here
Always Here
Posts: 5389
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Module ScaleGadgets

Post by mk-soft »

Update v0.30r2
- Added Font Management
. * Added ScaleLoadFont, ScaleFreeFont, GetScaleFontName, GetScaleFontHeight, GetScaleFontStyle
. * Redirection LoadFont and FreeFont to ScaleLoadFont and ScaleFreeFont
. * Redirection SetGadgetFont to SetScaleFontID

- Removed SetScaleFontArray (Not longer used)
- Change ScaleAllGagdgets. Removed optional parameters
- Change SetScale. Removed optional parameter

- Added SetScaleModeFont(Mode)
. * #ScaleModeFontNone ; No scaling
. * #ScaleModeFontScaled ; Scaling with set scale factor
. * #ScaleModeFontDymanic (Default); Scaling complet

- Added SetScaleModeImage(Mode)
. * #ScaleModeImageNone ; No scaling
. * #ScaleModeImageScaled ; Scaling with set scale factor
. * #ScaleModeImageDymanic (Default); Scaling complet

- Change SetScaleMode(Mode)
. * #ScaleModeDynamic as default

- Bugfix v0.30r2
. * SetScaleImage

Example
- Fix Font Callback

Code: Select all

;-Example v0.30

IncludeFile "Modul_ScaleGadgets.pb"

CompilerIf #PB_Compiler_IsMainFile
  
  UseModule ScaleGadgets
  
  Enumeration Window 1
    #Main
  EndEnumeration
  
  Enumeration Gadget
    #Container0
    #String0
    #String1
    #String2
    #String3
    #String4
    #Container1
    #ButtonB0
    #ButtonB1
    #ButtonB2
  EndEnumeration
  
  Enumeration MenuItem
    #New
    #Load
    #Save
    #Exit
  EndEnumeration
  
  Enumeration StatusBar
    #StatusBar
  EndEnumeration
  
  ; -----------------------------------------------------------------
  
  Global ExitApplication
  
  ; -----------------------------------------------------------------
  
  ; -----------------------------------------------------------------
  
  Global DPI.f = 1.25
  Global MyFont1 = LoadFont(#PB_Any, "Courier New", 15, #PB_Font_Bold | #PB_Font_Italic)
  Global MyFont2 = LoadFont(#PB_Any, "Comic Sans MS", 12)
  
  SetScale(DPI)
  
  ; Force orinal PB-Funktion
  Macro PB(Function)
    Function
  EndMacro
  
  ; -----------------------------------------------------------------
  
  Procedure MyFontCB(Gadget, ScaleX.d, ScaleY.d)
    Static old_fontsize
    Protected fontsize
    If ScaleX < ScaleY
      fontsize = 18 * ScaleX
    Else
      fontsize = 18 * ScaleY
    EndIf
    If fontsize <> old_fontsize
      old_fontsize = fontsize
      LoadFont(0, "Arial New", fontsize, #PB_Font_Bold | #PB_Font_Underline | #PB_Font_Italic)
    EndIf
    PB(SetGadgetFont)(Gadget, FontID(0))
  EndProcedure
  
  ; -----------------------------------------------------------------
  
  Procedure MyFontCB2(Gadget, ScaleX.d, ScaleY.d)
    Static old_fontsize
    Protected fontsize
    fontsize = 18 * ScaleY
    If fontsize <> old_fontsize
      old_fontsize = fontsize
      LoadFont(1, "Arial New", fontsize, #PB_Font_Bold | #PB_Font_Underline | #PB_Font_Italic)
    EndIf
    PB(SetGadgetFont)(Gadget, FontID(1))
  EndProcedure
  
  ; -----------------------------------------------------------------
  
  Procedure GetStatus(Gadget)
    Protected x, y, dx, dy, text.s
    
    SetScaleMode(#ScaleModeReal)
    x = GadgetX(Gadget)
    y = GadgetY(Gadget)
    dx = GadgetWidth(Gadget)
    dy = GadgetHeight(Gadget)
    text = "R = " + Str(x) + "/" + Str(y) + " - " + Str(dx) + "*" + Str(dy)
    StatusBarText(#StatusBar, 1, text)
    SetScaleMode(#ScaleModeScaled)
    x = GadgetX(Gadget)
    y = GadgetY(Gadget)
    dx = GadgetWidth(Gadget)
    dy = GadgetHeight(Gadget)
    text = "S = " + x + "/" + y + " - " + dx + "*" + dy
    StatusBarText(#StatusBar, 2, text)
    SetScaleMode(#ScaleModeDynamic)
    x = GadgetX(Gadget)
    y = GadgetY(Gadget)
    dx = GadgetWidth(Gadget)
    dy = GadgetHeight(Gadget)
    text = "D = " + x + "/" + y + " - " + dx + "*" + dy
    StatusBarText(#StatusBar, 3, text)
  EndProcedure
  
  ; -----------------------------------------------------------------
  
  Procedure DoSizeWindow()
    ScaleAllGadgets(#Main, MenuHeight() + StatusBarHeight(#StatusBar))
    GetStatus(#Container0)
  EndProcedure
  
  ; -----------------------------------------------------------------
  
  Procedure OpenMain(x = 10, y = 10, width = 550, height = 415)
    OpenWindow(#Main, x, y, width, height + MenuHeight(), "Module ScaleGadgets", 
               #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_ScreenCentered)
    
    If CreateMenu(0, WindowID(#Main))
      ; Mac Menu´s
      CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
        MenuItem(#PB_Menu_About, "")
        MenuItem(#PB_Menu_Preferences, "")
        MenuItem(#PB_Menu_Quit, "")
      CompilerEndIf
      MenuTitle("&File")
      MenuItem(#New, "&New")
      MenuItem(#Load, "&Load")
      MenuItem(#Save, "&Save")
      MenuBar()
      MenuItem(#Exit, "&Exit")
    EndIf
    
    CreateStatusBar(#StatusBar, WindowID(#Main))
    AddStatusBarField(180)
    AddStatusBarField(150)
    AddStatusBarField(150)
    AddStatusBarField(150)
    StatusBarText(#StatusBar, 0, "ScaleGadgets: DPI = " + StrF(DPI *100) + "%")
    
    
    ContainerGadget(#Container0, 10, 10, 530, 310, #PB_Container_Flat)
    StringGadget(#String0, 10, 5, 510, 35, "Default Font")
    StringGadget(#String1, 10, 45, 510, 35, "Font Courier")
    StringGadget(#String2, 10, 85, 510, 35, "Font Callback")
    StringGadget(#String3, 10, 125, 510, 35, "Font Callback (Scaled over gadget hight)")
    StringGadget(#String4, 10, 165, 510, 35, "Font Comic MS, 12")
    CloseGadgetList()
    
    ContainerGadget(#Container1, 10, 330, 530, 50, #PB_Container_Single)
    ButtonGadget(#ButtonB0, 10, 10, 160, 30, "Font Comic MS")
    ButtonGadget(#ButtonB1, 180, 10, 170, 30, "Font Arial")
    ButtonGadget(#ButtonB2, 360, 10, 160, 30, "Font Courier")
    CloseGadgetList()
    
    ; Create array with fonts
    ;InitFontArray()
    
    SetGadgetFont(#String1, FontID(MyFont1))
    SetScaleFontCallback(#String2, @MyFontCB())
    SetScaleFontCallback(#String3, @MyFontCB2())
    SetGadgetFont(#String4, FontID(MyFont2))
    
  EndProcedure
  
  ;-Main
  OpenMain()
  BindEvent(#PB_Event_SizeWindow, @DoSizeWindow())
  GetStatus(#Container0)
  
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        ExitApplication = 1
      Case #PB_Event_Gadget
        Select EventGadget()
          Case #ButtonB0
            FreeFont(MyFont2)
            MyFont2 = LoadFont(#PB_Any, "Comic Sans MS", 14)
            SetGadgetText(#String4, "Font Comic Sans MS, 14")
            SetGadgetFont(#String4, FontID(MyFont2))
          Case #ButtonB1
            FreeFont(MyFont2)
            MyFont2 = LoadFont(#PB_Any, "Arial", 16, #PB_Font_Italic)
            SetGadgetText(#String4, "Font Arial, 16")
            SetGadgetFont(#String4, FontID(MyFont2))
          Case #ButtonB2
            FreeFont(MyFont2)
            MyFont2 = LoadFont(#PB_Any, "Courier New", 17)
            SetGadgetText(#String4, "Font Courier New, 17")
            SetGadgetFont(#String4, FontID(MyFont2))
          EndSelect
    EndSelect
  Until ExitApplication
  
  End
  
CompilerEndIf
[/size]
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1251
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Re: Module ScaleGadgets

Post by Paul »

Unless I'm doing something wrong, there seems to be a problem with fonts resetting back to original size when a second Window is opened.

See video...
https://youtu.be/b6oNt3T45JA

This is the code used to test...

Code: Select all

XIncludeFile "Module_ScaleGadgets.pb"
UseModule ScaleGadgets
SetScale(1.0)


Define EventID,MenuID,GadgetID,WindowID


Enumeration 1
  #Window_Form1
  #Window_Form2
EndEnumeration

Enumeration 1
  #Gadget_Form1_Text2
  #Gadget_Form1_Text3
  #Gadget_Form1_Text4
  #Gadget_Form1_Button5
  #Gadget_Form1_Button6
  #Gadget_Form1_Button7

  #Gadget_Form2_CheckBox9
  #Gadget_Form2_CheckBox10
  #Gadget_Form2_CheckBox11
  #Gadget_Form2_Button12
  #Gadget_Form2_Button13
  #Gadget_Form2_Button14
  #Gadget_Form2_Text15
  #Gadget_Form2_Text16
EndEnumeration

Procedure.i Window_Form1()
  If OpenWindow(#Window_Form1,258,149,400,180,"Work Form1",#PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_ScreenCentered|#PB_Window_Invisible)
      TextGadget(#Gadget_Form1_Text2,35,35,60,15,"Text2")
      TextGadget(#Gadget_Form1_Text3,35,80,60,15,"Text3")
      TextGadget(#Gadget_Form1_Text4,35,125,60,15,"Text4")
      ButtonGadget(#Gadget_Form1_Button5,115,35,135,20,"Open Form 2")
      ButtonGadget(#Gadget_Form1_Button6,115,80,60,20,"Button6")
      ButtonGadget(#Gadget_Form1_Button7,115,125,60,20,"Button7")
      WindowBounds(#Window_Form1,WindowWidth(#Window_Form1),WindowHeight(#Window_Form1),#PB_Ignore,#PB_Ignore)
      PVDynamic_AddWindow(#Window_Form1)
      HideWindow(#Window_Form1,0)
    ProcedureReturn WindowID(#Window_Form1)
  EndIf
EndProcedure

Procedure.i Window_Form2()
  If OpenWindow(#Window_Form2,258,149,251,290,"Work Form 2",#PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_ScreenCentered|#PB_Window_Invisible)
      CheckBoxGadget(#Gadget_Form2_CheckBox9,30,25,80,15,"CheckBox9")
      CheckBoxGadget(#Gadget_Form2_CheckBox10,30,55,80,15,"CheckBox10")
      CheckBoxGadget(#Gadget_Form2_CheckBox11,30,85,80,15,"CheckBox11")
      ButtonGadget(#Gadget_Form2_Button12,30,130,60,20,"Button12")
      ButtonGadget(#Gadget_Form2_Button13,30,170,60,20,"Button13")
      ButtonGadget(#Gadget_Form2_Button14,30,210,60,20,"Button14")
      TextGadget(#Gadget_Form2_Text15,145,130,60,15,"Text15")
      TextGadget(#Gadget_Form2_Text16,145,170,60,15,"Text16")
      WindowBounds(#Window_Form2,WindowWidth(#Window_Form2),WindowHeight(#Window_Form2),#PB_Ignore,#PB_Ignore)
      PVDynamic_AddWindow(#Window_Form2)
      HideWindow(#Window_Form2,0)
    ProcedureReturn WindowID(#Window_Form2)
  EndIf
EndProcedure


Procedure SizeWindowHandler()
  ScaleAllGadgets(EventWindow())
  SetScaleModeImage(#ScaleModeImageDynamic)
  SetScaleModeFont(#ScaleModeFontDynamic)
EndProcedure
BindEvent(#PB_Event_SizeWindow,@SizeWindowHandler())





;- Main Loop
If Window_Form1()

  Define quitForm1=0
  Repeat
    EventID  =WaitWindowEvent()
    MenuID   =EventMenu()
    GadgetID =EventGadget()
    WindowID =EventWindow()

    Select EventID
      Case #PB_Event_CloseWindow
        Select WindowID
          Case #Window_Form1
            quitForm1=1
          Case #Window_Form2
            CloseWindow(#Window_Form2)
        EndSelect


      Case #PB_Event_Gadget
        Select GadgetID
          Case #Gadget_Form1_Button5
            window_Form2()
        EndSelect

    EndSelect
  Until quitForm1
  CloseWindow(#Window_Form1)
EndIf
End
Image Image
User avatar
mk-soft
Always Here
Always Here
Posts: 5389
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Module ScaleGadgets

Post by mk-soft »

Update v0.31
- Bugfix default font

I've found a solution.
This works too with SetGadgetFont(#PB_Default, FontID). :wink:

Just have a look at the resources later.

Code: Select all

XIncludeFile "Modul_ScaleGadgets.pb"
UseModule ScaleGadgets
SetScale(1.0)

Define EventID,MenuID,GadgetID,WindowID


Enumeration 1
  #Window_Form1
  #Window_Form2
EndEnumeration

Enumeration 1
  #Gadget_Form1_Text2
  #Gadget_Form1_Text3
  #Gadget_Form1_Text4
  #Gadget_Form1_Button5
  #Gadget_Form1_Button6
  #Gadget_Form1_Button7
  
  #Gadget_Form2_CheckBox9
  #Gadget_Form2_CheckBox10
  #Gadget_Form2_CheckBox11
  #Gadget_Form2_Button12
  #Gadget_Form2_Button13
  #Gadget_Form2_Button14
  #Gadget_Form2_Text15
  #Gadget_Form2_Text16
EndEnumeration

Enumeration 1
  #Font_Window_Form1
  #Font_Window_Form2
EndEnumeration

LoadFont(#Font_Window_Form1, "Arial", 9, #PB_Font_Italic)
LoadFont(#Font_Window_Form2, "", 9, #PB_Font_Italic)

Procedure.i Window_Form1()
  If OpenWindow(#Window_Form1,258,149,400,180,"Work Form1",#PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_ScreenCentered|#PB_Window_Invisible)
    ;SetGadgetFont(#PB_Default, FontID(#Font_Window_Form1))
    TextGadget(#Gadget_Form1_Text2,35,35,60,15,"Text2")
    TextGadget(#Gadget_Form1_Text3,35,80,60,15,"Text3")
    TextGadget(#Gadget_Form1_Text4,35,125,60,15,"Text4")
    ButtonGadget(#Gadget_Form1_Button5,115,35,135,20,"Open Form 2")
    ButtonGadget(#Gadget_Form1_Button6,115,80,60,20,"Button6")
    ButtonGadget(#Gadget_Form1_Button7,115,125,60,20,"Button7")
    WindowBounds(#Window_Form1,WindowWidth(#Window_Form1),WindowHeight(#Window_Form1),#PB_Ignore,#PB_Ignore)
    ;PVDynamic_AddWindow(#Window_Form1)
    HideWindow(#Window_Form1,0)
    ProcedureReturn WindowID(#Window_Form1)
  EndIf
EndProcedure

Procedure.i Window_Form2()
  If OpenWindow(#Window_Form2,258,149,251,290,"Work Form 2",#PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_ScreenCentered|#PB_Window_Invisible)
    SetGadgetFont(#PB_Default, FontID(#Font_Window_Form2))
    CheckBoxGadget(#Gadget_Form2_CheckBox9,30,25,80,15,"CheckBox9")
    CheckBoxGadget(#Gadget_Form2_CheckBox10,30,55,80,15,"CheckBox10")
    CheckBoxGadget(#Gadget_Form2_CheckBox11,30,85,80,15,"CheckBox11")
    ButtonGadget(#Gadget_Form2_Button12,30,130,60,20,"Button12")
    ButtonGadget(#Gadget_Form2_Button13,30,170,60,20,"Button13")
    ButtonGadget(#Gadget_Form2_Button14,30,210,60,20,"Button14")
    TextGadget(#Gadget_Form2_Text15,145,130,60,15,"Text15")
    TextGadget(#Gadget_Form2_Text16,145,170,60,15,"Text16")
    WindowBounds(#Window_Form2,WindowWidth(#Window_Form2),WindowHeight(#Window_Form2),#PB_Ignore,#PB_Ignore)
    ;PVDynamic_AddWindow(#Window_Form2)
    HideWindow(#Window_Form2,0)
    ProcedureReturn WindowID(#Window_Form2)
  EndIf
EndProcedure


Procedure SizeWindowHandler()
  ScaleAllGadgets(EventWindow())
EndProcedure

SetScaleModeImage(#ScaleModeImageDynamic)
SetScaleModeFont(#ScaleModeFontDynamic)

BindEvent(#PB_Event_SizeWindow,@SizeWindowHandler())

;- Main Loop
If Window_Form1()
  
  Define quitForm1=0
  Repeat
    EventID  =WaitWindowEvent()
    MenuID   =EventMenu()
    GadgetID =EventGadget()
    WindowID =EventWindow()
    
    Select EventID
      Case #PB_Event_CloseWindow
        Select WindowID
          Case #Window_Form1
            quitForm1=1
          Case #Window_Form2
            CloseWindow(#Window_Form2)
        EndSelect
        
        
      Case #PB_Event_Gadget
        Select GadgetID
          Case #Gadget_Form1_Button5
            window_Form2()
        EndSelect
        
    EndSelect
  Until quitForm1
  CloseWindow(#Window_Form1)
EndIf
End
[/size]
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1251
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Re: Module ScaleGadgets

Post by Paul »

If you happen to use an icon (.ico) then PB compiler will throw an error at line 1022...
"Error ResizeImage(): The #Image in the icon (.ico) format can't be resized."

I would suggest changing the line

Code: Select all

PB(ResizeImage)(\ScaleImage, ImageDX, ImageDY)
to

Code: Select all

DisableDebugger : PB(ResizeImage)(\ScaleImage, ImageDX, ImageDY) : EnableDebugger
That way you can still use icons, they just won't be resized and you won't be forced to use a different image format due to the compiler complaining.
Image Image
User avatar
mk-soft
Always Here
Always Here
Posts: 5389
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Module ScaleGadgets

Post by mk-soft »

Icons can not resized. Convert the Icon to png :wink:

GIMP works fine for convert icons
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
Mindphazer
Enthusiast
Enthusiast
Posts: 341
Joined: Mon Sep 10, 2012 10:41 am
Location: Savoie

Re: Module ScaleGadgets

Post by Mindphazer »

Hello mk-soft,
I'm trying to use your module to resize rows and columns in a LitIconGadget,
In the code below, rows are resized when the window is resized, but columns are not :

Code: Select all

XIncludeFile "Modul_ScaleGadgets.pb"
UseModule ScaleGadgets
SetScale(1,0)

Enumeration FormWindow
  #MainWindow
EndEnumeration

Enumeration FormGadget
  #ListIcon
EndEnumeration

Procedure SizeWindowHandler()
  ScaleAllGadgets(EventWindow())
EndProcedure

Procedure OpenMainWindow(x = 0, y = 0, width = 600, height = 410)
  Protected i
  OpenWindow(#MainWindow, x, y, width, height, "Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget)
  ListIconGadget(#ListIcon, 20, 120, 560, 270, "Colonne 1", 120, #PB_ListIcon_GridLines)
  AddGadgetColumn(#ListIcon, 1, "Colonne 2", 80)
  AddGadgetColumn(#ListIcon, 2, "Colonne 3", 100)
  AddGadgetColumn(#ListIcon, 3, "Colonne 4", 60)
  AddGadgetColumn(#ListIcon, 4, "Colonne 5", 110)
   For i = 1 To 5
     AddGadgetItem(#Listicon, -1, "Aknkgnffbb" + Chr(10) + "Dfdgfg" + Chr(10) + "Dejgkgn" + Chr(10) + "DDF" + Chr(10) + "Fddedd")
   Next
EndProcedure

OpenMainWindow()

BindEvent(#PB_Event_SizeWindow,@SizeWindowHandler())
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
What am I missing ?

Thank you
MacBook Pro 14" M1 Pro - 16 Gb - MacOS 14 - Iphone 15 Pro Max - iPad at home
...and unfortunately... Windows at work...
Post Reply