mirror of
https://github.com/weiju/amiga-stuff
synced 2025-11-19 16:01:31 +00:00
updates to IFFView and requesters
IFFView: * error in input file -> exit * can now view HAM and EHB requesters: * updated layout
This commit is contained in:
@ -16,6 +16,7 @@
|
|||||||
along with amiga30yrs. If not, see <http://www.gnu.org/licenses/>.
|
along with amiga30yrs. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <exec/libraries.h>
|
#include <exec/libraries.h>
|
||||||
#include <intuition/intuition.h>
|
#include <intuition/intuition.h>
|
||||||
@ -173,6 +174,7 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
ILBMData *ilbm_data = NULL;
|
ILBMData *ilbm_data = NULL;
|
||||||
ilbm_data = parse_file(argv[1]);
|
ilbm_data = parse_file(argv[1]);
|
||||||
|
if (!ilbm_data) exit(0);
|
||||||
image.Width = ilbm_data->bmheader->w;
|
image.Width = ilbm_data->bmheader->w;
|
||||||
image.Height = ilbm_data->bmheader->h;
|
image.Height = ilbm_data->bmheader->h;
|
||||||
image.Depth = ilbm_data->bmheader->nPlanes;
|
image.Depth = ilbm_data->bmheader->nPlanes;
|
||||||
@ -186,6 +188,7 @@ int main(int argc, char **argv)
|
|||||||
image.PlanePick = (1 << image.Depth) - 1;
|
image.PlanePick = (1 << image.Depth) - 1;
|
||||||
|
|
||||||
/* Adjust the new screen according to the IFF image */
|
/* Adjust the new screen according to the IFF image */
|
||||||
|
newscreen.ViewModes = ilbm_data->bmheader->camgFlags;
|
||||||
newscreen.Depth = image.Depth;
|
newscreen.Depth = image.Depth;
|
||||||
screen = OpenScreen(&newscreen);
|
screen = OpenScreen(&newscreen);
|
||||||
if (screen) {
|
if (screen) {
|
||||||
|
|||||||
@ -33,7 +33,7 @@ BitMapHeader *read_BMHD(FILE *fp, int datasize)
|
|||||||
BitMapHeader *header;
|
BitMapHeader *header;
|
||||||
int bytes_read;
|
int bytes_read;
|
||||||
|
|
||||||
header = malloc(sizeof(BitMapHeader));
|
header = calloc(1, sizeof(BitMapHeader));
|
||||||
bytes_read = fread(header, sizeof(char), datasize, fp);
|
bytes_read = fread(header, sizeof(char), datasize, fp);
|
||||||
|
|
||||||
#ifdef LITTLE_ENDIAN
|
#ifdef LITTLE_ENDIAN
|
||||||
@ -156,7 +156,7 @@ ILBMData *read_chunks(FILE *fp, int filesize, int total_read)
|
|||||||
if (!strncmp("BMHD", buffer, 4)) bmheader = read_BMHD(fp, datasize);
|
if (!strncmp("BMHD", buffer, 4)) bmheader = read_BMHD(fp, datasize);
|
||||||
else if (!strncmp("CMAP", buffer, 4)) colors = read_CMAP(fp, datasize, &result->num_colors);
|
else if (!strncmp("CMAP", buffer, 4)) colors = read_CMAP(fp, datasize, &result->num_colors);
|
||||||
else if (!strncmp("CRNG", buffer, 4)) read_CRNG(fp, datasize);
|
else if (!strncmp("CRNG", buffer, 4)) read_CRNG(fp, datasize);
|
||||||
else if (!strncmp("CAMG", buffer, 4)) read_CAMG(fp, datasize);
|
else if (!strncmp("CAMG", buffer, 4)) bmheader->camgFlags = read_CAMG(fp, datasize);
|
||||||
else if (!strncmp("BODY", buffer, 4)) imgdata = read_BODY(fp, datasize, bmheader, &imgdata_size);
|
else if (!strncmp("BODY", buffer, 4)) imgdata = read_BODY(fp, datasize, bmheader, &imgdata_size);
|
||||||
else {
|
else {
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
@ -285,14 +285,17 @@ int main(int argc, char **argv)
|
|||||||
} else {
|
} else {
|
||||||
ILBMData *data = parse_file(argv[1]);
|
ILBMData *data = parse_file(argv[1]);
|
||||||
print_ilbm_info(data);
|
print_ilbm_info(data);
|
||||||
|
int dest_width = data->bmheader->w;
|
||||||
int wordwidth = (data->bmheader->w + 16) / 16;
|
int mod16 = dest_width % 16;
|
||||||
int destWidth = wordwidth * 16;
|
if (mod16 > 0) {
|
||||||
int destHeight = data->bmheader->h;
|
dest_width += mod16;
|
||||||
|
}
|
||||||
|
int wordwidth = dest_width / 16;
|
||||||
|
int dest_height = data->bmheader->h;
|
||||||
int finalsize = wordwidth * data->bmheader->h * data->bmheader->nPlanes * 2;
|
int finalsize = wordwidth * data->bmheader->h * data->bmheader->nPlanes * 2;
|
||||||
printf("loaded size: %d, final size: %d\n", data->data_bytes, finalsize);
|
printf("loaded size: %d, final size: %d\n", data->data_bytes, finalsize);
|
||||||
char *dest = calloc(finalsize, sizeof(char));
|
char *dest = calloc(finalsize, sizeof(char));
|
||||||
ilbm_to_image_data(dest, data, destWidth, destHeight);
|
ilbm_to_image_data(dest, data, dest_width, dest_height);
|
||||||
free(dest);
|
free(dest);
|
||||||
free_ilbm_data(data);
|
free_ilbm_data(data);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -58,15 +58,16 @@ typedef UBYTE Compression;
|
|||||||
#define cmpByteRun1 1
|
#define cmpByteRun1 1
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
UWORD w, h;
|
UWORD w, h;
|
||||||
WORD x, y;
|
WORD x, y;
|
||||||
UBYTE nPlanes;
|
UBYTE nPlanes;
|
||||||
Masking masking;
|
Masking masking;
|
||||||
Compression compression;
|
Compression compression;
|
||||||
UBYTE pad1;
|
UBYTE pad1;
|
||||||
UWORD transparentColor;
|
UWORD transparentColor;
|
||||||
UBYTE xAspect, yAspect;
|
UBYTE xAspect, yAspect;
|
||||||
WORD pageWidth, pageHeight;
|
WORD pageWidth, pageHeight;
|
||||||
|
ULONG camgFlags;
|
||||||
} BitMapHeader;
|
} BitMapHeader;
|
||||||
|
|
||||||
/* Colors are in the range 0-255 */
|
/* Colors are in the range 0-255 */
|
||||||
|
|||||||
@ -7,7 +7,6 @@
|
|||||||
|
|
||||||
#include "filereq.h"
|
#include "filereq.h"
|
||||||
|
|
||||||
#define REQ_TEXT_XOFFSET 10
|
|
||||||
#define REQ_WIDTH 240
|
#define REQ_WIDTH 240
|
||||||
#define REQ_HEIGHT 175
|
#define REQ_HEIGHT 175
|
||||||
#define TOPAZ_BASELINE 8
|
#define TOPAZ_BASELINE 8
|
||||||
@ -21,19 +20,25 @@
|
|||||||
#define OK_BUTTON_WIDTH 40
|
#define OK_BUTTON_WIDTH 40
|
||||||
#define CANCEL_BUTTON_WIDTH 60
|
#define CANCEL_BUTTON_WIDTH 60
|
||||||
|
|
||||||
#define STR_GADGET_X 90
|
#define DRAWER_GADGET_X 80
|
||||||
#define STR_GADGET_Y 120
|
#define DRAWER_GADGET_Y 95
|
||||||
#define PATH_GADGET_WIDTH 100
|
#define FILE_GADGET_X 80
|
||||||
|
#define FILE_GADGET_Y 115
|
||||||
|
#define PATH_GADGET_WIDTH 120
|
||||||
|
#define STR_LABEL_XOFFSET -70
|
||||||
|
#define STR_LABEL_YOFFSET 2
|
||||||
|
|
||||||
static struct Requester requester;
|
static struct Requester requester;
|
||||||
static BOOL req_opened = FALSE;
|
static BOOL req_opened = FALSE;
|
||||||
static struct Window *req_window;
|
static struct Window *req_window;
|
||||||
|
|
||||||
static struct IntuiText labels[] = {
|
static struct IntuiText drawer_str_label = {1, 0, JAM2, STR_LABEL_XOFFSET, STR_LABEL_YOFFSET, NULL,
|
||||||
{1, 0, JAM2, REQ_TEXT_XOFFSET, STR_GADGET_Y, NULL, "Enter file path", NULL},
|
"Drawer", NULL};
|
||||||
{1, 0, JAM2, 10, TOPAZ_BASELINE - 4, NULL, "Ok", NULL},
|
static struct IntuiText file_str_label = {1, 0, JAM2, STR_LABEL_XOFFSET, STR_LABEL_YOFFSET, NULL,
|
||||||
{1, 0, JAM2, 10, TOPAZ_BASELINE - 4, NULL, "Cancel", NULL} /* TOPAZ_BASELINE is 8 */
|
"File", NULL};
|
||||||
};
|
static struct IntuiText ok_button_label = {1, 0, JAM2, 10, TOPAZ_BASELINE - 4, NULL, "Ok", NULL};
|
||||||
|
static struct IntuiText cancel_button_label = {1, 0, JAM2, 10, TOPAZ_BASELINE - 4, NULL,
|
||||||
|
"Cancel", NULL};
|
||||||
|
|
||||||
static WORD gadget_border_points[3][10] = {
|
static WORD gadget_border_points[3][10] = {
|
||||||
{0, 0, OK_BUTTON_WIDTH, 0, OK_BUTTON_WIDTH, BUTTON_HEIGHT, 0, BUTTON_HEIGHT, 0, 0},
|
{0, 0, OK_BUTTON_WIDTH, 0, OK_BUTTON_WIDTH, BUTTON_HEIGHT, 0, BUTTON_HEIGHT, 0, 0},
|
||||||
@ -43,14 +48,14 @@ static WORD gadget_border_points[3][10] = {
|
|||||||
{-2, -2, PATH_GADGET_WIDTH, -2, PATH_GADGET_WIDTH, 10, -2, 10, -2, -2}
|
{-2, -2, PATH_GADGET_WIDTH, -2, PATH_GADGET_WIDTH, 10, -2, 10, -2, -2}
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct Border gadget_borders[] = {
|
static struct Border ok_button_border = {0, 0, 1, 0, JAM1, 5, gadget_border_points[0], NULL};
|
||||||
{0, 0, 1, 0, JAM1, 5, gadget_border_points[0], NULL},
|
static struct Border cancel_button_border = {0, 0, 1, 0, JAM1, 5, gadget_border_points[1], NULL};
|
||||||
{0, 0, 1, 0, JAM1, 5, gadget_border_points[1], NULL},
|
static struct Border str_gadget_border = {0, 0, 1, 0, JAM1, 5, gadget_border_points[2], NULL};
|
||||||
{0, 0, 1, 0, JAM1, 5, gadget_border_points[2], NULL}
|
|
||||||
};
|
|
||||||
|
|
||||||
static UBYTE buffer[81], undobuffer[81];
|
static UBYTE buffer1[82], undobuffer1[82];
|
||||||
static struct StringInfo strinfo = {buffer, undobuffer, 0, 80, 0, 0, 0, 0, 0, 0, NULL, 0, NULL};
|
static struct StringInfo strinfo1 = {buffer1, undobuffer1, 0, 80, 0, 0, 0, 0, 0, 0, NULL, 0, NULL};
|
||||||
|
static UBYTE buffer2[82], undobuffer2[82];
|
||||||
|
static struct StringInfo strinfo2 = {buffer2, undobuffer2, 0, 80, 0, 0, 0, 0, 0, 0, NULL, 0, NULL};
|
||||||
|
|
||||||
#define REQWIN_WIDTH 260
|
#define REQWIN_WIDTH 260
|
||||||
#define REQWIN_HEIGHT 180
|
#define REQWIN_HEIGHT 180
|
||||||
@ -58,8 +63,8 @@ static struct StringInfo strinfo = {buffer, undobuffer, 0, 80, 0, 0, 0, 0, 0, 0,
|
|||||||
|
|
||||||
static struct NewWindow newwin = {
|
static struct NewWindow newwin = {
|
||||||
0, 0, REQWIN_WIDTH, REQWIN_HEIGHT, 0, 1,
|
0, 0, REQWIN_WIDTH, REQWIN_HEIGHT, 0, 1,
|
||||||
IDCMP_CLOSEWINDOW | IDCMP_GADGETUP,
|
IDCMP_GADGETUP,
|
||||||
WFLG_CLOSEGADGET | WFLG_SMART_REFRESH | WFLG_ACTIVATE | WFLG_DRAGBAR | WFLG_DEPTHGADGET,
|
WFLG_CLOSEGADGET | WFLG_SMART_REFRESH | WFLG_ACTIVATE | WFLG_DRAGBAR | WFLG_DEPTHGADGET | WFLG_NOCAREREFRESH,
|
||||||
NULL, NULL, WIN_TITLE,
|
NULL, NULL, WIN_TITLE,
|
||||||
NULL, NULL,
|
NULL, NULL,
|
||||||
REQWIN_WIDTH, REQWIN_HEIGHT,
|
REQWIN_WIDTH, REQWIN_HEIGHT,
|
||||||
@ -73,14 +78,17 @@ static struct NewWindow newwin = {
|
|||||||
*/
|
*/
|
||||||
static struct Gadget gadgets[] = {
|
static struct Gadget gadgets[] = {
|
||||||
{&gadgets[1], OK_BUTTON_X, BUTTON_Y, OK_BUTTON_WIDTH, BUTTON_HEIGHT, GFLG_GADGHCOMP,
|
{&gadgets[1], OK_BUTTON_X, BUTTON_Y, OK_BUTTON_WIDTH, BUTTON_HEIGHT, GFLG_GADGHCOMP,
|
||||||
GACT_RELVERIFY, GTYP_BOOLGADGET | GTYP_REQGADGET, &gadget_borders[0], NULL,
|
GACT_RELVERIFY, GTYP_BOOLGADGET | GTYP_REQGADGET, &ok_button_border, NULL,
|
||||||
&labels[1], 0, NULL, REQ_OK_BUTTON_ID, NULL},
|
&ok_button_label, 0, NULL, REQ_OK_BUTTON_ID, NULL},
|
||||||
{&gadgets[2], CANCEL_BUTTON_X, BUTTON_Y, CANCEL_BUTTON_WIDTH, BUTTON_HEIGHT, GFLG_GADGHCOMP,
|
{&gadgets[2], CANCEL_BUTTON_X, BUTTON_Y, CANCEL_BUTTON_WIDTH, BUTTON_HEIGHT, GFLG_GADGHCOMP,
|
||||||
GACT_RELVERIFY, GTYP_BOOLGADGET | GTYP_REQGADGET, &gadget_borders[1], NULL,
|
GACT_RELVERIFY, GTYP_BOOLGADGET | GTYP_REQGADGET, &cancel_button_border, NULL,
|
||||||
&labels[2], 0, NULL, REQ_CANCEL_BUTTON_ID, NULL},
|
&cancel_button_label, 0, NULL, REQ_CANCEL_BUTTON_ID, NULL},
|
||||||
{NULL, STR_GADGET_X, STR_GADGET_Y, PATH_GADGET_WIDTH, 10,
|
{&gadgets[3], DRAWER_GADGET_X, DRAWER_GADGET_Y, PATH_GADGET_WIDTH, 10,
|
||||||
GFLG_GADGHCOMP, GACT_RELVERIFY, GTYP_STRGADGET, &gadget_borders[2], NULL,
|
GFLG_GADGHCOMP, GACT_RELVERIFY, GTYP_STRGADGET, &str_gadget_border, NULL,
|
||||||
&labels[3], 0, &strinfo, 103, NULL},
|
&drawer_str_label, 0, &strinfo1, 103, NULL},
|
||||||
|
{NULL, FILE_GADGET_X, FILE_GADGET_Y, PATH_GADGET_WIDTH, 10,
|
||||||
|
GFLG_GADGHCOMP, GACT_RELVERIFY, GTYP_STRGADGET, &str_gadget_border, NULL,
|
||||||
|
&file_str_label, 0, &strinfo2, 104, NULL},
|
||||||
};
|
};
|
||||||
|
|
||||||
#define PATHBUFFER_SIZE 200
|
#define PATHBUFFER_SIZE 200
|
||||||
@ -100,9 +108,7 @@ static void print_fileinfo(struct FileInfoBlock *fileinfo)
|
|||||||
|
|
||||||
static void close_requester()
|
static void close_requester()
|
||||||
{
|
{
|
||||||
puts("close_requester()");
|
|
||||||
if (req_opened) {
|
if (req_opened) {
|
||||||
puts("EndRequest()");
|
|
||||||
EndRequest(&requester, req_window);
|
EndRequest(&requester, req_window);
|
||||||
req_opened = FALSE;
|
req_opened = FALSE;
|
||||||
}
|
}
|
||||||
@ -121,12 +127,9 @@ static void handle_events()
|
|||||||
if (msg = (struct IntuiMessage *) GetMsg(req_window->UserPort)) {
|
if (msg = (struct IntuiMessage *) GetMsg(req_window->UserPort)) {
|
||||||
msgClass = msg->Class;
|
msgClass = msg->Class;
|
||||||
switch (msgClass) {
|
switch (msgClass) {
|
||||||
case IDCMP_CLOSEWINDOW:
|
|
||||||
close_requester();
|
|
||||||
done = TRUE;
|
|
||||||
break;
|
|
||||||
case IDCMP_GADGETUP:
|
case IDCMP_GADGETUP:
|
||||||
buttonId = (int) ((struct Gadget *) (msg->IAddress))->GadgetID;
|
buttonId = (int) ((struct Gadget *) (msg->IAddress))->GadgetID;
|
||||||
|
ReplyMsg((struct Message *) msg);
|
||||||
if (buttonId == REQ_OK_BUTTON_ID) {
|
if (buttonId == REQ_OK_BUTTON_ID) {
|
||||||
close_requester();
|
close_requester();
|
||||||
done = TRUE;
|
done = TRUE;
|
||||||
@ -139,7 +142,6 @@ static void handle_events()
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ReplyMsg((struct Message *) msg);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -153,11 +155,11 @@ void open_file(struct Window *window)
|
|||||||
requester.TopEdge = 20;
|
requester.TopEdge = 20;
|
||||||
requester.Width = REQ_WIDTH;
|
requester.Width = REQ_WIDTH;
|
||||||
requester.Height = REQ_HEIGHT;
|
requester.Height = REQ_HEIGHT;
|
||||||
requester.Flags = 0;
|
requester.Flags = SIMPLEREQ;
|
||||||
requester.BackFill = 0;
|
requester.BackFill = 0;
|
||||||
requester.ReqGadget = &gadgets[0];
|
requester.ReqGadget = &gadgets[0];
|
||||||
requester.ReqBorder = NULL; // &req_border;
|
requester.ReqBorder = NULL;
|
||||||
requester.ReqText = &labels[0];
|
requester.ReqText = NULL;
|
||||||
|
|
||||||
/* scan current directory */
|
/* scan current directory */
|
||||||
/*
|
/*
|
||||||
@ -184,9 +186,7 @@ void open_file(struct Window *window)
|
|||||||
UnLock(flock);
|
UnLock(flock);
|
||||||
*/
|
*/
|
||||||
if (req_opened = Request(&requester, req_window)) {
|
if (req_opened = Request(&requester, req_window)) {
|
||||||
puts("handle requester events...");
|
|
||||||
handle_events();
|
handle_events();
|
||||||
puts("quit handling requester events");
|
|
||||||
CloseWindow(req_window);
|
CloseWindow(req_window);
|
||||||
req_window = NULL;
|
req_window = NULL;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -85,12 +85,7 @@ static void cleanup()
|
|||||||
|
|
||||||
static BOOL handle_menu(UWORD menuNum, UWORD itemNum, UWORD subItemNum)
|
static BOOL handle_menu(UWORD menuNum, UWORD itemNum, UWORD subItemNum)
|
||||||
{
|
{
|
||||||
printf("menu, menu num: %d, item num: %d, sub item num: %d\n",
|
if (menuNum == FILE_MENU_NUM && itemNum == QUIT_MENU_ITEM_NUM) return TRUE;
|
||||||
(int) menuNum, (int) itemNum, (int) subItemNum);
|
|
||||||
if (menuNum == FILE_MENU_NUM && itemNum == QUIT_MENU_ITEM_NUM) {
|
|
||||||
/* quit */
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
if (menuNum == FILE_MENU_NUM && itemNum == OPEN_MENU_ITEM_NUM) {
|
if (menuNum == FILE_MENU_NUM && itemNum == OPEN_MENU_ITEM_NUM) {
|
||||||
open_file(window);
|
open_file(window);
|
||||||
}
|
}
|
||||||
@ -106,22 +101,21 @@ static void handle_events()
|
|||||||
int buttonId;
|
int buttonId;
|
||||||
|
|
||||||
while (!done) {
|
while (!done) {
|
||||||
puts("main, wait...");
|
|
||||||
Wait(1 << window->UserPort->mp_SigBit);
|
Wait(1 << window->UserPort->mp_SigBit);
|
||||||
if (msg = (struct IntuiMessage *) GetMsg(window->UserPort)) {
|
if (msg = (struct IntuiMessage *) GetMsg(window->UserPort)) {
|
||||||
msgClass = msg->Class;
|
msgClass = msg->Class;
|
||||||
|
menuCode = msg->Code;
|
||||||
|
ReplyMsg((struct Message *) msg);
|
||||||
switch (msgClass) {
|
switch (msgClass) {
|
||||||
case IDCMP_CLOSEWINDOW:
|
case IDCMP_CLOSEWINDOW:
|
||||||
done = TRUE;
|
done = TRUE;
|
||||||
break;
|
break;
|
||||||
case IDCMP_MENUPICK:
|
case IDCMP_MENUPICK:
|
||||||
menuCode = msg->Code;
|
|
||||||
done = handle_menu(MENUNUM(menuCode), ITEMNUM(menuCode), SUBNUM(menuCode));
|
done = handle_menu(MENUNUM(menuCode), ITEMNUM(menuCode), SUBNUM(menuCode));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ReplyMsg((struct Message *) msg);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -172,7 +166,6 @@ int main(int argc, char **argv)
|
|||||||
setup_menu();
|
setup_menu();
|
||||||
handle_events();
|
handle_events();
|
||||||
}
|
}
|
||||||
puts("main cleanup");
|
|
||||||
cleanup();
|
cleanup();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user