void initMenu(int type) { // Read Logo or Menu from Array. if(!type) Source = pngToScreen(isWide ? (void*) openbor_logo_480x272_png.data : (void*) openbor_logo_320x240_png.data); else Source = pngToScreen(isWide ? (void*) openbor_menu_480x272_png.data : (void*) openbor_menu_320x240_png.data); // Depending on which mode we are in (WideScreen/FullScreen) // allocate proper size for final screen. Screen = allocscreen(Source->width, Source->height, PIXEL_32); // Allocate Scaler. Scaler = allocscreen(Screen->width, Screen->height, PIXEL_32); control_init(2); apply_controls(); }
/* * Attach, or possibly reattach, to window. * If reattaching, maintain value of screen pointer. */ int gengetwindow(Display *d, char *winname, Image **winp, Screen **scrp, int ref) { int n, fd; char buf[64+1]; Image *image; Rectangle r; fd = open(winname, OREAD); if(fd<0 || (n=read(fd, buf, sizeof buf-1))<=0){ if((image=d->image) == nil){ fprint(2, "gengetwindow: %r\n"); *winp = nil; d->screenimage = nil; return -1; } strcpy(buf, "noborder"); }else{ close(fd); buf[n] = '\0'; if(*winp != nil){ _freeimage1(*winp); freeimage((*scrp)->image); freescreen(*scrp); *scrp = nil; } image = namedimage(d, buf); if(image == 0){ fprint(2, "namedimage %s failed: %r\n", buf); *winp = nil; d->screenimage = nil; return -1; } assert(image->chan != 0); } d->screenimage = image; *scrp = allocscreen(image, d->white, 0); if(*scrp == nil){ freeimage(d->screenimage); *winp = nil; d->screenimage = nil; return -1; } r = image->r; if(strncmp(buf, "noborder", 8) != 0) r = insetrect(image->r, Borderwidth); *winp = _allocwindow(*winp, *scrp, r, ref, DWhite); if(*winp == nil){ freescreen(*scrp); *scrp = nil; freeimage(image); d->screenimage = nil; return -1; } d->screenimage = *winp; assert((*winp)->chan != 0); return 1; }
void resize(void) { Rectangle old, r; int dxo, dyo, dxn, dyn; Win *w; old = screen->r; dxo = Dx(old); dyo = Dy(old); if(getwindow(display, Refnone) < 0) sysfatal("resize failed: %r"); dxn = Dx(screen->r); dyn = Dy(screen->r); freescreen(scr); scr = allocscreen(screen, display->white, 0); if(scr == nil) sysfatal("allocscreen: %r"); for(w = wlist.next; w != &wlist; w = w->next){ r = rectsubpt(w->entire, old.min); r.min.x = muldiv(r.min.x, dxn, dxo); r.max.x = muldiv(r.max.x, dxn, dxo); r.min.y = muldiv(r.min.y, dyn, dyo); r.max.y = muldiv(r.max.y, dyn, dyo); w->entire = rectaddpt(r, screen->r.min); w->inner = insetrect(w->entire, BORDSIZ); freeimage(w->im); w->im = allocwindow(scr, w->entire, Refbackup, 0); if(w->im == nil) sysfatal("allocwindow: %r"); draw(w->im, w->inner, w->tab->cols[BACK], nil, ZP); border(w->im, w->entire, BORDSIZ, w->tab->cols[w == actw ? BORD : DISB], ZP); w->tab->draw(w); } }
void drawLogs() { int i=which_logfile, j, k, l, done=0; s_screen *Viewer = NULL; bothkeys = bothnewkeys = 0; Viewer = allocscreen(Source->width, Source->height, Source->pixelformat); clearscreen(Viewer); bothkeys = bothnewkeys = 0; while(!done) { copyScreens(Viewer); //inputrefresh(); refreshInput(); printText((isWide ? 410 : 250), 3, RED, 0, 0, "Quit : 1/B"); if(buttonsPressed & (WIIMOTE_1|CC_B|GC_B)) done = 1; if(logfile[i].ready) { printText(5, 3, RED, 0, 0, "OpenBorLog.txt"); if(buttonsHeld & DIR_UP) --logfile[i].line; if(buttonsHeld & DIR_DOWN) ++logfile[i].line; if(buttonsHeld & DIR_LEFT) logfile[i].line = 0; if(buttonsHeld & DIR_RIGHT) logfile[i].line = logfile[i].rows - (LOG_SCREEN_END - LOG_SCREEN_TOP); if(logfile[i].line > logfile[i].rows - (LOG_SCREEN_END - LOG_SCREEN_TOP) - 1) logfile[i].line = logfile[i].rows - (LOG_SCREEN_END - LOG_SCREEN_TOP) - 1; if(logfile[i].line < 0) logfile[i].line = 0; for(l=LOG_SCREEN_TOP, j=logfile[i].line; j<logfile[i].rows-1; l++, j++) { if(l<LOG_SCREEN_END) { char textpad[480] = {""}; for(k=0; k<480; k++) { if(!logfile[i].buf->ptr[logfile[i].pos[j]+k]) break; textpad[k] = logfile[i].buf->ptr[logfile[i].pos[j]+k]; } if(logfile[i].rows>0xFFFF) printText(5, l*10, WHITE, 0, 0, "0x%08x: %s", j, textpad); else printText(5, l*10, WHITE, 0, 0, "0x%04x: %s", j, textpad); } else break; } } else if(i == SCRIPT_LOG) printText(5, 3, RED, 0, 0, "Log NOT Found: ScriptLog.txt"); else printText(5, 3, RED, 0, 0, "Log NOT Found: OpenBorLog.txt"); drawScreens(NULL, 0, 0); } freescreen(&Viewer); Viewer = NULL; drawMenu(); }
void initwin(void) { Rectangle r; int i, j; scr = allocscreen(screen, display->white, 0); if(scr == nil) sysfatal("allocscreen: %r"); for(i = 0; i < NTYPES; i++) for(j = 0; j < NCOLS; j++) tabs[i]->cols[j] = allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, tabs[i]->hexcols[j]); invcol = allocimage(display, Rect(0, 0, 2, 2), screen->chan, 1, 0); draw(invcol, Rect(1, 0, 2, 1), display->white, nil, ZP); draw(invcol, Rect(0, 1, 1, 2), display->white, nil, ZP); wlist.next = wlist.prev = &wlist; flist.next = flist.prev = &flist; r = screen->r; r.max.y = r.min.y + Dy(r) / 5; cmdw = newwin(CMD, r, nil); if(cmdw == nil) sysfatal("newwin: %r"); }
s_screen *getPreview(char *filename) { int width = factor == 4 ? 640 : (factor == 2 ? 320 : 160); int height = factor == 4 ? 480 : (factor == 2 ? 240 : 120); s_screen *title = NULL; s_screen *scale = NULL; // Grab current path and filename getBasePath(packfile, filename, 1); // Create & Load & Scale Image return NULL; //if(!loadscreen("data/bgs/title.gif", packfile, realPal, PIXEL_8, &title)) return NULL; if((scale = allocscreen(width, height, title->pixelformat)) == NULL) return NULL; scalescreen(scale, title); // Free Images and Terminate FileCaching freescreen(&title); // ScreenShots within Menu will be saved as "Menu" strncpy(packfile,"Menu.ext",128); return scale; }
s_screen *pngToScreen(const void *data) { png_structp png_ptr; png_infop info_ptr; unsigned int sig_read = 0; png_uint_32 width, height; int bit_depth, color_type, interlace_type, y; u32 *line; s_screen *image; png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); if(png_ptr == NULL) { goto error; } png_set_error_fn(png_ptr, (png_voidp) NULL, (png_error_ptr) NULL, png_warning_fn); info_ptr = png_create_info_struct(png_ptr); if(info_ptr == NULL) { goto error2; } if(setjmp(png_jmpbuf(png_ptr))) { goto error2; } png_set_read_fn(png_ptr, &data, png_read_fn); png_set_sig_bytes(png_ptr, sig_read); png_read_info(png_ptr, info_ptr); png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, NULL, NULL); png_set_strip_16(png_ptr); png_set_packing(png_ptr); if(color_type == PNG_COLOR_TYPE_PALETTE) { png_set_palette_to_rgb(png_ptr); } if(color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) { png_set_expand_gray_1_2_4_to_8(png_ptr); } if(png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) { png_set_tRNS_to_alpha(png_ptr); } #if WII png_set_filler(png_ptr, 0xff, PNG_FILLER_BEFORE); #else png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER); #endif image = allocscreen(width, height, PIXEL_32); if(image == NULL) { goto error2; } line = (u32 *)image->data; for(y = 0; y < height; y++) { png_read_row(png_ptr, (u8 *) line, NULL); line += width; } png_read_end(png_ptr, info_ptr); png_destroy_read_struct(&png_ptr, &info_ptr, NULL); return image; error2: png_destroy_read_struct(&png_ptr, NULL, NULL); error: return NULL; }