Re: Module ScaleGadgets
Posted: Fri Dec 21, 2018 9:26 am
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! 

http://www.purebasic.com
https://www.purebasic.fr/english/
There was still a bug in the code, it's fixed.skywalk wrote:Very Nice![]()
I have problems with multiple open windows?
Could you show an example where BindEvent(#PB_Event_SizeWindow, @DoSizeWindow()) does not get confused?
I tested it under XP (VM) and I did not get this error.Mesa wrote:Doesn't compile because of a macro alert (infinite recursive...), line 725, with PB570beta4 x86 under windows xp32b.
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
in changing:Doesn't compile because of a macro alert (infinite recursive...), line 725, with PB570beta4 x86 under windows xp32b.
Code: Select all
Macro dq
" EndMacro
Code: Select all
Macro dq
"
;put 'EndMacro' in a new line
EndMacro
???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.
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)
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())
...
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
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