moved file requester to separate project

This commit is contained in:
Wei-ju Wu
2016-01-11 23:09:10 -08:00
parent 3537f8d4d5
commit 46566c361e
4 changed files with 7 additions and 167 deletions
+1 -1
View File
@@ -7,7 +7,7 @@ all: iffview
clean:
rm -f *.o iffview ilbm
iffview: iffview.o ilbm.o filereq.o
iffview: iffview.o ilbm.o
$(CC) $(CFLAGS) $^ -lamiga -lauto -o $@
# Mostly for testing
-131
View File
@@ -1,131 +0,0 @@
#include <intuition/intuition.h>
#include <clib/intuition_protos.h>
#include <clib/dos_protos.h>
#include <clib/alib_stdio_protos.h>
#include "filereq.h"
#define REQ_TEXT_XOFFSET 10
#define REQ_WIDTH 240
#define REQ_HEIGHT 170
#define TOPAZ_BASELINE 8
#define BUTTON_Y 140
#define BUTTON_HEIGHT 18
#define BUTTON_TEXT_XOFFSET 14
#define OK_BUTTON_X 20
#define CANCEL_BUTTON_X 160
#define OK_BUTTON_WIDTH 40
#define CANCEL_BUTTON_WIDTH 60
#define STR_GADGET_X 90
#define STR_GADGET_Y 120
#define PATH_GADGET_WIDTH 100
struct Requester requester;
struct IntuiText labels[] = {
{1, 0, JAM2, REQ_TEXT_XOFFSET, STR_GADGET_Y, NULL, "Enter file path", NULL},
{1, 0, JAM2, 10, TOPAZ_BASELINE - 4, NULL, "Ok", NULL},
{1, 0, JAM2, 10, TOPAZ_BASELINE - 4, 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},
/* the -2 is the margin to set to avoid that the string gadget will overdraw the
borders */
{-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, BUTTON_Y, 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], CANCEL_BUTTON_X, BUTTON_Y, 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, STR_GADGET_X, STR_GADGET_Y, PATH_GADGET_WIDTH, 10,
GFLG_GADGHCOMP, GACT_RELVERIFY, GTYP_STRGADGET, &gadget_borders[2], NULL,
&labels[3], 0, &strinfo, 103, NULL},
};
BOOL initialized = 0;
#define PATHBUFFER_SIZE 200
char dirname[PATHBUFFER_SIZE + 1];
BPTR flock;
LONG error;
struct FileInfoBlock fileinfo;
void print_fileinfo(struct FileInfoBlock *fileinfo)
{
if (fileinfo->fib_DirEntryType > 0) {
printf("dir: '%s'\n", fileinfo->fib_FileName);
} else {
printf("file: '%s'\n", fileinfo->fib_FileName);
}
}
struct Requester *open_file(struct Window *window)
{
BOOL result;
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];
/* scan current directory */
/*
on AmigaOS versions before 36 (essentially all 1.x versions), the
function GetCurrentDirName() does not exist, but it's obtainable
by calling Cli() and querying the returned CommandLineInterface
structure
*/
puts("scanning directory...");
/*
// on AmigaOS 1.x, this function does not exist !!!
GetCurrentDirName(dirname, PATHBUFFER_SIZE);
printf("current dir: '%s'\n", dirname);
flock = Lock(dirname, SHARED_LOCK);
if (Examine(flock, &fileinfo)) {
while (ExNext(flock, &fileinfo)) {
print_fileinfo(&fileinfo);
}
error = IoErr();
if (error != ERROR_NO_MORE_ENTRIES) {
puts("unknown I/O error, TODO handle");
}
}
UnLock(flock);
*/
initialized = 1;
}
result = Request(&requester, window);
return result ? &requester : NULL;
}
-10
View File
@@ -1,10 +0,0 @@
#pragma once
#ifndef __FILEREQ_H__
#define __FILEREQ_H__
extern struct Requester *open_file(struct Window *window);
#define REQ_OK_BUTTON_ID 101
#define REQ_CANCEL_BUTTON_ID 102
#endif /* __FILEREQ_H__ */
+6 -25
View File
@@ -28,7 +28,6 @@
#ifdef __VBCC__
#include <clib/alib_stdio_protos.h>
#endif
#include "filereq.h"
#include "ilbm.h"
#define WIN_LEFT 10
@@ -44,8 +43,7 @@
#define FILE_MENU_NUM 0
#define NUM_FILE_MENU_ITEMS 2
#define OPEN_MENU_ITEM_NUM 0
#define QUIT_MENU_ITEM_NUM 1
#define QUIT_MENU_ITEM_NUM 0
struct NewWindow newwin = {
WIN_LEFT, WIN_TOP, WIN_WIDTH, WIN_HEIGHT, 0, 1,
@@ -64,8 +62,6 @@ struct IntuiText menutext[] = {
};
struct MenuItem fileMenuItems[] = {
{&fileMenuItems[1], 0, 0, 0, 0, ITEMTEXT | ITEMENABLED | HIGHCOMP | COMMSEQ, 0,
&menutext[0], NULL, 'O', NULL, 0},
{NULL, 0, 0, 0, 0, ITEMTEXT | ITEMENABLED | HIGHCOMP | COMMSEQ, 0,
&menutext[1], NULL, 'Q', NULL, 0}
};
@@ -88,8 +84,6 @@ void cleanup()
}
}
struct Requester *filereq;
BOOL handle_menu(UWORD menuNum, UWORD itemNum, UWORD subItemNum)
{
printf("menu, menu num: %d, item num: %d, sub item num: %d\n",
@@ -98,9 +92,6 @@ BOOL handle_menu(UWORD menuNum, UWORD itemNum, UWORD subItemNum)
/* quit */
return TRUE;
}
if (menuNum == FILE_MENU_NUM && itemNum == OPEN_MENU_ITEM_NUM) {
filereq = open_file(window);
}
return FALSE;
}
@@ -124,11 +115,6 @@ void handle_events()
menuCode = msg->Code;
done = handle_menu(MENUNUM(menuCode), ITEMNUM(menuCode), SUBNUM(menuCode));
break;
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");
break;
@@ -194,9 +180,7 @@ int main(int argc, char **argv)
printf("DOS, version: %d, revision: %d\n",
(int) DOSBase->lib_Version, (int) DOSBase->lib_Revision);
ILBMData *ilbm_data = NULL;
//ilbm_data = parse_file("examples/Kickstart13.iff");
//ilbm_data = parse_file("examples/AH_KingTut.iff");
ilbm_data = parse_file("examples/DeluxePaint_Waterfall.iff");
ilbm_data = parse_file("examples/AH_KingTut.iff");
image.Width = ilbm_data->bmheader->w;
image.Height = ilbm_data->bmheader->h;
image.Depth = ilbm_data->bmheader->nPlanes;
@@ -206,13 +190,9 @@ int main(int argc, char **argv)
int wordwidth = image.Width / 16;
int finalsize = wordwidth * image.Height * image.Depth * sizeof(UWORD);
image.ImageData = AllocMem(finalsize, MEMF_CHIP|MEMF_CLEAR);
ilbm_to_image_data((char *) image.ImageData, ilbm_data, wordwidth * 16, image.Height);
ilbm_to_image_data((char *) image.ImageData, ilbm_data, wordwidth * 16,
image.Height);
image.PlanePick = (1 << image.Depth) - 1;
/*
Note that the image width is now set to the data's image width.
Displayed correctly now.
*/
image.Width = wordwidth * 16;
/* Adjust the new screen according to the IFF image */
newscreen.Depth = image.Depth;
@@ -220,7 +200,8 @@ int main(int argc, char **argv)
if (screen) {
for (int i = 0; i < ilbm_data->num_colors; i++) {
ColorRegister *color = &ilbm_data->colors[i];
SetRGB4(&screen->ViewPort, i, color->red >> 4, color->green >> 4, color->blue >> 4);
SetRGB4(&screen->ViewPort, i, color->red >> 4,
color->green >> 4, color->blue >> 4);
}
}