Live resize ?

Mac OSX specific forum
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Re: Live resize ?

Post by DoubleDutch »

Just wondering why does the Windows version have the 16 event handler restriction?
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Live resize ?

Post by wilbert »

Internally OS X works with real event handlers. You can simply add as many as you wish.
Windows doesn't have them, you need to hook into things. So I had to mimic things like searching if a handler already exists so the same one can't be assigned twice.
The windows version therefore has a table for all handlers. I simply chose room for 16 since that seemed enough to me. It could also have been 32 but that would make things a little slower.
I just couldn't imagine someone would want to add more than 16 resize handlers at the same time.
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Re: Live resize ?

Post by DoubleDutch »

Is it possible to release a version where you can set the number of handlers? (just in case)
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
User avatar
J. Baker
Addict
Addict
Posts: 2181
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Re: Live resize ?

Post by J. Baker »

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 platforms

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 handler must be a procedure with two parameters.
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.
Nice! But it gives a linker error. It assumes that your PureBasic folder is in "/User/YourName/PureBasic/...".
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef


Even the vine knows it surroundings but the man with eyes does not.
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Live resize ?

Post by wilbert »

I don't know about the linker error.
As far as I know that location isn't stored in the lib.
It probably is possible to do the same thing without a lib and use inline ASM.
For those interested, this was the source for the OS X resize procedure inside the lib.
I don't remember exactly what every line of code does since I haven't looked at it in a long time :oops:

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
User avatar
michel51
Enthusiast
Enthusiast
Posts: 290
Joined: Mon Nov 21, 2005 10:21 pm
Location: Germany

Re: Live resize ?

Post by michel51 »

J. Baker wrote:
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 platforms

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 handler must be a procedure with two parameters.
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.
Nice! But it gives a linker error. It assumes that your PureBasic folder is in "/User/YourName/PureBasic/...".
Same here...Linker error.

But the lib-files are not Library-files, but unix-compiled-files. May be this is the reason for the linker error.
michel51

Mac OS X Snow Leopard (10.6.8 ) Intel
PureBasic V 5.21(x64), V 5.22beta
Post Reply