void nds_clear_prompt() { u16 *vram = (u16 *)BG_BMP_RAM_SUB(4); if (prompt_img == NULL) { return; } clear_ppm(prompt_img, MAP_COLOUR(CLR_BLACK)); draw_ppm(prompt_img, vram, 4, prompt_y, 256); }
struct ppm *alloc_ppm(int width, int height) { struct ppm *img; img = (struct ppm *)malloc(sizeof(struct ppm)); img->width = width; img->height = height; img->bitmap = (unsigned char *)malloc(width * height); clear_ppm(img, 0); return img; }
void nds_draw_prompt(const char *prompt) { u16 *vram = (u16 *)BG_BMP_RAM_SUB(4); if (prompt_img == NULL) { prompt_img = alloc_ppm(252, system_font->height * 2); prompt_y = 192 - system_font->height * 2; } /* Draw the prompt */ clear_ppm(prompt_img, MAP_COLOUR(CLR_BLACK)); draw_string(system_font, (char *)prompt, prompt_img, 0, 0, -1, -1); draw_ppm(prompt_img, vram, 4, prompt_y, 256); }
void _nds_draw_scroller(nds_nhwindow_t *window, int clear) { u16 *vram = (u16 *)BG_BMP_RAM(2); int start_x, end_x, start_y, end_y; int maxidx; start_x = (256 / 2 - (window->region.dims.width / 2)); end_x = 256 / 2 + (window->region.dims.width / 2); if (window->buffer == NULL) { start_x -= tag_width; end_x += tag_width; } if (start_x < 0) { end_x -= start_x; start_x = 0; } if (window->region.dims.height > 192 - 32) { start_y = 16; end_y = 192 - 16; } else { start_y = 192 / 2 - window->region.dims.height / 2; end_y = 192 / 2 + window->region.dims.height / 2; } swiWaitForVBlank(); if (window->buffer == NULL) { nds_menu_t *menu = window->menu; int cur_y = 0; int i; if (clear) { nds_fill(vram, MAP_COLOUR(CLR_BLACK)); } if (! window->img) { window->img = alloc_ppm(end_x - start_x, system_font->height * TITLE_MAX_LINES); } for (i = window->topidx; (i < menu->count) && ((cur_y + menu->items[i].region.dims.height) <= (end_y - start_y)); i++) { if (clear || menu->items[i].refresh) { char tag[3] = " "; int linenum = 0; int fg, bg; fg = (menu->items[i].highlighted) ? CLR_BRIGHT_GREEN : -1; bg = (menu->focused_item == i) ? CLR_BLUE : -1; window->img->height = menu->items[i].region.dims.height; clear_ppm(window->img, MAP_COLOUR(bg)); if (menu->items[i].selected) { if (menu->items[i].count > 0) { sprintf(tag, "%d", menu->items[i].count); } else { strcpy(tag, "* "); } } for (linenum = 0; menu->items[i].title[linenum][0]; linenum++) { int yoffs = linenum * system_font->height; if (menu->items[i].id.a_int == 0) { draw_string(system_font, menu->items[i].title[linenum], window->img, 0, yoffs, fg, bg); } else { if (linenum == 0) { draw_string(system_font, tag, window->img, 0, yoffs, fg, bg); } draw_string(system_font, menu->items[i].title[linenum], window->img, tag_width, yoffs, fg, bg); } } /* * Yes, this is a complete frickin' hack. Not all items take the full * image height, but rather than write a new version of draw_ppm_bw that * allowed cropping, I just change the height of the image to match the * height of the item. This effectively crops the images to the height * of the item, while letting us use the same ppm struct during the * entire rendering process, which means fewer malloc/free pairs. */ draw_ppm(window->img, vram, start_x, start_y + cur_y, 256); menu->items[i].refresh = 0; } menu->items[i].region.start.x = start_x + tag_width; menu->items[i].region.start.y = start_y + cur_y; cur_y += menu->items[i].region.dims.height; } window->bottomidx = i - 1; maxidx = menu->count - 1; if (menu->how == PICK_ANY) { draw_ppm(okay_button, vram, 256 - okay_button->width * 2 - 8, 192 - okay_button->height, 256); } } else { nds_charbuf_t *charbuf = window->buffer; int cur_y = 0; int i; if (! window->img) { window->img = alloc_ppm(end_x - start_x, end_y - start_y); } clear_ppm(window->img, MAP_COLOUR(CLR_BLACK)); for (i = window->topidx; (i < charbuf->count) && (cur_y < (end_y - start_y)); i++) { draw_string(system_font, charbuf->lines[i].text, window->img, 0, cur_y, -1, -1); cur_y += charbuf->lines[i].height; } window->bottomidx = i - 1; maxidx = charbuf->count - 1; if (clear) { nds_fill(vram, 254); } draw_ppm(window->img, vram, start_x, start_y, 256); } if (window->topidx > 0) { draw_ppm(up_arrow, vram, 256 / 2 - up_arrow->width / 2, 0, 256); } if (window->bottomidx < maxidx) { draw_ppm(down_arrow, vram, 256 / 2 - down_arrow->width / 2, 192 - down_arrow->height, 256); } draw_ppm(cancel_button, vram, 256 - cancel_button->width, 192 - cancel_button->height, 256); }