Re: Live resize ?
Posted: Sat Aug 27, 2011 12:13 am
Just wondering why does the Windows version have the 16 event handler restriction?
Nice! But it gives a linker error. It assumes that your PureBasic folder is in "/User/YourName/PureBasic/...".wilbert wrote:Thanks for mentioning it also works on PPC.
For myself what I wanted (if possible) is a cross platform ( Win32 / OSX_x86 ) solution so I created a cross-platform userlib.
Since the lib is written in ASM, it isn't working on a PPC. For those who are using OSX_x86 and Win32, here it is
http://www.waterlijn.info/pb/wxl_Lib.zip
The zip file contains a userlib for Win32 and one for OSX_x86.
Example code that works on both platformsThe handler must be a procedure with two parameters.Code: Select all
Procedure LiveResizeHandler (newWidth.l, newHeight.l) ResizeGadget(0, 10, 10, newWidth - 20, newHeight - 50) EndProcedure If OpenWindow(0, 0, 0, 640, 480, "PureBasic - Live Resize", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget) wxl_AddLiveResizeEventHandler(WindowID(0), @LiveResizeHandler()) WindowBounds(0, 120, 150, 1024, 768) WebGadget(0, 10, 10, 620, 430, "http://www.purebasic.com") Repeat EventID = WaitWindowEvent() Until EventID = #PB_Event_CloseWindow EndIf End
The windows lib has the restriction that it can only handle 16 event handlers at the same time and all windows that want to use this function need to be created from the main thread.
Code: Select all
section .text
extern _ChangeWindowAttributes
extern _GetEventParameter
extern _GetWindowEventTarget
extern _InstallEventHandler
extern _RemoveEventHandler
global _PB_wxl_AddLiveResizeEventHandler
global _PB_wxl_RemoveEventHandler
callback:
add esp,8
pop dword [event]
pop dword [userdata]
sub esp,16
sub esp,12
sub esp,4
push dword current
push dword 0
push dword 16
push dword 0
push dword 0x68697263
push dword 0x63726374
push dword [event]
call dword [PStub_GetEventParameter]
add esp,32
sub esp,4
push dword previous
push dword 0
push dword 16
push dword 0
push dword 0x68697263
push dword 0x70726374
push dword [event]
call dword [PStub_GetEventParameter]
add esp,32
mov eax,dword [currentWidth]
cmp eax,dword [previousWidth]
jne _ok
mov eax,dword [currentHeight]
cmp eax,dword [previousHeight]
je _exit
_ok:
sub esp,12
fld dword [currentHeight]
fistp dword [esp]
sub esp,4
fld dword [currentWidth]
fistp dword [esp]
call dword [userdata]
add esp,8
_exit:
add esp,12
mov eax,-9874
ret
_PB_wxl_AddLiveResizeEventHandler:
add esp,4
pop dword [window]
pop dword [procedure]
sub esp,12
sub esp,12
sub esp,4
push dword 0
push dword 0x10000000
push dword [window]
call dword [PStub_ChangeWindowAttributes]
add esp,16
sub esp,12
push dword [window]
call dword [PStub_GetWindowEventTarget]
add esp,16
mov dword [target],eax
sub esp,8
mov dword [handler],0
push dword handler
push dword [procedure]
push dword eventList
push dword 1
push dword callback
push dword [target]
call dword [PStub_InstallEventHandler]
add esp,32
mov eax,dword [handler]
add esp,12
ret
_PB_wxl_RemoveEventHandler:
mov eax,esp
add eax,4
sub esp,12
sub esp,12
push dword [eax]
call dword [PStub_RemoveEventHandler]
add esp,16
add esp,12
ret
section .data
PStub_ChangeWindowAttributes dd _ChangeWindowAttributes
PStub_GetEventParameter dd _GetEventParameter
PStub_GetWindowEventTarget dd _GetWindowEventTarget
PStub_InstallEventHandler dd _InstallEventHandler
PStub_RemoveEventHandler dd _RemoveEventHandler
eventList dd $77696e64, 26
section .bss
handler resd 1
event resd 1
userdata resd 1
window resd 1
target resd 1
procedure resd 1
current resq 1
currentWidth resd 1
currentHeight resd 1
previous resq 1
previousWidth resd 1
previousHeight resd 1
Same here...Linker error.J. Baker wrote:Nice! But it gives a linker error. It assumes that your PureBasic folder is in "/User/YourName/PureBasic/...".wilbert wrote:Thanks for mentioning it also works on PPC.
For myself what I wanted (if possible) is a cross platform ( Win32 / OSX_x86 ) solution so I created a cross-platform userlib.
Since the lib is written in ASM, it isn't working on a PPC. For those who are using OSX_x86 and Win32, here it is
http://www.waterlijn.info/pb/wxl_Lib.zip
The zip file contains a userlib for Win32 and one for OSX_x86.
Example code that works on both platformsThe handler must be a procedure with two parameters.Code: Select all
Procedure LiveResizeHandler (newWidth.l, newHeight.l) ResizeGadget(0, 10, 10, newWidth - 20, newHeight - 50) EndProcedure If OpenWindow(0, 0, 0, 640, 480, "PureBasic - Live Resize", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget) wxl_AddLiveResizeEventHandler(WindowID(0), @LiveResizeHandler()) WindowBounds(0, 120, 150, 1024, 768) WebGadget(0, 10, 10, 620, 430, "http://www.purebasic.com") Repeat EventID = WaitWindowEvent() Until EventID = #PB_Event_CloseWindow EndIf End
The windows lib has the restriction that it can only handle 16 event handlers at the same time and all windows that want to use this function need to be created from the main thread.