X-Git-Url: https://jxself.org/git/?p=super-star-trek.git;a=blobdiff_plain;f=src%2Fxio.c;h=9e59c19945c595c9af846ff61a972695a7c98ef3;hp=2bdb4653d4ab0e38b4e75259a76ae693dbb6679e;hb=9aef5f5aae5fde0ed2b462945750c7aee59b3c1e;hpb=0626c18f1b1aa99ad4d91953d74446bff155ef57 diff --git a/src/xio.c b/src/xio.c index 2bdb465..9e59c19 100644 --- a/src/xio.c +++ b/src/xio.c @@ -1,4 +1,26 @@ +/* + * Problems with this code: + * 1. The text window behaves like it's only a few lines high, + * scrolling in response to Return when the insertion point + * is nowhere near the last line. + * 2. The attempt to insert text with XawTextReplace() core dumps. + * 3. I haven't found a way to write a callback that triggers on Return + * and yields the line before the return. The explanation at + * http://www.linuxjunkies.org/programming/GUI/xwindow/x11/text.html + * hints that this may be difficult. + * + * The functional goal is this: + * 1. Button pushes should be able to insert commands at the buffer's + * current insertion point. + * 2. When a user finishes a command with Return, a callback should + * receive the line of input typed. + * + * All the input passed to the game in back of this will be lines full + * of commands generated either by typing into the text buffer directly + * or by button presses that generate text unto the buffer. + */ #include +#include #include #include #include @@ -6,7 +28,9 @@ #include #include #include -#include "sst.h" +//#include "sst.h" +#define OPTION_PLANETS 1 +#define OPTION_PROBE 2 static XtAppContext app_context; static Widget toplevel, text, form; @@ -14,9 +38,30 @@ static Widget navigation, weapons, planets, misc; static Widget navlabel, weaplabel, planlabel, misclabel; static String fallback[] = { - /* text window resources */ "*text.resizable: true", "*text.resize: ResizeBoth", + "*text.width: 640", + "*text.height: 200", + "*text.autoFill: True", + "*text.scrollVertical: Always", + "*text.scrollHorizontal: WhenNeeded", + "*text.displayCaret: True", + "*navigation.fromVert: text", + "*navigation.borderWidth: 0", + "*navlabel.label: Navigation: ", + "*navlabel.borderWidth: 0", + "*weapons.fromVert: navigation", + "*weapons.borderWidth: 0", + "*weaplabel.label: Weapons: ", + "*weaplabel.borderWidth: 0", + "*planets.fromVert: weapons", + "*planets.borderWidth: 0", + "*planlabel.label: Planets: ", + "*planlabel.borderWidth: 0", + "*misc.fromVert: planets", + "*misc.borderWidth: 0", + "*misclabel.label: Miscellaneous:", + "*misclabel.borderWidth: 0", NULL, }; @@ -35,10 +80,25 @@ static void quit_proc(Widget w, XtPointer client_data, XtPointer call_data) exit (0); } +static void text_append_to(Widget w, String str) +/* append text to a specified text widget */ +{ + XawTextBlock txtblk; + XawTextPosition textend = XawTextGetInsertionPoint(w); + + txtblk.ptr = str; + txtblk.length = strlen(str); + txtblk.firstPos = 0; + txtblk.format = FMT8BIT; + + XawTextReplace(w, textend, textend, &txtblk); +} + static void noargs_proc(Widget w, XtPointer client_data, XtPointer call_data) /* use this for commands that take no arguments */ { /* currently a stub */ + text_append_to(w, XtName(w)); printf("Button %s pressed\n", XtName(w)); } @@ -76,9 +136,6 @@ static struct cmd_t commands[] = { {"Help", noargs_proc, &misc, 0}, }; -#define MAXWIDTH 640 -#define TEXTHEIGHT 200 - static void instantiate_main(int argc, char **argv) { struct cmd_t *cp; @@ -89,52 +146,41 @@ static void instantiate_main(int argc, char **argv) XtNallowShellResize, True, NULL); form = XtVaCreateManagedWidget("form", formWidgetClass, toplevel, NULL); /* the command window */ - text = XtVaCreateManagedWidget("text", asciiTextWidgetClass, form, - XtNwidth, MAXWIDTH, XtNheight, TEXTHEIGHT, + text = XtVaCreateManagedWidget("text", + asciiTextWidgetClass, form, + XtNeditType, XawtextEdit, NULL); - XtVaSetValues(text, XtNeditType,XawtextRead, XtNdisplayCaret,False, NULL); /* The button panels */ navigation = XtVaCreateManagedWidget("navigation", boxWidgetClass, form, - XtNborderWidth, 0, - XtNfromVert, text, XtNorientation, XtorientHorizontal, NULL); - navlabel = XtVaCreateManagedWidget("Navigation: ", + navlabel = XtVaCreateManagedWidget("navlabel", labelWidgetClass, navigation, - XtNborderWidth, 0, NULL); weapons = XtVaCreateManagedWidget("weapons", boxWidgetClass, form, - XtNborderWidth, 0, - XtNfromVert, navigation, XtNorientation, XtorientHorizontal, NULL); - weaplabel = XtVaCreateManagedWidget("Weapons: ", + weaplabel = XtVaCreateManagedWidget("weaplabel", labelWidgetClass, weapons, - XtNborderWidth, 0, NULL); planets = XtVaCreateManagedWidget("planets", boxWidgetClass, form, - XtNborderWidth, 0, - XtNfromVert, weapons, XtNorientation, XtorientHorizontal, NULL); - planlabel = XtVaCreateManagedWidget("Planets: ", + planlabel = XtVaCreateManagedWidget("planlabel", labelWidgetClass, planets, XtNborderWidth, 0, NULL); misc = XtVaCreateManagedWidget("misc", boxWidgetClass, form, - XtNborderWidth, 0, - XtNfromVert, planets, XtNorientation, XtorientHorizontal, NULL); - misclabel = XtVaCreateManagedWidget("Miscellaneous:", + misclabel = XtVaCreateManagedWidget("misclabel", labelWidgetClass, misc, - XtNborderWidth, 0, NULL); - for (cp = commands; cp < commands + sizeof(commands)/sizeof(commands[0]); cp++) { + for (cp = commands; cp < commands + ARRAY_SIZE(commands); cp++) { cp->widget = XtVaCreateManagedWidget(cp->name, commandWidgetClass, *cp->parent,