mirror of
https://github.com/weiju/amiga-stuff
synced 2026-09-11 19:26:01 +00:00
cleaned up requester logic
cancel button sends close event now, requester is initialized only once
This commit is contained in:
@@ -8,7 +8,7 @@ clean:
|
||||
rm -f *.o iffview ilbm
|
||||
|
||||
iffview: iffview.o ilbm.o filereq.o
|
||||
$(CC) $(CFLAGS) $? -lamiga -lauto -o $@
|
||||
$(CC) $(CFLAGS) $^ -lamiga -lauto -o $@
|
||||
|
||||
# Mostly for testing
|
||||
ilbm: ilbm.c
|
||||
|
||||
+61
-50
@@ -9,65 +9,76 @@
|
||||
|
||||
#define REQ_TEXT_XOFFSET 10
|
||||
#define BUTTON_TEXT_XOFFSET 14
|
||||
#define OK_BUTTON_WIDTH 40
|
||||
#define OK_BUTTON_HEIGHT 24
|
||||
#define REQ_WIDTH 200
|
||||
#define REQ_HEIGHT 100
|
||||
#define TOPAZ_BASELINE 8
|
||||
#define BUTTON_HEIGHT 24
|
||||
|
||||
#define OK_BUTTON_X 20
|
||||
#define OK_BUTTON_WIDTH 40
|
||||
#define CANCEL_BUTTON_WIDTH 60
|
||||
#define PATH_GADGET_WIDTH 100
|
||||
|
||||
|
||||
struct Requester requester;
|
||||
struct IntuiText labels[] = {
|
||||
{1, 0, JAM2, REQ_TEXT_XOFFSET, TOPAZ_BASELINE, NULL, "Enter file path", NULL},
|
||||
{1, 0, JAM2, 10, TOPAZ_BASELINE, NULL, "Ok", NULL},
|
||||
{1, 0, JAM2, 10, TOPAZ_BASELINE, NULL, "Cancel", NULL} /* TOPAZ_BASELINE is 8 */
|
||||
};
|
||||
WORD gadget_border_points[3][10] = {
|
||||
{0, 0, OK_BUTTON_WIDTH, 0, OK_BUTTON_WIDTH, BUTTON_HEIGHT, 0, BUTTON_HEIGHT, 0, 0},
|
||||
{0, 0, CANCEL_BUTTON_WIDTH, 0, CANCEL_BUTTON_WIDTH, BUTTON_HEIGHT, 0, BUTTON_HEIGHT, 0, 0},
|
||||
{-2, -2, PATH_GADGET_WIDTH, -2, PATH_GADGET_WIDTH, 10, -2, 10, -2, -2}
|
||||
};
|
||||
struct Border gadget_borders[] = {
|
||||
{0, 0, 1, 0, JAM1, 5, gadget_border_points[0], NULL},
|
||||
{0, 0, 1, 0, JAM1, 5, gadget_border_points[1], NULL},
|
||||
{0, 0, 1, 0, JAM1, 5, gadget_border_points[2], NULL}
|
||||
};
|
||||
|
||||
WORD req_border_points[] = {
|
||||
0, 0, REQ_WIDTH - 1, 0, REQ_WIDTH - 1, REQ_HEIGHT - 1, 0, REQ_HEIGHT - 1, 0, 0
|
||||
};
|
||||
struct Border req_border = {0, 0, 1, 0, JAM1, 5, req_border_points, NULL};
|
||||
|
||||
UBYTE buffer[81], undobuffer[81];
|
||||
struct StringInfo strinfo = {buffer, undobuffer, 0, 80, 0, 0, 0, 0, 0, 0, NULL, 0, NULL};
|
||||
|
||||
/*
|
||||
Note: Cancel does not specify the GACT_ENDGADGET flag, it seems that
|
||||
IDCMP_REQCLEAR is not fired when Intuition closes the requester automatically
|
||||
*/
|
||||
struct Gadget gadgets[] = {
|
||||
{&gadgets[1], OK_BUTTON_X, 50, OK_BUTTON_WIDTH, BUTTON_HEIGHT, GFLG_GADGHCOMP,
|
||||
GACT_RELVERIFY, GTYP_BOOLGADGET | GTYP_REQGADGET, &gadget_borders[0], NULL,
|
||||
&labels[1], 0, NULL, REQ_OK_BUTTON_ID, NULL},
|
||||
{&gadgets[2], 80, 50, CANCEL_BUTTON_WIDTH, BUTTON_HEIGHT, GFLG_GADGHCOMP,
|
||||
GACT_RELVERIFY, GTYP_BOOLGADGET | GTYP_REQGADGET, &gadget_borders[1], NULL,
|
||||
&labels[2], 0, NULL, REQ_CANCEL_BUTTON_ID, NULL},
|
||||
{NULL, OK_BUTTON_X, 20, PATH_GADGET_WIDTH, 10,
|
||||
GFLG_GADGHCOMP, GACT_RELVERIFY, GTYP_STRGADGET, &gadget_borders[2], NULL,
|
||||
&labels[3], 0, &strinfo, 103, NULL},
|
||||
};
|
||||
|
||||
BOOL initialized = 0;
|
||||
|
||||
struct Requester *open_file(struct Window *window)
|
||||
{
|
||||
/*
|
||||
* note that these are setup statically, otherwise they are lost as soon as
|
||||
* the functions exits
|
||||
*/
|
||||
static struct IntuiText labels[] = {
|
||||
{1, 0, JAM2, REQ_TEXT_XOFFSET, TOPAZ_BASELINE, NULL, "Enter file path", NULL},
|
||||
{1, 0, JAM2, 10, TOPAZ_BASELINE, NULL, "Ok", NULL},
|
||||
{1, 0, JAM2, 50, TOPAZ_BASELINE, NULL, "Cancel", NULL} /* TOPAZ_BASELINE is 8 */
|
||||
};
|
||||
|
||||
static WORD button_border_points[] = {
|
||||
0, 0, OK_BUTTON_WIDTH, 0, OK_BUTTON_WIDTH, OK_BUTTON_HEIGHT, 0, OK_BUTTON_HEIGHT, 0, 0
|
||||
};
|
||||
static struct Border button_border = {0, 0, 1, 0, JAM1, 5, button_border_points, NULL};
|
||||
|
||||
static WORD req_border_points[] = {
|
||||
0, 0, REQ_WIDTH - 1, 0, REQ_WIDTH - 1, REQ_HEIGHT - 1, 0, REQ_HEIGHT - 1, 0, 0
|
||||
};
|
||||
static struct Border req_border = {0, 0, 1, 0, JAM1, 5, req_border_points, NULL};
|
||||
BOOL result;
|
||||
|
||||
static struct Gadget button1 = {
|
||||
NULL, 20, 50, OK_BUTTON_WIDTH, OK_BUTTON_HEIGHT, GFLG_GADGHCOMP,
|
||||
GACT_RELVERIFY,
|
||||
/* GACT_RELVERIFY | GACT_ENDGADGET, */
|
||||
GTYP_BOOLGADGET | GTYP_REQGADGET,
|
||||
&button_border, NULL, &labels[1],
|
||||
0, NULL, REQ_OK_BUTTON_ID, NULL
|
||||
};
|
||||
|
||||
InitRequester(&requester);
|
||||
requester.LeftEdge = 20;
|
||||
requester.TopEdge = 20;
|
||||
requester.Width = REQ_WIDTH;
|
||||
requester.Height = REQ_HEIGHT;
|
||||
requester.Flags = 0;
|
||||
requester.BackFill = 0;
|
||||
requester.ReqGadget = &button1;
|
||||
requester.ReqBorder = &req_border;
|
||||
requester.ReqText = &labels[0];
|
||||
|
||||
if (!initialized) {
|
||||
InitRequester(&requester);
|
||||
requester.LeftEdge = 20;
|
||||
requester.TopEdge = 20;
|
||||
requester.Width = REQ_WIDTH;
|
||||
requester.Height = REQ_HEIGHT;
|
||||
requester.Flags = 0;
|
||||
requester.BackFill = 0;
|
||||
requester.ReqGadget = &gadgets[0];
|
||||
requester.ReqBorder = &req_border;
|
||||
requester.ReqText = &labels[0];
|
||||
initialized = 1;
|
||||
}
|
||||
result = Request(&requester, window);
|
||||
if (result) {
|
||||
puts("Requester could be opened");
|
||||
return &requester;
|
||||
}
|
||||
else {
|
||||
puts("Requester could not be opened");
|
||||
return NULL;
|
||||
}
|
||||
return result ? &requester : NULL;
|
||||
}
|
||||
|
||||
@@ -5,5 +5,6 @@
|
||||
extern struct Requester *open_file(struct Window *window);
|
||||
|
||||
#define REQ_OK_BUTTON_ID 101
|
||||
#define REQ_CANCEL_BUTTON_ID 102
|
||||
|
||||
#endif /* __FILEREQ_H__ */
|
||||
|
||||
@@ -123,6 +123,7 @@ void handle_events()
|
||||
case IDCMP_GADGETUP:
|
||||
buttonId = (int) ((struct Gadget *) (msg->IAddress))->GadgetID;
|
||||
if (buttonId == REQ_OK_BUTTON_ID && filereq) EndRequest(filereq, window);
|
||||
else if (buttonId == REQ_CANCEL_BUTTON_ID && filereq) EndRequest(filereq, window);
|
||||
break;
|
||||
case IDCMP_REQCLEAR:
|
||||
puts("requester closed");
|
||||
|
||||
Reference in New Issue
Block a user