2011-07-07 15:41:53 +02:00
|
|
|
SDL Considerations
|
|
|
|
==================
|
|
|
|
|
2015-11-10 18:13:43 +01:00
|
|
|
There are no special requirements to use PDCurses for SDL -- all
|
|
|
|
PDCurses-compatible code should work fine. (In fact, you can even build
|
|
|
|
against the Win32 console pdcurses.dll, and then swap in the SDL
|
|
|
|
pdcurses.dll.) Nothing extra is needed beyond the base SDL library.
|
2011-07-07 15:41:53 +02:00
|
|
|
However, there are some optional special features, described here.
|
|
|
|
|
2015-11-10 18:13:43 +01:00
|
|
|
The principal limitation of this port is that input is currently
|
|
|
|
restricted to ASCII (i.e., 0-127), plus the special keys like KEY_LEFT.
|
|
|
|
(You could have Unicode input, but then the input wouldn't match the
|
|
|
|
output, which is in Code Page 437.) Also, see the note about the
|
2011-07-07 15:41:53 +02:00
|
|
|
potential for incomplete output under "PDC_update_rects()", below.
|
|
|
|
|
|
|
|
|
|
|
|
Fonts
|
|
|
|
-----
|
|
|
|
|
2015-11-10 18:13:43 +01:00
|
|
|
The font is a simple BMP, 32 characters wide by 8 characters tall,
|
|
|
|
preferably with a palette. (BMPs without palettes still work, but in
|
|
|
|
that case, no attributes will be available, nor will the cursor work.)
|
|
|
|
The first entry in the palette (usually black) is treated as the
|
|
|
|
background color; the last entry (usually white) is treated as the
|
|
|
|
foreground. These are changed or made transparent as appropriate; any
|
|
|
|
other colors in the palette are passed through unchanged. So -- although
|
|
|
|
a one-bit depth is sufficient for a normal font -- you could redraw some
|
2011-07-07 15:41:53 +02:00
|
|
|
characters as multi-colored tiles.
|
|
|
|
|
2015-11-10 18:13:43 +01:00
|
|
|
The font must be monospaced. The size of each character is derived by
|
|
|
|
dividing the width of the BMP by 32 and the height by 8. There is no
|
2011-07-07 15:41:53 +02:00
|
|
|
constraint on the dimensions.
|
|
|
|
|
2015-11-10 18:13:43 +01:00
|
|
|
As provided in the default font and expected by acs_map[], the font is
|
|
|
|
in Code Page 437 form. But you can of course use any layout if you're
|
2011-07-07 15:41:53 +02:00
|
|
|
not relying on correct values for the ACS_* macros.
|
|
|
|
|
2015-11-10 18:13:43 +01:00
|
|
|
The font can be set via the environment variable PDC_FONT. If it's not
|
|
|
|
set, PDCurses looks for a file named "pdcfont.bmp" in the current
|
|
|
|
directory at the time of initscr(). If neither is found, it uses the
|
2011-07-07 15:41:53 +02:00
|
|
|
built-in default font encoded in deffont.h.
|
|
|
|
|
|
|
|
|
|
|
|
Backgrounds
|
|
|
|
-----------
|
|
|
|
|
2015-11-10 18:13:43 +01:00
|
|
|
PDCurses for SDL supports an optional background image BMP. This is used
|
|
|
|
whenever start_color() has not been called (see the ptest demo for an
|
|
|
|
example), or when use_default_colors() has been called after
|
|
|
|
start_color(), and the background color of a pair has been set to -1
|
|
|
|
(see newdemo, worm, and rain for examples). The usage parallels that of
|
|
|
|
ncurses in an appropriate terminal (e.g., Gnome Terminal). The image is
|
2011-07-07 15:41:53 +02:00
|
|
|
tiled to cover the PDCurses window, and can be any size or depth.
|
|
|
|
|
2015-11-10 18:13:43 +01:00
|
|
|
As with the font, you can point to a location for the background via the
|
|
|
|
environment variable PDC_BACKGROUND; "pdcback.bmp" is the fallback.
|
2011-07-07 15:41:53 +02:00
|
|
|
(There is no default background.)
|
|
|
|
|
|
|
|
|
|
|
|
Icons
|
|
|
|
-----
|
|
|
|
|
2015-11-10 18:13:43 +01:00
|
|
|
The icon (used with SDL_WM_SetIcon() -- not used for the executable
|
|
|
|
file) can be set via the environment variable PDC_ICON, and falls back
|
|
|
|
to "pdcicon.bmp", and then to the built-in icon from deficon.h. The
|
|
|
|
built-in icon is the PDCurses logo, as seen in ../x11/little_icon.xbm.
|
|
|
|
The SDL docs say that the icon must be 32x32, at least for use with MS
|
2011-07-07 15:41:53 +02:00
|
|
|
Windows.
|
|
|
|
|
2015-11-10 18:13:43 +01:00
|
|
|
If pdc_screen is preinitialized (see below), PDCurses does not attempt
|
2011-07-07 15:41:53 +02:00
|
|
|
to set the icon.
|
|
|
|
|
|
|
|
|
|
|
|
Screen size
|
|
|
|
-----------
|
|
|
|
|
2015-11-10 18:13:43 +01:00
|
|
|
The default screen size is 80x25 characters (whatever size they may be),
|
|
|
|
but you can override this via the environment variables PDC_COLS and/or
|
|
|
|
PDC_LINES. (Some other ports use COLS and LINES; this is not done here
|
|
|
|
because those values are, or should be, those of the controlling
|
|
|
|
terminal, and PDCurses for SDL is independent of the terminal.) If
|
2011-07-07 15:41:53 +02:00
|
|
|
pdc_screen is preinitialized (see below), these are ignored.
|
|
|
|
|
|
|
|
|
|
|
|
Integration with SDL
|
|
|
|
--------------------
|
|
|
|
|
2015-11-10 18:13:43 +01:00
|
|
|
If you want to go further, you can mix PDCurses and SDL functions. (Of
|
|
|
|
course this is extremely non-portable!) To aid you, there are several
|
|
|
|
external variables and functions specific to the SDL port; you could
|
2011-07-07 15:41:53 +02:00
|
|
|
include pdcsdl.h, or just add the declarations you need in your code:
|
|
|
|
|
|
|
|
PDCEX SDL_Surface *pdc_screen, *pdc_font, *pdc_icon, *pdc_back;
|
|
|
|
PDCEX int pdc_sheight, pdc_swidth, pdc_yoffset, pdc_xoffset;
|
|
|
|
|
|
|
|
void PDC_update_rects(void);
|
|
|
|
void PDC_retile(void);
|
|
|
|
|
2015-11-10 18:13:43 +01:00
|
|
|
pdc_screen is the main surface, created by SDL_SetVideoMode(), unless
|
|
|
|
it's preset before initscr(). You can perform normal SDL operations on
|
|
|
|
this surface, but PDCurses won't respect them when it updates. (For
|
|
|
|
that, see PDC_retile().) As an alternative, you can preinitialize this
|
|
|
|
surface before calling initscr(). In that case, you can use pdc_sheight,
|
|
|
|
pdc_swidth, pdc_yoffset and/or pdc_xoffset (q.v.) to confine PDCurses to
|
|
|
|
only a specific area of the surface, reserving the rest for other SDL
|
|
|
|
operations. If you preinitialize pdc_screen, you'll have to close it
|
|
|
|
yourself; PDCurses will ignore resize events, and won't try to set the
|
|
|
|
icon. Also note that if you preinitialize pdc_screen, it need not be the
|
2011-07-07 15:41:53 +02:00
|
|
|
display surface.
|
|
|
|
|
2015-11-10 18:13:43 +01:00
|
|
|
pdc_font, pdc_icon, and pdc_back are the SDL_surfaces for the font,
|
|
|
|
icon, and background, respectively. You can set any or all of them
|
|
|
|
before initscr(), and thus override any of the other ways to set them.
|
2011-07-07 15:41:53 +02:00
|
|
|
But note that pdc_icon will be ignored if pdc_screen is preset.
|
|
|
|
|
2015-11-10 18:13:43 +01:00
|
|
|
pdc_sheight and pdc_swidth are the dimensions of the area of pdc_screen
|
|
|
|
to be used by PDCurses. You can preset them before initscr(); if either
|
|
|
|
is not set, it defaults to the full screen size minus the x or y offset,
|
2011-07-07 15:41:53 +02:00
|
|
|
as appropriate.
|
|
|
|
|
2015-11-10 18:13:43 +01:00
|
|
|
pdc_xoffset and pdc_yoffset are the x and y offset for the area of
|
2011-07-07 15:41:53 +02:00
|
|
|
pdc_screen to be used by PDCurses. See the sdltest demo for an example.
|
|
|
|
|
2015-11-10 18:13:43 +01:00
|
|
|
PDC_retile() makes a copy of pdc_screen, then tiles it with the
|
|
|
|
background image, if any. The resulting surface is used as the
|
|
|
|
background for transparent character cells. PDC_retile() is called from
|
|
|
|
initscr() and resize_term(). However, you can also use it at other
|
|
|
|
times, to take advantage of the way it copies pdc_screen: Draw some SDL
|
|
|
|
stuff; call PDC_retile(); do some curses stuff -- it will use whatever
|
|
|
|
was on pdc_screen as the background. Then you can erase the curses
|
|
|
|
screen, do some more SDL stuff, and call PDC_retile() again to make a
|
|
|
|
new background. (If you don't erase the curses screen, it will be
|
|
|
|
incorporated into the background when you call PDC_retile().) But this
|
2011-07-07 15:41:53 +02:00
|
|
|
only works if no background image is set.
|
|
|
|
|
2015-11-10 18:13:43 +01:00
|
|
|
PDC_update_rects() is how the screen actually gets updated. For
|
|
|
|
performance reasons, when drawing, PDCurses for SDL maintains a table of
|
|
|
|
rectangles that need updating, and only updates (by calling this
|
|
|
|
function) during getch(), napms(), or when the table gets full.
|
|
|
|
Normally, this is sufficient; but if you're pausing in some way other
|
|
|
|
than by using napms(), and you're not doing keyboard checks, you may get
|
|
|
|
an incomplete update. If that happens, you can call PDC_update_rects()
|
2011-07-07 15:41:53 +02:00
|
|
|
manually.
|
|
|
|
|
|
|
|
|
|
|
|
Interaction with stdio
|
|
|
|
----------------------
|
|
|
|
|
2015-11-10 18:13:43 +01:00
|
|
|
As with X11, it's a bad idea to mix curses and stdio calls. (In fact,
|
|
|
|
that's true for PDCurses on any platform; but especially these two,
|
|
|
|
which don't run under terminals.) Depending on how SDL is built, stdout
|
2011-07-07 15:41:53 +02:00
|
|
|
and stderr may be redirected to files.
|