Reformat all C files.

I'll push a formatting guide at some point. There may still be
outstanding changes, but please feel free to resolve those as you arrive
a them.

To the best of my knowledge, there is no changes to the actual code
content, but the formatter does have the occasional bug. If you run into
an issue, please fix it!
This commit is contained in:
Sean Hunt
2015-05-09 13:43:16 -04:00
parent 167800afdf
commit 97d6fade74
270 changed files with 182649 additions and 173878 deletions
+107 -99
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 Window.c $NHDT-Date: 1430899134 2015/05/06 07:58:54 $ $NHDT-Branch: master $:$NHDT-Revision: 1.5 $ */
/* NetHack 3.6 Window.c $NHDT-Date: 1431192774 2015/05/09 17:32:54 $ $NHDT-Branch: master $:$NHDT-Revision: 1.8 $ */
/* NetHack 3.6 Window.c $Date: 2009/05/06 10:55:43 $ $Revision: 1.4 $ */
/* SCCS Id: @(#)Window.c 3.5 1993/02/02 */
/* Copyright (c) Dean Luick, 1992 */
@@ -10,10 +10,10 @@
*/
#ifndef SYSV
#define PRESERVE_NO_SYSV /* X11 include files may define SYSV */
#define PRESERVE_NO_SYSV /* X11 include files may define SYSV */
#endif
#ifdef MSDOS /* from compiler */
#ifdef MSDOS /* from compiler */
#define SHORT_FILENAMES
#endif
@@ -25,10 +25,10 @@
#include <X11/StringDefs.h>
#ifdef PRESERVE_NO_SYSV
# ifdef SYSV
# undef SYSV
# endif
# undef PRESERVE_NO_SYSV
#ifdef SYSV
#undef SYSV
#endif
#undef PRESERVE_NO_SYSV
#endif
#include "xwindowp.h"
@@ -40,60 +40,63 @@ static XtResource resources[] = {
#define offset(field) XtOffset(WindowWidget, window.field)
/* {name, class, type, size, offset, default_type, default_addr}, */
{ nhStr(XtNrows), nhStr(XtCRows), XtRDimension, sizeof(Dimension),
offset(rows), XtRImmediate, (XtPointer) 21},
offset(rows), XtRImmediate, (XtPointer) 21 },
{ nhStr(XtNcolumns), nhStr(XtCColumns), XtRDimension, sizeof(Dimension),
offset(columns), XtRImmediate, (XtPointer) 80},
offset(columns), XtRImmediate, (XtPointer) 80 },
{ nhStr(XtNforeground), XtCForeground, XtRPixel, sizeof(Pixel),
offset(foreground), XtRString, (XtPointer) XtDefaultForeground },
offset(foreground), XtRString, (XtPointer) XtDefaultForeground },
{ nhStr(XtNblack), XtCColor, XtRPixel, sizeof(Pixel),
offset(black), XtRString, (XtPointer) "black"},
{ nhStr(XtNred), XtCColor, XtRPixel, sizeof(Pixel),
offset(red), XtRString, (XtPointer) "red" },
{ nhStr(XtNgreen), XtCColor, XtRPixel, sizeof(Pixel),
offset(green), XtRString, (XtPointer) "pale green" },
{ nhStr(XtNbrown), XtCColor, XtRPixel, sizeof(Pixel),
offset(brown), XtRString, (XtPointer) "brown" },
{ nhStr(XtNblue), XtCColor, XtRPixel, sizeof(Pixel),
offset(blue), XtRString, (XtPointer) "blue" },
{ nhStr(XtNmagenta), XtCColor, XtRPixel, sizeof(Pixel),
offset(magenta), XtRString, (XtPointer) "magenta" },
{ nhStr(XtNcyan), XtCColor, XtRPixel, sizeof(Pixel),
offset(cyan), XtRString, (XtPointer) "light cyan" },
{ nhStr(XtNgray), XtCColor, XtRPixel, sizeof(Pixel),
offset(gray), XtRString, (XtPointer) "gray" },
{ nhStr(XtNorange), XtCColor, XtRPixel, sizeof(Pixel),
offset(orange), XtRString, (XtPointer) "orange" },
{ nhStr(XtNblack), XtCColor, XtRPixel, sizeof(Pixel), offset(black),
XtRString, (XtPointer) "black" },
{ nhStr(XtNred), XtCColor, XtRPixel, sizeof(Pixel), offset(red),
XtRString, (XtPointer) "red" },
{ nhStr(XtNgreen), XtCColor, XtRPixel, sizeof(Pixel), offset(green),
XtRString, (XtPointer) "pale green" },
{ nhStr(XtNbrown), XtCColor, XtRPixel, sizeof(Pixel), offset(brown),
XtRString, (XtPointer) "brown" },
{ nhStr(XtNblue), XtCColor, XtRPixel, sizeof(Pixel), offset(blue),
XtRString, (XtPointer) "blue" },
{ nhStr(XtNmagenta), XtCColor, XtRPixel, sizeof(Pixel), offset(magenta),
XtRString, (XtPointer) "magenta" },
{ nhStr(XtNcyan), XtCColor, XtRPixel, sizeof(Pixel), offset(cyan),
XtRString, (XtPointer) "light cyan" },
{ nhStr(XtNgray), XtCColor, XtRPixel, sizeof(Pixel), offset(gray),
XtRString, (XtPointer) "gray" },
{ nhStr(XtNorange), XtCColor, XtRPixel, sizeof(Pixel), offset(orange),
XtRString, (XtPointer) "orange" },
{ nhStr(XtNbright_green), XtCColor, XtRPixel, sizeof(Pixel),
offset(bright_green), XtRString, (XtPointer) "green" },
{ nhStr(XtNyellow), XtCColor, XtRPixel, sizeof(Pixel),
offset(yellow), XtRString, (XtPointer) "yellow" },
offset(bright_green), XtRString, (XtPointer) "green" },
{ nhStr(XtNyellow), XtCColor, XtRPixel, sizeof(Pixel), offset(yellow),
XtRString, (XtPointer) "yellow" },
{ nhStr(XtNbright_blue), XtCColor, XtRPixel, sizeof(Pixel),
offset(bright_blue), XtRString, (XtPointer) "royal blue" },
offset(bright_blue), XtRString, (XtPointer) "royal blue" },
{ nhStr(XtNbright_magenta), XtCColor, XtRPixel, sizeof(Pixel),
offset(bright_magenta), XtRString, (XtPointer) "violet" },
offset(bright_magenta), XtRString, (XtPointer) "violet" },
{ nhStr(XtNbright_cyan), XtCColor, XtRPixel, sizeof(Pixel),
offset(bright_cyan), XtRString, (XtPointer) "cyan" },
{ nhStr(XtNwhite), XtCColor, XtRPixel, sizeof(Pixel),
offset(white), XtRString, (XtPointer) "white" },
offset(bright_cyan), XtRString, (XtPointer) "cyan" },
{ nhStr(XtNwhite), XtCColor, XtRPixel, sizeof(Pixel), offset(white),
XtRString, (XtPointer) "white" },
{ nhStr(XtNfont), XtCFont, XtRFontStruct, sizeof(XFontStruct *),
offset(font), XtRString, (XtPointer) XtDefaultFont },
{ nhStr(XtNexposeCallback), XtCCallback, XtRCallback, sizeof(XtCallbackList),
offset(expose_callback), XtRCallback, (char *)0 },
offset(font), XtRString, (XtPointer) XtDefaultFont },
{ nhStr(XtNexposeCallback), XtCCallback, XtRCallback,
sizeof(XtCallbackList), offset(expose_callback), XtRCallback,
(char *) 0 },
{ nhStr(XtNcallback), XtCCallback, XtRCallback, sizeof(XtCallbackList),
offset(input_callback), XtRCallback, (char *)0 },
{ nhStr(XtNresizeCallback), XtCCallback, XtRCallback, sizeof(XtCallbackList),
offset(resize_callback), XtRCallback, (char *)0 },
offset(input_callback), XtRCallback, (char *) 0 },
{ nhStr(XtNresizeCallback), XtCCallback, XtRCallback,
sizeof(XtCallbackList), offset(resize_callback), XtRCallback,
(char *) 0 },
#undef offset
};
/* ARGSUSED */
static void no_op(w, event, params, num_params)
Widget w; /* unused */
XEvent *event; /* unused */
String *params; /* unused */
Cardinal *num_params; /* unused */
static void
no_op(w, event, params, num_params)
Widget w; /* unused */
XEvent *event; /* unused */
String *params; /* unused */
Cardinal *num_params; /* unused */
{
nhUse(w);
nhUse(event);
@@ -103,20 +106,19 @@ static void no_op(w, event, params, num_params)
return;
}
static XtActionsRec actions[] =
{
{ nhStr("no-op"), no_op },
static XtActionsRec actions[] = {
{ nhStr("no-op"), no_op },
};
static char translations[] =
"<BtnDown>: input() \
static char translations[] = "<BtnDown>: input() \
";
/* ARGSUSED */
static void Redisplay(w, event, region)
Widget w;
XEvent *event;
Region region; /* unused */
static void
Redisplay(w, event, region)
Widget w;
XEvent *event;
Region region; /* unused */
{
nhUse(region);
@@ -125,57 +127,63 @@ static void Redisplay(w, event, region)
}
/* ARGSUSED */
static void Resize(w)
Widget w;
static void
Resize(w)
Widget w;
{
XtCallCallbacks(w, XtNresizeCallback, (caddr_t) 0);
}
WindowClassRec windowClassRec = {
{ /* core fields */
/* superclass */ (WidgetClass) &widgetClassRec,
/* class_name */ nhStr("Window"),
/* widget_size */ sizeof(WindowRec),
/* class_initialize */ 0,
/* class_part_initialize */ 0,
/* class_inited */ FALSE,
/* initialize */ 0,
/* initialize_hook */ 0,
/* realize */ XtInheritRealize,
/* actions */ actions,
/* num_actions */ XtNumber(actions),
/* resources */ resources,
/* num_resources */ XtNumber(resources),
/* xrm_class */ NULLQUARK,
/* compress_motion */ TRUE,
/* compress_exposure */ TRUE,
/* compress_enterleave */ TRUE,
/* visible_interest */ FALSE,
/* destroy */ 0,
/* resize */ Resize,
/* expose */ Redisplay,
/* set_values */ 0,
/* set_values_hook */ 0,
/* set_values_almost */ XtInheritSetValuesAlmost,
/* get_values_hook */ 0,
/* accept_focus */ 0,
/* version */ XtVersion,
/* callback_private */ 0,
/* tm_table */ translations,
/* query_geometry */ XtInheritQueryGeometry,
/* display_accelerator */ XtInheritDisplayAccelerator,
/* extension */ 0
},
{ /* window fields */
/* empty */ 0
}
{ /* core fields */
/* superclass */ (WidgetClass) &widgetClassRec,
/* class_name */ nhStr("Window"),
/* widget_size */ sizeof(WindowRec),
/* class_initialize */ 0,
/* class_part_initialize */ 0,
/* class_inited */ FALSE,
/* initialize */ 0,
/* initialize_hook */ 0,
/* realize */ XtInheritRealize,
/* actions */ actions,
/* num_actions */ XtNumber(actions),
/* resources */ resources,
/* num_resources */ XtNumber(resources),
/* xrm_class */ NULLQUARK,
/* compress_motion */ TRUE,
/* compress_exposure */ TRUE,
/* compress_enterleave */ TRUE,
/* visible_interest */ FALSE,
/* destroy */ 0,
/* resize */ Resize,
/* expose */ Redisplay,
/* set_values */ 0,
/* set_values_hook */ 0,
/* set_values_almost */ XtInheritSetValuesAlmost,
/* get_values_hook */ 0,
/* accept_focus */ 0,
/* version */ XtVersion,
/* callback_private */ 0,
/* tm_table */ translations,
/* query_geometry */ XtInheritQueryGeometry,
/* display_accelerator */ XtInheritDisplayAccelerator,
/* extension */ 0 },
{ /* window fields */
/* empty */ 0 }
};
WidgetClass windowWidgetClass = (WidgetClass)&windowClassRec;
WidgetClass windowWidgetClass = (WidgetClass) &windowClassRec;
Font
WindowFont(w) Widget w; { return ((WindowWidget)w)->window.font->fid; }
WindowFont(w)
Widget w;
{
return ((WindowWidget) w)->window.font->fid;
}
XFontStruct *
WindowFontStruct(w) Widget w; { return ((WindowWidget)w)->window.font; }
WindowFontStruct(w)
Widget w;
{
return ((WindowWidget) w)->window.font;
}
+154 -107
View File
@@ -14,7 +14,8 @@
*
* THE UNIVERSITY OF WISCONSIN-MADISON DISCLAIMS ALL WARRANTIES WITH REGARD TO
* THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS, IN NO EVENT SHALL THE UNIVERSITY OF WISCONSIN-MADISON BE LIABLE FOR
* FITNESS, IN NO EVENT SHALL THE UNIVERSITY OF WISCONSIN-MADISON BE LIABLE
*FOR
* ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
* CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
@@ -48,12 +49,12 @@
* target type" issued by 'gcc -Wwrite-strings' as used by nethack.
* (For this file, always the second parameter to XtSetArg().)
*
* $NHDT-Date: 1430899133 2015/05/06 07:58:53 $ $NHDT-Branch: master $:$NHDT-Revision: 1.3 $
* $NHDT-Date: 1431192774 2015/05/09 17:32:54 $ $NHDT-Branch: master $:$NHDT-Revision: 1.5 $
* $Date: 2002/03/31 17:11:23 $ $Revision: 1.2 $
*/
#ifndef SYSV
#define PRESERVE_NO_SYSV /* X11 include files may define SYSV */
#define PRESERVE_NO_SYSV /* X11 include files may define SYSV */
#endif
#include <X11/Intrinsic.h>
@@ -66,26 +67,23 @@
#include <X11/Xaw/Command.h>
#ifdef PRESERVE_NO_SYSV
# ifdef SYSV
# undef SYSV
# endif
# undef PRESERVE_NO_SYSV
#ifdef SYSV
#undef SYSV
#endif
#undef PRESERVE_NO_SYSV
#endif
#include "config.h" /* #define for const for non __STDC__ compilers */
#include "lint.h" /* for nethack's nhStr() macro */
#include "config.h" /* #define for const for non __STDC__ compilers */
#include "lint.h" /* for nethack's nhStr() macro */
/* ":" added to both translations below to allow limited redefining of
* keysyms before testing for keysym values -- dlc */
static const char okay_accelerators[] =
"#override\n\
static const char okay_accelerators[] = "#override\n\
:<Key>Return: set() notify() unset()\n";
static const char cancel_accelerators[] =
"#override\n\
static const char cancel_accelerators[] = "#override\n\
:<Key>Escape: set() notify() unset()\n\
:<Ctrl>[: set() notify() unset()\n"; /* for keyboards w/o an ESC */
:<Ctrl>[: set() notify() unset()\n"; /* for keyboards w/o an ESC */
/* Create a dialog widget. It is just a form widget with
* a label prompt
@@ -95,99 +93,139 @@ static const char cancel_accelerators[] =
*/
Widget
CreateDialog(parent, name, okay_callback, cancel_callback)
Widget parent;
String name;
XtCallbackProc okay_callback;
XtCallbackProc cancel_callback;
Widget parent;
String name;
XtCallbackProc okay_callback;
XtCallbackProc cancel_callback;
{
Widget form, prompt, response, okay, cancel;
Arg args[20];
Cardinal num_args;
num_args = 0;
num_args = 0;
#ifdef SPECIAL_CMAP
if (special_cmap) {
XtSetArg(args[num_args], nhStr(XtNbackground), white); num_args++;
XtSetArg(args[num_args], nhStr(XtNbackground), white);
num_args++;
}
#endif
form = XtCreateManagedWidget(name, formWidgetClass, parent, args, num_args);
form =
XtCreateManagedWidget(name, formWidgetClass, parent, args, num_args);
num_args = 0;
num_args = 0;
#ifdef SPECIAL_CMAP
if (special_cmap) {
XtSetArg(args[num_args], nhStr(XtNforeground), black); num_args++;
XtSetArg(args[num_args], nhStr(XtNbackground), white); num_args++;
XtSetArg(args[num_args], nhStr(XtNforeground), black);
num_args++;
XtSetArg(args[num_args], nhStr(XtNbackground), white);
num_args++;
}
#endif
XtSetArg(args[num_args], nhStr(XtNtop), XtChainTop); num_args++;
XtSetArg(args[num_args], nhStr(XtNbottom), XtChainTop); num_args++;
XtSetArg(args[num_args], nhStr(XtNleft), XtChainLeft); num_args++;
XtSetArg(args[num_args], nhStr(XtNright), XtChainLeft); num_args++;
XtSetArg(args[num_args], nhStr(XtNresizable), True); num_args++;
XtSetArg(args[num_args], nhStr(XtNborderWidth), 0); num_args++;
prompt = XtCreateManagedWidget("prompt", labelWidgetClass,
form, args, num_args);
XtSetArg(args[num_args], nhStr(XtNtop), XtChainTop);
num_args++;
XtSetArg(args[num_args], nhStr(XtNbottom), XtChainTop);
num_args++;
XtSetArg(args[num_args], nhStr(XtNleft), XtChainLeft);
num_args++;
XtSetArg(args[num_args], nhStr(XtNright), XtChainLeft);
num_args++;
XtSetArg(args[num_args], nhStr(XtNresizable), True);
num_args++;
XtSetArg(args[num_args], nhStr(XtNborderWidth), 0);
num_args++;
prompt = XtCreateManagedWidget("prompt", labelWidgetClass, form, args,
num_args);
num_args = 0;
num_args = 0;
#ifdef SPECIAL_CMAP
if (special_cmap) {
XtSetArg(args[num_args], nhStr(XtNforeground), black); num_args++;
XtSetArg(args[num_args], nhStr(XtNbackground), white); num_args++;
XtSetArg(args[num_args], nhStr(XtNforeground), black);
num_args++;
XtSetArg(args[num_args], nhStr(XtNbackground), white);
num_args++;
}
#endif
XtSetArg(args[num_args], nhStr(XtNfromVert), prompt); num_args++;
XtSetArg(args[num_args], nhStr(XtNtop), XtChainTop); num_args++;
XtSetArg(args[num_args], nhStr(XtNbottom), XtChainTop); num_args++;
XtSetArg(args[num_args], nhStr(XtNleft), XtChainLeft); num_args++;
XtSetArg(args[num_args], nhStr(XtNright), XtChainLeft); num_args++;
XtSetArg(args[num_args], nhStr(XtNresizable), True); num_args++;
XtSetArg(args[num_args], nhStr(XtNeditType), XawtextEdit); num_args++;
XtSetArg(args[num_args], nhStr(XtNresize), XawtextResizeWidth); num_args++;
XtSetArg(args[num_args], nhStr(XtNstring), ""); num_args++;
response = XtCreateManagedWidget("response", asciiTextWidgetClass,
form, args, num_args);
XtSetArg(args[num_args], nhStr(XtNfromVert), prompt);
num_args++;
XtSetArg(args[num_args], nhStr(XtNtop), XtChainTop);
num_args++;
XtSetArg(args[num_args], nhStr(XtNbottom), XtChainTop);
num_args++;
XtSetArg(args[num_args], nhStr(XtNleft), XtChainLeft);
num_args++;
XtSetArg(args[num_args], nhStr(XtNright), XtChainLeft);
num_args++;
XtSetArg(args[num_args], nhStr(XtNresizable), True);
num_args++;
XtSetArg(args[num_args], nhStr(XtNeditType), XawtextEdit);
num_args++;
XtSetArg(args[num_args], nhStr(XtNresize), XawtextResizeWidth);
num_args++;
XtSetArg(args[num_args], nhStr(XtNstring), "");
num_args++;
response = XtCreateManagedWidget("response", asciiTextWidgetClass, form,
args, num_args);
num_args = 0;
num_args = 0;
#ifdef SPECIAL_CMAP
if (special_cmap) {
XtSetArg(args[num_args], nhStr(XtNforeground), black); num_args++;
XtSetArg(args[num_args], nhStr(XtNbackground), white); num_args++;
XtSetArg(args[num_args], nhStr(XtNforeground), black);
num_args++;
XtSetArg(args[num_args], nhStr(XtNbackground), white);
num_args++;
}
#endif
XtSetArg(args[num_args], nhStr(XtNfromVert), response); num_args++;
XtSetArg(args[num_args], nhStr(XtNtop), XtChainTop); num_args++;
XtSetArg(args[num_args], nhStr(XtNbottom), XtChainTop); num_args++;
XtSetArg(args[num_args], nhStr(XtNleft), XtChainLeft); num_args++;
XtSetArg(args[num_args], nhStr(XtNright), XtChainLeft); num_args++;
XtSetArg(args[num_args], nhStr(XtNresizable), True); num_args++;
XtSetArg(args[num_args], nhStr(XtNfromVert), response);
num_args++;
XtSetArg(args[num_args], nhStr(XtNtop), XtChainTop);
num_args++;
XtSetArg(args[num_args], nhStr(XtNbottom), XtChainTop);
num_args++;
XtSetArg(args[num_args], nhStr(XtNleft), XtChainLeft);
num_args++;
XtSetArg(args[num_args], nhStr(XtNright), XtChainLeft);
num_args++;
XtSetArg(args[num_args], nhStr(XtNresizable), True);
num_args++;
XtSetArg(args[num_args], nhStr(XtNaccelerators),
XtParseAcceleratorTable(okay_accelerators)); num_args++;
okay = XtCreateManagedWidget("okay", commandWidgetClass,
form, args, num_args);
XtParseAcceleratorTable(okay_accelerators));
num_args++;
okay = XtCreateManagedWidget("okay", commandWidgetClass, form, args,
num_args);
XtAddCallback(okay, XtNcallback, okay_callback, form);
/* Only create cancel button if there is a callback for it. */
if (cancel_callback) {
num_args = 0;
num_args = 0;
#ifdef SPECIAL_CMAP
if (special_cmap) {
XtSetArg(args[num_args], nhStr(XtNforeground), black); num_args++;
XtSetArg(args[num_args], nhStr(XtNbackground), white); num_args++;
}
if (special_cmap) {
XtSetArg(args[num_args], nhStr(XtNforeground), black);
num_args++;
XtSetArg(args[num_args], nhStr(XtNbackground), white);
num_args++;
}
#endif
XtSetArg(args[num_args], nhStr(XtNfromVert), response); num_args++;
XtSetArg(args[num_args], nhStr(XtNfromHoriz), okay); num_args++;
XtSetArg(args[num_args], nhStr(XtNtop), XtChainTop); num_args++;
XtSetArg(args[num_args], nhStr(XtNbottom), XtChainTop); num_args++;
XtSetArg(args[num_args], nhStr(XtNleft), XtChainLeft); num_args++;
XtSetArg(args[num_args], nhStr(XtNright), XtChainLeft); num_args++;
XtSetArg(args[num_args], nhStr(XtNresizable), True); num_args++;
XtSetArg(args[num_args], nhStr(XtNaccelerators),
XtParseAcceleratorTable(cancel_accelerators)); num_args++;
cancel = XtCreateManagedWidget("cancel", commandWidgetClass,
form, args, num_args);
XtAddCallback(cancel, XtNcallback, cancel_callback, form);
XtInstallAccelerators(response, cancel);
XtSetArg(args[num_args], nhStr(XtNfromVert), response);
num_args++;
XtSetArg(args[num_args], nhStr(XtNfromHoriz), okay);
num_args++;
XtSetArg(args[num_args], nhStr(XtNtop), XtChainTop);
num_args++;
XtSetArg(args[num_args], nhStr(XtNbottom), XtChainTop);
num_args++;
XtSetArg(args[num_args], nhStr(XtNleft), XtChainLeft);
num_args++;
XtSetArg(args[num_args], nhStr(XtNright), XtChainLeft);
num_args++;
XtSetArg(args[num_args], nhStr(XtNresizable), True);
num_args++;
XtSetArg(args[num_args], nhStr(XtNaccelerators),
XtParseAcceleratorTable(cancel_accelerators));
num_args++;
cancel = XtCreateManagedWidget("cancel", commandWidgetClass, form,
args, num_args);
XtAddCallback(cancel, XtNcallback, cancel_callback, form);
XtInstallAccelerators(response, cancel);
}
XtInstallAccelerators(response, okay);
@@ -217,8 +255,8 @@ GetDialogPrompt(w)
/* set the prompt. This is used to put error information in the prompt */
void
SetDialogPrompt(w, newprompt)
Widget w;
String newprompt;
Widget w;
String newprompt;
{
Arg args[1];
Widget label;
@@ -231,7 +269,7 @@ SetDialogPrompt(w, newprompt)
/* get what the user typed; caller must free the response */
String
GetDialogResponse(w)
Widget w;
Widget w;
{
Arg args[1];
Widget response;
@@ -243,12 +281,12 @@ GetDialogResponse(w)
return XtNewString(s);
}
#define max(a,b) (((a) > (b)) ? (a) : (b))
#define max(a, b) (((a) > (b)) ? (a) : (b))
/* set the default reponse */
void
SetDialogResponse(w, s)
Widget w;
String s;
Widget w;
String s;
{
Arg args[4];
Widget response;
@@ -262,9 +300,9 @@ SetDialogResponse(w, s)
XtSetArg(args[3], nhStr(XtNwidth), &width);
XtGetValues(response, args, FOUR);
/* width includes margins as per Xaw documentation */
nwidth = (font->max_bounds.width * strlen(s))+leftMargin+rightMargin;
nwidth = (font->max_bounds.width * strlen(s)) + leftMargin + rightMargin;
if (nwidth < width)
nwidth = width;
nwidth = width;
XtSetArg(args[0], nhStr(XtNstring), s);
XtSetArg(args[1], nhStr(XtNwidth), nwidth);
@@ -288,14 +326,14 @@ ClearDialogResponse(w)
}
#endif
/* Not a part of the original dialogs.c from ghostview --------------------- */
/* Not a part of the original dialogs.c from ghostview ---------------------
*/
/* position popup window under the cursor */
void
positionpopup(w, bottom)
Widget w;
boolean bottom; /* position y on bottom? */
Widget w;
boolean bottom; /* position y on bottom? */
{
Arg args[3];
Cardinal num_args;
@@ -310,38 +348,47 @@ positionpopup(w, bottom)
/* following line deals with a race condition w/brain-damaged WM's -dlc */
XtUnrealizeWidget(w);
XQueryPointer(XtDisplay(toplevel), XtWindow(toplevel), &root, &child,
&x, &y, &dummyx, &dummyy, &dummymask);
XQueryPointer(XtDisplay(toplevel), XtWindow(toplevel), &root, &child, &x,
&y, &dummyx, &dummyy, &dummymask);
num_args = 0;
XtSetArg(args[num_args], XtNwidth, &width); num_args++;
XtSetArg(args[num_args], XtNheight, &height); num_args++;
XtSetArg(args[num_args], XtNborderWidth, &b_width); num_args++;
XtSetArg(args[num_args], XtNwidth, &width);
num_args++;
XtSetArg(args[num_args], XtNheight, &height);
num_args++;
XtSetArg(args[num_args], XtNborderWidth, &b_width);
num_args++;
XtGetValues(w, args, num_args);
/* position so that the cursor is center,center or center,bottom */
width += 2 * b_width;
x -= ( (Position) width/2 );
if (x < 0) x = 0;
if ( x > (max_x = (Position) (XtScreen(w)->width - width)) ) x = max_x;
x -= ((Position) width / 2);
if (x < 0)
x = 0;
if (x > (max_x = (Position)(XtScreen(w)->width - width)))
x = max_x;
if (bottom) {
y -= (height+b_width-1);
height += 2 * b_width;
y -= (height + b_width - 1);
height += 2 * b_width;
} else {
height += 2 * b_width;
y -= ( (Position) height/2 );
height += 2 * b_width;
y -= ((Position) height / 2);
}
if (y < 0) y = 0;
if ( y > (max_y = (Position) (XtScreen(w)->height - height)) ) y = max_y;
if (y < 0)
y = 0;
if (y > (max_y = (Position)(XtScreen(w)->height - height)))
y = max_y;
num_args = 0;
XtSetArg(args[num_args], XtNx, x); num_args++;
XtSetArg(args[num_args], XtNy, y); num_args++;
XtSetArg(args[num_args], XtNx, x);
num_args++;
XtSetArg(args[num_args], XtNy, y);
num_args++;
XtSetValues(w, args, num_args);
/* Some older window managers ignore XtN{x,y}; hint the same values */
/* The {x,y} are not used by newer window managers; older ones need them */
/* The {x,y} are not used by newer window managers; older ones need them
*/
XtRealizeWidget(w);
hints = XAllocSizeHints();
hints->flags = USPosition;
+98 -107
View File
@@ -1,4 +1,4 @@
/* $NHDT-Date: 1430640199 2015/05/03 08:03:19 $ $NHDT-Branch: master $:$NHDT-Revision: 1.3 $ */
/* $NHDT-Date: 1431192774 2015/05/09 17:32:54 $ $NHDT-Branch: master $:$NHDT-Revision: 1.5 $ */
/* $Date: 2002/03/17 20:02:47 $ $Revision: 1.2 $ */
/*
@@ -9,47 +9,44 @@
* + Two dimensional byte arrays are in row order and are not padded
* between rows (x11_colormap[][]).
*/
#include "hack.h" /* for MAX_GLYPH */
#include "hack.h" /* for MAX_GLYPH */
#include "tile.h"
#include "tile2x11.h" /* x11 output file header structure */
#include "tile2x11.h" /* x11 output file header structure */
#define OUTNAME "x11tiles" /* output file name */
/* #define PRINT_COLORMAP */ /* define to print the colormap */
x11_header header;
unsigned char tile_bytes[TILE_X*TILE_Y*(MAX_GLYPH+TILES_PER_ROW)];
unsigned char *curr_tb = tile_bytes;
unsigned char x11_colormap[MAXCOLORMAPSIZE][3];
#define OUTNAME "x11tiles" /* output file name */
/* #define PRINT_COLORMAP */ /* define to print the colormap */
x11_header header;
unsigned char tile_bytes[TILE_X * TILE_Y * (MAX_GLYPH + TILES_PER_ROW)];
unsigned char *curr_tb = tile_bytes;
unsigned char x11_colormap[MAXCOLORMAPSIZE][3];
/* Look up the given pixel and return its colormap index. */
static unsigned char
pix_to_colormap(pix)
pixel pix;
pixel pix;
{
unsigned i;
for (i = 0; i < header.ncolors; i++) {
if (pix.r == ColorMap[CM_RED][i] &&
pix.g == ColorMap[CM_GREEN][i] &&
pix.b == ColorMap[CM_BLUE][i])
break;
if (pix.r == ColorMap[CM_RED][i] && pix.g == ColorMap[CM_GREEN][i]
&& pix.b == ColorMap[CM_BLUE][i])
break;
}
if (i == header.ncolors) {
Fprintf(stderr, "can't find color: [%u,%u,%u]\n", pix.r, pix.g, pix.b);
exit(1);
Fprintf(stderr, "can't find color: [%u,%u,%u]\n", pix.r, pix.g,
pix.b);
exit(1);
}
return (unsigned char) (i & 0xFF);
}
/* Convert the tiles in the file to our format of bytes. */
static unsigned long
convert_tiles(tb_ptr, total)
unsigned char **tb_ptr; /* pointer to a tile byte pointer */
unsigned long total; /* total tiles so far */
unsigned char **tb_ptr; /* pointer to a tile byte pointer */
unsigned long total; /* total tiles so far */
{
unsigned char *tb = *tb_ptr;
unsigned long count = 0;
@@ -57,69 +54,67 @@ convert_tiles(tb_ptr, total)
int x, y;
while (read_text_tile(tile)) {
count++;
total++;
for (y = 0; y < TILE_Y; y++) {
for (x = 0; x < TILE_X; x++)
tb[x] = pix_to_colormap(tile[y][x]);
tb += TILE_X * header.per_row;
}
count++;
total++;
for (y = 0; y < TILE_Y; y++) {
for (x = 0; x < TILE_X; x++)
tb[x] = pix_to_colormap(tile[y][x]);
tb += TILE_X * header.per_row;
}
/* repoint at the upper-left corner of the next tile */
*tb_ptr += TILE_X;
if (header.per_row == 1 || (total % header.per_row) == 0)
*tb_ptr += TILE_X * (TILE_Y - 1) * header.per_row;
tb = *tb_ptr;
/* repoint at the upper-left corner of the next tile */
*tb_ptr += TILE_X;
if (header.per_row == 1 || (total % header.per_row) == 0)
*tb_ptr += TILE_X * (TILE_Y - 1) * header.per_row;
tb = *tb_ptr;
}
return count;
}
/* Merge the current text colormap (ColorMap) with ours (x11_colormap). */
static void
merge_text_colormap()
{
unsigned i, j;
for (i = 0; i < (unsigned)colorsinmap; i++) {
for (j = 0; j < header.ncolors; j++)
if (x11_colormap[j][CM_RED] == ColorMap[CM_RED][i] &&
x11_colormap[j][CM_GREEN] == ColorMap[CM_GREEN][i] &&
x11_colormap[j][CM_BLUE] == ColorMap[CM_BLUE][i])
break;
for (i = 0; i < (unsigned) colorsinmap; i++) {
for (j = 0; j < header.ncolors; j++)
if (x11_colormap[j][CM_RED] == ColorMap[CM_RED][i]
&& x11_colormap[j][CM_GREEN] == ColorMap[CM_GREEN][i]
&& x11_colormap[j][CM_BLUE] == ColorMap[CM_BLUE][i])
break;
if (j >= MAXCOLORMAPSIZE) {
Fprintf(stderr, "colormap overflow\n");
exit(1);
}
if (j >= MAXCOLORMAPSIZE) {
Fprintf(stderr, "colormap overflow\n");
exit(1);
}
if (j == header.ncolors) { /* couldn't find it */
if (j == header.ncolors) { /* couldn't find it */
#ifdef PRINT_COLORMAP
printf("color %2d: %3d %3d %3d\n", header.ncolors,
ColorMap[CM_RED][i], ColorMap[CM_GREEN][i],
ColorMap[CM_BLUE][i]);
printf("color %2d: %3d %3d %3d\n", header.ncolors,
ColorMap[CM_RED][i], ColorMap[CM_GREEN][i],
ColorMap[CM_BLUE][i]);
#endif
x11_colormap[j][CM_RED] = ColorMap[CM_RED][i];
x11_colormap[j][CM_GREEN] = ColorMap[CM_GREEN][i];
x11_colormap[j][CM_BLUE] = ColorMap[CM_BLUE][i];
header.ncolors++;
}
x11_colormap[j][CM_RED] = ColorMap[CM_RED][i];
x11_colormap[j][CM_GREEN] = ColorMap[CM_GREEN][i];
x11_colormap[j][CM_BLUE] = ColorMap[CM_BLUE][i];
header.ncolors++;
}
}
}
/* Open the given file, read & merge the colormap, convert the tiles. */
static void
process_file(fname)
char *fname;
char *fname;
{
unsigned long count;
if (!fopen_text_file(fname, RDTMODE)) {
Fprintf(stderr, "can't open file \"%s\"\n", fname);
exit(1);
Fprintf(stderr, "can't open file \"%s\"\n", fname);
exit(1);
}
merge_text_colormap();
count = convert_tiles(&curr_tb, header.ntiles);
@@ -128,7 +123,6 @@ process_file(fname)
fclose_text_file();
}
#ifdef USE_XPM
static int
xpm_write(fp)
@@ -137,99 +131,96 @@ FILE *fp;
int i, j, n;
if (header.ncolors > 64) {
Fprintf(stderr, "Sorry, only configured for up to 64 colors\n");
exit(1);
/* All you need to do is add more char per color - below */
Fprintf(stderr, "Sorry, only configured for up to 64 colors\n");
exit(1);
/* All you need to do is add more char per color - below */
}
Fprintf(fp, "/* XPM */\n");
Fprintf(fp, "static char* nhtiles[] = {\n");
Fprintf(fp, "\"%lu %lu %lu %d\",\n",
header.tile_width*header.per_row,
(header.tile_height*header.ntiles)/header.per_row,
header.ncolors,
1 /* char per color */);
Fprintf(fp, "\"%lu %lu %lu %d\",\n", header.tile_width * header.per_row,
(header.tile_height * header.ntiles) / header.per_row,
header.ncolors, 1 /* char per color */);
for (i = 0; i < header.ncolors; i++)
Fprintf(fp, "\"%c c #%02x%02x%02x\",\n",
i+'0', /* just one char per color */
x11_colormap[i][0],
x11_colormap[i][1],
x11_colormap[i][2]);
Fprintf(fp, "\"%c c #%02x%02x%02x\",\n",
i + '0', /* just one char per color */
x11_colormap[i][0], x11_colormap[i][1], x11_colormap[i][2]);
n = 0;
for (i = 0; i < (header.tile_height*header.ntiles)/header.per_row; i++) {
Fprintf(fp, "\"");
for (j = 0; j < header.tile_width*header.per_row; j++) {
/* just one char per color */
fputc(tile_bytes[n++]+'0', fp);
}
for (i = 0; i < (header.tile_height * header.ntiles) / header.per_row;
i++) {
Fprintf(fp, "\"");
for (j = 0; j < header.tile_width * header.per_row; j++) {
/* just one char per color */
fputc(tile_bytes[n++] + '0', fp);
}
Fprintf(fp, "\",\n");
Fprintf(fp, "\",\n");
}
return fprintf(fp, "};\n") >= 0;
}
#endif /* USE_XPM */
#endif /* USE_XPM */
int
main(argc, argv)
int argc;
char **argv;
int argc;
char **argv;
{
FILE *fp;
int i;
header.version = 2; /* version 1 had no per_row field */
header.ncolors = 0;
header.tile_width = TILE_X;
header.tile_height = TILE_Y;
header.ntiles = 0; /* updated as we read in files */
header.per_row = TILES_PER_ROW;
header.version = 2; /* version 1 had no per_row field */
header.ncolors = 0;
header.tile_width = TILE_X;
header.tile_height = TILE_Y;
header.ntiles = 0; /* updated as we read in files */
header.per_row = TILES_PER_ROW;
if (argc == 1) {
Fprintf(stderr, "usage: %s txt_file1 [txt_file2 ...]\n", argv[0]);
exit(1);
Fprintf(stderr, "usage: %s txt_file1 [txt_file2 ...]\n", argv[0]);
exit(1);
}
fp = fopen(OUTNAME, "w");
if (!fp) {
Fprintf(stderr, "can't open output file\n");
exit(1);
Fprintf(stderr, "can't open output file\n");
exit(1);
}
/* don't leave garbage at end of partial row */
(void) memset((genericptr_t)tile_bytes, 0, sizeof(tile_bytes));
(void) memset((genericptr_t) tile_bytes, 0, sizeof(tile_bytes));
for (i = 1; i < argc; i++)
process_file(argv[i]);
process_file(argv[i]);
Fprintf(stderr, "Total tiles: %ld\n", header.ntiles);
/* round size up to the end of the row */
if ((header.ntiles % header.per_row) != 0) {
header.ntiles += header.per_row - (header.ntiles % header.per_row);
header.ntiles += header.per_row - (header.ntiles % header.per_row);
}
#ifdef USE_XPM
if (xpm_write(fp) == 0) {
Fprintf(stderr, "can't write XPM file\n");
exit(1);
Fprintf(stderr, "can't write XPM file\n");
exit(1);
}
#else
if (fwrite((char *)&header, sizeof(x11_header), 1, fp) == 0) {
Fprintf(stderr, "can't open output header\n");
exit(1);
if (fwrite((char *) &header, sizeof(x11_header), 1, fp) == 0) {
Fprintf(stderr, "can't open output header\n");
exit(1);
}
if (fwrite((char *)x11_colormap, 1, header.ncolors*3, fp) == 0) {
Fprintf(stderr, "can't write output colormap\n");
exit(1);
if (fwrite((char *) x11_colormap, 1, header.ncolors * 3, fp) == 0) {
Fprintf(stderr, "can't write output colormap\n");
exit(1);
}
if (fwrite((char *)tile_bytes, 1,
(int) header.ntiles*header.tile_width*header.tile_height, fp) == 0) {
Fprintf(stderr, "can't write tile bytes\n");
exit(1);
if (fwrite((char *) tile_bytes, 1,
(int) header.ntiles * header.tile_width * header.tile_height,
fp) == 0) {
Fprintf(stderr, "can't write tile bytes\n");
exit(1);
}
#endif
+1039 -994
View File
File diff suppressed because it is too large Load Diff
+827 -805
View File
File diff suppressed because it is too large Load Diff
+665 -593
View File
File diff suppressed because it is too large Load Diff
+242 -239
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 winmesg.c $NHDT-Date: 1430899136 2015/05/06 07:58:56 $ $NHDT-Branch: master $:$NHDT-Revision: 1.5 $ */
/* NetHack 3.6 winmesg.c $NHDT-Date: 1431192773 2015/05/09 17:32:53 $ $NHDT-Branch: master $:$NHDT-Revision: 1.8 $ */
/* NetHack 3.6 winmesg.c $Date: 2009/05/06 10:55:57 $ $Revision: 1.4 $ */
/* SCCS Id: @(#)winmesg.c 3.5 1996/04/05 */
/* Copyright (c) Dean Luick, 1992 */
@@ -15,7 +15,7 @@
*/
#ifndef SYSV
#define PRESERVE_NO_SYSV /* X11 include files may define SYSV */
#define PRESERVE_NO_SYSV /* X11 include files may define SYSV */
#endif
#include <X11/Intrinsic.h>
@@ -26,36 +26,35 @@
#include <X11/Xatom.h>
#ifdef PRESERVE_NO_SYSV
# ifdef SYSV
# undef SYSV
# endif
# undef PRESERVE_NO_SYSV
#ifdef SYSV
#undef SYSV
#endif
#undef PRESERVE_NO_SYSV
#endif
#include "xwindow.h" /* Window widget declarations */
#include "xwindow.h" /* Window widget declarations */
#include "hack.h"
#include "winX.h"
static struct line_element *FDECL(get_previous, (struct line_element *));
static void FDECL(set_circle_buf, (struct mesg_info_t *,int));
static char *FDECL(split, (char *,XFontStruct *,DIMENSION_P));
static void FDECL(add_line, (struct mesg_info_t *,const char *));
static void FDECL(set_circle_buf, (struct mesg_info_t *, int));
static char *FDECL(split, (char *, XFontStruct *, DIMENSION_P));
static void FDECL(add_line, (struct mesg_info_t *, const char *));
static void FDECL(redraw_message_window, (struct xwindow *));
static void FDECL(mesg_check_size_change, (struct xwindow *));
static void FDECL(mesg_exposed, (Widget,XtPointer,XtPointer));
static void FDECL(get_gc, (Widget,struct mesg_info_t *));
static void FDECL(mesg_resized, (Widget,XtPointer,XtPointer));
static void FDECL(mesg_exposed, (Widget, XtPointer, XtPointer));
static void FDECL(get_gc, (Widget, struct mesg_info_t *));
static void FDECL(mesg_resized, (Widget, XtPointer, XtPointer));
static char mesg_translations[] =
"#override\n\
static char mesg_translations[] = "#override\n\
<Key>: input() \
";
/* Move the message window's vertical scrollbar's slider to the bottom. */
void
set_message_slider(wp)
struct xwindow *wp;
struct xwindow *wp;
{
Widget scrollbar;
float top;
@@ -63,17 +62,16 @@ set_message_slider(wp)
scrollbar = XtNameToWidget(XtParent(wp->w), "vertical");
if (scrollbar) {
top = 1.0;
XtCallCallbacks(scrollbar, XtNjumpProc, &top);
top = 1.0;
XtCallCallbacks(scrollbar, XtNjumpProc, &top);
}
}
void
create_message_window(wp, create_popup, parent)
struct xwindow *wp; /* window pointer */
boolean create_popup;
Widget parent;
struct xwindow *wp; /* window pointer */
boolean create_popup;
Widget parent;
{
Arg args[8];
Cardinal num_args;
@@ -83,34 +81,35 @@ create_message_window(wp, create_popup, parent)
wp->type = NHW_MESSAGE;
wp->mesg_information = mesg_info =
(struct mesg_info_t *) alloc(sizeof(struct mesg_info_t));
(struct mesg_info_t *) alloc(sizeof(struct mesg_info_t));
mesg_info->fs = 0;
mesg_info->num_lines = 0;
mesg_info->head = mesg_info->line_here = mesg_info->last_pause =
mesg_info->last_pause_head = (struct line_element *) 0;
mesg_info->last_pause_head = (struct line_element *) 0;
mesg_info->dirty = False;
mesg_info->viewport_width = mesg_info->viewport_height = 0;
if (iflags.msg_history < (unsigned) appResources.message_lines)
iflags.msg_history = (unsigned) appResources.message_lines;
if (iflags.msg_history > MAX_HISTORY) /* a sanity check */
iflags.msg_history = MAX_HISTORY;
iflags.msg_history = (unsigned) appResources.message_lines;
if (iflags.msg_history > MAX_HISTORY) /* a sanity check */
iflags.msg_history = MAX_HISTORY;
set_circle_buf(mesg_info, (int) iflags.msg_history);
/* Create a popup that becomes the parent. */
if (create_popup) {
num_args = 0;
XtSetArg(args[num_args], XtNallowShellResize, True); num_args++;
num_args = 0;
XtSetArg(args[num_args], XtNallowShellResize, True);
num_args++;
wp->popup = parent = XtCreatePopupShell("message_popup",
topLevelShellWidgetClass,
toplevel, args, num_args);
/*
* If we're here, then this is an auxiliary message window. If we're
* cancelled via a delete window message, we should just pop down.
*/
wp->popup = parent =
XtCreatePopupShell("message_popup", topLevelShellWidgetClass,
toplevel, args, num_args);
/*
* If we're here, then this is an auxiliary message window. If we're
* cancelled via a delete window message, we should just pop down.
*/
}
/*
@@ -119,13 +118,14 @@ create_message_window(wp, create_popup, parent)
* always be visible, due to the stupid way the Athena viewport operates.
*/
num_args = 0;
XtSetArg(args[num_args], XtNallowVert, True); num_args++;
XtSetArg(args[num_args], XtNallowVert, True);
num_args++;
viewport = XtCreateManagedWidget(
"mesg_viewport", /* name */
viewportWidgetClass, /* widget class from Window.h */
parent, /* parent widget */
args, /* set some values */
num_args); /* number of values to set */
"mesg_viewport", /* name */
viewportWidgetClass, /* widget class from Window.h */
parent, /* parent widget */
args, /* set some values */
num_args); /* number of values to set */
/*
* Create a message window. We will change the width and height once
@@ -133,15 +133,16 @@ create_message_window(wp, create_popup, parent)
*/
num_args = 0;
if (!create_popup) {
XtSetArg(args[num_args], XtNtranslations,
XtParseTranslationTable(mesg_translations)); num_args++;
XtSetArg(args[num_args], XtNtranslations,
XtParseTranslationTable(mesg_translations));
num_args++;
}
wp->w = XtCreateManagedWidget(
"message", /* name */
windowWidgetClass, /* widget class from Window.h */
viewport, /* parent widget */
args, /* set some values */
num_args); /* number of values to set */
"message", /* name */
windowWidgetClass, /* widget class from Window.h */
viewport, /* parent widget */
args, /* set some values */
num_args); /* number of values to set */
XtAddCallback(wp->w, XtNexposeCallback, mesg_exposed, (XtPointer) 0);
@@ -152,39 +153,43 @@ create_message_window(wp, create_popup, parent)
/* Get the font information. */
num_args = 0;
XtSetArg(args[num_args], XtNfont, &mesg_info->fs); num_args++;
XtSetArg(args[num_args], XtNfont, &mesg_info->fs);
num_args++;
XtGetValues(wp->w, args, num_args);
/* Save character information for fast use later. */
mesg_info->char_width = mesg_info->fs->max_bounds.width;
mesg_info->char_height = mesg_info->fs->max_bounds.ascent +
mesg_info->fs->max_bounds.descent;
mesg_info->char_ascent = mesg_info->fs->max_bounds.ascent;
mesg_info->char_width = mesg_info->fs->max_bounds.width;
mesg_info->char_height =
mesg_info->fs->max_bounds.ascent + mesg_info->fs->max_bounds.descent;
mesg_info->char_ascent = mesg_info->fs->max_bounds.ascent;
mesg_info->char_lbearing = -mesg_info->fs->min_bounds.lbearing;
get_gc(wp->w, mesg_info);
wp->pixel_height = ((int)iflags.msg_history) * mesg_info->char_height;
wp->pixel_height = ((int) iflags.msg_history) * mesg_info->char_height;
/* If a variable spaced font, only use 2/3 of the default size */
if (mesg_info->fs->min_bounds.width != mesg_info->fs->max_bounds.width) {
wp->pixel_width = ((2*DEFAULT_MESSAGE_WIDTH)/3) *
mesg_info->fs->max_bounds.width;
wp->pixel_width = ((2 * DEFAULT_MESSAGE_WIDTH) / 3)
* mesg_info->fs->max_bounds.width;
} else
wp->pixel_width = (DEFAULT_MESSAGE_WIDTH *
mesg_info->fs->max_bounds.width);
wp->pixel_width =
(DEFAULT_MESSAGE_WIDTH * mesg_info->fs->max_bounds.width);
/* Set the new width and height. */
num_args = 0;
XtSetArg(args[num_args], XtNwidth, wp->pixel_width); num_args++;
XtSetArg(args[num_args], XtNheight, wp->pixel_height); num_args++;
XtSetArg(args[num_args], XtNwidth, wp->pixel_width);
num_args++;
XtSetArg(args[num_args], XtNheight, wp->pixel_height);
num_args++;
XtSetValues(wp->w, args, num_args);
/* make sure viewport height makes sense before realizing it */
num_args = 0;
mesg_info->viewport_height =
appResources.message_lines * mesg_info->char_height;
XtSetArg(args[num_args], XtNheight, mesg_info->viewport_height);num_args++;
appResources.message_lines * mesg_info->char_height;
XtSetArg(args[num_args], XtNheight, mesg_info->viewport_height);
num_args++;
XtSetValues(viewport, args, num_args);
XtAddCallback(wp->w, XtNresizeCallback, mesg_resized, (XtPointer) 0);
@@ -194,66 +199,67 @@ create_message_window(wp, create_popup, parent)
* viewport is also realized.
*/
if (create_popup) {
XtRealizeWidget(wp->popup);
XSetWMProtocols(XtDisplay(wp->popup), XtWindow(wp->popup),
&wm_delete_window, 1);
XtRealizeWidget(wp->popup);
XSetWMProtocols(XtDisplay(wp->popup), XtWindow(wp->popup),
&wm_delete_window, 1);
}
}
void
destroy_message_window(wp)
struct xwindow *wp;
struct xwindow *wp;
{
if (wp->popup) {
nh_XtPopdown(wp->popup);
if (!wp->keep_window)
XtDestroyWidget(wp->popup), wp->popup = (Widget)0;
nh_XtPopdown(wp->popup);
if (!wp->keep_window)
XtDestroyWidget(wp->popup), wp->popup = (Widget) 0;
}
if (wp->mesg_information) {
set_circle_buf(wp->mesg_information, 0); /* free buffer list */
free((genericptr_t)wp->mesg_information), wp->mesg_information = 0;
set_circle_buf(wp->mesg_information, 0); /* free buffer list */
free((genericptr_t) wp->mesg_information), wp->mesg_information = 0;
}
if (wp->keep_window)
XtRemoveCallback(wp->w, XtNexposeCallback, mesg_exposed, (XtPointer)0);
XtRemoveCallback(wp->w, XtNexposeCallback, mesg_exposed,
(XtPointer) 0);
else
wp->type = NHW_NONE;
wp->type = NHW_NONE;
}
/* Redraw message window if new lines have been added. */
void
display_message_window(wp)
struct xwindow *wp;
struct xwindow *wp;
{
if (wp->mesg_information->dirty) redraw_message_window(wp);
if (wp->mesg_information->dirty)
redraw_message_window(wp);
}
/*
* Append a line of text to the message window. Split the line if the
* rendering of the text is too long for the window.
*/
void
append_message(wp, str)
struct xwindow *wp;
const char *str;
struct xwindow *wp;
const char *str;
{
char *mark, *remainder, buf[BUFSZ];
if (!str) return;
if (!str)
return;
Strcpy(buf, str); /* we might mark it up */
Strcpy(buf, str); /* we might mark it up */
remainder = buf;
do {
mark = remainder;
remainder = split(mark, wp->mesg_information->fs, wp->pixel_width);
add_line(wp->mesg_information, mark);
mark = remainder;
remainder = split(mark, wp->mesg_information->fs, wp->pixel_width);
add_line(wp->mesg_information, mark);
} while (remainder);
}
/* private functions ======================================================= */
/* private functions =======================================================
*/
/*
* Return the element in the circular linked list just before the given
@@ -261,18 +267,18 @@ append_message(wp, str)
*/
static struct line_element *
get_previous(mark)
struct line_element *mark;
struct line_element *mark;
{
struct line_element *curr;
if (!mark) return (struct line_element *) 0;
if (!mark)
return (struct line_element *) 0;
for (curr = mark; curr->next != mark; curr = curr->next)
;
;
return curr;
}
/*
* Set the information buffer size to count lines. We do this by creating
* a circular linked list of elements, each of which represents a line of
@@ -281,67 +287,70 @@ get_previous(mark)
*/
static void
set_circle_buf(mesg_info, count)
struct mesg_info_t *mesg_info;
int count;
struct mesg_info_t *mesg_info;
int count;
{
int i;
struct line_element *tail, *curr, *head;
if (count < 0) panic("set_circle_buf: bad count [= %d]", count);
if (count == mesg_info->num_lines) return; /* no change in size */
if (count < 0)
panic("set_circle_buf: bad count [= %d]", count);
if (count == mesg_info->num_lines)
return; /* no change in size */
if (count < mesg_info->num_lines) {
/*
* Toss num_lines - count line entries from our circular list.
*
* We lose lines from the front (top) of the list. We _know_
* the list is non_empty.
*/
tail = get_previous(mesg_info->head);
for (i = mesg_info->num_lines - count; i > 0; i--) {
curr = mesg_info->head;
mesg_info->head = curr->next;
if (curr->line) free((genericptr_t)curr->line);
free((genericptr_t)curr);
}
if (count == 0) {
/* make sure we don't have a dangling pointer */
mesg_info->head = (struct line_element *) 0;
} else {
tail->next = mesg_info->head; /* link the tail to the head */
}
/*
* Toss num_lines - count line entries from our circular list.
*
* We lose lines from the front (top) of the list. We _know_
* the list is non_empty.
*/
tail = get_previous(mesg_info->head);
for (i = mesg_info->num_lines - count; i > 0; i--) {
curr = mesg_info->head;
mesg_info->head = curr->next;
if (curr->line)
free((genericptr_t) curr->line);
free((genericptr_t) curr);
}
if (count == 0) {
/* make sure we don't have a dangling pointer */
mesg_info->head = (struct line_element *) 0;
} else {
tail->next = mesg_info->head; /* link the tail to the head */
}
} else {
/*
* Add count - num_lines blank lines to the head of the list.
*
* Create a separate list, keeping track of the tail.
*/
for (head = tail = 0, i = 0; i < count - mesg_info->num_lines; i++) {
curr = (struct line_element *) alloc(sizeof(struct line_element));
curr->line = 0;
curr->buf_length = 0;
curr->str_length = 0;
if (tail) {
tail->next = curr;
tail = curr;
} else {
head = tail = curr;
}
}
/*
* Complete the circle by making the new tail point to the old head
* and the old tail point to the new head. If our line count was
* zero, then make the new list circular.
*/
if (mesg_info->num_lines) {
curr = get_previous(mesg_info->head);/* get end of old list */
/*
* Add count - num_lines blank lines to the head of the list.
*
* Create a separate list, keeping track of the tail.
*/
for (head = tail = 0, i = 0; i < count - mesg_info->num_lines; i++) {
curr = (struct line_element *) alloc(sizeof(struct line_element));
curr->line = 0;
curr->buf_length = 0;
curr->str_length = 0;
if (tail) {
tail->next = curr;
tail = curr;
} else {
head = tail = curr;
}
}
/*
* Complete the circle by making the new tail point to the old head
* and the old tail point to the new head. If our line count was
* zero, then make the new list circular.
*/
if (mesg_info->num_lines) {
curr = get_previous(mesg_info->head); /* get end of old list */
tail->next = mesg_info->head; /* new tail -> old head */
curr->next = head; /* old tail -> new head */
} else {
tail->next = head;
}
mesg_info->head = head;
tail->next = mesg_info->head; /* new tail -> old head */
curr->next = head; /* old tail -> new head */
} else {
tail->next = head;
}
mesg_info->head = head;
}
mesg_info->num_lines = count;
@@ -349,33 +358,33 @@ set_circle_buf(mesg_info, count)
mesg_info->last_pause = (struct line_element *) 0;
}
/*
* Make sure the given string is shorter than the given pixel width. If
* not, back up from the end by words until we find a place to split.
*/
static char *
split(s, fs, pixel_width)
char *s;
XFontStruct *fs; /* Font for the window. */
Dimension pixel_width;
char *s;
XFontStruct *fs; /* Font for the window. */
Dimension pixel_width;
{
char save, *end, *remainder;
save = '\0';
remainder = 0;
end = eos(s); /* point to null at end of string */
end = eos(s); /* point to null at end of string */
/* assume that if end == s, XXXXXX returns 0) */
while ((Dimension) XTextWidth(fs, s, (int) strlen(s)) > pixel_width) {
*end-- = save;
while (*end != ' ') {
if (end == s) panic("split: eos!");
--end;
}
save = *end;
*end = '\0';
remainder = end + 1;
*end-- = save;
while (*end != ' ') {
if (end == s)
panic("split: eos!");
--end;
}
save = *end;
*end = '\0';
remainder = end + 1;
}
return remainder;
}
@@ -388,27 +397,27 @@ split(s, fs, pixel_width)
*/
static void
add_line(mesg_info, s)
struct mesg_info_t *mesg_info;
const char *s;
struct mesg_info_t *mesg_info;
const char *s;
{
register struct line_element *curr = mesg_info->head;
register int new_line_length = strlen(s);
if (new_line_length + 1 > curr->buf_length) {
if (curr->line) free(curr->line); /* free old line */
if (curr->line)
free(curr->line); /* free old line */
curr->buf_length = new_line_length + 1;
curr->line = (char *) alloc((unsigned)curr->buf_length);
curr->buf_length = new_line_length + 1;
curr->line = (char *) alloc((unsigned) curr->buf_length);
}
Strcpy(curr->line, s); /* copy info */
curr->str_length = new_line_length; /* save string length */
Strcpy(curr->line, s); /* copy info */
curr->str_length = new_line_length; /* save string length */
mesg_info->head = mesg_info->head->next; /* move head to next line */
mesg_info->dirty = True; /* we have undrawn lines */
mesg_info->head = mesg_info->head->next; /* move head to next line */
mesg_info->dirty = True; /* we have undrawn lines */
}
/*
* Save a position in the text buffer so we can draw a line to seperate
* text from the last time this function was called.
@@ -419,7 +428,7 @@ add_line(mesg_info, s)
*/
void
set_last_pause(wp)
struct xwindow *wp;
struct xwindow *wp;
{
register struct mesg_info_t *mesg_info = wp->mesg_information;
@@ -429,26 +438,25 @@ set_last_pause(wp)
* don't try to erase the line again.
*/
if (!mesg_info->last_pause
&& mesg_info->last_pause_head == mesg_info->head)
return;
&& mesg_info->last_pause_head == mesg_info->head)
return;
if (mesg_info->last_pause == mesg_info->head) {
/* No new messages in last turn. Redraw window to erase line. */
mesg_info->last_pause = (struct line_element *) 0;
mesg_info->last_pause_head = mesg_info->head;
redraw_message_window(wp);
/* No new messages in last turn. Redraw window to erase line. */
mesg_info->last_pause = (struct line_element *) 0;
mesg_info->last_pause_head = mesg_info->head;
redraw_message_window(wp);
} else {
#endif
mesg_info->last_pause = mesg_info->head;
mesg_info->last_pause = mesg_info->head;
#ifdef ERASE_LINE
}
#endif
}
static void
redraw_message_window(wp)
struct xwindow *wp;
struct xwindow *wp;
{
struct mesg_info_t *mesg_info = wp->mesg_information;
register struct line_element *curr;
@@ -464,43 +472,36 @@ redraw_message_window(wp)
* Only need to clear if window has new text.
*/
if (mesg_info->dirty) {
XClearWindow(XtDisplay(wp->w), XtWindow(wp->w));
mesg_info->line_here = mesg_info->last_pause;
XClearWindow(XtDisplay(wp->w), XtWindow(wp->w));
mesg_info->line_here = mesg_info->last_pause;
}
/* For now, just update the whole shootn' match. */
for (y_base = row = 0, curr = mesg_info->head;
row < mesg_info->num_lines;
row++, y_base += mesg_info->char_height, curr = curr->next) {
XDrawString(XtDisplay(wp->w), XtWindow(wp->w),
mesg_info->gc,
mesg_info->char_lbearing,
mesg_info->char_ascent + y_base,
curr->line,
curr->str_length);
/*
* This draws a line at the _top_ of the line of text pointed to by
* mesg_info->last_pause.
*/
if (appResources.message_line && curr == mesg_info->line_here) {
XDrawLine(XtDisplay(wp->w), XtWindow(wp->w),
mesg_info->gc,
0, y_base, wp->pixel_width, y_base);
}
for (y_base = row = 0, curr = mesg_info->head; row < mesg_info->num_lines;
row++, y_base += mesg_info->char_height, curr = curr->next) {
XDrawString(XtDisplay(wp->w), XtWindow(wp->w), mesg_info->gc,
mesg_info->char_lbearing, mesg_info->char_ascent + y_base,
curr->line, curr->str_length);
/*
* This draws a line at the _top_ of the line of text pointed to by
* mesg_info->last_pause.
*/
if (appResources.message_line && curr == mesg_info->line_here) {
XDrawLine(XtDisplay(wp->w), XtWindow(wp->w), mesg_info->gc, 0,
y_base, wp->pixel_width, y_base);
}
}
mesg_info->dirty = False;
}
/*
* Check the size of the viewport. If it has shrunk, then we want to
* move the vertical slider to the bottom.
*/
static void
mesg_check_size_change(wp)
struct xwindow *wp;
struct xwindow *wp;
{
struct mesg_info_t *mesg_info = wp->mesg_information;
Arg arg[2];
@@ -509,59 +510,59 @@ mesg_check_size_change(wp)
viewport = XtParent(wp->w);
XtSetArg(arg[0], XtNwidth, &new_width);
XtSetArg(arg[0], XtNwidth, &new_width);
XtSetArg(arg[1], XtNheight, &new_height);
XtGetValues(viewport, arg, TWO);
/* Only move slider to bottom if new size is smaller. */
if (new_width < mesg_info->viewport_width
|| new_height < mesg_info->viewport_height) {
set_message_slider(wp);
|| new_height < mesg_info->viewport_height) {
set_message_slider(wp);
}
mesg_info->viewport_width = new_width;
mesg_info->viewport_height = new_height;
}
/* Event handler for message window expose events. */
/*ARGSUSED*/
static void
mesg_exposed(w, client_data, widget_data)
Widget w;
XtPointer client_data; /* unused */
XtPointer widget_data; /* expose event from Window widget */
Widget w;
XtPointer client_data; /* unused */
XtPointer widget_data; /* expose event from Window widget */
{
XExposeEvent *event = (XExposeEvent *) widget_data;
nhUse(client_data);
if (XtIsRealized(w) && event->count == 0) {
struct xwindow *wp;
Display *dpy;
Window win;
XEvent evt;
struct xwindow *wp;
Display *dpy;
Window win;
XEvent evt;
/*
* Drain all pending expose events for the message window;
* we'll redraw the whole thing at once.
*/
dpy = XtDisplay(w);
win = XtWindow(w);
while (XCheckTypedWindowEvent(dpy, win, Expose, &evt)) continue;
/*
* Drain all pending expose events for the message window;
* we'll redraw the whole thing at once.
*/
dpy = XtDisplay(w);
win = XtWindow(w);
while (XCheckTypedWindowEvent(dpy, win, Expose, &evt))
continue;
wp = find_widget(w);
if (wp->keep_window && !wp->mesg_information) return;
mesg_check_size_change(wp);
redraw_message_window(wp);
wp = find_widget(w);
if (wp->keep_window && !wp->mesg_information)
return;
mesg_check_size_change(wp);
redraw_message_window(wp);
}
}
static void
get_gc(w, mesg_info)
Widget w;
struct mesg_info_t *mesg_info;
Widget w;
struct mesg_info_t *mesg_info;
{
XGCValues values;
XtGCMask mask = GCFunction | GCForeground | GCBackground | GCFont;
@@ -574,8 +575,8 @@ get_gc(w, mesg_info)
values.foreground = fgpixel;
values.background = bgpixel;
values.function = GXcopy;
values.font = WindowFont(w);
values.function = GXcopy;
values.font = WindowFont(w);
mesg_info->gc = XtGetGC(w, mask, &values);
}
@@ -592,8 +593,8 @@ get_gc(w, mesg_info)
/* ARGSUSED */
static void
mesg_resized(w, client_data, call_data)
Widget w;
XtPointer call_data, client_data;
Widget w;
XtPointer call_data, client_data;
{
Arg args[4];
Cardinal num_args;
@@ -602,30 +603,32 @@ mesg_resized(w, client_data, call_data)
#ifdef VERBOSE
int old_lines;
old_lines = wp->mesg_information->num_lines;;
old_lines = wp->mesg_information->num_lines;
;
#endif
nhUse(call_data);
nhUse(client_data);
num_args = 0;
XtSetArg(args[num_args], XtNwidth, &pixel_width); num_args++;
XtSetArg(args[num_args], XtNheight, &pixel_height); num_args++;
XtSetArg(args[num_args], XtNwidth, &pixel_width);
num_args++;
XtSetArg(args[num_args], XtNheight, &pixel_height);
num_args++;
XtGetValues(w, args, num_args);
wp = find_widget(w);
wp->pixel_width = pixel_width;
wp->pixel_width = pixel_width;
wp->pixel_height = pixel_height;
set_circle_buf(wp->mesg_information,
(int) pixel_height / wp->mesg_information->char_height);
(int) pixel_height / wp->mesg_information->char_height);
#ifdef VERBOSE
printf("Message resize. Pixel: width = %d, height = %d; Lines: old = %d, new = %d\n",
pixel_width,
pixel_height,
old_lines,
wp->mesg_information->num_lines);
printf("Message resize. Pixel: width = %d, height = %d; Lines: old = "
"%d, new = %d\n",
pixel_width, pixel_height, old_lines,
wp->mesg_information->num_lines);
#endif
}
+534 -513
View File
File diff suppressed because it is too large Load Diff
+634 -547
View File
File diff suppressed because it is too large Load Diff
+260 -244
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 wintext.c $NHDT-Date: 1430899138 2015/05/06 07:58:58 $ $NHDT-Branch: master $:$NHDT-Revision: 1.10 $ */
/* NetHack 3.6 wintext.c $NHDT-Date: 1431192773 2015/05/09 17:32:53 $ $NHDT-Branch: master $:$NHDT-Revision: 1.13 $ */
/* NetHack 3.6 wintext.c $Date: 2012/01/24 04:26:27 $ $Revision: 1.7 $ */
/* SCCS Id: @(#)wintext.c 3.5 1996/04/05 */
/* Copyright (c) Dean Luick, 1992 */
@@ -11,7 +11,7 @@
*/
#ifndef SYSV
#define PRESERVE_NO_SYSV /* X11 include files may define SYSV */
#define PRESERVE_NO_SYSV /* X11 include files may define SYSV */
#endif
#include <X11/Intrinsic.h>
@@ -24,10 +24,10 @@
#include <X11/Xatom.h>
#ifdef PRESERVE_NO_SYSV
# ifdef SYSV
# undef SYSV
# endif
# undef PRESERVE_NO_SYSV
#ifdef SYSV
#undef SYSV
#endif
#undef PRESERVE_NO_SYSV
#endif
#include "hack.h"
@@ -38,17 +38,15 @@
#include <X11/xpm.h>
#endif
#define TRANSIENT_TEXT /* text window is a transient window (no positioning) \
*/
#define TRANSIENT_TEXT /* text window is a transient window (no positioning) */
static const char text_translations[] =
"#override\n\
static const char text_translations[] = "#override\n\
<BtnDown>: dismiss_text()\n\
<Key>: key_dismiss_text()";
#ifdef GRAPHIC_TOMBSTONE
static const char rip_translations[] =
"#override\n\
static const char rip_translations[] = "#override\n\
<BtnDown>: rip_dismiss_text()\n\
<Key>: rip_dismiss_text()";
@@ -58,10 +56,10 @@ static Widget FDECL(create_ripout_widget, (Widget));
/*ARGSUSED*/
void
delete_text(w, event, params, num_params)
Widget w;
XEvent *event;
String *params;
Cardinal *num_params;
Widget w;
XEvent *event;
String *params;
Cardinal *num_params;
{
struct xwindow *wp;
struct text_info_t *text_info;
@@ -76,9 +74,9 @@ delete_text(w, event, params, num_params)
nh_XtPopdown(wp->popup);
if (text_info->blocked) {
exit_x_event = TRUE;
exit_x_event = TRUE;
} else if (text_info->destroy_on_ack) {
destroy_text_window(wp);
destroy_text_window(wp);
}
}
@@ -90,10 +88,10 @@ delete_text(w, event, params, num_params)
/*ARGSUSED*/
void
dismiss_text(w, event, params, num_params)
Widget w;
XEvent *event;
String *params;
Cardinal *num_params;
Widget w;
XEvent *event;
String *params;
Cardinal *num_params;
{
struct xwindow *wp;
struct text_info_t *text_info;
@@ -108,44 +106,44 @@ dismiss_text(w, event, params, num_params)
nh_XtPopdown(wp->popup);
if (text_info->blocked) {
exit_x_event = TRUE;
exit_x_event = TRUE;
} else if (text_info->destroy_on_ack) {
destroy_text_window(wp);
destroy_text_window(wp);
}
}
/* Dismiss when a non-modifier key pressed. */
void
key_dismiss_text(w, event, params, num_params)
Widget w;
XEvent *event;
String *params;
Cardinal *num_params;
Widget w;
XEvent *event;
String *params;
Cardinal *num_params;
{
char ch = key_event_to_char((XKeyEvent *) event);
if (ch) dismiss_text(w, event, params, num_params);
if (ch)
dismiss_text(w, event, params, num_params);
}
#ifdef GRAPHIC_TOMBSTONE
/* Dismiss from clicking on rip image. */
void
rip_dismiss_text(w, event, params, num_params)
Widget w;
XEvent *event;
String *params;
Cardinal *num_params;
Widget w;
XEvent *event;
String *params;
Cardinal *num_params;
{
dismiss_text(XtParent(w), event, params, num_params);
}
#endif
/* ARGSUSED */
void
add_to_text_window(wp, attr, str)
struct xwindow *wp;
int attr; /* currently unused */
const char *str;
struct xwindow *wp;
int attr; /* currently unused */
const char *str;
{
struct text_info_t *text_info = wp->text_information;
int width;
@@ -157,13 +155,13 @@ add_to_text_window(wp, attr, str)
/* Calculate text width and save longest line */
width = XTextWidth(text_info->fs, str, (int) strlen(str));
if (width > text_info->max_width)
text_info->max_width = width;
text_info->max_width = width;
}
void
display_text_window(wp, blocking)
struct xwindow *wp;
boolean blocking;
struct xwindow *wp;
boolean blocking;
{
struct text_info_t *text_info;
Arg args[8];
@@ -172,7 +170,7 @@ display_text_window(wp, blocking)
int nlines;
text_info = wp->text_information;
width = text_info->max_width + text_info->extra_width;
width = text_info->max_width + text_info->extra_width;
text_info->blocked = blocking;
text_info->destroy_on_ack = FALSE;
font_height = nhFontHeight(wp->w);
@@ -185,74 +183,83 @@ display_text_window(wp, blocking)
* _some_ lines. Finally, use the number of lines in the text if
* there are fewer than the max.
*/
nlines = (XtScreen(wp->w)->height - text_info->extra_height) / font_height;
nlines =
(XtScreen(wp->w)->height - text_info->extra_height) / font_height;
nlines -= 4;
if (nlines > text_info->text.num_lines)
nlines = text_info->text.num_lines;
if (nlines <= 0) nlines = 1;
nlines = text_info->text.num_lines;
if (nlines <= 0)
nlines = 1;
height = nlines * font_height + text_info->extra_height;
num_args = 0;
if (nlines < text_info->text.num_lines) {
/* add on width of scrollbar. Really should look this up,
* but can't until the window is realized. Chicken-and-egg problem.
*/
width += 20;
/* add on width of scrollbar. Really should look this up,
* but can't until the window is realized. Chicken-and-egg problem.
*/
width += 20;
}
#ifdef GRAPHIC_TOMBSTONE
if (text_info->is_rip) {
Widget rip = create_ripout_widget(XtParent(wp->w));
XtSetArg(args[num_args], XtNfromVert, rip); num_args++;
Widget rip = create_ripout_widget(XtParent(wp->w));
XtSetArg(args[num_args], XtNfromVert, rip);
num_args++;
}
#endif
if (width > (Dimension) XtScreen(wp->w)->width) { /* too wide for screen */
/* Back off some amount - we really need to back off the scrollbar */
/* width plus some extra. */
width = XtScreen(wp->w)->width - 20;
if (width
> (Dimension) XtScreen(wp->w)->width) { /* too wide for screen */
/* Back off some amount - we really need to back off the scrollbar */
/* width plus some extra. */
width = XtScreen(wp->w)->width - 20;
}
XtSetArg(args[num_args], XtNstring, text_info->text.text); num_args++;
XtSetArg(args[num_args], XtNwidth, width); num_args++;
XtSetArg(args[num_args], XtNheight, height); num_args++;
XtSetArg(args[num_args], XtNstring, text_info->text.text);
num_args++;
XtSetArg(args[num_args], XtNwidth, width);
num_args++;
XtSetArg(args[num_args], XtNheight, height);
num_args++;
XtSetValues(wp->w, args, num_args);
#ifdef TRANSIENT_TEXT
XtRealizeWidget(wp->popup);
XSetWMProtocols(XtDisplay(wp->popup), XtWindow(wp->popup),
&wm_delete_window, 1);
&wm_delete_window, 1);
positionpopup(wp->popup, FALSE);
#endif
nh_XtPopup(wp->popup, (int)XtGrabNone, wp->w);
nh_XtPopup(wp->popup, (int) XtGrabNone, wp->w);
/* Kludge alert. Scrollbars are not sized correctly by the Text widget */
/* if added before the window is displayed, so do it afterward. */
num_args = 0;
if (nlines < text_info->text.num_lines) { /* add vert scrollbar */
XtSetArg(args[num_args], nhStr(XtNscrollVertical),
XawtextScrollAlways); num_args++;
if (nlines < text_info->text.num_lines) { /* add vert scrollbar */
XtSetArg(args[num_args], nhStr(XtNscrollVertical),
XawtextScrollAlways);
num_args++;
}
if (width >= (Dimension) (XtScreen(wp->w)->width-20)) { /* too wide */
XtSetArg(args[num_args], nhStr(XtNscrollHorizontal),
XawtextScrollAlways); num_args++;
if (width >= (Dimension)(XtScreen(wp->w)->width - 20)) { /* too wide */
XtSetArg(args[num_args], nhStr(XtNscrollHorizontal),
XawtextScrollAlways);
num_args++;
}
if (num_args) XtSetValues(wp->w, args, num_args);
if (num_args)
XtSetValues(wp->w, args, num_args);
/* We want the user to acknowlege. */
if (blocking) {
(void) x_event(EXIT_ON_EXIT);
nh_XtPopdown(wp->popup);
(void) x_event(EXIT_ON_EXIT);
nh_XtPopdown(wp->popup);
}
}
void
create_text_window(wp)
struct xwindow *wp;
struct xwindow *wp;
{
struct text_info_t *text_info;
Arg args[8];
@@ -263,72 +270,80 @@ create_text_window(wp)
wp->type = NHW_TEXT;
wp->text_information = text_info =
(struct text_info_t *) alloc(sizeof(struct text_info_t));
(struct text_info_t *) alloc(sizeof(struct text_info_t));
init_text_buffer(&text_info->text);
text_info->max_width = 0;
text_info->extra_width = 0;
text_info->extra_height = 0;
text_info->blocked = FALSE;
text_info->destroy_on_ack = TRUE; /* Ok to destroy before display */
text_info->max_width = 0;
text_info->extra_width = 0;
text_info->extra_height = 0;
text_info->blocked = FALSE;
text_info->destroy_on_ack = TRUE; /* Ok to destroy before display */
#ifdef GRAPHIC_TOMBSTONE
text_info->is_rip = FALSE;
text_info->is_rip = FALSE;
#endif
num_args = 0;
XtSetArg(args[num_args], XtNallowShellResize, True); num_args++;
XtSetArg(args[num_args], XtNallowShellResize, True);
num_args++;
XtSetArg(args[num_args], XtNtranslations,
XtParseTranslationTable(text_translations)); num_args++;
XtParseTranslationTable(text_translations));
num_args++;
#ifdef TRANSIENT_TEXT
wp->popup = XtCreatePopupShell("text", transientShellWidgetClass,
toplevel, args, num_args);
toplevel, args, num_args);
#else
wp->popup = XtCreatePopupShell("text", topLevelShellWidgetClass,
toplevel, args, num_args);
wp->popup = XtCreatePopupShell("text", topLevelShellWidgetClass, toplevel,
args, num_args);
#endif
XtOverrideTranslations(wp->popup,
XtParseTranslationTable("<Message>WM_PROTOCOLS: delete_text()"));
XtOverrideTranslations(
wp->popup,
XtParseTranslationTable("<Message>WM_PROTOCOLS: delete_text()"));
num_args = 0;
XtSetArg(args[num_args], XtNallowShellResize, True); num_args++;
form = XtCreateManagedWidget("form", formWidgetClass, wp->popup,
args, num_args);
XtSetArg(args[num_args], XtNallowShellResize, True);
num_args++;
form = XtCreateManagedWidget("form", formWidgetClass, wp->popup, args,
num_args);
num_args = 0;
XtSetArg(args[num_args], nhStr(XtNdisplayCaret), False); num_args++;
XtSetArg(args[num_args], XtNresize, XawtextResizeBoth); num_args++;
XtSetArg(args[num_args], nhStr(XtNdisplayCaret), False);
num_args++;
XtSetArg(args[num_args], XtNresize, XawtextResizeBoth);
num_args++;
XtSetArg(args[num_args], XtNtranslations,
XtParseTranslationTable(text_translations)); num_args++;
XtParseTranslationTable(text_translations));
num_args++;
wp->w = XtCreateManagedWidget(
killer.name[0] && WIN_MAP == WIN_ERR ?
"tombstone" : "text_text", /* name */
asciiTextWidgetClass,
form, /* parent widget */
args, /* set some values */
num_args); /* number of values to set */
wp->w = XtCreateManagedWidget(killer.name[0] && WIN_MAP == WIN_ERR
? "tombstone"
: "text_text", /* name */
asciiTextWidgetClass,
form, /* parent widget */
args, /* set some values */
num_args); /* number of values to set */
/* Get the font and margin information. */
num_args = 0;
XtSetArg(args[num_args], XtNfont, &text_info->fs); num_args++;
XtSetArg(args[num_args], nhStr(XtNtopMargin),
&top_margin); num_args++;
XtSetArg(args[num_args], nhStr(XtNbottomMargin),
&bottom_margin); num_args++;
XtSetArg(args[num_args], nhStr(XtNleftMargin),
&left_margin); num_args++;
XtSetArg(args[num_args], nhStr(XtNrightMargin),
&right_margin); num_args++;
XtSetArg(args[num_args], XtNfont, &text_info->fs);
num_args++;
XtSetArg(args[num_args], nhStr(XtNtopMargin), &top_margin);
num_args++;
XtSetArg(args[num_args], nhStr(XtNbottomMargin), &bottom_margin);
num_args++;
XtSetArg(args[num_args], nhStr(XtNleftMargin), &left_margin);
num_args++;
XtSetArg(args[num_args], nhStr(XtNrightMargin), &right_margin);
num_args++;
XtGetValues(wp->w, args, num_args);
text_info->extra_width = left_margin + right_margin;
text_info->extra_width = left_margin + right_margin;
text_info->extra_height = top_margin + bottom_margin;
}
void
destroy_text_window(wp)
struct xwindow *wp;
struct xwindow *wp;
{
/* Don't need to pop down, this only called from dismiss_text(). */
@@ -341,78 +356,81 @@ destroy_text_window(wp)
* press.
*/
if (text_info->blocked || text_info->destroy_on_ack) {
XtDestroyWidget(wp->popup);
free_text_buffer(&text_info->text);
free((genericptr_t)text_info), wp->text_information = 0;
wp->type = NHW_NONE; /* allow reuse */
XtDestroyWidget(wp->popup);
free_text_buffer(&text_info->text);
free((genericptr_t) text_info), wp->text_information = 0;
wp->type = NHW_NONE; /* allow reuse */
} else {
text_info->destroy_on_ack = TRUE; /* destroy on next ACK */
text_info->destroy_on_ack = TRUE; /* destroy on next ACK */
}
}
void
clear_text_window(wp)
struct xwindow *wp;
struct xwindow *wp;
{
clear_text_buffer(&wp->text_information->text);
}
/* text buffer routines ---------------------------------------------------- */
/* text buffer routines ----------------------------------------------------
*/
/* Append a line to the text buffer. */
void
append_text_buffer(tb, str, concat)
struct text_buffer *tb;
const char *str;
boolean concat;
struct text_buffer *tb;
const char *str;
boolean concat;
{
char *copy;
int length;
if (!tb->text) panic("append_text_buffer: null text buffer");
if (!tb->text)
panic("append_text_buffer: null text buffer");
if (str) {
length = strlen(str);
length = strlen(str);
} else {
length = 0;
length = 0;
}
if (length + tb->text_last + 1 >= tb->text_size) {
/* we need to go to a bigger buffer! */
/* we need to go to a bigger buffer! */
#ifdef VERBOSE
printf("append_text_buffer: text buffer growing from %d to %d bytes\n",
tb->text_size, 2*tb->text_size);
printf(
"append_text_buffer: text buffer growing from %d to %d bytes\n",
tb->text_size, 2 * tb->text_size);
#endif
copy = (char *) alloc((unsigned)tb->text_size*2);
(void) memcpy(copy, tb->text, tb->text_last);
free(tb->text);
tb->text = copy;
tb->text_size *= 2;
copy = (char *) alloc((unsigned) tb->text_size * 2);
(void) memcpy(copy, tb->text, tb->text_last);
free(tb->text);
tb->text = copy;
tb->text_size *= 2;
}
if (tb->num_lines) { /* not first --- append a newline */
char appchar = '\n';
if (tb->num_lines) { /* not first --- append a newline */
char appchar = '\n';
if(concat && !index("!.?'\")", tb->text[tb->text_last-1])) {
appchar = ' ';
tb->num_lines--; /* offset increment at end of function */
}
if (concat && !index("!.?'\")", tb->text[tb->text_last - 1])) {
appchar = ' ';
tb->num_lines--; /* offset increment at end of function */
}
*(tb->text + tb->text_last) = appchar;
tb->text_last++;
*(tb->text + tb->text_last) = appchar;
tb->text_last++;
}
if (str) {
(void) memcpy((tb->text+tb->text_last), str, length+1);
if(length) {
/* Remove all newlines. Otherwise we have a confused line count. */
copy = (tb->text+tb->text_last);
while ((copy = index(copy, '\n')) != (char*)0)
*copy = ' ';
}
(void) memcpy((tb->text + tb->text_last), str, length + 1);
if (length) {
/* Remove all newlines. Otherwise we have a confused line count.
*/
copy = (tb->text + tb->text_last);
while ((copy = index(copy, '\n')) != (char *) 0)
*copy = ' ';
}
tb->text_last += length;
tb->text_last += length;
}
tb->text[tb->text_last] = '\0';
tb->num_lines++;
@@ -421,10 +439,10 @@ append_text_buffer(tb, str, concat)
/* Initialize text buffer. */
void
init_text_buffer(tb)
struct text_buffer *tb;
struct text_buffer *tb;
{
tb->text = (char *) alloc(START_SIZE);
tb->text[0] = '\0';
tb->text = (char *) alloc(START_SIZE);
tb->text[0] = '\0';
tb->text_size = START_SIZE;
tb->text_last = 0;
tb->num_lines = 0;
@@ -433,17 +451,17 @@ init_text_buffer(tb)
/* Empty the text buffer */
void
clear_text_buffer(tb)
struct text_buffer *tb;
struct text_buffer *tb;
{
tb->text_last = 0;
tb->text[0] = '\0';
tb->text[0] = '\0';
tb->num_lines = 0;
}
/* Free up allocated memory. */
void
free_text_buffer(tb)
struct text_buffer *tb;
struct text_buffer *tb;
{
free(tb->text);
tb->text = (char *) 0;
@@ -452,100 +470,95 @@ free_text_buffer(tb)
tb->num_lines = 0;
}
#ifdef GRAPHIC_TOMBSTONE
static void FDECL(rip_exposed, (Widget,XtPointer,XtPointer));
static void FDECL(rip_exposed, (Widget, XtPointer, XtPointer));
static XImage* rip_image=0;
static XImage *rip_image = 0;
#define STONE_LINE_LEN 16 /* # chars that fit on one line */
#define NAME_LINE 0 /* line # for player name */
#define GOLD_LINE 1 /* line # for amount of gold */
#define DEATH_LINE 2 /* line # for death description */
#define YEAR_LINE 6 /* line # for year */
#define STONE_LINE_LEN 16 /* # chars that fit on one line */
#define NAME_LINE 0 /* line # for player name */
#define GOLD_LINE 1 /* line # for amount of gold */
#define DEATH_LINE 2 /* line # for death description */
#define YEAR_LINE 6 /* line # for year */
static char rip_line[YEAR_LINE+1][STONE_LINE_LEN+1];
static char rip_line[YEAR_LINE + 1][STONE_LINE_LEN + 1];
void
calculate_rip_text(int how, time_t when)
{
/* Follows same algorithm as genl_outrip() */
/* Follows same algorithm as genl_outrip() */
char buf[BUFSZ];
char *dpx;
int line;
long year;
char buf[BUFSZ];
char *dpx;
int line;
long year;
/* Put name on stone */
Sprintf(rip_line[NAME_LINE], "%s", plname);
/* Put name on stone */
Sprintf(rip_line[NAME_LINE], "%s", plname);
/* Put $ on stone */
Sprintf(rip_line[GOLD_LINE], "%ld Au",
done_money);
/* Put together death description */
formatkiller(buf, sizeof buf, how);
/* Put $ on stone */
Sprintf(rip_line[GOLD_LINE], "%ld Au", done_money);
/* Put together death description */
formatkiller(buf, sizeof buf, how);
/* Put death type on stone */
for (line=DEATH_LINE, dpx = buf; line<YEAR_LINE; line++) {
register int i,i0;
char tmpchar;
/* Put death type on stone */
for (line = DEATH_LINE, dpx = buf; line < YEAR_LINE; line++) {
register int i, i0;
char tmpchar;
if ( (i0=strlen(dpx)) > STONE_LINE_LEN) {
for(i = STONE_LINE_LEN;
((i0 > STONE_LINE_LEN) && i); i--)
if(dpx[i] == ' ') i0 = i;
if(!i) i0 = STONE_LINE_LEN;
}
tmpchar = dpx[i0];
dpx[i0] = 0;
strcpy(rip_line[line], dpx);
if (tmpchar != ' ') {
dpx[i0] = tmpchar;
dpx= &dpx[i0];
} else dpx= &dpx[i0+1];
}
if ((i0 = strlen(dpx)) > STONE_LINE_LEN) {
for (i = STONE_LINE_LEN; ((i0 > STONE_LINE_LEN) && i); i--)
if (dpx[i] == ' ')
i0 = i;
if (!i)
i0 = STONE_LINE_LEN;
}
tmpchar = dpx[i0];
dpx[i0] = 0;
strcpy(rip_line[line], dpx);
if (tmpchar != ' ') {
dpx[i0] = tmpchar;
dpx = &dpx[i0];
} else
dpx = &dpx[i0 + 1];
}
/* Put year on stone */
year = yyyymmdd(when) / 10000L;
Sprintf(rip_line[YEAR_LINE], "%4ld", year);
/* Put year on stone */
year = yyyymmdd(when) / 10000L;
Sprintf(rip_line[YEAR_LINE], "%4ld", year);
}
/*
* RIP image expose callback.
*/
/*ARGSUSED*/
static void
rip_exposed(w, client_data, widget_data)
Widget w;
XtPointer client_data; /* unused */
XtPointer widget_data; /* expose event from Window widget */
Widget w;
XtPointer client_data; /* unused */
XtPointer widget_data; /* expose event from Window widget */
{
XExposeEvent *event = (XExposeEvent *) widget_data;
Display* dpy=XtDisplay(w);
Display *dpy = XtDisplay(w);
Arg args[8];
XGCValues values;
XtGCMask mask;
GC gc;
static Pixmap rip_pixmap=None;
static Pixmap rip_pixmap = None;
int i, x, y;
if (!XtIsRealized(w) || event->count > 0) return;
if (!XtIsRealized(w) || event->count > 0)
return;
if (rip_pixmap == None && rip_image) {
rip_pixmap = XCreatePixmap(dpy, XtWindow(w),
rip_image->width,
rip_image->height,
DefaultDepth(dpy, DefaultScreen(dpy)));
XPutImage(dpy, rip_pixmap,
DefaultGC(dpy, DefaultScreen(dpy)),
rip_image,
0,0, 0,0, /* src, dest top left */
rip_image->width,
rip_image->height);
XDestroyImage(rip_image); /* data bytes free'd also */
rip_pixmap = XCreatePixmap(dpy, XtWindow(w), rip_image->width,
rip_image->height,
DefaultDepth(dpy, DefaultScreen(dpy)));
XPutImage(dpy, rip_pixmap, DefaultGC(dpy, DefaultScreen(dpy)),
rip_image, 0, 0, 0, 0, /* src, dest top left */
rip_image->width, rip_image->height);
XDestroyImage(rip_image); /* data bytes free'd also */
}
mask = GCFunction | GCForeground | GCGraphicsExposures | GCFont;
@@ -557,21 +570,19 @@ rip_exposed(w, client_data, widget_data)
gc = XtGetGC(w, mask, &values);
if (rip_pixmap != None) {
XCopyArea(dpy, rip_pixmap, XtWindow(w), gc,
event->x, event->y, event->width, event->height,
event->x, event->y);
XCopyArea(dpy, rip_pixmap, XtWindow(w), gc, event->x, event->y,
event->width, event->height, event->x, event->y);
}
x=appResources.tombtext_x;
y=appResources.tombtext_y;
for (i=0; i<=YEAR_LINE; i++) {
int len=strlen(rip_line[i]);
XFontStruct* font=WindowFontStruct(w);
int width=XTextWidth(font, rip_line[i], len);
XDrawString(dpy, XtWindow(w), gc,
x-width/2, y, rip_line[i], len);
x+=appResources.tombtext_dx;
y+=appResources.tombtext_dy;
x = appResources.tombtext_x;
y = appResources.tombtext_y;
for (i = 0; i <= YEAR_LINE; i++) {
int len = strlen(rip_line[i]);
XFontStruct *font = WindowFontStruct(w);
int width = XTextWidth(font, rip_line[i], len);
XDrawString(dpy, XtWindow(w), gc, x - width / 2, y, rip_line[i], len);
x += appResources.tombtext_dx;
y += appResources.tombtext_dy;
}
XtReleaseGC(w, gc);
@@ -590,30 +601,35 @@ create_ripout_widget(Widget parent)
static int rip_width, rip_height;
if (!rip_image) {
XpmAttributes attributes;
int errorcode;
XpmAttributes attributes;
int errorcode;
attributes.valuemask = XpmCloseness;
attributes.closeness = 65535; /* Try anything */
errorcode = XpmReadFileToImage(XtDisplay(parent), appResources.tombstone, &rip_image, 0, &attributes);
if (errorcode != XpmSuccess) {
char buf[BUFSZ];
Sprintf(buf, "Failed to load %s: %s", appResources.tombstone,
XpmGetErrorString(errorcode));
X11_raw_print(buf);
}
rip_width = rip_image->width;
rip_height = rip_image->height;
attributes.valuemask = XpmCloseness;
attributes.closeness = 65535; /* Try anything */
errorcode =
XpmReadFileToImage(XtDisplay(parent), appResources.tombstone,
&rip_image, 0, &attributes);
if (errorcode != XpmSuccess) {
char buf[BUFSZ];
Sprintf(buf, "Failed to load %s: %s", appResources.tombstone,
XpmGetErrorString(errorcode));
X11_raw_print(buf);
}
rip_width = rip_image->width;
rip_height = rip_image->height;
}
num_args = 0;
XtSetArg(args[num_args], XtNwidth, rip_width); num_args++;
XtSetArg(args[num_args], XtNheight, rip_height); num_args++;
XtSetArg(args[num_args], XtNwidth, rip_width);
num_args++;
XtSetArg(args[num_args], XtNheight, rip_height);
num_args++;
XtSetArg(args[num_args], XtNtranslations,
XtParseTranslationTable(rip_translations)); num_args++;
XtParseTranslationTable(rip_translations));
num_args++;
imageport = XtCreateManagedWidget("rip", windowWidgetClass,
parent, args, num_args);
imageport = XtCreateManagedWidget("rip", windowWidgetClass, parent, args,
num_args);
XtAddCallback(imageport, XtNexposeCallback, rip_exposed, (XtPointer) 0);
+47 -43
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 winval.c $NHDT-Date: 1430899139 2015/05/06 07:58:59 $ $NHDT-Branch: master $:$NHDT-Revision: 1.5 $ */
/* NetHack 3.6 winval.c $NHDT-Date: 1431192774 2015/05/09 17:32:54 $ $NHDT-Branch: master $:$NHDT-Revision: 1.8 $ */
/* NetHack 3.6 winval.c $Date: 2009/05/06 10:56:06 $ $Revision: 1.4 $ */
/* SCCS Id: @(#)winval.c 3.5 1992/3/7 */
/* Copyright (c) Dean Luick, 1992 */
@@ -11,7 +11,7 @@
#include <stdio.h>
#ifndef SYSV
#define PRESERVE_NO_SYSV /* X11 include files may define SYSV */
#define PRESERVE_NO_SYSV /* X11 include files may define SYSV */
#endif
#include <X11/Intrinsic.h>
@@ -21,59 +21,65 @@
#include <X11/Xaw/Cardinals.h>
#ifdef PRESERVE_NO_SYSV
# ifdef SYSV
# undef SYSV
# endif
# undef PRESERVE_NO_SYSV
#ifdef SYSV
#undef SYSV
#endif
#undef PRESERVE_NO_SYSV
#endif
#include "hack.h" /* #define for const for non __STDC__ compilers */
#include "hack.h" /* #define for const for non __STDC__ compilers */
#include "winX.h"
#define WNAME "name"
#define WVALUE "value"
Widget
create_value(parent, name_value)
Widget parent;
const char *name_value;
Widget parent;
const char *name_value;
{
Widget form, name;
Arg args[8];
Cardinal num_args;
num_args = 0;
XtSetArg(args[num_args], XtNborderWidth, 0); num_args++;
XtSetArg(args[num_args], nhStr(XtNdefaultDistance), 0); num_args++;
form = XtCreateManagedWidget(name_value,
formWidgetClass,
parent, args, num_args);
XtSetArg(args[num_args], XtNborderWidth, 0);
num_args++;
XtSetArg(args[num_args], nhStr(XtNdefaultDistance), 0);
num_args++;
form = XtCreateManagedWidget(name_value, formWidgetClass, parent, args,
num_args);
num_args = 0;
XtSetArg(args[num_args], XtNjustify, XtJustifyRight); num_args++;
XtSetArg(args[num_args], XtNborderWidth, 0); num_args++;
XtSetArg(args[num_args], XtNlabel, name_value); num_args++;
XtSetArg(args[num_args], XtNinternalHeight, 0); num_args++;
name = XtCreateManagedWidget(WNAME,
labelWidgetClass,
form, args, num_args);
XtSetArg(args[num_args], XtNjustify, XtJustifyRight);
num_args++;
XtSetArg(args[num_args], XtNborderWidth, 0);
num_args++;
XtSetArg(args[num_args], XtNlabel, name_value);
num_args++;
XtSetArg(args[num_args], XtNinternalHeight, 0);
num_args++;
name =
XtCreateManagedWidget(WNAME, labelWidgetClass, form, args, num_args);
num_args = 0;
XtSetArg(args[num_args], XtNjustify, XtJustifyRight); num_args++;
XtSetArg(args[num_args], XtNborderWidth, 0); num_args++;
XtSetArg(args[num_args], nhStr(XtNfromHoriz), name); num_args++;
XtSetArg(args[num_args], XtNinternalHeight, 0); num_args++;
(void) XtCreateManagedWidget(WVALUE,
labelWidgetClass,
form, args, num_args);
XtSetArg(args[num_args], XtNjustify, XtJustifyRight);
num_args++;
XtSetArg(args[num_args], XtNborderWidth, 0);
num_args++;
XtSetArg(args[num_args], nhStr(XtNfromHoriz), name);
num_args++;
XtSetArg(args[num_args], XtNinternalHeight, 0);
num_args++;
(void) XtCreateManagedWidget(WVALUE, labelWidgetClass, form, args,
num_args);
return form;
}
void
set_name(w, new_label)
Widget w;
const char *new_label;
Widget w;
const char *new_label;
{
Arg args[1];
Widget name;
@@ -85,8 +91,8 @@ set_name(w, new_label)
void
set_name_width(w, new_width)
Widget w;
int new_width;
Widget w;
int new_width;
{
Arg args[1];
Widget name;
@@ -98,7 +104,7 @@ set_name_width(w, new_width)
int
get_name_width(w)
Widget w;
Widget w;
{
Arg args[1];
Dimension width;
@@ -110,11 +116,10 @@ get_name_width(w)
return (int) width;
}
void
set_value(w, new_value)
Widget w;
const char *new_value;
Widget w;
const char *new_value;
{
Arg args[1];
Widget val;
@@ -126,8 +131,8 @@ set_value(w, new_value)
void
set_value_width(w, new_width)
Widget w;
int new_width;
Widget w;
int new_width;
{
Arg args[1];
Widget val;
@@ -139,7 +144,7 @@ set_value_width(w, new_width)
int
get_value_width(w)
Widget w;
Widget w;
{
Arg args[1];
Widget val;
@@ -155,7 +160,7 @@ get_value_width(w)
/* a label widget, unless I can get some init hook in there). */
void
hilight_value(w)
Widget w;
Widget w;
{
swap_fg_bg(XtNameToWidget(w, WVALUE));
}
@@ -163,7 +168,7 @@ hilight_value(w)
/* Swap the foreground and background colors of the given widget */
void
swap_fg_bg(w)
Widget w;
Widget w;
{
Arg args[2];
Pixel fg, bg;
@@ -176,4 +181,3 @@ swap_fg_bg(w)
XtSetArg(args[1], XtNbackground, fg);
XtSetValues(w, args, TWO);
}
+207 -234
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 wc_chainin.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
/* NetHack 3.6 wc_chainin.c $NHDT-Date: 1431192771 2015/05/09 17:32:51 $ $NHDT-Branch: master $:$NHDT-Revision: 1.5 $ */
/* NetHack 3.6 wc_chainin.c $Date: 2012/01/23 10:45:31 $ $Revision: 1.2 $ */
/* Copyright (c) Kenneth Lorber, 2012 */
/* NetHack may be freely redistributed. See license for details. */
@@ -9,10 +9,10 @@
#include "hack.h"
struct chainin_data {
struct chain_procs *nprocs;
void *ndata;
struct chain_procs *nprocs;
void *ndata;
int linknum;
int linknum;
};
/* Normally, a processor gets this information from the first parm of each
@@ -22,35 +22,35 @@ static struct chainin_data *cibase;
void *
chainin_procs_chain(cmd, n, me, nextprocs, nextdata)
int cmd;
int n;
void *me;
void *nextprocs;
void *nextdata;
int cmd;
int n;
void *me;
void *nextprocs;
void *nextdata;
{
switch(cmd){
case WINCHAIN_ALLOC: {
struct chainin_data *tdp = calloc(1, sizeof(struct chainin_data));
tdp->linknum = n;
cibase = tdp;
return tdp;
}
case WINCHAIN_INIT: {
struct chainin_data *tdp = me;
tdp->nprocs = nextprocs;
tdp->ndata = nextdata;
return tdp;
}
default:
raw_printf("chainin_procs_chain: bad cmd\n");
exit(EXIT_FAILURE);
}
switch (cmd) {
case WINCHAIN_ALLOC: {
struct chainin_data *tdp = calloc(1, sizeof(struct chainin_data));
tdp->linknum = n;
cibase = tdp;
return tdp;
}
case WINCHAIN_INIT: {
struct chainin_data *tdp = me;
tdp->nprocs = nextprocs;
tdp->ndata = nextdata;
return tdp;
}
default:
raw_printf("chainin_procs_chain: bad cmd\n");
exit(EXIT_FAILURE);
}
}
/* XXX if we don't need this, take it out of the table */
void
chainin_procs_init(dir)
int dir UNUSED;
int dir UNUSED;
{
}
@@ -60,358 +60,357 @@ chainin_procs_init(dir)
void
chainin_init_nhwindows(argcp, argv)
int *argcp;
char **argv;
int *argcp;
char **argv;
{
(*cibase->nprocs->win_init_nhwindows)(cibase->ndata, argcp, argv);
(*cibase->nprocs->win_init_nhwindows)(cibase->ndata, argcp, argv);
}
void
chainin_player_selection()
{
(*cibase->nprocs->win_player_selection)(cibase->ndata);
(*cibase->nprocs->win_player_selection)(cibase->ndata);
}
void
chainin_askname()
{
(*cibase->nprocs->win_askname)(cibase->ndata);
(*cibase->nprocs->win_askname)(cibase->ndata);
}
void
chainin_get_nh_event()
{
(*cibase->nprocs->win_get_nh_event)(cibase->ndata);
(*cibase->nprocs->win_get_nh_event)(cibase->ndata);
}
void
chainin_exit_nhwindows(str)
const char *str;
const char *str;
{
(*cibase->nprocs->win_exit_nhwindows)(cibase->ndata, str);
(*cibase->nprocs->win_exit_nhwindows)(cibase->ndata, str);
}
void
chainin_suspend_nhwindows(str)
const char *str;
const char *str;
{
(*cibase->nprocs->win_suspend_nhwindows)(cibase->ndata, str);
(*cibase->nprocs->win_suspend_nhwindows)(cibase->ndata, str);
}
void
chainin_resume_nhwindows()
{
(*cibase->nprocs->win_resume_nhwindows)(cibase->ndata);
(*cibase->nprocs->win_resume_nhwindows)(cibase->ndata);
}
winid
chainin_create_nhwindow(type)
int type;
int type;
{
winid rv;
winid rv;
rv = (*cibase->nprocs->win_create_nhwindow)(cibase->ndata, type);
rv = (*cibase->nprocs->win_create_nhwindow)(cibase->ndata, type);
return rv;
return rv;
}
void
chainin_clear_nhwindow(window)
winid window;
winid window;
{
(*cibase->nprocs->win_clear_nhwindow)(cibase->ndata, window);
(*cibase->nprocs->win_clear_nhwindow)(cibase->ndata, window);
}
void
chainin_display_nhwindow(window, blocking)
winid window;
BOOLEAN_P blocking;
winid window;
BOOLEAN_P blocking;
{
(*cibase->nprocs->win_display_nhwindow)(cibase->ndata, window, blocking);
(*cibase->nprocs->win_display_nhwindow)(cibase->ndata, window, blocking);
}
void
chainin_destroy_nhwindow(window)
winid window;
winid window;
{
(*cibase->nprocs->win_destroy_nhwindow)(cibase->ndata, window);
(*cibase->nprocs->win_destroy_nhwindow)(cibase->ndata, window);
}
void
chainin_curs(window, x, y)
winid window;
int x;
int y;
winid window;
int x;
int y;
{
(*cibase->nprocs->win_curs)(cibase->ndata, window, x, y);
(*cibase->nprocs->win_curs)(cibase->ndata, window, x, y);
}
void
chainin_putstr(window, attr, str)
winid window;
int attr;
const char *str;
winid window;
int attr;
const char *str;
{
(*cibase->nprocs->win_putstr)(cibase->ndata, window, attr, str);
(*cibase->nprocs->win_putstr)(cibase->ndata, window, attr, str);
}
void
chainin_putmixed(window, attr, str)
winid window;
int attr;
const char *str;
winid window;
int attr;
const char *str;
{
(*cibase->nprocs->win_putmixed)(cibase->ndata, window, attr, str);
(*cibase->nprocs->win_putmixed)(cibase->ndata, window, attr, str);
}
void
chainin_display_file(fname, complain)
const char *fname;
boolean complain;
const char *fname;
boolean complain;
{
(*cibase->nprocs->win_display_file)(cibase->ndata, fname, complain);
(*cibase->nprocs->win_display_file)(cibase->ndata, fname, complain);
}
void
chainin_start_menu(window)
winid window;
winid window;
{
(*cibase->nprocs->win_start_menu)(cibase->ndata, window);
(*cibase->nprocs->win_start_menu)(cibase->ndata, window);
}
void
chainin_add_menu(window, glyph, identifier, ch, gch, attr, str, preselected)
winid window; /* window to use, must be of type NHW_MENU */
int glyph; /* glyph to display with item (unused) */
const anything *identifier; /* what to return if selected */
char ch; /* keyboard accelerator (0 = pick our own) */
char gch; /* group accelerator (0 = no group) */
int attr; /* attribute for string (like tty_putstr()) */
const char *str; /* menu string */
boolean preselected; /* item is marked as selected */
winid window; /* window to use, must be of type NHW_MENU */
int glyph; /* glyph to display with item (unused) */
const anything *identifier; /* what to return if selected */
char ch; /* keyboard accelerator (0 = pick our own) */
char gch; /* group accelerator (0 = no group) */
int attr; /* attribute for string (like tty_putstr()) */
const char *str; /* menu string */
boolean preselected; /* item is marked as selected */
{
(*cibase->nprocs->win_add_menu)(cibase->ndata, window, glyph, identifier,
ch, gch, attr, str, preselected);
(*cibase->nprocs->win_add_menu)(cibase->ndata, window, glyph, identifier,
ch, gch, attr, str, preselected);
}
void
chainin_end_menu(window, prompt)
winid window;
const char *prompt;
winid window;
const char *prompt;
{
(*cibase->nprocs->win_end_menu)(cibase->ndata, window, prompt);
(*cibase->nprocs->win_end_menu)(cibase->ndata, window, prompt);
}
int
chainin_select_menu(window, how, menu_list)
winid window;
int how;
menu_item **menu_list;
winid window;
int how;
menu_item **menu_list;
{
int rv;
int rv;
rv = (*cibase->nprocs->win_select_menu)(cibase->ndata, window, how,
(void *)menu_list);
rv = (*cibase->nprocs->win_select_menu)(cibase->ndata, window, how,
(void *) menu_list);
return rv;
return rv;
}
char
chainin_message_menu(let, how, mesg)
char let;
int how;
const char *mesg;
char let;
int how;
const char *mesg;
{
char rv;
char rv;
rv = (*cibase->nprocs->win_message_menu)(cibase->ndata, let, how, mesg);
rv = (*cibase->nprocs->win_message_menu)(cibase->ndata, let, how, mesg);
return rv;
return rv;
}
void
chainin_update_inventory()
{
(*cibase->nprocs->win_update_inventory)(cibase->ndata);
(*cibase->nprocs->win_update_inventory)(cibase->ndata);
}
void
chainin_mark_synch()
{
(*cibase->nprocs->win_mark_synch)(cibase->ndata);
(*cibase->nprocs->win_mark_synch)(cibase->ndata);
}
void
chainin_wait_synch()
{
(*cibase->nprocs->win_wait_synch)(cibase->ndata);
(*cibase->nprocs->win_wait_synch)(cibase->ndata);
}
#ifdef CLIPPING
void
chainin_cliparound(x, y)
int x;
int y;
int x;
int y;
{
(*cibase->nprocs->win_cliparound)(cibase->ndata, x, y);
(*cibase->nprocs->win_cliparound)(cibase->ndata, x, y);
}
#endif
#ifdef POSITIONBAR
void
chainin_update_positionbar(posbar)
char *posbar;
char *posbar;
{
(*cibase->nprocs->win_update_positionbar)(cibase->ndata, posbar);
(*cibase->nprocs->win_update_positionbar)(cibase->ndata, posbar);
}
#endif
/* XXX can we decode the glyph in a meaningful way? */
void
chainin_print_glyph(window, x, y, glyph)
winid window;
xchar x, y;
int glyph;
winid window;
xchar x, y;
int glyph;
{
(*cibase->nprocs->win_print_glyph)(cibase->ndata, window, x, y, glyph);
(*cibase->nprocs->win_print_glyph)(cibase->ndata, window, x, y, glyph);
}
void
chainin_raw_print(str)
const char *str;
const char *str;
{
(*cibase->nprocs->win_raw_print)(cibase->ndata, str);
(*cibase->nprocs->win_raw_print)(cibase->ndata, str);
}
void
chainin_raw_print_bold(str)
const char *str;
const char *str;
{
(*cibase->nprocs->win_raw_print_bold)(cibase->ndata, str);
(*cibase->nprocs->win_raw_print_bold)(cibase->ndata, str);
}
int
chainin_nhgetch()
{
int rv;
int rv;
rv = (*cibase->nprocs->win_nhgetch)(cibase->ndata);
rv = (*cibase->nprocs->win_nhgetch)(cibase->ndata);
return rv;
return rv;
}
int
chainin_nh_poskey(x, y, mod)
int *x;
int *y;
int *mod;
int *x;
int *y;
int *mod;
{
int rv;
int rv;
rv = (*cibase->nprocs->win_nh_poskey)(cibase->ndata, x, y, mod);
rv = (*cibase->nprocs->win_nh_poskey)(cibase->ndata, x, y, mod);
return rv;
return rv;
}
void
chainin_nhbell()
{
(*cibase->nprocs->win_nhbell)(cibase->ndata);
(*cibase->nprocs->win_nhbell)(cibase->ndata);
}
int
chainin_doprev_message()
{
int rv;
int rv;
rv = (*cibase->nprocs->win_doprev_message)(cibase->ndata);
rv = (*cibase->nprocs->win_doprev_message)(cibase->ndata);
return rv;
return rv;
}
char
chainin_yn_function(query, resp, def)
const char *query, *resp;
char def;
const char *query, *resp;
char def;
{
int rv;
int rv;
rv = (*cibase->nprocs->win_yn_function)(cibase->ndata, query, resp, def);
rv = (*cibase->nprocs->win_yn_function)(cibase->ndata, query, resp, def);
return rv;
return rv;
}
void
chainin_getlin(query, bufp)
const char *query;
char *bufp;
const char *query;
char *bufp;
{
(*cibase->nprocs->win_getlin)(cibase->ndata, query, bufp);
(*cibase->nprocs->win_getlin)(cibase->ndata, query, bufp);
}
int
chainin_get_ext_cmd()
{
int rv;
int rv;
rv = (*cibase->nprocs->win_get_ext_cmd)(cibase->ndata);
rv = (*cibase->nprocs->win_get_ext_cmd)(cibase->ndata);
return rv;
return rv;
}
void
chainin_number_pad(state)
int state;
int state;
{
(*cibase->nprocs->win_number_pad)(cibase->ndata, state);
(*cibase->nprocs->win_number_pad)(cibase->ndata, state);
}
void
chainin_delay_output()
{
(*cibase->nprocs->win_delay_output)(cibase->ndata);
(*cibase->nprocs->win_delay_output)(cibase->ndata);
}
#ifdef CHANGE_COLOR
void
chainin_change_color(color, value, reverse)
int color;
long value;
int reverse;
int color;
long value;
int reverse;
{
(*cibase->nprocs->win_change_color)(cibase->ndata, color, value, reverse);
(*cibase->nprocs->win_change_color)(cibase->ndata, color, value, reverse);
}
#ifdef MAC
void
chainin_change_background(bw)
int bw;
int bw;
{
(*cibase->nprocs->win_change_background)(cibase->ndata, bw);
(*cibase->nprocs->win_change_background)(cibase->ndata, bw);
}
short
chainin_set_font_name(window, font)
winid window;
char *font;
winid window;
char *font;
{
short rv;
short rv;
rv = (*cibase->nprocs->win_set_font_name)(cibase->ndata, window, font);
rv = (*cibase->nprocs->win_set_font_name)(cibase->ndata, window, font);
return rv;
return rv;
}
#endif
char *trace_get_color_string()
char *
trace_get_color_string()
{
char *rv;
char *rv;
rv = (*cibase->nprocs->win_get_color_string)(cibase->ndata);
rv = (*cibase->nprocs->win_get_color_string)(cibase->ndata);
return rv;
return rv;
}
#endif
@@ -420,41 +419,40 @@ char *trace_get_color_string()
void
chainin_start_screen()
{
(*cibase->nprocs->win_start_screen)(cibase->ndata);
(*cibase->nprocs->win_start_screen)(cibase->ndata);
}
void
chainin_end_screen()
{
(*cibase->nprocs->win_end_screen)(cibase->ndata);
(*cibase->nprocs->win_end_screen)(cibase->ndata);
}
void
chainin_outrip(tmpwin, how, when)
winid tmpwin;
int how;
time_t when;
winid tmpwin;
int how;
time_t when;
{
(*cibase->nprocs->win_outrip)(cibase->ndata, tmpwin, how, when);
(*cibase->nprocs->win_outrip)(cibase->ndata, tmpwin, how, when);
}
void
chainin_preference_update(pref)
const char *pref;
const char *pref;
{
(*cibase->nprocs->win_preference_update)(cibase->ndata, pref);
(*cibase->nprocs->win_preference_update)(cibase->ndata, pref);
}
char *
chainin_getmsghistory(init)
boolean init;
{
char *rv;
char *rv;
rv = (*cibase->nprocs->win_getmsghistory)(cibase->ndata,init);
rv = (*cibase->nprocs->win_getmsghistory)(cibase->ndata, init);
return rv;
return rv;
}
void
@@ -462,20 +460,20 @@ chainin_putmsghistory(msg, is_restoring)
const char *msg;
boolean is_restoring;
{
(*cibase->nprocs->win_putmsghistory)(cibase->ndata, msg, is_restoring);
(*cibase->nprocs->win_putmsghistory)(cibase->ndata, msg, is_restoring);
}
#ifdef STATUS_VIA_WINDOWPORT
void
chainin_status_init()
{
(*cibase->nprocs->win_status_init)(cibase->ndata);
(*cibase->nprocs->win_status_init)(cibase->ndata);
}
void
chainin_status_finish()
{
(*cibase->nprocs->win_status_finish)(cibase->ndata);
(*cibase->nprocs->win_status_finish)(cibase->ndata);
}
void
@@ -485,8 +483,8 @@ const char *nm;
const char *fmt;
boolean enable;
{
(*cibase->nprocs->win_status_enablefield)(cibase->ndata, fieldidx, nm,
fmt, enable);
(*cibase->nprocs->win_status_enablefield)(cibase->ndata, fieldidx, nm,
fmt, enable);
}
void
@@ -494,107 +492,82 @@ chainin_status_update(idx, ptr, chg, percent)
int idx, chg, percent;
genericptr_t ptr;
{
(*cibase->nprocs->win_status_update)(cibase->ndata, idx, ptr, chg, percent);
(*cibase->nprocs->win_status_update)(cibase->ndata, idx, ptr, chg,
percent);
}
# ifdef STATUS_HILITES
#ifdef STATUS_HILITES
void
chainin_status_threshold(fldidx, thresholdtype, threshold, behavior, under, over)
int fldidx,thresholdtype;
chainin_status_threshold(fldidx, thresholdtype, threshold, behavior, under,
over)
int fldidx, thresholdtype;
int behavior, under, over;
anything threshold;
{
(*cibase->nprocs->win_status_threshold)(cibase->ndata,fldidx, thresholdtype,
threshold, behavior, under, over);
(*cibase->nprocs->win_status_threshold)(cibase->ndata, fldidx,
thresholdtype, threshold,
behavior, under, over);
}
# endif
#endif
#endif
boolean
chainin_can_suspend()
{
boolean rv;
boolean rv;
rv = (*cibase->nprocs->win_can_suspend)(cibase->ndata);
rv = (*cibase->nprocs->win_can_suspend)(cibase->ndata);
return rv;
return rv;
}
struct window_procs chainin_procs = {
"-chainin",
0, /* wincap */
0, /* wincap2 */
/*
XXX problem - the above need to come from the real window port, possibly
modified. May need to do something to call an additional init fn later
or if this is the only place like this the choose_windows fn can do the fixup
(but not if the value can be modified by the stack?) TBD
*/
"-chainin", 0, /* wincap */
0, /* wincap2 */
/*
XXX problem - the above need to come from the real window port, possibly
modified. May need to do something to call an additional init fn later
or if this is the only place like this the choose_windows fn can do the
fixup
(but not if the value can be modified by the stack?) TBD
*/
chainin_init_nhwindows,
chainin_player_selection,
chainin_askname,
chainin_get_nh_event,
chainin_exit_nhwindows,
chainin_suspend_nhwindows,
chainin_resume_nhwindows,
chainin_create_nhwindow,
chainin_clear_nhwindow,
chainin_display_nhwindow,
chainin_destroy_nhwindow,
chainin_curs,
chainin_putstr,
chainin_putmixed,
chainin_display_file,
chainin_start_menu,
chainin_add_menu,
chainin_end_menu,
chainin_select_menu,
chainin_message_menu,
chainin_update_inventory,
chainin_mark_synch,
chainin_wait_synch,
chainin_player_selection, chainin_askname, chainin_get_nh_event,
chainin_exit_nhwindows, chainin_suspend_nhwindows,
chainin_resume_nhwindows, chainin_create_nhwindow, chainin_clear_nhwindow,
chainin_display_nhwindow, chainin_destroy_nhwindow, chainin_curs,
chainin_putstr, chainin_putmixed, chainin_display_file,
chainin_start_menu, chainin_add_menu, chainin_end_menu,
chainin_select_menu, chainin_message_menu, chainin_update_inventory,
chainin_mark_synch, chainin_wait_synch,
#ifdef CLIPPING
chainin_cliparound,
#endif
#ifdef POSITIONBAR
chainin_update_positionbar,
#endif
chainin_print_glyph,
chainin_raw_print,
chainin_raw_print_bold,
chainin_nhgetch,
chainin_nh_poskey,
chainin_nhbell,
chainin_doprev_message,
chainin_yn_function,
chainin_getlin,
chainin_get_ext_cmd,
chainin_number_pad,
chainin_delay_output,
chainin_print_glyph, chainin_raw_print, chainin_raw_print_bold,
chainin_nhgetch, chainin_nh_poskey, chainin_nhbell,
chainin_doprev_message, chainin_yn_function, chainin_getlin,
chainin_get_ext_cmd, chainin_number_pad, chainin_delay_output,
#ifdef CHANGE_COLOR
chainin_change_color,
#ifdef MAC
chainin_change_background,
chainin_set_font_name,
chainin_change_background, chainin_set_font_name,
#endif
chainin_get_color_string,
#endif
chainin_start_screen,
chainin_end_screen,
chainin_start_screen, chainin_end_screen,
chainin_outrip,
chainin_preference_update,
chainin_getmsghistory,
chainin_outrip, chainin_preference_update, chainin_getmsghistory,
chainin_putmsghistory,
#ifdef STATUS_VIA_WINDOWPORT
chainin_status_init,
chainin_status_finish,
chainin_status_enablefield,
chainin_status_init, chainin_status_finish, chainin_status_enablefield,
chainin_status_update,
# ifdef STATUS_HILITES
#ifdef STATUS_HILITES
chainin_status_threshold,
# endif
#endif
#endif
chainin_can_suspend,
};
+308 -335
View File
File diff suppressed because it is too large Load Diff
+704 -713
View File
File diff suppressed because it is too large Load Diff
+264 -269
View File
@@ -8,7 +8,7 @@
* -> Programmcode *
\****************************/
/*
* $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$
* $NHDT-Date: 1431192775 2015/05/09 17:32:55 $ $NHDT-Branch: master $:$NHDT-Revision: 1.3 $
* $Date: 2002/01/05 21:06:00 $ $Revision: 1.1 $
*/
@@ -24,321 +24,316 @@
#define IMG_COMPRESSED
typedef struct
{
UWORD img_version;
UWORD img_headlen;
UWORD img_nplanes;
UWORD img_patlen;
UWORD img_pixw;
UWORD img_pixh;
UWORD img_w;
UWORD img_h;
} IMG_HEADER;
typedef struct {
UWORD img_version;
UWORD img_headlen;
UWORD img_nplanes;
UWORD img_patlen;
UWORD img_pixw;
UWORD img_pixh;
UWORD img_w;
UWORD img_h;
} IMG_HEADER;
typedef enum {NONE, SOLID0, SOLID1, PATRUN, BITSTR} IMG_MODE;
typedef enum { NONE, SOLID0, SOLID1, PATRUN, BITSTR } IMG_MODE;
typedef UBYTE IMG_SOLID;
typedef enum { RGB=0, CMY=1, Pantone=2 } XIMG_COLMODEL;
typedef enum { RGB = 0, CMY = 1, Pantone = 2 } XIMG_COLMODEL;
typedef struct
{
ULONG img_ximg;
XIMG_COLMODEL img_colmodel;
} XIMG_HEADER;
typedef struct {
ULONG img_ximg;
XIMG_COLMODEL img_colmodel;
} XIMG_HEADER;
typedef struct RGB XIMG_RGB;
int
bitmap_to_img(FILE_TYP typ, int ww, int wh, unsigned int pixw,
unsigned int pixh, unsigned int planes, unsigned int colors,
const char *filename,
void (*get_color)(unsigned int colind, struct RGB *rgb),
void (*get_pixel)(int x, int y, unsigned int *colind))
{
int file, error, cnt;
IMG_HEADER header;
XIMG_HEADER xheader;
XIMG_RGB xrgb;
IMG_MODE mode;
UBYTE *line_buf, *write_buf;
register UBYTE *startpnt, *bufpnt;
unsigned int colind, line_len, line, bit;
register unsigned int byte;
register UBYTE count;
int bitmap_to_img(FILE_TYP typ, int ww, int wh,
unsigned int pixw, unsigned int pixh,
unsigned int planes, unsigned int colors,
const char *filename,
void(*get_color)(unsigned int colind, struct RGB *rgb),
void(*get_pixel)(int x, int y, unsigned int *colind) )
{
int file, error, cnt;
IMG_HEADER header;
XIMG_HEADER xheader;
XIMG_RGB xrgb;
IMG_MODE mode;
UBYTE *line_buf, *write_buf;
register UBYTE *startpnt, *bufpnt;
unsigned int colind, line_len, line, bit;
register unsigned int byte;
register UBYTE count;
/* fill in (X) IMG-Header */
/* fill in (X) IMG-Header */
header.img_version = 1;
header.img_headlen = (UWORD) sizeof(header) / 2;
if (typ == XIMG)
header.img_headlen +=
(UWORD)(sizeof(xheader) + colors * sizeof(xrgb)) / 2;
header.img_version = 1;
header.img_headlen = (UWORD) sizeof(header) /2;
if (typ == XIMG)
header.img_headlen += (UWORD)(sizeof(xheader)+colors*sizeof(xrgb))/2;
header.img_nplanes = planes;
header.img_patlen = 2;
header.img_pixw = pixw;
header.img_pixh = pixh;
header.img_w = ww;
header.img_h = wh;
header.img_nplanes = planes;
header.img_patlen = 2;
header.img_pixw = pixw;
header.img_pixh = pixh;
header.img_w = ww;
header.img_h = wh;
xheader.img_ximg = XIMG_MAGIC;
xheader.img_colmodel = RGB;
xheader.img_ximg = XIMG_MAGIC;
xheader.img_colmodel= RGB;
/* calculate linelength, allocate buffer. */
/* calculate linelength, allocate buffer. */
line_len = (ww + 7) / 8;
line_len = (ww+7)/8;
line_buf = malloc((size_t) planes * line_len);
if (line_buf == NULL)
return (ENOMEM);
line_buf = malloc((size_t)planes*line_len);
if (line_buf == NULL)
return(ENOMEM);
/* Worst case: the bufferd line could grow to max. 3 times the length */
/* of the original!
*/
/* Worst case: the bufferd line could grow to max. 3 times the length */
/* of the original! */
write_buf = malloc((size_t) 3 * line_len);
if (write_buf == NULL) {
free(line_buf);
return (ENOMEM);
};
write_buf = malloc((size_t)3*line_len);
if (write_buf == NULL)
{
free(line_buf);
return(ENOMEM);
};
/* open file */
/* open file */
file = open(filename, O_WRONLY | O_CREAT | O_TRUNC);
if (file < 0) {
error = errno;
free(line_buf);
free(write_buf);
return (error);
};
file = open(filename, O_WRONLY | O_CREAT | O_TRUNC);
if (file<0)
{
error = errno;
free(line_buf);
free(write_buf);
return(error);
};
/* write Header */
/* write Header */
if (write(file, &header, sizeof(header)) != sizeof(header)
|| (typ == XIMG
&& write(file, &xheader, sizeof(xheader)) != sizeof(xheader))) {
error = errno;
close(file);
free(line_buf);
free(write_buf);
return (error);
};
if (write (file, &header, sizeof(header)) != sizeof(header) ||
(typ == XIMG && write (file, &xheader, sizeof(xheader) ) != sizeof(xheader)))
{
error = errno;
close(file);
free(line_buf);
free(write_buf);
return(error);
};
/* save the colortable if possible */
/* save the colortable if possible */
if (typ == XIMG)
for (cnt = 0; cnt < colors; cnt++) {
get_color(cnt, &xrgb);
if (write(file, &xrgb, sizeof(xrgb)) != sizeof(xrgb)) {
error = errno;
close(file);
free(line_buf);
free(write_buf);
return (error);
};
};
if ( typ == XIMG )
for (cnt=0; cnt<colors; cnt++)
{
get_color(cnt,&xrgb);
if (write(file,&xrgb,sizeof(xrgb)) != sizeof(xrgb))
{
error = errno;
close(file);
free(line_buf);
free(write_buf);
return(error);
};
};
/* And now line by line ... */
/* And now line by line ... */
for (line = 0; line < wh; line++) {
/* get pixel, split it up and */
/* store it as planes in buffer */
for (line=0; line<wh; line++)
{
/* get pixel, split it up and */
/* store it as planes in buffer */
for (byte = 0; byte < line_len; byte++) {
for (cnt = 0; cnt < planes; cnt++)
line_buf[cnt * line_len + byte] = 0x00;
for (byte=0; byte<line_len; byte++)
{
for (cnt=0; cnt<planes; cnt++)
line_buf[cnt*line_len+byte] = 0x00;
for (bit = 0; bit < 8; bit++) {
if (8 * byte + bit < ww)
get_pixel(8 * byte + bit, line, &colind);
for (bit=0; bit<8; bit++)
{
if (8*byte+bit < ww)
get_pixel(8*byte+bit, line, &colind);
for (cnt = 0; cnt < planes; cnt++) {
line_buf[cnt * line_len + byte] <<= 1;
line_buf[cnt * line_len + byte] |= colind & 0x01;
colind >>= 1;
};
};
};
for (cnt=0; cnt<planes; cnt++)
{
line_buf[cnt*line_len+byte] <<= 1;
line_buf[cnt*line_len+byte] |= colind & 0x01;
colind >>= 1;
};
};
};
/* compress bitstrings in buffer */
/* and write it to file */
/* compress bitstrings in buffer */
/* and write it to file */
for (cnt = 0; cnt < planes; cnt++) {
/* Bitstringpointer to start of plane */
for (cnt=0; cnt<planes; cnt++)
{
/* Bitstringpointer to start of plane */
startpnt = &line_buf[cnt * line_len];
bufpnt = write_buf;
startpnt = &line_buf[cnt*line_len];
bufpnt = write_buf;
while (startpnt < &line_buf[(cnt + 1) * line_len]) {
/*********************************************/
/* Which _new_ compression-mode "fits" the */
/* the current byte?
*/
/* Note: the compressing modes get choosen */
/* "positive". The non compressing BITSTR- */
/* mode is choosen only if nothing else */
/* "fits" ...
*/
/*********************************************/
while (startpnt < &line_buf[(cnt+1)*line_len])
{
/*********************************************/
/* Which _new_ compression-mode "fits" the */
/* the current byte? */
/* Note: the compressing modes get choosen */
/* "positive". The non compressing BITSTR- */
/* mode is choosen only if nothing else */
/* "fits" ... */
/*********************************************/
switch (*startpnt) {
case 0x00:
mode = SOLID0;
break;
case 0xFF:
mode = SOLID1;
break;
default:
if (startpnt < &line_buf[(cnt + 1) * line_len - 3]
&& *(startpnt) == *(startpnt + 2)
&& *(startpnt + 1) == *(startpnt + 3))
mode = PATRUN;
else
mode = BITSTR;
};
switch (*startpnt)
{
case 0x00:
mode = SOLID0;
break;
case 0xFF:
mode = SOLID1;
break;
default:
if ( startpnt < &line_buf[(cnt+1)*line_len-3] &&
*(startpnt) == *(startpnt+2) &&
*(startpnt+1) == *(startpnt+3) )
mode = PATRUN;
else
mode = BITSTR;
};
/************************************************/
/* The mode is choosen, now work with it.
*/
/* The compressing modi stay current as long as */
/* possible.
*/
/************************************************/
/************************************************/
/* The mode is choosen, now work with it. */
/* The compressing modi stay current as long as */
/* possible. */
/************************************************/
count = 0;
count = 0;
switch (mode) {
case SOLID0:
while ((startpnt < &line_buf[(cnt + 1) * line_len])
&& (*(startpnt) == 0x00) && (count < 0x7F)) {
startpnt++;
count++;
};
*(bufpnt++) = count;
break;
switch (mode)
{
case SOLID0:
while ( (startpnt < &line_buf[(cnt+1)*line_len]) &&
(*(startpnt)==0x00) &&
(count < 0x7F) )
{
startpnt++;
count++;
};
*(bufpnt++) = count;
break;
case SOLID1:
while ((startpnt < &line_buf[(cnt + 1) * line_len])
&& (*(startpnt) == 0xFF) && (count < 0x7F)) {
startpnt++;
count++;
};
*(bufpnt++) = 0x80 | count;
break;
case SOLID1:
while ( (startpnt < &line_buf[(cnt+1)*line_len]) &&
(*(startpnt)==0xFF) &&
(count < 0x7F) )
{
startpnt++;
count++;
};
*(bufpnt++) = 0x80 | count;
break;
case PATRUN:
*(bufpnt++) = 0x00;
startpnt += 2;
count = 1;
while (startpnt < &line_buf[(cnt + 1) * line_len - 1]
&& *(startpnt) == *(startpnt - 2)
&& *(startpnt + 1) == *(startpnt - 1)
&& (count < 0xFF)) {
count++;
startpnt += 2;
};
*(bufpnt++) = count;
*(bufpnt++) = *(startpnt - 2);
*(bufpnt++) = *(startpnt - 1);
break;
case PATRUN:
*(bufpnt++) = 0x00;
startpnt += 2;
count = 1;
while ( startpnt < &line_buf[(cnt+1)*line_len-1] &&
*(startpnt) == *(startpnt-2) &&
*(startpnt+1) == *(startpnt-1) &&
(count < 0xFF) )
{
count++;
startpnt += 2;
};
*(bufpnt++) = count;
*(bufpnt++) = *(startpnt-2);
*(bufpnt++) = *(startpnt-1);
break;
/************************************************/
/* The while Condition is ment as follows: */
/* */
/* while ( NOT(2-Byte-Solidrun possible) &&
*/
/* NOT(6-Byte-Patternrun possible) &&
*/
/* count < 0xFF
* && */
/* still Bytes remaining )
*/
/* */
/* As soon as a _compressing_ alternative shows */
/* up, BITSTR gets cancelled!
*/
/************************************************/
/************************************************/
/* The while Condition is ment as follows: */
/* */
/* while ( NOT(2-Byte-Solidrun possible) && */
/* NOT(6-Byte-Patternrun possible) && */
/* count < 0xFF && */
/* still Bytes remaining ) */
/* */
/* As soon as a _compressing_ alternative shows */
/* up, BITSTR gets cancelled! */
/************************************************/
case BITSTR:
*(bufpnt++) = 0x80;
while (!(((startpnt + count)
< &line_buf[(cnt + 1) * line_len - 1])
&& (((*(startpnt + count) == 0xFF)
&& (*(startpnt + count + 1) == 0xFF))
|| ((*(startpnt + count) == 0x00)
&& (*(startpnt + count + 1) == 0x00))))
&& !(((startpnt + count)
< &line_buf[(cnt + 1) * line_len - 5])
&& (*(startpnt + count)
== *(startpnt + count + 2))
&& (*(startpnt + count + 1)
== *(startpnt + count + 3))
&& (*(startpnt + count)
== *(startpnt + count + 4))
&& (*(startpnt + count + 1)
== *(startpnt + count + 5)))
&& (count < 0xFF)
&& ((startpnt + count)
< &line_buf[(cnt + 1) * line_len]))
count++;
*(bufpnt++) = count;
for (; count > 0; count--)
*(bufpnt++) = *(startpnt++);
break;
};
};
case BITSTR:
*(bufpnt++) = 0x80;
while ( !(((startpnt+count)<&line_buf[(cnt+1)*line_len-1])&&
(((*(startpnt+count)==0xFF) && (*(startpnt+count+1)==0xFF))||
((*(startpnt+count)==0x00) && (*(startpnt+count+1)==0x00)))) &&
!(((startpnt+count)<&line_buf[(cnt+1)*line_len-5])&&
(*(startpnt+count) == *(startpnt+count+2))&&
(*(startpnt+count+1) == *(startpnt+count+3))&&
(*(startpnt+count) == *(startpnt+count+4))&&
(*(startpnt+count+1) == *(startpnt+count+5))) &&
(count < 0xFF) &&
((startpnt+count) < &line_buf[(cnt+1)*line_len]) )
count++;
*(bufpnt++) = count;
for(; count>0; count--)
*(bufpnt++) = *(startpnt++);
break;
};
};
if (write(file, write_buf, bufpnt - write_buf)
!= (bufpnt - write_buf)) {
error = errno;
close(file);
free(line_buf);
free(write_buf);
return (error);
};
};
};
if (write(file,write_buf,bufpnt-write_buf) != (bufpnt-write_buf))
{
error = errno;
close(file);
free(line_buf);
free(write_buf);
return(error);
};
};
};
/*close file, free buffer. */
close(file);
free(line_buf);
free(write_buf);
return(0);
/*close file, free buffer. */
close(file);
free(line_buf);
free(write_buf);
return (0);
}
/*---filetype-dispatcher--------------------*/
const char *get_file_ext(FILE_TYP typ)
{
switch (typ)
{
case IMG:
case XIMG:
return("IMG");
default:
return("");
};
const char *
get_file_ext(FILE_TYP typ)
{
switch (typ) {
case IMG:
case XIMG:
return ("IMG");
default:
return ("");
};
}
int bitmap_to_file(FILE_TYP typ, int ww, int wh,
unsigned int pwx, unsigned int pwy,
unsigned int planes, unsigned int colors,
const char *filename,
void (*get_color)(unsigned int colind, struct RGB *rgb),
void (*get_pixel)(int x, int y, unsigned int *colind))
{
switch (typ)
{
case IMG:
case XIMG:
return(bitmap_to_img(typ,ww,wh,pwx,pwy,planes,colors,filename,get_color,get_pixel));
default:
return(-1);
};
int
bitmap_to_file(FILE_TYP typ, int ww, int wh, unsigned int pwx,
unsigned int pwy, unsigned int planes, unsigned int colors,
const char *filename,
void (*get_color)(unsigned int colind, struct RGB *rgb),
void (*get_pixel)(int x, int y, unsigned int *colind))
{
switch (typ) {
case IMG:
case XIMG:
return (bitmap_to_img(typ, ww, wh, pwx, pwy, planes, colors, filename,
get_color, get_pixel));
default:
return (-1);
};
}
+187 -164
View File
@@ -1,7 +1,8 @@
/* NetHack 3.6 gr_rect.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
/* NetHack 3.6 gr_rect.c $NHDT-Date: 1431192775 2015/05/09 17:32:55 $ $NHDT-Branch: master $:$NHDT-Revision: 1.6 $ */
/* NetHack 3.6 gr_rect.c $Date: 2009/05/06 10:56:40 $ $Revision: 1.3 $ */
/* SCCS Id: @(#)gr_rect.c 3.5 2001/12/10 */
/* Copyright (c) Christian Bressler, 2001 */
/* SCCS Id: @(#)gr_rect.c 3.5 2001/12/10
*/
/* Copyright (c) Christian Bressler, 2001 */
/* NetHack may be freely redistributed. See license for details. */
/* This is an almost exact copy of qt_clust.cpp */
/* gr_rect.c */
@@ -9,175 +10,197 @@
#include <stdio.h>
#include <limits.h>
#include "gr_rect.h"
dirty_rect *new_dirty_rect(int size){
dirty_rect *new=NULL;
if(size>0){
new=(dirty_rect *)calloc(1L,sizeof(dirty_rect));
if(new){
new->rects=(GRECT *)calloc((long)size,sizeof(GRECT));
if(new->rects==NULL){
free(new);
return(NULL);
}
new->max=size;
}
}
return(new);
dirty_rect *
new_dirty_rect(int size)
{
dirty_rect *new = NULL;
if (size > 0) {
new = (dirty_rect *) calloc(1L, sizeof(dirty_rect));
if (new) {
new->rects = (GRECT *) calloc((long) size, sizeof(GRECT));
if (new->rects == NULL) {
free(new);
return (NULL);
}
new->max = size;
}
}
return (new);
}
void delete_dirty_rect(dirty_rect *this){
if(this==NULL)
return;
if(this->rects)
free(this->rects);
/* In case the Pointer is reused wrongly */
this->rects=NULL;
this->max=0;
this->used=0;
free(this);
void
delete_dirty_rect(dirty_rect *this)
{
if (this == NULL)
return;
if (this->rects)
free(this->rects);
/* In case the Pointer is reused wrongly */
this->rects = NULL;
this->max = 0;
this->used = 0;
free(this);
}
static int gc_inside(GRECT *frame,GRECT *test);
static int gc_touch(GRECT *frame,GRECT *test);
static void gc_combine(GRECT *frame,GRECT *test);
static int gc_inside(GRECT *frame, GRECT *test);
static int gc_touch(GRECT *frame, GRECT *test);
static void gc_combine(GRECT *frame, GRECT *test);
static long gc_area(GRECT *area);
int add_dirty_rect(dirty_rect *dr,GRECT *area){
int cursor;
long lowestcost=9999999L;
int cheapest=-1;
int cheapestmerge1=-1;
int cheapestmerge2=-1;
int merge1;
int merge2;
for (cursor=0; cursor<dr->used; cursor++) {
if (gc_inside(&dr->rects[cursor],area)) {
/* Wholly contained already. */
return(TRUE);
}
}
for (cursor=0; cursor<dr->used; cursor++) {
if (gc_touch(&dr->rects[cursor],area)) {
GRECT larger=dr->rects[cursor];
long cost;
gc_combine(&larger,area);
cost=gc_area(&larger)-gc_area(&dr->rects[cursor]);
if (cost < lowestcost) {
int bad=FALSE,c;
for (c=0; c<dr->used && !bad; c++) {
bad=gc_touch(&dr->rects[c],&larger) && c!=cursor;
}
if (!bad) {
cheapest=cursor;
lowestcost=cost;
}
}
}
}
if (cheapest>=0) {
gc_combine(&dr->rects[cheapest],area);
return(TRUE);
}
if (dr->used < dr->max) {
dr->rects[dr->used++]=*area;
return(TRUE);
}
// Do cheapest of:
// add to closest cluster
// do cheapest cluster merge, add to new cluster
lowestcost=9999999L;
cheapest=-1;
for (cursor=0; cursor<dr->used; cursor++) {
GRECT larger=dr->rects[cursor];
long cost;
gc_combine(&larger,area);
cost=gc_area(&larger)-gc_area(&dr->rects[cursor]);
if (cost < lowestcost) {
int bad=FALSE, c;
for (c=0; c<dr->used && !bad; c++) {
bad=gc_touch(&dr->rects[c],&larger) && c!=cursor;
}
if (!bad) {
cheapest=cursor;
lowestcost=cost;
}
}
}
// XXX could make an heuristic guess as to whether we
// XXX need to bother looking for a cheap merge.
for (merge1=0; merge1<dr->used; merge1++) {
for (merge2=0; merge2<dr->used; merge2++) {
if (merge1!=merge2) {
GRECT larger=dr->rects[merge1];
long cost;
gc_combine(&larger,&dr->rects[merge2]);
cost=gc_area(&larger)-gc_area(&dr->rects[merge1])-gc_area(&dr->rects[merge2]);
if (cost < lowestcost) {
int bad=FALSE, c;
for (c=0; c<dr->used && !bad; c++) {
bad=gc_touch(&dr->rects[c],&larger) && c!=cursor;
}
if (!bad) {
cheapestmerge1=merge1;
cheapestmerge2=merge2;
lowestcost=cost;
}
}
}
}
}
if (cheapestmerge1>=0) {
gc_combine(&dr->rects[cheapestmerge1],&dr->rects[cheapestmerge2]);
dr->rects[cheapestmerge2]=dr->rects[dr->used-1];
dr->rects[dr->used-1]=*area;
} else {
gc_combine(&dr->rects[cheapest],area);
}
// NB: clusters do not intersect (or intersection will
// overwrite). This is a result of the above algorithm,
// given the assumption that (x,y) are ordered topleft
// to bottomright.
return(TRUE);
int
add_dirty_rect(dirty_rect *dr, GRECT *area)
{
int cursor;
long lowestcost = 9999999L;
int cheapest = -1;
int cheapestmerge1 = -1;
int cheapestmerge2 = -1;
int merge1;
int merge2;
for (cursor = 0; cursor < dr->used; cursor++) {
if (gc_inside(&dr->rects[cursor], area)) {
/* Wholly contained already. */
return (TRUE);
}
}
for (cursor = 0; cursor < dr->used; cursor++) {
if (gc_touch(&dr->rects[cursor], area)) {
GRECT larger = dr->rects[cursor];
long cost;
gc_combine(&larger, area);
cost = gc_area(&larger) - gc_area(&dr->rects[cursor]);
if (cost < lowestcost) {
int bad = FALSE, c;
for (c = 0; c < dr->used && !bad; c++) {
bad = gc_touch(&dr->rects[c], &larger) && c != cursor;
}
if (!bad) {
cheapest = cursor;
lowestcost = cost;
}
}
}
}
if (cheapest >= 0) {
gc_combine(&dr->rects[cheapest], area);
return (TRUE);
}
if (dr->used < dr->max) {
dr->rects[dr->used++] = *area;
return (TRUE);
}
// Do cheapest of:
// add to closest cluster
// do cheapest cluster merge, add to new cluster
lowestcost = 9999999L;
cheapest = -1;
for (cursor = 0; cursor < dr->used; cursor++) {
GRECT larger = dr->rects[cursor];
long cost;
gc_combine(&larger, area);
cost = gc_area(&larger) - gc_area(&dr->rects[cursor]);
if (cost < lowestcost) {
int bad = FALSE, c;
for (c = 0; c < dr->used && !bad; c++) {
bad = gc_touch(&dr->rects[c], &larger) && c != cursor;
}
if (!bad) {
cheapest = cursor;
lowestcost = cost;
}
}
}
// XXX could make an heuristic guess as to whether we
// XXX need to bother looking for a cheap merge.
for (merge1 = 0; merge1 < dr->used; merge1++) {
for (merge2 = 0; merge2 < dr->used; merge2++) {
if (merge1 != merge2) {
GRECT larger = dr->rects[merge1];
long cost;
gc_combine(&larger, &dr->rects[merge2]);
cost = gc_area(&larger) - gc_area(&dr->rects[merge1])
- gc_area(&dr->rects[merge2]);
if (cost < lowestcost) {
int bad = FALSE, c;
for (c = 0; c < dr->used && !bad; c++) {
bad = gc_touch(&dr->rects[c], &larger) && c != cursor;
}
if (!bad) {
cheapestmerge1 = merge1;
cheapestmerge2 = merge2;
lowestcost = cost;
}
}
}
}
}
if (cheapestmerge1 >= 0) {
gc_combine(&dr->rects[cheapestmerge1], &dr->rects[cheapestmerge2]);
dr->rects[cheapestmerge2] = dr->rects[dr->used - 1];
dr->rects[dr->used - 1] = *area;
} else {
gc_combine(&dr->rects[cheapest], area);
}
// NB: clusters do not intersect (or intersection will
// overwrite). This is a result of the above algorithm,
// given the assumption that (x,y) are ordered topleft
// to bottomright.
return (TRUE);
}
int get_dirty_rect(dirty_rect* dr,GRECT *area){
if(dr==NULL || area==NULL || dr->rects==NULL || dr->used<=0 || dr->max<=0)
return(FALSE);
*area=dr->rects[--dr->used];
return(TRUE);
int
get_dirty_rect(dirty_rect *dr, GRECT *area)
{
if (dr == NULL || area == NULL || dr->rects == NULL || dr->used <= 0
|| dr->max <= 0)
return (FALSE);
*area = dr->rects[--dr->used];
return (TRUE);
}
int clear_dirty_rect(dirty_rect *dr){
if(dr)
dr->used=0;
return(TRUE);
int
clear_dirty_rect(dirty_rect *dr)
{
if (dr)
dr->used = 0;
return (TRUE);
}
int resize_dirty_rect(dirty_rect *dr,int new_size){
return(FALSE);
int
resize_dirty_rect(dirty_rect *dr, int new_size)
{
return (FALSE);
}
static int gc_inside(GRECT *frame,GRECT *test){
if(frame && test && frame->g_x<=test->g_x && frame->g_y<=test->g_y &&
frame->g_x+frame->g_w>=test->g_x+test->g_w &&
frame->g_y+frame->g_h>=test->g_y+test->g_h
)
return(TRUE);
return(FALSE);
static int
gc_inside(GRECT *frame, GRECT *test)
{
if (frame && test && frame->g_x <= test->g_x && frame->g_y <= test->g_y
&& frame->g_x + frame->g_w >= test->g_x + test->g_w
&& frame->g_y + frame->g_h >= test->g_y + test->g_h)
return (TRUE);
return (FALSE);
}
static int gc_touch(GRECT *frame,GRECT *test){
GRECT tmp={test->g_x-1,test->g_y-1,test->g_w+2,test->g_h+2};
return(rc_intersect(frame,&tmp));
static int
gc_touch(GRECT *frame, GRECT *test)
{
GRECT tmp = { test->g_x - 1, test->g_y - 1, test->g_w + 2,
test->g_h + 2 };
return (rc_intersect(frame, &tmp));
}
static void gc_combine(GRECT *frame,GRECT *test){
if(!frame || !test)
return;
if(frame->g_x>test->g_x){
frame->g_w+=frame->g_x-test->g_x;
frame->g_x=test->g_x;
}
if(frame->g_y>test->g_y){
frame->g_h+=frame->g_y-test->g_y;
frame->g_y=test->g_y;
}
if(frame->g_x+frame->g_w<test->g_x+test->g_w)
frame->g_w=test->g_x+test->g_w-frame->g_x;
if(frame->g_y+frame->g_h<test->g_y+test->g_h)
frame->g_h=test->g_y+test->g_h-frame->g_y;
static void
gc_combine(GRECT *frame, GRECT *test)
{
if (!frame || !test)
return;
if (frame->g_x > test->g_x) {
frame->g_w += frame->g_x - test->g_x;
frame->g_x = test->g_x;
}
if (frame->g_y > test->g_y) {
frame->g_h += frame->g_y - test->g_y;
frame->g_y = test->g_y;
}
if (frame->g_x + frame->g_w < test->g_x + test->g_w)
frame->g_w = test->g_x + test->g_w - frame->g_x;
if (frame->g_y + frame->g_h < test->g_y + test->g_h)
frame->g_h = test->g_y + test->g_h - frame->g_y;
}
static long gc_area(GRECT *area){
return((long)area->g_h*(long)area->g_w);
static long
gc_area(GRECT *area)
{
return ((long) area->g_h * (long) area->g_w);
}
+267 -238
View File
@@ -1,5 +1,5 @@
/*
* $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$
* $NHDT-Date: 1431192775 2015/05/09 17:32:55 $ $NHDT-Branch: master $:$NHDT-Revision: 1.4 $
* $Date: 2002/03/20 03:45:03 $ $Revision: 1.2 $
*/
#define __TCC_COMPAT__
@@ -15,279 +15,308 @@
#ifndef FALSE
#define FALSE 0
#define TRUE !FALSE
#define TRUE !FALSE
#endif
/* VDI <-> Device palette order conversion matrixes: */
/* Four-plane vdi-device */
int vdi2dev4[]={0,15,1,2,4,6,3,5,7,8,9,10,12,14,11,13};
int vdi2dev4[] = { 0, 15, 1, 2, 4, 6, 3, 5, 7, 8, 9, 10, 12, 14, 11, 13 };
/* Two-plane vdi-device */
int vdi2dev2[]={0,3,1,2};
int vdi2dev2[] = { 0, 3, 1, 2 };
void get_colors(int handle, short *palette, int col){
int i, idx;
void
get_colors(int handle, short *palette, int col)
{
int i, idx;
/* get current color palette */
for(i=0; i < col; i ++){
/* device->vdi->device palette order */
switch(planes){
case 1:
idx=i;break;
case 2:
idx=vdi2dev2[i];break;
case 4:
idx=vdi2dev4[i];break;
default:
if(i<16)
idx=vdi2dev4[i];
else
idx= i==255 ? 1 : i;
}
vq_color(handle, i, 0, (int *)palette + idx * 3);
}
}
void img_set_colors(int handle, short *palette, int col){
int i, idx, end;
/* set color palette */
end=min(1<<col,1<<planes);
for(i=0; i<end; i++){
switch(planes){ /* MAR -- war col 10.01.2001 */
case 1:
idx=i;break;
case 2:
idx=vdi2dev2[i];break;
case 4:
idx=vdi2dev4[i];break;
default:
if(i<16)
idx=vdi2dev4[i];
else
idx= i==255 ? 1 : i;
/* get current color palette */
for (i = 0; i < col; i++) {
/* device->vdi->device palette order */
switch (planes) {
case 1:
idx = i;
break;
case 2:
idx = vdi2dev2[i];
break;
case 4:
idx = vdi2dev4[i];
break;
default:
if (i < 16)
idx = vdi2dev4[i];
else
idx = i == 255 ? 1 : i;
}
vq_color(handle, i, 0, (int *) palette + idx * 3);
}
vs_color(handle, i, (int *)palette + idx * 3);
}
}
int convert(MFDB *image, long size){
int plane, mplanes;
char *line_addr, *buf_addr, *new_addr, *new1_addr, *image_addr, *screen_addr;
MFDB dev_form, tmp;
long new_size;
void
img_set_colors(int handle, short *palette, int col)
{
int i, idx, end;
/* convert size from words to bytes */
size <<= 1;
/* memory for the device raster */
new_size=size*(long)planes;
if((new_addr=(char *) calloc(1,new_size)) == NULL)
return(FALSE);
/* initialize MFDBs */
tmp=*image;
tmp.fd_nplanes=planes;
tmp.fd_addr=new_addr;
tmp.fd_stand=1; /* standard format */
dev_form=tmp;
screen_addr=new_addr;
dev_form.fd_stand=0; /* device format */
image_addr=(char *)image->fd_addr;
/* initialize some variables and zero temp. line buffer */
mplanes=min(image->fd_nplanes, planes);
/* convert image */
line_addr=image_addr;
buf_addr=screen_addr;
if(mplanes>1){
/* cut/pad color planes into temp buf */
for(plane=0; plane<mplanes; plane ++){
memcpy(buf_addr, line_addr, size);
line_addr += size;
buf_addr += size;
}
}else{
/* fill temp line bitplanes with a b&w line */
for(plane=0; plane < planes; plane ++){
memcpy(buf_addr, line_addr, size);
buf_addr += size;
}
}
free(image->fd_addr);
/* convert image line in temp into current device raster format */
if((new1_addr=(char *) calloc(1,new_size)) == NULL)
return(FALSE);
dev_form.fd_addr=new1_addr;
vr_trnfm(x_handle, &tmp, &dev_form);
free(new_addr);
/* change image description */
image->fd_stand=0; /* device format */
image->fd_addr=new1_addr;
image->fd_nplanes=planes;
return(TRUE);
/* set color palette */
end = min(1 << col, 1 << planes);
for (i = 0; i < end; i++) {
switch (planes) { /* MAR -- war col 10.01.2001 */
case 1:
idx = i;
break;
case 2:
idx = vdi2dev2[i];
break;
case 4:
idx = vdi2dev4[i];
break;
default:
if (i < 16)
idx = vdi2dev4[i];
else
idx = i == 255 ? 1 : i;
}
vs_color(handle, i, (int *) palette + idx * 3);
}
}
int transform_img(MFDB *image){ /* return FALSE if transform_img fails */
int success;
long size;
int
convert(MFDB *image, long size)
{
int plane, mplanes;
char *line_addr, *buf_addr, *new_addr, *new1_addr, *image_addr,
*screen_addr;
MFDB dev_form, tmp;
long new_size;
if(!image->fd_addr)
return(FALSE);
/* convert size from words to bytes */
size <<= 1;
size=(long)((long)image->fd_wdwidth * (long)image->fd_h);
success=convert(image, size); /* Use vr_trfm(), which needs quite a lot memory. */
if(success) return(TRUE);
/* else show_error(ERR_ALLOC); */
return(FALSE);
/* memory for the device raster */
new_size = size * (long) planes;
if ((new_addr = (char *) calloc(1, new_size)) == NULL)
return (FALSE);
/* initialize MFDBs */
tmp = *image;
tmp.fd_nplanes = planes;
tmp.fd_addr = new_addr;
tmp.fd_stand = 1; /* standard format */
dev_form = tmp;
screen_addr = new_addr;
dev_form.fd_stand = 0; /* device format */
image_addr = (char *) image->fd_addr;
/* initialize some variables and zero temp. line buffer */
mplanes = min(image->fd_nplanes, planes);
/* convert image */
line_addr = image_addr;
buf_addr = screen_addr;
if (mplanes > 1) {
/* cut/pad color planes into temp buf */
for (plane = 0; plane < mplanes; plane++) {
memcpy(buf_addr, line_addr, size);
line_addr += size;
buf_addr += size;
}
} else {
/* fill temp line bitplanes with a b&w line */
for (plane = 0; plane < planes; plane++) {
memcpy(buf_addr, line_addr, size);
buf_addr += size;
}
}
free(image->fd_addr);
/* convert image line in temp into current device raster format */
if ((new1_addr = (char *) calloc(1, new_size)) == NULL)
return (FALSE);
dev_form.fd_addr = new1_addr;
vr_trnfm(x_handle, &tmp, &dev_form);
free(new_addr);
/* change image description */
image->fd_stand = 0; /* device format */
image->fd_addr = new1_addr;
image->fd_nplanes = planes;
return (TRUE);
}
int
transform_img(MFDB *image)
{ /* return FALSE if transform_img fails */
int success;
long size;
if (!image->fd_addr)
return (FALSE);
size = (long) ((long) image->fd_wdwidth * (long) image->fd_h);
success = convert(
image, size); /* Use vr_trfm(), which needs quite a lot memory. */
if (success)
return (TRUE);
/* else show_error(ERR_ALLOC); */
return (FALSE);
}
/* Loads & depacks IMG (0 if succeded, else error). */
/* Bitplanes are one after another in address IMG_HEADER.addr. */
int depack_img(char *name, IMG_header *pic){
int b, line, plane, width, word_aligned, opcode, patt_len, pal_size,
byte_repeat, patt_repeat, scan_repeat, error = FALSE;
char *pattern, *to, *endline, *puffer, sol_pat;
long size;
FILE *fp;
int
depack_img(char *name, IMG_header *pic)
{
int b, line, plane, width, word_aligned, opcode, patt_len, pal_size,
byte_repeat, patt_repeat, scan_repeat, error = FALSE;
char *pattern, *to, *endline, *puffer, sol_pat;
long size;
FILE *fp;
if((fp = fopen(name, "rb")) == NULL)
return(ERR_FILE);
if ((fp = fopen(name, "rb")) == NULL)
return (ERR_FILE);
setvbuf(fp,NULL,_IOLBF,BUFSIZ);
setvbuf(fp, NULL, _IOLBF, BUFSIZ);
/* read header info (bw & ximg) into image structure */
fread((char *)&(pic->version), 2, 8 + 3, fp);
/* read header info (bw & ximg) into image structure */
fread((char *) &(pic->version), 2, 8 + 3, fp);
/* only 2-256 color imgs */
if(pic->planes < 1 || pic->planes > 8){
error = ERR_COLOR;
goto end_depack;
}
/* only 2-256 color imgs */
if (pic->planes < 1 || pic->planes > 8) {
error = ERR_COLOR;
goto end_depack;
}
/* if XIMG, read info */
if(pic->magic == XIMG && pic->paltype == 0){
pal_size = (1 << pic->planes) * 3 * 2;
if((pic->palette = (short *)calloc(1,pal_size))){
fread((char *)pic->palette, 1, pal_size, fp);
}
}else{
pic->palette = NULL;
}
/* if XIMG, read info */
if (pic->magic == XIMG && pic->paltype == 0) {
pal_size = (1 << pic->planes) * 3 * 2;
if ((pic->palette = (short *) calloc(1, pal_size))) {
fread((char *) pic->palette, 1, pal_size, fp);
}
} else {
pic->palette = NULL;
}
/* width in bytes word aliged */
word_aligned = (pic->img_w + 15) >> 4;
word_aligned <<= 1;
/* width in bytes word aliged */
word_aligned = (pic->img_w + 15) >> 4;
word_aligned <<= 1;
/* width byte aligned */
width = (pic->img_w + 7) >> 3;
/* width byte aligned */
width = (pic->img_w + 7) >> 3;
/* allocate memory for the picture */
free(pic->addr);
size = (long)((long)word_aligned * (long)pic->img_h * (long)pic->planes); /*MAR*/
/* allocate memory for the picture */
free(pic->addr);
size = (long) ((long) word_aligned * (long) pic->img_h
* (long) pic->planes); /*MAR*/
/* check for header validity & malloc long... */
if (pic->length > 7 && pic->planes < 33 && pic->img_w > 0 && pic->img_h > 0){
if(!(pic->addr=(char *)calloc(1,size))){
error = ERR_ALLOC;
goto end_depack;
}
}else{
error = ERR_HEADER;
goto end_depack;
}
/* check for header validity & malloc long... */
if (pic->length > 7 && pic->planes < 33 && pic->img_w > 0
&& pic->img_h > 0) {
if (!(pic->addr = (char *) calloc(1, size))) {
error = ERR_ALLOC;
goto end_depack;
}
} else {
error = ERR_HEADER;
goto end_depack;
}
patt_len = pic->pat_len;
patt_len = pic->pat_len;
/* jump over the header and possible (XIMG) info */
fseek(fp, (long) pic->length * 2L, SEEK_SET);
/* jump over the header and possible (XIMG) info */
fseek(fp, (long) pic->length * 2L, SEEK_SET);
for(line=0,to=pic->addr; line<pic->img_h; line+=scan_repeat){ /* depack whole img */
for(plane=0,scan_repeat=1; plane<pic->planes; plane++){ /* depack one scan line */
puffer=to=pic->addr+(long)(line+plane*pic->img_h)*(long)word_aligned;
endline=puffer+width;
do{ /* depack one line in one bitplane */
switch((opcode= fgetc(fp))){
case 0: /* pattern or scan repeat */
if((patt_repeat=fgetc(fp))){ /* repeat a pattern */
fread(to,patt_len,1,fp);
pattern=to;
to+=patt_len;
while(--patt_repeat){ /* copy pattern */
memcpy(to,pattern,patt_len);
to+=patt_len;
}
}else{ /* repeat a line */
if(fgetc(fp)==0xFF)
scan_repeat=fgetc(fp);
else{
error = ERR_DEPACK;
goto end_depack;
}
}
break;
case 0x80: /* Literal */
byte_repeat=fgetc(fp);
fread(to,byte_repeat,1,fp);
to+=byte_repeat;
break;
default: /* Solid run */
byte_repeat = opcode & 0x7F;
sol_pat = opcode&0x80 ? 0xFF : 0x00;
while(byte_repeat--) *to++=sol_pat;
}
}while(to<endline);
for (line = 0, to = pic->addr; line < pic->img_h;
line += scan_repeat) { /* depack whole img */
for (plane = 0, scan_repeat = 1; plane < pic->planes;
plane++) { /* depack one scan line */
puffer = to =
pic->addr
+ (long) (line + plane * pic->img_h) * (long) word_aligned;
endline = puffer + width;
do { /* depack one line in one bitplane */
switch ((opcode = fgetc(fp))) {
case 0: /* pattern or scan repeat */
if ((patt_repeat = fgetc(fp))) { /* repeat a pattern */
fread(to, patt_len, 1, fp);
pattern = to;
to += patt_len;
while (--patt_repeat) { /* copy pattern */
memcpy(to, pattern, patt_len);
to += patt_len;
}
} else { /* repeat a line */
if (fgetc(fp) == 0xFF)
scan_repeat = fgetc(fp);
else {
error = ERR_DEPACK;
goto end_depack;
}
}
break;
case 0x80: /* Literal */
byte_repeat = fgetc(fp);
fread(to, byte_repeat, 1, fp);
to += byte_repeat;
break;
default: /* Solid run */
byte_repeat = opcode & 0x7F;
sol_pat = opcode & 0x80 ? 0xFF : 0x00;
while (byte_repeat--)
*to++ = sol_pat;
}
} while (to < endline);
if(to == endline){
/* ensure that lines aren't repeated past the end of the img */
if(line + scan_repeat > pic->img_h)
scan_repeat = pic->img_h - line;
/* copy line to image buffer */
if(scan_repeat>1){
/* calculate address of a current line in a current bitplane */
/* to=pic->addr+(long)(line+1+plane*pic->img_h)*(long)word_aligned;*/
for(b=scan_repeat-1; b; --b){
memcpy(to, puffer, width);
to+=word_aligned;
}
}
}else{
error = ERR_DEPACK;
goto end_depack;
}
}
}
if (to == endline) {
/* ensure that lines aren't repeated past the end of the img
*/
if (line + scan_repeat > pic->img_h)
scan_repeat = pic->img_h - line;
/* copy line to image buffer */
if (scan_repeat > 1) {
/* calculate address of a current line in a current
* bitplane */
/* to=pic->addr+(long)(line+1+plane*pic->img_h)*(long)word_aligned;*/
for (b = scan_repeat - 1; b; --b) {
memcpy(to, puffer, width);
to += word_aligned;
}
}
} else {
error = ERR_DEPACK;
goto end_depack;
}
}
}
end_depack:
fclose(fp);
return(error);
end_depack:
fclose(fp);
return (error);
}
int half_img(MFDB *s, MFDB *d){
int pxy[8], i, j;
MFDB tmp;
int
half_img(MFDB *s, MFDB *d)
{
int pxy[8], i, j;
MFDB tmp;
mfdb(&tmp,NULL,s->fd_w/2,s->fd_h,s->fd_stand,s->fd_nplanes);
tmp.fd_w=s->fd_w/2;
tmp.fd_addr=calloc(1,mfdb_size(&tmp));
if(!tmp.fd_addr)
return(FALSE);
mfdb(&tmp, NULL, s->fd_w / 2, s->fd_h, s->fd_stand, s->fd_nplanes);
tmp.fd_w = s->fd_w / 2;
tmp.fd_addr = calloc(1, mfdb_size(&tmp));
if (!tmp.fd_addr)
return (FALSE);
pxy[1]=pxy[5]=0;
pxy[3]=pxy[7]=s->fd_h-1;
for(i=0;i<s->fd_w/2;i++){
pxy[0]=pxy[2]=2*i;
pxy[4]=pxy[6]=i;
vro_cpyfm(x_handle,S_ONLY,pxy,s,&tmp);
}
pxy[0]=pxy[4]=0;
pxy[2]=pxy[6]=s->fd_w/2-1;
for(j=0;j<s->fd_h/2;j++){
pxy[1]=pxy[3]=2*j;
pxy[5]=pxy[7]=j;
vro_cpyfm(x_handle,S_ONLY,pxy,&tmp,d);
}
free(tmp.fd_addr);
return(TRUE);
pxy[1] = pxy[5] = 0;
pxy[3] = pxy[7] = s->fd_h - 1;
for (i = 0; i < s->fd_w / 2; i++) {
pxy[0] = pxy[2] = 2 * i;
pxy[4] = pxy[6] = i;
vro_cpyfm(x_handle, S_ONLY, pxy, s, &tmp);
}
pxy[0] = pxy[4] = 0;
pxy[2] = pxy[6] = s->fd_w / 2 - 1;
for (j = 0; j < s->fd_h / 2; j++) {
pxy[1] = pxy[3] = 2 * j;
pxy[5] = pxy[7] = j;
vro_cpyfm(x_handle, S_ONLY, pxy, &tmp, d);
}
free(tmp.fd_addr);
return (TRUE);
}
+90 -87
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 tile2img.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
/* NetHack 3.6 tile2img.c $NHDT-Date: 1431192775 2015/05/09 17:32:55 $ $NHDT-Branch: master $:$NHDT-Revision: 1.5 $ */
/* NetHack 3.6 tile2img.c $Date: 2009/05/06 10:56:40 $ $Revision: 1.2 $ */
/* SCCS Id: @(#)tile2bmp.c 3.2 95/09/06 */
/* Copyright (c) NetHack PC Development Team 1995 */
@@ -18,16 +18,15 @@
#include "bitmfile.h"
/* #define COLORS_IN_USE MAXCOLORMAPSIZE /* 256 colors */
#define COLORS_IN_USE 16 /* 16 colors */
#define COLORS_IN_USE 16 /* 16 colors */
extern char *FDECL(tilename, (int, int));
static void FDECL(build_ximgtile,(pixel (*)[TILE_X]));
static void FDECL(build_ximgtile, (pixel(*) [TILE_X]));
void get_color(unsigned int colind, struct RGB *rgb);
void get_pixel(int x, int y, unsigned int *colind);
#if COLORS_IN_USE==16
#define MAX_X 320 /* 2 per byte, 4 bits per pixel */
#if COLORS_IN_USE == 16
#define MAX_X 320 /* 2 per byte, 4 bits per pixel */
#else
#define MAX_X 640
#endif
@@ -37,9 +36,9 @@ FILE *tibfile2;
pixel tilepixels[TILE_Y][TILE_X];
char *tilefiles[] = { "..\\win\\share\\monsters.txt",
"..\\win\\share\\objects.txt",
"..\\win\\share\\other.txt"};
char *tilefiles[] = { "..\\win\\share\\monsters.txt",
"..\\win\\share\\objects.txt",
"..\\win\\share\\other.txt" };
unsigned int **Bild_daten;
int num_colors = 0;
@@ -48,7 +47,7 @@ int max_tiles_in_row = 40;
int tiles_in_row;
int filenum;
int initflag;
int yoffset,xoffset;
int yoffset, xoffset;
char bmpname[128];
FILE *fp;
@@ -57,102 +56,106 @@ main(argc, argv)
int argc;
char *argv[];
{
int i;
int i;
if (argc != 2) {
Fprintf(stderr, "usage: tile2img outfile.img\n");
exit(EXIT_FAILURE);
} else
strcpy(bmpname, argv[1]);
if (argc != 2) {
Fprintf(stderr, "usage: tile2img outfile.img\n");
exit(EXIT_FAILURE);
} else
strcpy(bmpname, argv[1]);
#ifdef OBSOLETE
bmpfile2 = fopen(NETHACK_PACKED_TILEFILE, WRBMODE);
if (bmpfile2 == (FILE *)0) {
Fprintf(stderr, "Unable to open output file %s\n",
NETHACK_PACKED_TILEFILE);
exit(EXIT_FAILURE);
}
bmpfile2 = fopen(NETHACK_PACKED_TILEFILE, WRBMODE);
if (bmpfile2 == (FILE *) 0) {
Fprintf(stderr, "Unable to open output file %s\n",
NETHACK_PACKED_TILEFILE);
exit(EXIT_FAILURE);
}
#endif
tilecount = 0;
xoffset = yoffset = 0;
initflag = 0;
filenum = 0;
fp = fopen(bmpname,"wb");
if (!fp) {
printf("Error creating tile file %s, aborting.\n",bmpname);
exit(1);
}
fclose(fp);
tilecount = 0;
xoffset = yoffset = 0;
initflag = 0;
filenum = 0;
fp = fopen(bmpname, "wb");
if (!fp) {
printf("Error creating tile file %s, aborting.\n", bmpname);
exit(1);
}
fclose(fp);
Bild_daten=(unsigned int **)malloc(MAX_Y*sizeof(unsigned int *));
for(i=0;i<MAX_Y;i++)
Bild_daten[i]=(unsigned int *)malloc(MAX_X*sizeof(unsigned int));
Bild_daten = (unsigned int **) malloc(MAX_Y * sizeof(unsigned int *));
for (i = 0; i < MAX_Y; i++)
Bild_daten[i] = (unsigned int *) malloc(MAX_X * sizeof(unsigned int));
while (filenum < 3) {
if (!fopen_text_file(tilefiles[filenum], RDTMODE)) {
Fprintf(stderr,
"usage: tile2img (from the util directory)\n");
exit(EXIT_FAILURE);
}
num_colors = colorsinmap;
if (num_colors > 62) {
Fprintf(stderr, "too many colors (%d)\n", num_colors);
exit(EXIT_FAILURE);
}
while (read_text_tile(tilepixels)) {
build_ximgtile(tilepixels);
tilecount++;
xoffset += TILE_X;
if (xoffset >= MAX_X) {
yoffset += TILE_Y;
xoffset = 0;
}
}
(void) fclose_text_file();
++filenum;
}
Fprintf(stderr, "Total of %d tiles in memory.\n",tilecount);
while (filenum < 3) {
if (!fopen_text_file(tilefiles[filenum], RDTMODE)) {
Fprintf(stderr, "usage: tile2img (from the util directory)\n");
exit(EXIT_FAILURE);
}
num_colors = colorsinmap;
if (num_colors > 62) {
Fprintf(stderr, "too many colors (%d)\n", num_colors);
exit(EXIT_FAILURE);
}
while (read_text_tile(tilepixels)) {
build_ximgtile(tilepixels);
tilecount++;
xoffset += TILE_X;
if (xoffset >= MAX_X) {
yoffset += TILE_Y;
xoffset = 0;
}
}
(void) fclose_text_file();
++filenum;
}
Fprintf(stderr, "Total of %d tiles in memory.\n", tilecount);
bitmap_to_file(XIMG, MAX_X, (tilecount/20+1)*16, 372, 372, 4, 16, bmpname, get_color, get_pixel ) ;
bitmap_to_file(XIMG, MAX_X, (tilecount / 20 + 1) * 16, 372, 372, 4, 16,
bmpname, get_color, get_pixel);
Fprintf(stderr, "Total of %d tiles written to %s.\n",tilecount, bmpname);
Fprintf(stderr, "Total of %d tiles written to %s.\n", tilecount, bmpname);
exit(EXIT_SUCCESS);
/*NOTREACHED*/
return 0;
exit(EXIT_SUCCESS);
/*NOTREACHED*/
return 0;
}
void get_color(unsigned int colind, struct RGB *rgb){
rgb->r=(1000L*(long)ColorMap[CM_RED][colind])/0xFF;
rgb->g=(1000L*(long)ColorMap[CM_GREEN][colind])/0xFF;
rgb->b=(1000L*(long)ColorMap[CM_BLUE][colind])/0xFF;
void
get_color(unsigned int colind, struct RGB *rgb)
{
rgb->r = (1000L * (long) ColorMap[CM_RED][colind]) / 0xFF;
rgb->g = (1000L * (long) ColorMap[CM_GREEN][colind]) / 0xFF;
rgb->b = (1000L * (long) ColorMap[CM_BLUE][colind]) / 0xFF;
}
void get_pixel(int x, int y, unsigned int *colind){
*colind=Bild_daten[y][x];
void
get_pixel(int x, int y, unsigned int *colind)
{
*colind = Bild_daten[y][x];
}
static void
build_ximgtile(pixels)
pixel (*pixels)[TILE_X];
{
int cur_x, cur_y, cur_color;
int x,y;
int cur_x, cur_y, cur_color;
int x, y;
for (cur_y = 0; cur_y < TILE_Y; cur_y++) {
for (cur_x = 0; cur_x < TILE_X; cur_x++) {
for (cur_color = 0; cur_color < num_colors; cur_color++) {
if (ColorMap[CM_RED][cur_color] == pixels[cur_y][cur_x].r &&
ColorMap[CM_GREEN][cur_color] == pixels[cur_y][cur_x].g &&
ColorMap[CM_BLUE][cur_color] == pixels[cur_y][cur_x].b)
break;
}
if (cur_color >= num_colors)
Fprintf(stderr, "color not in colormap!\n");
y = cur_y + yoffset;
x = cur_x + xoffset;
Bild_daten[y][x] =cur_color;
}
}
for (cur_y = 0; cur_y < TILE_Y; cur_y++) {
for (cur_x = 0; cur_x < TILE_X; cur_x++) {
for (cur_color = 0; cur_color < num_colors; cur_color++) {
if (ColorMap[CM_RED][cur_color] == pixels[cur_y][cur_x].r
&& ColorMap[CM_GREEN][cur_color] == pixels[cur_y][cur_x].g
&& ColorMap[CM_BLUE][cur_color] == pixels[cur_y][cur_x].b)
break;
}
if (cur_color >= num_colors)
Fprintf(stderr, "color not in colormap!\n");
y = cur_y + yoffset;
x = cur_x + xoffset;
Bild_daten[y][x] = cur_color;
}
}
}
+831 -832
View File
File diff suppressed because it is too large Load Diff
+2495 -2200
View File
File diff suppressed because it is too large Load Diff
+145 -125
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 xpm2img.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
/* NetHack 3.6 xpm2img.c $NHDT-Date: 1431192775 2015/05/09 17:32:55 $ $NHDT-Branch: master $:$NHDT-Revision: 1.6 $ */
/* NetHack 3.6 xpm2img.c $Date: 2009/05/06 10:56:48 $ $Revision: 1.3 $ */
/* SCCS Id: @(#)xpm2img.c 3.5 2002/03/17 */
/* Copyright (c) Christian Bressler 2002 */
@@ -16,13 +16,13 @@ char *xpmgetline();
unsigned int **Bild_daten;
/* translation table from xpm characters to RGB and colormap slots */
struct Ttable {
char flag;
struct RGB col;
int slot; /* output colortable index */
}ttable[256];
char flag;
struct RGB col;
int slot; /* output colortable index */
} ttable[256];
struct RGB *ColorMap;
int num_colors = 0;
int width=0, height=0;
int width = 0, height = 0;
int initflag;
FILE *fp;
int
@@ -30,66 +30,73 @@ main(argc, argv)
int argc;
char *argv[];
{
int i;
int row, col, planeno;
int farben, planes;
if (argc != 3) {
fprintf(stderr, "usage: tile2img infile.xpm outfile.img\n");
exit(EXIT_FAILURE);
}
initflag = 0;
fp = fopen(argv[2],"wb");
if (!fp) {
printf("Error creating IMG-file %s, aborting.\n",argv[2]);
exit(EXIT_FAILURE);
}
fclose(fp);
if(fopen_xpm_file(argv[1],"r")!=TRUE){
printf("Error reading xpm-file %s, aborting.\n",argv[1]);
exit(EXIT_FAILURE);
}
Bild_daten=(unsigned int **)malloc((long)height*sizeof(unsigned int *));
for(i=0;i<height;i++)
Bild_daten[i]=(unsigned int *)malloc((long)width*sizeof(unsigned int));
for(row = 0;row<height;row++){
char *xb = xpmgetline();
int plane_offset;
if(xb==0){
printf("Error to few lines in xpm-file %s, aborting.\n",argv[1]);
exit(EXIT_FAILURE);
}
for(col = 0;col<width;col++){
int color = xb[col];
if(!ttable[color].flag)
fprintf(stderr, "Bad image data\n");
Bild_daten[row][col]= ttable[color].slot;
}
}
if(num_colors>256){
fprintf(stderr,"ERROR: zuviele Farben\n");
exit(EXIT_FAILURE);
}else if(num_colors>16){
farben=256;
planes=8;
}else if(num_colors>2){
farben=16;
planes=4;
}else{
farben=2;
planes=1;
}
bitmap_to_file(XIMG, width, height, 372, 372, planes, farben, argv[2], get_color, get_pixel );
exit(EXIT_SUCCESS);
/*NOTREACHED*/
return 0;
int i;
int row, col, planeno;
int farben, planes;
if (argc != 3) {
fprintf(stderr, "usage: tile2img infile.xpm outfile.img\n");
exit(EXIT_FAILURE);
}
initflag = 0;
fp = fopen(argv[2], "wb");
if (!fp) {
printf("Error creating IMG-file %s, aborting.\n", argv[2]);
exit(EXIT_FAILURE);
}
fclose(fp);
if (fopen_xpm_file(argv[1], "r") != TRUE) {
printf("Error reading xpm-file %s, aborting.\n", argv[1]);
exit(EXIT_FAILURE);
}
Bild_daten =
(unsigned int **) malloc((long) height * sizeof(unsigned int *));
for (i = 0; i < height; i++)
Bild_daten[i] =
(unsigned int *) malloc((long) width * sizeof(unsigned int));
for (row = 0; row < height; row++) {
char *xb = xpmgetline();
int plane_offset;
if (xb == 0) {
printf("Error to few lines in xpm-file %s, aborting.\n", argv[1]);
exit(EXIT_FAILURE);
}
for (col = 0; col < width; col++) {
int color = xb[col];
if (!ttable[color].flag)
fprintf(stderr, "Bad image data\n");
Bild_daten[row][col] = ttable[color].slot;
}
}
if (num_colors > 256) {
fprintf(stderr, "ERROR: zuviele Farben\n");
exit(EXIT_FAILURE);
} else if (num_colors > 16) {
farben = 256;
planes = 8;
} else if (num_colors > 2) {
farben = 16;
planes = 4;
} else {
farben = 2;
planes = 1;
}
bitmap_to_file(XIMG, width, height, 372, 372, planes, farben, argv[2],
get_color, get_pixel);
exit(EXIT_SUCCESS);
/*NOTREACHED*/
return 0;
}
void get_color(unsigned int colind, struct RGB *rgb){
rgb->r=(1000L*(long)ColorMap[colind].r)/0xFF;
rgb->g=(1000L*(long)ColorMap[colind].g)/0xFF;
rgb->b=(1000L*(long)ColorMap[colind].b)/0xFF;
void
get_color(unsigned int colind, struct RGB *rgb)
{
rgb->r = (1000L * (long) ColorMap[colind].r) / 0xFF;
rgb->g = (1000L * (long) ColorMap[colind].g) / 0xFF;
rgb->b = (1000L * (long) ColorMap[colind].b) / 0xFF;
}
void get_pixel(int x, int y, unsigned int *colind){
*colind=Bild_daten[y][x];
void
get_pixel(int x, int y, unsigned int *colind)
{
*colind = Bild_daten[y][x];
}
FILE *xpmfh = 0;
char initbuf[200];
@@ -97,70 +104,83 @@ char *xpmbuf = initbuf;
/* version 1. Reads the raw xpm file, NOT the compiled version. This is
* not a particularly good idea but I don't have time to do the right thing
* at this point, even if I was absolutely sure what that was. */
fopen_xpm_file(const char *fn, const char *mode){
int temp;
char *xb;
if(strcmp(mode, "r"))return FALSE; /* no choice now */
if(xpmfh)return FALSE; /* one file at a time */
xpmfh = fopen(fn, mode);
if(!xpmfh)return FALSE; /* I'm hard to please */
/* read the header */
xb = xpmgetline();
if(xb == 0)return FALSE;
if(4 != sscanf(xb,"%d %d %d %d",
&width, &height,&num_colors, &temp))
return FALSE; /* bad header */
/* replace the original buffer with one big enough for
* the real data
*/
/* XXX */
xpmbuf = malloc(width * 2);
if(!xpmbuf){
fprintf(stderr,"ERROR: Can't allocate line buffer\n");
exit(1);
}
if(temp != 1)return FALSE; /* limitation of this code */
{
/* read the colormap and translation table */
int ccount = -1;
ColorMap = (struct RGB *)malloc((long)num_colors*sizeof(struct RGB));
while(ccount++ < (num_colors-1)){
char index;
int r, g, b;
xb = xpmgetline();
if(xb==0)return FALSE;
if(4 != sscanf(xb,"%c c #%2x%2x%2x",&index,&r,&g,&b)){
fprintf(stderr,"Bad color entry: %s\n",xb);
return FALSE;
}
ttable[index].flag = 1; /* this color is valid */
ttable[index].col.r = r;
ttable[index].col.g = g;
ttable[index].col.b = b;
ttable[index].slot = ccount;
ColorMap[ccount].r=r;
ColorMap[ccount].g=g;
ColorMap[ccount].b=b;
}
}
return TRUE;
fopen_xpm_file(const char *fn, const char *mode)
{
int temp;
char *xb;
if (strcmp(mode, "r"))
return FALSE; /* no choice now */
if (xpmfh)
return FALSE; /* one file at a time */
xpmfh = fopen(fn, mode);
if (!xpmfh)
return FALSE; /* I'm hard to please */
/* read the header */
xb = xpmgetline();
if (xb == 0)
return FALSE;
if (4 != sscanf(xb, "%d %d %d %d", &width, &height, &num_colors, &temp))
return FALSE; /* bad header */
/* replace the original buffer with one big enough for
* the real data
*/
/* XXX */
xpmbuf = malloc(width * 2);
if (!xpmbuf) {
fprintf(stderr, "ERROR: Can't allocate line buffer\n");
exit(1);
}
if (temp != 1)
return FALSE; /* limitation of this code */
{
/* read the colormap and translation table */
int ccount = -1;
ColorMap =
(struct RGB *) malloc((long) num_colors * sizeof(struct RGB));
while (ccount++ < (num_colors - 1)) {
char index;
int r, g, b;
xb = xpmgetline();
if (xb == 0)
return FALSE;
if (4 != sscanf(xb, "%c c #%2x%2x%2x", &index, &r, &g, &b)) {
fprintf(stderr, "Bad color entry: %s\n", xb);
return FALSE;
}
ttable[index].flag = 1; /* this color is valid */
ttable[index].col.r = r;
ttable[index].col.g = g;
ttable[index].col.b = b;
ttable[index].slot = ccount;
ColorMap[ccount].r = r;
ColorMap[ccount].g = g;
ColorMap[ccount].b = b;
}
}
return TRUE;
}
/* This deserves better. Don't read it too closely - you'll get ill. */
#define bufsz 2048
char buf[bufsz];
char *
xpmgetline(){
char *bp;
do {
if(fgets(buf, bufsz, xpmfh) == 0)return 0;
} while(buf[0] != '"');
/* strip off the trailing <",> if any */
for(bp = buf;*bp;bp++);
bp--;
while(isspace(*bp))bp--;
if(*bp==',')bp--;
if(*bp=='"')bp--;
bp++;
*bp = '\0';
return &buf[1];
xpmgetline()
{
char *bp;
do {
if (fgets(buf, bufsz, xpmfh) == 0)
return 0;
} while (buf[0] != '"');
/* strip off the trailing <",> if any */
for (bp = buf; *bp; bp++)
;
bp--;
while (isspace(*bp))
bp--;
if (*bp == ',')
bp--;
if (*bp == '"')
bp--;
bp++;
*bp = '\0';
return &buf[1];
}
+28 -32
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 gnaskstr.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
/* NetHack 3.6 gnaskstr.c $NHDT-Date: 1431192772 2015/05/09 17:32:52 $ $NHDT-Branch: master $:$NHDT-Revision: 1.7 $ */
/* NetHack 3.6 gnaskstr.c $Date: 2009/05/06 10:57:24 $ $Revision: 1.4 $ */
/* SCCS Id: @(#)gnaskstr.c 3.5 2000/07/16 */
/* Copyright (C) 1998 by Erik Andersen <andersee@debian.org> */
@@ -8,56 +8,52 @@
#include "gnmain.h"
#include <gnome.h>
static
void ghack_ask_string_callback(gchar * string, gpointer data)
static void
ghack_ask_string_callback(gchar *string, gpointer data)
{
char **user_text = (char **) data;
char **user_text = (char **) data;
g_assert(user_text != NULL);
g_assert(user_text != NULL);
*user_text = string; /* note - value must be g_free'd */
*user_text = string; /* note - value must be g_free'd */
}
int ghack_ask_string_dialog(const char *szMessageStr,
const char *szDefaultStr, const char *szTitleStr,
char *buffer)
int
ghack_ask_string_dialog(const char *szMessageStr, const char *szDefaultStr,
const char *szTitleStr, char *buffer)
{
int i;
GtkWidget* dialog;
gchar *user_text = NULL;
GtkWidget *dialog;
gchar *user_text = NULL;
dialog = gnome_request_dialog(FALSE, szMessageStr,
szDefaultStr, 0,
ghack_ask_string_callback,
&user_text, NULL);
dialog =
gnome_request_dialog(FALSE, szMessageStr, szDefaultStr, 0,
ghack_ask_string_callback, &user_text, NULL);
g_assert(dialog != NULL);
gtk_window_set_title(GTK_WINDOW(dialog), szTitleStr);
gnome_dialog_set_default( GNOME_DIALOG(dialog), 0);
gtk_window_set_modal( GTK_WINDOW(dialog), TRUE);
gnome_dialog_set_parent (GNOME_DIALOG (dialog),
GTK_WINDOW (ghack_get_main_window ()) );
gnome_dialog_set_default(GNOME_DIALOG(dialog), 0);
gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
gnome_dialog_set_parent(GNOME_DIALOG(dialog),
GTK_WINDOW(ghack_get_main_window()));
i = gnome_dialog_run_and_close(GNOME_DIALOG(dialog));
i = gnome_dialog_run_and_close (GNOME_DIALOG (dialog));
/* Quit */
if ( i != 0 || user_text == NULL ) {
if (user_text)
g_free(user_text);
return -1;
if (i != 0 || user_text == NULL) {
if (user_text)
g_free(user_text);
return -1;
}
if ( *user_text == 0 ) {
g_free(user_text);
return -1;
if (*user_text == 0) {
g_free(user_text);
return -1;
}
g_assert(strlen(user_text) > 0);
strcpy (buffer, user_text);
strcpy(buffer, user_text);
g_free(user_text);
return 0;
}
+634 -638
View File
File diff suppressed because it is too large Load Diff
+65 -74
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 gnglyph.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
/* NetHack 3.6 gnglyph.c $NHDT-Date: 1431192772 2015/05/09 17:32:52 $ $NHDT-Branch: master $:$NHDT-Revision: 1.9 $ */
/* NetHack 3.6 gnglyph.c $Date: 2009/05/06 10:57:29 $ $Revision: 1.6 $ */
/* SCCS Id: @(#)gnglyph.c 3.5 2000/07/16 */
/* Copyright (C) 1998 by Erik Andersen <andersee@debian.org> */
@@ -10,8 +10,8 @@
/* from tile.c */
extern int total_tiles_used;
static GHackGlyphs ghack_glyphs;
static GdkImlibImage** ghack_tiles = NULL;
static GHackGlyphs ghack_glyphs;
static GdkImlibImage **ghack_tiles = NULL;
/* NAME:
* ghack_init_glyphs(char* xpm_file)
@@ -53,47 +53,46 @@ int
ghack_init_glyphs(const char *xpmFile)
{
ghack_glyphs.im = gdk_imlib_load_image((char *) xpmFile);
if ( ! ghack_glyphs.im ) {
g_error("Couldn't load required xpmFile!");
return -1;
if (!ghack_glyphs.im) {
g_error("Couldn't load required xpmFile!");
return -1;
}
gdk_imlib_render(ghack_glyphs.im, ghack_glyphs.im->rgb_width,
ghack_glyphs.im->rgb_height);
ghack_glyphs.im->rgb_height);
if ((ghack_glyphs.im->rgb_width % TILES_PER_ROW) != 0 ||
ghack_glyphs.im->rgb_width <= TILES_PER_ROW) {
g_error("%s is not a multiple of %d (number of tiles/row) pixels wide",
xpmFile, TILES_PER_ROW);
return -1;
if ((ghack_glyphs.im->rgb_width % TILES_PER_ROW) != 0
|| ghack_glyphs.im->rgb_width <= TILES_PER_ROW) {
g_error(
"%s is not a multiple of %d (number of tiles/row) pixels wide",
xpmFile, TILES_PER_ROW);
return -1;
}
ghack_glyphs.count = total_tiles_used;
if ((ghack_glyphs.count % TILES_PER_ROW) != 0) {
ghack_glyphs.count +=
TILES_PER_ROW - (ghack_glyphs.count % TILES_PER_ROW);
ghack_glyphs.count +=
TILES_PER_ROW - (ghack_glyphs.count % TILES_PER_ROW);
}
ghack_glyphs.width = ghack_glyphs.im->rgb_width / TILES_PER_ROW;
ghack_glyphs.height =
ghack_glyphs.im->rgb_height / (ghack_glyphs.count / TILES_PER_ROW);
ghack_glyphs.im->rgb_height / (ghack_glyphs.count / TILES_PER_ROW);
/* Assume the tiles are organized in rows of TILES_PER_ROW */
ghack_tiles = g_new0( GdkImlibImage*, ghack_glyphs.count );
ghack_tiles = g_new0(GdkImlibImage *, ghack_glyphs.count);
return (ghack_tiles == NULL) ? -1 : 0;
}
void
ghack_free_glyphs( )
ghack_free_glyphs()
{
int i;
for ( i=0 ; i<ghack_glyphs.count ; i++)
gdk_imlib_destroy_image(ghack_tiles[i]);
g_free( ghack_tiles);
for (i = 0; i < ghack_glyphs.count; i++)
gdk_imlib_destroy_image(ghack_tiles[i]);
g_free(ghack_tiles);
gdk_imlib_destroy_image(ghack_glyphs.im);
ghack_glyphs.im=NULL;
ghack_glyphs.im = NULL;
}
/* NAME:
* ghack_glyph_count( )
*
@@ -108,12 +107,11 @@ ghack_free_glyphs( )
*/
int
ghack_glyph_count( )
ghack_glyph_count()
{
return ghack_glyphs.count;
return ghack_glyphs.count;
}
/* NAME:
* ghack_glyph_height()
*
@@ -130,10 +128,9 @@ ghack_glyph_count( )
int
ghack_glyph_height()
{
return ghack_glyphs.height;
return ghack_glyphs.height;
}
/* NAME:
* ghack_glyph_width()
*
@@ -150,10 +147,9 @@ ghack_glyph_height()
int
ghack_glyph_width()
{
return ghack_glyphs.width;
return ghack_glyphs.width;
}
/* NAME:
* ghack_image_from_glyph( int glyph, gboolean force)
*
@@ -168,38 +164,36 @@ ghack_glyph_width()
* Decodes the glyph into an image suitable for manipulation
*/
GdkImlibImage*
ghack_image_from_glyph( int glyph, gboolean force )
GdkImlibImage *
ghack_image_from_glyph(int glyph, gboolean force)
{
int tile = glyph2tile[glyph];
int tile = glyph2tile[glyph];
if ( tile >= ghack_glyphs.count || tile < 0 )
{
g_warning("Aiiee! I've was asked for a tile outside the allowed range!\n"
"Email this to other-gnomehack@lists.debian.org");
g_warning("Max tile: %d Tile asked for: %d",
ghack_glyphs.count, tile);
return NULL;
if (tile >= ghack_glyphs.count || tile < 0) {
g_warning(
"Aiiee! I've was asked for a tile outside the allowed range!\n"
"Email this to other-gnomehack@lists.debian.org");
g_warning("Max tile: %d Tile asked for: %d", ghack_glyphs.count,
tile);
return NULL;
}
if (ghack_glyphs.im == NULL)
{
g_warning("Aiiee! I've been asked to clone from a null image.\n"
"Email this to other-gnomehack@lists.debian.org");
g_warning( "making image from tile %d, force=%s\n", tile,
(force==TRUE)? "TRUE": "FALSE");
if (ghack_glyphs.im == NULL) {
g_warning("Aiiee! I've been asked to clone from a null image.\n"
"Email this to other-gnomehack@lists.debian.org");
g_warning("making image from tile %d, force=%s\n", tile,
(force == TRUE) ? "TRUE" : "FALSE");
}
if (force == TRUE)
{
g_warning("Aiiee! I've been asked to force rendering.\n"
"Email this to other-gnomehack@lists.debian.org");
g_warning( "making image from tile %d, force=%s\n", tile,
(force==TRUE)? "TRUE" : "FALSE");
if (force == TRUE) {
g_warning("Aiiee! I've been asked to force rendering.\n"
"Email this to other-gnomehack@lists.debian.org");
g_warning("making image from tile %d, force=%s\n", tile,
(force == TRUE) ? "TRUE" : "FALSE");
}
if (!ghack_tiles[tile] || force) {
int src_x, src_y;
if (!ghack_tiles[tile] || force) {
int src_x, src_y;
#if 0
fprintf( stderr, "crop_and_clone: glyph=%d, tile=%d, ptr=%p, x=%d, y=%d, w=%d, h=%d\n", glyph, tile,
(void*)&(ghack_tiles[tile]), 0,
@@ -207,26 +201,23 @@ ghack_image_from_glyph( int glyph, gboolean force )
ghack_glyphs.height,
ghack_glyphs.width);
#endif
if (ghack_glyphs.im->pixmap == NULL)
g_warning( "Aiiee! ghack_glyphs.im->pixmap==NULL!!!!\n");
src_x = (tile % TILES_PER_ROW) * ghack_glyphs.width;
src_y = (tile / TILES_PER_ROW) * ghack_glyphs.height;
ghack_tiles[tile] = gdk_imlib_crop_and_clone_image(ghack_glyphs.im,
src_x, src_y,
ghack_glyphs.width,
ghack_glyphs.height);
}
if (ghack_glyphs.im->pixmap == NULL)
g_warning("Aiiee! ghack_glyphs.im->pixmap==NULL!!!!\n");
src_x = (tile % TILES_PER_ROW) * ghack_glyphs.width;
src_y = (tile / TILES_PER_ROW) * ghack_glyphs.height;
ghack_tiles[tile] = gdk_imlib_crop_and_clone_image(
ghack_glyphs.im, src_x, src_y, ghack_glyphs.width,
ghack_glyphs.height);
}
if (ghack_tiles[tile] && (!ghack_tiles[tile]->pixmap || force))
{
if ( gdk_imlib_render(ghack_tiles[tile],
ghack_tiles[tile]->rgb_width,
ghack_tiles[tile]->rgb_height) == 0) {
g_error("GLYPH: couldn't create tile # %d", tile);
}
if ( !ghack_tiles[tile]->pixmap )
g_error("Strange, tile # %d didn't get rendered???", tile);
}
if (ghack_tiles[tile] && (!ghack_tiles[tile]->pixmap || force)) {
if (gdk_imlib_render(ghack_tiles[tile], ghack_tiles[tile]->rgb_width,
ghack_tiles[tile]->rgb_height) == 0) {
g_error("GLYPH: couldn't create tile # %d", tile);
}
if (!ghack_tiles[tile]->pixmap)
g_error("Strange, tile # %d didn't get rendered???", tile);
}
return ghack_tiles[tile];
return ghack_tiles[tile];
}
+450 -604
View File
File diff suppressed because it is too large Load Diff
+368 -458
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 gnmap.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
/* NetHack 3.6 gnmap.c $NHDT-Date: 1431192773 2015/05/09 17:32:53 $ $NHDT-Branch: master $:$NHDT-Revision: 1.9 $ */
/* NetHack 3.6 gnmap.c $Date: 2009/05/06 10:57:34 $ $Revision: 1.6 $ */
/* SCCS Id: @(#)gnmap.c 3.5 2000/07/16 */
/* Copyright (C) 1998 by Erik Andersen <andersee@debian.org> */
@@ -17,29 +17,30 @@
/* globals static to this file go here */
struct {
GnomeCanvas *canvas;
GnomeCanvasImage *map[(ROWNO + 1) * COLNO];
GnomeCanvasImage *overlay[(ROWNO + 1) * COLNO];
double zoom;
GtkWidget *frame;
GnomeCanvas *canvas;
GnomeCanvasImage *map[(ROWNO + 1) * COLNO];
GnomeCanvasImage *overlay[(ROWNO + 1) * COLNO];
double zoom;
GtkWidget *frame;
} ghack_map;
static GdkImlibImage *background;
static GdkImlibImage *petmark;
static GnomeCanvasGroup *myCanvasGroup;
/* static function declarations -- local to this file go here */
void ghack_map_cursor_to( GtkWidget *win, int x, int y, gpointer data);
void ghack_map_putstr( GtkWidget *win, int attr, const char* text, gpointer data);
void ghack_map_print_glyph( GtkObject *win, guint x, guint y, GdkImlibImage *im, gpointer data);
void ghack_map_clear( GtkWidget *win, gpointer data);
static void ghack_map_display( GtkWidget *win, boolean block, gpointer data);
static void ghack_map_cliparound( GtkWidget *win, int x, int y, gpointer data);
static void ghack_map_window_zoom( GtkAdjustment *adj, gpointer data);
void ghack_map_cursor_to(GtkWidget *win, int x, int y, gpointer data);
void ghack_map_putstr(GtkWidget *win, int attr, const char *text,
gpointer data);
void ghack_map_print_glyph(GtkObject *win, guint x, guint y,
GdkImlibImage *im, gpointer data);
void ghack_map_clear(GtkWidget *win, gpointer data);
static void ghack_map_display(GtkWidget *win, boolean block, gpointer data);
static void ghack_map_cliparound(GtkWidget *win, int x, int y, gpointer data);
static void ghack_map_window_zoom(GtkAdjustment *adj, gpointer data);
/* The following XPM is the artwork of Warwick Allison
* <warwick@troll.no>. It has been borrowed from
* <warwick@troll.no>. It has been borrowed from
* the most excellent NetHackQt, until such time as
* we can come up with something better.
*
@@ -49,23 +50,16 @@ static void ghack_map_window_zoom( GtkAdjustment *adj, gpointer data);
/* XPM */
static char *pet_mark_xpm[] = {
/* width height ncolors chars_per_pixel */
"8 7 2 1",
/* colors */
". c None",
" c #FF0000",
/* pixels */
"........",
".. . .",
". ",
". ",
".. .",
"... ..",
".... ..."
/* width height ncolors chars_per_pixel */
"8 7 2 1",
/* colors */
". c None", " c #FF0000",
/* pixels */
"........", ".. . .", ". ", ". ",
".. .", "... ..", ".... ..."
};
/* NAME:
/* NAME:
* ghack_init_map_window( )
*
* ARGUMENTS:
@@ -81,234 +75,191 @@ static char *pet_mark_xpm[] = {
* to behave properly.
*/
GtkWidget*
ghack_init_map_window ( )
GtkWidget *
ghack_init_map_window()
{
GtkWidget *vbox;
GtkWidget *hbox;
GtkWidget *table;
GtkWidget *frame;
GtkWidget *w;
GtkWidget *hSeparator;
GtkAdjustment *adj;
GnomeCanvasImage *bg;
double width, height, x, y;
int i;
GtkWidget *vbox;
GtkWidget *hbox;
GtkWidget *table;
GtkWidget *frame;
GtkWidget *w;
GtkWidget *hSeparator;
GtkAdjustment *adj;
GnomeCanvasImage *bg;
double width, height, x, y;
int i;
width = COLNO * ghack_glyph_width();
height = ROWNO * ghack_glyph_height();
width = COLNO * ghack_glyph_width();
height = ROWNO * ghack_glyph_height();
vbox = gtk_vbox_new (FALSE, 4);
gtk_container_set_border_width (GTK_CONTAINER (vbox), 4);
gtk_widget_show (vbox);
/* Add in a horiz seperator */
hSeparator = gtk_hseparator_new ();
gtk_box_pack_start (GTK_BOX (vbox), hSeparator, FALSE, FALSE, 2);
gtk_widget_show ( hSeparator);
hbox = gtk_hbox_new (FALSE, 4);
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
gtk_widget_show (hbox);
vbox = gtk_vbox_new(FALSE, 4);
gtk_container_set_border_width(GTK_CONTAINER(vbox), 4);
gtk_widget_show(vbox);
/* Create the Zoom spinbutton.
*/
ghack_map.zoom = 1.0;
w = gtk_label_new ("Zoom:");
gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
gtk_widget_show (w);
adj = GTK_ADJUSTMENT (gtk_adjustment_new (1.00, 0.5, 3.00, 0.05, 0.50, 0.50));
w = gtk_spin_button_new (adj, 0.5, 2);
gtk_widget_set_usize (w, 50, 0);
gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
gtk_widget_show (w);
/* Add in a horiz seperator */
hSeparator = gtk_hseparator_new();
gtk_box_pack_start(GTK_BOX(vbox), hSeparator, FALSE, FALSE, 2);
gtk_widget_show(hSeparator);
/* Canvas and scrollbars
*/
gtk_widget_push_visual (gdk_imlib_get_visual ());
gtk_widget_push_colormap (gdk_imlib_get_colormap ());
ghack_map.canvas = GNOME_CANVAS (gnome_canvas_new());
//gtk_widget_push_visual(gdk_rgb_get_visual());
//gtk_widget_push_colormap(gdk_rgb_get_cmap());
//ghack_map.canvas = GNOME_CANVAS (gnome_canvas_new_aa());
hbox = gtk_hbox_new(FALSE, 4);
gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
gtk_widget_show(hbox);
gtk_widget_pop_colormap();
gtk_widget_pop_visual();
gtk_widget_show (GTK_WIDGET(ghack_map.canvas));
/* Create the Zoom spinbutton.
*/
ghack_map.zoom = 1.0;
w = gtk_label_new("Zoom:");
gtk_box_pack_start(GTK_BOX(hbox), w, FALSE, FALSE, 0);
gtk_widget_show(w);
adj =
GTK_ADJUSTMENT(gtk_adjustment_new(1.00, 0.5, 3.00, 0.05, 0.50, 0.50));
w = gtk_spin_button_new(adj, 0.5, 2);
gtk_widget_set_usize(w, 50, 0);
gtk_box_pack_start(GTK_BOX(hbox), w, FALSE, FALSE, 0);
gtk_widget_show(w);
table = gtk_table_new (2, 2, FALSE);
gtk_table_set_row_spacings (GTK_TABLE (table), 4);
gtk_table_set_col_spacings (GTK_TABLE (table), 4);
gtk_box_pack_start (GTK_BOX (vbox), table, TRUE, TRUE, 0);
gtk_widget_show (table);
frame = gtk_frame_new (NULL);
ghack_map.frame = frame;
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
gtk_table_attach (GTK_TABLE (table), frame,
0, 1, 0, 1,
GTK_EXPAND | GTK_FILL | GTK_SHRINK,
GTK_EXPAND | GTK_FILL | GTK_SHRINK,
0, 0);
gtk_widget_show (frame);
/* Canvas and scrollbars
*/
gtk_widget_push_visual(gdk_imlib_get_visual());
gtk_widget_push_colormap(gdk_imlib_get_colormap());
ghack_map.canvas = GNOME_CANVAS(gnome_canvas_new());
// gtk_widget_push_visual(gdk_rgb_get_visual());
// gtk_widget_push_colormap(gdk_rgb_get_cmap());
// ghack_map.canvas = GNOME_CANVAS (gnome_canvas_new_aa());
gtk_container_add (GTK_CONTAINER (frame), GTK_WIDGET(ghack_map.canvas));
gnome_canvas_set_scroll_region (GNOME_CANVAS(ghack_map.canvas), 0, 0,
width+2*ghack_glyph_width(), height+2*ghack_glyph_height());
gtk_widget_pop_colormap();
gtk_widget_pop_visual();
gtk_widget_show(GTK_WIDGET(ghack_map.canvas));
gnome_canvas_set_pixels_per_unit (GNOME_CANVAS(ghack_map.canvas), 1.0);
table = gtk_table_new(2, 2, FALSE);
gtk_table_set_row_spacings(GTK_TABLE(table), 4);
gtk_table_set_col_spacings(GTK_TABLE(table), 4);
gtk_box_pack_start(GTK_BOX(vbox), table, TRUE, TRUE, 0);
gtk_widget_show(table);
w = gtk_hscrollbar_new (GTK_LAYOUT (ghack_map.canvas)->hadjustment);
gtk_table_attach (GTK_TABLE (table), w,
0, 1, 1, 2,
GTK_EXPAND | GTK_FILL | GTK_SHRINK,
GTK_FILL,
0, 0);
gtk_widget_show (w);
frame = gtk_frame_new(NULL);
ghack_map.frame = frame;
gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN);
gtk_table_attach(GTK_TABLE(table), frame, 0, 1, 0, 1,
GTK_EXPAND | GTK_FILL | GTK_SHRINK,
GTK_EXPAND | GTK_FILL | GTK_SHRINK, 0, 0);
gtk_widget_show(frame);
w = gtk_vscrollbar_new (GTK_LAYOUT (ghack_map.canvas)->vadjustment);
gtk_table_attach (GTK_TABLE (table), w,
1, 2, 0, 1, GTK_FILL,
GTK_EXPAND | GTK_FILL | GTK_SHRINK,
0, 0);
gtk_widget_show (w);
myCanvasGroup = GNOME_CANVAS_GROUP ( gnome_canvas_item_new (
gnome_canvas_root(GNOME_CANVAS(ghack_map.canvas)),
gnome_canvas_group_get_type (),
"x", 0.0,
"y", 0.0,
NULL) );
gtk_container_add(GTK_CONTAINER(frame), GTK_WIDGET(ghack_map.canvas));
gnome_canvas_set_scroll_region(GNOME_CANVAS(ghack_map.canvas), 0, 0,
width + 2 * ghack_glyph_width(),
height + 2 * ghack_glyph_height());
/* Tile the map background with a pretty image */
background = gdk_imlib_load_image((char *) "mapbg.xpm");
if (background == NULL) {
g_warning("Bummer! Failed to load the map background image (mapbg.xpm)!");
}
else {
gdk_imlib_render(background, background->rgb_width,
background->rgb_height);
gnome_canvas_set_pixels_per_unit(GNOME_CANVAS(ghack_map.canvas), 1.0);
/* Tile the map background */
for (y = 0; y < height+background->rgb_height; y+=background->rgb_height)
{
for (x = 0; x < width+background->rgb_width; x+=background->rgb_width)
{
bg = GNOME_CANVAS_IMAGE( gnome_canvas_item_new (
myCanvasGroup, gnome_canvas_image_get_type (),
"x", (double) x,
"y", (double) y,
"width", (double) background->rgb_width,
"height", (double) background->rgb_height,
"image", background,
"anchor", (GtkAnchorType) GTK_ANCHOR_CENTER,
NULL) );
gnome_canvas_item_lower_to_bottom (GNOME_CANVAS_ITEM( bg));
}
}
}
w = gtk_hscrollbar_new(GTK_LAYOUT(ghack_map.canvas)->hadjustment);
gtk_table_attach(GTK_TABLE(table), w, 0, 1, 1, 2,
GTK_EXPAND | GTK_FILL | GTK_SHRINK, GTK_FILL, 0, 0);
gtk_widget_show(w);
/* ghack_map.map is an array of canvas images. Each cell of
* the array will contain one tile. Here, we create the
* space for the cells and then create the cells for easy
* access later.
*/
for (i=0, y = 0; y < height; y+=ghack_glyph_height())
{
for (x = 0; x < width; x+=ghack_glyph_width())
{
ghack_map.map[i++] = GNOME_CANVAS_IMAGE(
gnome_canvas_item_new (
myCanvasGroup,
gnome_canvas_image_get_type (),
"x", (double) x,
"y", (double) y,
"width", (double) ghack_glyph_width(),
"height", (double) ghack_glyph_height(),
"anchor", GTK_ANCHOR_NORTH_WEST,
NULL) );
}
w = gtk_vscrollbar_new(GTK_LAYOUT(ghack_map.canvas)->vadjustment);
gtk_table_attach(GTK_TABLE(table), w, 1, 2, 0, 1, GTK_FILL,
GTK_EXPAND | GTK_FILL | GTK_SHRINK, 0, 0);
gtk_widget_show(w);
myCanvasGroup = GNOME_CANVAS_GROUP(gnome_canvas_item_new(
gnome_canvas_root(GNOME_CANVAS(ghack_map.canvas)),
gnome_canvas_group_get_type(), "x", 0.0, "y", 0.0, NULL));
/* Tile the map background with a pretty image */
background = gdk_imlib_load_image((char *) "mapbg.xpm");
if (background == NULL) {
g_warning(
"Bummer! Failed to load the map background image (mapbg.xpm)!");
} else {
gdk_imlib_render(background, background->rgb_width,
background->rgb_height);
/* Tile the map background */
for (y = 0; y < height + background->rgb_height;
y += background->rgb_height) {
for (x = 0; x < width + background->rgb_width;
x += background->rgb_width) {
bg = GNOME_CANVAS_IMAGE(gnome_canvas_item_new(
myCanvasGroup, gnome_canvas_image_get_type(), "x",
(double) x, "y", (double) y, "width",
(double) background->rgb_width, "height",
(double) background->rgb_height, "image", background,
"anchor", (GtkAnchorType) GTK_ANCHOR_CENTER, NULL));
gnome_canvas_item_lower_to_bottom(GNOME_CANVAS_ITEM(bg));
}
}
}
/* Set up the pet mark image */
petmark = gdk_imlib_create_image_from_xpm_data( pet_mark_xpm);
if (petmark == NULL) {
g_warning("Bummer! Failed to load the pet_mark image!");
}
else {
gdk_imlib_render(petmark, petmark->rgb_width, petmark->rgb_height);
/* ghack_map.map is an array of canvas images. Each cell of
* the array will contain one tile. Here, we create the
* space for the cells and then create the cells for easy
* access later.
*/
for (i = 0, y = 0; y < height; y += ghack_glyph_height()) {
for (x = 0; x < width; x += ghack_glyph_width()) {
ghack_map.map[i++] = GNOME_CANVAS_IMAGE(gnome_canvas_item_new(
myCanvasGroup, gnome_canvas_image_get_type(), "x", (double) x,
"y", (double) y, "width", (double) ghack_glyph_width(),
"height", (double) ghack_glyph_height(), "anchor",
GTK_ANCHOR_NORTH_WEST, NULL));
}
}
/* ghack_map.overlay is an array of canvas images used to
* overlay tile images...
*/
for (i=0, y = 0; y < height; y+=ghack_glyph_height())
{
for (x = 0; x < width; x+=ghack_glyph_width())
{
ghack_map.overlay[i] = GNOME_CANVAS_IMAGE(
gnome_canvas_item_new (
myCanvasGroup,
gnome_canvas_image_get_type (),
"x", (double) x,
"y", (double) y,
"width", (double) petmark->rgb_width,
"height", (double) petmark->rgb_height,
"image", petmark,
"anchor", GTK_ANCHOR_NORTH_WEST,
NULL) );
gnome_canvas_item_lower_to_bottom (
GNOME_CANVAS_ITEM( ghack_map.overlay[i++]));
}
}
}
/* Set up the pet mark image */
petmark = gdk_imlib_create_image_from_xpm_data(pet_mark_xpm);
if (petmark == NULL) {
g_warning("Bummer! Failed to load the pet_mark image!");
} else {
gdk_imlib_render(petmark, petmark->rgb_width, petmark->rgb_height);
/* Resize the canvas when the spinbutton changes
*/
gtk_signal_connect (GTK_OBJECT (adj),
"value_changed",
(GtkSignalFunc) ghack_map_window_zoom,
ghack_map.canvas);
/* ghack_map.overlay is an array of canvas images used to
* overlay tile images...
*/
for (i = 0, y = 0; y < height; y += ghack_glyph_height()) {
for (x = 0; x < width; x += ghack_glyph_width()) {
ghack_map.overlay[i] =
GNOME_CANVAS_IMAGE(gnome_canvas_item_new(
myCanvasGroup, gnome_canvas_image_get_type(), "x",
(double) x, "y", (double) y, "width",
(double) petmark->rgb_width, "height",
(double) petmark->rgb_height, "image", petmark,
"anchor", GTK_ANCHOR_NORTH_WEST, NULL));
gnome_canvas_item_lower_to_bottom(
GNOME_CANVAS_ITEM(ghack_map.overlay[i++]));
}
}
}
/* Game signals
*/
gtk_signal_connect (GTK_OBJECT (vbox),
"ghack_curs",
GTK_SIGNAL_FUNC (ghack_map_cursor_to),
NULL);
gtk_signal_connect (GTK_OBJECT (vbox),
"ghack_putstr",
GTK_SIGNAL_FUNC (ghack_map_putstr),
NULL);
gtk_signal_connect (GTK_OBJECT (vbox),
"ghack_print_glyph",
GTK_SIGNAL_FUNC (ghack_map_print_glyph),
NULL);
gtk_signal_connect (GTK_OBJECT (vbox),
"ghack_clear",
GTK_SIGNAL_FUNC (ghack_map_clear),
NULL);
gtk_signal_connect (GTK_OBJECT (vbox),
"ghack_display",
GTK_SIGNAL_FUNC (ghack_map_display),
NULL);
gtk_signal_connect (GTK_OBJECT (vbox),
"ghack_cliparound",
GTK_SIGNAL_FUNC (ghack_map_cliparound),
NULL);
gtk_signal_connect (GTK_OBJECT (ghack_map.canvas),
"button_press_event",
GTK_SIGNAL_FUNC (ghack_handle_button_press),
NULL);
gtk_signal_connect(GTK_OBJECT (ghack_map.canvas),
"gnome_delay_output",
GTK_SIGNAL_FUNC(ghack_delay),
NULL);
return GTK_WIDGET(vbox);
/* Resize the canvas when the spinbutton changes
*/
gtk_signal_connect(GTK_OBJECT(adj), "value_changed",
(GtkSignalFunc) ghack_map_window_zoom,
ghack_map.canvas);
/* Game signals
*/
gtk_signal_connect(GTK_OBJECT(vbox), "ghack_curs",
GTK_SIGNAL_FUNC(ghack_map_cursor_to), NULL);
gtk_signal_connect(GTK_OBJECT(vbox), "ghack_putstr",
GTK_SIGNAL_FUNC(ghack_map_putstr), NULL);
gtk_signal_connect(GTK_OBJECT(vbox), "ghack_print_glyph",
GTK_SIGNAL_FUNC(ghack_map_print_glyph), NULL);
gtk_signal_connect(GTK_OBJECT(vbox), "ghack_clear",
GTK_SIGNAL_FUNC(ghack_map_clear), NULL);
gtk_signal_connect(GTK_OBJECT(vbox), "ghack_display",
GTK_SIGNAL_FUNC(ghack_map_display), NULL);
gtk_signal_connect(GTK_OBJECT(vbox), "ghack_cliparound",
GTK_SIGNAL_FUNC(ghack_map_cliparound), NULL);
gtk_signal_connect(GTK_OBJECT(ghack_map.canvas), "button_press_event",
GTK_SIGNAL_FUNC(ghack_handle_button_press), NULL);
gtk_signal_connect(GTK_OBJECT(ghack_map.canvas), "gnome_delay_output",
GTK_SIGNAL_FUNC(ghack_delay), NULL);
return GTK_WIDGET(vbox);
}
/* NAME:
/* NAME:
* ghack_map_window_zoom
*
* ARGUMENTS:
@@ -324,67 +275,59 @@ ghack_init_map_window ( )
*/
static void
ghack_map_window_zoom( GtkAdjustment *adj, gpointer data)
ghack_map_window_zoom(GtkAdjustment *adj, gpointer data)
{
if ( adj->value > 3.0 )
adj->value = 3.0;
if ( adj->value < 0.5 )
adj->value = 0.5;
ghack_map.zoom = adj->value;
gnome_canvas_set_pixels_per_unit (data, adj->value);
if (adj->value > 3.0)
adj->value = 3.0;
if (adj->value < 0.5)
adj->value = 0.5;
ghack_map.zoom = adj->value;
gnome_canvas_set_pixels_per_unit(data, adj->value);
}
void
ghack_map_cursor_to( GtkWidget *win, int x, int y, gpointer data)
ghack_map_cursor_to(GtkWidget *win, int x, int y, gpointer data)
{
GnomeCanvasGroup *group;
static GnomeCanvasRE *cursor = NULL;
GnomeCanvasGroup *group;
static GnomeCanvasRE *cursor = NULL;
double x1, y1, x2, y2;
float hp;
guint r, g, b;
double x1, y1, x2, y2;
float hp;
guint r, g, b;
x1 = x * ghack_glyph_width() - 1;
y1 = y * ghack_glyph_height() - 1;
x2 = x1 + ghack_glyph_width() + 2;
y2 = y1 + ghack_glyph_height() + 2;
hp = u.mtimedone
? (u.mhmax ? (float)u.mh/u.mhmax : 1)
: (u.uhpmax ? (float)u.uhp/u.uhpmax : 1);
x1 = x * ghack_glyph_width() - 1;
y1 = y * ghack_glyph_height() - 1;
x2 = x1 + ghack_glyph_width() + 2;
y2 = y1 + ghack_glyph_height() + 2;
hp = u.mtimedone ? (u.mhmax ? (float) u.mh / u.mhmax : 1)
: (u.uhpmax ? (float) u.uhp / u.uhpmax : 1);
r = 255;
g = (hp >= 0.75) ? 255 : (hp >= 0.25 ? 255*2*(hp-0.25) : 0);
b = (hp >= 0.75) ? 255*4*(hp-0.75) : (hp >= 0.25 ? 0 : 255*4*(0.25-hp));
r = 255;
g = (hp >= 0.75) ? 255 : (hp >= 0.25 ? 255 * 2 * (hp - 0.25) : 0);
b = (hp >= 0.75) ? 255 * 4 * (hp - 0.75)
: (hp >= 0.25 ? 0 : 255 * 4 * (0.25 - hp));
group = gnome_canvas_root(GNOME_CANVAS(ghack_map.canvas));
group = gnome_canvas_root(GNOME_CANVAS(ghack_map.canvas));
if (!cursor) {
cursor = GNOME_CANVAS_RE (gnome_canvas_item_new (group,
gnome_canvas_rect_get_type (),
"width_units", 1.0, NULL));
}
gnome_canvas_item_set (GNOME_CANVAS_ITEM (cursor),
"outline_color_rgba", GNOME_CANVAS_COLOR(r, g, b),
"x1", x1,
"y1", y1,
"x2", x2,
"y2", y2,
NULL);
if (!cursor) {
cursor = GNOME_CANVAS_RE(gnome_canvas_item_new(
group, gnome_canvas_rect_get_type(), "width_units", 1.0, NULL));
}
gnome_canvas_item_set(GNOME_CANVAS_ITEM(cursor), "outline_color_rgba",
GNOME_CANVAS_COLOR(r, g, b), "x1", x1, "y1", y1,
"x2", x2, "y2", y2, NULL);
gnome_canvas_item_raise_to_top( GNOME_CANVAS_ITEM( cursor));
gnome_canvas_item_show( GNOME_CANVAS_ITEM(cursor));
gnome_canvas_item_raise_to_top(GNOME_CANVAS_ITEM(cursor));
gnome_canvas_item_show(GNOME_CANVAS_ITEM(cursor));
}
void
ghack_map_putstr( GtkWidget *win, int attr, const char* text, gpointer data)
ghack_map_putstr(GtkWidget *win, int attr, const char *text, gpointer data)
{
g_warning("Fixme!!! ghack_map_putstr is not implemented");
}
/* NAME:
/* NAME:
* ghack_map_print_glyph( )
*
* ARGUMENTS:
@@ -399,43 +342,37 @@ ghack_map_putstr( GtkWidget *win, int attr, const char* text, gpointer data)
*/
void
ghack_map_print_glyph( GtkObject *win,
guint x,
guint y,
GdkImlibImage *im,
gpointer data)
ghack_map_print_glyph(GtkObject *win, guint x, guint y, GdkImlibImage *im,
gpointer data)
{
GnomeCanvasGroup *group;
int i = y * COLNO + x;
int glyph = glyph_at(x,y);
GnomeCanvasImage *canvas_image = GNOME_CANVAS_IMAGE( ghack_map.map[i]);
GnomeCanvasGroup *group;
int i = y * COLNO + x;
int glyph = glyph_at(x, y);
GnomeCanvasImage *canvas_image = GNOME_CANVAS_IMAGE(ghack_map.map[i]);
group = gnome_canvas_root (GNOME_CANVAS (ghack_map.canvas));
gnome_canvas_item_set (GNOME_CANVAS_ITEM ( canvas_image),
"image", im, NULL);
gnome_canvas_item_show( GNOME_CANVAS_ITEM( canvas_image));
group = gnome_canvas_root(GNOME_CANVAS(ghack_map.canvas));
canvas_image = GNOME_CANVAS_IMAGE( ghack_map.overlay[i]);
gnome_canvas_item_set(GNOME_CANVAS_ITEM(canvas_image), "image", im, NULL);
gnome_canvas_item_show(GNOME_CANVAS_ITEM(canvas_image));
if (x==u.ux && y==u.uy)
ghack_map_cliparound(NULL, x, y, NULL);
canvas_image = GNOME_CANVAS_IMAGE(ghack_map.overlay[i]);
if (glyph_is_pet(glyph)
if (x == u.ux && y == u.uy)
ghack_map_cliparound(NULL, x, y, NULL);
if (glyph_is_pet(glyph)
#ifdef TEXTCOLOR
&& iflags.hilite_pet
&& iflags.hilite_pet
#endif
) {
gnome_canvas_item_raise_to_top( GNOME_CANVAS_ITEM( canvas_image));
gnome_canvas_item_show( GNOME_CANVAS_ITEM( canvas_image));
}
else {
gnome_canvas_item_hide( GNOME_CANVAS_ITEM( canvas_image));
}
) {
gnome_canvas_item_raise_to_top(GNOME_CANVAS_ITEM(canvas_image));
gnome_canvas_item_show(GNOME_CANVAS_ITEM(canvas_image));
} else {
gnome_canvas_item_hide(GNOME_CANVAS_ITEM(canvas_image));
}
}
/* NAME:
/* NAME:
* ghack_map_clear( )
*
* ARGUMENTS:
@@ -449,173 +386,146 @@ ghack_map_print_glyph( GtkObject *win,
*/
void
ghack_map_clear( GtkWidget *win, gpointer data)
ghack_map_clear(GtkWidget *win, gpointer data)
{
int i;
int i;
for (i = 0; i < ROWNO * COLNO; i++)
{
if (GNOME_IS_CANVAS_IMAGE(ghack_map.map[i]))
{
gnome_canvas_item_hide( GNOME_CANVAS_ITEM (ghack_map.map[i]));
}
if (GNOME_IS_CANVAS_IMAGE(ghack_map.overlay[i]))
{
gnome_canvas_item_hide( GNOME_CANVAS_ITEM (ghack_map.overlay[i]));
}
for (i = 0; i < ROWNO * COLNO; i++) {
if (GNOME_IS_CANVAS_IMAGE(ghack_map.map[i])) {
gnome_canvas_item_hide(GNOME_CANVAS_ITEM(ghack_map.map[i]));
}
if (GNOME_IS_CANVAS_IMAGE(ghack_map.overlay[i])) {
gnome_canvas_item_hide(GNOME_CANVAS_ITEM(ghack_map.overlay[i]));
}
}
gnome_canvas_update_now ( GNOME_CANVAS(ghack_map.canvas));
gnome_canvas_update_now(GNOME_CANVAS(ghack_map.canvas));
}
void
ghack_map_display( GtkWidget *win, boolean block, gpointer data)
ghack_map_display(GtkWidget *win, boolean block, gpointer data)
{
gtk_widget_show_all( GTK_WIDGET(win));
gtk_widget_show_all(GTK_WIDGET(win));
}
void
ghack_map_cliparound( GtkWidget *win,
int x,
int y,
gpointer data)
ghack_map_cliparound(GtkWidget *win, int x, int y, gpointer data)
{
int map_width, map_height;
int to_x, to_y;
int cur_x, cur_y;
int width, height, half_width, half_height;
int map_width, map_height;
int to_x, to_y;
int cur_x, cur_y;
int width, height, half_width, half_height;
x *= ghack_glyph_width() * ghack_map.zoom;
y *= ghack_glyph_height() * ghack_map.zoom;
map_width = COLNO * ghack_glyph_width() * ghack_map.zoom;
map_height = ROWNO * ghack_glyph_height() * ghack_map.zoom;
x *= ghack_glyph_width() * ghack_map.zoom;
y *= ghack_glyph_height() * ghack_map.zoom;
map_width = COLNO * ghack_glyph_width() * ghack_map.zoom;
map_height = ROWNO * ghack_glyph_height() * ghack_map.zoom;
gdk_window_get_size( GTK_LAYOUT (ghack_map.canvas)->bin_window,
&width, &height);
gnome_canvas_get_scroll_offsets( ghack_map.canvas, &cur_x, &cur_y);
gdk_window_get_size(GTK_LAYOUT(ghack_map.canvas)->bin_window, &width,
&height);
gnome_canvas_get_scroll_offsets(ghack_map.canvas, &cur_x, &cur_y);
half_width = width * 0.5;
half_height = height * 0.5;
half_width = width * 0.5;
half_height = height * 0.5;
if ( ((x - cur_x) < (width * 0.25) ) || ( (x - cur_x) > (width * 0.75) ) ) {
to_x = ((x-half_width) > 0)? x - half_width : 0;
to_x = ((x+half_width) > map_width)? map_width - 2 * half_width : to_x;
}
else {
to_x = cur_x;
}
if ( ((y - cur_y) < (height * 0.25) ) || ( (y - cur_y) > (height * 0.75) ) ) {
to_y = ((y-half_height) > 0)? y - half_height : 0;
to_y = ((y+half_height) > map_height)? map_height - 2 * half_height : to_y;
}
else {
to_y = cur_y;
}
if (to_x != cur_x || to_y != cur_y)
gnome_canvas_scroll_to( ghack_map.canvas, to_x, to_y);
//gnome_canvas_update_now ( ghack_map.canvas);
}
void
ghack_reinit_map_window ( )
{
GnomeCanvasImage *bg;
double width, height, x, y;
int i;
/* ghack_map_clear(NULL, NULL); */
width = COLNO * ghack_glyph_width();
height = ROWNO * ghack_glyph_height();
gnome_canvas_set_scroll_region (GNOME_CANVAS(ghack_map.canvas), 0, 0,
width+2*ghack_glyph_width(), height+2*ghack_glyph_height());
/* remove everything currently in the canvas map */
gtk_object_destroy( GTK_OBJECT (myCanvasGroup));
/* Put some groups back */
myCanvasGroup = GNOME_CANVAS_GROUP ( gnome_canvas_item_new (
gnome_canvas_root(GNOME_CANVAS(ghack_map.canvas)),
gnome_canvas_group_get_type (),
"x", 0.0,
"y", 0.0,
NULL) );
/* Tile the map background with a pretty image */
if (background != NULL) {
/* Tile the map background */
for (y = 0; y < height+background->rgb_height; y+=background->rgb_height)
{
for (x = 0; x < width+background->rgb_width; x+=background->rgb_width)
{
bg = GNOME_CANVAS_IMAGE( gnome_canvas_item_new (
myCanvasGroup, gnome_canvas_image_get_type (),
"x", (double) x,
"y", (double) y,
"width", (double) background->rgb_width,
"height", (double) background->rgb_height,
"image", background,
"anchor", (GtkAnchorType) GTK_ANCHOR_CENTER,
NULL) );
gnome_canvas_item_lower_to_bottom (GNOME_CANVAS_ITEM( bg));
}
if (((x - cur_x) < (width * 0.25)) || ((x - cur_x) > (width * 0.75))) {
to_x = ((x - half_width) > 0) ? x - half_width : 0;
to_x = ((x + half_width) > map_width) ? map_width - 2 * half_width
: to_x;
} else {
to_x = cur_x;
}
}
/* ghack_map.map is an array of canvas images. Each cell of
* the array will contain one tile. Here, we create the
* space for the cells and then create the cells for easy
* access later.
*/
for (i=0, y = 0; y < height; y+=ghack_glyph_height()) {
for (x = 0; x < width; x+=ghack_glyph_width()) {
ghack_map.map[i++] = GNOME_CANVAS_IMAGE(
gnome_canvas_item_new (
myCanvasGroup,
gnome_canvas_image_get_type (),
"x", (double) x,
"y", (double) y,
"width", (double) ghack_glyph_width(),
"height", (double) ghack_glyph_height(),
"anchor", GTK_ANCHOR_NORTH_WEST,
NULL) );
}
}
if (petmark != NULL) {
/* ghack_map.overlay is an array of canvas images used to
* overlay tile images...
*/
for (i=0, y = 0; y < height; y+=ghack_glyph_height()) {
for (x = 0; x < width; x+=ghack_glyph_width()) {
ghack_map.overlay[i] = GNOME_CANVAS_IMAGE(
gnome_canvas_item_new (
myCanvasGroup,
gnome_canvas_image_get_type (),
"x", (double) x,
"y", (double) y,
"width", (double) petmark->rgb_width,
"height", (double) petmark->rgb_height,
"image", petmark,
"anchor", GTK_ANCHOR_NORTH_WEST,
NULL) );
gnome_canvas_item_lower_to_bottom (
GNOME_CANVAS_ITEM( ghack_map.overlay[i++]));
}
}
}
if (((y - cur_y) < (height * 0.25)) || ((y - cur_y) > (height * 0.75))) {
to_y = ((y - half_height) > 0) ? y - half_height : 0;
to_y = ((y + half_height) > map_height) ? map_height - 2 * half_height
: to_y;
} else {
to_y = cur_y;
}
ghack_map_cliparound(NULL, u.ux, u.uy, NULL);
ghack_map_cursor_to(NULL, u.ux, u.uy, NULL);
gnome_canvas_update_now ( ghack_map.canvas);
doredraw();
if (to_x != cur_x || to_y != cur_y)
gnome_canvas_scroll_to(ghack_map.canvas, to_x, to_y);
// gnome_canvas_update_now ( ghack_map.canvas);
}
void
ghack_reinit_map_window()
{
GnomeCanvasImage *bg;
double width, height, x, y;
int i;
/* ghack_map_clear(NULL, NULL); */
width = COLNO * ghack_glyph_width();
height = ROWNO * ghack_glyph_height();
gnome_canvas_set_scroll_region(GNOME_CANVAS(ghack_map.canvas), 0, 0,
width + 2 * ghack_glyph_width(),
height + 2 * ghack_glyph_height());
/* remove everything currently in the canvas map */
gtk_object_destroy(GTK_OBJECT(myCanvasGroup));
/* Put some groups back */
myCanvasGroup = GNOME_CANVAS_GROUP(gnome_canvas_item_new(
gnome_canvas_root(GNOME_CANVAS(ghack_map.canvas)),
gnome_canvas_group_get_type(), "x", 0.0, "y", 0.0, NULL));
/* Tile the map background with a pretty image */
if (background != NULL) {
/* Tile the map background */
for (y = 0; y < height + background->rgb_height;
y += background->rgb_height) {
for (x = 0; x < width + background->rgb_width;
x += background->rgb_width) {
bg = GNOME_CANVAS_IMAGE(gnome_canvas_item_new(
myCanvasGroup, gnome_canvas_image_get_type(), "x",
(double) x, "y", (double) y, "width",
(double) background->rgb_width, "height",
(double) background->rgb_height, "image", background,
"anchor", (GtkAnchorType) GTK_ANCHOR_CENTER, NULL));
gnome_canvas_item_lower_to_bottom(GNOME_CANVAS_ITEM(bg));
}
}
}
/* ghack_map.map is an array of canvas images. Each cell of
* the array will contain one tile. Here, we create the
* space for the cells and then create the cells for easy
* access later.
*/
for (i = 0, y = 0; y < height; y += ghack_glyph_height()) {
for (x = 0; x < width; x += ghack_glyph_width()) {
ghack_map.map[i++] = GNOME_CANVAS_IMAGE(gnome_canvas_item_new(
myCanvasGroup, gnome_canvas_image_get_type(), "x", (double) x,
"y", (double) y, "width", (double) ghack_glyph_width(),
"height", (double) ghack_glyph_height(), "anchor",
GTK_ANCHOR_NORTH_WEST, NULL));
}
}
if (petmark != NULL) {
/* ghack_map.overlay is an array of canvas images used to
* overlay tile images...
*/
for (i = 0, y = 0; y < height; y += ghack_glyph_height()) {
for (x = 0; x < width; x += ghack_glyph_width()) {
ghack_map.overlay[i] =
GNOME_CANVAS_IMAGE(gnome_canvas_item_new(
myCanvasGroup, gnome_canvas_image_get_type(), "x",
(double) x, "y", (double) y, "width",
(double) petmark->rgb_width, "height",
(double) petmark->rgb_height, "image", petmark,
"anchor", GTK_ANCHOR_NORTH_WEST, NULL));
gnome_canvas_item_lower_to_bottom(
GNOME_CANVAS_ITEM(ghack_map.overlay[i++]));
}
}
}
ghack_map_cliparound(NULL, u.ux, u.uy, NULL);
ghack_map_cursor_to(NULL, u.ux, u.uy, NULL);
gnome_canvas_update_now(ghack_map.canvas);
doredraw();
}
+476 -490
View File
File diff suppressed because it is too large Load Diff
+37 -40
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 gnmesg.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
/* NetHack 3.6 gnmesg.c $NHDT-Date: 1431192772 2015/05/09 17:32:52 $ $NHDT-Branch: master $:$NHDT-Revision: 1.7 $ */
/* NetHack 3.6 gnmesg.c $Date: 2009/05/06 10:57:39 $ $Revision: 1.4 $ */
/* SCCS Id: @(#)gnmesg.c 3.5 2000/07/16 */
/* Copyright (C) 1998 by Erik Andersen <andersee@debian.org> */
@@ -7,69 +7,71 @@
#include "gnmesg.h"
#include "gnsignal.h"
/* Pick an arbitrary number of chars such as 80 col X 40 rows text = 3200 chars */
#define nCharsBeforeDeletingStuff 3200
/* Pick an arbitrary number of chars such as 80 col X 40 rows text = 3200
* chars */
#define nCharsBeforeDeletingStuff 3200
/* Message Window widgets */
GtkWidget *MW_table;
GtkWidget *MW_text;
GtkWidget *MW_scrollbar;
void ghack_message_window_clear(GtkWidget *widget, gpointer data)
void
ghack_message_window_clear(GtkWidget *widget, gpointer data)
{
/* Seems nethack calls this after every move -- we don't want
* to really clear the window at all though. Ignore the request */
gint len;
len = gtk_text_get_length(GTK_TEXT(MW_text));
if(len < nCharsBeforeDeletingStuff)
if (len < nCharsBeforeDeletingStuff)
return;
gtk_text_freeze(GTK_TEXT(MW_text));
gtk_text_set_point(GTK_TEXT(MW_text), 0);
gtk_text_forward_delete(GTK_TEXT(MW_text), len-((guint)(nCharsBeforeDeletingStuff*0.5)));
gtk_text_set_point(GTK_TEXT(MW_text), (guint)(nCharsBeforeDeletingStuff*0.5));
gtk_text_forward_delete(GTK_TEXT(MW_text),
len - ((guint)(nCharsBeforeDeletingStuff * 0.5)));
gtk_text_set_point(GTK_TEXT(MW_text),
(guint)(nCharsBeforeDeletingStuff * 0.5));
gtk_text_thaw(GTK_TEXT(MW_text));
}
void ghack_message_window_destroy( GtkWidget *win, gpointer data)
void
ghack_message_window_destroy(GtkWidget *win, gpointer data)
{
}
void ghack_message_window_display(GtkWidget *widget, boolean block,
gpointer data)
void
ghack_message_window_display(GtkWidget *widget, boolean block, gpointer data)
{
}
void ghack_message_window_put_string(GtkWidget *widget, int attr,
const char* text, gpointer data)
void
ghack_message_window_put_string(GtkWidget *widget, int attr, const char *text,
gpointer data)
{
if(text == NULL)
if (text == NULL)
return;
/* Don't bother with attributes yet */
gtk_text_insert(GTK_TEXT(MW_text), NULL, NULL, NULL, text, -1);
gtk_text_insert(GTK_TEXT(MW_text), NULL, NULL, NULL, "\n", -1);
}
void ghack_message_window_use_RIP(int how)
void
ghack_message_window_use_RIP(int how)
{
}
void ghack_message_window_scroll(int dx, int dy)
void
ghack_message_window_scroll(int dx, int dy)
{
}
GtkWidget* ghack_init_message_window(void)
GtkWidget *
ghack_init_message_window(void)
{
MW_table = gtk_table_new(2, 1, FALSE);
gtk_table_set_row_spacing(GTK_TABLE(MW_table), 0, 2);
@@ -77,28 +79,23 @@ GtkWidget* ghack_init_message_window(void)
gtk_text_set_editable(GTK_TEXT(MW_text), FALSE);
gtk_text_set_word_wrap(GTK_TEXT(MW_text), TRUE);
gtk_table_attach(GTK_TABLE(MW_table), MW_text, 0, 1, 0, 1,
(GTK_EXPAND | GTK_FILL),
(GTK_EXPAND | GTK_FILL),
0, 0);
(GTK_EXPAND | GTK_FILL), (GTK_EXPAND | GTK_FILL), 0, 0);
MW_scrollbar = gtk_vscrollbar_new(GTK_TEXT(MW_text)->vadj);
gtk_table_attach(GTK_TABLE(MW_table), MW_scrollbar, 1, 2, 0, 1,
GTK_FILL, (GTK_EXPAND | GTK_FILL), 0, 0);
gtk_table_attach(GTK_TABLE(MW_table), MW_scrollbar, 1, 2, 0, 1, GTK_FILL,
(GTK_EXPAND | GTK_FILL), 0, 0);
gtk_signal_connect(GTK_OBJECT(MW_table), "ghack_putstr",
GTK_SIGNAL_FUNC(ghack_message_window_put_string),
NULL);
GTK_SIGNAL_FUNC(ghack_message_window_put_string),
NULL);
gtk_signal_connect(GTK_OBJECT(MW_table), "ghack_clear",
GTK_SIGNAL_FUNC(ghack_message_window_clear),
NULL);
GTK_SIGNAL_FUNC(ghack_message_window_clear), NULL);
gtk_signal_connect(GTK_OBJECT(MW_table), "gnome_delay_output",
GTK_SIGNAL_FUNC(ghack_delay), NULL);
GTK_SIGNAL_FUNC(ghack_delay), NULL);
gtk_widget_show_all(MW_table);
return GTK_WIDGET(MW_table);
}
+66 -69
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 gnopts.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
/* NetHack 3.6 gnopts.c $NHDT-Date: 1431192772 2015/05/09 17:32:52 $ $NHDT-Branch: master $:$NHDT-Revision: 1.8 $ */
/* NetHack 3.6 gnopts.c $Date: 2009/05/06 10:57:40 $ $Revision: 1.5 $ */
/* SCCS Id: @(#)gnopts.c 3.5 2000/07/16 */
/* Copyright (C) 1998 by Erik Andersen <andersee@debian.org> */
@@ -13,19 +13,19 @@
#include "hack.h"
static gint tileset;
static GtkWidget* clist;
const char* tilesets[] = { "Traditional (16x16)", "Big (32x32)", 0 };
static GtkWidget *clist;
const char *tilesets[] = { "Traditional (16x16)", "Big (32x32)", 0 };
static void
opt_sel_key_hit(GtkWidget *widget, GdkEventKey *event, gpointer data)
{
int i;
for (i = 0; tilesets[i] != 0; ++i) {
if (tilesets[i][0] == toupper(event->keyval)) {
tileset = i;
gtk_clist_select_row( GTK_CLIST (clist), i, 0);
}
}
int i;
for (i = 0; tilesets[i] != 0; ++i) {
if (tilesets[i][0] == toupper(event->keyval)) {
tileset = i;
gtk_clist_select_row(GTK_CLIST(clist), i, 0);
}
}
}
static void
@@ -38,82 +38,79 @@ void
ghack_settings_dialog()
{
int i;
static GtkWidget* dialog;
static GtkWidget* swin;
static GtkWidget* frame1;
static GtkWidget *dialog;
static GtkWidget *swin;
static GtkWidget *frame1;
dialog = gnome_dialog_new (_("GnomeHack Settings"),
GNOME_STOCK_BUTTON_OK,
GNOME_STOCK_BUTTON_CANCEL,
NULL);
gnome_dialog_close_hides (GNOME_DIALOG (dialog), FALSE);
gtk_signal_connect (GTK_OBJECT (dialog), "key_press_event",
GTK_SIGNAL_FUNC (opt_sel_key_hit), tilesets );
dialog = gnome_dialog_new(_("GnomeHack Settings"), GNOME_STOCK_BUTTON_OK,
GNOME_STOCK_BUTTON_CANCEL, NULL);
gnome_dialog_close_hides(GNOME_DIALOG(dialog), FALSE);
gtk_signal_connect(GTK_OBJECT(dialog), "key_press_event",
GTK_SIGNAL_FUNC(opt_sel_key_hit), tilesets);
frame1 = gtk_frame_new (_("Choose one of the following tilesets:"));
gtk_object_set_data (GTK_OBJECT (dialog), "frame1", frame1);
gtk_widget_show (frame1);
gtk_container_border_width (GTK_CONTAINER (frame1), 3);
frame1 = gtk_frame_new(_("Choose one of the following tilesets:"));
gtk_object_set_data(GTK_OBJECT(dialog), "frame1", frame1);
gtk_widget_show(frame1);
gtk_container_border_width(GTK_CONTAINER(frame1), 3);
swin = gtk_scrolled_window_new (NULL, NULL);
clist = gtk_clist_new (2);
gtk_clist_column_titles_hide (GTK_CLIST (clist));
gtk_widget_set_usize (GTK_WIDGET (clist), 100, 180);
gtk_container_add (GTK_CONTAINER (swin), clist);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swin),
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
swin = gtk_scrolled_window_new(NULL, NULL);
clist = gtk_clist_new(2);
gtk_clist_column_titles_hide(GTK_CLIST(clist));
gtk_widget_set_usize(GTK_WIDGET(clist), 100, 180);
gtk_container_add(GTK_CONTAINER(swin), clist);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(swin),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
gtk_signal_connect (GTK_OBJECT (clist), "select_row",
GTK_SIGNAL_FUNC (opt_sel_row_selected), NULL );
gtk_signal_connect(GTK_OBJECT(clist), "select_row",
GTK_SIGNAL_FUNC(opt_sel_row_selected), NULL);
gtk_container_add (GTK_CONTAINER (frame1), swin);
gtk_box_pack_start_defaults (GTK_BOX (GNOME_DIALOG (dialog)->vbox), frame1);
gtk_container_add(GTK_CONTAINER(frame1), swin);
gtk_box_pack_start_defaults(GTK_BOX(GNOME_DIALOG(dialog)->vbox), frame1);
/* Add the tilesets into the list here... */
for (i=0; tilesets[i]; i++) {
gchar accelBuf[BUFSZ];
const char *text[3]={accelBuf, tilesets[i],NULL};
sprintf( accelBuf, "%c ", tolower(tilesets[i][0]));
gtk_clist_insert (GTK_CLIST (clist), i, (char**)text);
for (i = 0; tilesets[i]; i++) {
gchar accelBuf[BUFSZ];
const char *text[3] = { accelBuf, tilesets[i], NULL };
sprintf(accelBuf, "%c ", tolower(tilesets[i][0]));
gtk_clist_insert(GTK_CLIST(clist), i, (char **) text);
}
gtk_clist_columns_autosize (GTK_CLIST (clist));
gtk_widget_show_all (swin);
gtk_clist_columns_autosize(GTK_CLIST(clist));
gtk_widget_show_all(swin);
/* Center the dialog over over parent */
gnome_dialog_set_default( GNOME_DIALOG(dialog), 0);
gtk_window_set_modal( GTK_WINDOW(dialog), TRUE);
gnome_dialog_set_parent (GNOME_DIALOG (dialog),
GTK_WINDOW (ghack_get_main_window ()) );
gnome_dialog_set_default(GNOME_DIALOG(dialog), 0);
gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
gnome_dialog_set_parent(GNOME_DIALOG(dialog),
GTK_WINDOW(ghack_get_main_window()));
/* Run the dialog -- returning whichever button was pressed */
i = gnome_dialog_run (GNOME_DIALOG (dialog));
gnome_dialog_close (GNOME_DIALOG (dialog));
i = gnome_dialog_run(GNOME_DIALOG(dialog));
gnome_dialog_close(GNOME_DIALOG(dialog));
/* They hit Quit or error */
if (i != 0 ) {
return;
if (i != 0) {
return;
}
switch (tileset) {
case 0:
/* They selected traditional */
ghack_free_glyphs();
if (ghack_init_glyphs(HACKDIR "/x11tiles"))
g_error ("ERROR: Could not initialize glyphs.\n");
ghack_reinit_map_window();
break;
case 1:
ghack_free_glyphs();
if (ghack_init_glyphs(HACKDIR "/t32-1024.xpm"))
g_error ("ERROR: Could not initialize glyphs.\n");
ghack_reinit_map_window();
case 0:
/* They selected traditional */
ghack_free_glyphs();
if (ghack_init_glyphs(HACKDIR "/x11tiles"))
g_error("ERROR: Could not initialize glyphs.\n");
ghack_reinit_map_window();
break;
case 1:
ghack_free_glyphs();
if (ghack_init_glyphs(HACKDIR "/t32-1024.xpm"))
g_error("ERROR: Could not initialize glyphs.\n");
ghack_reinit_map_window();
/* They selected big */
break;
default:
/* This shouldn't happen */
g_warning("This shouldn't happen\n");
/* They selected big */
break;
default:
/* This shouldn't happen */
g_warning("This shouldn't happen\n");
}
}
+53 -56
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 gnplayer.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
/* NetHack 3.6 gnplayer.c $NHDT-Date: 1431192773 2015/05/09 17:32:53 $ $NHDT-Branch: master $:$NHDT-Revision: 1.9 $ */
/* NetHack 3.6 gnplayer.c $Date: 2009/05/06 10:57:42 $ $Revision: 1.6 $ */
/* SCCS Id: @(#)gnplayer.c 3.5 2000/07/16 */
/* Copyright (C) 1998 by Erik Andersen <andersee@debian.org> */
@@ -11,95 +11,92 @@
#include "hack.h"
static gint role_number;
static GtkWidget* clist;
static GtkWidget *clist;
static void
player_sel_key_hit (GtkWidget *widget, GdkEventKey *event, gpointer data)
player_sel_key_hit(GtkWidget *widget, GdkEventKey *event, gpointer data)
{
const char** roles = data;
const char **roles = data;
int i;
for (i = 0; roles[i] != 0; ++i) {
if (tolower(roles[i][0]) == tolower(event->keyval)) {
role_number = i;
gtk_clist_select_row( GTK_CLIST (clist), i, 0);
if (gtk_clist_row_is_visible(GTK_CLIST(clist),
i) != GTK_VISIBILITY_FULL)
gtk_clist_moveto(GTK_CLIST(clist), i, 0, 0.5, 0);
}
if (tolower(roles[i][0]) == tolower(event->keyval)) {
role_number = i;
gtk_clist_select_row(GTK_CLIST(clist), i, 0);
if (gtk_clist_row_is_visible(GTK_CLIST(clist), i)
!= GTK_VISIBILITY_FULL)
gtk_clist_moveto(GTK_CLIST(clist), i, 0, 0.5, 0);
}
}
}
static void
player_sel_row_selected (GtkCList *clist, int row, int col, GdkEvent *event)
player_sel_row_selected(GtkCList *clist, int row, int col, GdkEvent *event)
{
role_number = row;
}
int
ghack_player_sel_dialog(const char** choices,
const gchar* title,
const gchar* prompt)
ghack_player_sel_dialog(const char **choices, const gchar *title,
const gchar *prompt)
{
int i;
static GtkWidget* dialog;
static GtkWidget* swin;
static GtkWidget* frame1;
static GtkWidget *dialog;
static GtkWidget *swin;
static GtkWidget *frame1;
dialog = gnome_dialog_new(title,
GNOME_STOCK_BUTTON_OK,
_("Random"),
GNOME_STOCK_BUTTON_CANCEL,
NULL);
gnome_dialog_close_hides (GNOME_DIALOG (dialog), FALSE);
gtk_signal_connect (GTK_OBJECT (dialog), "key_press_event",
GTK_SIGNAL_FUNC (player_sel_key_hit), choices );
dialog = gnome_dialog_new(title, GNOME_STOCK_BUTTON_OK, _("Random"),
GNOME_STOCK_BUTTON_CANCEL, NULL);
gnome_dialog_close_hides(GNOME_DIALOG(dialog), FALSE);
gtk_signal_connect(GTK_OBJECT(dialog), "key_press_event",
GTK_SIGNAL_FUNC(player_sel_key_hit), choices);
frame1 = gtk_frame_new(prompt);
gtk_object_set_data (GTK_OBJECT (dialog), "frame1", frame1);
gtk_widget_show (frame1);
gtk_container_border_width (GTK_CONTAINER (frame1), 3);
gtk_object_set_data(GTK_OBJECT(dialog), "frame1", frame1);
gtk_widget_show(frame1);
gtk_container_border_width(GTK_CONTAINER(frame1), 3);
swin = gtk_scrolled_window_new (NULL, NULL);
clist = gtk_clist_new (2);
gtk_clist_column_titles_hide (GTK_CLIST (clist));
gtk_widget_set_usize (GTK_WIDGET (clist), 100, 180);
gtk_container_add (GTK_CONTAINER (swin), clist);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swin),
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
swin = gtk_scrolled_window_new(NULL, NULL);
clist = gtk_clist_new(2);
gtk_clist_column_titles_hide(GTK_CLIST(clist));
gtk_widget_set_usize(GTK_WIDGET(clist), 100, 180);
gtk_container_add(GTK_CONTAINER(swin), clist);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(swin),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
gtk_signal_connect (GTK_OBJECT (clist), "select_row",
GTK_SIGNAL_FUNC (player_sel_row_selected), NULL );
gtk_signal_connect(GTK_OBJECT(clist), "select_row",
GTK_SIGNAL_FUNC(player_sel_row_selected), NULL);
gtk_container_add (GTK_CONTAINER (frame1), swin);
gtk_box_pack_start_defaults (GTK_BOX (GNOME_DIALOG (dialog)->vbox), frame1);
gtk_container_add(GTK_CONTAINER(frame1), swin);
gtk_box_pack_start_defaults(GTK_BOX(GNOME_DIALOG(dialog)->vbox), frame1);
/* Add the roles into the list here... */
for (i=0; choices[i]; i++) {
gchar accelBuf[BUFSZ];
const char *text[3]={accelBuf, choices[i],NULL};
sprintf( accelBuf, "%c ", tolower(choices[i][0]));
gtk_clist_insert (GTK_CLIST (clist), i, (char**)text);
for (i = 0; choices[i]; i++) {
gchar accelBuf[BUFSZ];
const char *text[3] = { accelBuf, choices[i], NULL };
sprintf(accelBuf, "%c ", tolower(choices[i][0]));
gtk_clist_insert(GTK_CLIST(clist), i, (char **) text);
}
gtk_clist_columns_autosize (GTK_CLIST (clist));
gtk_widget_show_all (swin);
gtk_clist_columns_autosize(GTK_CLIST(clist));
gtk_widget_show_all(swin);
/* Center the dialog over over parent */
gnome_dialog_set_default( GNOME_DIALOG(dialog), 0);
gtk_window_set_modal( GTK_WINDOW(dialog), TRUE);
gnome_dialog_set_parent (GNOME_DIALOG (dialog),
GTK_WINDOW (ghack_get_main_window ()) );
gnome_dialog_set_default(GNOME_DIALOG(dialog), 0);
gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
gnome_dialog_set_parent(GNOME_DIALOG(dialog),
GTK_WINDOW(ghack_get_main_window()));
/* Run the dialog -- returning whichever button was pressed */
i = gnome_dialog_run_and_close(GNOME_DIALOG(dialog));
/* Quit on button 2 or error */
if (i < 0 || i > 1) {
return(ROLE_NONE);
if (i < 0 || i > 1) {
return (ROLE_NONE);
}
/* Random is button 1*/
if (i == 1 ) {
return(ROLE_RANDOM);
if (i == 1) {
return (ROLE_RANDOM);
}
return ( role_number);
return (role_number);
}
+191 -234
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 gnsignal.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
/* NetHack 3.6 gnsignal.c $NHDT-Date: 1431192772 2015/05/09 17:32:52 $ $NHDT-Branch: master $:$NHDT-Revision: 1.10 $ */
/* NetHack 3.6 gnsignal.c $Date: 2009/05/06 10:57:45 $ $Revision: 1.7 $ */
/* SCCS Id: @(#)gnsignal.c 3.5 2005/11/19 */
/* Copyright (C) 1998 by Anthony Taylor <tonyt@ptialaska.net> */
@@ -10,10 +10,10 @@
GList *g_keyBuffer;
GList *g_clickBuffer;
int g_numKeys=0;
int g_numClicks=0;
int g_askingQuestion=0;
static int s_done=FALSE;
int g_numKeys = 0;
int g_numClicks = 0;
int g_askingQuestion = 0;
static int s_done = FALSE;
/*
* ghack_init_signals
@@ -59,161 +59,102 @@ static int s_done=FALSE;
*/
void
ghack_init_signals( void)
ghack_init_signals(void)
{
ghack_signals[GHSIG_CURS] =
gtk_object_class_user_signal_new (gtk_type_class (gtk_widget_get_type ()),
"ghack_curs",
GTK_RUN_FIRST,
gtk_marshal_NONE__INT_INT,
GTK_TYPE_NONE,
2,
GTK_TYPE_INT,
GTK_TYPE_INT);
ghack_signals[GHSIG_CURS] = gtk_object_class_user_signal_new(
gtk_type_class(gtk_widget_get_type()), "ghack_curs", GTK_RUN_FIRST,
gtk_marshal_NONE__INT_INT, GTK_TYPE_NONE, 2, GTK_TYPE_INT,
GTK_TYPE_INT);
ghack_signals[GHSIG_PUTSTR] =
gtk_object_class_user_signal_new (gtk_type_class (gtk_widget_get_type ()),
"ghack_putstr",
GTK_RUN_FIRST,
gtk_marshal_NONE__INT_POINTER,
GTK_TYPE_NONE,
2,
GTK_TYPE_INT,
GTK_TYPE_POINTER);
ghack_signals[GHSIG_PUTSTR] = gtk_object_class_user_signal_new(
gtk_type_class(gtk_widget_get_type()), "ghack_putstr", GTK_RUN_FIRST,
gtk_marshal_NONE__INT_POINTER, GTK_TYPE_NONE, 2, GTK_TYPE_INT,
GTK_TYPE_POINTER);
ghack_signals[GHSIG_PRINT_GLYPH] =
gtk_object_class_user_signal_new (gtk_type_class (gtk_widget_get_type ()),
"ghack_print_glyph",
GTK_RUN_FIRST,
gtk_marshal_NONE__INT_INT_POINTER,
GTK_TYPE_NONE,
3,
GTK_TYPE_INT,
GTK_TYPE_INT,
GTK_TYPE_POINTER);
ghack_signals[GHSIG_PRINT_GLYPH] = gtk_object_class_user_signal_new(
gtk_type_class(gtk_widget_get_type()), "ghack_print_glyph",
GTK_RUN_FIRST, gtk_marshal_NONE__INT_INT_POINTER, GTK_TYPE_NONE, 3,
GTK_TYPE_INT, GTK_TYPE_INT, GTK_TYPE_POINTER);
ghack_signals[GHSIG_CLEAR] =
gtk_object_class_user_signal_new (gtk_type_class (gtk_widget_get_type ()),
"ghack_clear",
GTK_RUN_FIRST,
gtk_marshal_NONE__NONE,
GTK_TYPE_NONE,
0);
ghack_signals[GHSIG_DISPLAY] =
gtk_object_class_user_signal_new (gtk_type_class (gtk_widget_get_type ()),
"ghack_display",
GTK_RUN_FIRST,
gtk_marshal_NONE__BOOL,
GTK_TYPE_NONE,
1,
GTK_TYPE_BOOL);
ghack_signals[GHSIG_START_MENU] =
gtk_object_class_user_signal_new (gtk_type_class (gtk_widget_get_type ()),
"ghack_start_menu",
GTK_RUN_FIRST,
gtk_marshal_NONE__NONE,
GTK_TYPE_NONE,
0);
ghack_signals[GHSIG_ADD_MENU] =
gtk_object_class_user_signal_new (gtk_type_class (gtk_widget_get_type ()),
"ghack_add_menu",
GTK_RUN_FIRST,
gtk_marshal_NONE__POINTER,
GTK_TYPE_NONE,
1,
GTK_TYPE_POINTER);
ghack_signals[GHSIG_END_MENU] =
gtk_object_class_user_signal_new (gtk_type_class (gtk_widget_get_type ()),
"ghack_end_menu",
GTK_RUN_FIRST,
gtk_marshal_NONE__POINTER,
GTK_TYPE_NONE,
1,
GTK_TYPE_POINTER);
ghack_signals[GHSIG_SELECT_MENU] =
gtk_object_class_user_signal_new (gtk_type_class (gtk_widget_get_type ()),
"ghack_select_menu",
GTK_RUN_FIRST,
gtk_marshal_NONE__POINTER_INT_POINTER,
GTK_TYPE_NONE,
3,
GTK_TYPE_POINTER,
GTK_TYPE_INT,
GTK_TYPE_POINTER);
ghack_signals[GHSIG_CLIPAROUND] =
gtk_object_class_user_signal_new (gtk_type_class (gtk_widget_get_type ()),
"ghack_cliparound",
GTK_RUN_FIRST,
gtk_marshal_NONE__INT_INT,
GTK_TYPE_NONE,
2,
GTK_TYPE_INT,
GTK_TYPE_INT);
ghack_signals[GHSIG_CLEAR] = gtk_object_class_user_signal_new(
gtk_type_class(gtk_widget_get_type()), "ghack_clear", GTK_RUN_FIRST,
gtk_marshal_NONE__NONE, GTK_TYPE_NONE, 0);
ghack_signals[GHSIG_FADE_HIGHLIGHT] =
gtk_object_class_user_signal_new (gtk_type_class (gtk_widget_get_type ()),
"ghack_fade_highlight",
GTK_RUN_FIRST,
gtk_marshal_NONE__NONE,
GTK_TYPE_NONE,
0);
ghack_signals[GHSIG_DELAY] =
gtk_object_class_user_signal_new (gtk_type_class (gtk_widget_get_type ()),
"gnome_delay_output",
GTK_RUN_FIRST,
gtk_marshal_NONE__INT,
GTK_TYPE_NONE,
1,
GTK_TYPE_INT);
ghack_signals[GHSIG_DISPLAY] = gtk_object_class_user_signal_new(
gtk_type_class(gtk_widget_get_type()), "ghack_display", GTK_RUN_FIRST,
gtk_marshal_NONE__BOOL, GTK_TYPE_NONE, 1, GTK_TYPE_BOOL);
ghack_signals[GHSIG_START_MENU] = gtk_object_class_user_signal_new(
gtk_type_class(gtk_widget_get_type()), "ghack_start_menu",
GTK_RUN_FIRST, gtk_marshal_NONE__NONE, GTK_TYPE_NONE, 0);
ghack_signals[GHSIG_ADD_MENU] = gtk_object_class_user_signal_new(
gtk_type_class(gtk_widget_get_type()), "ghack_add_menu",
GTK_RUN_FIRST, gtk_marshal_NONE__POINTER, GTK_TYPE_NONE, 1,
GTK_TYPE_POINTER);
ghack_signals[GHSIG_END_MENU] = gtk_object_class_user_signal_new(
gtk_type_class(gtk_widget_get_type()), "ghack_end_menu",
GTK_RUN_FIRST, gtk_marshal_NONE__POINTER, GTK_TYPE_NONE, 1,
GTK_TYPE_POINTER);
ghack_signals[GHSIG_SELECT_MENU] = gtk_object_class_user_signal_new(
gtk_type_class(gtk_widget_get_type()), "ghack_select_menu",
GTK_RUN_FIRST, gtk_marshal_NONE__POINTER_INT_POINTER, GTK_TYPE_NONE,
3, GTK_TYPE_POINTER, GTK_TYPE_INT, GTK_TYPE_POINTER);
ghack_signals[GHSIG_CLIPAROUND] = gtk_object_class_user_signal_new(
gtk_type_class(gtk_widget_get_type()), "ghack_cliparound",
GTK_RUN_FIRST, gtk_marshal_NONE__INT_INT, GTK_TYPE_NONE, 2,
GTK_TYPE_INT, GTK_TYPE_INT);
ghack_signals[GHSIG_FADE_HIGHLIGHT] = gtk_object_class_user_signal_new(
gtk_type_class(gtk_widget_get_type()), "ghack_fade_highlight",
GTK_RUN_FIRST, gtk_marshal_NONE__NONE, GTK_TYPE_NONE, 0);
ghack_signals[GHSIG_DELAY] = gtk_object_class_user_signal_new(
gtk_type_class(gtk_widget_get_type()), "gnome_delay_output",
GTK_RUN_FIRST, gtk_marshal_NONE__INT, GTK_TYPE_NONE, 1, GTK_TYPE_INT);
}
/* For want of a better place, I'm putting the delay output stuff here
* -Erik
*/
static gint timeout_callback(gpointer data)
static gint
timeout_callback(gpointer data)
{
s_done=TRUE;
s_done = TRUE;
return FALSE;
}
void
ghack_delay( GtkWidget *win, int numMillisecs, gpointer data)
ghack_delay(GtkWidget *win, int numMillisecs, gpointer data)
{
s_done=FALSE;
gtk_timeout_add( (unsigned int) numMillisecs,
timeout_callback, NULL);
while( s_done==FALSE)
gtk_main_iteration();
s_done = FALSE;
gtk_timeout_add((unsigned int) numMillisecs, timeout_callback, NULL);
while (s_done == FALSE)
gtk_main_iteration();
}
void
ghack_handle_button_press(GtkWidget *widget, GdkEventButton *event,
gpointer data)
void
ghack_handle_button_press(GtkWidget *widget, GdkEventButton *event,
gpointer data)
{
GHClick *click;
double x1, y1;
if (event->type != GDK_BUTTON_PRESS)
return;
gnome_canvas_window_to_world( GNOME_CANVAS( widget), event->x,
event->y, &x1, &y1);
/*
g_message("I got a click at %f,%f with button %d \n",
x1, y1, event->button);
*/
return;
gnome_canvas_window_to_world(GNOME_CANVAS(widget), event->x, event->y,
&x1, &y1);
/*
g_message("I got a click at %f,%f with button %d \n",
x1, y1, event->button);
*/
/* We allocate storage here, so we need to remember if (g_numClicks>0)
* to blow this away when closing the app using something like
* to blow this away when closing the app using something like
* while (g_clickBuffer)
* {
* g_free((GHClick)g_clickBuffer->data);
@@ -222,32 +163,31 @@ ghack_handle_button_press(GtkWidget *widget, GdkEventButton *event,
* g_list_free( g_clickBuffer );
*
*/
click = g_new( GHClick, 1);
click->x=(int)x1/ghack_glyph_width();
click->y=(int)y1/ghack_glyph_height();
click->mod=(event->button == 1)? CLICK_1 : CLICK_2;
g_clickBuffer = g_list_prepend (g_clickBuffer, click);
click = g_new(GHClick, 1);
click->x = (int) x1 / ghack_glyph_width();
click->y = (int) y1 / ghack_glyph_height();
click->mod = (event->button == 1) ? CLICK_1 : CLICK_2;
g_clickBuffer = g_list_prepend(g_clickBuffer, click);
/* Could use g_list_length(), but it is stupid and just
* traverses the list while counting, so we'll just do
* traverses the list while counting, so we'll just do
* the counting ourselves in advance. */
g_numClicks++;
}
#ifndef M
# ifndef NHSTDC
# define M(c) (0x80 | (c))
# else
# define M(c) ((c) - 128)
# endif /* NHSTDC */
#ifndef NHSTDC
#define M(c) (0x80 | (c))
#else
#define M(c) ((c) -128)
#endif /* NHSTDC */
#endif
#ifndef C
#define C(c) (0x1f & (c))
#define C(c) (0x1f & (c))
#endif
void
void
ghack_handle_key_press(GtkWidget *widget, GdkEventKey *event, gpointer data)
{
static int was_pound = 0;
@@ -255,7 +195,7 @@ ghack_handle_key_press(GtkWidget *widget, GdkEventKey *event, gpointer data)
int ctl = GDK_CONTROL_MASK;
int alt = GDK_MOD1_MASK;
/* Turn this on to debug key events */
/* Turn this on to debug key events */
#if 0
g_message("I got a \"%s\" key (%d) %s%s",
gdk_keyval_name (event->keyval), event->keyval,
@@ -263,118 +203,136 @@ ghack_handle_key_press(GtkWidget *widget, GdkEventKey *event, gpointer data)
#endif
switch (event->keyval) {
/* special keys to do stuff with */
/* special keys to do stuff with */
/* Set up the direction keys */
/* Set up the direction keys */
/* First handle the arrow keys -- these always mean move */
/* First handle the arrow keys -- these always mean move */
case GDK_Right:
case GDK_rightarrow:
key = Cmd.move_E; break;
key = Cmd.move_E;
break;
case GDK_Left:
case GDK_leftarrow:
key = Cmd.move_W; break;
key = Cmd.move_W;
break;
case GDK_Up:
case GDK_uparrow:
key = Cmd.move_N; break;
key = Cmd.move_N;
break;
case GDK_Down:
case GDK_downarrow:
key = Cmd.move_S; break;
key = Cmd.move_S;
break;
case GDK_Home:
key = Cmd.move_NW; break;
key = Cmd.move_NW;
break;
case GDK_End:
key = Cmd.move_SW; break;
key = Cmd.move_SW;
break;
case GDK_Page_Down:
key = Cmd.move_SE; break;
key = Cmd.move_SE;
break;
case GDK_Page_Up:
key = Cmd.move_NE; break;
case ' ': key='.'; break;
key = Cmd.move_NE;
break;
case ' ':
key = '.';
break;
/* Now, handle the numberpad (move or numbers) */
/* Now, handle the numberpad (move or numbers) */
case GDK_KP_Right:
case GDK_KP_6:
if (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK) && iflags.num_pad)
key = GDK_KP_6;
else
key='6';
break;
if (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)
&& iflags.num_pad)
key = GDK_KP_6;
else
key = '6';
break;
case GDK_KP_Left:
case GDK_KP_4:
if (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK) && iflags.num_pad)
key = GDK_KP_4;
else
key='4';
break;
if (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)
&& iflags.num_pad)
key = GDK_KP_4;
else
key = '4';
break;
case GDK_KP_Up:
case GDK_KP_8:
if (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK) && iflags.num_pad)
key = GDK_KP_8;
else
key='8';
break;
if (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)
&& iflags.num_pad)
key = GDK_KP_8;
else
key = '8';
break;
case GDK_KP_Down:
case GDK_KP_2:
if (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK) && iflags.num_pad)
key = GDK_KP_2;
else
key='2';
break;
if (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)
&& iflags.num_pad)
key = GDK_KP_2;
else
key = '2';
break;
/* Move Top-Left */
/* Move Top-Left */
case GDK_KP_Home:
case GDK_KP_7:
if (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK) && iflags.num_pad)
key = GDK_KP_7;
else
key='7';
break;
if (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)
&& iflags.num_pad)
key = GDK_KP_7;
else
key = '7';
break;
case GDK_KP_Page_Up:
case GDK_KP_9:
if (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK) && iflags.num_pad)
key = GDK_KP_9;
else
key='9';
break;
if (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)
&& iflags.num_pad)
key = GDK_KP_9;
else
key = '9';
break;
case GDK_KP_End:
case GDK_KP_1:
if (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK) && iflags.num_pad)
key = GDK_KP_1;
else
key='1';
break;
if (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)
&& iflags.num_pad)
key = GDK_KP_1;
else
key = '1';
break;
case GDK_KP_Page_Down:
case GDK_KP_3:
if (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK) && iflags.num_pad)
key = GDK_KP_3;
else
key='3';
break;
if (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)
&& iflags.num_pad)
key = GDK_KP_3;
else
key = '3';
break;
case GDK_KP_5:
if (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK) && iflags.num_pad)
key = GDK_KP_5;
else
key='5';
break;
if (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)
&& iflags.num_pad)
key = GDK_KP_5;
else
key = '5';
break;
case GDK_KP_Delete:
case GDK_KP_Decimal:
key='.';
break;
key = '.';
break;
/* can't just ignore "#", it's a core feature */
/* can't just ignore "#", it's a core feature */
case GDK_numbersign:
key='#';
break;
key = '#';
break;
/* We will probably want to do something with these later... */
/* We will probably want to do something with these later... */
case GDK_KP_Begin:
case GDK_KP_F1:
case GDK_F1:
@@ -392,8 +350,8 @@ ghack_handle_key_press(GtkWidget *widget, GdkEventKey *event, gpointer data)
case GDK_F10:
case GDK_F11:
case GDK_F12:
break;
/* various keys to ignore */
break;
/* various keys to ignore */
case GDK_KP_Insert:
case GDK_Insert:
case GDK_Delete:
@@ -414,31 +372,30 @@ ghack_handle_key_press(GtkWidget *widget, GdkEventKey *event, gpointer data)
case GDK_Meta_R:
case GDK_Mode_switch:
case GDK_Multi_key:
return;
return;
default:
key = event->keyval;
break;
key = event->keyval;
break;
}
if ((event->state & alt) || was_pound) {
key=M(event->keyval);
key = M(event->keyval);
} else if (event->state & ctl) {
key=C(event->keyval);
key = C(event->keyval);
}
if (was_pound) {
was_pound = 0;
was_pound = 0;
}
/* Ok, here is where we do clever stuff to overide the default
* game behavior */
if (g_askingQuestion == 0) {
if (key == 'S' || key == M('S') || key == C('S')) {
ghack_save_game_cb( NULL, NULL);
return;
}
if (key == 'S' || key == M('S') || key == C('S')) {
ghack_save_game_cb(NULL, NULL);
return;
}
}
g_keyBuffer = g_list_prepend (g_keyBuffer, GINT_TO_POINTER( key));
g_keyBuffer = g_list_prepend(g_keyBuffer, GINT_TO_POINTER(key));
g_numKeys++;
}
+647 -663
View File
File diff suppressed because it is too large Load Diff
+71 -78
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 gntext.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
/* NetHack 3.6 gntext.c $NHDT-Date: 1431192772 2015/05/09 17:32:52 $ $NHDT-Branch: master $:$NHDT-Revision: 1.8 $ */
/* NetHack 3.6 gntext.c $Date: 2009/05/06 10:58:00 $ $Revision: 1.5 $ */
/* SCCS Id: @(#)gntext.c 3.5 2000/07/16 */
/* Copyright (C) 1998 by Erik Andersen <andersee@debian.org> */
@@ -21,8 +21,6 @@
#define RIP_DRAW_X 114
#define RIP_DRAW_Y 69
/* Text Window widgets */
GtkWidget *RIP = NULL;
GtkWidget *RIPlabel = NULL;
@@ -31,130 +29,125 @@ GnomeLess *gless;
static int showRIP = 0;
void ghack_text_window_clear(GtkWidget *widget, gpointer data)
void
ghack_text_window_clear(GtkWidget *widget, gpointer data)
{
g_assert (gless != NULL);
gtk_editable_delete_text (GTK_EDITABLE (gless->text), 0, 0);
g_assert(gless != NULL);
gtk_editable_delete_text(GTK_EDITABLE(gless->text), 0, 0);
}
void ghack_text_window_destroy()
void
ghack_text_window_destroy()
{
TW_window = NULL;
}
void ghack_text_window_display(GtkWidget *widget, boolean block,
gpointer data)
void
ghack_text_window_display(GtkWidget *widget, boolean block, gpointer data)
{
if(showRIP == 1) {
gtk_widget_show (GTK_WIDGET ( RIP));
gtk_window_set_title(GTK_WINDOW( TW_window), "Rest In Peace");
if (showRIP == 1) {
gtk_widget_show(GTK_WIDGET(RIP));
gtk_window_set_title(GTK_WINDOW(TW_window), "Rest In Peace");
}
gtk_signal_connect (GTK_OBJECT (TW_window), "destroy",
(GtkSignalFunc) ghack_text_window_destroy, NULL);
gtk_signal_connect(GTK_OBJECT(TW_window), "destroy",
(GtkSignalFunc) ghack_text_window_destroy, NULL);
if (block)
gnome_dialog_run(GNOME_DIALOG(TW_window));
gnome_dialog_run(GNOME_DIALOG(TW_window));
else
gnome_dialog_run_and_close(GNOME_DIALOG(TW_window));
if(showRIP == 1) {
showRIP = 0;
gtk_widget_hide (GTK_WIDGET ( RIP));
gtk_window_set_title(GTK_WINDOW(TW_window), "Text Window");
gnome_dialog_run_and_close(GNOME_DIALOG(TW_window));
if (showRIP == 1) {
showRIP = 0;
gtk_widget_hide(GTK_WIDGET(RIP));
gtk_window_set_title(GTK_WINDOW(TW_window), "Text Window");
}
}
void ghack_text_window_put_string(GtkWidget *widget, int attr,
const char* text, gpointer data)
void
ghack_text_window_put_string(GtkWidget *widget, int attr, const char *text,
gpointer data)
{
if(text == NULL)
if (text == NULL)
return;
/* Don't bother with attributes yet */
gtk_text_insert (GTK_TEXT (gless->text), NULL, NULL, NULL, text, -1);
gtk_text_insert (GTK_TEXT (gless->text), NULL, NULL, NULL, "\n", -1);
gtk_text_insert(GTK_TEXT(gless->text), NULL, NULL, NULL, text, -1);
gtk_text_insert(GTK_TEXT(gless->text), NULL, NULL, NULL, "\n", -1);
}
GtkWidget* ghack_init_text_window ( )
GtkWidget *
ghack_init_text_window()
{
GtkWidget *pixmap;
if(TW_window)
return(GTK_WIDGET(TW_window));
if (TW_window)
return (GTK_WIDGET(TW_window));
TW_window = gnome_dialog_new("Text Window", GNOME_STOCK_BUTTON_OK, NULL);
gtk_window_set_default_size( GTK_WINDOW(TW_window), 500, 400);
gtk_window_set_default_size(GTK_WINDOW(TW_window), 500, 400);
gtk_window_set_policy(GTK_WINDOW(TW_window), TRUE, TRUE, FALSE);
gtk_window_set_title(GTK_WINDOW(TW_window), "Text Window");
/* create GNOME pixmap object */
pixmap = gnome_pixmap_new_from_xpm_d (rip_xpm);
g_assert (pixmap != NULL);
gtk_widget_show (GTK_WIDGET (pixmap));
pixmap = gnome_pixmap_new_from_xpm_d(rip_xpm);
g_assert(pixmap != NULL);
gtk_widget_show(GTK_WIDGET(pixmap));
/* create label with our "death message", sized to fit into the
* tombstone */
RIPlabel = gtk_label_new ("RIP");
g_assert (RIPlabel != NULL);
RIPlabel = gtk_label_new("RIP");
g_assert(RIPlabel != NULL);
/* gtk_label_set_justify is broken? */
gtk_label_set_justify (GTK_LABEL (RIPlabel), GTK_JUSTIFY_CENTER);
gtk_label_set_line_wrap (GTK_LABEL (RIPlabel), TRUE);
gtk_widget_set_usize (RIPlabel, RIP_DRAW_WIDTH, RIP_DRAW_HEIGHT);
gtk_widget_show (RIPlabel);
gtk_label_set_justify(GTK_LABEL(RIPlabel), GTK_JUSTIFY_CENTER);
gtk_label_set_line_wrap(GTK_LABEL(RIPlabel), TRUE);
gtk_widget_set_usize(RIPlabel, RIP_DRAW_WIDTH, RIP_DRAW_HEIGHT);
gtk_widget_show(RIPlabel);
/* create a fixed sized widget for the RIP pixmap */
RIP = gtk_fixed_new ();
g_assert (RIP != NULL);
gtk_widget_set_usize (RIP, RIP_IMAGE_WIDTH, RIP_IMAGE_HEIGHT);
gtk_fixed_put (GTK_FIXED (RIP), pixmap, 0, 0);
gtk_fixed_put (GTK_FIXED (RIP), RIPlabel, RIP_DRAW_X, RIP_DRAW_Y);
gtk_widget_show (RIP);
gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(TW_window)->vbox), RIP,
TRUE, TRUE, 0);
RIP = gtk_fixed_new();
g_assert(RIP != NULL);
gtk_widget_set_usize(RIP, RIP_IMAGE_WIDTH, RIP_IMAGE_HEIGHT);
gtk_fixed_put(GTK_FIXED(RIP), pixmap, 0, 0);
gtk_fixed_put(GTK_FIXED(RIP), RIPlabel, RIP_DRAW_X, RIP_DRAW_Y);
gtk_widget_show(RIP);
gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(TW_window)->vbox), RIP, TRUE,
TRUE, 0);
/* create a gnome Less widget for the text stuff */
gless = GNOME_LESS (gnome_less_new ());
g_assert (gless != NULL);
gtk_widget_show (GTK_WIDGET (gless));
gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(TW_window)->vbox),
GTK_WIDGET (gless), TRUE, TRUE, 0);
gless = GNOME_LESS(gnome_less_new());
g_assert(gless != NULL);
gtk_widget_show(GTK_WIDGET(gless));
gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(TW_window)->vbox),
GTK_WIDGET(gless), TRUE, TRUE, 0);
/* Hook up some signals */
gtk_signal_connect(GTK_OBJECT(TW_window), "ghack_putstr",
GTK_SIGNAL_FUNC(ghack_text_window_put_string),
NULL);
GTK_SIGNAL_FUNC(ghack_text_window_put_string), NULL);
gtk_signal_connect(GTK_OBJECT(TW_window), "ghack_clear",
GTK_SIGNAL_FUNC(ghack_text_window_clear),
NULL);
GTK_SIGNAL_FUNC(ghack_text_window_clear), NULL);
gtk_signal_connect(GTK_OBJECT(TW_window), "ghack_display",
GTK_SIGNAL_FUNC(ghack_text_window_display),
NULL);
GTK_SIGNAL_FUNC(ghack_text_window_display), NULL);
/* Center the dialog over over parent */
gnome_dialog_set_parent( GNOME_DIALOG (TW_window),
GTK_WINDOW(ghack_get_main_window()) );
gnome_dialog_set_parent(GNOME_DIALOG(TW_window),
GTK_WINDOW(ghack_get_main_window()));
gtk_window_set_modal( GTK_WINDOW(TW_window), TRUE);
gtk_window_set_modal(GTK_WINDOW(TW_window), TRUE);
gtk_widget_show_all(TW_window);
gtk_widget_hide (GTK_WIDGET ( RIP));
gnome_dialog_close_hides (GNOME_DIALOG (TW_window), TRUE);
gtk_widget_hide(GTK_WIDGET(RIP));
gnome_dialog_close_hides(GNOME_DIALOG(TW_window), TRUE);
return GTK_WIDGET(TW_window);
}
void ghack_text_window_rip_string( const char* string)
void
ghack_text_window_rip_string(const char *string)
{
/* This is called to specify that the next message window will
* be a RIP window, which will include this text */
showRIP = 1;
gtk_label_set( GTK_LABEL( RIPlabel), string);
gtk_label_set(GTK_LABEL(RIPlabel), string);
}
+37 -31
View File
@@ -1,6 +1,6 @@
/* NetHack 3.6 gnworn.c 2009/05/06 10:58:06 1.3 */
/*
* $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$
* $NHDT-Date: 1431192771 2015/05/09 17:32:51 $ $NHDT-Branch: master $:$NHDT-Revision: 1.9 $
* $Date: 2012/01/10 17:47:38 $ $Revision: 1.4 $
*/
/* Copyright (C) 2002, Dylan Alex Simon */
@@ -11,17 +11,21 @@
#include "gnsignal.h"
#include "gnomeprv.h"
#define WORN_WIDTH 3
#define WORN_HEIGHT 6
#define WORN_WIDTH 3
#define WORN_HEIGHT 6
#define WORN_OBJECT_LIST /* struct obj *[WORN_HEIGHT][WORN_WIDTH] = */ { \
{ uquiver, uarmh, u.twoweap ? NULL : uswapwep }, \
{ u.twoweap ? uswapwep : NULL, ublindf, uwep }, \
{ uleft, uamul, uright }, \
{ uarms, uarmc, uarmg }, \
{ uarmu, uarm, uskin }, \
{ uball, uarmf, uchain } \
}
#define WORN_OBJECT_LIST /* struct obj *[WORN_HEIGHT][WORN_WIDTH] = */ \
{ \
{ \
uquiver, uarmh, u.twoweap ? NULL : uswapwep \
} \
, { u.twoweap ? uswapwep : NULL, ublindf, uwep }, \
{ uleft, uamul, uright }, { uarms, uarmc, uarmg }, \
{ uarmu, uarm, uskin }, \
{ \
uball, uarmf, uchain \
} \
}
static GtkWidget *worn_contents[WORN_HEIGHT][WORN_WIDTH];
static struct obj *last_worn_objects[WORN_HEIGHT][WORN_WIDTH];
@@ -29,26 +33,27 @@ static struct obj *last_worn_objects[WORN_HEIGHT][WORN_WIDTH];
GdkImlibImage *image_of_worn_object(struct obj *o);
void ghack_worn_display(GtkWidget *win, boolean block, gpointer data);
GtkWidget*
GtkWidget *
ghack_init_worn_window()
{
GtkWidget *top;
GtkWidget *table;
GtkWidget *tablealign;
GtkWidget *label;
int i,j;
int i, j;
top = gtk_vbox_new(FALSE, 2);
table = gtk_table_new(WORN_HEIGHT, WORN_WIDTH, TRUE);
for (i = 0; i < WORN_HEIGHT; i++) {
for (j = 0; j < WORN_WIDTH; j++) {
worn_contents[i][j] =
gnome_pixmap_new_from_imlib(image_of_worn_object(NULL));
last_worn_objects[i][j] = NULL; /* a pointer that will never be */
gtk_table_attach(GTK_TABLE(table), GTK_WIDGET(worn_contents[i][j]),
j, j+1, i, i+1, 0, 0, 0, 0);
}
for (j = 0; j < WORN_WIDTH; j++) {
worn_contents[i][j] =
gnome_pixmap_new_from_imlib(image_of_worn_object(NULL));
last_worn_objects[i][j] = NULL; /* a pointer that will never be */
gtk_table_attach(GTK_TABLE(table),
GTK_WIDGET(worn_contents[i][j]), j, j + 1, i,
i + 1, 0, 0, 0, 0);
}
}
tablealign = gtk_alignment_new(0.5, 0.0, 0.0, 1.0);
gtk_box_pack_start(GTK_BOX(top), tablealign, FALSE, FALSE, 0);
@@ -59,21 +64,21 @@ ghack_init_worn_window()
gtk_box_pack_start(GTK_BOX(top), label, FALSE, FALSE, 0);
gtk_signal_connect(GTK_OBJECT(top), "ghack_display",
GTK_SIGNAL_FUNC(ghack_worn_display), NULL);
GTK_SIGNAL_FUNC(ghack_worn_display), NULL);
return top;
}
GdkImlibImage*
GdkImlibImage *
image_of_worn_object(struct obj *o)
{
int glyph;
GdkImlibImage *im;
if (o)
glyph = obj_to_glyph(o);
glyph = obj_to_glyph(o);
else
glyph = cmap_to_glyph(S_stone);
glyph = cmap_to_glyph(S_stone);
im = ghack_image_from_glyph(glyph, FALSE);
@@ -87,12 +92,13 @@ ghack_worn_display(GtkWidget *win, boolean block, gpointer data)
struct obj *worn_objects[WORN_HEIGHT][WORN_WIDTH] = WORN_OBJECT_LIST;
for (i = 0; i < WORN_HEIGHT; i++) {
for (j = 0; j < WORN_WIDTH; j++) {
if (worn_objects[i][j] != last_worn_objects[i][j]) {
last_worn_objects[i][j] = worn_objects[i][j];
gnome_pixmap_load_imlib(GNOME_PIXMAP(worn_contents[i][j]),
image_of_worn_object(worn_objects[i][j]));
}
}
for (j = 0; j < WORN_WIDTH; j++) {
if (worn_objects[i][j] != last_worn_objects[i][j]) {
last_worn_objects[i][j] = worn_objects[i][j];
gnome_pixmap_load_imlib(
GNOME_PIXMAP(worn_contents[i][j]),
image_of_worn_object(worn_objects[i][j]));
}
}
}
}
+37 -43
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 gnyesno.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
/* NetHack 3.6 gnyesno.c $NHDT-Date: 1431192773 2015/05/09 17:32:53 $ $NHDT-Branch: master $:$NHDT-Revision: 1.7 $ */
/* NetHack 3.6 gnyesno.c $Date: 2009/05/06 10:58:06 $ $Revision: 1.4 $ */
/* SCCS Id: @(#)gnyesno.c 3.5 2000/07/16 */
/* Copyright (C) 1998 by Erik Andersen <andersee@debian.org> */
@@ -7,47 +7,42 @@
#include "gnbind.h"
#include "gnyesno.h"
int ghack_yes_no_dialog( const char *question,
const char *choices, int def)
int
ghack_yes_no_dialog(const char *question, const char *choices, int def)
{
int i=0, ret;
int i = 0, ret;
gchar button_name[BUFSZ];
GtkWidget *box;
GtkWidget* mainWnd=NULL;
GtkWidget *mainWnd = NULL;
box = gnome_message_box_new ( question, GNOME_MESSAGE_BOX_QUESTION, NULL);
box = gnome_message_box_new(question, GNOME_MESSAGE_BOX_QUESTION, NULL);
/* add buttons for each choice */
if (!strcmp(GNOME_STOCK_BUTTON_OK, choices)) {
gnome_dialog_append_button ( GNOME_DIALOG(box), GNOME_STOCK_BUTTON_OK);
gnome_dialog_set_default( GNOME_DIALOG(box), 0);
gnome_dialog_set_accelerator( GNOME_DIALOG(box), 0, 'o', 0);
gnome_dialog_append_button(GNOME_DIALOG(box), GNOME_STOCK_BUTTON_OK);
gnome_dialog_set_default(GNOME_DIALOG(box), 0);
gnome_dialog_set_accelerator(GNOME_DIALOG(box), 0, 'o', 0);
#if 0
g_print("Setting accelerator '%c' for button %d\n", 'o', 0);
#endif
}
else {
for( ; choices[i]!='\0'; i++) {
if (choices[i]=='y') {
sprintf( button_name, GNOME_STOCK_BUTTON_YES);
}
else if (choices[i]=='n') {
sprintf( button_name, GNOME_STOCK_BUTTON_NO);
}
else if (choices[i] == 'q') {
sprintf( button_name, "Quit");
} else {
sprintf( button_name, "%c", choices[i]);
}
if (def==choices[i])
gnome_dialog_set_default( GNOME_DIALOG(box), i);
gnome_dialog_append_button ( GNOME_DIALOG(box), button_name);
gnome_dialog_set_accelerator( GNOME_DIALOG(box), i, choices[i], 0);
} else {
for (; choices[i] != '\0'; i++) {
if (choices[i] == 'y') {
sprintf(button_name, GNOME_STOCK_BUTTON_YES);
} else if (choices[i] == 'n') {
sprintf(button_name, GNOME_STOCK_BUTTON_NO);
} else if (choices[i] == 'q') {
sprintf(button_name, "Quit");
} else {
sprintf(button_name, "%c", choices[i]);
}
if (def == choices[i])
gnome_dialog_set_default(GNOME_DIALOG(box), i);
gnome_dialog_append_button(GNOME_DIALOG(box), button_name);
gnome_dialog_set_accelerator(GNOME_DIALOG(box), i, choices[i], 0);
#if 0
g_print("Setting accelerator '%c' for button %d\n", choices[i], i);
#endif
}
}
}
#if 0
/* Perhaps add in a quit game button, like this... */
@@ -56,23 +51,22 @@ int ghack_yes_no_dialog( const char *question,
g_print("Setting accelerator '%c' for button %d\n", 'Q', i);
#endif
gnome_dialog_set_close(GNOME_DIALOG (box), TRUE);
mainWnd = ghack_get_main_window ();
gtk_window_set_modal( GTK_WINDOW(box), TRUE);
gtk_window_set_title( GTK_WINDOW(box), "GnomeHack");
if ( mainWnd != NULL ) {
gnome_dialog_set_parent (GNOME_DIALOG (box),
GTK_WINDOW ( mainWnd) );
gnome_dialog_set_close(GNOME_DIALOG(box), TRUE);
mainWnd = ghack_get_main_window();
gtk_window_set_modal(GTK_WINDOW(box), TRUE);
gtk_window_set_title(GTK_WINDOW(box), "GnomeHack");
if (mainWnd != NULL) {
gnome_dialog_set_parent(GNOME_DIALOG(box), GTK_WINDOW(mainWnd));
}
ret=gnome_dialog_run_and_close ( GNOME_DIALOG (box));
ret = gnome_dialog_run_and_close(GNOME_DIALOG(box));
#if 0
g_print("You selected button %d\n", ret);
#endif
if (ret==-1)
return( '\033');
if (ret == -1)
return ('\033');
else
return( choices[ret]);
return (choices[ret]);
}
+517 -515
View File
File diff suppressed because it is too large Load Diff
+96 -97
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 ppmwrite.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
/* NetHack 3.6 ppmwrite.c $NHDT-Date: 1431192770 2015/05/09 17:32:50 $ $NHDT-Branch: master $:$NHDT-Revision: 1.5 $ */
/* NetHack 3.6 ppmwrite.c $Date: 2009/05/06 10:59:00 $ $Revision: 1.2 $ */
/* this produces a raw ppm file, with a 15-character header of
* "P6 3-digit-width 3-digit-height 255\n"
@@ -14,8 +14,8 @@ extern long *FDECL(alloc, (unsigned int));
FILE *ppm_file;
struct ppmscreen {
int Width;
int Height;
int Width;
int Height;
} PpmScreen;
static int tiles_across, tiles_down, curr_tiles_across;
@@ -27,22 +27,22 @@ static void NDECL(WriteTileStrip);
static void
write_header()
{
(void) fprintf(ppm_file, "P6 %03d %03d 255\n",
PpmScreen.Width, PpmScreen.Height);
(void) fprintf(ppm_file, "P6 %03d %03d 255\n", PpmScreen.Width,
PpmScreen.Height);
}
static void
WriteTileStrip()
{
int i, j;
int i, j;
for (j = 0; j < TILE_Y; j++) {
for (i = 0; i < PpmScreen.Width; i++) {
(void) fputc((char)image[j][i].r, ppm_file);
(void) fputc((char)image[j][i].g, ppm_file);
(void) fputc((char)image[j][i].b, ppm_file);
}
}
for (j = 0; j < TILE_Y; j++) {
for (i = 0; i < PpmScreen.Width; i++) {
(void) fputc((char) image[j][i].r, ppm_file);
(void) fputc((char) image[j][i].g, ppm_file);
(void) fputc((char) image[j][i].b, ppm_file);
}
}
}
boolean
@@ -50,124 +50,123 @@ fopen_ppm_file(filename, type)
const char *filename;
const char *type;
{
int i;
int i;
if (strcmp(type, WRBMODE)) {
Fprintf(stderr, "using writing routine for non-writing?\n");
return FALSE;
}
ppm_file = fopen(filename, type);
if (ppm_file == (FILE *)0) {
Fprintf(stderr, "cannot open ppm file %s\n", filename);
return FALSE;
}
if (strcmp(type, WRBMODE)) {
Fprintf(stderr, "using writing routine for non-writing?\n");
return FALSE;
}
ppm_file = fopen(filename, type);
if (ppm_file == (FILE *) 0) {
Fprintf(stderr, "cannot open ppm file %s\n", filename);
return FALSE;
}
if (!colorsinmainmap) {
Fprintf(stderr, "no colormap set yet\n");
return FALSE;
}
if (!colorsinmainmap) {
Fprintf(stderr, "no colormap set yet\n");
return FALSE;
}
tiles_across = 20;
curr_tiles_across = 0;
PpmScreen.Width = 20 * TILE_X;
tiles_across = 20;
curr_tiles_across = 0;
PpmScreen.Width = 20 * TILE_X;
tiles_down = 0;
PpmScreen.Height = 0; /* will be rewritten later */
tiles_down = 0;
PpmScreen.Height = 0; /* will be rewritten later */
write_header();
write_header();
image = (pixel **)alloc(TILE_Y * sizeof(pixel *));
for (i = 0; i < TILE_Y; i++) {
image[i] = (pixel *) alloc(PpmScreen.Width * sizeof(pixel));
}
image = (pixel **) alloc(TILE_Y * sizeof(pixel *));
for (i = 0; i < TILE_Y; i++) {
image[i] = (pixel *) alloc(PpmScreen.Width * sizeof(pixel));
}
return TRUE;
return TRUE;
}
boolean
write_ppm_tile(pixels)
pixel (*pixels)[TILE_X];
{
int i, j;
int i, j;
for (j = 0; j < TILE_Y; j++) {
for (i = 0; i < TILE_X; i++) {
image[j][curr_tiles_across*TILE_X + i] = pixels[j][i];
}
}
curr_tiles_across++;
if (curr_tiles_across == tiles_across) {
WriteTileStrip();
curr_tiles_across = 0;
tiles_down++;
}
return TRUE;
for (j = 0; j < TILE_Y; j++) {
for (i = 0; i < TILE_X; i++) {
image[j][curr_tiles_across * TILE_X + i] = pixels[j][i];
}
}
curr_tiles_across++;
if (curr_tiles_across == tiles_across) {
WriteTileStrip();
curr_tiles_across = 0;
tiles_down++;
}
return TRUE;
}
int
fclose_ppm_file()
{
int i, j;
int i, j;
if (curr_tiles_across) { /* partial row */
/* fill with checkerboard, for lack of a better idea */
for (j = 0; j < TILE_Y; j++) {
for (i = curr_tiles_across * TILE_X;
i < PpmScreen.Width; i += 2 ) {
image[j][i].r = MainColorMap[CM_RED][0];
image[j][i].g = MainColorMap[CM_GREEN][0];
image[j][i].b = MainColorMap[CM_BLUE][0];
image[j][i+1].r = MainColorMap[CM_RED][1];
image[j][i+1].g = MainColorMap[CM_GREEN][1];
image[j][i+1].b = MainColorMap[CM_BLUE][1];
}
}
WriteTileStrip();
curr_tiles_across = 0;
tiles_down++;
}
if (curr_tiles_across) { /* partial row */
/* fill with checkerboard, for lack of a better idea */
for (j = 0; j < TILE_Y; j++) {
for (i = curr_tiles_across * TILE_X; i < PpmScreen.Width;
i += 2) {
image[j][i].r = MainColorMap[CM_RED][0];
image[j][i].g = MainColorMap[CM_GREEN][0];
image[j][i].b = MainColorMap[CM_BLUE][0];
image[j][i + 1].r = MainColorMap[CM_RED][1];
image[j][i + 1].g = MainColorMap[CM_GREEN][1];
image[j][i + 1].b = MainColorMap[CM_BLUE][1];
}
}
WriteTileStrip();
curr_tiles_across = 0;
tiles_down++;
}
for (i = 0; i < TILE_Y; i++) {
free((genericptr_t)image[i]);
}
free((genericptr_t)image);
for (i = 0; i < TILE_Y; i++) {
free((genericptr_t) image[i]);
}
free((genericptr_t) image);
PpmScreen.Height = tiles_down * TILE_Y;
rewind(ppm_file);
write_header(); /* update size */
PpmScreen.Height = tiles_down * TILE_Y;
rewind(ppm_file);
write_header(); /* update size */
return(fclose(ppm_file));
return (fclose(ppm_file));
}
int
main(argc, argv)
int argc;
char *argv[];
{
pixel pixels[TILE_Y][TILE_X];
pixel pixels[TILE_Y][TILE_X];
if (argc != 3) {
Fprintf(stderr, "usage: txt2ppm txtfile ppmfile\n");
exit(EXIT_FAILURE);
}
if (argc != 3) {
Fprintf(stderr, "usage: txt2ppm txtfile ppmfile\n");
exit(EXIT_FAILURE);
}
if (!fopen_text_file(argv[1], RDTMODE))
exit(EXIT_FAILURE);
if (!fopen_text_file(argv[1], RDTMODE))
exit(EXIT_FAILURE);
init_colormap();
init_colormap();
if (!fopen_ppm_file(argv[2], WRBMODE)) {
(void) fclose_text_file();
exit(EXIT_FAILURE);
}
if (!fopen_ppm_file(argv[2], WRBMODE)) {
(void) fclose_text_file();
exit(EXIT_FAILURE);
}
while (read_text_tile(pixels))
(void) write_ppm_tile(pixels);
while (read_text_tile(pixels))
(void) write_ppm_tile(pixels);
(void) fclose_text_file();
(void) fclose_ppm_file();
exit(EXIT_SUCCESS);
/*NOTREACHED*/
return 0;
(void) fclose_text_file();
(void) fclose_ppm_file();
exit(EXIT_SUCCESS);
/*NOTREACHED*/
return 0;
}
+79 -81
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 thintile.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
/* NetHack 3.6 thintile.c $NHDT-Date: 1431192771 2015/05/09 17:32:51 $ $NHDT-Branch: master $:$NHDT-Revision: 1.8 $ */
/* NetHack 3.6 thintile.c $Date: 2012/01/10 17:47:40 $ $Revision: 1.5 $ */
/* Copyright (c) NetHack Development Team 1995 */
/* NetHack may be freely redistributed. See license for details. */
@@ -14,13 +14,13 @@
static char pixels[TILE_Y][TILE_X];
static char *tilefiles[] = { "../win/share/monsters.txt",
"../win/share/objects.txt",
"../win/share/other.txt"};
static char *tilefiles[] = { "../win/share/monsters.txt",
"../win/share/objects.txt",
"../win/share/other.txt" };
static char *thinfiles[] = { "../win/share/monthin.txt",
"../win/share/objthin.txt",
"../win/share/oththin.txt"};
static char *thinfiles[] = { "../win/share/monthin.txt",
"../win/share/objthin.txt",
"../win/share/oththin.txt" };
static FILE *infile, *outfile;
static int tilecount;
static int tilecount_per_file;
@@ -30,101 +30,99 @@ static char comment[BUFSZ];
static void
copy_colormap()
{
int r, g, b;
char c[2];
int r, g, b;
char c[2];
while (fscanf(infile, "%[A-Za-z0-9] = (%d, %d, %d) ", c, &r, &g, &b)
== 4) {
Fprintf(outfile, "%c = (%d, %d, %d)\n", c[0], r, g, b);
}
while (fscanf(infile, "%[A-Za-z0-9] = (%d, %d, %d) ", c, &r, &g, &b)
== 4) {
Fprintf(outfile, "%c = (%d, %d, %d)\n", c[0], r, g, b);
}
}
static boolean
read_txttile()
{
int i, j;
char buf[BUFSZ];
char buf2[BUFSZ];
int i, j;
char buf[BUFSZ];
char buf2[BUFSZ];
char c[2];
char c[2];
if (fscanf(infile, "# %s %d (%[^)])", buf2, &i, buf) <= 0)
return FALSE;
if (fscanf(infile, "# %s %d (%[^)])", buf2, &i, buf) <= 0)
return FALSE;
Sprintf(comment,"# tile %d (%s)", i, buf);
/* look for non-whitespace at each stage */
if (fscanf(infile, "%1s", c) < 0) {
Fprintf(stderr, "unexpected EOF\n");
return FALSE;
}
if (c[0] != '{') {
Fprintf(stderr, "didn't find expected '{'\n");
return FALSE;
}
for (j = 0; j < TILE_Y; j++) {
for (i = 0; i < TILE_X; i++) {
if (fscanf(infile, "%1s", c) < 0) {
Fprintf(stderr, "unexpected EOF\n");
return FALSE;
}
pixels[j][i] = c[0];
}
}
if (fscanf(infile, "%1s ", c) < 0) {
Fprintf(stderr, "unexpected EOF\n");
return FALSE;
}
if (c[0] != '}') {
Fprintf(stderr, "didn't find expected '}'\n");
return FALSE;
}
return TRUE;
Sprintf(comment, "# tile %d (%s)", i, buf);
/* look for non-whitespace at each stage */
if (fscanf(infile, "%1s", c) < 0) {
Fprintf(stderr, "unexpected EOF\n");
return FALSE;
}
if (c[0] != '{') {
Fprintf(stderr, "didn't find expected '{'\n");
return FALSE;
}
for (j = 0; j < TILE_Y; j++) {
for (i = 0; i < TILE_X; i++) {
if (fscanf(infile, "%1s", c) < 0) {
Fprintf(stderr, "unexpected EOF\n");
return FALSE;
}
pixels[j][i] = c[0];
}
}
if (fscanf(infile, "%1s ", c) < 0) {
Fprintf(stderr, "unexpected EOF\n");
return FALSE;
}
if (c[0] != '}') {
Fprintf(stderr, "didn't find expected '}'\n");
return FALSE;
}
return TRUE;
}
static void
write_thintile()
{
int i, j;
int i, j;
Fprintf(outfile, "%s\n", comment);
Fprintf(outfile, "{\n");
for (j = 0; j < TILE_Y; j++) {
Fprintf(outfile, " ");
for (i = 0; i < TILE_X; i += 2) {
(void) fputc(pixels[j][i], outfile);
}
Fprintf(outfile, "\n");
}
Fprintf(outfile, "}\n");
Fprintf(outfile, "%s\n", comment);
Fprintf(outfile, "{\n");
for (j = 0; j < TILE_Y; j++) {
Fprintf(outfile, " ");
for (i = 0; i < TILE_X; i += 2) {
(void) fputc(pixels[j][i], outfile);
}
Fprintf(outfile, "\n");
}
Fprintf(outfile, "}\n");
}
int
main(argc, argv)
int argc;
char *argv[];
{
while (filenum < 3) {
tilecount_per_file = 0;
infile = fopen(tilefiles[filenum], RDTMODE);
outfile = fopen(thinfiles[filenum], WRTMODE);
copy_colormap();
while (read_txttile()) {
write_thintile();
tilecount_per_file++;
tilecount++;
}
fclose(outfile);
fclose(infile);
printf("%d tiles processed from %s\n",
tilecount_per_file, tilefiles[filenum]);
++filenum;
}
printf("Grand total of %d tiles processed.\n", tilecount);
exit(EXIT_SUCCESS);
/*NOTREACHED*/
return 0;
while (filenum < 3) {
tilecount_per_file = 0;
infile = fopen(tilefiles[filenum], RDTMODE);
outfile = fopen(thinfiles[filenum], WRTMODE);
copy_colormap();
while (read_txttile()) {
write_thintile();
tilecount_per_file++;
tilecount++;
}
fclose(outfile);
fclose(infile);
printf("%d tiles processed from %s\n", tilecount_per_file,
tilefiles[filenum]);
++filenum;
}
printf("Grand total of %d tiles processed.\n", tilecount);
exit(EXIT_SUCCESS);
/*NOTREACHED*/
return 0;
}
/*thintile.c*/
+205 -206
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 tile2bmp.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
/* NetHack 3.6 tile2bmp.c $NHDT-Date: 1431192770 2015/05/09 17:32:50 $ $NHDT-Branch: master $:$NHDT-Revision: 1.14 $ */
/* Copyright (c) NetHack PC Development Team 1995 */
/* NetHack may be freely redistributed. See license for details. */
@@ -18,53 +18,55 @@
#include "win32api.h"
#endif
#if (TILE_X==32)
#if (TILE_X == 32)
#define COLORS_IN_USE 256
#else
/*#define COLORS_IN_USE 16 */ /* 16 colors */
#define COLORS_IN_USE 256 /* 256 colors */
/*#define COLORS_IN_USE 16 */ /* 16 colors */
#define COLORS_IN_USE 256 /* 256 colors */
#endif
#define BITCOUNT 8
extern char *FDECL(tilename, (int, int));
#define MAGICTILENO (340 + 440 + 231 + 340)
#define MAGICTILENO (340 + 440 + 231 + 340)
#if BITCOUNT==4
#define MAX_X 320 /* 2 per byte, 4 bits per pixel */
#if BITCOUNT == 4
#define MAX_X 320 /* 2 per byte, 4 bits per pixel */
#define MAX_Y 480
#else
# if (TILE_X==32)
#if (TILE_X == 32)
#define MAX_X (32 * 40)
#define MAX_Y ((MAGICTILENO * 32) / 40) * 2
# else
#else
#define MAX_X (16 * 40)
#define MAX_Y ((MAGICTILENO * 16) / 40) * 2
# endif
#endif
#endif
#endif
/* GCC fix by Paolo Bonzini 1999/03/28 */
#ifdef __GNUC__
#define PACK __attribute__((packed))
#define PACK __attribute__((packed))
#else
#define PACK
#endif
#endif
static short leshort(short x)
static short
leshort(short x)
{
#ifdef __BIG_ENDIAN__
return ((x&0xff)<<8)|((x>>8)&0xff);
return ((x & 0xff) << 8) | ((x >> 8) & 0xff);
#else
return x;
#endif
}
static long lelong(long x)
static long
lelong(long x)
{
#ifdef __BIG_ENDIAN__
return ((x&0xff)<<24)|((x&0xff00)<<8)|((x>>8)&0xff00)|((x>>24)&0xff);
return ((x & 0xff) << 24) | ((x & 0xff00) << 8) | ((x >> 8) & 0xff00)
| ((x >> 24) & 0xff);
#else
return x;
#endif
@@ -72,63 +74,63 @@ static long lelong(long x)
#ifdef __GNUC__
typedef struct tagBMIH {
unsigned long biSize;
long biWidth;
long biHeight;
unsigned short biPlanes;
unsigned short biBitCount;
unsigned long biCompression;
unsigned long biSizeImage;
long biXPelsPerMeter;
long biYPelsPerMeter;
unsigned long biClrUsed;
unsigned long biClrImportant;
unsigned long biSize;
long biWidth;
long biHeight;
unsigned short biPlanes;
unsigned short biBitCount;
unsigned long biCompression;
unsigned long biSizeImage;
long biXPelsPerMeter;
long biYPelsPerMeter;
unsigned long biClrUsed;
unsigned long biClrImportant;
} PACK BITMAPINFOHEADER;
typedef struct tagBMFH {
unsigned short bfType;
unsigned long bfSize;
unsigned short bfReserved1;
unsigned short bfReserved2;
unsigned long bfOffBits;
unsigned short bfType;
unsigned long bfSize;
unsigned short bfReserved1;
unsigned short bfReserved2;
unsigned long bfOffBits;
} PACK BITMAPFILEHEADER;
typedef struct tagRGBQ {
unsigned char rgbBlue;
unsigned char rgbGreen;
unsigned char rgbRed;
unsigned char rgbReserved;
unsigned char rgbBlue;
unsigned char rgbGreen;
unsigned char rgbRed;
unsigned char rgbReserved;
} PACK RGBQUAD;
#define UINT unsigned int
#define DWORD unsigned long
#define LONG long
#define WORD unsigned short
#define BI_RGB 0L
#define BI_RLE8 1L
#define BI_RLE4 2L
#define BI_BITFIELDS 3L
#define BI_RGB 0L
#define BI_RLE8 1L
#define BI_RLE4 2L
#define BI_BITFIELDS 3L
#endif /* __GNUC__ */
#pragma pack(1)
struct tagBMP{
struct tagBMP {
BITMAPFILEHEADER bmfh;
BITMAPINFOHEADER bmih;
#if BITCOUNT==4
#if BITCOUNT == 4
#define RGBQUAD_COUNT 16
RGBQUAD bmaColors[RGBQUAD_COUNT];
RGBQUAD bmaColors[RGBQUAD_COUNT];
#else
#if (TILE_X==32)
#if (TILE_X == 32)
#define RGBQUAD_COUNT 256
#else
/*#define RGBQUAD_COUNT 16 */
#define RGBQUAD_COUNT 256
#endif
RGBQUAD bmaColors[RGBQUAD_COUNT];
RGBQUAD bmaColors[RGBQUAD_COUNT];
#endif
#if (COLORS_IN_USE==16)
uchar packtile[MAX_Y][MAX_X];
#if (COLORS_IN_USE == 16)
uchar packtile[MAX_Y][MAX_X];
#else
uchar packtile[MAX_Y][MAX_X];
uchar packtile[MAX_Y][MAX_X];
/* uchar packtile[TILE_Y][TILE_X]; */
#endif
} PACK bmp;
@@ -140,19 +142,17 @@ FILE *tibfile2;
pixel tilepixels[TILE_Y][TILE_X];
static void FDECL(build_bmfh,(BITMAPFILEHEADER *));
static void FDECL(build_bmih,(BITMAPINFOHEADER *));
static void FDECL(build_bmptile,(pixel (*)[TILE_X]));
static void FDECL(build_bmfh, (BITMAPFILEHEADER *));
static void FDECL(build_bmih, (BITMAPINFOHEADER *));
static void FDECL(build_bmptile, (pixel(*) [TILE_X]));
char *tilefiles[] = {
#if (TILE_X == 32)
"../win/share/mon32.txt",
"../win/share/obj32.txt",
"../win/share/oth32.txt",
"../win/share/mon32.txt", "../win/share/obj32.txt",
"../win/share/oth32.txt",
#else
"../win/share/monsters.txt",
"../win/share/objects.txt",
"../win/share/other.txt",
"../win/share/monsters.txt", "../win/share/objects.txt",
"../win/share/other.txt",
#endif
};
@@ -163,7 +163,7 @@ int tiles_in_row;
int filenum;
int initflag;
int pass;
int yoffset,xoffset;
int yoffset, xoffset;
char bmpname[128];
FILE *fp;
@@ -172,190 +172,189 @@ main(argc, argv)
int argc;
char *argv[];
{
int i, j;
int i, j;
if (argc != 2) {
Fprintf(stderr, "usage: %s outfile.bmp\n", argv[0]);
exit(EXIT_FAILURE);
} else
strcpy(bmpname, argv[1]);
if (argc != 2) {
Fprintf(stderr, "usage: %s outfile.bmp\n", argv[0]);
exit(EXIT_FAILURE);
} else
strcpy(bmpname, argv[1]);
#ifdef OBSOLETE
bmpfile2 = fopen(NETHACK_PACKED_TILEFILE, WRBMODE);
if (bmpfile2 == (FILE *)0) {
Fprintf(stderr, "Unable to open output file %s\n",
NETHACK_PACKED_TILEFILE);
exit(EXIT_FAILURE);
}
bmpfile2 = fopen(NETHACK_PACKED_TILEFILE, WRBMODE);
if (bmpfile2 == (FILE *) 0) {
Fprintf(stderr, "Unable to open output file %s\n",
NETHACK_PACKED_TILEFILE);
exit(EXIT_FAILURE);
}
#endif
tilecount = 0;
xoffset = yoffset = 0;
initflag = 0;
filenum = 0;
pass = 0;
fp = fopen(bmpname,"wb");
if (!fp) {
printf("Error creating tile file %s, aborting.\n",bmpname);
exit(1);
}
while (pass < 4) {
filenum =pass % (sizeof(tilefiles) / sizeof(char *));
if (!fopen_text_file(tilefiles[filenum], RDTMODE)) {
Fprintf(stderr,
"usage: tile2bmp (from the util directory)\n");
exit(EXIT_FAILURE);
}
num_colors = colorsinmap;
if (num_colors > 62) {
Fprintf(stderr, "too many colors (%d)\n", num_colors);
exit(EXIT_FAILURE);
}
if (!initflag) {
build_bmfh(&bmp.bmfh);
build_bmih(&bmp.bmih);
for (i = 0; i < MAX_Y; ++i)
for (j = 0; j < MAX_X; ++j)
bmp.packtile[i][j] = (uchar)0;
for (i = 0; i < num_colors; i++) {
bmp.bmaColors[i].rgbRed = ColorMap[CM_RED][i];
bmp.bmaColors[i].rgbGreen = ColorMap[CM_GREEN][i];
bmp.bmaColors[i].rgbBlue = ColorMap[CM_BLUE][i];
bmp.bmaColors[i].rgbReserved = 0;
}
initflag = 1;
}
/* printf("Colormap initialized\n"); */
while (read_text_tile(tilepixels)) {
build_bmptile(tilepixels);
tilecount++;
#if BITCOUNT==4
xoffset += (TILE_X / 2);
tilecount = 0;
xoffset = yoffset = 0;
initflag = 0;
filenum = 0;
pass = 0;
fp = fopen(bmpname, "wb");
if (!fp) {
printf("Error creating tile file %s, aborting.\n", bmpname);
exit(1);
}
while (pass < 4) {
filenum = pass % (sizeof(tilefiles) / sizeof(char *));
if (!fopen_text_file(tilefiles[filenum], RDTMODE)) {
Fprintf(stderr, "usage: tile2bmp (from the util directory)\n");
exit(EXIT_FAILURE);
}
num_colors = colorsinmap;
if (num_colors > 62) {
Fprintf(stderr, "too many colors (%d)\n", num_colors);
exit(EXIT_FAILURE);
}
if (!initflag) {
build_bmfh(&bmp.bmfh);
build_bmih(&bmp.bmih);
for (i = 0; i < MAX_Y; ++i)
for (j = 0; j < MAX_X; ++j)
bmp.packtile[i][j] = (uchar) 0;
for (i = 0; i < num_colors; i++) {
bmp.bmaColors[i].rgbRed = ColorMap[CM_RED][i];
bmp.bmaColors[i].rgbGreen = ColorMap[CM_GREEN][i];
bmp.bmaColors[i].rgbBlue = ColorMap[CM_BLUE][i];
bmp.bmaColors[i].rgbReserved = 0;
}
initflag = 1;
}
/* printf("Colormap initialized\n"); */
while (read_text_tile(tilepixels)) {
build_bmptile(tilepixels);
tilecount++;
#if BITCOUNT == 4
xoffset += (TILE_X / 2);
#else
xoffset += TILE_X;
xoffset += TILE_X;
#endif
if (xoffset >= MAX_X) {
yoffset += TILE_Y;
xoffset = 0;
}
}
(void) fclose_text_file();
++pass;
}
fwrite(&bmp, sizeof(bmp), 1, fp);
fclose(fp);
Fprintf(stderr, "Total of %d tiles written to %s.\n",
tilecount, bmpname);
if (xoffset >= MAX_X) {
yoffset += TILE_Y;
xoffset = 0;
}
}
(void) fclose_text_file();
++pass;
}
fwrite(&bmp, sizeof(bmp), 1, fp);
fclose(fp);
Fprintf(stderr, "Total of %d tiles written to %s.\n", tilecount, bmpname);
exit(EXIT_SUCCESS);
/*NOTREACHED*/
return 0;
exit(EXIT_SUCCESS);
/*NOTREACHED*/
return 0;
}
static void
build_bmfh(pbmfh)
BITMAPFILEHEADER *pbmfh;
{
pbmfh->bfType = leshort(0x4D42);
pbmfh->bfSize = lelong(BMPFILESIZE);
pbmfh->bfReserved1 = (UINT)0;
pbmfh->bfReserved2 = (UINT)0;
pbmfh->bfOffBits = lelong(sizeof(bmp.bmfh) + sizeof(bmp.bmih) +
(RGBQUAD_COUNT * sizeof(RGBQUAD)));
pbmfh->bfType = leshort(0x4D42);
pbmfh->bfSize = lelong(BMPFILESIZE);
pbmfh->bfReserved1 = (UINT) 0;
pbmfh->bfReserved2 = (UINT) 0;
pbmfh->bfOffBits = lelong(sizeof(bmp.bmfh) + sizeof(bmp.bmih)
+ (RGBQUAD_COUNT * sizeof(RGBQUAD)));
}
static void
build_bmih(pbmih)
BITMAPINFOHEADER *pbmih;
{
WORD cClrBits;
int w,h;
pbmih->biSize = lelong(sizeof(bmp.bmih));
#if BITCOUNT==4
pbmih->biWidth = lelong(w = MAX_X * 2);
WORD cClrBits;
int w, h;
pbmih->biSize = lelong(sizeof(bmp.bmih));
#if BITCOUNT == 4
pbmih->biWidth = lelong(w = MAX_X * 2);
#else
pbmih->biWidth = lelong(w = MAX_X);
pbmih->biWidth = lelong(w = MAX_X);
#endif
pbmih->biHeight = lelong(h = MAX_Y);
pbmih->biPlanes = leshort(1);
#if BITCOUNT==4
pbmih->biBitCount = leshort(4);
cClrBits = 4;
pbmih->biHeight = lelong(h = MAX_Y);
pbmih->biPlanes = leshort(1);
#if BITCOUNT == 4
pbmih->biBitCount = leshort(4);
cClrBits = 4;
#else
pbmih->biBitCount = leshort(8);
cClrBits = 8;
pbmih->biBitCount = leshort(8);
cClrBits = 8;
#endif
if (cClrBits == 1)
cClrBits = 1;
else if (cClrBits <= 4)
cClrBits = 4;
else if (cClrBits <= 8)
cClrBits = 8;
else if (cClrBits <= 16)
cClrBits = 16;
else if (cClrBits <= 24)
cClrBits = 24;
else cClrBits = 32;
pbmih->biCompression = lelong(BI_RGB);
pbmih->biXPelsPerMeter = lelong(0);
pbmih->biYPelsPerMeter = lelong(0);
#if (TILE_X==32)
if (cClrBits < 24)
pbmih->biClrUsed = lelong(1<<cClrBits);
if (cClrBits == 1)
cClrBits = 1;
else if (cClrBits <= 4)
cClrBits = 4;
else if (cClrBits <= 8)
cClrBits = 8;
else if (cClrBits <= 16)
cClrBits = 16;
else if (cClrBits <= 24)
cClrBits = 24;
else
cClrBits = 32;
pbmih->biCompression = lelong(BI_RGB);
pbmih->biXPelsPerMeter = lelong(0);
pbmih->biYPelsPerMeter = lelong(0);
#if (TILE_X == 32)
if (cClrBits < 24)
pbmih->biClrUsed = lelong(1 << cClrBits);
#else
pbmih->biClrUsed = lelong(RGBQUAD_COUNT);
pbmih->biClrUsed = lelong(RGBQUAD_COUNT);
#endif
#if (TILE_X==16)
/* pbmih->biSizeImage = lelong(0); */
pbmih->biSizeImage = lelong(((w * cClrBits +31) & ~31) /8 * h);
#if (TILE_X == 16)
/* pbmih->biSizeImage = lelong(0); */
pbmih->biSizeImage = lelong(((w * cClrBits + 31) & ~31) / 8 * h);
#else
pbmih->biSizeImage = lelong(((w * cClrBits +31) & ~31) /8 * h);
pbmih->biSizeImage = lelong(((w * cClrBits + 31) & ~31) / 8 * h);
#endif
pbmih->biClrImportant = (DWORD)0;
pbmih->biClrImportant = (DWORD) 0;
}
static int graymappings[] = {
/* . A B C D E F G H I J K L M N O P */
0, 1,17,18,19,20,27,22,23,24,25,26,21,15,13,14,14};
/* . A B C D E F G H I J K L M N O P */
0, 1, 17, 18, 19, 20, 27, 22, 23, 24, 25, 26, 21, 15, 13, 14, 14
};
static void
build_bmptile(pixels)
pixel (*pixels)[TILE_X];
{
int cur_x, cur_y, cur_color, apply_color;
int x,y;
int cur_x, cur_y, cur_color, apply_color;
int x, y;
for (cur_y = 0; cur_y < TILE_Y; cur_y++) {
for (cur_x = 0; cur_x < TILE_X; cur_x++) {
for (cur_color = 0; cur_color < num_colors; cur_color++) {
if (ColorMap[CM_RED][cur_color] == pixels[cur_y][cur_x].r &&
ColorMap[CM_GREEN][cur_color]== pixels[cur_y][cur_x].g &&
ColorMap[CM_BLUE][cur_color] == pixels[cur_y][cur_x].b)
break;
}
if (cur_color >= num_colors)
Fprintf(stderr, "color not in colormap!\n");
y = (MAX_Y - 1) - (cur_y + yoffset);
apply_color = cur_color;
if (pass == 3) {
/* map to shades of gray */
if (cur_color > (SIZE(graymappings)-1))
Fprintf(stderr, "Gray mapping issue %d %d.\n",
cur_color, SIZE(graymappings)-1);
else
apply_color = graymappings[cur_color];
}
#if BITCOUNT==4
x = (cur_x / 2) + xoffset;
bmp.packtile[y][x] = cur_x%2 ?
(uchar)(bmp.packtile[y][x] | cur_color) :
(uchar)(cur_color<<4);
for (cur_y = 0; cur_y < TILE_Y; cur_y++) {
for (cur_x = 0; cur_x < TILE_X; cur_x++) {
for (cur_color = 0; cur_color < num_colors; cur_color++) {
if (ColorMap[CM_RED][cur_color] == pixels[cur_y][cur_x].r
&& ColorMap[CM_GREEN][cur_color] == pixels[cur_y][cur_x].g
&& ColorMap[CM_BLUE][cur_color] == pixels[cur_y][cur_x].b)
break;
}
if (cur_color >= num_colors)
Fprintf(stderr, "color not in colormap!\n");
y = (MAX_Y - 1) - (cur_y + yoffset);
apply_color = cur_color;
if (pass == 3) {
/* map to shades of gray */
if (cur_color > (SIZE(graymappings) - 1))
Fprintf(stderr, "Gray mapping issue %d %d.\n", cur_color,
SIZE(graymappings) - 1);
else
apply_color = graymappings[cur_color];
}
#if BITCOUNT == 4
x = (cur_x / 2) + xoffset;
bmp.packtile[y][x] = cur_x % 2
? (uchar)(bmp.packtile[y][x] | cur_color)
: (uchar)(cur_color << 4);
#else
x = cur_x + xoffset;
bmp.packtile[y][x] = (uchar)apply_color;
x = cur_x + xoffset;
bmp.packtile[y][x] = (uchar) apply_color;
#endif
}
}
}
}
}
+343 -361
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 tilemap.c $NHDT-Date: 1431183539 2015/05/09 14:58:59 $ $NHDT-Branch: master $:$NHDT-Revision: 1.22 $ */
/* NetHack 3.6 tilemap.c $NHDT-Date: 1431192771 2015/05/09 17:32:51 $ $NHDT-Branch: master $:$NHDT-Revision: 1.23 $ */
/* SCCS Id: @(#)tilemap.c 3.5 2000/06/04 */
/* NetHack may be freely redistributed. See license for details. */
@@ -10,7 +10,7 @@
#include "hack.h"
const char * FDECL(tilename, (int, int));
const char *FDECL(tilename, (int, int));
void NDECL(init_tilemap);
void FDECL(process_substitutions, (FILE *));
@@ -27,50 +27,49 @@ extern void FDECL(exit, (int));
#define MON_GLYPH 1
#define OBJ_GLYPH 2
#define OTH_GLYPH 3 /* fortunately unnecessary */
#define OTH_GLYPH 3 /* fortunately unnecessary */
/* note that the ifdefs here should be the opposite sense from monst.c/
* objects.c/rm.h
*/
struct conditionals {
int sequence, predecessor;
const char *name;
int sequence, predecessor;
const char *name;
} conditionals[] = {
#ifndef CHARON /* not supported yet */
{ MON_GLYPH, PM_HELL_HOUND, "Cerberus" },
{ MON_GLYPH, PM_HELL_HOUND, "Cerberus" },
#endif
/* commented out in monst.c at present */
{ MON_GLYPH, PM_SHOCKING_SPHERE, "beholder" },
{ MON_GLYPH, PM_BABY_SILVER_DRAGON, "baby shimmering dragon" },
{ MON_GLYPH, PM_SILVER_DRAGON, "shimmering dragon" },
{ MON_GLYPH, PM_JABBERWOCK, "vorpal jabberwock" },
{ MON_GLYPH, PM_VAMPIRE_LORD, "vampire mage" },
/* commented out in monst.c at present */
{ MON_GLYPH, PM_SHOCKING_SPHERE, "beholder" },
{ MON_GLYPH, PM_BABY_SILVER_DRAGON, "baby shimmering dragon" },
{ MON_GLYPH, PM_SILVER_DRAGON, "shimmering dragon" },
{ MON_GLYPH, PM_JABBERWOCK, "vorpal jabberwock" },
{ MON_GLYPH, PM_VAMPIRE_LORD, "vampire mage" },
#ifndef CHARON /* not supported yet */
{ MON_GLYPH, PM_CROESUS, "Charon" },
{ MON_GLYPH, PM_CROESUS, "Charon" },
#endif
#ifndef MAIL
{ MON_GLYPH, PM_FAMINE, "mail daemon" },
{ MON_GLYPH, PM_FAMINE, "mail daemon" },
#endif
/* commented out in monst.c at present */
{ MON_GLYPH, PM_SHAMAN_KARNOV, "Earendil" },
{ MON_GLYPH, PM_SHAMAN_KARNOV, "Elwing" },
/* commented out in monst.c at present */
{ MON_GLYPH, PM_CHROMATIC_DRAGON, "Goblin King" },
{ MON_GLYPH, PM_NEANDERTHAL, "High-elf" },
/* objects commented out in objects.c at present */
{ OBJ_GLYPH, SILVER_DRAGON_SCALE_MAIL, "shimmering dragon scale mail" },
{ OBJ_GLYPH, SILVER_DRAGON_SCALES, "shimmering dragon scales" },
/* allow slime mold to look like slice of pizza, since we
* don't know what a slime mold should look like when renamed anyway
*/
/* commented out in monst.c at present */
{ MON_GLYPH, PM_SHAMAN_KARNOV, "Earendil" },
{ MON_GLYPH, PM_SHAMAN_KARNOV, "Elwing" },
/* commented out in monst.c at present */
{ MON_GLYPH, PM_CHROMATIC_DRAGON, "Goblin King" },
{ MON_GLYPH, PM_NEANDERTHAL, "High-elf" },
/* objects commented out in objects.c at present */
{ OBJ_GLYPH, SILVER_DRAGON_SCALE_MAIL, "shimmering dragon scale mail" },
{ OBJ_GLYPH, SILVER_DRAGON_SCALES, "shimmering dragon scales" },
/* allow slime mold to look like slice of pizza, since we
* don't know what a slime mold should look like when renamed anyway
*/
#ifndef MAIL
{ OBJ_GLYPH, SCR_STINKING_CLOUD+4, "stamped / mail" },
{ OBJ_GLYPH, SCR_STINKING_CLOUD + 4, "stamped / mail" },
#endif
{ 0, 0, 0}
{ 0, 0, 0 }
};
/*
* Some entries in glyph2tile[] should be substituted for on various levels.
* The tiles used for the substitute entries will follow the usual ones in
@@ -80,20 +79,17 @@ struct conditionals {
* overlap in the future.
*/
struct substitute {
int first_glyph, last_glyph;
const char *sub_name; /* for explanations */
const char *level_test;
} substitutes[] = {
{ GLYPH_CMAP_OFF + S_vwall, GLYPH_CMAP_OFF + S_trwall,
"mine walls", "In_mines(plev)" },
{ GLYPH_CMAP_OFF + S_vwall, GLYPH_CMAP_OFF + S_trwall,
"gehennom walls", "In_hell(plev)" },
{ GLYPH_CMAP_OFF + S_vwall, GLYPH_CMAP_OFF + S_trwall,
"knox walls", "Is_knox(plev)" },
{ GLYPH_CMAP_OFF + S_vwall, GLYPH_CMAP_OFF + S_trwall,
"sokoban walls", "In_sokoban(plev)" }
};
int first_glyph, last_glyph;
const char *sub_name; /* for explanations */
const char *level_test;
} substitutes[] = { { GLYPH_CMAP_OFF + S_vwall, GLYPH_CMAP_OFF + S_trwall,
"mine walls", "In_mines(plev)" },
{ GLYPH_CMAP_OFF + S_vwall, GLYPH_CMAP_OFF + S_trwall,
"gehennom walls", "In_hell(plev)" },
{ GLYPH_CMAP_OFF + S_vwall, GLYPH_CMAP_OFF + S_trwall,
"knox walls", "Is_knox(plev)" },
{ GLYPH_CMAP_OFF + S_vwall, GLYPH_CMAP_OFF + S_trwall,
"sokoban walls", "In_sokoban(plev)" } };
#ifdef TILETEXT
@@ -104,140 +100,139 @@ const char *
tilename(set, entry)
int set, entry;
{
int i, j, condnum, tilenum;
static char buf[BUFSZ];
int i, j, condnum, tilenum;
static char buf[BUFSZ];
/* Note: these initializers don't do anything except guarantee that
we're linked properly.
*/
monst_init();
objects_init();
(void) def_char_to_objclass(']');
/* Note: these initializers don't do anything except guarantee that
we're linked properly.
*/
monst_init();
objects_init();
(void) def_char_to_objclass(']');
condnum = tilenum = 0;
condnum = tilenum = 0;
for (i = 0; i < NUMMONS; i++) {
if (set == MON_GLYPH && tilenum == entry)
return mons[i].mname;
tilenum++;
while (conditionals[condnum].sequence == MON_GLYPH &&
conditionals[condnum].predecessor == i) {
if (set == MON_GLYPH && tilenum == entry)
return conditionals[condnum].name;
condnum++;
tilenum++;
}
}
if (set == MON_GLYPH && tilenum == entry)
return "invisible monster";
for (i = 0; i < NUMMONS; i++) {
if (set == MON_GLYPH && tilenum == entry)
return mons[i].mname;
tilenum++;
while (conditionals[condnum].sequence == MON_GLYPH
&& conditionals[condnum].predecessor == i) {
if (set == MON_GLYPH && tilenum == entry)
return conditionals[condnum].name;
condnum++;
tilenum++;
}
}
if (set == MON_GLYPH && tilenum == entry)
return "invisible monster";
tilenum = 0; /* set-relative number */
for (i = 0; i < NUM_OBJECTS; i++) {
/* prefer to give the description - that's all the tile's
* appearance should reveal */
if (set == OBJ_GLYPH && tilenum == entry) {
if ( !obj_descr[i].oc_descr )
return obj_descr[i].oc_name;
if ( !obj_descr[i].oc_name )
return obj_descr[i].oc_descr;
tilenum = 0; /* set-relative number */
for (i = 0; i < NUM_OBJECTS; i++) {
/* prefer to give the description - that's all the tile's
* appearance should reveal */
if (set == OBJ_GLYPH && tilenum == entry) {
if (!obj_descr[i].oc_descr)
return obj_descr[i].oc_name;
if (!obj_descr[i].oc_name)
return obj_descr[i].oc_descr;
Sprintf(buf, "%s / %s",
obj_descr[i].oc_descr,
obj_descr[i].oc_name);
return buf;
}
Sprintf(buf, "%s / %s", obj_descr[i].oc_descr,
obj_descr[i].oc_name);
return buf;
}
tilenum++;
while (conditionals[condnum].sequence == OBJ_GLYPH &&
conditionals[condnum].predecessor == i) {
if (set == OBJ_GLYPH && tilenum == entry)
return conditionals[condnum].name;
condnum++;
tilenum++;
}
}
tilenum++;
while (conditionals[condnum].sequence == OBJ_GLYPH
&& conditionals[condnum].predecessor == i) {
if (set == OBJ_GLYPH && tilenum == entry)
return conditionals[condnum].name;
condnum++;
tilenum++;
}
}
tilenum = 0; /* set-relative number */
for (i = 0; i < (MAXPCHARS - MAXEXPCHARS); i++) {
if (set == OTH_GLYPH && tilenum == entry) {
if (*defsyms[i].explanation) {
return defsyms[i].explanation;
tilenum = 0; /* set-relative number */
for (i = 0; i < (MAXPCHARS - MAXEXPCHARS); i++) {
if (set == OTH_GLYPH && tilenum == entry) {
if (*defsyms[i].explanation) {
return defsyms[i].explanation;
} else {
Sprintf(buf, "cmap %d", tilenum);
return buf;
}
}
tilenum++;
while (conditionals[condnum].sequence == OTH_GLYPH &&
conditionals[condnum].predecessor == i) {
if (set == OTH_GLYPH && tilenum == entry)
return conditionals[condnum].name;
condnum++;
tilenum++;
}
}
/* explosions */
tilenum = MAXPCHARS - MAXEXPCHARS;
i = entry - tilenum;
if (i < (MAXEXPCHARS * EXPL_MAX)) {
if (set == OTH_GLYPH) {
static const char *explosion_types[] = { /* hack.h */
"dark", "noxious", "muddy", "wet",
"magical", "fiery", "frosty"
};
Sprintf(buf, "explosion %s %d",
explosion_types[i / MAXEXPCHARS], i % MAXEXPCHARS);
return buf;
}
}
tilenum += (MAXEXPCHARS * EXPL_MAX);
return buf;
}
}
tilenum++;
while (conditionals[condnum].sequence == OTH_GLYPH
&& conditionals[condnum].predecessor == i) {
if (set == OTH_GLYPH && tilenum == entry)
return conditionals[condnum].name;
condnum++;
tilenum++;
}
}
/* explosions */
tilenum = MAXPCHARS - MAXEXPCHARS;
i = entry - tilenum;
if (i < (MAXEXPCHARS * EXPL_MAX)) {
if (set == OTH_GLYPH) {
static const char *explosion_types[] = {
/* hack.h */
"dark", "noxious", "muddy", "wet", "magical", "fiery",
"frosty"
};
Sprintf(buf, "explosion %s %d", explosion_types[i / MAXEXPCHARS],
i % MAXEXPCHARS);
return buf;
}
}
tilenum += (MAXEXPCHARS * EXPL_MAX);
i = entry - tilenum;
if (i < (NUM_ZAP << 2)) {
if (set == OTH_GLYPH) {
Sprintf(buf, "zap %d %d", i/4, i%4);
return buf;
}
}
tilenum += (NUM_ZAP << 2);
i = entry - tilenum;
if (i < (NUM_ZAP << 2)) {
if (set == OTH_GLYPH) {
Sprintf(buf, "zap %d %d", i / 4, i % 4);
return buf;
}
}
tilenum += (NUM_ZAP << 2);
i = entry - tilenum;
if (i < WARNCOUNT) {
if (set == OTH_GLYPH) {
Sprintf(buf, "warning %d", i);
return buf;
}
}
tilenum += WARNCOUNT;
i = entry - tilenum;
if (i < WARNCOUNT) {
if (set == OTH_GLYPH) {
Sprintf(buf, "warning %d", i);
return buf;
}
}
tilenum += WARNCOUNT;
for (i = 0; i < SIZE(substitutes); i++) {
j = entry - tilenum;
if (j <= substitutes[i].last_glyph - substitutes[i].first_glyph) {
if (set == OTH_GLYPH) {
Sprintf(buf, "sub %s %d", substitutes[i].sub_name, j);
return buf;
}
}
tilenum += substitutes[i].last_glyph
- substitutes[i].first_glyph + 1;
}
for (i = 0; i < SIZE(substitutes); i++) {
j = entry - tilenum;
if (j <= substitutes[i].last_glyph - substitutes[i].first_glyph) {
if (set == OTH_GLYPH) {
Sprintf(buf, "sub %s %d", substitutes[i].sub_name, j);
return buf;
}
}
tilenum += substitutes[i].last_glyph - substitutes[i].first_glyph + 1;
}
Sprintf(buf, "unknown %d %d", set, entry);
return buf;
Sprintf(buf, "unknown %d %d", set, entry);
return buf;
}
#else /* TILETEXT */
#else /* TILETEXT */
#define TILE_FILE "tile.c"
#define TILE_FILE "tile.c"
#ifdef AMIGA
# define SOURCE_TEMPLATE "NH:src/%s"
#define SOURCE_TEMPLATE "NH:src/%s"
#else
# ifdef MAC
# define SOURCE_TEMPLATE ":src:%s"
# else
# define SOURCE_TEMPLATE "../src/%s"
# endif
#ifdef MAC
#define SOURCE_TEMPLATE ":src:%s"
#else
#define SOURCE_TEMPLATE "../src/%s"
#endif
#endif
short tilemap[MAX_GLYPH];
@@ -264,229 +259,215 @@ int lastmontile, lastobjtile, lastothtile;
void
init_tilemap()
{
int i, j, condnum, tilenum;
int corpsetile, swallowbase;
int i, j, condnum, tilenum;
int corpsetile, swallowbase;
for (i = 0; i < MAX_GLYPH; i++) {
tilemap[i] = -1;
}
for (i = 0; i < MAX_GLYPH; i++) {
tilemap[i] = -1;
}
corpsetile = NUMMONS + NUM_INVIS_TILES + CORPSE;
swallowbase= NUMMONS + NUM_INVIS_TILES + NUM_OBJECTS + S_sw_tl;
corpsetile = NUMMONS + NUM_INVIS_TILES + CORPSE;
swallowbase = NUMMONS + NUM_INVIS_TILES + NUM_OBJECTS + S_sw_tl;
/* add number compiled out */
for (i = 0; conditionals[i].sequence; i++) {
switch (conditionals[i].sequence) {
case MON_GLYPH:
corpsetile++;
swallowbase++;
break;
case OBJ_GLYPH:
if (conditionals[i].predecessor < CORPSE)
corpsetile++;
swallowbase++;
break;
case OTH_GLYPH:
if (conditionals[i].predecessor < S_sw_tl)
swallowbase++;
break;
}
}
/* add number compiled out */
for (i = 0; conditionals[i].sequence; i++) {
switch (conditionals[i].sequence) {
case MON_GLYPH:
corpsetile++;
swallowbase++;
break;
case OBJ_GLYPH:
if (conditionals[i].predecessor < CORPSE)
corpsetile++;
swallowbase++;
break;
case OTH_GLYPH:
if (conditionals[i].predecessor < S_sw_tl)
swallowbase++;
break;
}
}
condnum = tilenum = 0;
for (i = 0; i < NUMMONS; i++) {
tilemap[GLYPH_MON_OFF+i] = tilenum;
tilemap[GLYPH_PET_OFF+i] = tilenum;
tilemap[GLYPH_DETECT_OFF+i] = tilenum;
tilemap[GLYPH_RIDDEN_OFF+i] = tilenum;
tilemap[GLYPH_BODY_OFF+i] = corpsetile;
j = GLYPH_SWALLOW_OFF + 8*i;
tilemap[j] = swallowbase;
tilemap[j+1] = swallowbase+1;
tilemap[j+2] = swallowbase+2;
tilemap[j+3] = swallowbase+3;
tilemap[j+4] = swallowbase+4;
tilemap[j+5] = swallowbase+5;
tilemap[j+6] = swallowbase+6;
tilemap[j+7] = swallowbase+7;
tilenum++;
while (conditionals[condnum].sequence == MON_GLYPH &&
conditionals[condnum].predecessor == i) {
condnum++;
tilenum++;
}
}
tilemap[GLYPH_INVISIBLE] = tilenum++;
lastmontile = tilenum - 1;
condnum = tilenum = 0;
for (i = 0; i < NUMMONS; i++) {
tilemap[GLYPH_MON_OFF + i] = tilenum;
tilemap[GLYPH_PET_OFF + i] = tilenum;
tilemap[GLYPH_DETECT_OFF + i] = tilenum;
tilemap[GLYPH_RIDDEN_OFF + i] = tilenum;
tilemap[GLYPH_BODY_OFF + i] = corpsetile;
j = GLYPH_SWALLOW_OFF + 8 * i;
tilemap[j] = swallowbase;
tilemap[j + 1] = swallowbase + 1;
tilemap[j + 2] = swallowbase + 2;
tilemap[j + 3] = swallowbase + 3;
tilemap[j + 4] = swallowbase + 4;
tilemap[j + 5] = swallowbase + 5;
tilemap[j + 6] = swallowbase + 6;
tilemap[j + 7] = swallowbase + 7;
tilenum++;
while (conditionals[condnum].sequence == MON_GLYPH
&& conditionals[condnum].predecessor == i) {
condnum++;
tilenum++;
}
}
tilemap[GLYPH_INVISIBLE] = tilenum++;
lastmontile = tilenum - 1;
for (i = 0; i < NUM_OBJECTS; i++) {
tilemap[GLYPH_OBJ_OFF+i] = tilenum;
tilenum++;
while (conditionals[condnum].sequence == OBJ_GLYPH &&
conditionals[condnum].predecessor == i) {
condnum++;
tilenum++;
}
}
lastobjtile = tilenum - 1;
for (i = 0; i < NUM_OBJECTS; i++) {
tilemap[GLYPH_OBJ_OFF + i] = tilenum;
tilenum++;
while (conditionals[condnum].sequence == OBJ_GLYPH
&& conditionals[condnum].predecessor == i) {
condnum++;
tilenum++;
}
}
lastobjtile = tilenum - 1;
for (i = 0; i < (MAXPCHARS - MAXEXPCHARS); i++) {
tilemap[GLYPH_CMAP_OFF+i] = tilenum;
tilenum++;
while (conditionals[condnum].sequence == OTH_GLYPH &&
conditionals[condnum].predecessor == i) {
condnum++;
tilenum++;
}
}
for (i = 0; i < (MAXPCHARS - MAXEXPCHARS); i++) {
tilemap[GLYPH_CMAP_OFF + i] = tilenum;
tilenum++;
while (conditionals[condnum].sequence == OTH_GLYPH
&& conditionals[condnum].predecessor == i) {
condnum++;
tilenum++;
}
}
for (i = 0; i < (MAXEXPCHARS * EXPL_MAX); i++) {
tilemap[GLYPH_EXPLODE_OFF+i] = tilenum;
tilenum++;
while (conditionals[condnum].sequence == OTH_GLYPH &&
conditionals[condnum].predecessor == (i + MAXPCHARS)) {
condnum++;
tilenum++;
}
}
for (i = 0; i < (MAXEXPCHARS * EXPL_MAX); i++) {
tilemap[GLYPH_EXPLODE_OFF + i] = tilenum;
tilenum++;
while (conditionals[condnum].sequence == OTH_GLYPH
&& conditionals[condnum].predecessor == (i + MAXPCHARS)) {
condnum++;
tilenum++;
}
}
for (i = 0; i < NUM_ZAP << 2; i++) {
tilemap[GLYPH_ZAP_OFF+i] = tilenum;
tilenum++;
while (conditionals[condnum].sequence == OTH_GLYPH &&
conditionals[condnum].predecessor == (i + MAXEXPCHARS)) {
condnum++;
tilenum++;
}
}
for (i = 0; i < NUM_ZAP << 2; i++) {
tilemap[GLYPH_ZAP_OFF + i] = tilenum;
tilenum++;
while (conditionals[condnum].sequence == OTH_GLYPH
&& conditionals[condnum].predecessor == (i + MAXEXPCHARS)) {
condnum++;
tilenum++;
}
}
for (i = 0; i < WARNCOUNT; i++) {
tilemap[GLYPH_WARNING_OFF+i] = tilenum;
tilenum++;
}
for (i = 0; i < WARNCOUNT; i++) {
tilemap[GLYPH_WARNING_OFF + i] = tilenum;
tilenum++;
}
#ifndef STATUES_LOOK_LIKE_MONSTERS
/* statue patch: statues still use the same glyph as in vanilla */
for ( i = 0; i < NUMMONS; i++) {
tilemap[GLYPH_STATUE_OFF+i] = tilemap[GLYPH_OBJ_OFF+STATUE];
}
/* statue patch: statues still use the same glyph as in vanilla */
for (i = 0; i < NUMMONS; i++) {
tilemap[GLYPH_STATUE_OFF + i] = tilemap[GLYPH_OBJ_OFF + STATUE];
}
#endif
lastothtile = tilenum - 1;
lastothtile = tilenum - 1;
#ifdef STATUES_LOOK_LIKE_MONSTERS
/* skip over the substitutes to get to the grayscale statues */
for (i = 0; i < SIZE(substitutes); i++) {
tilenum += substitutes[i].last_glyph - substitutes[i].first_glyph + 1;
}
/* skip over the substitutes to get to the grayscale statues */
for (i = 0; i < SIZE(substitutes); i++) {
tilenum += substitutes[i].last_glyph - substitutes[i].first_glyph + 1;
}
/* statue patch: statues look more like the monster */
condnum = 0; /* doing monsters again, so reset */
for (i = 0; i < NUMMONS; i++) {
tilemap[GLYPH_STATUE_OFF+i] = tilenum;
tilenum++;
while (conditionals[condnum].sequence == MON_GLYPH &&
conditionals[condnum].predecessor == i) {
condnum++;
tilenum++;
}
}
laststatuetile = tilenum - 1;
/* statue patch: statues look more like the monster */
condnum = 0; /* doing monsters again, so reset */
for (i = 0; i < NUMMONS; i++) {
tilemap[GLYPH_STATUE_OFF + i] = tilenum;
tilenum++;
while (conditionals[condnum].sequence == MON_GLYPH
&& conditionals[condnum].predecessor == i) {
condnum++;
tilenum++;
}
}
laststatuetile = tilenum - 1;
#endif
}
const char *prolog[] = {
"",
"",
"void",
"substitute_tiles(plev)",
"d_level *plev;",
"{",
"\tint i;",
""
};
const char *prolog[] = { "", "", "void", "substitute_tiles(plev)",
"d_level *plev;", "{", "\tint i;", "" };
const char *epilog[] = {
"}"
};
const char *epilog[] = { "}" };
/* write out the substitutions in an easily-used form. */
void
process_substitutions(ofp)
FILE *ofp;
{
int i, j, k, span, start;
int i, j, k, span, start;
fprintf(ofp, "\n\n");
fprintf(ofp, "\n\n");
j = 0; /* unnecessary */
span = -1;
for (i = 0; i < SIZE(substitutes); i++) {
if (i == 0
|| substitutes[i].first_glyph != substitutes[j].first_glyph
|| substitutes[i].last_glyph != substitutes[j].last_glyph) {
j = i;
span++;
fprintf(ofp, "short std_tiles%d[] = { ", span);
for (k = substitutes[i].first_glyph;
k < substitutes[i].last_glyph; k++)
fprintf(ofp, "%d, ", tilemap[k]);
fprintf(ofp, "%d };\n",
tilemap[substitutes[i].last_glyph]);
}
}
j = 0; /* unnecessary */
span = -1;
for (i = 0; i < SIZE(substitutes); i++) {
if (i == 0 || substitutes[i].first_glyph != substitutes[j].first_glyph
|| substitutes[i].last_glyph != substitutes[j].last_glyph) {
j = i;
span++;
fprintf(ofp, "short std_tiles%d[] = { ", span);
for (k = substitutes[i].first_glyph;
k < substitutes[i].last_glyph; k++)
fprintf(ofp, "%d, ", tilemap[k]);
fprintf(ofp, "%d };\n", tilemap[substitutes[i].last_glyph]);
}
}
for (i = 0; i < SIZE(prolog); i++) {
fprintf(ofp, "%s\n", prolog[i]);
}
j = -1;
span = -1;
start = lastothtile + 1;
for (i = 0; i < SIZE(substitutes); i++) {
if (i == 0
|| substitutes[i].first_glyph != substitutes[j].first_glyph
|| substitutes[i].last_glyph != substitutes[j].last_glyph) {
if (i != 0) { /* finish previous span */
fprintf(ofp, "\t} else {\n");
fprintf(ofp, "\t\tfor (i = %d; i <= %d; i++)\n",
substitutes[j].first_glyph,
substitutes[j].last_glyph);
fprintf(ofp, "\t\t\tglyph2tile[i] = std_tiles%d[i - %d];\n",
span, substitutes[j].first_glyph);
fprintf(ofp, "\t}\n\n");
}
j = i;
span++;
}
if (i != j) fprintf(ofp, "\t} else ");
fprintf(ofp, "\tif (%s) {\n", substitutes[i].level_test);
fprintf(ofp, "\t\tfor (i = %d; i <= %d; i++)\n",
substitutes[i].first_glyph,
substitutes[i].last_glyph);
fprintf(ofp, "\t\t\tglyph2tile[i] = %d + i - %d;\n",
start, substitutes[i].first_glyph);
start += substitutes[i].last_glyph - substitutes[i].first_glyph + 1;
}
/* finish last span */
fprintf(ofp, "\t} else {\n");
fprintf(ofp, "\t\tfor (i = %d; i <= %d; i++)\n",
substitutes[j].first_glyph,
substitutes[j].last_glyph);
fprintf(ofp, "\t\t\tglyph2tile[i] = std_tiles%d[i - %d];\n",
span, substitutes[j].first_glyph);
fprintf(ofp, "\t}\n\n");
for (i = 0; i < SIZE(prolog); i++) {
fprintf(ofp, "%s\n", prolog[i]);
}
j = -1;
span = -1;
start = lastothtile + 1;
for (i = 0; i < SIZE(substitutes); i++) {
if (i == 0 || substitutes[i].first_glyph != substitutes[j].first_glyph
|| substitutes[i].last_glyph != substitutes[j].last_glyph) {
if (i != 0) { /* finish previous span */
fprintf(ofp, "\t} else {\n");
fprintf(ofp, "\t\tfor (i = %d; i <= %d; i++)\n",
substitutes[j].first_glyph,
substitutes[j].last_glyph);
fprintf(ofp, "\t\t\tglyph2tile[i] = std_tiles%d[i - %d];\n",
span, substitutes[j].first_glyph);
fprintf(ofp, "\t}\n\n");
}
j = i;
span++;
}
if (i != j)
fprintf(ofp, "\t} else ");
fprintf(ofp, "\tif (%s) {\n", substitutes[i].level_test);
fprintf(ofp, "\t\tfor (i = %d; i <= %d; i++)\n",
substitutes[i].first_glyph, substitutes[i].last_glyph);
fprintf(ofp, "\t\t\tglyph2tile[i] = %d + i - %d;\n", start,
substitutes[i].first_glyph);
start += substitutes[i].last_glyph - substitutes[i].first_glyph + 1;
}
/* finish last span */
fprintf(ofp, "\t} else {\n");
fprintf(ofp, "\t\tfor (i = %d; i <= %d; i++)\n",
substitutes[j].first_glyph, substitutes[j].last_glyph);
fprintf(ofp, "\t\t\tglyph2tile[i] = std_tiles%d[i - %d];\n", span,
substitutes[j].first_glyph);
fprintf(ofp, "\t}\n\n");
for (i = 0; i < SIZE(epilog); i++) {
fprintf(ofp, "%s\n", epilog[i]);
}
for (i = 0; i < SIZE(epilog); i++) {
fprintf(ofp, "%s\n", epilog[i]);
}
fprintf(ofp, "\nint total_tiles_used = %d;\n", start);
lastothtile = start - 1;
fprintf(ofp, "\nint total_tiles_used = %d;\n", start);
lastothtile = start - 1;
}
int main()
int
main()
{
register int i;
char filename[30];
@@ -499,25 +480,26 @@ int main()
*/
Sprintf(filename, SOURCE_TEMPLATE, TILE_FILE);
if (!(ofp = fopen(filename, "w"))) {
perror(filename);
exit(EXIT_FAILURE);
perror(filename);
exit(EXIT_FAILURE);
}
fprintf(ofp,"/* This file is automatically generated. Do not edit. */\n");
fprintf(ofp,"\n#include \"hack.h\"\n\n");
fprintf(ofp,"short glyph2tile[MAX_GLYPH] = {\n");
fprintf(ofp,
"/* This file is automatically generated. Do not edit. */\n");
fprintf(ofp, "\n#include \"hack.h\"\n\n");
fprintf(ofp, "short glyph2tile[MAX_GLYPH] = {\n");
for (i = 0; i < MAX_GLYPH; i++) {
fprintf(ofp,"%2d,%c", tilemap[i], (i % 12) ? ' ' : '\n');
fprintf(ofp, "%2d,%c", tilemap[i], (i % 12) ? ' ' : '\n');
}
fprintf(ofp,"%s};\n", (i % 12) ? "\n" : "");
fprintf(ofp, "%s};\n", (i % 12) ? "\n" : "");
process_substitutions(ofp);
fprintf(ofp,"\n#define MAXMONTILE %d\n", lastmontile);
fprintf(ofp,"#define MAXOBJTILE %d\n", lastobjtile);
fprintf(ofp,"#define MAXOTHTILE %d\n", lastothtile);
fprintf(ofp, "\n#define MAXMONTILE %d\n", lastmontile);
fprintf(ofp, "#define MAXOBJTILE %d\n", lastobjtile);
fprintf(ofp, "#define MAXOTHTILE %d\n", lastothtile);
fprintf(ofp,"\n/*tile.c*/\n");
fprintf(ofp, "\n/*tile.c*/\n");
fclose(ofp);
exit(EXIT_SUCCESS);
@@ -525,4 +507,4 @@ int main()
return 0;
}
#endif /* TILETEXT */
#endif /* TILETEXT */
+224 -221
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 tiletext.c $NHDT-Date: 1430640200 2015/05/03 08:03:20 $ $NHDT-Branch: master $:$NHDT-Revision: 1.7 $ */
/* NetHack 3.6 tiletext.c $NHDT-Date: 1431192770 2015/05/09 17:32:50 $ $NHDT-Branch: master $:$NHDT-Revision: 1.10 $ */
/* NetHack 3.6 tiletext.c $Date: 2009/05/06 10:59:03 $ $Revision: 1.4 $ */
/* SCCS Id: @(#)tiletext.c 3.5 1999/10/24 */
/* NetHack may be freely redistributed. See license for details. */
@@ -19,41 +19,44 @@ static int placeholder_init = 0;
static pixel placeholder[TILE_Y][TILE_X];
static FILE *tile_file;
static int tile_set, tile_set_indx;
#if (TILE_X==8)
static const char *text_sets[] = { "monthin.txt", "objthin.txt", "oththin.txt" };
#if (TILE_X == 8)
static const char *text_sets[] = { "monthin.txt", "objthin.txt",
"oththin.txt" };
#else
static const char *text_sets[] = { "monsters.txt", "objects.txt", "other.txt" };
static const char *text_sets[] = { "monsters.txt", "objects.txt",
"other.txt" };
#endif
extern const char *FDECL(tilename, (int, int));
static void FDECL(read_text_colormap, (FILE *));
static boolean FDECL(write_text_colormap, (FILE *));
static boolean FDECL(read_txttile, (FILE *, pixel(*)[TILE_X]));
static void FDECL(write_txttile, (FILE *, pixel(*)[TILE_X]));
static boolean FDECL(read_txttile, (FILE *, pixel (*)[TILE_X]));
static void FDECL(write_txttile, (FILE *, pixel (*)[TILE_X]));
/* Ugh. DICE doesn't like %[A-Z], so we have to spell it out... */
#define FORMAT_STRING \
"%[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.] = (%d, %d, %d) "
#define FORMAT_STRING \
"%[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.] = " \
"(%d, %d, %d) "
static void
read_text_colormap(txtfile)
FILE *txtfile;
{
int i, r, g, b;
char c[2];
int i, r, g, b;
char c[2];
for (i = 0; i < MAXCOLORMAPSIZE; i++)
color_index[i] = -1;
for (i = 0; i < MAXCOLORMAPSIZE; i++)
color_index[i] = -1;
num_colors = 0;
while (fscanf(txtfile, FORMAT_STRING, c, &r, &g, &b) == 4) {
color_index[(int) c[0]] = num_colors;
ColorMap[CM_RED][num_colors] = r;
ColorMap[CM_GREEN][num_colors] = g;
ColorMap[CM_BLUE][num_colors] = b;
num_colors++;
}
colorsinmap = num_colors;
num_colors = 0;
while (fscanf(txtfile, FORMAT_STRING, c, &r, &g, &b) == 4) {
color_index[(int) c[0]] = num_colors;
ColorMap[CM_RED][num_colors] = r;
ColorMap[CM_GREEN][num_colors] = g;
ColorMap[CM_BLUE][num_colors] = b;
num_colors++;
}
colorsinmap = num_colors;
}
#undef FORMAT_STRING
@@ -62,26 +65,28 @@ static boolean
write_text_colormap(txtfile)
FILE *txtfile;
{
int i;
char c;
int i;
char c;
num_colors = colorsinmainmap;
if (num_colors > 62) {
Fprintf(stderr, "too many colors (%d)\n", num_colors);
return FALSE;
}
for (i = 0; i < num_colors; i++) {
if (i < 26) c = 'A' + i;
else if (i < 52) c = 'a' + i - 26;
else c = '0' + i - 52;
num_colors = colorsinmainmap;
if (num_colors > 62) {
Fprintf(stderr, "too many colors (%d)\n", num_colors);
return FALSE;
}
for (i = 0; i < num_colors; i++) {
if (i < 26)
c = 'A' + i;
else if (i < 52)
c = 'a' + i - 26;
else
c = '0' + i - 52;
charcolors[i] = c;
Fprintf(txtfile, "%c = (%d, %d, %d)\n", c,
(int)MainColorMap[CM_RED][i],
(int)MainColorMap[CM_GREEN][i],
(int)MainColorMap[CM_BLUE][i]);
}
return TRUE;
charcolors[i] = c;
Fprintf(
txtfile, "%c = (%d, %d, %d)\n", c, (int) MainColorMap[CM_RED][i],
(int) MainColorMap[CM_GREEN][i], (int) MainColorMap[CM_BLUE][i]);
}
return TRUE;
}
static boolean
@@ -89,82 +94,78 @@ read_txttile(txtfile, pixels)
FILE *txtfile;
pixel (*pixels)[TILE_X];
{
int ph, i, j, k;
char buf[BUFSZ], ttype[BUFSZ];
const char *p;
char c[2];
int ph, i, j, k;
char buf[BUFSZ], ttype[BUFSZ];
const char *p;
char c[2];
if (fscanf(txtfile, "# %s %d (%[^)])", ttype, &i, buf) <= 0)
return FALSE;
ph = strcmp(ttype, "placeholder") == 0;
if (fscanf(txtfile, "# %s %d (%[^)])", ttype, &i, buf) <= 0)
return FALSE;
if (!ph && strcmp(ttype,"tile") != 0)
Fprintf(stderr,
"Keyword \"%s\" unexpected for entry %d\n",
ttype, i);
ph = strcmp(ttype, "placeholder") == 0;
if (tile_set != 0) {
/* check tile name, but not relative number, which will
* change when tiles are added
*/
p = tilename(tile_set, tile_set_indx);
if (p && strcmp(p, buf)) {
Fprintf(stderr, "warning: for tile %d (numbered %d) of %s,\n",
tile_set_indx, i, text_sets[tile_set-1]);
Fprintf(stderr, "\tfound '%s' while expecting '%s'\n",
buf, p);
}
}
tile_set_indx++;
/* look for non-whitespace at each stage */
if (fscanf(txtfile, "%1s", c) < 0) {
Fprintf(stderr, "unexpected EOF\n");
return FALSE;
}
if (c[0] != '{') {
Fprintf(stderr, "didn't find expected '{'\n");
return FALSE;
}
for (j = 0; j < TILE_Y; j++) {
for (i = 0; i < TILE_X; i++) {
if (fscanf(txtfile, "%1s", c) < 0) {
Fprintf(stderr, "unexpected EOF\n");
return FALSE;
}
k = color_index[(int) c[0]];
if (k == -1)
Fprintf(stderr,
"color %c not in colormap!\n", c[0]);
else {
pixels[j][i].r = ColorMap[CM_RED][k];
pixels[j][i].g = ColorMap[CM_GREEN][k];
pixels[j][i].b = ColorMap[CM_BLUE][k];
}
}
}
if ( ph ) {
/* remember it for later */
memcpy( placeholder, pixels, sizeof(placeholder) );
}
if (fscanf(txtfile, "%1s ", c) < 0) {
Fprintf(stderr, "unexpected EOF\n");
return FALSE;
}
if (c[0] != '}') {
Fprintf(stderr, "didn't find expected '}'\n");
return FALSE;
}
if (!ph && strcmp(ttype, "tile") != 0)
Fprintf(stderr, "Keyword \"%s\" unexpected for entry %d\n", ttype, i);
if (tile_set != 0) {
/* check tile name, but not relative number, which will
* change when tiles are added
*/
p = tilename(tile_set, tile_set_indx);
if (p && strcmp(p, buf)) {
Fprintf(stderr, "warning: for tile %d (numbered %d) of %s,\n",
tile_set_indx, i, text_sets[tile_set - 1]);
Fprintf(stderr, "\tfound '%s' while expecting '%s'\n", buf, p);
}
}
tile_set_indx++;
/* look for non-whitespace at each stage */
if (fscanf(txtfile, "%1s", c) < 0) {
Fprintf(stderr, "unexpected EOF\n");
return FALSE;
}
if (c[0] != '{') {
Fprintf(stderr, "didn't find expected '{'\n");
return FALSE;
}
for (j = 0; j < TILE_Y; j++) {
for (i = 0; i < TILE_X; i++) {
if (fscanf(txtfile, "%1s", c) < 0) {
Fprintf(stderr, "unexpected EOF\n");
return FALSE;
}
k = color_index[(int) c[0]];
if (k == -1)
Fprintf(stderr, "color %c not in colormap!\n", c[0]);
else {
pixels[j][i].r = ColorMap[CM_RED][k];
pixels[j][i].g = ColorMap[CM_GREEN][k];
pixels[j][i].b = ColorMap[CM_BLUE][k];
}
}
}
if (ph) {
/* remember it for later */
memcpy(placeholder, pixels, sizeof(placeholder));
}
if (fscanf(txtfile, "%1s ", c) < 0) {
Fprintf(stderr, "unexpected EOF\n");
return FALSE;
}
if (c[0] != '}') {
Fprintf(stderr, "didn't find expected '}'\n");
return FALSE;
}
#ifdef _DCC
/* DICE again... it doesn't seem to eat whitespace after the } like
* it should, so we have to do so manually.
*/
while ((*c = fgetc(txtfile)) != EOF && isspace(*c))
;
ungetc(*c, txtfile);
/* DICE again... it doesn't seem to eat whitespace after the } like
* it should, so we have to do so manually.
*/
while ((*c = fgetc(txtfile)) != EOF && isspace(*c))
;
ungetc(*c, txtfile);
#endif
return TRUE;
return TRUE;
}
static void
@@ -172,84 +173,84 @@ write_txttile(txtfile, pixels)
FILE *txtfile;
pixel (*pixels)[TILE_X];
{
const char *p;
const char *type;
int i, j, k;
const char *p;
const char *type;
int i, j, k;
if ( memcmp(placeholder, pixels, sizeof(placeholder)) == 0 )
type = "placeholder";
else
type = "tile";
if (memcmp(placeholder, pixels, sizeof(placeholder)) == 0)
type = "placeholder";
else
type = "tile";
if (tile_set == 0)
Fprintf(txtfile, "# %s %d (unknown)\n", type, tile_set_indx);
else {
p = tilename(tile_set, tile_set_indx);
if (p)
Fprintf(txtfile, "# %s %d (%s)\n", type, tile_set_indx, p);
else
Fprintf(txtfile, "# %s %d (null)\n", type, tile_set_indx);
}
tile_set_indx++;
if (tile_set == 0)
Fprintf(txtfile, "# %s %d (unknown)\n", type, tile_set_indx);
else {
p = tilename(tile_set, tile_set_indx);
if (p)
Fprintf(txtfile, "# %s %d (%s)\n", type, tile_set_indx, p);
else
Fprintf(txtfile, "# %s %d (null)\n", type, tile_set_indx);
}
tile_set_indx++;
Fprintf(txtfile, "{\n");
for (j = 0; j < TILE_Y; j++) {
Fprintf(txtfile, " ");
for (i = 0; i < TILE_X; i++) {
for (k = 0; k < num_colors; k++) {
if (ColorMap[CM_RED][k] == pixels[j][i].r &&
ColorMap[CM_GREEN][k] == pixels[j][i].g &&
ColorMap[CM_BLUE][k] == pixels[j][i].b)
break;
}
if (k >= num_colors)
Fprintf(stderr, "color not in colormap!\n");
(void) fputc(charcolors[k], txtfile);
}
Fprintf(txtfile, "\n");
}
Fprintf(txtfile, "}\n");
Fprintf(txtfile, "{\n");
for (j = 0; j < TILE_Y; j++) {
Fprintf(txtfile, " ");
for (i = 0; i < TILE_X; i++) {
for (k = 0; k < num_colors; k++) {
if (ColorMap[CM_RED][k] == pixels[j][i].r
&& ColorMap[CM_GREEN][k] == pixels[j][i].g
&& ColorMap[CM_BLUE][k] == pixels[j][i].b)
break;
}
if (k >= num_colors)
Fprintf(stderr, "color not in colormap!\n");
(void) fputc(charcolors[k], txtfile);
}
Fprintf(txtfile, "\n");
}
Fprintf(txtfile, "}\n");
}
/* initialize main colormap from globally accessed ColorMap */
void
init_colormap()
{
int i;
int i;
colorsinmainmap = colorsinmap;
for (i = 0; i < colorsinmap; i++) {
MainColorMap[CM_RED][i] = ColorMap[CM_RED][i];
MainColorMap[CM_GREEN][i] = ColorMap[CM_GREEN][i];
MainColorMap[CM_BLUE][i] = ColorMap[CM_BLUE][i];
}
colorsinmainmap = colorsinmap;
for (i = 0; i < colorsinmap; i++) {
MainColorMap[CM_RED][i] = ColorMap[CM_RED][i];
MainColorMap[CM_GREEN][i] = ColorMap[CM_GREEN][i];
MainColorMap[CM_BLUE][i] = ColorMap[CM_BLUE][i];
}
}
/* merge new colors from ColorMap into MainColorMap */
void
merge_colormap()
{
int i, j;
int i, j;
for (i = 0; i < colorsinmap; i++) {
for (j = 0; j < colorsinmainmap; j++) {
if (MainColorMap[CM_RED][j] == ColorMap[CM_RED][i] &&
MainColorMap[CM_GREEN][j] == ColorMap[CM_GREEN][i] &&
MainColorMap[CM_BLUE][j] == ColorMap[CM_BLUE][i])
break;
}
if (j >= colorsinmainmap) { /* new color */
if (colorsinmainmap >= MAXCOLORMAPSIZE) {
Fprintf(stderr,
"Too many colors to merge -- excess ignored.\n");
}
j = colorsinmainmap;
MainColorMap[CM_RED][j] = ColorMap[CM_RED][i];
MainColorMap[CM_GREEN][j] = ColorMap[CM_GREEN][i];
MainColorMap[CM_BLUE][j] = ColorMap[CM_BLUE][i];
colorsinmainmap++;
}
}
for (i = 0; i < colorsinmap; i++) {
for (j = 0; j < colorsinmainmap; j++) {
if (MainColorMap[CM_RED][j] == ColorMap[CM_RED][i]
&& MainColorMap[CM_GREEN][j] == ColorMap[CM_GREEN][i]
&& MainColorMap[CM_BLUE][j] == ColorMap[CM_BLUE][i])
break;
}
if (j >= colorsinmainmap) { /* new color */
if (colorsinmainmap >= MAXCOLORMAPSIZE) {
Fprintf(stderr,
"Too many colors to merge -- excess ignored.\n");
}
j = colorsinmainmap;
MainColorMap[CM_RED][j] = ColorMap[CM_RED][i];
MainColorMap[CM_GREEN][j] = ColorMap[CM_GREEN][i];
MainColorMap[CM_BLUE][j] = ColorMap[CM_BLUE][i];
colorsinmainmap++;
}
}
}
boolean
@@ -257,78 +258,80 @@ fopen_text_file(filename, type)
const char *filename;
const char *type;
{
const char *p;
int i;
const char *p;
int i;
if (tile_file != (FILE *)0) {
Fprintf(stderr, "can only open one text file at at time\n");
return FALSE;
}
if (tile_file != (FILE *) 0) {
Fprintf(stderr, "can only open one text file at at time\n");
return FALSE;
}
tile_file = fopen(filename, type);
if (tile_file == (FILE *)0) {
Fprintf(stderr, "cannot open text file %s\n", filename);
return FALSE;
}
tile_file = fopen(filename, type);
if (tile_file == (FILE *) 0) {
Fprintf(stderr, "cannot open text file %s\n", filename);
return FALSE;
}
p = rindex(filename, '/');
if (p) p++;
else p = filename;
p = rindex(filename, '/');
if (p)
p++;
else
p = filename;
tile_set = 0;
for (i = 0; i < SIZE(text_sets); i++) {
if (!strcmp(p, text_sets[i]))
tile_set = i+1;
}
tile_set_indx = 0;
tile_set = 0;
for (i = 0; i < SIZE(text_sets); i++) {
if (!strcmp(p, text_sets[i]))
tile_set = i + 1;
}
tile_set_indx = 0;
if (!strcmp(type, RDTMODE)) {
/* Fill placeholder with noise */
if ( !placeholder_init ) {
placeholder_init++;
for (i = 0; i < (int)sizeof placeholder; i++)
((char *)placeholder)[i] = i % 256;
}
if (!strcmp(type, RDTMODE)) {
/* Fill placeholder with noise */
if (!placeholder_init) {
placeholder_init++;
for (i = 0; i < (int) sizeof placeholder; i++)
((char *) placeholder)[i] = i % 256;
}
read_text_colormap(tile_file);
if (!colorsinmainmap)
init_colormap();
else
merge_colormap();
return TRUE;
} else if (!strcmp(type, WRTMODE)) {
if (!colorsinmainmap) {
Fprintf(stderr, "no colormap set yet\n");
return FALSE;
}
return(write_text_colormap(tile_file));
} else {
Fprintf(stderr, "bad mode (%s) for fopen_text_file\n", type);
return FALSE;
}
read_text_colormap(tile_file);
if (!colorsinmainmap)
init_colormap();
else
merge_colormap();
return TRUE;
} else if (!strcmp(type, WRTMODE)) {
if (!colorsinmainmap) {
Fprintf(stderr, "no colormap set yet\n");
return FALSE;
}
return (write_text_colormap(tile_file));
} else {
Fprintf(stderr, "bad mode (%s) for fopen_text_file\n", type);
return FALSE;
}
}
boolean
read_text_tile(pixels)
pixel (*pixels)[TILE_X];
{
return(read_txttile(tile_file, pixels));
return (read_txttile(tile_file, pixels));
}
boolean
write_text_tile(pixels)
pixel (*pixels)[TILE_X];
{
write_txttile(tile_file, pixels);
return TRUE;
write_txttile(tile_file, pixels);
return TRUE;
}
int
fclose_text_file()
{
int ret;
int ret;
ret = fclose(tile_file);
tile_file = (FILE *)0;
return ret;
ret = fclose(tile_file);
tile_file = (FILE *) 0;
return ret;
}
+189 -173
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 getline.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
/* NetHack 3.6 getline.c $NHDT-Date: 1431192778 2015/05/09 17:32:58 $ $NHDT-Branch: master $:$NHDT-Revision: 1.27 $ */
/* NetHack 3.6 getline.c $Date: 2011/12/11 01:54:56 $ $Revision: 1.18 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* NetHack may be freely redistributed. See license for details. */
@@ -14,15 +14,16 @@
#include "wintty.h"
#include "func_tab.h"
char morc = 0; /* tell the outside world what char you chose */
char morc = 0; /* tell the outside world what char you chose */
STATIC_DCL boolean FDECL(ext_cmd_getlin_hook, (char *));
typedef boolean FDECL((*getlin_hook_proc), (char *));
STATIC_DCL void FDECL(hooked_tty_getlin, (const char*,char*,getlin_hook_proc));
extern int NDECL(extcmd_via_menu); /* cmd.c */
STATIC_DCL void FDECL(hooked_tty_getlin,
(const char *, char *, getlin_hook_proc));
extern int NDECL(extcmd_via_menu); /* cmd.c */
extern char erase_char, kill_char; /* from appropriate tty.c file */
extern char erase_char, kill_char; /* from appropriate tty.c file */
/*
* Read a line closed with '\n' into the array char bufp[BUFSZ].
@@ -44,166 +45,177 @@ const char *query;
register char *bufp;
getlin_hook_proc hook;
{
register char *obufp = bufp;
register int c;
struct WinDesc *cw = wins[WIN_MESSAGE];
boolean doprev = 0;
register char *obufp = bufp;
register int c;
struct WinDesc *cw = wins[WIN_MESSAGE];
boolean doprev = 0;
if(ttyDisplay->toplin == 1 && !(cw->flags & WIN_STOP)) more();
cw->flags &= ~WIN_STOP;
ttyDisplay->toplin = 3; /* special prompt state */
ttyDisplay->inread++;
pline("%s ", query);
*obufp = 0;
for(;;) {
(void) fflush(stdout);
Strcat(strcat(strcpy(toplines, query), " "), obufp);
c = pgetchar();
if (c == '\033' || c == EOF) {
if (c == '\033' && obufp[0] != '\0') {
obufp[0] = '\0';
bufp = obufp;
tty_clear_nhwindow(WIN_MESSAGE);
cw->maxcol = cw->maxrow;
addtopl(query);
addtopl(" ");
addtopl(obufp);
} else {
obufp[0] = '\033';
obufp[1] = '\0';
break;
}
}
if (ttyDisplay->intr) {
ttyDisplay->intr--;
*bufp = 0;
}
if(c == '\020') { /* ctrl-P */
if (iflags.prevmsg_window != 's') {
int sav = ttyDisplay->inread;
ttyDisplay->inread = 0;
(void) tty_doprev_message();
ttyDisplay->inread = sav;
tty_clear_nhwindow(WIN_MESSAGE);
cw->maxcol = cw->maxrow;
addtopl(query);
addtopl(" ");
*bufp = 0;
addtopl(obufp);
} else {
if (!doprev)
(void) tty_doprev_message();/* need two initially */
(void) tty_doprev_message();
doprev = 1;
continue;
}
} else if (doprev && iflags.prevmsg_window == 's') {
tty_clear_nhwindow(WIN_MESSAGE);
cw->maxcol = cw->maxrow;
doprev = 0;
addtopl(query);
addtopl(" ");
*bufp = 0;
addtopl(obufp);
}
if(c == erase_char || c == '\b') {
if(bufp != obufp) {
if (ttyDisplay->toplin == 1 && !(cw->flags & WIN_STOP))
more();
cw->flags &= ~WIN_STOP;
ttyDisplay->toplin = 3; /* special prompt state */
ttyDisplay->inread++;
pline("%s ", query);
*obufp = 0;
for (;;) {
(void) fflush(stdout);
Strcat(strcat(strcpy(toplines, query), " "), obufp);
c = pgetchar();
if (c == '\033' || c == EOF) {
if (c == '\033' && obufp[0] != '\0') {
obufp[0] = '\0';
bufp = obufp;
tty_clear_nhwindow(WIN_MESSAGE);
cw->maxcol = cw->maxrow;
addtopl(query);
addtopl(" ");
addtopl(obufp);
} else {
obufp[0] = '\033';
obufp[1] = '\0';
break;
}
}
if (ttyDisplay->intr) {
ttyDisplay->intr--;
*bufp = 0;
}
if (c == '\020') { /* ctrl-P */
if (iflags.prevmsg_window != 's') {
int sav = ttyDisplay->inread;
ttyDisplay->inread = 0;
(void) tty_doprev_message();
ttyDisplay->inread = sav;
tty_clear_nhwindow(WIN_MESSAGE);
cw->maxcol = cw->maxrow;
addtopl(query);
addtopl(" ");
*bufp = 0;
addtopl(obufp);
} else {
if (!doprev)
(void) tty_doprev_message(); /* need two initially */
(void) tty_doprev_message();
doprev = 1;
continue;
}
} else if (doprev && iflags.prevmsg_window == 's') {
tty_clear_nhwindow(WIN_MESSAGE);
cw->maxcol = cw->maxrow;
doprev = 0;
addtopl(query);
addtopl(" ");
*bufp = 0;
addtopl(obufp);
}
if (c == erase_char || c == '\b') {
if (bufp != obufp) {
#ifdef NEWAUTOCOMP
char *i;
char *i;
#endif /* NEWAUTOCOMP */
bufp--;
bufp--;
#ifndef NEWAUTOCOMP
putsyms("\b \b");/* putsym converts \b */
#else /* NEWAUTOCOMP */
putsyms("\b");
for (i = bufp; *i; ++i) putsyms(" ");
for (; i > bufp; --i) putsyms("\b");
*bufp = 0;
#endif /* NEWAUTOCOMP */
} else tty_nhbell();
putsyms("\b \b"); /* putsym converts \b */
#else /* NEWAUTOCOMP */
putsyms("\b");
for (i = bufp; *i; ++i)
putsyms(" ");
for (; i > bufp; --i)
putsyms("\b");
*bufp = 0;
#endif /* NEWAUTOCOMP */
} else
tty_nhbell();
#if defined(apollo)
} else if(c == '\n' || c == '\r') {
} else if (c == '\n' || c == '\r') {
#else
} else if(c == '\n') {
} else if (c == '\n') {
#endif
#ifndef NEWAUTOCOMP
*bufp = 0;
*bufp = 0;
#endif /* not NEWAUTOCOMP */
break;
} else if(' ' <= (unsigned char) c && c != '\177' &&
(bufp-obufp < BUFSZ-1 && bufp-obufp < COLNO)) {
/* avoid isprint() - some people don't have it
' ' is not always a printing char */
break;
} else if (' ' <= (unsigned char) c && c != '\177'
&& (bufp - obufp < BUFSZ - 1 && bufp - obufp < COLNO)) {
/* avoid isprint() - some people don't have it
' ' is not always a printing char */
#ifdef NEWAUTOCOMP
char *i = eos(bufp);
char *i = eos(bufp);
#endif /* NEWAUTOCOMP */
*bufp = c;
bufp[1] = 0;
putsyms(bufp);
bufp++;
if (hook && (*hook)(obufp)) {
putsyms(bufp);
*bufp = c;
bufp[1] = 0;
putsyms(bufp);
bufp++;
if (hook && (*hook)(obufp)) {
putsyms(bufp);
#ifndef NEWAUTOCOMP
bufp = eos(bufp);
#else /* NEWAUTOCOMP */
/* pointer and cursor left where they were */
for (i = bufp; *i; ++i) putsyms("\b");
} else if (i > bufp) {
char *s = i;
bufp = eos(bufp);
#else /* NEWAUTOCOMP */
/* pointer and cursor left where they were */
for (i = bufp; *i; ++i)
putsyms("\b");
} else if (i > bufp) {
char *s = i;
/* erase rest of prior guess */
for (; i > bufp; --i) putsyms(" ");
for (; s > bufp; --s) putsyms("\b");
/* erase rest of prior guess */
for (; i > bufp; --i)
putsyms(" ");
for (; s > bufp; --s)
putsyms("\b");
#endif /* NEWAUTOCOMP */
}
} else if(c == kill_char || c == '\177') { /* Robert Viduya */
/* this test last - @ might be the kill_char */
}
} else if (c == kill_char || c == '\177') { /* Robert Viduya */
/* this test last - @ might be the kill_char */
#ifndef NEWAUTOCOMP
while(bufp != obufp) {
bufp--;
putsyms("\b \b");
}
#else /* NEWAUTOCOMP */
for (; *bufp; ++bufp) putsyms(" ");
for (; bufp != obufp; --bufp) putsyms("\b \b");
*bufp = 0;
while (bufp != obufp) {
bufp--;
putsyms("\b \b");
}
#else /* NEWAUTOCOMP */
for (; *bufp; ++bufp)
putsyms(" ");
for (; bufp != obufp; --bufp)
putsyms("\b \b");
*bufp = 0;
#endif /* NEWAUTOCOMP */
} else
tty_nhbell();
}
ttyDisplay->toplin = 2; /* nonempty, no --More-- required */
ttyDisplay->inread--;
clear_nhwindow(WIN_MESSAGE); /* clean up after ourselves */
} else
tty_nhbell();
}
ttyDisplay->toplin = 2; /* nonempty, no --More-- required */
ttyDisplay->inread--;
clear_nhwindow(WIN_MESSAGE); /* clean up after ourselves */
}
void
xwaitforspace(s)
register const char *s; /* chars allowed besides return */
register const char *s; /* chars allowed besides return */
{
register int c, x = ttyDisplay ? (int) ttyDisplay->dismiss_more : '\n';
morc = 0;
while (
#ifdef HANGUPHANDLING
!program_state.done_hup &&
!program_state.done_hup &&
#endif
(c = tty_nhgetch()) != EOF) {
if (c == '\n') break;
(c = tty_nhgetch()) != EOF) {
if (c == '\n')
break;
if(iflags.cbreak) {
if (c == '\033') {
if (ttyDisplay) ttyDisplay->dismiss_more = 1;
morc = '\033';
break;
}
if ((s && index(s,c)) || c == x) {
morc = (char) c;
break;
}
tty_nhbell();
}
if (iflags.cbreak) {
if (c == '\033') {
if (ttyDisplay)
ttyDisplay->dismiss_more = 1;
morc = '\033';
break;
}
if ((s && index(s, c)) || c == x) {
morc = (char) c;
break;
}
tty_nhbell();
}
}
}
@@ -221,25 +233,25 @@ register const char *s; /* chars allowed besides return */
*/
STATIC_OVL boolean
ext_cmd_getlin_hook(base)
char *base;
char *base;
{
int oindex, com_index;
int oindex, com_index;
com_index = -1;
for (oindex = 0; extcmdlist[oindex].ef_txt != (char *)0; oindex++) {
if (!strncmpi(base, extcmdlist[oindex].ef_txt, strlen(base))) {
if (com_index == -1) /* no matches yet */
com_index = oindex;
else /* more than 1 match */
return FALSE;
}
}
if (com_index >= 0) {
Strcpy(base, extcmdlist[com_index].ef_txt);
return TRUE;
}
com_index = -1;
for (oindex = 0; extcmdlist[oindex].ef_txt != (char *) 0; oindex++) {
if (!strncmpi(base, extcmdlist[oindex].ef_txt, strlen(base))) {
if (com_index == -1) /* no matches yet */
com_index = oindex;
else /* more than 1 match */
return FALSE;
}
}
if (com_index >= 0) {
Strcpy(base, extcmdlist[com_index].ef_txt);
return TRUE;
}
return FALSE; /* didn't match anything */
return FALSE; /* didn't match anything */
}
/*
@@ -249,33 +261,37 @@ ext_cmd_getlin_hook(base)
int
tty_get_ext_cmd()
{
int i;
char buf[BUFSZ];
int i;
char buf[BUFSZ];
if (iflags.extmenu) return extcmd_via_menu();
/* maybe a runtime option? */
/* hooked_tty_getlin("#", buf, flags.cmd_comp ? ext_cmd_getlin_hook : (getlin_hook_proc) 0); */
hooked_tty_getlin("#", buf, in_doagain ? (getlin_hook_proc)0
: ext_cmd_getlin_hook);
(void) mungspaces(buf);
if (buf[0] == 0 || buf[0] == '\033') return -1;
if (iflags.extmenu)
return extcmd_via_menu();
/* maybe a runtime option? */
/* hooked_tty_getlin("#", buf, flags.cmd_comp ? ext_cmd_getlin_hook :
* (getlin_hook_proc) 0); */
hooked_tty_getlin("#", buf, in_doagain ? (getlin_hook_proc) 0
: ext_cmd_getlin_hook);
(void) mungspaces(buf);
if (buf[0] == 0 || buf[0] == '\033')
return -1;
for (i = 0; extcmdlist[i].ef_txt != (char *)0; i++)
if (!strcmpi(buf, extcmdlist[i].ef_txt)) break;
for (i = 0; extcmdlist[i].ef_txt != (char *) 0; i++)
if (!strcmpi(buf, extcmdlist[i].ef_txt))
break;
if (!in_doagain) {
int j;
for (j = 0; buf[j]; j++)
savech(buf[j]);
savech('\n');
}
if (!in_doagain) {
int j;
for (j = 0; buf[j]; j++)
savech(buf[j]);
savech('\n');
}
if (extcmdlist[i].ef_txt == (char *)0) {
pline("%s: unknown extended command.", buf);
i = -1;
}
if (extcmdlist[i].ef_txt == (char *) 0) {
pline("%s: unknown extended command.", buf);
i = -1;
}
return i;
return i;
}
#endif /* TTY_GRAPHICS */
+806 -774
View File
File diff suppressed because it is too large Load Diff
+359 -322
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 topl.c $NHDT-Date: 1430040322 2015/04/26 09:25:22 $ $NHDT-Branch: master $:$NHDT-Revision: 1.29 $ */
/* NetHack 3.6 topl.c $NHDT-Date: 1431192777 2015/05/09 17:32:57 $ $NHDT-Branch: master $:$NHDT-Revision: 1.32 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* NetHack may be freely redistributed. See license for details. */
@@ -10,11 +10,11 @@
#include "wintty.h"
#include <ctype.h>
#ifndef C /* this matches src/cmd.c */
#define C(c) (0x1f & (c))
#ifndef C /* this matches src/cmd.c */
#define C(c) (0x1f & (c))
#endif
STATIC_DCL void FDECL(redotoplin, (const char*));
STATIC_DCL void FDECL(redotoplin, (const char *));
STATIC_DCL void FDECL(topl_putsym, (CHAR_P));
STATIC_DCL void NDECL(remember_topl);
STATIC_DCL void FDECL(removetopl, (int));
@@ -28,36 +28,41 @@ tty_doprev_message()
winid prevmsg_win;
int i;
if ((iflags.prevmsg_window != 's') && !ttyDisplay->inread) { /* not single */
if(iflags.prevmsg_window == 'f') { /* full */
if ((iflags.prevmsg_window != 's')
&& !ttyDisplay->inread) { /* not single */
if (iflags.prevmsg_window == 'f') { /* full */
prevmsg_win = create_nhwindow(NHW_MENU);
putstr(prevmsg_win, 0, "Message History");
putstr(prevmsg_win, 0, "");
cw->maxcol = cw->maxrow;
i = cw->maxcol;
do {
if(cw->data[i] && strcmp(cw->data[i], "") )
if (cw->data[i] && strcmp(cw->data[i], ""))
putstr(prevmsg_win, 0, cw->data[i]);
i = (i + 1) % cw->rows;
} while (i != cw->maxcol);
putstr(prevmsg_win, 0, toplines);
display_nhwindow(prevmsg_win, TRUE);
destroy_nhwindow(prevmsg_win);
} else if (iflags.prevmsg_window == 'c') { /* combination */
} else if (iflags.prevmsg_window == 'c') { /* combination */
do {
morc = 0;
if (cw->maxcol == cw->maxrow) {
ttyDisplay->dismiss_more = C('p'); /* <ctrl/P> allowed at --More-- */
ttyDisplay->dismiss_more =
C('p'); /* <ctrl/P> allowed at --More-- */
redotoplin(toplines);
cw->maxcol--;
if (cw->maxcol < 0) cw->maxcol = cw->rows-1;
if (cw->maxcol < 0)
cw->maxcol = cw->rows - 1;
if (!cw->data[cw->maxcol])
cw->maxcol = cw->maxrow;
} else if (cw->maxcol == (cw->maxrow - 1)){
ttyDisplay->dismiss_more = C('p'); /* <ctrl/P> allowed at --More-- */
} else if (cw->maxcol == (cw->maxrow - 1)) {
ttyDisplay->dismiss_more =
C('p'); /* <ctrl/P> allowed at --More-- */
redotoplin(cw->data[cw->maxcol]);
cw->maxcol--;
if (cw->maxcol < 0) cw->maxcol = cw->rows-1;
if (cw->maxcol < 0)
cw->maxcol = cw->rows - 1;
if (!cw->data[cw->maxcol])
cw->maxcol = cw->maxrow;
} else {
@@ -67,7 +72,7 @@ tty_doprev_message()
cw->maxcol = cw->maxrow;
i = cw->maxcol;
do {
if(cw->data[i] && strcmp(cw->data[i], "") )
if (cw->data[i] && strcmp(cw->data[i], ""))
putstr(prevmsg_win, 0, cw->data[i]);
i = (i + 1) % cw->rows;
} while (i != cw->maxcol);
@@ -84,12 +89,14 @@ tty_doprev_message()
putstr(prevmsg_win, 0, "Message History");
putstr(prevmsg_win, 0, "");
putstr(prevmsg_win, 0, toplines);
cw->maxcol=cw->maxrow-1;
if(cw->maxcol < 0) cw->maxcol = cw->rows-1;
cw->maxcol = cw->maxrow - 1;
if (cw->maxcol < 0)
cw->maxcol = cw->rows - 1;
do {
putstr(prevmsg_win, 0, cw->data[cw->maxcol]);
cw->maxcol--;
if (cw->maxcol < 0) cw->maxcol = cw->rows-1;
if (cw->maxcol < 0)
cw->maxcol = cw->rows - 1;
if (!cw->data[cw->maxcol])
cw->maxcol = cw->maxrow;
} while (cw->maxcol != cw->maxrow);
@@ -99,8 +106,8 @@ tty_doprev_message()
cw->maxcol = cw->maxrow;
ttyDisplay->dismiss_more = 0;
}
} else if(iflags.prevmsg_window == 's') { /* single */
ttyDisplay->dismiss_more = C('p'); /* <ctrl/P> allowed at --More-- */
} else if (iflags.prevmsg_window == 's') { /* single */
ttyDisplay->dismiss_more = C('p'); /* <ctrl/P> allowed at --More-- */
do {
morc = 0;
if (cw->maxcol == cw->maxrow)
@@ -108,7 +115,8 @@ tty_doprev_message()
else if (cw->data[cw->maxcol])
redotoplin(cw->data[cw->maxcol]);
cw->maxcol--;
if (cw->maxcol < 0) cw->maxcol = cw->rows-1;
if (cw->maxcol < 0)
cw->maxcol = cw->rows - 1;
if (!cw->data[cw->maxcol])
cw->maxcol = cw->maxrow;
} while (morc == C('p'));
@@ -119,22 +127,22 @@ tty_doprev_message()
STATIC_OVL void
redotoplin(str)
const char *str;
const char *str;
{
int otoplin = ttyDisplay->toplin;
home();
if(*str & 0x80) {
/* kludge for the / command, the only time we ever want a */
/* graphics character on the top line */
g_putch((int)*str++);
ttyDisplay->curx++;
}
end_glyphout(); /* in case message printed during graphics output */
putsyms(str);
cl_end();
ttyDisplay->toplin = 1;
if(ttyDisplay->cury && otoplin != 3)
more();
int otoplin = ttyDisplay->toplin;
home();
if (*str & 0x80) {
/* kludge for the / command, the only time we ever want a */
/* graphics character on the top line */
g_putch((int) *str++);
ttyDisplay->curx++;
}
end_glyphout(); /* in case message printed during graphics output */
putsyms(str);
cl_end();
ttyDisplay->toplin = 1;
if (ttyDisplay->cury && otoplin != 3)
more();
}
STATIC_OVL void
@@ -144,14 +152,15 @@ remember_topl()
int idx = cw->maxrow;
unsigned len = strlen(toplines) + 1;
if ((cw->flags & WIN_LOCKHISTORY) || !*toplines) return;
if ((cw->flags & WIN_LOCKHISTORY) || !*toplines)
return;
if (len > (unsigned)cw->datlen[idx]) {
if (cw->data[idx]) free(cw->data[idx]);
len += (8 - (len & 7)); /* pad up to next multiple of 8 */
cw->data[idx] = (char *)alloc(len);
cw->datlen[idx] = (short)len;
if (len > (unsigned) cw->datlen[idx]) {
if (cw->data[idx])
free(cw->data[idx]);
len += (8 - (len & 7)); /* pad up to next multiple of 8 */
cw->data[idx] = (char *) alloc(len);
cw->datlen[idx] = (short) len;
}
Strcpy(cw->data[idx], toplines);
*toplines = '\0';
@@ -164,7 +173,7 @@ const char *s;
{
register struct WinDesc *cw = wins[WIN_MESSAGE];
tty_curs(BASE_WINDOW,cw->curx+1,cw->cury);
tty_curs(BASE_WINDOW, cw->curx + 1, cw->cury);
putsyms(s);
cl_end();
ttyDisplay->toplin = 1;
@@ -176,33 +185,34 @@ more()
struct WinDesc *cw = wins[WIN_MESSAGE];
/* avoid recursion -- only happens from interrupts */
if(ttyDisplay->inmore++)
return;
if (ttyDisplay->inmore++)
return;
if(ttyDisplay->toplin) {
tty_curs(BASE_WINDOW, cw->curx+1, cw->cury);
if(cw->curx >= CO - 8) topl_putsym('\n');
if (ttyDisplay->toplin) {
tty_curs(BASE_WINDOW, cw->curx + 1, cw->cury);
if (cw->curx >= CO - 8)
topl_putsym('\n');
}
if(flags.standout)
standoutbeg();
if (flags.standout)
standoutbeg();
putsyms(defmorestr);
if(flags.standout)
standoutend();
if (flags.standout)
standoutend();
xwaitforspace("\033 ");
if(morc == '\033')
cw->flags |= WIN_STOP;
if (morc == '\033')
cw->flags |= WIN_STOP;
if(ttyDisplay->toplin && cw->cury) {
docorner(1, cw->cury+1);
cw->curx = cw->cury = 0;
home();
} else if(morc == '\033') {
cw->curx = cw->cury = 0;
home();
cl_end();
if (ttyDisplay->toplin && cw->cury) {
docorner(1, cw->cury + 1);
cw->curx = cw->cury = 0;
home();
} else if (morc == '\033') {
cw->curx = cw->cury = 0;
home();
cl_end();
}
ttyDisplay->toplin = 0;
ttyDisplay->inmore = 0;
@@ -210,88 +220,94 @@ more()
void
update_topl(bp)
register const char *bp;
register const char *bp;
{
register char *tl, *otl;
register int n0;
int notdied = 1;
struct WinDesc *cw = wins[WIN_MESSAGE];
register char *tl, *otl;
register int n0;
int notdied = 1;
struct WinDesc *cw = wins[WIN_MESSAGE];
/* If there is room on the line, print message on same line */
/* But messages like "You die..." deserve their own line */
n0 = strlen(bp);
if ((ttyDisplay->toplin == 1 || (cw->flags & WIN_STOP)) &&
cw->cury == 0 &&
n0 + (int)strlen(toplines) + 3 < CO-8 && /* room for --More-- */
(notdied = strncmp(bp, "You die", 7))) {
Strcat(toplines, " ");
Strcat(toplines, bp);
cw->curx += 2;
if(!(cw->flags & WIN_STOP))
addtopl(bp);
return;
} else if (!(cw->flags & WIN_STOP)) {
if(ttyDisplay->toplin == 1) more();
else if(cw->cury) { /* for when flags.toplin == 2 && cury > 1 */
docorner(1, cw->cury+1); /* reset cury = 0 if redraw screen */
cw->curx = cw->cury = 0;/* from home--cls() & docorner(1,n) */
}
}
remember_topl();
(void) strncpy(toplines, bp, TBUFSZ);
toplines[TBUFSZ - 1] = 0;
/* If there is room on the line, print message on same line */
/* But messages like "You die..." deserve their own line */
n0 = strlen(bp);
if ((ttyDisplay->toplin == 1 || (cw->flags & WIN_STOP)) && cw->cury == 0
&& n0 + (int) strlen(toplines) + 3 < CO - 8 && /* room for --More-- */
(notdied = strncmp(bp, "You die", 7))) {
Strcat(toplines, " ");
Strcat(toplines, bp);
cw->curx += 2;
if (!(cw->flags & WIN_STOP))
addtopl(bp);
return;
} else if (!(cw->flags & WIN_STOP)) {
if (ttyDisplay->toplin == 1)
more();
else if (cw->cury) { /* for when flags.toplin == 2 && cury > 1 */
docorner(1, cw->cury + 1); /* reset cury = 0 if redraw screen */
cw->curx = cw->cury = 0; /* from home--cls() & docorner(1,n) */
}
}
remember_topl();
(void) strncpy(toplines, bp, TBUFSZ);
toplines[TBUFSZ - 1] = 0;
for(tl = toplines; n0 >= CO; ){
otl = tl;
for(tl+=CO-1; tl != otl && !isspace(*tl); --tl) ;
if(tl == otl) {
/* Eek! A huge token. Try splitting after it. */
tl = index(otl, ' ');
if (!tl) break; /* No choice but to spit it out whole. */
}
*tl++ = '\n';
n0 = strlen(tl);
}
if(!notdied) cw->flags &= ~WIN_STOP;
if(!(cw->flags & WIN_STOP)) redotoplin(toplines);
for (tl = toplines; n0 >= CO;) {
otl = tl;
for (tl += CO - 1; tl != otl && !isspace(*tl); --tl)
;
if (tl == otl) {
/* Eek! A huge token. Try splitting after it. */
tl = index(otl, ' ');
if (!tl)
break; /* No choice but to spit it out whole. */
}
*tl++ = '\n';
n0 = strlen(tl);
}
if (!notdied)
cw->flags &= ~WIN_STOP;
if (!(cw->flags & WIN_STOP))
redotoplin(toplines);
}
STATIC_OVL
void
topl_putsym(c)
char c;
char c;
{
register struct WinDesc *cw = wins[WIN_MESSAGE];
if(cw == (struct WinDesc *) 0) panic("Putsym window MESSAGE nonexistant");
switch(c) {
if (cw == (struct WinDesc *) 0)
panic("Putsym window MESSAGE nonexistant");
switch (c) {
case '\b':
if(ttyDisplay->curx == 0 && ttyDisplay->cury > 0)
tty_curs(BASE_WINDOW, CO, (int)ttyDisplay->cury-1);
backsp();
ttyDisplay->curx--;
cw->curx = ttyDisplay->curx;
return;
if (ttyDisplay->curx == 0 && ttyDisplay->cury > 0)
tty_curs(BASE_WINDOW, CO, (int) ttyDisplay->cury - 1);
backsp();
ttyDisplay->curx--;
cw->curx = ttyDisplay->curx;
return;
case '\n':
cl_end();
ttyDisplay->curx = 0;
ttyDisplay->cury++;
cw->cury = ttyDisplay->cury;
cl_end();
ttyDisplay->curx = 0;
ttyDisplay->cury++;
cw->cury = ttyDisplay->cury;
#ifdef WIN32CON
(void) putchar(c);
(void) putchar(c);
#endif
break;
break;
default:
if(ttyDisplay->curx == CO-1)
topl_putsym('\n'); /* 1 <= curx <= CO; avoid CO */
if (ttyDisplay->curx == CO - 1)
topl_putsym('\n'); /* 1 <= curx <= CO; avoid CO */
#ifdef WIN32CON
(void) putchar(c);
(void) putchar(c);
#endif
ttyDisplay->curx++;
ttyDisplay->curx++;
}
cw->curx = ttyDisplay->curx;
if(cw->curx == 0) cl_end();
if (cw->curx == 0)
cl_end();
#ifndef WIN32CON
(void) putchar(c);
#endif
@@ -299,10 +315,10 @@ topl_putsym(c)
void
putsyms(str)
const char *str;
const char *str;
{
while(*str)
topl_putsym(*str++);
while (*str)
topl_putsym(*str++);
}
STATIC_OVL void
@@ -310,14 +326,15 @@ removetopl(n)
register int n;
{
/* assume addtopl() has been done, so ttyDisplay->toplin is already set */
while (n-- > 0) putsyms("\b \b");
while (n-- > 0)
putsyms("\b \b");
}
extern char erase_char; /* from xxxtty.c; don't need kill_char */
extern char erase_char; /* from xxxtty.c; don't need kill_char */
char
tty_yn_function(query,resp, def)
const char *query,*resp;
tty_yn_function(query, resp, def)
const char *query, *resp;
char def;
/*
* Generic yes/no function. 'def' is the default (returned by space or
@@ -331,148 +348,163 @@ char def;
* be shown in the prompt to the user but will be acceptable as input.
*/
{
register char q;
char rtmp[40];
boolean digit_ok, allow_num, preserve_case = FALSE;
struct WinDesc *cw = wins[WIN_MESSAGE];
boolean doprev = 0;
char prompt[BUFSZ];
register char q;
char rtmp[40];
boolean digit_ok, allow_num, preserve_case = FALSE;
struct WinDesc *cw = wins[WIN_MESSAGE];
boolean doprev = 0;
char prompt[BUFSZ];
if(ttyDisplay->toplin == 1 && !(cw->flags & WIN_STOP)) more();
cw->flags &= ~WIN_STOP;
ttyDisplay->toplin = 3; /* special prompt state */
ttyDisplay->inread++;
if (resp) {
char *rb, respbuf[QBUFSZ];
if (ttyDisplay->toplin == 1 && !(cw->flags & WIN_STOP))
more();
cw->flags &= ~WIN_STOP;
ttyDisplay->toplin = 3; /* special prompt state */
ttyDisplay->inread++;
if (resp) {
char *rb, respbuf[QBUFSZ];
allow_num = (index(resp, '#') != 0);
Strcpy(respbuf, resp);
/* normally we force lowercase, but if any uppercase letters
are present in the allowed response, preserve case;
check this before stripping the hidden choices */
for (rb = respbuf; *rb; ++rb)
if ('A' <= *rb && *rb <= 'Z') {
preserve_case = TRUE;
break;
}
/* any acceptable responses that follow <esc> aren't displayed */
if ((rb = index(respbuf, '\033')) != 0) *rb = '\0';
(void)strncpy(prompt, query, QBUFSZ-1);
prompt[QBUFSZ-1] = '\0';
Sprintf(eos(prompt), " [%s]", respbuf);
if (def) Sprintf(eos(prompt), " (%c)", def);
/* not pline("%s ", prompt);
trailing space is wanted here in case of reprompt */
Strcat(prompt, " ");
pline("%s", prompt);
} else {
/* no restriction on allowed response, so always preserve case */
/* preserve_case = TRUE; -- moot since we're jumping to the end */
pline("%s ", query);
q = readchar();
goto clean_up;
}
allow_num = (index(resp, '#') != 0);
Strcpy(respbuf, resp);
/* normally we force lowercase, but if any uppercase letters
are present in the allowed response, preserve case;
check this before stripping the hidden choices */
for (rb = respbuf; *rb; ++rb)
if ('A' <= *rb && *rb <= 'Z') {
preserve_case = TRUE;
break;
}
/* any acceptable responses that follow <esc> aren't displayed */
if ((rb = index(respbuf, '\033')) != 0)
*rb = '\0';
(void) strncpy(prompt, query, QBUFSZ - 1);
prompt[QBUFSZ - 1] = '\0';
Sprintf(eos(prompt), " [%s]", respbuf);
if (def)
Sprintf(eos(prompt), " (%c)", def);
/* not pline("%s ", prompt);
trailing space is wanted here in case of reprompt */
Strcat(prompt, " ");
pline("%s", prompt);
} else {
/* no restriction on allowed response, so always preserve case */
/* preserve_case = TRUE; -- moot since we're jumping to the end */
pline("%s ", query);
q = readchar();
goto clean_up;
}
do { /* loop until we get valid input */
q = readchar();
if (!preserve_case) q = lowc(q);
if (q == '\020') { /* ctrl-P */
if (iflags.prevmsg_window != 's') {
int sav = ttyDisplay->inread;
ttyDisplay->inread = 0;
(void) tty_doprev_message();
ttyDisplay->inread = sav;
tty_clear_nhwindow(WIN_MESSAGE);
cw->maxcol = cw->maxrow;
addtopl(prompt);
} else {
if(!doprev)
(void) tty_doprev_message(); /* need two initially */
(void) tty_doprev_message();
doprev = 1;
}
q = '\0'; /* force another loop iteration */
continue;
} else if (doprev) {
/* BUG[?]: this probably ought to check whether the
character which has just been read is an acceptable
response; if so, skip the reprompt and use it. */
tty_clear_nhwindow(WIN_MESSAGE);
cw->maxcol = cw->maxrow;
doprev = 0;
addtopl(prompt);
q = '\0'; /* force another loop iteration */
continue;
}
digit_ok = allow_num && digit(q);
if (q == '\033') {
if (index(resp, 'q'))
q = 'q';
else if (index(resp, 'n'))
q = 'n';
else
q = def;
break;
} else if (index(quitchars, q)) {
q = def;
break;
}
if (!index(resp, q) && !digit_ok) {
tty_nhbell();
q = (char)0;
} else if (q == '#' || digit_ok) {
char z, digit_string[2];
int n_len = 0;
long value = 0;
addtopl("#"), n_len++;
digit_string[1] = '\0';
if (q != '#') {
digit_string[0] = q;
addtopl(digit_string), n_len++;
value = q - '0';
q = '#';
}
do { /* loop until we get a non-digit */
z = readchar();
if (!preserve_case) z = lowc(z);
if (digit(z)) {
value = (10 * value) + (z - '0');
if (value < 0) break; /* overflow: try again */
digit_string[0] = z;
addtopl(digit_string), n_len++;
} else if (z == 'y' || index(quitchars, z)) {
if (z == '\033') value = -1; /* abort */
z = '\n'; /* break */
} else if (z == erase_char || z == '\b') {
if (n_len <= 1) { value = -1; break; }
else { value /= 10; removetopl(1), n_len--; }
} else {
value = -1; /* abort */
tty_nhbell();
break;
}
} while (z != '\n');
if (value > 0) yn_number = value;
else if (value == 0) q = 'n'; /* 0 => "no" */
else { /* remove number from top line, then try again */
removetopl(n_len), n_len = 0;
q = '\0';
}
}
} while(!q);
do { /* loop until we get valid input */
q = readchar();
if (!preserve_case)
q = lowc(q);
if (q == '\020') { /* ctrl-P */
if (iflags.prevmsg_window != 's') {
int sav = ttyDisplay->inread;
ttyDisplay->inread = 0;
(void) tty_doprev_message();
ttyDisplay->inread = sav;
tty_clear_nhwindow(WIN_MESSAGE);
cw->maxcol = cw->maxrow;
addtopl(prompt);
} else {
if (!doprev)
(void) tty_doprev_message(); /* need two initially */
(void) tty_doprev_message();
doprev = 1;
}
q = '\0'; /* force another loop iteration */
continue;
} else if (doprev) {
/* BUG[?]: this probably ought to check whether the
character which has just been read is an acceptable
response; if so, skip the reprompt and use it. */
tty_clear_nhwindow(WIN_MESSAGE);
cw->maxcol = cw->maxrow;
doprev = 0;
addtopl(prompt);
q = '\0'; /* force another loop iteration */
continue;
}
digit_ok = allow_num && digit(q);
if (q == '\033') {
if (index(resp, 'q'))
q = 'q';
else if (index(resp, 'n'))
q = 'n';
else
q = def;
break;
} else if (index(quitchars, q)) {
q = def;
break;
}
if (!index(resp, q) && !digit_ok) {
tty_nhbell();
q = (char) 0;
} else if (q == '#' || digit_ok) {
char z, digit_string[2];
int n_len = 0;
long value = 0;
addtopl("#"), n_len++;
digit_string[1] = '\0';
if (q != '#') {
digit_string[0] = q;
addtopl(digit_string), n_len++;
value = q - '0';
q = '#';
}
do { /* loop until we get a non-digit */
z = readchar();
if (!preserve_case)
z = lowc(z);
if (digit(z)) {
value = (10 * value) + (z - '0');
if (value < 0)
break; /* overflow: try again */
digit_string[0] = z;
addtopl(digit_string), n_len++;
} else if (z == 'y' || index(quitchars, z)) {
if (z == '\033')
value = -1; /* abort */
z = '\n'; /* break */
} else if (z == erase_char || z == '\b') {
if (n_len <= 1) {
value = -1;
break;
} else {
value /= 10;
removetopl(1), n_len--;
}
} else {
value = -1; /* abort */
tty_nhbell();
break;
}
} while (z != '\n');
if (value > 0)
yn_number = value;
else if (value == 0)
q = 'n'; /* 0 => "no" */
else { /* remove number from top line, then try again */
removetopl(n_len), n_len = 0;
q = '\0';
}
}
} while (!q);
if (q != '#') {
Sprintf(rtmp, "%c", q);
addtopl(rtmp);
}
clean_up:
ttyDisplay->inread--;
ttyDisplay->toplin = 2;
if (ttyDisplay->intr) ttyDisplay->intr--;
if(wins[WIN_MESSAGE]->cury)
tty_clear_nhwindow(WIN_MESSAGE);
if (q != '#') {
Sprintf(rtmp, "%c", q);
addtopl(rtmp);
}
clean_up:
ttyDisplay->inread--;
ttyDisplay->toplin = 2;
if (ttyDisplay->intr)
ttyDisplay->intr--;
if (wins[WIN_MESSAGE]->cury)
tty_clear_nhwindow(WIN_MESSAGE);
return q;
return q;
}
/* shared by tty_getmsghistory() and tty_putmsghistory() */
@@ -482,14 +514,15 @@ static char **snapshot_mesgs = 0;
optionally, purge that data from the active circular buffer set as we go */
STATIC_OVL void
msghistory_snapshot(purge)
boolean purge; /* clear message history buffer as we copy it */
boolean purge; /* clear message history buffer as we copy it */
{
char *mesg;
int i, inidx, outidx;
struct WinDesc *cw;
/* paranoia (too early or too late panic save attempt?) */
if (WIN_MESSAGE == WIN_ERR || !wins[WIN_MESSAGE]) return;
if (WIN_MESSAGE == WIN_ERR || !wins[WIN_MESSAGE])
return;
cw = wins[WIN_MESSAGE];
/* flush toplines[], moving most recent message to history */
@@ -497,49 +530,52 @@ boolean purge; /* clear message history buffer as we copy it */
/* for a passive snapshot, we just copy pointers, so can't allow further
history updating to take place because that could clobber them */
if (!purge) cw->flags |= WIN_LOCKHISTORY;
if (!purge)
cw->flags |= WIN_LOCKHISTORY;
snapshot_mesgs = (char **)alloc((cw->rows + 1) * sizeof (char *));
snapshot_mesgs = (char **) alloc((cw->rows + 1) * sizeof(char *));
outidx = 0;
inidx = cw->maxrow;
for (i = 0; i < cw->rows; ++i) {
snapshot_mesgs[i] = (char *)0;
mesg = cw->data[inidx];
if (mesg && *mesg) {
snapshot_mesgs[outidx++] = mesg;
if (purge) {
/* we're taking this pointer away; subsequest history
updates will eventually allocate a new one to replace it */
cw->data[inidx] = (char *)0;
cw->datlen[inidx] = 0;
}
}
inidx = (inidx + 1) % cw->rows;
snapshot_mesgs[i] = (char *) 0;
mesg = cw->data[inidx];
if (mesg && *mesg) {
snapshot_mesgs[outidx++] = mesg;
if (purge) {
/* we're taking this pointer away; subsequest history
updates will eventually allocate a new one to replace it */
cw->data[inidx] = (char *) 0;
cw->datlen[inidx] = 0;
}
}
inidx = (inidx + 1) % cw->rows;
}
snapshot_mesgs[cw->rows] = (char *)0; /* sentinel */
snapshot_mesgs[cw->rows] = (char *) 0; /* sentinel */
/* for a destructive snapshot, history is now completely empty */
if (purge) cw->maxcol = cw->maxrow = 0;
if (purge)
cw->maxcol = cw->maxrow = 0;
}
/* release memory allocated to message history snapshot */
STATIC_OVL void
free_msghistory_snapshot(purged)
boolean purged; /* True: took history's pointers, False: just cloned them */
boolean purged; /* True: took history's pointers, False: just cloned them */
{
if (snapshot_mesgs) {
/* snapshot pointers are no longer in use */
if (purged) {
int i;
/* snapshot pointers are no longer in use */
if (purged) {
int i;
for (i = 0; snapshot_mesgs[i]; ++i)
free((genericptr_t)snapshot_mesgs[i]);
}
for (i = 0; snapshot_mesgs[i]; ++i)
free((genericptr_t) snapshot_mesgs[i]);
}
free((genericptr_t)snapshot_mesgs), snapshot_mesgs = (char **)0;
free((genericptr_t) snapshot_mesgs), snapshot_mesgs = (char **) 0;
/* history can resume being updated at will now... */
if (!purged) wins[WIN_MESSAGE]->flags &= ~WIN_LOCKHISTORY;
/* history can resume being updated at will now... */
if (!purged)
wins[WIN_MESSAGE]->flags &= ~WIN_LOCKHISTORY;
}
}
@@ -562,17 +598,17 @@ boolean init;
char *result = 0;
if (init) {
msghistory_snapshot(FALSE);
nxtidx = 0;
msghistory_snapshot(FALSE);
nxtidx = 0;
}
if (snapshot_mesgs) {
nextmesg = snapshot_mesgs[nxtidx++];
if (nextmesg) {
result = (char *)nextmesg;
} else {
free_msghistory_snapshot(FALSE);
}
nextmesg = snapshot_mesgs[nxtidx++];
if (nextmesg) {
result = (char *) nextmesg;
} else {
free_msghistory_snapshot(FALSE);
}
}
return result;
}
@@ -603,28 +639,29 @@ boolean restoring_msghist;
int idx;
if (restoring_msghist && !initd) {
/* we're restoring history from the previous session, but new
messages have already been issued this session ("Restoring...",
for instance); collect current history (ie, those new messages),
and also clear it out so that nothing will be present when the
restored ones are being put into place */
msghistory_snapshot(TRUE);
initd = TRUE;
/* we're restoring history from the previous session, but new
messages have already been issued this session ("Restoring...",
for instance); collect current history (ie, those new messages),
and also clear it out so that nothing will be present when the
restored ones are being put into place */
msghistory_snapshot(TRUE);
initd = TRUE;
}
if (msg) {
/* move most recent message to history, make this become most recent */
remember_topl();
Strcpy(toplines, msg);
/* move most recent message to history, make this become most recent
*/
remember_topl();
Strcpy(toplines, msg);
} else if (snapshot_mesgs) {
/* done putting arbitrary messages in; put the snapshot ones back */
for (idx = 0; snapshot_mesgs[idx]; ++idx) {
remember_topl();
Strcpy(toplines, snapshot_mesgs[idx]);
}
/* now release the snapshot */
free_msghistory_snapshot(TRUE);
initd = FALSE; /* reset */
/* done putting arbitrary messages in; put the snapshot ones back */
for (idx = 0; snapshot_mesgs[idx]; ++idx) {
remember_topl();
Strcpy(toplines, snapshot_mesgs[idx]);
}
/* now release the snapshot */
free_msghistory_snapshot(TRUE);
initd = FALSE; /* reset */
}
}
+1891 -1802
View File
File diff suppressed because it is too large Load Diff
+7 -7
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 mhaskyn.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
/* NetHack 3.6 mhaskyn.c $NHDT-Date: 1431192776 2015/05/09 17:32:56 $ $NHDT-Branch: master $:$NHDT-Revision: 1.9 $ */
/* NetHack 3.6 mhaskyn.c $Date: 2009/05/06 10:59:46 $ $Revision: 1.5 $ */
/* SCCS Id: @(#)mhaskyn.c 3.5 2005/01/23 */
/* Copyright (C) 2001 by Alex Kompel */
@@ -8,11 +8,11 @@
#include "winMS.h"
#include "mhaskyn.h"
int mswin_yes_no_dialog( const char *question, const char *choices, int def)
int
mswin_yes_no_dialog(const char *question, const char *choices, int def)
{
UNREFERENCED_PARAMETER(question);
UNREFERENCED_PARAMETER(choices);
UNREFERENCED_PARAMETER(def);
return '\032';
UNREFERENCED_PARAMETER(question);
UNREFERENCED_PARAMETER(choices);
UNREFERENCED_PARAMETER(def);
return '\032';
}
+679 -631
View File
File diff suppressed because it is too large Load Diff
+182 -162
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 mhfont.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
/* NetHack 3.6 mhfont.c $NHDT-Date: 1431192776 2015/05/09 17:32:56 $ $NHDT-Branch: master $:$NHDT-Revision: 1.22 $ */
/* NetHack 3.6 mhfont.c $Date: 2009/05/06 10:59:46 $ $Revision: 1.17 $ */
/* SCCS Id: @(#)mhfont.c 3.5 2005/01/23 */
/* Copyright (C) 2001 by Alex Kompel */
@@ -8,201 +8,221 @@
#include "mhfont.h"
#define MAXFONTS 64
#define MAXFONTS 64
/* font table - 64 fonts ought to be enough */
static struct font_table_entry {
int code;
HFONT hFont;
} font_table[MAXFONTS] ;
int code;
HFONT hFont;
} font_table[MAXFONTS];
static int font_table_size = 0;
HFONT version_splash_font;
#define NHFONT_CODE(win, attr) (((attr&0xFF)<<8)|(win_type&0xFF))
#define NHFONT_CODE(win, attr) (((attr & 0xFF) << 8) | (win_type & 0xFF))
static void __cdecl font_table_cleanup(void);
void mswin_init_splashfonts(HWND hWnd)
void
mswin_init_splashfonts(HWND hWnd)
{
HDC hdc = GetDC(hWnd);
LOGFONT lgfnt;
ZeroMemory( &lgfnt, sizeof(lgfnt) );
lgfnt.lfHeight = -80; // height of font
lgfnt.lfWidth = 0; // average character width
lgfnt.lfEscapement = 0; // angle of escapement
lgfnt.lfOrientation = 0; // base-line orientation angle
lgfnt.lfWeight = FW_BOLD; // font weight
lgfnt.lfItalic = FALSE; // italic attribute option
lgfnt.lfUnderline = FALSE; // underline attribute option
lgfnt.lfStrikeOut = FALSE; // strikeout attribute option
lgfnt.lfCharSet = ANSI_CHARSET; // character set identifier
lgfnt.lfOutPrecision = OUT_DEFAULT_PRECIS; // output precision
lgfnt.lfClipPrecision = CLIP_DEFAULT_PRECIS; // clipping precision
lgfnt.lfQuality = DEFAULT_QUALITY; // output quality
lgfnt.lfPitchAndFamily = DEFAULT_PITCH; // pitch and family
NH_A2W( "Times New Roman", lgfnt.lfFaceName, LF_FACESIZE);
version_splash_font = CreateFontIndirect(&lgfnt);
ReleaseDC(hWnd, hdc);
HDC hdc = GetDC(hWnd);
LOGFONT lgfnt;
ZeroMemory(&lgfnt, sizeof(lgfnt));
lgfnt.lfHeight = -80; // height of font
lgfnt.lfWidth = 0; // average character width
lgfnt.lfEscapement = 0; // angle of escapement
lgfnt.lfOrientation = 0; // base-line orientation angle
lgfnt.lfWeight = FW_BOLD; // font weight
lgfnt.lfItalic = FALSE; // italic attribute option
lgfnt.lfUnderline = FALSE; // underline attribute option
lgfnt.lfStrikeOut = FALSE; // strikeout attribute option
lgfnt.lfCharSet = ANSI_CHARSET; // character set identifier
lgfnt.lfOutPrecision = OUT_DEFAULT_PRECIS; // output precision
lgfnt.lfClipPrecision = CLIP_DEFAULT_PRECIS; // clipping precision
lgfnt.lfQuality = DEFAULT_QUALITY; // output quality
lgfnt.lfPitchAndFamily = DEFAULT_PITCH; // pitch and family
NH_A2W("Times New Roman", lgfnt.lfFaceName, LF_FACESIZE);
version_splash_font = CreateFontIndirect(&lgfnt);
ReleaseDC(hWnd, hdc);
}
void mswin_destroy_splashfonts()
void
mswin_destroy_splashfonts()
{
DeleteObject (version_splash_font);
DeleteObject(version_splash_font);
}
/* create font based on window type, charater attributes and
window device context */
HGDIOBJ mswin_get_font(int win_type, int attr, HDC hdc, BOOL replace)
HGDIOBJ
mswin_get_font(int win_type, int attr, HDC hdc, BOOL replace)
{
HFONT fnt = NULL;
LOGFONT lgfnt;
int font_size;
int font_index;
static BOOL once = FALSE;
HFONT fnt = NULL;
LOGFONT lgfnt;
int font_size;
int font_index;
static BOOL once = FALSE;
if( !once ) {
once = TRUE;
atexit(font_table_cleanup);
}
if (!once) {
once = TRUE;
atexit(font_table_cleanup);
}
ZeroMemory( &lgfnt, sizeof(lgfnt) );
ZeroMemory(&lgfnt, sizeof(lgfnt));
/* try find font in the table */
for(font_index=0; font_index<font_table_size; font_index++)
if(NHFONT_CODE(win_type, attr)==font_table[font_index].code)
break;
/* try find font in the table */
for (font_index = 0; font_index < font_table_size; font_index++)
if (NHFONT_CODE(win_type, attr) == font_table[font_index].code)
break;
if( !replace && font_index<font_table_size )
return font_table[font_index].hFont;
if (!replace && font_index < font_table_size)
return font_table[font_index].hFont;
switch(win_type) {
case NHW_STATUS:
font_size = (attr==ATR_BOLD)? iflags.wc_fontsiz_status+1 : iflags.wc_fontsiz_status;
lgfnt.lfHeight = -font_size*GetDeviceCaps(hdc, LOGPIXELSY)/72; // height of font
lgfnt.lfWidth = 0; // average character width
lgfnt.lfEscapement = 0; // angle of escapement
lgfnt.lfOrientation = 0; // base-line orientation angle
lgfnt.lfWeight = (attr==ATR_BOLD)? FW_BOLD : FW_NORMAL; // font weight
lgfnt.lfItalic = FALSE; // italic attribute option
lgfnt.lfUnderline = FALSE; // underline attribute option
lgfnt.lfStrikeOut = FALSE; // strikeout attribute option
lgfnt.lfCharSet = mswin_charset(); // character set identifier
lgfnt.lfOutPrecision = OUT_DEFAULT_PRECIS; // output precision
lgfnt.lfClipPrecision = CLIP_DEFAULT_PRECIS; // clipping precision
lgfnt.lfQuality = DEFAULT_QUALITY; // output quality
if( iflags.wc_font_status &&
*iflags.wc_font_status ) {
lgfnt.lfPitchAndFamily = DEFAULT_PITCH; // pitch and family
NH_A2W( iflags.wc_font_status, lgfnt.lfFaceName, LF_FACESIZE);
} else {
lgfnt.lfPitchAndFamily = FIXED_PITCH; // pitch and family
}
break;
switch (win_type) {
case NHW_STATUS:
font_size = (attr == ATR_BOLD) ? iflags.wc_fontsiz_status + 1
: iflags.wc_fontsiz_status;
lgfnt.lfHeight = -font_size * GetDeviceCaps(hdc, LOGPIXELSY)
/ 72; // height of font
lgfnt.lfWidth = 0; // average character width
lgfnt.lfEscapement = 0; // angle of escapement
lgfnt.lfOrientation = 0; // base-line orientation angle
lgfnt.lfWeight =
(attr == ATR_BOLD) ? FW_BOLD : FW_NORMAL; // font weight
lgfnt.lfItalic = FALSE; // italic attribute option
lgfnt.lfUnderline = FALSE; // underline attribute option
lgfnt.lfStrikeOut = FALSE; // strikeout attribute option
lgfnt.lfCharSet = mswin_charset(); // character set identifier
lgfnt.lfOutPrecision = OUT_DEFAULT_PRECIS; // output precision
lgfnt.lfClipPrecision = CLIP_DEFAULT_PRECIS; // clipping precision
lgfnt.lfQuality = DEFAULT_QUALITY; // output quality
if (iflags.wc_font_status && *iflags.wc_font_status) {
lgfnt.lfPitchAndFamily = DEFAULT_PITCH; // pitch and family
NH_A2W(iflags.wc_font_status, lgfnt.lfFaceName, LF_FACESIZE);
} else {
lgfnt.lfPitchAndFamily = FIXED_PITCH; // pitch and family
}
break;
case NHW_MENU:
lgfnt.lfHeight = -iflags.wc_fontsiz_menu*GetDeviceCaps(hdc, LOGPIXELSY)/72; // height of font
lgfnt.lfWidth = 0; // average character width
lgfnt.lfEscapement = 0; // angle of escapement
lgfnt.lfOrientation = 0; // base-line orientation angle
lgfnt.lfWeight = (attr==ATR_BOLD || attr==ATR_INVERSE)? FW_BOLD : FW_NORMAL; // font weight
lgfnt.lfItalic = (attr==ATR_BLINK)? TRUE: FALSE; // italic attribute option
lgfnt.lfUnderline = (attr==ATR_ULINE)? TRUE : FALSE; // underline attribute option
lgfnt.lfStrikeOut = FALSE; // strikeout attribute option
lgfnt.lfCharSet = mswin_charset(); // character set identifier
lgfnt.lfOutPrecision = OUT_DEFAULT_PRECIS; // output precision
lgfnt.lfClipPrecision = CLIP_DEFAULT_PRECIS; // clipping precision
lgfnt.lfQuality = DEFAULT_QUALITY; // output quality
if( iflags.wc_font_menu &&
*iflags.wc_font_menu ) {
lgfnt.lfPitchAndFamily = DEFAULT_PITCH; // pitch and family
NH_A2W( iflags.wc_font_menu, lgfnt.lfFaceName, LF_FACESIZE);
} else {
lgfnt.lfPitchAndFamily = FIXED_PITCH; // pitch and family
}
break;
case NHW_MENU:
lgfnt.lfHeight = -iflags.wc_fontsiz_menu
* GetDeviceCaps(hdc, LOGPIXELSY)
/ 72; // height of font
lgfnt.lfWidth = 0; // average character width
lgfnt.lfEscapement = 0; // angle of escapement
lgfnt.lfOrientation = 0; // base-line orientation angle
lgfnt.lfWeight = (attr == ATR_BOLD || attr == ATR_INVERSE)
? FW_BOLD
: FW_NORMAL; // font weight
lgfnt.lfItalic =
(attr == ATR_BLINK) ? TRUE : FALSE; // italic attribute option
lgfnt.lfUnderline =
(attr == ATR_ULINE) ? TRUE : FALSE; // underline attribute option
lgfnt.lfStrikeOut = FALSE; // strikeout attribute option
lgfnt.lfCharSet = mswin_charset(); // character set identifier
lgfnt.lfOutPrecision = OUT_DEFAULT_PRECIS; // output precision
lgfnt.lfClipPrecision = CLIP_DEFAULT_PRECIS; // clipping precision
lgfnt.lfQuality = DEFAULT_QUALITY; // output quality
if (iflags.wc_font_menu && *iflags.wc_font_menu) {
lgfnt.lfPitchAndFamily = DEFAULT_PITCH; // pitch and family
NH_A2W(iflags.wc_font_menu, lgfnt.lfFaceName, LF_FACESIZE);
} else {
lgfnt.lfPitchAndFamily = FIXED_PITCH; // pitch and family
}
break;
case NHW_MESSAGE:
font_size = (attr==ATR_INVERSE)? iflags.wc_fontsiz_message+1 : iflags.wc_fontsiz_message;
lgfnt.lfHeight = -font_size*GetDeviceCaps(hdc, LOGPIXELSY)/72; // height of font
lgfnt.lfWidth = 0; // average character width
lgfnt.lfEscapement = 0; // angle of escapement
lgfnt.lfOrientation = 0; // base-line orientation angle
lgfnt.lfWeight = (attr==ATR_BOLD || attr==ATR_INVERSE)? FW_BOLD : FW_NORMAL; // font weight
lgfnt.lfItalic = (attr==ATR_BLINK)? TRUE: FALSE; // italic attribute option
lgfnt.lfUnderline = (attr==ATR_ULINE)? TRUE : FALSE; // underline attribute option
lgfnt.lfStrikeOut = FALSE; // strikeout attribute option
lgfnt.lfCharSet = mswin_charset(); // character set identifier
lgfnt.lfOutPrecision = OUT_DEFAULT_PRECIS; // output precision
lgfnt.lfClipPrecision = CLIP_DEFAULT_PRECIS; // clipping precision
lgfnt.lfQuality = DEFAULT_QUALITY; // output quality
if( iflags.wc_font_message &&
*iflags.wc_font_message ) {
lgfnt.lfPitchAndFamily = DEFAULT_PITCH; // pitch and family
NH_A2W( iflags.wc_font_message, lgfnt.lfFaceName, LF_FACESIZE);
} else {
lgfnt.lfPitchAndFamily = VARIABLE_PITCH; // pitch and family
}
break;
case NHW_MESSAGE:
font_size = (attr == ATR_INVERSE) ? iflags.wc_fontsiz_message + 1
: iflags.wc_fontsiz_message;
lgfnt.lfHeight = -font_size * GetDeviceCaps(hdc, LOGPIXELSY)
/ 72; // height of font
lgfnt.lfWidth = 0; // average character width
lgfnt.lfEscapement = 0; // angle of escapement
lgfnt.lfOrientation = 0; // base-line orientation angle
lgfnt.lfWeight = (attr == ATR_BOLD || attr == ATR_INVERSE)
? FW_BOLD
: FW_NORMAL; // font weight
lgfnt.lfItalic =
(attr == ATR_BLINK) ? TRUE : FALSE; // italic attribute option
lgfnt.lfUnderline =
(attr == ATR_ULINE) ? TRUE : FALSE; // underline attribute option
lgfnt.lfStrikeOut = FALSE; // strikeout attribute option
lgfnt.lfCharSet = mswin_charset(); // character set identifier
lgfnt.lfOutPrecision = OUT_DEFAULT_PRECIS; // output precision
lgfnt.lfClipPrecision = CLIP_DEFAULT_PRECIS; // clipping precision
lgfnt.lfQuality = DEFAULT_QUALITY; // output quality
if (iflags.wc_font_message && *iflags.wc_font_message) {
lgfnt.lfPitchAndFamily = DEFAULT_PITCH; // pitch and family
NH_A2W(iflags.wc_font_message, lgfnt.lfFaceName, LF_FACESIZE);
} else {
lgfnt.lfPitchAndFamily = VARIABLE_PITCH; // pitch and family
}
break;
case NHW_TEXT:
lgfnt.lfHeight = -iflags.wc_fontsiz_text*GetDeviceCaps(hdc, LOGPIXELSY)/72; // height of font
lgfnt.lfWidth = 0; // average character width
lgfnt.lfEscapement = 0; // angle of escapement
lgfnt.lfOrientation = 0; // base-line orientation angle
lgfnt.lfWeight = (attr==ATR_BOLD || attr==ATR_INVERSE)? FW_BOLD : FW_NORMAL; // font weight
lgfnt.lfItalic = (attr==ATR_BLINK)? TRUE: FALSE; // italic attribute option
lgfnt.lfUnderline = (attr==ATR_ULINE)? TRUE : FALSE; // underline attribute option
lgfnt.lfStrikeOut = FALSE; // strikeout attribute option
lgfnt.lfCharSet = mswin_charset(); // character set identifier
lgfnt.lfOutPrecision = OUT_DEFAULT_PRECIS; // output precision
lgfnt.lfClipPrecision = CLIP_DEFAULT_PRECIS; // clipping precision
lgfnt.lfQuality = DEFAULT_QUALITY; // output quality
if( iflags.wc_font_text &&
*iflags.wc_font_text ) {
lgfnt.lfPitchAndFamily = DEFAULT_PITCH; // pitch and family
NH_A2W( iflags.wc_font_text, lgfnt.lfFaceName, LF_FACESIZE);
} else {
lgfnt.lfPitchAndFamily = FIXED_PITCH; // pitch and family
}
break;
}
case NHW_TEXT:
lgfnt.lfHeight = -iflags.wc_fontsiz_text
* GetDeviceCaps(hdc, LOGPIXELSY)
/ 72; // height of font
lgfnt.lfWidth = 0; // average character width
lgfnt.lfEscapement = 0; // angle of escapement
lgfnt.lfOrientation = 0; // base-line orientation angle
lgfnt.lfWeight = (attr == ATR_BOLD || attr == ATR_INVERSE)
? FW_BOLD
: FW_NORMAL; // font weight
lgfnt.lfItalic =
(attr == ATR_BLINK) ? TRUE : FALSE; // italic attribute option
lgfnt.lfUnderline =
(attr == ATR_ULINE) ? TRUE : FALSE; // underline attribute option
lgfnt.lfStrikeOut = FALSE; // strikeout attribute option
lgfnt.lfCharSet = mswin_charset(); // character set identifier
lgfnt.lfOutPrecision = OUT_DEFAULT_PRECIS; // output precision
lgfnt.lfClipPrecision = CLIP_DEFAULT_PRECIS; // clipping precision
lgfnt.lfQuality = DEFAULT_QUALITY; // output quality
if (iflags.wc_font_text && *iflags.wc_font_text) {
lgfnt.lfPitchAndFamily = DEFAULT_PITCH; // pitch and family
NH_A2W(iflags.wc_font_text, lgfnt.lfFaceName, LF_FACESIZE);
} else {
lgfnt.lfPitchAndFamily = FIXED_PITCH; // pitch and family
}
break;
}
fnt = CreateFontIndirect(&lgfnt);
fnt = CreateFontIndirect(&lgfnt);
/* add font to the table */
if( font_index==font_table_size ) {
if( font_table_size>=MAXFONTS ) panic( "font table overflow!" );
font_table_size++;
} else {
DeleteObject(font_table[font_index].hFont);
}
/* add font to the table */
if (font_index == font_table_size) {
if (font_table_size >= MAXFONTS)
panic("font table overflow!");
font_table_size++;
} else {
DeleteObject(font_table[font_index].hFont);
}
font_table[font_index].code = NHFONT_CODE(win_type, attr);
font_table[font_index].hFont = fnt;
return fnt;
font_table[font_index].code = NHFONT_CODE(win_type, attr);
font_table[font_index].hFont = fnt;
return fnt;
}
UINT mswin_charset()
UINT
mswin_charset()
{
CHARSETINFO cis;
if( SYMHANDLING(H_IBM) )
if( TranslateCharsetInfo((DWORD*)GetOEMCP(), &cis, TCI_SRCCODEPAGE) )
return cis.ciCharset;
else
return OEM_CHARSET;
else
if( TranslateCharsetInfo((DWORD*)GetACP(), &cis, TCI_SRCCODEPAGE) )
return cis.ciCharset;
else
return ANSI_CHARSET;
CHARSETINFO cis;
if (SYMHANDLING(H_IBM))
if (TranslateCharsetInfo((DWORD *) GetOEMCP(), &cis, TCI_SRCCODEPAGE))
return cis.ciCharset;
else
return OEM_CHARSET;
else if (TranslateCharsetInfo((DWORD *) GetACP(), &cis, TCI_SRCCODEPAGE))
return cis.ciCharset;
else
return ANSI_CHARSET;
}
void __cdecl font_table_cleanup(void)
{
int i;
for(i=0; i<font_table_size; i++) {
DeleteObject(font_table[i].hFont);
}
font_table_size = 0;
int i;
for (i = 0; i < font_table_size; i++) {
DeleteObject(font_table[i].hFont);
}
font_table_size = 0;
}
+64 -58
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 mhinput.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
/* NetHack 3.6 mhinput.c $NHDT-Date: 1431192776 2015/05/09 17:32:56 $ $NHDT-Branch: master $:$NHDT-Revision: 1.10 $ */
/* NetHack 3.6 mhinput.c $Date: 2009/05/06 10:59:48 $ $Revision: 1.7 $ */
/* SCCS Id: @(#)mhinput.c 3.5 2005/01/23 */
/* Copyright (C) 2001 by Alex Kompel */
@@ -10,9 +10,9 @@
/* nethack input queue functions */
#define NH_INPUT_BUFFER_SIZE 64
#define NH_INPUT_BUFFER_SIZE 64
/* as it stands right now we need only one slot
/* as it stands right now we need only one slot
since events are processed almost the same time as
they occur but I like large round numbers */
@@ -22,93 +22,99 @@ static int nhi_read_pos = 0;
static int nhi_write_pos = 0;
/* initialize input queue */
void mswin_nh_input_init(void)
void
mswin_nh_input_init(void)
{
if( !nhi_init_input ) {
nhi_init_input = 1;
if (!nhi_init_input) {
nhi_init_input = 1;
ZeroMemory( nhi_input_buffer, sizeof(nhi_input_buffer) );
nhi_read_pos = 0;
nhi_write_pos = 0;
}
ZeroMemory(nhi_input_buffer, sizeof(nhi_input_buffer));
nhi_read_pos = 0;
nhi_write_pos = 0;
}
}
/* check for input */
int mswin_have_input()
int
mswin_have_input()
{
return
return
#ifdef SAFERHANGUP
/* we always have input (ESC) if hangup was requested */
program_state.done_hup ||
/* we always have input (ESC) if hangup was requested */
program_state.done_hup ||
#endif
(nhi_read_pos!=nhi_write_pos);
(nhi_read_pos != nhi_write_pos);
}
/* add event to the queue */
void mswin_input_push(PMSNHEvent event)
void
mswin_input_push(PMSNHEvent event)
{
int new_write_pos;
int new_write_pos;
if( !nhi_init_input ) mswin_nh_input_init();
if (!nhi_init_input)
mswin_nh_input_init();
new_write_pos = (nhi_write_pos+1) % NH_INPUT_BUFFER_SIZE;
if(new_write_pos!=nhi_read_pos) {
memcpy(nhi_input_buffer+nhi_write_pos, event, sizeof(*event));
nhi_write_pos = new_write_pos;
}
new_write_pos = (nhi_write_pos + 1) % NH_INPUT_BUFFER_SIZE;
if (new_write_pos != nhi_read_pos) {
memcpy(nhi_input_buffer + nhi_write_pos, event, sizeof(*event));
nhi_write_pos = new_write_pos;
}
}
/* get event from the queue and delete it */
PMSNHEvent mswin_input_pop()
PMSNHEvent
mswin_input_pop()
{
PMSNHEvent retval;
PMSNHEvent retval;
#ifdef SAFERHANGUP
/* always return ESC when hangup was requested */
if( program_state.done_hup ) {
static MSNHEvent hangup_event;
hangup_event.type = NHEVENT_CHAR;
hangup_event.kbd.ch = '\033';
return &hangup_event;
}
/* always return ESC when hangup was requested */
if (program_state.done_hup) {
static MSNHEvent hangup_event;
hangup_event.type = NHEVENT_CHAR;
hangup_event.kbd.ch = '\033';
return &hangup_event;
}
#endif
if( !nhi_init_input ) mswin_nh_input_init();
if (!nhi_init_input)
mswin_nh_input_init();
if( nhi_read_pos!=nhi_write_pos ) {
retval = &nhi_input_buffer[nhi_read_pos];
nhi_read_pos = (nhi_read_pos+1) % NH_INPUT_BUFFER_SIZE;
} else {
retval = NULL;
}
if (nhi_read_pos != nhi_write_pos) {
retval = &nhi_input_buffer[nhi_read_pos];
nhi_read_pos = (nhi_read_pos + 1) % NH_INPUT_BUFFER_SIZE;
} else {
retval = NULL;
}
return retval;
return retval;
}
/* get event from the queue but leave it there */
PMSNHEvent mswin_input_peek()
PMSNHEvent
mswin_input_peek()
{
PMSNHEvent retval;
PMSNHEvent retval;
#ifdef SAFERHANGUP
/* always return ESC when hangup was requested */
if( program_state.done_hup ) {
static MSNHEvent hangup_event;
hangup_event.type = NHEVENT_CHAR;
hangup_event.kbd.ch = '\033';
return &hangup_event;
}
/* always return ESC when hangup was requested */
if (program_state.done_hup) {
static MSNHEvent hangup_event;
hangup_event.type = NHEVENT_CHAR;
hangup_event.kbd.ch = '\033';
return &hangup_event;
}
#endif
if( !nhi_init_input ) mswin_nh_input_init();
if (!nhi_init_input)
mswin_nh_input_init();
if( nhi_read_pos!=nhi_write_pos ) {
retval = &nhi_input_buffer[nhi_read_pos];
} else {
retval = NULL;
}
return retval;
if (nhi_read_pos != nhi_write_pos) {
retval = &nhi_input_buffer[nhi_read_pos];
} else {
retval = NULL;
}
return retval;
}
+947 -992
View File
File diff suppressed because it is too large Load Diff
+845 -812
View File
File diff suppressed because it is too large Load Diff
+1360 -1312
View File
File diff suppressed because it is too large Load Diff
+745 -696
View File
File diff suppressed because it is too large Load Diff
+231 -224
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 mhrip.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
/* NetHack 3.6 mhrip.c $NHDT-Date: 1431192777 2015/05/09 17:32:57 $ $NHDT-Branch: master $:$NHDT-Revision: 1.18 $ */
/* NetHack 3.6 mhrip.c $Date: 2012/01/11 01:45:02 $ $Revision: 1.13 $ */
/* Copyright (C) 2001 by Alex Kompel */
/* NetHack may be freely redistributed. See license for details. */
@@ -9,260 +9,267 @@
#include "mhmsg.h"
#include "mhfont.h"
#define RIP_WIDTH 400
#define RIP_HEIGHT 200
#define RIP_WIDTH 400
#define RIP_HEIGHT 200
#define RIP_GRAVE_HEIGHT 120
#define RIP_GRAVE_WIDTH 115
#define RIP_GRAVE_X 90
#define RIP_GRAVE_Y 60
#define RIP_GRAVE_HEIGHT 120
#define RIP_GRAVE_WIDTH 115
#define RIP_GRAVE_X 90
#define RIP_GRAVE_Y 60
#define RIP_OFFSET_X 10
#define RIP_OFFSET_Y 10
#define RIP_OFFSET_X 10
#define RIP_OFFSET_Y 10
PNHWinApp GetNHApp(void);
typedef struct mswin_nethack_text_window {
HANDLE rip_bmp;
TCHAR* window_text;
TCHAR* rip_text;
HANDLE rip_bmp;
TCHAR *window_text;
TCHAR *rip_text;
} NHRIPWindow, *PNHRIPWindow;
INT_PTR CALLBACK NHRIPWndProc(HWND, UINT, WPARAM, LPARAM);
static void onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam);
HWND mswin_init_RIP_window () {
HWND ret;
PNHRIPWindow data;
ret = CreateDialog(
GetNHApp()->hApp,
MAKEINTRESOURCE(IDD_NHRIP),
GetNHApp()->hMainWnd,
NHRIPWndProc
);
if( !ret ) panic("Cannot create rip window");
data = (PNHRIPWindow)malloc(sizeof(NHRIPWindow));
if( !data ) panic("out of memory");
ZeroMemory(data, sizeof(NHRIPWindow));
SetWindowLongPtr(ret, GWLP_USERDATA, (LONG_PTR)data);
return ret;
}
void mswin_display_RIP_window (HWND hWnd)
HWND
mswin_init_RIP_window()
{
MSG msg;
RECT rt;
PNHRIPWindow data;
HWND mapWnd;
RECT riprt;
RECT clientrect;
RECT textrect;
HDC hdc;
HFONT OldFont;
HWND ret;
PNHRIPWindow data;
data = (PNHRIPWindow)GetWindowLongPtr(hWnd, GWLP_USERDATA);
ret = CreateDialog(GetNHApp()->hApp, MAKEINTRESOURCE(IDD_NHRIP),
GetNHApp()->hMainWnd, NHRIPWndProc);
if (!ret)
panic("Cannot create rip window");
GetNHApp()->hPopupWnd = hWnd;
mapWnd = mswin_hwnd_from_winid(WIN_MAP);
if( !IsWindow(mapWnd) ) mapWnd = GetNHApp()->hMainWnd;
GetWindowRect(mapWnd, &rt);
GetWindowRect(hWnd, &riprt);
GetClientRect (hWnd, &clientrect);
textrect = clientrect;
textrect.top += RIP_OFFSET_Y;
textrect.left += RIP_OFFSET_X;
textrect.right -= RIP_OFFSET_X;
if (data->window_text)
{
hdc = GetDC (hWnd);
OldFont = SelectObject (hdc, mswin_get_font(NHW_TEXT, 0, hdc, FALSE));
DrawText (hdc, data->window_text, strlen(data->window_text), &textrect,
DT_LEFT | DT_NOPREFIX | DT_CALCRECT);
SelectObject (hdc, OldFont);
ReleaseDC(hWnd, hdc);
}
if (textrect.right - textrect.left > RIP_WIDTH)
clientrect.right = textrect.right + RIP_OFFSET_X - clientrect.right;
else
clientrect.right = textrect.left + 2 * RIP_OFFSET_X + RIP_WIDTH - clientrect.right;
clientrect.bottom = textrect.bottom + RIP_HEIGHT + RIP_OFFSET_Y - clientrect.bottom;
GetWindowRect (GetDlgItem(hWnd, IDOK), &textrect);
textrect.right -= textrect.left;
textrect.bottom -= textrect.top;
clientrect.bottom += textrect.bottom + RIP_OFFSET_Y;
riprt.right -= riprt.left;
riprt.bottom -= riprt.top;
riprt.right += clientrect.right;
riprt.bottom += clientrect.bottom;
rt.left += (rt.right - rt.left - riprt.right) / 2;
rt.top += (rt.bottom - rt.top - riprt.bottom) / 2;
data = (PNHRIPWindow) malloc(sizeof(NHRIPWindow));
if (!data)
panic("out of memory");
MoveWindow(hWnd, rt.left, rt.top, riprt.right, riprt.bottom, TRUE);
GetClientRect (hWnd, &clientrect);
MoveWindow (GetDlgItem(hWnd, IDOK),
(clientrect.right - clientrect.left - textrect.right) / 2,
clientrect.bottom - textrect.bottom - RIP_OFFSET_Y, textrect.right, textrect.bottom, TRUE);
ShowWindow(hWnd, SW_SHOW);
while( IsWindow(hWnd) &&
GetMessage(&msg, NULL, 0, 0)!=0 ) {
if( !IsDialogMessage(hWnd, &msg) ) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
GetNHApp()->hPopupWnd = NULL;
ZeroMemory(data, sizeof(NHRIPWindow));
SetWindowLongPtr(ret, GWLP_USERDATA, (LONG_PTR) data);
return ret;
}
INT_PTR CALLBACK NHRIPWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
void
mswin_display_RIP_window(HWND hWnd)
{
HDC hdc;
PNHRIPWindow data;
MSG msg;
RECT rt;
PNHRIPWindow data;
HWND mapWnd;
RECT riprt;
RECT clientrect;
RECT textrect;
HDC hdc;
HFONT OldFont;
data = (PNHRIPWindow)GetWindowLongPtr(hWnd, GWLP_USERDATA);
switch (message)
{
case WM_INITDIALOG:
/* set text control font */
hdc = GetDC(hWnd);
SendMessage(hWnd, WM_SETFONT,
(WPARAM)mswin_get_font(NHW_TEXT, ATR_NONE, hdc, FALSE), 0);
ReleaseDC(hWnd, hdc);
data = (PNHRIPWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA);
SetFocus(GetDlgItem(hWnd, IDOK));
return FALSE;
GetNHApp()->hPopupWnd = hWnd;
mapWnd = mswin_hwnd_from_winid(WIN_MAP);
if (!IsWindow(mapWnd))
mapWnd = GetNHApp()->hMainWnd;
GetWindowRect(mapWnd, &rt);
GetWindowRect(hWnd, &riprt);
GetClientRect(hWnd, &clientrect);
textrect = clientrect;
textrect.top += RIP_OFFSET_Y;
textrect.left += RIP_OFFSET_X;
textrect.right -= RIP_OFFSET_X;
if (data->window_text) {
hdc = GetDC(hWnd);
OldFont = SelectObject(hdc, mswin_get_font(NHW_TEXT, 0, hdc, FALSE));
DrawText(hdc, data->window_text, strlen(data->window_text), &textrect,
DT_LEFT | DT_NOPREFIX | DT_CALCRECT);
SelectObject(hdc, OldFont);
ReleaseDC(hWnd, hdc);
}
if (textrect.right - textrect.left > RIP_WIDTH)
clientrect.right = textrect.right + RIP_OFFSET_X - clientrect.right;
else
clientrect.right =
textrect.left + 2 * RIP_OFFSET_X + RIP_WIDTH - clientrect.right;
clientrect.bottom =
textrect.bottom + RIP_HEIGHT + RIP_OFFSET_Y - clientrect.bottom;
GetWindowRect(GetDlgItem(hWnd, IDOK), &textrect);
textrect.right -= textrect.left;
textrect.bottom -= textrect.top;
clientrect.bottom += textrect.bottom + RIP_OFFSET_Y;
riprt.right -= riprt.left;
riprt.bottom -= riprt.top;
riprt.right += clientrect.right;
riprt.bottom += clientrect.bottom;
rt.left += (rt.right - rt.left - riprt.right) / 2;
rt.top += (rt.bottom - rt.top - riprt.bottom) / 2;
case WM_MSNH_COMMAND:
onMSNHCommand(hWnd, wParam, lParam);
break;
MoveWindow(hWnd, rt.left, rt.top, riprt.right, riprt.bottom, TRUE);
GetClientRect(hWnd, &clientrect);
MoveWindow(GetDlgItem(hWnd, IDOK),
(clientrect.right - clientrect.left - textrect.right) / 2,
clientrect.bottom - textrect.bottom - RIP_OFFSET_Y,
textrect.right, textrect.bottom, TRUE);
ShowWindow(hWnd, SW_SHOW);
case WM_PAINT:
{
int bitmap_offset;
RECT clientrect;
RECT textrect;
HDC hdcBitmap;
HANDLE OldBitmap;
PAINTSTRUCT ps;
HFONT OldFont;
while (IsWindow(hWnd) && GetMessage(&msg, NULL, 0, 0) != 0) {
if (!IsDialogMessage(hWnd, &msg)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
hdc = BeginPaint (hWnd, &ps);
OldFont = SelectObject (hdc, mswin_get_font(NHW_TEXT, 0, hdc, FALSE));
hdcBitmap = CreateCompatibleDC(hdc);
SetBkMode (hdc, TRANSPARENT);
GetClientRect (hWnd, &clientrect);
textrect = clientrect;
textrect.top += RIP_OFFSET_Y;
textrect.left += RIP_OFFSET_X;
textrect.right -= RIP_OFFSET_X;
if (data->window_text)
{
DrawText (hdc, data->window_text, strlen(data->window_text), &textrect,
DT_LEFT | DT_NOPREFIX | DT_CALCRECT);
DrawText (hdc, data->window_text, strlen(data->window_text), &textrect,
DT_LEFT | DT_NOPREFIX);
}
OldBitmap = SelectObject(hdcBitmap, GetNHApp()->bmpRip);
SetBkMode (hdc, OPAQUE);
bitmap_offset = (textrect.right - textrect.left - RIP_WIDTH) / 2;
BitBlt (hdc, textrect.left + bitmap_offset, textrect.bottom, RIP_WIDTH,
RIP_HEIGHT, hdcBitmap, 0, 0, SRCCOPY);
SetBkMode (hdc, TRANSPARENT);
if (data->rip_text)
{
textrect.left += RIP_GRAVE_X + bitmap_offset;
textrect.top = textrect.bottom + RIP_GRAVE_Y;
textrect.right = textrect.left + RIP_GRAVE_WIDTH;
textrect.bottom = textrect.top + RIP_GRAVE_HEIGHT;
DrawText (hdc, data->rip_text, strlen(data->rip_text), &textrect,
DT_CENTER | DT_VCENTER | DT_NOPREFIX | DT_WORDBREAK);
}
SelectObject (hdcBitmap, OldBitmap);
SelectObject (hdc, OldFont);
DeleteDC (hdcBitmap);
EndPaint (hWnd, &ps);
}
break;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDOK:
mswin_window_mark_dead(mswin_winid_from_handle(hWnd));
if( GetNHApp()->hMainWnd==hWnd )
GetNHApp()->hMainWnd=NULL;
DestroyWindow(hWnd);
SetFocus(GetNHApp()->hMainWnd);
return TRUE;
}
break;
case WM_CLOSE:
/* if we get this here, we saved the bones so we can just force a quit */
mswin_window_mark_dead(mswin_winid_from_handle(hWnd));
if( GetNHApp()->hMainWnd==hWnd )
GetNHApp()->hMainWnd=NULL;
DestroyWindow(hWnd);
SetFocus(GetNHApp()->hMainWnd);
program_state.stopprint++;
return TRUE;
case WM_DESTROY:
if( data ) {
if( data->window_text ) free(data->window_text);
if( data->rip_text ) free(data->rip_text);
if (data->rip_bmp != NULL) DeleteObject(data->rip_bmp);
free(data);
SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)0);
}
break;
}
return FALSE;
GetNHApp()->hPopupWnd = NULL;
}
void onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
INT_PTR CALLBACK
NHRIPWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PNHRIPWindow data;
static int InRipText = 1;
data = (PNHRIPWindow)GetWindowLongPtr(hWnd, GWLP_USERDATA);
switch( wParam ) {
case MSNH_MSG_PUTSTR: {
PMSNHMsgPutstr msg_data = (PMSNHMsgPutstr)lParam;
TCHAR wbuf[BUFSZ];
size_t text_size;
HDC hdc;
PNHRIPWindow data;
if( !data->window_text ) {
text_size = strlen(msg_data->text) + 4;
data->window_text = (TCHAR*)malloc(text_size*sizeof(data->window_text[0]));
ZeroMemory(data->window_text, text_size*sizeof(data->window_text[0]));
} else {
text_size = _tcslen(data->window_text) + strlen(msg_data->text) + 4;
data->window_text = (TCHAR*)realloc(data->window_text, text_size*sizeof(data->window_text[0]));
}
if( !data->window_text ) break;
data = (PNHRIPWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA);
switch (message) {
case WM_INITDIALOG:
/* set text control font */
hdc = GetDC(hWnd);
SendMessage(hWnd, WM_SETFONT,
(WPARAM) mswin_get_font(NHW_TEXT, ATR_NONE, hdc, FALSE),
0);
ReleaseDC(hWnd, hdc);
_tcscat(data->window_text, NH_A2W(msg_data->text, wbuf, BUFSZ));
_tcscat(data->window_text, TEXT("\r\n"));
break;
}
case MSNH_MSG_DIED:
{
data->rip_text = data->window_text;
data->window_text = NULL;
break;
}
SetFocus(GetDlgItem(hWnd, IDOK));
return FALSE;
}
case WM_MSNH_COMMAND:
onMSNHCommand(hWnd, wParam, lParam);
break;
case WM_PAINT: {
int bitmap_offset;
RECT clientrect;
RECT textrect;
HDC hdcBitmap;
HANDLE OldBitmap;
PAINTSTRUCT ps;
HFONT OldFont;
hdc = BeginPaint(hWnd, &ps);
OldFont = SelectObject(hdc, mswin_get_font(NHW_TEXT, 0, hdc, FALSE));
hdcBitmap = CreateCompatibleDC(hdc);
SetBkMode(hdc, TRANSPARENT);
GetClientRect(hWnd, &clientrect);
textrect = clientrect;
textrect.top += RIP_OFFSET_Y;
textrect.left += RIP_OFFSET_X;
textrect.right -= RIP_OFFSET_X;
if (data->window_text) {
DrawText(hdc, data->window_text, strlen(data->window_text),
&textrect, DT_LEFT | DT_NOPREFIX | DT_CALCRECT);
DrawText(hdc, data->window_text, strlen(data->window_text),
&textrect, DT_LEFT | DT_NOPREFIX);
}
OldBitmap = SelectObject(hdcBitmap, GetNHApp()->bmpRip);
SetBkMode(hdc, OPAQUE);
bitmap_offset = (textrect.right - textrect.left - RIP_WIDTH) / 2;
BitBlt(hdc, textrect.left + bitmap_offset, textrect.bottom, RIP_WIDTH,
RIP_HEIGHT, hdcBitmap, 0, 0, SRCCOPY);
SetBkMode(hdc, TRANSPARENT);
if (data->rip_text) {
textrect.left += RIP_GRAVE_X + bitmap_offset;
textrect.top = textrect.bottom + RIP_GRAVE_Y;
textrect.right = textrect.left + RIP_GRAVE_WIDTH;
textrect.bottom = textrect.top + RIP_GRAVE_HEIGHT;
DrawText(hdc, data->rip_text, strlen(data->rip_text), &textrect,
DT_CENTER | DT_VCENTER | DT_NOPREFIX | DT_WORDBREAK);
}
SelectObject(hdcBitmap, OldBitmap);
SelectObject(hdc, OldFont);
DeleteDC(hdcBitmap);
EndPaint(hWnd, &ps);
} break;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDOK:
mswin_window_mark_dead(mswin_winid_from_handle(hWnd));
if (GetNHApp()->hMainWnd == hWnd)
GetNHApp()->hMainWnd = NULL;
DestroyWindow(hWnd);
SetFocus(GetNHApp()->hMainWnd);
return TRUE;
}
break;
case WM_CLOSE:
/* if we get this here, we saved the bones so we can just force a quit
*/
mswin_window_mark_dead(mswin_winid_from_handle(hWnd));
if (GetNHApp()->hMainWnd == hWnd)
GetNHApp()->hMainWnd = NULL;
DestroyWindow(hWnd);
SetFocus(GetNHApp()->hMainWnd);
program_state.stopprint++;
return TRUE;
case WM_DESTROY:
if (data) {
if (data->window_text)
free(data->window_text);
if (data->rip_text)
free(data->rip_text);
if (data->rip_bmp != NULL)
DeleteObject(data->rip_bmp);
free(data);
SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR) 0);
}
break;
}
return FALSE;
}
void mswin_finish_rip_text(winid wid)
void
onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
SendMessage (mswin_hwnd_from_winid(wid), WM_MSNH_COMMAND, MSNH_MSG_DIED, 0);
PNHRIPWindow data;
static int InRipText = 1;
data = (PNHRIPWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA);
switch (wParam) {
case MSNH_MSG_PUTSTR: {
PMSNHMsgPutstr msg_data = (PMSNHMsgPutstr) lParam;
TCHAR wbuf[BUFSZ];
size_t text_size;
if (!data->window_text) {
text_size = strlen(msg_data->text) + 4;
data->window_text =
(TCHAR *) malloc(text_size * sizeof(data->window_text[0]));
ZeroMemory(data->window_text,
text_size * sizeof(data->window_text[0]));
} else {
text_size =
_tcslen(data->window_text) + strlen(msg_data->text) + 4;
data->window_text = (TCHAR *) realloc(
data->window_text, text_size * sizeof(data->window_text[0]));
}
if (!data->window_text)
break;
_tcscat(data->window_text, NH_A2W(msg_data->text, wbuf, BUFSZ));
_tcscat(data->window_text, TEXT("\r\n"));
break;
}
case MSNH_MSG_DIED: {
data->rip_text = data->window_text;
data->window_text = NULL;
break;
}
}
}
void
mswin_finish_rip_text(winid wid)
{
SendMessage(mswin_hwnd_from_winid(wid), WM_MSNH_COMMAND, MSNH_MSG_DIED,
0);
}
+203 -209
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 mhsplash.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
/* NetHack 3.6 mhsplash.c $NHDT-Date: 1431192777 2015/05/09 17:32:57 $ $NHDT-Branch: master $:$NHDT-Revision: 1.24 $ */
/* NetHack 3.6 mhsplash.c $Date: 2012/01/11 01:15:37 $ $Revision: 1.17 $ */
/* Copyright (C) 2001 by Alex Kompel */
/* NetHack may be freely redistributed. See license for details. */
@@ -18,236 +18,230 @@ PNHWinApp GetNHApp(void);
INT_PTR CALLBACK NHSplashWndProc(HWND, UINT, WPARAM, LPARAM);
#define SPLASH_WIDTH 440
#define SPLASH_HEIGHT 322
#define SPLASH_VERSION_X 290
#define SPLASH_VERSION_Y 10
#define SPLASH_OFFSET_X 10
#define SPLASH_OFFSET_Y 10
#define SPLASH_WIDTH 440
#define SPLASH_HEIGHT 322
#define SPLASH_VERSION_X 290
#define SPLASH_VERSION_Y 10
#define SPLASH_OFFSET_X 10
#define SPLASH_OFFSET_Y 10
extern HFONT version_splash_font;
void mswin_display_splash_window (BOOL show_ver)
void
mswin_display_splash_window(BOOL show_ver)
{
MSG msg;
int left, top;
RECT splashrt;
RECT clientrt;
RECT controlrt;
HWND hWnd;
int buttop;
int strsize = 0;
int bufsize = BUFSZ;
char *buf = malloc(bufsize);
if (buf == NULL)
panic("out of memory");
buf[0] = '\0';
MSG msg;
int left, top;
RECT splashrt;
RECT clientrt;
RECT controlrt;
HWND hWnd;
int buttop;
int strsize = 0;
int bufsize = BUFSZ;
char *buf = malloc(bufsize);
hWnd = CreateDialog(GetNHApp()->hApp, MAKEINTRESOURCE(IDD_SPLASH),
GetNHApp()->hMainWnd, NHSplashWndProc);
if( !hWnd ) panic("Cannot create Splash window");
mswin_init_splashfonts(hWnd);
GetNHApp()->hPopupWnd = hWnd;
/* Get control size */
GetWindowRect (GetDlgItem(hWnd, IDOK), &controlrt);
controlrt.right -= controlrt.left;
controlrt.bottom -= controlrt.top;
/* Get current client area */
GetClientRect (hWnd, &clientrt);
/* Get window size */
GetWindowRect(hWnd, &splashrt);
splashrt.right -= splashrt.left;
splashrt.bottom -= splashrt.top;
/* Get difference between requested client area and current value */
splashrt.right += SPLASH_WIDTH + SPLASH_OFFSET_X * 2 - clientrt.right;
splashrt.bottom += SPLASH_HEIGHT + controlrt.bottom + SPLASH_OFFSET_Y * 3 - clientrt.bottom;
/* Place the window centered */
/* On the screen, not on the parent window */
left = (GetSystemMetrics(SM_CXSCREEN) - splashrt.right) / 2;
top = (GetSystemMetrics(SM_CYSCREEN) - splashrt.bottom) / 2;
MoveWindow(hWnd, left, top, splashrt.right, splashrt.bottom, TRUE);
/* Place the OK control */
GetClientRect (hWnd, &clientrt);
MoveWindow (GetDlgItem(hWnd, IDOK),
(clientrt.right - clientrt.left - controlrt.right) / 2,
clientrt.bottom - controlrt.bottom - SPLASH_OFFSET_Y,
controlrt.right, controlrt.bottom, TRUE);
buttop = clientrt.bottom - controlrt.bottom - SPLASH_OFFSET_Y;
/* Place the text control */
GetWindowRect (GetDlgItem(hWnd, IDC_EXTRAINFO), &controlrt);
controlrt.right -= controlrt.left;
controlrt.bottom -= controlrt.top;
GetClientRect (hWnd, &clientrt);
MoveWindow (GetDlgItem(hWnd, IDC_EXTRAINFO),
clientrt.left + SPLASH_OFFSET_X,
buttop - controlrt.bottom - SPLASH_OFFSET_Y,
clientrt.right - 2 * SPLASH_OFFSET_X, controlrt.bottom, TRUE);
if (buf == NULL)
panic("out of memory");
buf[0] = '\0';
/* Fill the text control */
Sprintf (buf, "%s\r\n%s\r\n%s\r\n%s\r\n\r\n", COPYRIGHT_BANNER_A, COPYRIGHT_BANNER_B,
COPYRIGHT_BANNER_C, COPYRIGHT_BANNER_D);
strsize = strlen(buf);
hWnd = CreateDialog(GetNHApp()->hApp, MAKEINTRESOURCE(IDD_SPLASH),
GetNHApp()->hMainWnd, NHSplashWndProc);
if (!hWnd)
panic("Cannot create Splash window");
mswin_init_splashfonts(hWnd);
GetNHApp()->hPopupWnd = hWnd;
/* Get control size */
GetWindowRect(GetDlgItem(hWnd, IDOK), &controlrt);
controlrt.right -= controlrt.left;
controlrt.bottom -= controlrt.top;
/* Get current client area */
GetClientRect(hWnd, &clientrt);
/* Get window size */
GetWindowRect(hWnd, &splashrt);
splashrt.right -= splashrt.left;
splashrt.bottom -= splashrt.top;
/* Get difference between requested client area and current value */
splashrt.right += SPLASH_WIDTH + SPLASH_OFFSET_X * 2 - clientrt.right;
splashrt.bottom += SPLASH_HEIGHT + controlrt.bottom + SPLASH_OFFSET_Y * 3
- clientrt.bottom;
/* Place the window centered */
/* On the screen, not on the parent window */
left = (GetSystemMetrics(SM_CXSCREEN) - splashrt.right) / 2;
top = (GetSystemMetrics(SM_CYSCREEN) - splashrt.bottom) / 2;
MoveWindow(hWnd, left, top, splashrt.right, splashrt.bottom, TRUE);
/* Place the OK control */
GetClientRect(hWnd, &clientrt);
MoveWindow(GetDlgItem(hWnd, IDOK),
(clientrt.right - clientrt.left - controlrt.right) / 2,
clientrt.bottom - controlrt.bottom - SPLASH_OFFSET_Y,
controlrt.right, controlrt.bottom, TRUE);
buttop = clientrt.bottom - controlrt.bottom - SPLASH_OFFSET_Y;
/* Place the text control */
GetWindowRect(GetDlgItem(hWnd, IDC_EXTRAINFO), &controlrt);
controlrt.right -= controlrt.left;
controlrt.bottom -= controlrt.top;
GetClientRect(hWnd, &clientrt);
MoveWindow(GetDlgItem(hWnd, IDC_EXTRAINFO),
clientrt.left + SPLASH_OFFSET_X,
buttop - controlrt.bottom - SPLASH_OFFSET_Y,
clientrt.right - 2 * SPLASH_OFFSET_X, controlrt.bottom, TRUE);
if (show_ver) {
/* Show complete version information */
dlb *f;
/* Fill the text control */
Sprintf(buf, "%s\r\n%s\r\n%s\r\n%s\r\n\r\n", COPYRIGHT_BANNER_A,
COPYRIGHT_BANNER_B, COPYRIGHT_BANNER_C, COPYRIGHT_BANNER_D);
strsize = strlen(buf);
getversionstring(buf + strsize);
strcat(buf, "\r\n\r\n");
strsize = strlen(buf);
if (show_ver) {
/* Show complete version information */
dlb *f;
/* Add compile options */
f = dlb_fopen(OPTIONS_USED, RDTMODE);
if (f) {
char line[LLEN + 1];
while (dlb_fgets(line, LLEN, f)) {
size_t len;
len = strlen(line);
if (len > 0 && line[len - 1] == '\n') {
line[len - 1] = '\r';
line[len] = '\n';
line[len + 1] = '\0';
len++;
}
if (strsize + (int)len + 1 > bufsize)
{
bufsize += BUFSZ;
buf = realloc(buf, bufsize);
if (buf == NULL)
panic("out of memory");
}
strcat(buf, line);
strsize += len;
}
(void) dlb_fclose(f);
}
} else {
/* Show news, if any */
if (iflags.news) {
FILE *nf;
getversionstring(buf + strsize);
strcat(buf, "\r\n\r\n");
strsize = strlen(buf);
iflags.news = 0; /* prevent newgame() from re-displaying news */
nf = fopen(NEWS, "r");
if (nf != NULL) {
char line[LLEN + 1];
while (fgets(line, LLEN, nf)) {
size_t len;
len = strlen(line);
if (len > 0 && line[len - 1] == '\n') {
line[len - 1] = '\r';
line[len] = '\n';
line[len + 1] = '\0';
len++;
}
if (strsize + (int)len + 1 > bufsize)
{
bufsize += BUFSZ;
buf = realloc(buf, bufsize);
if (buf == NULL)
panic("out of memory");
}
strcat(buf, line);
strsize += len;
}
(void) fclose(nf);
}
else
{
strcat(buf, "No news.");
}
}
}
SetWindowText(GetDlgItem(hWnd, IDC_EXTRAINFO), buf);
free(buf);
ShowWindow(hWnd, SW_SHOW);
/* Add compile options */
f = dlb_fopen(OPTIONS_USED, RDTMODE);
if (f) {
char line[LLEN + 1];
while( IsWindow(hWnd) &&
GetMessage(&msg, NULL, 0, 0)!=0 ) {
if( !IsDialogMessage(hWnd, &msg) ) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
GetNHApp()->hPopupWnd = NULL;
mswin_destroy_splashfonts();
while (dlb_fgets(line, LLEN, f)) {
size_t len;
len = strlen(line);
if (len > 0 && line[len - 1] == '\n') {
line[len - 1] = '\r';
line[len] = '\n';
line[len + 1] = '\0';
len++;
}
if (strsize + (int) len + 1 > bufsize) {
bufsize += BUFSZ;
buf = realloc(buf, bufsize);
if (buf == NULL)
panic("out of memory");
}
strcat(buf, line);
strsize += len;
}
(void) dlb_fclose(f);
}
} else {
/* Show news, if any */
if (iflags.news) {
FILE *nf;
iflags.news = 0; /* prevent newgame() from re-displaying news */
nf = fopen(NEWS, "r");
if (nf != NULL) {
char line[LLEN + 1];
while (fgets(line, LLEN, nf)) {
size_t len;
len = strlen(line);
if (len > 0 && line[len - 1] == '\n') {
line[len - 1] = '\r';
line[len] = '\n';
line[len + 1] = '\0';
len++;
}
if (strsize + (int) len + 1 > bufsize) {
bufsize += BUFSZ;
buf = realloc(buf, bufsize);
if (buf == NULL)
panic("out of memory");
}
strcat(buf, line);
strsize += len;
}
(void) fclose(nf);
} else {
strcat(buf, "No news.");
}
}
}
SetWindowText(GetDlgItem(hWnd, IDC_EXTRAINFO), buf);
free(buf);
ShowWindow(hWnd, SW_SHOW);
while (IsWindow(hWnd) && GetMessage(&msg, NULL, 0, 0) != 0) {
if (!IsDialogMessage(hWnd, &msg)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
GetNHApp()->hPopupWnd = NULL;
mswin_destroy_splashfonts();
}
INT_PTR CALLBACK NHSplashWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
INT_PTR CALLBACK
NHSplashWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
HDC hdc;
UNREFERENCED_PARAMETER(lParam);
UNREFERENCED_PARAMETER(lParam);
switch (message)
{
case WM_INITDIALOG:
/* set text control font */
hdc = GetDC(hWnd);
SendMessage(hWnd, WM_SETFONT,
(WPARAM)mswin_get_font(NHW_TEXT, ATR_NONE, hdc, FALSE), 0);
ReleaseDC(hWnd, hdc);
switch (message) {
case WM_INITDIALOG:
/* set text control font */
hdc = GetDC(hWnd);
SendMessage(hWnd, WM_SETFONT,
(WPARAM) mswin_get_font(NHW_TEXT, ATR_NONE, hdc, FALSE),
0);
ReleaseDC(hWnd, hdc);
SetFocus(GetDlgItem(hWnd, IDOK));
return FALSE;
SetFocus(GetDlgItem(hWnd, IDOK));
return FALSE;
case WM_PAINT:
{
char VersionString[BUFSZ];
RECT rt;
HDC hdcBitmap;
HANDLE OldBitmap;
HANDLE OldFont;
PAINTSTRUCT ps;
case WM_PAINT: {
char VersionString[BUFSZ];
RECT rt;
HDC hdcBitmap;
HANDLE OldBitmap;
HANDLE OldFont;
PAINTSTRUCT ps;
hdc = BeginPaint (hWnd, &ps);
/* Show splash graphic */
hdc = BeginPaint(hWnd, &ps);
/* Show splash graphic */
hdcBitmap = CreateCompatibleDC(hdc);
SetBkMode (hdc, OPAQUE);
OldBitmap = SelectObject(hdcBitmap, GetNHApp()->bmpSplash);
nhapply_image_transparent(hdc, SPLASH_OFFSET_X, SPLASH_OFFSET_Y,
SPLASH_WIDTH, SPLASH_HEIGHT,
hdcBitmap, 0, 0, SPLASH_WIDTH, SPLASH_HEIGHT,
TILE_BK_COLOR);
hdcBitmap = CreateCompatibleDC(hdc);
SetBkMode(hdc, OPAQUE);
OldBitmap = SelectObject(hdcBitmap, GetNHApp()->bmpSplash);
nhapply_image_transparent(hdc, SPLASH_OFFSET_X, SPLASH_OFFSET_Y,
SPLASH_WIDTH, SPLASH_HEIGHT, hdcBitmap, 0,
0, SPLASH_WIDTH, SPLASH_HEIGHT,
TILE_BK_COLOR);
SelectObject (hdcBitmap, OldBitmap);
DeleteDC (hdcBitmap);
SelectObject(hdcBitmap, OldBitmap);
DeleteDC(hdcBitmap);
SetBkMode (hdc, TRANSPARENT);
/* Print version number */
SetBkMode(hdc, TRANSPARENT);
/* Print version number */
SetTextColor (hdc, RGB(0, 0, 0));
rt.right = rt.left = SPLASH_VERSION_X;
rt.bottom = rt.top = SPLASH_VERSION_Y;
Sprintf (VersionString, "%d.%d.%d", VERSION_MAJOR, VERSION_MINOR,
PATCHLEVEL);
OldFont = SelectObject(hdc, version_splash_font);
DrawText (hdc, VersionString, strlen(VersionString), &rt,
DT_LEFT | DT_NOPREFIX | DT_CALCRECT);
DrawText (hdc, VersionString, strlen(VersionString), &rt,
DT_LEFT | DT_NOPREFIX);
EndPaint (hWnd, &ps);
}
break;
SetTextColor(hdc, RGB(0, 0, 0));
rt.right = rt.left = SPLASH_VERSION_X;
rt.bottom = rt.top = SPLASH_VERSION_Y;
Sprintf(VersionString, "%d.%d.%d", VERSION_MAJOR, VERSION_MINOR,
PATCHLEVEL);
OldFont = SelectObject(hdc, version_splash_font);
DrawText(hdc, VersionString, strlen(VersionString), &rt,
DT_LEFT | DT_NOPREFIX | DT_CALCRECT);
DrawText(hdc, VersionString, strlen(VersionString), &rt,
DT_LEFT | DT_NOPREFIX);
EndPaint(hWnd, &ps);
} break;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDOK:
mswin_window_mark_dead(mswin_winid_from_handle(hWnd));
if( GetNHApp()->hMainWnd==hWnd )
GetNHApp()->hMainWnd=NULL;
DestroyWindow(hWnd);
SetFocus(GetNHApp()->hMainWnd);
return TRUE;
}
break;
}
return FALSE;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDOK:
mswin_window_mark_dead(mswin_winid_from_handle(hWnd));
if (GetNHApp()->hMainWnd == hWnd)
GetNHApp()->hMainWnd = NULL;
DestroyWindow(hWnd);
SetFocus(GetNHApp()->hMainWnd);
return TRUE;
}
break;
}
return FALSE;
}
+297 -283
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 mhstatus.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
/* NetHack 3.6 mhstatus.c $NHDT-Date: 1431192775 2015/05/09 17:32:55 $ $NHDT-Branch: master $:$NHDT-Revision: 1.21 $ */
/* NetHack 3.6 mhstatus.c $Date: 2012/01/11 01:45:02 $ $Revision: 1.14 $ */
/* Copyright (C) 2001 by Alex Kompel */
/* NetHack may be freely redistributed. See license for details. */
@@ -8,342 +8,356 @@
#include "mhmsg.h"
#include "mhfont.h"
#define NHSW_LINES 2
#define NHSW_LINES 2
#define MAXWINDOWTEXT BUFSZ
extern COLORREF nhcolor_to_RGB (int c); /* from mhmap */
extern COLORREF nhcolor_to_RGB(int c); /* from mhmap */
typedef struct mswin_nethack_status_window {
int index;
char window_text[NHSW_LINES][MAXWINDOWTEXT+1];
int n_fields;
const char** vals;
boolean* activefields;
int* colors;
int index;
char window_text[NHSW_LINES][MAXWINDOWTEXT + 1];
int n_fields;
const char **vals;
boolean *activefields;
int *colors;
} NHStatusWindow, *PNHStatusWindow;
#ifdef STATUS_VIA_WINDOWPORT
static int fieldorder1[] = {
BL_TITLE, BL_STR, BL_DX,BL_CO, BL_IN,
BL_WI, BL_CH,BL_ALIGN, BL_SCORE, -1
};
static int fieldorder2[] = {
BL_LEVELDESC, BL_GOLD, BL_HP, BL_HPMAX,
BL_ENE, BL_ENEMAX, BL_AC, BL_XP, BL_EXP, BL_HD,
BL_TIME, BL_HUNGER,BL_CAP, BL_CONDITION, -1
};
static int* fieldorders[] = {fieldorder1, fieldorder2, NULL};
static int fieldorder1[] = { BL_TITLE, BL_STR, BL_DX, BL_CO, BL_IN,
BL_WI, BL_CH, BL_ALIGN, BL_SCORE, -1 };
static int fieldorder2[] = { BL_LEVELDESC, BL_GOLD, BL_HP, BL_HPMAX,
BL_ENE, BL_ENEMAX, BL_AC, BL_XP,
BL_EXP, BL_HD, BL_TIME, BL_HUNGER,
BL_CAP, BL_CONDITION, -1 };
static int *fieldorders[] = { fieldorder1, fieldorder2, NULL };
#endif /* STATUS_VIA_WINDOWPORT */
static TCHAR szStatusWindowClass[] = TEXT("MSNHStatusWndClass");
LRESULT CALLBACK StatusWndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK StatusWndProc(HWND, UINT, WPARAM, LPARAM);
static void register_status_window_class(void);
static LRESULT onWMPaint(HWND hWnd, WPARAM wParam, LPARAM lParam);
static LRESULT onWMPaint(HWND hWnd, WPARAM wParam, LPARAM lParam);
#define DEFAULT_COLOR_BG_STATUS COLOR_WINDOW
#define DEFAULT_COLOR_FG_STATUS COLOR_WINDOWTEXT
#define DEFAULT_COLOR_BG_STATUS COLOR_WINDOW
#define DEFAULT_COLOR_FG_STATUS COLOR_WINDOWTEXT
HWND mswin_init_status_window () {
static int run_once = 0;
HWND ret;
NHStatusWindow* data;
RECT rt;
HWND
mswin_init_status_window()
{
static int run_once = 0;
HWND ret;
NHStatusWindow *data;
RECT rt;
if( !run_once ) {
register_status_window_class( );
run_once = 1;
}
if (!run_once) {
register_status_window_class();
run_once = 1;
}
/* get window position */
if( GetNHApp()->bAutoLayout ) {
SetRect( &rt, 0, 0, 0, 0);
} else {
mswin_get_window_placement(NHW_STATUS, &rt);
}
/* get window position */
if (GetNHApp()->bAutoLayout) {
SetRect(&rt, 0, 0, 0, 0);
} else {
mswin_get_window_placement(NHW_STATUS, &rt);
}
/* create status window object */
ret = CreateWindow(
szStatusWindowClass,
NULL,
WS_CHILD | WS_CLIPSIBLINGS | WS_SIZEBOX,
rt.left, /* horizontal position of window */
rt.top, /* vertical position of window */
rt.right - rt.left, /* window width */
rt.bottom - rt.top, /* window height */
GetNHApp()->hMainWnd,
NULL,
GetNHApp()->hApp,
NULL );
if( !ret ) panic("Cannot create status window");
/* create status window object */
ret = CreateWindow(szStatusWindowClass, NULL,
WS_CHILD | WS_CLIPSIBLINGS | WS_SIZEBOX,
rt.left, /* horizontal position of window */
rt.top, /* vertical position of window */
rt.right - rt.left, /* window width */
rt.bottom - rt.top, /* window height */
GetNHApp()->hMainWnd, NULL, GetNHApp()->hApp, NULL);
if (!ret)
panic("Cannot create status window");
/* Set window caption */
SetWindowText(ret, "Status");
/* Set window caption */
SetWindowText(ret, "Status");
/* create window data */
data = (PNHStatusWindow)malloc(sizeof(NHStatusWindow));
if( !data ) panic("out of memory");
/* create window data */
data = (PNHStatusWindow) malloc(sizeof(NHStatusWindow));
if (!data)
panic("out of memory");
ZeroMemory(data, sizeof(NHStatusWindow));
SetWindowLongPtr(ret, GWLP_USERDATA, (LONG_PTR)data);
return ret;
ZeroMemory(data, sizeof(NHStatusWindow));
SetWindowLongPtr(ret, GWLP_USERDATA, (LONG_PTR) data);
return ret;
}
void register_status_window_class()
void
register_status_window_class()
{
WNDCLASS wcex;
ZeroMemory( &wcex, sizeof(wcex));
WNDCLASS wcex;
ZeroMemory(&wcex, sizeof(wcex));
wcex.style = CS_NOCLOSE;
wcex.lpfnWndProc = (WNDPROC)StatusWndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = GetNHApp()->hApp;
wcex.hIcon = NULL;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = status_bg_brush
? status_bg_brush : SYSCLR_TO_BRUSH(DEFAULT_COLOR_BG_STATUS);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = szStatusWindowClass;
wcex.style = CS_NOCLOSE;
wcex.lpfnWndProc = (WNDPROC) StatusWndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = GetNHApp()->hApp;
wcex.hIcon = NULL;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = status_bg_brush
? status_bg_brush
: SYSCLR_TO_BRUSH(DEFAULT_COLOR_BG_STATUS);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = szStatusWindowClass;
RegisterClass(&wcex);
RegisterClass(&wcex);
}
LRESULT CALLBACK StatusWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PNHStatusWindow data;
data = (PNHStatusWindow)GetWindowLongPtr(hWnd, GWLP_USERDATA);
switch (message)
{
case WM_MSNH_COMMAND: {
switch( wParam ) {
case MSNH_MSG_PUTSTR: {
PMSNHMsgPutstr msg_data = (PMSNHMsgPutstr)lParam;
strncpy(data->window_text[data->index], msg_data->text,
MAXWINDOWTEXT);
data->index = (data->index+1) % NHSW_LINES;
InvalidateRect(hWnd, NULL, TRUE);
} break;
case MSNH_MSG_CLEAR_WINDOW: {
data->index = 0;
ZeroMemory(data->window_text, sizeof(data->window_text));
InvalidateRect(hWnd, NULL, TRUE);
} break;
case MSNH_MSG_GETTEXT: {
PMSNHMsgGetText msg_data = (PMSNHMsgGetText)lParam;
LRESULT CALLBACK
StatusWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PNHStatusWindow data;
data = (PNHStatusWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA);
switch (message) {
case WM_MSNH_COMMAND: {
switch (wParam) {
case MSNH_MSG_PUTSTR: {
PMSNHMsgPutstr msg_data = (PMSNHMsgPutstr) lParam;
strncpy(data->window_text[data->index], msg_data->text,
MAXWINDOWTEXT);
data->index = (data->index + 1) % NHSW_LINES;
InvalidateRect(hWnd, NULL, TRUE);
} break;
case MSNH_MSG_CLEAR_WINDOW: {
data->index = 0;
ZeroMemory(data->window_text, sizeof(data->window_text));
InvalidateRect(hWnd, NULL, TRUE);
} break;
case MSNH_MSG_GETTEXT: {
PMSNHMsgGetText msg_data = (PMSNHMsgGetText) lParam;
#ifdef STATUS_VIA_WINDOWPORT
int **fop;
int *f;
msg_data->buffer[0] = '\0';
if( data->n_fields>0 ) {
for(fop = fieldorders; *fop; fop++) {
for(f=*fop; *f!=-1; f++) {
if (data->activefields[*f])
strncat(msg_data->buffer, data->vals[*f], msg_data->max_size - strlen(msg_data->buffer));
}
strncat(msg_data->buffer, "\r\n", msg_data->max_size - strlen(msg_data->buffer) );
}
}
#else /* STATUS_VIA_WINDOWPORT */
strncpy(msg_data->buffer, data->window_text[0], msg_data->max_size);
strncat(msg_data->buffer, "\r\n", msg_data->max_size - strlen(msg_data->buffer) );
strncat(msg_data->buffer, data->window_text[1], msg_data->max_size - strlen(msg_data->buffer) );
int **fop;
int *f;
msg_data->buffer[0] = '\0';
if (data->n_fields > 0) {
for (fop = fieldorders; *fop; fop++) {
for (f = *fop; *f != -1; f++) {
if (data->activefields[*f])
strncat(msg_data->buffer, data->vals[*f],
msg_data->max_size
- strlen(msg_data->buffer));
}
strncat(msg_data->buffer, "\r\n",
msg_data->max_size - strlen(msg_data->buffer));
}
}
#else /* STATUS_VIA_WINDOWPORT */
strncpy(msg_data->buffer, data->window_text[0],
msg_data->max_size);
strncat(msg_data->buffer, "\r\n",
msg_data->max_size - strlen(msg_data->buffer));
strncat(msg_data->buffer, data->window_text[1],
msg_data->max_size - strlen(msg_data->buffer));
#endif /* STATUS_VIA_WINDOWPORT */
} break;
} break;
case MSNH_MSG_UPDATE_STATUS: {
PMSNHMsgUpdateStatus msg_data = (PMSNHMsgUpdateStatus)lParam;
data->n_fields = msg_data->n_fields;
data->vals = msg_data->vals;
data->activefields = msg_data->activefields;
data->colors = msg_data->colors;
InvalidateRect(hWnd, NULL, TRUE);
} break;
} /* end switch( wParam ) { */
} break;
case MSNH_MSG_UPDATE_STATUS: {
PMSNHMsgUpdateStatus msg_data = (PMSNHMsgUpdateStatus) lParam;
data->n_fields = msg_data->n_fields;
data->vals = msg_data->vals;
data->activefields = msg_data->activefields;
data->colors = msg_data->colors;
InvalidateRect(hWnd, NULL, TRUE);
} break;
} /* end switch( wParam ) { */
} break;
case WM_PAINT:
return onWMPaint(hWnd, wParam, lParam);
case WM_PAINT:
return onWMPaint(hWnd, wParam, lParam);
case WM_SIZE: {
RECT rt;
GetWindowRect(hWnd, &rt);
ScreenToClient(GetNHApp()->hMainWnd, (LPPOINT)&rt);
ScreenToClient(GetNHApp()->hMainWnd, ((LPPOINT)&rt)+1);
mswin_update_window_placement(NHW_STATUS, &rt);
} return FALSE;
case WM_SIZE: {
RECT rt;
GetWindowRect(hWnd, &rt);
ScreenToClient(GetNHApp()->hMainWnd, (LPPOINT) &rt);
ScreenToClient(GetNHApp()->hMainWnd, ((LPPOINT) &rt) + 1);
mswin_update_window_placement(NHW_STATUS, &rt);
}
return FALSE;
case WM_MOVE: {
RECT rt;
GetWindowRect(hWnd, &rt);
ScreenToClient(GetNHApp()->hMainWnd, (LPPOINT)&rt);
ScreenToClient(GetNHApp()->hMainWnd, ((LPPOINT)&rt)+1);
mswin_update_window_placement(NHW_STATUS, &rt);
} return FALSE;
case WM_MOVE: {
RECT rt;
GetWindowRect(hWnd, &rt);
ScreenToClient(GetNHApp()->hMainWnd, (LPPOINT) &rt);
ScreenToClient(GetNHApp()->hMainWnd, ((LPPOINT) &rt) + 1);
mswin_update_window_placement(NHW_STATUS, &rt);
}
return FALSE;
case WM_DESTROY:
free(data);
SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)0);
break;
case WM_DESTROY:
free(data);
SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR) 0);
break;
case WM_SETFOCUS:
SetFocus(GetNHApp()->hMainWnd);
break;
case WM_SETFOCUS:
SetFocus(GetNHApp()->hMainWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
#ifdef STATUS_VIA_WINDOWPORT
static LRESULT onWMPaint(HWND hWnd, WPARAM wParam, LPARAM lParam)
static LRESULT
onWMPaint(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
int* f;
int** fop;
SIZE sz;
HGDIOBJ oldFont, normalFont, boldFont;
TCHAR wbuf[BUFSZ];
COLORREF OldBg, OldFg, Bg, Fg;
RECT rt;
PAINTSTRUCT ps;
HDC hdc;
PNHStatusWindow data;
data = (PNHStatusWindow)GetWindowLongPtr(hWnd, GWLP_USERDATA);
int *f;
int **fop;
SIZE sz;
HGDIOBJ oldFont, normalFont, boldFont;
TCHAR wbuf[BUFSZ];
COLORREF OldBg, OldFg, Bg, Fg;
RECT rt;
PAINTSTRUCT ps;
HDC hdc;
PNHStatusWindow data;
hdc = BeginPaint(hWnd, &ps);
GetClientRect(hWnd, &rt);
normalFont = mswin_get_font(NHW_STATUS, ATR_NONE, hdc, FALSE);
boldFont = mswin_get_font(NHW_STATUS, ATR_BOLD, hdc, FALSE);
oldFont = SelectObject(hdc, normalFont);
data = (PNHStatusWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA);
Bg = status_bg_brush? status_bg_color : (COLORREF)GetSysColor(DEFAULT_COLOR_BG_STATUS);
OldBg = SetBkColor(hdc, Bg);
Fg = status_fg_brush? status_fg_color : (COLORREF)GetSysColor(DEFAULT_COLOR_FG_STATUS);
OldFg = SetTextColor(hdc, Fg);
for(fop = fieldorders; *fop; fop++) {
LONG left = rt.left;
LONG cy = 0;
int vlen;
for(f=*fop; *f!=-1; f++) {
if( ((*f)>= data->n_fields) || (!data->activefields[*f])) continue;
vlen = strlen(data->vals[*f]);
NH_A2W(data->vals[*f], wbuf, SIZE(wbuf));
if(data->colors[*f]==CLR_MAX || data->colors[*f]==BL_HILITE_NONE) {
SelectObject(hdc, normalFont);
SetBkColor(hdc, Bg);
SetTextColor(hdc, Fg);
} else if(data->colors[*f]>0) {
SelectObject(hdc, normalFont);
SetBkColor(hdc, Bg);
SetTextColor(hdc, nhcolor_to_RGB(data->colors[*f]));
} else if(data->colors[*f]==BL_HILITE_INVERSE) {
SelectObject(hdc, normalFont);
SetBkColor(hdc, Fg);
SetTextColor(hdc, Bg);
} else if(data->colors[*f]==BL_HILITE_BOLD) {
SelectObject(hdc, boldFont);
SetBkColor(hdc, Bg);
SetTextColor(hdc, Fg);
} else {
SelectObject(hdc, normalFont);
SetBkColor(hdc, Bg);
SetTextColor(hdc, Fg);
}
GetTextExtentPoint32(hdc, wbuf, vlen, &sz);
DrawText(hdc, wbuf, vlen, &rt, DT_LEFT);
rt.left += sz.cx;
cy = max(cy, sz.cy);
}
rt.left = left;
rt.top += cy;
}
hdc = BeginPaint(hWnd, &ps);
GetClientRect(hWnd, &rt);
SelectObject(hdc, oldFont);
SetTextColor (hdc, OldFg);
SetBkColor (hdc, OldBg);
EndPaint(hWnd, &ps);
return 0;
normalFont = mswin_get_font(NHW_STATUS, ATR_NONE, hdc, FALSE);
boldFont = mswin_get_font(NHW_STATUS, ATR_BOLD, hdc, FALSE);
oldFont = SelectObject(hdc, normalFont);
Bg = status_bg_brush ? status_bg_color
: (COLORREF) GetSysColor(DEFAULT_COLOR_BG_STATUS);
OldBg = SetBkColor(hdc, Bg);
Fg = status_fg_brush ? status_fg_color
: (COLORREF) GetSysColor(DEFAULT_COLOR_FG_STATUS);
OldFg = SetTextColor(hdc, Fg);
for (fop = fieldorders; *fop; fop++) {
LONG left = rt.left;
LONG cy = 0;
int vlen;
for (f = *fop; *f != -1; f++) {
if (((*f) >= data->n_fields) || (!data->activefields[*f]))
continue;
vlen = strlen(data->vals[*f]);
NH_A2W(data->vals[*f], wbuf, SIZE(wbuf));
if (data->colors[*f] == CLR_MAX
|| data->colors[*f] == BL_HILITE_NONE) {
SelectObject(hdc, normalFont);
SetBkColor(hdc, Bg);
SetTextColor(hdc, Fg);
} else if (data->colors[*f] > 0) {
SelectObject(hdc, normalFont);
SetBkColor(hdc, Bg);
SetTextColor(hdc, nhcolor_to_RGB(data->colors[*f]));
} else if (data->colors[*f] == BL_HILITE_INVERSE) {
SelectObject(hdc, normalFont);
SetBkColor(hdc, Fg);
SetTextColor(hdc, Bg);
} else if (data->colors[*f] == BL_HILITE_BOLD) {
SelectObject(hdc, boldFont);
SetBkColor(hdc, Bg);
SetTextColor(hdc, Fg);
} else {
SelectObject(hdc, normalFont);
SetBkColor(hdc, Bg);
SetTextColor(hdc, Fg);
}
GetTextExtentPoint32(hdc, wbuf, vlen, &sz);
DrawText(hdc, wbuf, vlen, &rt, DT_LEFT);
rt.left += sz.cx;
cy = max(cy, sz.cy);
}
rt.left = left;
rt.top += cy;
}
SelectObject(hdc, oldFont);
SetTextColor(hdc, OldFg);
SetBkColor(hdc, OldBg);
EndPaint(hWnd, &ps);
return 0;
}
#else
static LRESULT onWMPaint(HWND hWnd, WPARAM wParam, LPARAM lParam)
static LRESULT
onWMPaint(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
int i;
SIZE sz;
HGDIOBJ oldFont;
TCHAR wbuf[BUFSZ];
COLORREF OldBg, OldFg;
RECT rt;
PAINTSTRUCT ps;
HDC hdc;
PNHStatusWindow data;
data = (PNHStatusWindow)GetWindowLongPtr(hWnd, GWLP_USERDATA);
int i;
SIZE sz;
HGDIOBJ oldFont;
TCHAR wbuf[BUFSZ];
COLORREF OldBg, OldFg;
RECT rt;
PAINTSTRUCT ps;
HDC hdc;
PNHStatusWindow data;
hdc = BeginPaint(hWnd, &ps);
GetClientRect(hWnd, &rt);
oldFont = SelectObject(hdc, mswin_get_font(NHW_STATUS, ATR_NONE, hdc, FALSE));
data = (PNHStatusWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA);
OldBg = SetBkColor(hdc, status_bg_brush
? status_bg_color : (COLORREF)GetSysColor(DEFAULT_COLOR_BG_STATUS));
OldFg = SetTextColor(hdc, status_fg_brush
? status_fg_color : (COLORREF)GetSysColor(DEFAULT_COLOR_FG_STATUS));
for(i=0; i<NHSW_LINES; i++ ) {
int wlen = strlen(data->window_text[i]);
NH_A2W(data->window_text[i], wbuf, SIZE(wbuf));
GetTextExtentPoint32(hdc, wbuf, wlen, &sz);
DrawText(hdc, wbuf, wlen, &rt, DT_LEFT | DT_END_ELLIPSIS);
rt.top += sz.cy;
}
hdc = BeginPaint(hWnd, &ps);
GetClientRect(hWnd, &rt);
SelectObject(hdc, oldFont);
SetTextColor (hdc, OldFg);
SetBkColor (hdc, OldBg);
EndPaint(hWnd, &ps);
return 0;
oldFont =
SelectObject(hdc, mswin_get_font(NHW_STATUS, ATR_NONE, hdc, FALSE));
OldBg = SetBkColor(hdc, status_bg_brush ? status_bg_color
: (COLORREF) GetSysColor(
DEFAULT_COLOR_BG_STATUS));
OldFg = SetTextColor(hdc, status_fg_brush ? status_fg_color
: (COLORREF) GetSysColor(
DEFAULT_COLOR_FG_STATUS));
for (i = 0; i < NHSW_LINES; i++) {
int wlen = strlen(data->window_text[i]);
NH_A2W(data->window_text[i], wbuf, SIZE(wbuf));
GetTextExtentPoint32(hdc, wbuf, wlen, &sz);
DrawText(hdc, wbuf, wlen, &rt, DT_LEFT | DT_END_ELLIPSIS);
rt.top += sz.cy;
}
SelectObject(hdc, oldFont);
SetTextColor(hdc, OldFg);
SetBkColor(hdc, OldBg);
EndPaint(hWnd, &ps);
return 0;
}
#endif /*STATUS_VIA_WINDOWPORT*/
void mswin_status_window_size (HWND hWnd, LPSIZE sz)
void
mswin_status_window_size(HWND hWnd, LPSIZE sz)
{
TEXTMETRIC tm;
HGDIOBJ saveFont;
HDC hdc;
PNHStatusWindow data;
RECT rt;
SIZE text_sz;
GetClientRect(hWnd, &rt);
HGDIOBJ saveFont;
HDC hdc;
PNHStatusWindow data;
RECT rt;
SIZE text_sz;
data = (PNHStatusWindow)GetWindowLongPtr(hWnd, GWLP_USERDATA);
if(data) {
hdc = GetDC(hWnd);
saveFont = SelectObject(hdc, mswin_get_font(NHW_STATUS, ATR_NONE, hdc, FALSE));
GetTextExtentPoint32(hdc, _T("W"), 1, &text_sz);
GetTextMetrics(hdc, &tm);
GetClientRect(hWnd, &rt);
rt.bottom = rt.top + text_sz.cy*NHSW_LINES;
data = (PNHStatusWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA);
if (data) {
hdc = GetDC(hWnd);
saveFont = SelectObject(
hdc, mswin_get_font(NHW_STATUS, ATR_NONE, hdc, FALSE));
GetTextExtentPoint32(hdc, _T("W"), 1, &text_sz);
GetTextMetrics(hdc, &tm);
SelectObject(hdc, saveFont);
ReleaseDC(hWnd, hdc);
}
AdjustWindowRect(&rt, GetWindowLong(hWnd, GWL_STYLE), FALSE);
sz->cx = rt.right - rt.left;
sz->cy = rt.bottom - rt.top;
rt.bottom = rt.top + text_sz.cy * NHSW_LINES;
SelectObject(hdc, saveFont);
ReleaseDC(hWnd, hdc);
}
AdjustWindowRect(&rt, GetWindowLong(hWnd, GWL_STYLE), FALSE);
sz->cx = rt.right - rt.left;
sz->cy = rt.bottom - rt.top;
}
+232 -214
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 mhtext.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
/* NetHack 3.6 mhtext.c $NHDT-Date: 1431192777 2015/05/09 17:32:57 $ $NHDT-Branch: master $:$NHDT-Revision: 1.24 $ */
/* NetHack 3.6 mhtext.c $Date: 2012/01/11 01:53:44 $ $Revision: 1.17 $ */
/* Copyright (C) 2001 by Alex Kompel */
/* NetHack may be freely redistributed. See license for details. */
@@ -12,264 +12,283 @@
PNHWinApp GetNHApp(void);
typedef struct mswin_nethack_text_window {
TCHAR* window_text;
TCHAR *window_text;
} NHTextWindow, *PNHTextWindow;
static WNDPROC editControlWndProc = 0;
#define DEFAULT_COLOR_BG_TEXT COLOR_WINDOW
#define DEFAULT_COLOR_FG_TEXT COLOR_WINDOWTEXT
static WNDPROC editControlWndProc = 0;
#define DEFAULT_COLOR_BG_TEXT COLOR_WINDOW
#define DEFAULT_COLOR_FG_TEXT COLOR_WINDOWTEXT
INT_PTR CALLBACK NHTextWndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK NHEditHookWndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK NHTextWndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK NHEditHookWndProc(HWND, UINT, WPARAM, LPARAM);
static void onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam);
static void LayoutText(HWND hwnd);
HWND mswin_init_text_window () {
HWND ret;
PNHTextWindow data;
RECT rt;
HWND
mswin_init_text_window()
{
HWND ret;
PNHTextWindow data;
RECT rt;
/* get window position */
if( GetNHApp()->bAutoLayout ) {
SetRect( &rt, 0, 0, 0, 0);
} else {
mswin_get_window_placement(NHW_TEXT, &rt);
}
/* get window position */
if (GetNHApp()->bAutoLayout) {
SetRect(&rt, 0, 0, 0, 0);
} else {
mswin_get_window_placement(NHW_TEXT, &rt);
}
/* create text widnow object */
ret = CreateDialog(
GetNHApp()->hApp,
MAKEINTRESOURCE(IDD_NHTEXT),
GetNHApp()->hMainWnd,
NHTextWndProc
);
if( !ret ) panic("Cannot create text window");
/* create text widnow object */
ret = CreateDialog(GetNHApp()->hApp, MAKEINTRESOURCE(IDD_NHTEXT),
GetNHApp()->hMainWnd, NHTextWndProc);
if (!ret)
panic("Cannot create text window");
/* move it in the predefined position */
if( !GetNHApp()->bAutoLayout ) {
MoveWindow(ret, rt.left, rt.top, rt.right - rt.left, rt.bottom - rt.top, TRUE);
}
/* move it in the predefined position */
if (!GetNHApp()->bAutoLayout) {
MoveWindow(ret, rt.left, rt.top, rt.right - rt.left,
rt.bottom - rt.top, TRUE);
}
/* Set window caption */
SetWindowText(ret, "Text");
if( !GetNHApp()->bWindowsLocked ) {
DWORD style;
style = GetWindowLong(ret, GWL_STYLE);
style |= WS_CAPTION;
SetWindowLong(ret, GWL_STYLE, style);
SetWindowPos(ret, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
}
/* Set window caption */
SetWindowText(ret, "Text");
if (!GetNHApp()->bWindowsLocked) {
DWORD style;
style = GetWindowLong(ret, GWL_STYLE);
style |= WS_CAPTION;
SetWindowLong(ret, GWL_STYLE, style);
SetWindowPos(ret, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE
| SWP_NOZORDER
| SWP_FRAMECHANGED);
}
/* create and set window data */
data = (PNHTextWindow)malloc(sizeof(NHTextWindow));
if( !data ) panic("out of memory");
ZeroMemory(data, sizeof(NHTextWindow));
SetWindowLongPtr(ret, GWLP_USERDATA, (LONG_PTR)data);
return ret;
/* create and set window data */
data = (PNHTextWindow) malloc(sizeof(NHTextWindow));
if (!data)
panic("out of memory");
ZeroMemory(data, sizeof(NHTextWindow));
SetWindowLongPtr(ret, GWLP_USERDATA, (LONG_PTR) data);
return ret;
}
void mswin_display_text_window (HWND hWnd)
void
mswin_display_text_window(HWND hWnd)
{
PNHTextWindow data;
data = (PNHTextWindow)GetWindowLongPtr(hWnd, GWLP_USERDATA);
if( data && data->window_text ) {
HWND control;
control = GetDlgItem(hWnd, IDC_TEXT_CONTROL);
SendMessage(control, EM_FMTLINES, 1, 0 );
SetWindowText(control, data->window_text);
}
PNHTextWindow data;
mswin_popup_display(hWnd, NULL);
mswin_popup_destroy(hWnd);
data = (PNHTextWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA);
if (data && data->window_text) {
HWND control;
control = GetDlgItem(hWnd, IDC_TEXT_CONTROL);
SendMessage(control, EM_FMTLINES, 1, 0);
SetWindowText(control, data->window_text);
}
mswin_popup_display(hWnd, NULL);
mswin_popup_destroy(hWnd);
}
INT_PTR CALLBACK NHTextWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
INT_PTR CALLBACK
NHTextWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HWND control;
HDC hdc;
PNHTextWindow data;
HWND control;
HDC hdc;
PNHTextWindow data;
TCHAR title[MAX_LOADSTRING];
data = (PNHTextWindow)GetWindowLongPtr(hWnd, GWLP_USERDATA);
switch (message)
{
case WM_INITDIALOG:
/* set text control font */
control = GetDlgItem(hWnd, IDC_TEXT_CONTROL);
if( !control ) {
panic("cannot get text view window");
}
hdc = GetDC(control);
SendMessage(control, WM_SETFONT, (WPARAM)mswin_get_font(NHW_TEXT, ATR_NONE, hdc, FALSE), 0);
ReleaseDC(control, hdc);
data = (PNHTextWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA);
switch (message) {
case WM_INITDIALOG:
/* set text control font */
control = GetDlgItem(hWnd, IDC_TEXT_CONTROL);
if (!control) {
panic("cannot get text view window");
}
/* subclass edit control */
editControlWndProc = (WNDPROC)GetWindowLongPtr(control, GWLP_WNDPROC);
SetWindowLongPtr(control, GWLP_WNDPROC, (LONG_PTR)NHEditHookWndProc);
hdc = GetDC(control);
SendMessage(control, WM_SETFONT,
(WPARAM) mswin_get_font(NHW_TEXT, ATR_NONE, hdc, FALSE),
0);
ReleaseDC(control, hdc);
SetFocus(control);
/* subclass edit control */
editControlWndProc =
(WNDPROC) GetWindowLongPtr(control, GWLP_WNDPROC);
SetWindowLongPtr(control, GWLP_WNDPROC, (LONG_PTR) NHEditHookWndProc);
/* Even though the dialog has no caption, you can still set the title
SetFocus(control);
/* Even though the dialog has no caption, you can still set the title
which shows on Alt-Tab */
LoadString(GetNHApp()->hApp, IDS_APP_TITLE, title, MAX_LOADSTRING);
SetWindowText(hWnd, title);
return FALSE;
return FALSE;
case WM_MSNH_COMMAND:
onMSNHCommand(hWnd, wParam, lParam);
break;
case WM_MSNH_COMMAND:
onMSNHCommand(hWnd, wParam, lParam);
break;
case WM_SIZE: {
RECT rt;
case WM_SIZE: {
RECT rt;
GetWindowRect(hWnd, &rt);
ScreenToClient(GetNHApp()->hMainWnd, (LPPOINT)&rt);
ScreenToClient(GetNHApp()->hMainWnd, ((LPPOINT)&rt)+1);
mswin_update_window_placement(NHW_TEXT, &rt);
GetWindowRect(hWnd, &rt);
ScreenToClient(GetNHApp()->hMainWnd, (LPPOINT) &rt);
ScreenToClient(GetNHApp()->hMainWnd, ((LPPOINT) &rt) + 1);
mswin_update_window_placement(NHW_TEXT, &rt);
LayoutText(hWnd);
} return FALSE;
LayoutText(hWnd);
}
return FALSE;
case WM_MOVE: {
RECT rt;
GetWindowRect(hWnd, &rt);
ScreenToClient(GetNHApp()->hMainWnd, (LPPOINT)&rt);
ScreenToClient(GetNHApp()->hMainWnd, ((LPPOINT)&rt)+1);
mswin_update_window_placement(NHW_TEXT, &rt);
} return FALSE;
case WM_MOVE: {
RECT rt;
GetWindowRect(hWnd, &rt);
ScreenToClient(GetNHApp()->hMainWnd, (LPPOINT) &rt);
ScreenToClient(GetNHApp()->hMainWnd, ((LPPOINT) &rt) + 1);
mswin_update_window_placement(NHW_TEXT, &rt);
}
return FALSE;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDOK:
case IDCANCEL:
mswin_window_mark_dead(mswin_winid_from_handle(hWnd));
if( GetNHApp()->hMainWnd==hWnd )
GetNHApp()->hMainWnd=NULL;
DestroyWindow(hWnd);
SetFocus(GetNHApp()->hMainWnd);
return TRUE;
}
break;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDOK:
case IDCANCEL:
mswin_window_mark_dead(mswin_winid_from_handle(hWnd));
if (GetNHApp()->hMainWnd == hWnd)
GetNHApp()->hMainWnd = NULL;
DestroyWindow(hWnd);
SetFocus(GetNHApp()->hMainWnd);
return TRUE;
}
break;
case WM_CTLCOLORSTATIC: { /* sent by edit control before it is drawn */
HDC hdcEdit = (HDC) wParam;
HWND hwndEdit = (HWND) lParam;
if( hwndEdit == GetDlgItem(hWnd, IDC_TEXT_CONTROL) ) {
SetBkColor(hdcEdit,
text_bg_brush ? text_bg_color : (COLORREF)GetSysColor(DEFAULT_COLOR_BG_TEXT)
);
SetTextColor(hdcEdit,
text_fg_brush ? text_fg_color : (COLORREF)GetSysColor(DEFAULT_COLOR_FG_TEXT)
);
return (INT_PTR)(text_bg_brush
? text_bg_brush : SYSCLR_TO_BRUSH(DEFAULT_COLOR_BG_TEXT));
}
} return FALSE;
case WM_CTLCOLORSTATIC: { /* sent by edit control before it is drawn */
HDC hdcEdit = (HDC) wParam;
HWND hwndEdit = (HWND) lParam;
if (hwndEdit == GetDlgItem(hWnd, IDC_TEXT_CONTROL)) {
SetBkColor(hdcEdit, text_bg_brush ? text_bg_color
: (COLORREF) GetSysColor(
DEFAULT_COLOR_BG_TEXT));
SetTextColor(hdcEdit, text_fg_brush ? text_fg_color
: (COLORREF) GetSysColor(
DEFAULT_COLOR_FG_TEXT));
return (INT_PTR)(text_bg_brush
? text_bg_brush
: SYSCLR_TO_BRUSH(DEFAULT_COLOR_BG_TEXT));
}
}
return FALSE;
case WM_DESTROY:
if( data ) {
if( data->window_text ) free(data->window_text);
free(data);
SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)0);
}
break;
}
return FALSE;
case WM_DESTROY:
if (data) {
if (data->window_text)
free(data->window_text);
free(data);
SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR) 0);
}
break;
}
return FALSE;
}
void onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
void
onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
PNHTextWindow data;
data = (PNHTextWindow)GetWindowLongPtr(hWnd, GWLP_USERDATA);
switch( wParam ) {
case MSNH_MSG_PUTSTR: {
PMSNHMsgPutstr msg_data = (PMSNHMsgPutstr)lParam;
TCHAR wbuf[BUFSZ];
size_t text_size;
PNHTextWindow data;
if( !data->window_text ) {
text_size = strlen(msg_data->text) + 4;
data->window_text = (TCHAR*)malloc(text_size*sizeof(data->window_text[0]));
ZeroMemory(data->window_text, text_size*sizeof(data->window_text[0]));
} else {
text_size = _tcslen(data->window_text) + strlen(msg_data->text) + 4;
data->window_text = (TCHAR*)realloc(data->window_text, text_size*sizeof(data->window_text[0]));
}
if( !data->window_text ) break;
_tcscat(data->window_text, NH_A2W(msg_data->text, wbuf, BUFSZ));
_tcscat(data->window_text, TEXT("\r\n"));
break;
}
}
data = (PNHTextWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA);
switch (wParam) {
case MSNH_MSG_PUTSTR: {
PMSNHMsgPutstr msg_data = (PMSNHMsgPutstr) lParam;
TCHAR wbuf[BUFSZ];
size_t text_size;
if (!data->window_text) {
text_size = strlen(msg_data->text) + 4;
data->window_text =
(TCHAR *) malloc(text_size * sizeof(data->window_text[0]));
ZeroMemory(data->window_text,
text_size * sizeof(data->window_text[0]));
} else {
text_size =
_tcslen(data->window_text) + strlen(msg_data->text) + 4;
data->window_text = (TCHAR *) realloc(
data->window_text, text_size * sizeof(data->window_text[0]));
}
if (!data->window_text)
break;
_tcscat(data->window_text, NH_A2W(msg_data->text, wbuf, BUFSZ));
_tcscat(data->window_text, TEXT("\r\n"));
break;
}
}
}
void LayoutText(HWND hWnd)
void
LayoutText(HWND hWnd)
{
HWND btn_ok;
HWND text;
RECT clrt, rt;
POINT pt_elem, pt_ok;
SIZE sz_elem, sz_ok;
HWND btn_ok;
HWND text;
RECT clrt, rt;
POINT pt_elem, pt_ok;
SIZE sz_elem, sz_ok;
text = GetDlgItem(hWnd, IDC_TEXT_CONTROL);
btn_ok = GetDlgItem(hWnd, IDOK);
text = GetDlgItem(hWnd, IDC_TEXT_CONTROL);
btn_ok = GetDlgItem(hWnd, IDOK);
/* get window coordinates */
GetClientRect(hWnd, &clrt );
/* set window placements */
GetWindowRect(btn_ok, &rt);
sz_ok.cx = clrt.right - clrt.left;
sz_ok.cy = rt.bottom-rt.top;
pt_ok.x = clrt.left;
pt_ok.y = clrt.bottom - sz_ok.cy;
/* get window coordinates */
GetClientRect(hWnd, &clrt);
pt_elem.x = clrt.left;
pt_elem.y = clrt.top;
sz_elem.cx = clrt.right - clrt.left;
sz_elem.cy = pt_ok.y;
/* set window placements */
GetWindowRect(btn_ok, &rt);
sz_ok.cx = clrt.right - clrt.left;
sz_ok.cy = rt.bottom - rt.top;
pt_ok.x = clrt.left;
pt_ok.y = clrt.bottom - sz_ok.cy;
MoveWindow(text, pt_elem.x, pt_elem.y, sz_elem.cx, sz_elem.cy, TRUE );
MoveWindow(btn_ok, pt_ok.x, pt_ok.y, sz_ok.cx, sz_ok.cy, TRUE );
pt_elem.x = clrt.left;
pt_elem.y = clrt.top;
sz_elem.cx = clrt.right - clrt.left;
sz_elem.cy = pt_ok.y;
MoveWindow(text, pt_elem.x, pt_elem.y, sz_elem.cx, sz_elem.cy, TRUE);
MoveWindow(btn_ok, pt_ok.x, pt_ok.y, sz_ok.cx, sz_ok.cy, TRUE);
}
/* Edit box hook */
LRESULT CALLBACK NHEditHookWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
LRESULT CALLBACK
NHEditHookWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hDC;
RECT rc;
HDC hDC;
RECT rc;
switch(message) {
case WM_ERASEBKGND:
hDC = (HDC) wParam;
GetClientRect(hWnd, &rc);
FillRect(hDC, &rc, text_bg_brush? text_bg_brush : SYSCLR_TO_BRUSH(DEFAULT_COLOR_BG_TEXT));
return 1;
switch (message) {
case WM_ERASEBKGND:
hDC = (HDC) wParam;
GetClientRect(hWnd, &rc);
FillRect(hDC, &rc, text_bg_brush
? text_bg_brush
: SYSCLR_TO_BRUSH(DEFAULT_COLOR_BG_TEXT));
return 1;
case WM_KEYDOWN:
switch (wParam)
{
/* close on space in Windows mode
case WM_KEYDOWN:
switch (wParam) {
/* close on space in Windows mode
page down on space in NetHack mode */
case VK_SPACE:
{
case VK_SPACE: {
SCROLLINFO si;
si.cbSize = sizeof(SCROLLINFO);
si.fMask = SIF_POS | SIF_RANGE | SIF_PAGE;
GetScrollInfo(hWnd, SB_VERT, &si);
/* If nethackmode and not at the end of the list */
if (GetNHApp()->regNetHackMode &&
(si.nPos + (int)si.nPage) <= (si.nMax - si.nMin))
if (GetNHApp()->regNetHackMode
&& (si.nPos + (int) si.nPage) <= (si.nMax - si.nMin))
SendMessage(hWnd, EM_SCROLL, SB_PAGEDOWN, 0);
else
PostMessage(GetParent(hWnd), WM_COMMAND, MAKELONG(IDOK, 0), 0);
PostMessage(GetParent(hWnd), WM_COMMAND, MAKELONG(IDOK, 0),
0);
return 0;
}
case VK_NEXT:
@@ -284,20 +303,19 @@ LRESULT CALLBACK NHEditHookWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARA
case VK_DOWN:
SendMessage(hWnd, EM_SCROLL, SB_LINEDOWN, 0);
return 0;
}
break;
}
break;
/* edit control needs to know nothing of focus. We will take care of it
* for it */
case WM_SETFOCUS:
HideCaret(hWnd);
return 0;
}
/* edit control needs to know nothing of focus. We will take care of it for it */
case WM_SETFOCUS:
HideCaret(hWnd);
return 0;
}
if( editControlWndProc )
return CallWindowProc(editControlWndProc, hWnd, message, wParam, lParam);
else
return 0;
if (editControlWndProc)
return CallWindowProc(editControlWndProc, hWnd, message, wParam,
lParam);
else
return 0;
}
+2006 -1929
View File
File diff suppressed because it is too large Load Diff
+175 -162
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 winhack.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
/* NetHack 3.6 winhack.c $NHDT-Date: 1431192776 2015/05/09 17:32:56 $ $NHDT-Branch: master $:$NHDT-Revision: 1.39 $ */
/* NetHack 3.6 winhack.c $Date: 2009/05/06 11:00:43 $ $Revision: 1.32 $ */
/* SCCS Id: @(#)winhack.c 3.5 2006/04/01 */
/* Copyright (C) 2001 by Alex Kompel */
@@ -17,13 +17,12 @@
/* Borland and MinGW redefine "boolean" in shlwapi.h,
so just use the little bit we need */
typedef struct _DLLVERSIONINFO
{
typedef struct _DLLVERSIONINFO {
DWORD cbSize;
DWORD dwMajorVersion; // Major version
DWORD dwMinorVersion; // Minor version
DWORD dwBuildNumber; // Build number
DWORD dwPlatformID; // DLLVER_PLATFORM_*
DWORD dwMajorVersion; // Major version
DWORD dwMinorVersion; // Minor version
DWORD dwBuildNumber; // Build number
DWORD dwPlatformID; // DLLVER_PLATFORM_*
} DLLVERSIONINFO;
//
@@ -31,7 +30,7 @@ typedef struct _DLLVERSIONINFO
// implicitly link to it.
//
typedef HRESULT (CALLBACK* DLLGETVERSIONPROC)(DLLVERSIONINFO *);
typedef HRESULT(CALLBACK *DLLGETVERSIONPROC)(DLLVERSIONINFO *);
/* end of shlwapi.h */
@@ -47,120 +46,124 @@ Version _WIN_32IE Platform/IE
#define MIN_COMCTLMAJOR 4
#define MIN_COMCTLMINOR 71
#define INSTALL_NOTES "http://www.nethack.org/v340/ports/download-win.html#cc"
/*#define COMCTL_URL "http://www.microsoft.com/msdownload/ieplatform/ie/comctrlx86.asp"*/
/*#define COMCTL_URL
* "http://www.microsoft.com/msdownload/ieplatform/ie/comctrlx86.asp"*/
extern void FDECL(nethack_exit,(int));
static TCHAR* _get_cmd_arg(TCHAR* pCmdLine);
extern void FDECL(nethack_exit, (int));
static TCHAR *_get_cmd_arg(TCHAR *pCmdLine);
static HRESULT GetComCtlVersion(LPDWORD pdwMajor, LPDWORD pdwMinor);
// Global Variables:
NHWinApp _nethack_app;
#ifdef __BORLANDC__
#define _stricmp(s1,s2) stricmp(s1,s2)
#define _strdup(s1) strdup(s1)
#define _stricmp(s1, s2) stricmp(s1, s2)
#define _strdup(s1) strdup(s1)
#endif
// Foward declarations of functions included in this code module:
extern boolean FDECL(pcmain, (int,char **));
extern boolean FDECL(pcmain, (int, char **));
static void __cdecl mswin_moveloop(void *);
#define MAX_CMDLINE_PARAM 255
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
int APIENTRY
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
int nCmdShow)
{
INITCOMMONCONTROLSEX InitCtrls;
int argc;
char* argv[MAX_CMDLINE_PARAM];
size_t len;
TCHAR *p;
TCHAR wbuf[BUFSZ];
char buf[BUFSZ];
INITCOMMONCONTROLSEX InitCtrls;
int argc;
char *argv[MAX_CMDLINE_PARAM];
size_t len;
TCHAR *p;
TCHAR wbuf[BUFSZ];
char buf[BUFSZ];
DWORD major, minor;
boolean resuming;
boolean resuming;
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
UNREFERENCED_PARAMETER(nCmdShow);
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
UNREFERENCED_PARAMETER(nCmdShow);
/* ensure that we don't access violate on a panic() */
windowprocs.win_raw_print = mswin_raw_print;
windowprocs.win_raw_print_bold = mswin_raw_print_bold;
/* ensure that we don't access violate on a panic() */
windowprocs.win_raw_print = mswin_raw_print;
windowprocs.win_raw_print_bold = mswin_raw_print_bold;
/* init applicatio structure */
_nethack_app.hApp = hInstance;
_nethack_app.hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_NETHACKW);
_nethack_app.hMainWnd = NULL;
_nethack_app.hPopupWnd = NULL;
_nethack_app.bmpTiles = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_TILES));
if( _nethack_app.bmpTiles==NULL ) panic("cannot load tiles bitmap");
_nethack_app.bmpPetMark = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_PETMARK));
if( _nethack_app.bmpPetMark==NULL ) panic("cannot load pet mark bitmap");
_nethack_app.bmpRip = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_RIP));
if ( _nethack_app.bmpRip == NULL ) panic("cannot load rip bitmap");
_nethack_app.bmpSplash = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_SPLASH));
if ( _nethack_app.bmpSplash == NULL ) panic("cannot load splash bitmap");
_nethack_app.bmpMapTiles = _nethack_app.bmpTiles;
_nethack_app.mapTile_X = TILE_X;
_nethack_app.mapTile_Y = TILE_Y;
_nethack_app.mapTilesPerLine = TILES_PER_LINE;
/* init applicatio structure */
_nethack_app.hApp = hInstance;
_nethack_app.hAccelTable =
LoadAccelerators(hInstance, (LPCTSTR) IDC_NETHACKW);
_nethack_app.hMainWnd = NULL;
_nethack_app.hPopupWnd = NULL;
_nethack_app.bmpTiles = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_TILES));
if (_nethack_app.bmpTiles == NULL)
panic("cannot load tiles bitmap");
_nethack_app.bmpPetMark =
LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_PETMARK));
if (_nethack_app.bmpPetMark == NULL)
panic("cannot load pet mark bitmap");
_nethack_app.bmpRip = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_RIP));
if (_nethack_app.bmpRip == NULL)
panic("cannot load rip bitmap");
_nethack_app.bmpSplash =
LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_SPLASH));
if (_nethack_app.bmpSplash == NULL)
panic("cannot load splash bitmap");
_nethack_app.bmpMapTiles = _nethack_app.bmpTiles;
_nethack_app.mapTile_X = TILE_X;
_nethack_app.mapTile_Y = TILE_Y;
_nethack_app.mapTilesPerLine = TILES_PER_LINE;
_nethack_app.bNoHScroll = FALSE;
_nethack_app.bNoVScroll = FALSE;
_nethack_app.saved_text = strdup("");
_nethack_app.bNoHScroll = FALSE;
_nethack_app.bNoVScroll = FALSE;
_nethack_app.saved_text = strdup("");
_nethack_app.bAutoLayout = TRUE;
_nethack_app.bWindowsLocked = TRUE;
_nethack_app.bAutoLayout = TRUE;
_nethack_app.bWindowsLocked = TRUE;
_nethack_app.bNoSounds = FALSE;
_nethack_app.bNoSounds = FALSE;
// init controls
if (FAILED(GetComCtlVersion(&major, &minor)))
{
if (FAILED(GetComCtlVersion(&major, &minor))) {
char buf[TBUFSZ];
Sprintf(buf, "Cannot load common control library.\n%s\n%s",
"For further information, refer to the installation notes at",
INSTALL_NOTES);
"For further information, refer to the installation notes at",
INSTALL_NOTES);
panic(buf);
}
if (major < MIN_COMCTLMAJOR
|| (major == MIN_COMCTLMAJOR && minor < MIN_COMCTLMINOR))
{
|| (major == MIN_COMCTLMAJOR && minor < MIN_COMCTLMINOR)) {
char buf[TBUFSZ];
Sprintf(buf, "Common control library is outdated.\n%s %d.%d\n%s\n%s",
"NetHack requires at least version ",
MIN_COMCTLMAJOR, MIN_COMCTLMINOR,
"For further information, refer to the installation notes at",
INSTALL_NOTES);
"NetHack requires at least version ", MIN_COMCTLMAJOR,
MIN_COMCTLMINOR,
"For further information, refer to the installation notes at",
INSTALL_NOTES);
panic(buf);
}
ZeroMemory(&InitCtrls, sizeof(InitCtrls));
InitCtrls.dwSize = sizeof(InitCtrls);
InitCtrls.dwICC = ICC_LISTVIEW_CLASSES;
InitCommonControlsEx(&InitCtrls);
/* get command line parameters */
p = _get_cmd_arg(GetCommandLine());
p = _get_cmd_arg(NULL); /* skip first paramter - command name */
for( argc = 1; p && argc<MAX_CMDLINE_PARAM; argc++ ) {
len = _tcslen(p);
if( len>0 ) {
argv[argc] = _strdup( NH_W2A(p, buf, BUFSZ) );
} else {
argv[argc] = "";
}
p = _get_cmd_arg(NULL);
}
GetModuleFileName(NULL, wbuf, BUFSZ);
argv[0] = _strdup(NH_W2A(wbuf, buf, BUFSZ));
ZeroMemory(&InitCtrls, sizeof(InitCtrls));
InitCtrls.dwSize = sizeof(InitCtrls);
InitCtrls.dwICC = ICC_LISTVIEW_CLASSES;
InitCommonControlsEx(&InitCtrls);
/* get command line parameters */
p = _get_cmd_arg(GetCommandLine());
p = _get_cmd_arg(NULL); /* skip first paramter - command name */
for (argc = 1; p && argc < MAX_CMDLINE_PARAM; argc++) {
len = _tcslen(p);
if (len > 0) {
argv[argc] = _strdup(NH_W2A(p, buf, BUFSZ));
} else {
argv[argc] = "";
}
p = _get_cmd_arg(NULL);
}
GetModuleFileName(NULL, wbuf, BUFSZ);
argv[0] = _strdup(NH_W2A(wbuf, buf, BUFSZ));
if (argc == 2) {
TCHAR *savefile = strdup(argv[1]);
TCHAR *plname;
TCHAR *savefile = strdup(argv[1]);
TCHAR *plname;
for (p = savefile; *p && *p != '-'; p++)
;
if (*p) {
@@ -179,100 +182,110 @@ int APIENTRY WinMain(HINSTANCE hInstance,
}
free(savefile);
}
resuming = pcmain(argc,argv);
resuming = pcmain(argc, argv);
moveloop(resuming);
moveloop(resuming);
return 0;
return 0;
}
PNHWinApp GetNHApp()
PNHWinApp
GetNHApp()
{
return &_nethack_app;
return &_nethack_app;
}
TCHAR* _get_cmd_arg(TCHAR* pCmdLine)
TCHAR *
_get_cmd_arg(TCHAR *pCmdLine)
{
static TCHAR* pArgs = NULL;
TCHAR *pRetArg;
BOOL bQuoted;
static TCHAR *pArgs = NULL;
TCHAR *pRetArg;
BOOL bQuoted;
if( !pCmdLine && !pArgs ) return NULL;
if( !pArgs ) pArgs = pCmdLine;
if (!pCmdLine && !pArgs)
return NULL;
if (!pArgs)
pArgs = pCmdLine;
/* skip whitespace */
for(pRetArg = pArgs; *pRetArg && _istspace(*pRetArg); pRetArg = CharNext(pRetArg));
if( !*pRetArg ) {
pArgs = NULL;
return NULL;
}
/* skip whitespace */
for (pRetArg = pArgs; *pRetArg && _istspace(*pRetArg);
pRetArg = CharNext(pRetArg))
;
if (!*pRetArg) {
pArgs = NULL;
return NULL;
}
/* check for quote */
if( *pRetArg==TEXT('"') ) {
bQuoted = TRUE;
pRetArg = CharNext(pRetArg);
pArgs = _tcschr(pRetArg, TEXT('"'));
} else {
/* skip to whitespace */
for(pArgs = pRetArg; *pArgs && !_istspace(*pArgs); pArgs = CharNext(pArgs));
}
if( pArgs && *pArgs ) {
TCHAR* p;
p = pArgs;
pArgs = CharNext(pArgs);
*p = (TCHAR)0;
} else {
pArgs = NULL;
}
/* check for quote */
if (*pRetArg == TEXT('"')) {
bQuoted = TRUE;
pRetArg = CharNext(pRetArg);
pArgs = _tcschr(pRetArg, TEXT('"'));
} else {
/* skip to whitespace */
for (pArgs = pRetArg; *pArgs && !_istspace(*pArgs);
pArgs = CharNext(pArgs))
;
}
return pRetArg;
if (pArgs && *pArgs) {
TCHAR *p;
p = pArgs;
pArgs = CharNext(pArgs);
*p = (TCHAR) 0;
} else {
pArgs = NULL;
}
return pRetArg;
}
/* Get the version of the Common Control library on this machine.
Copied from the Microsoft SDK
*/
HRESULT GetComCtlVersion(LPDWORD pdwMajor, LPDWORD pdwMinor)
HRESULT
GetComCtlVersion(LPDWORD pdwMajor, LPDWORD pdwMinor)
{
HINSTANCE hComCtl;
HRESULT hr = S_OK;
DLLGETVERSIONPROC pDllGetVersion;
HINSTANCE hComCtl;
HRESULT hr = S_OK;
DLLGETVERSIONPROC pDllGetVersion;
if(IsBadWritePtr(pdwMajor, sizeof(DWORD)) ||
IsBadWritePtr(pdwMinor, sizeof(DWORD)))
return E_INVALIDARG;
//load the DLL
hComCtl = LoadLibrary(TEXT("comctl32.dll"));
if (!hComCtl) return E_FAIL;
if (IsBadWritePtr(pdwMajor, sizeof(DWORD))
|| IsBadWritePtr(pdwMinor, sizeof(DWORD)))
return E_INVALIDARG;
// load the DLL
hComCtl = LoadLibrary(TEXT("comctl32.dll"));
if (!hComCtl)
return E_FAIL;
/*
You must get this function explicitly because earlier versions of the DLL
don't implement this function. That makes the lack of implementation of the
function a version marker in itself.
*/
pDllGetVersion = (DLLGETVERSIONPROC)GetProcAddress(hComCtl, TEXT("DllGetVersion"));
if(pDllGetVersion) {
DLLVERSIONINFO dvi;
ZeroMemory(&dvi, sizeof(dvi));
dvi.cbSize = sizeof(dvi);
hr = (*pDllGetVersion)(&dvi);
if(SUCCEEDED(hr)) {
*pdwMajor = dvi.dwMajorVersion;
*pdwMinor = dvi.dwMinorVersion;
} else {
hr = E_FAIL;
}
/*
You must get this function explicitly because earlier versions of the DLL
don't implement this function. That makes the lack of implementation of
the
function a version marker in itself.
*/
pDllGetVersion =
(DLLGETVERSIONPROC) GetProcAddress(hComCtl, TEXT("DllGetVersion"));
if (pDllGetVersion) {
DLLVERSIONINFO dvi;
ZeroMemory(&dvi, sizeof(dvi));
dvi.cbSize = sizeof(dvi);
hr = (*pDllGetVersion)(&dvi);
if (SUCCEEDED(hr)) {
*pdwMajor = dvi.dwMajorVersion;
*pdwMinor = dvi.dwMinorVersion;
} else {
/*
If GetProcAddress failed, then the DLL is a version previous to the one
shipped with IE 3.x.
*/
*pdwMajor = 4;
*pdwMinor = 0;
}
FreeLibrary(hComCtl);
return hr;
hr = E_FAIL;
}
} else {
/*
If GetProcAddress failed, then the DLL is a version previous to the
one
shipped with IE 3.x.
*/
*pdwMajor = 4;
*pdwMinor = 0;
}
FreeLibrary(hComCtl);
return hr;
}