From 766df0d2abf0915a3e8ed06d2726017992c335ad Mon Sep 17 00:00:00 2001 From: Wei-ju Wu Date: Fri, 15 Jan 2016 18:32:06 -0800 Subject: [PATCH] filereq and iffview update filereq - added offline buffer for file list iffview - free image memory --- 30years/iffview/iffview.c | 16 ++++++++-- requesters/filereq.c | 67 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 78 insertions(+), 5 deletions(-) diff --git a/30years/iffview/iffview.c b/30years/iffview/iffview.c index 1b0dea7..560b73a 100644 --- a/30years/iffview/iffview.c +++ b/30years/iffview/iffview.c @@ -174,7 +174,10 @@ int main(int argc, char **argv) } ILBMData *ilbm_data = NULL; ilbm_data = parse_file(argv[1]); - if (!ilbm_data) exit(0); + if (!ilbm_data) { + puts("error reading IFF file"); + exit(0); + } image.Width = ilbm_data->bmheader->w; image.Height = ilbm_data->bmheader->h; image.Depth = ilbm_data->bmheader->nPlanes; @@ -184,6 +187,12 @@ 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); + + if (!image.ImageData) { + puts("can't allocate chip memory for image"); + free_ilbm_data(ilbm_data); + exit(0); + } ilbm_to_image_data((char *) image.ImageData, ilbm_data, image.Width, image.Height); image.PlanePick = (1 << image.Depth) - 1; @@ -210,7 +219,8 @@ int main(int argc, char **argv) handle_events(); } } - if (ilbm_data) free_ilbm_data(ilbm_data); cleanup(); - return 1; + if (ilbm_data) free_ilbm_data(ilbm_data); + FreeMem(image.ImageData, finalsize); + return 0; } diff --git a/requesters/filereq.c b/requesters/filereq.c index 595f159..a5e6847 100644 --- a/requesters/filereq.c +++ b/requesters/filereq.c @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -39,9 +40,16 @@ #define STR_LABEL_XOFFSET -60 #define STR_LABEL_YOFFSET 2 +#define FILE_LIST_X 0 +#define FILE_LIST_Y 0 #define FILE_LIST_WIDTH 229 #define FILE_LIST_HEIGHT 86 +#define FILE_LIST_BM_X 1 +#define FILE_LIST_BM_Y 1 +#define FILE_LIST_BM_WIDTH (FILE_LIST_WIDTH - 2) +#define FILE_LIST_BM_HEIGHT (FILE_LIST_HEIGHT - 2) + #define LIST_VSLIDER_X FILE_LIST_WIDTH #define LIST_VSLIDER_Y 0 #define LIST_VSLIDER_WIDTH 11 @@ -108,7 +116,8 @@ static struct Border drives_button_border = {0, 0, 1, 0, JAM1, 5, cancel_border_ static struct Border parent_button_border = {0, 0, 1, 0, JAM1, 5, cancel_border_points, NULL}; static struct Border cancel_button_border = {0, 0, 1, 0, JAM1, 5, cancel_border_points, NULL}; static struct Border str_gadget_border = {0, 0, 1, 0, JAM1, 5, string_border_points, NULL}; -static struct Border file_list_border = {0, 0, 1, 0, JAM1, 5, list_border_points, NULL}; +static struct Border file_list_border = {FILE_LIST_X, FILE_LIST_Y, 1, 0, JAM1, 5, + list_border_points, NULL}; static UBYTE buffer1[82], undobuffer1[82]; static struct StringInfo strinfo1 = {buffer1, undobuffer1, 0, 80, 0, 0, 0, 0, 0, 0, NULL, 0, NULL}; @@ -193,11 +202,16 @@ static struct Gadget ok_button = {&drives_button, OK_BUTTON_X, BUTTON_Y, &ok_button_border, NULL, &ok_button_label, 0, NULL, REQ_OK_BUTTON_ID, NULL}; +static int filelist_bm_depth = 1; +static struct BitMap filelist_bitmap; +static struct RastPort filelist_rastport; + #define PATHBUFFER_SIZE 200 static char dirname[PATHBUFFER_SIZE + 1]; static BPTR flock; static LONG error; static struct FileInfoBlock fileinfo; +static struct TextFont *reqwin_font; static void print_fileinfo(struct FileInfoBlock *fileinfo) { @@ -248,6 +262,15 @@ static void handle_events() } } +static void cleanup() +{ + for (int i = 0; i < filelist_bm_depth; i++) { + if (filelist_bitmap.Planes[i]) FreeRaster(filelist_bitmap.Planes[i], + FILE_LIST_WIDTH, + FILE_LIST_HEIGHT); + } +} + void open_file(struct Window *window) { BOOL result; @@ -257,12 +280,30 @@ void open_file(struct Window *window) requester.TopEdge = REQ_Y; requester.Width = REQ_WIDTH; requester.Height = REQ_HEIGHT; - requester.Flags = SIMPLEREQ; + requester.Flags = SIMPLEREQ | NOREQBACKFILL; requester.BackFill = 0; requester.ReqGadget = &ok_button; requester.ReqBorder = &file_list_border; requester.ReqText = NULL; + reqwin_font = req_window->IFont; + printf("Font ysize: %d, baseline: %d\n", (int) reqwin_font->tf_YSize, + (int) reqwin_font->tf_Baseline); + + InitBitMap(&filelist_bitmap, filelist_bm_depth, FILE_LIST_BM_WIDTH, FILE_LIST_BM_HEIGHT); + for (int i = 0; i < filelist_bm_depth; i++) filelist_bitmap.Planes[i] = NULL; + for (int i = 0; i < filelist_bm_depth; i++) { + if (!(filelist_bitmap.Planes[i] = AllocRaster(FILE_LIST_WIDTH, FILE_LIST_HEIGHT))) { + cleanup(); + return; + } else { + BltClear(filelist_bitmap.Planes[i], + RASSIZE(FILE_LIST_WIDTH, FILE_LIST_HEIGHT), 1); + } + } + InitRastPort(&filelist_rastport); + filelist_rastport.BitMap = &filelist_bitmap; + /* scan current directory */ /* on AmigaOS versions before 36 (essentially all 1.x versions), the @@ -288,12 +329,34 @@ void open_file(struct Window *window) UnLock(flock); */ if (req_opened = Request(&requester, req_window)) { + // Note that we need to render into the requester + // layer's rastport, because it is rendered on top of the + // parent window and obscures the content + struct RastPort *src_rp = &filelist_rastport; + struct RastPort *dst_rp = requester.ReqLayer->rp; + + // make sure drawing is clipped, otherwise it will + // draw somewhere else into memory + SetAPen(src_rp, 1); + Move(src_rp, 8, 10); + Text(src_rp, "filename1.txt", 13); + Move(src_rp, 8, 20); + Text(src_rp, "filename2.txt", 13); + /* + BltBitMap(&filelist_bitmap, 0, 0, + req_window->RPort->BitMap, 10, 10, FILE_LIST_WIDTH, FILE_LIST_HEIGHT, + 0xc0, 0xff, 0); // Minterm, mask, TempA + */ + BltBitMapRastPort(&filelist_bitmap, 0, 0, dst_rp, + FILE_LIST_BM_X, FILE_LIST_BM_Y, FILE_LIST_BM_WIDTH, FILE_LIST_BM_HEIGHT, + 0xc0); handle_events(); CloseWindow(req_window); req_window = NULL; } else { puts("Request() failed !!!"); } + cleanup(); } else { puts("OpenWindow() failed !!!"); }