Tim Mcd wrote:
> Nit Khair wrote:
>> Tim Mcd wrote:
>>> Matthew Moss wrote:
> Yeah, it's tough finding proper ruby documentation on Ncurses. I've just
> been using the Ncurses book linked at the ruby-ncurses site. That is
> written for C coding tho, so it's a bit hard porting it over. Panels?
> Enlighten me please!
1. The only documentation on ncurses-ruby is the README file the author
gives.
2. The only documentation on ncurses is a large file with sample C
program by one
Pradeep Padala which comes up on searching google. It is pretty
comprehensive but mainly examples - no real-world stuff.
3. Usually, I just grep thru the source, esp form_wrap.c and ncurses.rb.
4. Another useful source is "man" (if you are using *nix). This can give
you
explanations of methods. I use it quite a bit.
Forgive my cut-pasting from "man panel" - will explain after:
----
Panels are curses(3X) windows with the added feature of depth.
Panel functions allow the use of stacked windows and ensure the
proper portions of each window and the curses stdscr window are hidden
or displayed when panels are added, moved, modified or removed. The set
of currently visible panels is the stack of panels. The stdscr
window is beneath all panels, and is not considered part of the stack.
A window is associated with every panel. The panel routines
enable you to create, move, hide, and show panels, as well as position
a panel at any desired location in the stack.
Panel routines are a functional layer added to curses(3X),
make only high-level curses calls, and work anywhere terminfo curses
does.
----
Basically, in my app i have a main menu, which calls various programs
and when you return from any program, you come back to the main menu -
its precisely like "alpine". So when Menu calls Contracts, and you
return from Contracts, you want your Menu screen like it was, not with
stuff from Contracts all over. This is best done using panels. A window
gives you a panel. When you remove the panel whats below is
automatically there without your repainting etc.
Pretty neat and efficient compared to many apps I have seen recently
that used windows or stdscr and had to do all this jugglery themselves.
Here's some snips of code to make it clear:
my_form_win = WINDOW.new(rows_to_show,0,startrow ,0)
my_panel = my_form_win.new_panel
Ncurses::Panel.update_panels
In line 2, I create a panel from my window. Pls note that these will go
into instance variables so the caller can destroy them later - V IMP.
Finally, I have a method "free_all" which frees the fields etc. It also
has:
Ncurses::Panel.del_panel(@panel) if !@panel.nil?
@window.delwin if !@window.nil?
The rest of the time, you actually can forget you created a panel, and
just keep writing on the window.
====
Now in your game, i can guess when you jump levels you really don't want
the user to come back (like a stack). However, you could be popping up a
help screen, or a screen where the user can select weapons ... and then
come back to the main screen. So its best to wrap those windows in
panels as shown above. The freeing can be put/called in an ensure block.
Also, you may have some side or bottom panels showing scores, weapons,
time, lives etc. These are best implemented by putting a panel at the
bottom or side.
The snakes game i made was based on the sample code from the Pickaxe and
used only stdscr -- quite ugly if you ask me and it was only one screen
anyway. However, some folks have actually managed to build an entire app
using stdscr only ("sup", iirc). "raggle" otoh uses windows but not
panels, so he has to implement some kind of global array of windows, so
he can pop and push. I don't know their experience in implementing it -
was it clean or did they lose a lot of hair. i can tell you panels
*are* a clean way to implement layered windows.
--
Posted via http://www.ruby-forum.com/.