static void gfxset_draw_item(running_machine &machine, gfx_element *gfx, int index, bitmap_rgb32 &bitmap, int dstx, int dsty, int color, int rotate) { static const pen_t default_palette[] = { MAKE_RGB(0,0,0), MAKE_RGB(0,0,255), MAKE_RGB(0,255,0), MAKE_RGB(0,255,255), MAKE_RGB(255,0,0), MAKE_RGB(255,0,255), MAKE_RGB(255,255,0), MAKE_RGB(255,255,255) }; int width = (rotate & ORIENTATION_SWAP_XY) ? gfx->height() : gfx->width(); int height = (rotate & ORIENTATION_SWAP_XY) ? gfx->width() : gfx->height(); const rgb_t *palette = (machine.total_colors() != 0) ? palette_entry_list_raw(machine.palette) : NULL; UINT32 palette_mask = ~0; int x, y; if (palette != NULL) palette += gfx->colorbase() + color * gfx->granularity(); else { palette = default_palette; palette_mask = 7; } /* loop over rows in the cell */ for (y = 0; y < height; y++) { UINT32 *dest = &bitmap.pix32(dsty + y, dstx); const UINT8 *src = gfx->get_data(index); /* loop over columns in the cell */ for (x = 0; x < width; x++) { int effx = x, effy = y; const UINT8 *s; /* compute effective x,y values after rotation */ if (!(rotate & ORIENTATION_SWAP_XY)) { if (rotate & ORIENTATION_FLIP_X) effx = gfx->width() - 1 - effx; if (rotate & ORIENTATION_FLIP_Y) effy = gfx->height() - 1 - effy; } else { int temp; if (rotate & ORIENTATION_FLIP_X) effx = gfx->height() - 1 - effx; if (rotate & ORIENTATION_FLIP_Y) effy = gfx->width() - 1 - effy; temp = effx; effx = effy; effy = temp; } /* get a pointer to the start of this source row */ s = src + effy * gfx->rowbytes(); /* extract the pixel */ *dest++ = 0xff000000 | palette[s[effx] & palette_mask]; } } }
static void palette_handle_keys(running_machine &machine, ui_gfx_state *state) { int rowcount, screencount; int total; /* handle zoom (minus,plus) */ if (ui_input_pressed(machine, IPT_UI_ZOOM_OUT)) state->palette.count /= 2; if (ui_input_pressed(machine, IPT_UI_ZOOM_IN)) state->palette.count *= 2; /* clamp within range */ if (state->palette.count <= 4) state->palette.count = 4; if (state->palette.count > 64) state->palette.count = 64; /* handle colormap selection (open bracket,close bracket) */ if (ui_input_pressed(machine, IPT_UI_PREV_GROUP)) state->palette.which--; if (ui_input_pressed(machine, IPT_UI_NEXT_GROUP)) state->palette.which++; /* clamp within range */ if (state->palette.which < 0) state->palette.which = 0; if (state->palette.which > (int)(machine.colortable != NULL)) state->palette.which = (int)(machine.colortable != NULL); /* cache some info in locals */ total = state->palette.which ? colortable_palette_get_size(machine.colortable) : machine.total_colors(); /* determine number of entries per row and total */ rowcount = state->palette.count; screencount = rowcount * rowcount; /* handle keyboard navigation */ if (ui_input_pressed_repeat(machine, IPT_UI_UP, 4)) state->palette.offset -= rowcount; if (ui_input_pressed_repeat(machine, IPT_UI_DOWN, 4)) state->palette.offset += rowcount; if (ui_input_pressed_repeat(machine, IPT_UI_PAGE_UP, 6)) state->palette.offset -= screencount; if (ui_input_pressed_repeat(machine, IPT_UI_PAGE_DOWN, 6)) state->palette.offset += screencount; if (ui_input_pressed_repeat(machine, IPT_UI_HOME, 4)) state->palette.offset = 0; if (ui_input_pressed_repeat(machine, IPT_UI_END, 4)) state->palette.offset = total; /* clamp within range */ if (state->palette.offset + screencount > ((total + rowcount - 1) / rowcount) * rowcount) state->palette.offset = ((total + rowcount - 1) / rowcount) * rowcount - screencount; if (state->palette.offset < 0) state->palette.offset = 0; }
static void set_pens( running_machine &machine ) { cave_state *state = machine.driver_data<cave_state>(); int pen; for (pen = 0; pen < machine.total_colors(); pen++) { UINT16 data = state->m_paletteram[state->m_palette_map[pen]]; rgb_t color = MAKE_RGB(pal5bit(data >> 5), pal5bit(data >> 10), pal5bit(data >> 0)); palette_set_color(machine, pen, color); } }
int sdlvideo_init(running_machine &machine) { int index, tc; // extract data from the options extract_video_config(machine); // ensure we get called on the way out machine.add_notifier(MACHINE_NOTIFY_EXIT, machine_notify_delegate(FUNC(video_exit), &machine)); // set up monitors first init_monitors(); // we need the beam width in a float, contrary to what the core does. video_config.beamwidth = machine.options().beam(); // initialize the window system so we can make windows if (sdlwindow_init(machine)) return 1; tc = machine.total_colors(); // create the windows sdl_options &options = downcast<sdl_options &>(machine.options()); for (index = 0; index < video_config.numscreens; index++) { sdl_window_config conf; memset(&conf, 0, sizeof(conf)); extract_window_config(machine, index, &conf); conf.totalColors = tc; if (sdlwindow_video_window_create(machine, index, pick_monitor(options, index), &conf)) return 1; } return 0; }
static void palette_handler(running_machine &machine, render_container *container, ui_gfx_state *state) { int total = state->palette.which ? colortable_palette_get_size(machine.colortable) : machine.total_colors(); const char *title = state->palette.which ? "COLORTABLE" : "PALETTE"; const rgb_t *raw_color = palette_entry_list_raw(machine.palette); render_font *ui_font = ui_get_font(machine); float cellwidth, cellheight; float chwidth, chheight; float titlewidth; float x0, y0; render_bounds cellboxbounds; render_bounds boxbounds; int x, y, skip; /* add a half character padding for the box */ chheight = ui_get_line_height(machine); chwidth = ui_font->char_width(chheight, machine.render().ui_aspect(), '0'); boxbounds.x0 = 0.0f + 0.5f * chwidth; boxbounds.x1 = 1.0f - 0.5f * chwidth; boxbounds.y0 = 0.0f + 0.5f * chheight; boxbounds.y1 = 1.0f - 0.5f * chheight; /* the character cell box bounds starts a half character in from the box */ cellboxbounds = boxbounds; cellboxbounds.x0 += 0.5f * chwidth; cellboxbounds.x1 -= 0.5f * chwidth; cellboxbounds.y0 += 0.5f * chheight; cellboxbounds.y1 -= 0.5f * chheight; /* add space on the left for 5 characters of text, plus a half character of padding */ cellboxbounds.x0 += 5.5f * chwidth; /* add space on the top for a title, a half line of padding, a header, and another half line */ cellboxbounds.y0 += 3.0f * chheight; /* figure out the title and expand the outer box to fit */ titlewidth = ui_font->string_width(chheight, machine.render().ui_aspect(), title); x0 = 0.0f; if (boxbounds.x1 - boxbounds.x0 < titlewidth + chwidth) x0 = boxbounds.x0 - (0.5f - 0.5f * (titlewidth + chwidth)); /* go ahead and draw the outer box now */ ui_draw_outlined_box(container, boxbounds.x0 - x0, boxbounds.y0, boxbounds.x1 + x0, boxbounds.y1, UI_GFXVIEWER_BG_COLOR); /* draw the title */ x0 = 0.5f - 0.5f * titlewidth; y0 = boxbounds.y0 + 0.5f * chheight; for (x = 0; title[x] != 0; x++) { container->add_char(x0, y0, chheight, machine.render().ui_aspect(), ARGB_WHITE, *ui_font, title[x]); x0 += ui_font->char_width(chheight, machine.render().ui_aspect(), title[x]); } /* compute the cell size */ cellwidth = (cellboxbounds.x1 - cellboxbounds.x0) / (float)state->palette.count; cellheight = (cellboxbounds.y1 - cellboxbounds.y0) / (float)state->palette.count; /* draw the top column headers */ skip = (int)(chwidth / cellwidth); for (x = 0; x < state->palette.count; x += 1 + skip) { x0 = boxbounds.x0 + 6.0f * chwidth + (float)x * cellwidth; y0 = boxbounds.y0 + 2.0f * chheight; container->add_char(x0 + 0.5f * (cellwidth - chwidth), y0, chheight, machine.render().ui_aspect(), ARGB_WHITE, *ui_font, "0123456789ABCDEF"[x & 0xf]); /* if we're skipping, draw a point between the character and the box to indicate which */ /* one it's referring to */ if (skip != 0) container->add_point(x0 + 0.5f * cellwidth, 0.5f * (y0 + chheight + cellboxbounds.y0), UI_LINE_WIDTH, ARGB_WHITE, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); } /* draw the side column headers */ skip = (int)(chheight / cellheight); for (y = 0; y < state->palette.count; y += 1 + skip) /* only display if there is data to show */ if (state->palette.offset + y * state->palette.count < total) { char buffer[10]; /* if we're skipping, draw a point between the character and the box to indicate which */ /* one it's referring to */ x0 = boxbounds.x0 + 5.5f * chwidth; y0 = boxbounds.y0 + 3.5f * chheight + (float)y * cellheight; if (skip != 0) container->add_point(0.5f * (x0 + cellboxbounds.x0), y0 + 0.5f * cellheight, UI_LINE_WIDTH, ARGB_WHITE, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); /* draw the row header */ sprintf(buffer, "%5X", state->palette.offset + y * state->palette.count); for (x = 4; x >= 0; x--) { x0 -= ui_font->char_width(chheight, machine.render().ui_aspect(), buffer[x]); container->add_char(x0, y0 + 0.5f * (cellheight - chheight), chheight, machine.render().ui_aspect(), ARGB_WHITE, *ui_font, buffer[x]); } } /* now add the rectangles for the colors */ for (y = 0; y < state->palette.count; y++) for (x = 0; x < state->palette.count; x++) { int index = state->palette.offset + y * state->palette.count + x; if (index < total) { pen_t pen = state->palette.which ? colortable_palette_get_color(machine.colortable, index) : raw_color[index]; container->add_rect(cellboxbounds.x0 + x * cellwidth, cellboxbounds.y0 + y * cellheight, cellboxbounds.x0 + (x + 1) * cellwidth, cellboxbounds.y0 + (y + 1) * cellheight, 0xff000000 | pen, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); } } /* handle keys */ palette_handle_keys(machine, state); }
UINT32 ui_gfx_ui_handler(running_machine &machine, render_container *container, UINT32 uistate) { ui_gfx_state *state = &ui_gfx; /* if we have nothing, implicitly cancel */ if (machine.total_colors() == 0 && machine.colortable == NULL && machine.gfx[0] == NULL && machine.tilemap().count() == 0) goto cancel; /* if we're not paused, mark the bitmap dirty */ if (!machine.paused()) state->bitmap_dirty = TRUE; /* switch off the state to display something */ again: switch (state->mode) { case 0: /* if we have a palette, display it */ if (machine.total_colors() > 0) { palette_handler(machine, container, state); break; } /* fall through...*/ state->mode++; case 1: /* if we have graphics sets, display them */ if (machine.gfx[0] != NULL) { gfxset_handler(machine, container, state); break; } /* fall through...*/ state->mode++; case 2: /* if we have tilemaps, display them */ if (machine.tilemap().count() > 0) { tilemap_handler(machine, container, state); break; } state->mode = 0; goto again; } /* handle keys */ if (ui_input_pressed(machine, IPT_UI_SELECT)) { state->mode = (state->mode + 1) % 3; state->bitmap_dirty = TRUE; } if (ui_input_pressed(machine, IPT_UI_PAUSE)) { if (machine.paused()) machine.resume(); else machine.pause(); } if (ui_input_pressed(machine, IPT_UI_CANCEL) || ui_input_pressed(machine, IPT_UI_SHOW_GFX)) goto cancel; return uistate; cancel: if (!uistate) machine.resume(); state->bitmap_dirty = TRUE; return UI_HANDLER_CANCEL; }