Module ScaleGadgets

Share your advanced PureBasic knowledge/code with the community.
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2056
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Re: Module ScaleGadgets

Post by Andre »

Even if I prefer the GUI creation using "native" XML dialogs (made easier with the DynamicDialogs module) this is an impressive project. Thanks for sharing! :D
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
User avatar
skywalk
Addict
Addict
Posts: 3972
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Module ScaleGadgets

Post by skywalk »

Very Nice 8)
I have problems with multiple open windows?
Could you show an example where BindEvent(#PB_Event_SizeWindow, @DoSizeWindow()) does not get confused?
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Mesa
Enthusiast
Enthusiast
Posts: 346
Joined: Fri Feb 24, 2012 10:19 am

Re: Module ScaleGadgets

Post by Mesa »

Doesn't compile because of a macro alert (infinite recursive...), line 725, with PB570beta4 x86 under windows xp32b.

M.
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Module ScaleGadgets

Post by mk-soft »

Update v0.11
- Bugfix Multiple Windows
- Added internal parent gadget management
- Bugfix SplitterGadget problem. Gadgets inside SplitterGadget don't like ResizeGadget
skywalk wrote:Very Nice 8)
I have problems with multiple open windows?
Could you show an example where BindEvent(#PB_Event_SizeWindow, @DoSizeWindow()) does not get confused?
There was still a bug in the code, it's fixed.
Besides that the SplitterGadget doesn't like if the gadgets are changed in the big one.
Therefore I have now added the parent gadget management to be able to react to it.
I wanted to solve it before with API´s, but with macOS it doesn't work with the gadgets in the PanelGadget because there is no "SuperView"...
Mesa wrote:Doesn't compile because of a macro alert (infinite recursive...), line 725, with PB570beta4 x86 under windows xp32b.
I tested it under XP (VM) and I did not get this error.
Do you have a code example where the error occurs?
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: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Module ScaleGadgets

Post by mk-soft »

Update v0.12
- Bugfix ResizeWindow

: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: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Module ScaleGadgets

Post by mk-soft »

Update v0.13
- Bugfix ResizeWindow
- Added WindowWidth and WindowHeight calculation

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 = DesktopResolutionX()
SetScale(dpi)

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

Procedure DoSizeWindow()
  ResizeGadget(#Editor, 10, 10, WindowWidth(#Main) - 20 , WindowHeight(#Main) - 105 - MenuHeight())
  ResizeGadget(#Container, 10, WindowHeight(#Main) - 85 - MenuHeight() , WindowWidth(#Main) - 20, 50)
  ;ScaleAllGadgets(#Main, MenuHeight() + StatusBarHeight(#StatusBar))
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)
  
  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(#PB_Ignore)
  StatusBarText(#StatusBar, 0, "ScaleGadgets")
  EditorGadget(#Editor, 10, 10, 530, 310)
  SetGadgetText(#Editor, "I like Purebasic!")
  ContainerGadget(#Container, 10, 330, 530, 50, #PB_Container_Single)
  ButtonGadget(#ButtonB0, 10, 10, 160, 30, "Button 0")
  ButtonGadget(#ButtonB1, 180, 10, 170, 30, "Button 1")
  ButtonGadget(#ButtonB2, 360, 10, 160, 30, "Button 2")
  CloseGadgetList()
EndProcedure

OpenMain()

BindEvent(#PB_Event_SizeWindow, @DoSizeWindow())

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      ExitApplication = 1
      
  EndSelect
Until ExitApplication

End
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: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Module ScaleGadgets

Post by mk-soft »

Update v0.14
- Bugfix Scale Gadgets
- Bugfix Parent Gadget
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
Mesa
Enthusiast
Enthusiast
Posts: 346
Joined: Fri Feb 24, 2012 10:19 am

Re: Module ScaleGadgets

Post by Mesa »

I fixed my bug:
Doesn't compile because of a macro alert (infinite recursive...), line 725, with PB570beta4 x86 under windows xp32b.
in changing:

Code: Select all

Macro dq 
" EndMacro 
into

Code: Select all

Macro dq 
" 
;put 'EndMacro' in a new line
EndMacro 
M.
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Module ScaleGadgets

Post by mk-soft »

Mesa wrote:I fixed my bug:
Doesn't compile because of a macro alert (infinite recursive...), line 725, with PB570beta4 x86 under windows xp32b.
...
M.
???

No any problem with XP!
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
Mesa
Enthusiast
Enthusiast
Posts: 346
Joined: Fri Feb 24, 2012 10:19 am

Re: Module ScaleGadgets

Post by Mesa »

It could be an odd bug when i copy/paste between my firefox and the PB IDE, but i'm not sure....
XP use an old version of firefox because firefox is not update anymore for XP.

Sorry ;)

M.
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Module ScaleGadgets

Post by mk-soft »

Update v0.16
- Added ScaleRegisterGadget(Gadget, ...) for owner gadget

New feature to add custom gadgets to the ScaleGadget system.

First create your own gadget and then register the gadget with the gadget number. The gadget will then be changed to the correct size.

Code: Select all

; Add owner gadget with PB_Any
Define MyButton = MyOwnerDrawButtonGadget(#PB_Any, 360, 10, 160, 30, "My Button")
; Register gadget to ScaleGadget system and resize gadget to scale factors
ScaleRegisterGadget(MyButton)
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: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Module ScaleGadgets

Post by mk-soft »

Update v0.18
- Change ScaleRegisterGadget(Gadget, *Callback, ...) * Format for Callback: MyResizeCallback(Gadget, x, y, Width, Height)

For own gadgets a callback can be specified.
This will be called when the size of the gadget is changed.

The format of the callback must have the following structure.

Code: Select all

Procedure MyResizeGadget(Gadget, x, y, Width, Height)
  Debug "Resize gadget = " + Gadget + " w = " + Width + " h = " + Height
EndProcedure
...
Define MyButton = MyOwnerDrawButtonGadget(#PB_Any, 360, 10, 160, 30, "My Button")
; Register gadget to ScaleGadget system and resize gadget to scale factors
ScaleRegisterGadget(MyButton, @MyResizeGadget())
...
First I wanted to use an event. But this does not work under MacOS, because the events come too late.
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: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Module ScaleGadgets

Post by mk-soft »

Update v0.19
- Limit minimum position and size to zero

and update example with owner gadget :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: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Module ScaleGadgets

Post by mk-soft »

It is now very easy to use the GFX_Wizzard_BF gadgets with ScaleGadgets. Link: GFX_Wizzard-BF

For this you only have to register the gadget with ScaleRegisterGadget.
You only have to pass the gadget number and resize function.

Code: Select all

;-TOP

IncludeFile("ScaleGadgets.pbi")
IncludeFile("GFX_Wizzard_BF.pbi")

UseModule ScaleGadgets

Enumeration Window
  #Main
EndEnumeration

Enumeration StatusBar
  #StatusBar
EndEnumeration

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

Global ExitApplication

Global dpi.f = 1.5

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

Global font_ID=LoadFont(#PB_Any, "", 30, #PB_Font_Bold) ; Set a font with the max needed font size - Recommended : Use simple the ScaleModule Max Font

Global ImageGadget_0_ID
Global TextGadget_0_ID 

Procedure DoSizeWindow()
  ScaleAllGadgets(#Main, StatusBarHeight(#StatusBar))
EndProcedure

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

Procedure OpenMain(x = 10, y = 10, width = 550, height = 180)
  OpenWindow(#Main, x, y, width, height, "Module ScaleGadgets with GFX_Wizzard_BF Gadgets",
             #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_ScreenCentered)
  
  CreateStatusBar(#StatusBar, WindowID(#Main))
  AddStatusBarField(#PB_Ignore)
  StatusBarText(#StatusBar, 0, "ScaleGadgets : DPI = " + StrF(dpi * 100.0) + "%")
  
  Protected image_1_ID=LoadImage(#PB_Any, "./Image_Set/Lion.png") ; Needed Image for Gadgets_BF output - What ever you want 
  
  AddPadding_DrawTextCreateImage_X_BF(15) ; Adjust the automatic text padding for exact adjustment to the PB Gadget text size
  AddPadding_DrawTextCreateImage_Y_BF(-15)
  
  ; ImageGadget_BF - 0 ================================================
  FitImageActivateUpscaling_BF(1) ; Activate automatically image upsacaling
  
  ImageGadget_0_ID=ImageGadget_BF(image_1_ID, ; For initializing a image_ID is not needed
                                  340,        ; Output pos x
                                  10,         ; Output pos y
                                  200,        ; Gadget width
                                  140,        ; Gadget height
                                  $808080,    ; Background color - For a invisible background set background_color=-2 (-1 is reserved for ignore)
                                  15,         ; Padding
                                  $F0F0F0,    ; Grid color
                                  5,          ; Grid size
                                  10,         ; Grid tiling
                                  $808080,    ; Frame color
                                  5,          ; Frame size
                                  0)          ; Flags same the PB function
                                              ; The function give back the gadget ID
                                              ; For a empty image output set image_ID=-1
                                              ; The Gadget is compatible to the PB ImageGadget 
                                              ; The function give back the gadget ID
                                              ; BF Supports also automatically image upscaling with the function FitImageActivateUpscaling_BF
                                              ; Use a invisible background only for images with invisible color or you see nothing
  
  FitImageActivateUpscaling_BF(0) ; Deactivate again - This is a globale function - You can, but you must not deactivate again
  
  ScaleRegisterGadget(ImageGadget_0_ID, @ResizeGadget_BF()) ; Register gadget
  
  ; TextGadget_BF - 0 =================================================
  Define text_1$ : text_1$="ScaleGadgets"+#LF$+#LF$+
                           "Resizable GUI creating module"+#LF$+#LF$+
                           "This text is created with TextGadget_BF"+#LF$+#LF$+
                           "With automatic text size adjustment"+#LF$+#LF$+
                           "Available features"+#LF$+
                           "Left, right, revers, centred, RTL, vertical"
  TextGadget_0_ID=TextGadget_BF(text_1$,
                                10,                ; Output pos x
                                10,                ; Output pos y
                                305,               ; Gadget width
                                137,               ; Gadget height
                                #Blue,             ; Text color
                                #Yellow,           ; Background color - For a invisible background set background_color=-2 (-1 is reserved for ignore)
                                font_ID,           ; Declared large font - The font must have the max needed size for a enlarged output
                                0,                 ; Text stretching x (Headline mode)
                                0,                 ; Text stretching y
                                1,                 ; Text flag -  center=1 - right=2 - Textvertical=3
                                0,                 ; Text mode Revers=1 - RTL=2
                                #PB_Canvas_Border) ; Canvas flag - Same PB
  
  ScaleRegisterGadget(TextGadget_0_ID, @ResizeGadget_BF()) ; Register gadget 
  
EndProcedure

SetScale(dpi)

OpenMain()

BindEvent(#PB_Event_SizeWindow, @DoSizeWindow())

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      ExitApplication = 1
      
  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
Paul
PureBasic Expert
PureBasic Expert
Posts: 1243
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Re: Module ScaleGadgets

Post by Paul »

Tired your module and very nice so far but noticed some issues.

Since there are no options for locking the minimum Window size, Gadgets of course can be sized to small but at some point a Gadget might revert back to its minimum size...

Code: Select all

XIncludeFile "ScaleGadgets.pbi"
UseModule ScaleGadgets
SetScale(1.0)




Define EventID,MenuID,GadgetID,WindowID

Enumeration 1
  #Window_Main
EndEnumeration

Enumeration 1
  #Gadget_Main_List
  #Gadget_Main_Combo
  #Gadget_Main_Button4
  #Gadget_Main_Button5
  #Gadget_Main_Text6
EndEnumeration

Procedure.i Window_Main()
  If OpenWindow(#Window_Main,399,109,400,350,"Work Form1",#PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_ScreenCentered|#PB_Window_Invisible)
      ListIconGadget(#Gadget_Main_List,10,10,380,235,"ListIcon2",100,#PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection)
      ComboBoxGadget(#Gadget_Main_Combo,105,255,185,20)
      ButtonGadget(#Gadget_Main_Button4,10,255,85,20,"Button4")
      ButtonGadget(#Gadget_Main_Button5,305,255,85,20,"Button5")
      TextGadget(#Gadget_Main_Text6,10,310,380,15,"This is just a resize test !!!",#PB_Text_Center)
      HideWindow(#Window_Main,0)
    ProcedureReturn WindowID(#Window_Main)
  EndIf
EndProcedure




Procedure DoSizeWindow()
  ScaleAllGadgets(#Window_Main)
EndProcedure
BindEvent(#PB_Event_SizeWindow, @DoSizeWindow())


;- Main Loop
If Window_Main()
  ;WindowBounds(#Window_Main,400,350,#PB_Ignore,#PB_Ignore)  ;<--- Add this line to set a minimum Window size (prevents gadgets from shrinking to small)

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

    Select EventID
      Case #PB_Event_CloseWindow
        Select WindowID
          Case #Window_Main
            quitMain=1
        EndSelect

    EndSelect
  Until quitMain
  CloseWindow(#Window_Main)
EndIf
End
In this example if you grab the bottom border and make the Window smaller, at some point the ComboBox jumps back to the original size (height 20?) yet all the other Gadgets keep shrinking.
Image


As soon as start resizing the Window the height of the ListIcon rows jumps to very large and stays that way.
Column widths should also be scaled with the rest of the ListIcon Gadget so text is not cut off when enlarged.
ImageImage


If you make the height of the Window larger and don't change the width, the text enlarges to the point it no longer fits in the Gadgets.
Text should not be scaled if the width of the Gadget won't hold it.
Image
Image Image
Post Reply