Author |
Topic: New Multiple Output Window library (Read 778 times) |
|
admin
Administrator
member is offline


Posts: 1145
|
 |
New Multiple Output Window library
« Thread started on: Sep 7th, 2009, 10:39am » |
|
I'm pleased to announce a new library for BBC BASIC for Windows. MULTIWIN.BBC provides BB4W with the capability of having multiple output windows. There can be as many windows as you like (within reason) and each can be independently written to using normal BBC BASIC text and graphics output statements. The library is here:
http://groups.yahoo.com/group/bb4w/files/Libraries/MULTIWIN.BBC
The library calls PROC_createwindow in WINLIB5 so that must be INSTALLed as well. There are a few minor restrictions in its use:
1. MULTIWIN disables *REFRESH (there are other ways of achieving a similar effect).
2. The text cursor (caret) can only be shown in the main window.
3. The output windows share the same colour palette.
I have listed below a short demo program illustrating how the library is used.
Richard.
Code: INSTALL @lib$+"WINLIB5"
INSTALL @lib$+"MULTIWIN"
PROC_multiwin(3)
ON CLOSE PROCcleanup : QUIT
ON ERROR ON ERROR OFF : PROCcleanup : PRINT 'REPORT$ : END
PROC_createwin(1, "Window one", 100, 100, 400, 300, 0, &96CA0000, 0)
PROC_createwin(2, "Window two", 200, 200, 400, 300, 0, &96CA0000, 0)
PROC_createwin(3, "Window three", 300, 300, 400, 300, 0, &96CA0000, 0)
PROC_selectwin(1)
*FONT Ariel,11,B
COLOUR 4
REPEAT
WAIT 20
PROC_selectwin(1)
PRINT "Hello world! "; N%
N% += 1
PROC_selectwin(2)
GCOL RND(15)
RECTANGLE FILL RND(800),RND(600),RND(800),RND(600)
PROC_selectwin(3)
GCOL RND(15)
CIRCLE FILL RND(800), RND(600), RND(200)
PROC_selectwin(0)
PRINT "Main window "; N%
UNTIL FALSE
PROCcleanup
END
DEF PROCcleanup
PROC_selectwin(0)
PROC_closewin(1)
PROC_closewin(2)
PROC_closewin(3)
ENDPROC
|
|
Logged
|
|
|
|
19Grumpah42
Junior Member
member is offline


Gender: 
Posts: 57
|
 |
Re: New Multiple Output Window library
« Reply #1 on: Sep 12th, 2009, 06:09am » |
|
This is a wonderful tool! I am not having much luck hooking the user closure of spawned windows, which I need to do so that my compiled & hidden window(0) exits (QUITs) when the offspring is closed by the user. I find that none of ON CLOSE PROC_cleanup:QUIT , ON SYS PROC_cleanup:QUIT, ON ERROR ON ERROR OFF : PROC_cleanup : QUIT
actually trap the offspring window closure, although they do respond promptly to an <Esc> (but I don't want to use that.) Is there some other Win system call I can use to determine whether a spawned window is open? I Might be able to put that in somewhere to invoke PROC_cleanup etc., but I think it would be best to have a 'permanent' interrupt-based error trap in place. Is this possible? --G
|
|
Logged
|
C-2-Q 3GB, C-2-Duo 2GB, both GeForce 9500 GT, WinXP sp3. Two Linux Ubuntu boxes (rock solid, lean and mean, but they won't run BB4W!).
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: New Multiple Output Window library
« Reply #2 on: Sep 12th, 2009, 06:58am » |
|
Quote:I am not having much luck hooking the user closure of spawned windows |
|
The approach I think I'd adopt is to 'poll' for the window being open (SYS "IsWindow") and take whatever action you desire if you find it's been closed by the user. If you want it to behave like an 'event' do the polling in an ON TIME interrupt.
Another possible approach is simply to disable the close button: http://bb4w.wikispaces.com/Disabling+the+close+button
It might be possible to intercept the WM_CLOSE message by subclassing, but using SUBCLASS.BBC can impose undesirable constraints on the rest of the program, and you'd have to subclass all the 'spawned' windows.
Triggering a genuine ON CLOSE event would theoretically be possible, but it would involve assembler code to intercept the WM_CLOSE message. Rather a 'last resort' solution I would say!
Richard.
|
|
Logged
|
|
|
|
19Grumpah42
Junior Member
member is offline


Gender: 
Posts: 57
|
 |
Re: New Multiple Output Window library
« Reply #3 on: Sep 15th, 2009, 06:38am » |
|
Some ongoing experiences with this wonderful mind-broadening tool. [1] The BBC "ON CLOSE" trap only applies to the top window, window(0). I find this very useful for catching a mistaken user [X] click (which would trash the whole job.) I use
ON CLOSE PROC_naughty_closure :RETURN
(where the PROC just notifies the user of his mistake!) [2] The created sub-windows behave as a hierarchy: last on first off. You must do PROC-closewin(n%) in the reverse order of their FN_createwin(,,,,,,) if you expect to close only the sub-window you (programme or user) told it to close. So, if window(3) is still open when 'you' close window(2), window(3) will be killed at the same time. This imposes important mental discipline upon all concerned. It also suggests that the PROC for closing down all sub-windows should best iterate downwards, as in FOR I%=DIM(Win{()},1) TO 1 STEP -1 SYS "IsWindow", Win{(I%)}.hwnd% TO R% etc.
[3] The sub-windows - but not the main window - appear to have a palette of only COLOURS 0-7 available to them. I was expecting 0-15 colours, like the main window(0). So, for example if you do (after all the sub-windows are created) COLOUR 7,255,224,228: PROC_selectwin(n%):COLOUR 7:CLS The window(n) [where n is 0-DIM(Win{()},1)]will go a gentle pale pink. But if you do e.g. COLOUR 8,255,224,228: PROC_selectwin(n%):COLOUR 8:CLS only window(0) will be that colour; windows(n%>0) will go a nasty colour, possibly black. I have tried using VDU instead of COLOUR: same result. Was this expected? I regret that the assembler code in the library is beyond my comprehension, but Richard had told me that VDU 22 was involved in setting up the sub-windows. Interesting. Does anyone think I have done something wrong? Now would be a good time to tell.  --Grahame
|
|
Logged
|
C-2-Q 3GB, C-2-Duo 2GB, both GeForce 9500 GT, WinXP sp3. Two Linux Ubuntu boxes (rock solid, lean and mean, but they won't run BB4W!).
|
|
|
19Grumpah42
Junior Member
member is offline


Gender: 
Posts: 57
|
 |
Re: New Multiple Output Window library
« Reply #4 on: Sep 15th, 2009, 07:05am » |
|
Booboob!
I just realised before dropping off to sleep that I had neglected to add 128 to the COLOURs I quoted to set the backgrounds. So, COLOUR 135,6 are good in window(0) but COLOUR 136 and up are bad in a sub-window. --G
|
|
Logged
|
C-2-Q 3GB, C-2-Duo 2GB, both GeForce 9500 GT, WinXP sp3. Two Linux Ubuntu boxes (rock solid, lean and mean, but they won't run BB4W!).
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: New Multiple Output Window library
« Reply #5 on: Sep 15th, 2009, 08:52am » |
|
Quote:The created sub-windows behave as a hierarchy: last on first off. You must do PROC-closewin(n%) in the reverse order of their FN_createwin(,,,,,,) |
|
That's definitely not as expected, and suggests a bug somewhere. I suspect the bug may be in your program: you should call FN_createwin only when the main window (window 0) is selected.
So for example if you do this (as per my demo program) I would not expect any such 'hierarchy' to arise:
Code: hw1% = FN_createwin(1, "Window one", 100, 100, 400, 300, 0, &96CA0000, 0)
hw2% = FN_createwin(2, "Window two", 200, 200, 400, 300, 0, &96CA0000, 0)
hw3% = FN_createwin(3, "Window three", 300, 300, 400, 300, 0, &96CA0000, 0)
hw4% = FN_createwin(4, "Window four", 400, 400, 400, 300, 0, &96CA0000, 0)
However if you do this you may get the described effect:
Code: hw1% = FN_createwin(1, "Window one", 100, 100, 400, 300, 0, &96CA0000, 0)
PROC_selectwin(1)
hw2% = FN_createwin(2, "Window two", 200, 200, 400, 300, 0, &96CA0000, 0)
PROC_selectwin(2)
hw3% = FN_createwin(3, "Window three", 300, 300, 400, 300, 0, &96CA0000, 0)
PROC_selectwin(3)
hw4% = FN_createwin(4, "Window four", 400, 400, 400, 300, 0, &96CA0000, 0) This is because the currently-selected window becomes the parent of the newly-created window.
Quote:The sub-windows - but not the main window - appear to have a palette of only COLOURS 0-7 available to them. |
|
That is indeed a bug in the library. I have uploaded a corrected version:
http://groups.yahoo.com/group/bb4w/files/Libraries/MULTIWIN.BBC
Richard.
|
|
Logged
|
|
|
|
19Grumpah42
Junior Member
member is offline


Gender: 
Posts: 57
|
 |
Re: New Multiple Output Window library
« Reply #6 on: Sep 15th, 2009, 4:50pm » |
|
Many thanks for the promptly powerful reply, Richard.
I could have lived with the 8-colour sub-windows, having figured it out (sub-colour%=colour% EOR 7), but now I don't need to. The specification of "hierarchies or not" is now exceedingly clear. Thanks! This is enormously powerful, one can create little sub-hierarchies as required, and use your nifty code (already posted) to grey out and re-enable the sub-window [X] button under programme control. Magical! Great stuff, Richard. --Grahame
|
|
Logged
|
C-2-Q 3GB, C-2-Duo 2GB, both GeForce 9500 GT, WinXP sp3. Two Linux Ubuntu boxes (rock solid, lean and mean, but they won't run BB4W!).
|
|
|
|