diff options
author | 2016-09-02 18:04:38 -0400 | |
---|---|---|
committer | 2016-09-02 18:04:38 -0400 | |
commit | 0a8652e03f82e8bda55dcea445ce88b1c5038d1c (patch) | |
tree | 9ab289431cbee5b705eea93efa7ea01cb6cf78be /src/frontend/mame/ui/viewgfx.cpp | |
parent | c357acd3dfe1c2a508df2974d9dd135a7e5cb8e9 (diff) |
More new features for UI graphics viewer
- Mouse over GFX tiles to reveal pixel values
- Mouse over tilemap to reveal tile codes and colors
- UI tilemap scrolling controls are now orientation-relative
- Make mouse visible everywhere in UI graphics viewer by treating it like a menu
- Add all necessary getters to tilemap_t and a few more (nw)
- Add comment about role of decoder in tilemap creation (nw)
Diffstat (limited to 'src/frontend/mame/ui/viewgfx.cpp')
-rw-r--r-- | src/frontend/mame/ui/viewgfx.cpp | 148 |
1 files changed, 117 insertions, 31 deletions
diff --git a/src/frontend/mame/ui/viewgfx.cpp b/src/frontend/mame/ui/viewgfx.cpp index f299cacd3cf..8dc9bd331a8 100644 --- a/src/frontend/mame/ui/viewgfx.cpp +++ b/src/frontend/mame/ui/viewgfx.cpp @@ -387,8 +387,8 @@ static void palette_handler(mame_ui_manager &mui, render_container &container, u // if the mouse pointer is over one of our cells, add some info about the corresponding palette entry INT32 mouse_target_x, mouse_target_y; - bool mouse_button; float mouse_x, mouse_y; + bool mouse_button; render_target *mouse_target = mui.machine().ui_input().find_mouse(&mouse_target_x, &mouse_target_y, &mouse_button); if (mouse_target != nullptr && mouse_target->map_point_container(mouse_target_x, mouse_target_y, container, mouse_x, mouse_y) && cellboxbounds.x0 <= mouse_x && cellboxbounds.x1 > mouse_x @@ -661,12 +661,49 @@ static void gfxset_handler(mame_ui_manager &mui, render_container &container, ui boxbounds.y0 = (1.0f - fullheight) * 0.5f; boxbounds.y1 = boxbounds.y0 + fullheight; - // figure out the title and expand the outer box to fit - const std::string title = string_format("'%s' %d/%d %dx%d COLOR %X", - interface.device().tag(), - set, info.setcount - 1, - gfx.width(), gfx.height(), - info.color[set]); + // recompute cellboxbounds + cellboxbounds.x0 = boxbounds.x0 + 6.0f * chwidth; + cellboxbounds.x1 = cellboxbounds.x0 + (float)cellboxwidth / (float)targwidth; + cellboxbounds.y0 = boxbounds.y0 + 3.5f * chheight; + cellboxbounds.y1 = cellboxbounds.y0 + (float)cellboxheight / (float)targheight; + + // figure out the title + std::ostringstream title_buf; + util::stream_format(title_buf, "'%s' %d/%d", interface.device().tag(), set, info.setcount - 1); + + // if the mouse pointer is over a pixel in a tile, add some info about the tile and pixel + bool found_pixel = false; + INT32 mouse_target_x, mouse_target_y; + float mouse_x, mouse_y; + bool mouse_button; + render_target *mouse_target = mui.machine().ui_input().find_mouse(&mouse_target_x, &mouse_target_y, &mouse_button); + if (mouse_target != nullptr && mouse_target->map_point_container(mouse_target_x, mouse_target_y, container, mouse_x, mouse_y) + && cellboxbounds.x0 <= mouse_x && cellboxbounds.x1 > mouse_x + && cellboxbounds.y0 <= mouse_y && cellboxbounds.y1 > mouse_y) + { + int code = info.offset[set] + int((mouse_x - cellboxbounds.x0) / cellwidth) + int((mouse_y - cellboxbounds.y0) / cellheight) * xcells; + int xpixel = int((mouse_x - cellboxbounds.x0) / (cellwidth / cellxpix)) % cellxpix; + int ypixel = int((mouse_y - cellboxbounds.y0) / (cellheight / cellypix)) % cellypix; + if (code < gfx.elements() && xpixel < (cellxpix - 1) && ypixel < (cellypix - 1)) + { + found_pixel = true; + if (info.rotate[set] & ORIENTATION_FLIP_X) + xpixel = (cellxpix - 2) - xpixel; + if (info.rotate[set] & ORIENTATION_FLIP_Y) + ypixel = (cellypix - 2) - ypixel; + if (info.rotate[set] & ORIENTATION_SWAP_XY) + std::swap(xpixel, ypixel); + UINT8 pixdata = gfx.get_data(code)[xpixel + ypixel * gfx.rowbytes()]; + util::stream_format(title_buf, " #%X:%X @ %d,%d = %X", + code, info.color[set], xpixel, ypixel, + gfx.colorbase() + info.color[set] * gfx.granularity() + pixdata); + } + } + if (!found_pixel) + util::stream_format(title_buf, " %dx%d COLOR %X/%X", gfx.width(), gfx.height(), info.color[set], gfx.colors()); + + // expand the outer box to fit the title + const std::string title = title_buf.str(); titlewidth = ui_font->string_width(chheight, mui.machine().render().ui_aspect(), title.c_str()); x0 = 0.0f; if (boxbounds.x1 - boxbounds.x0 < titlewidth + chwidth) @@ -727,9 +764,7 @@ static void gfxset_handler(mame_ui_manager &mui, render_container &container, ui gfxset_update_bitmap(mui.machine(), state, xcells, ycells, gfx); // add the final quad - container.add_quad(boxbounds.x0 + 6.0f * chwidth, boxbounds.y0 + 3.5f * chheight, - boxbounds.x0 + 6.0f * chwidth + (float)cellboxwidth / (float)targwidth, - boxbounds.y0 + 3.5f * chheight + (float)cellboxheight / (float)targheight, + container.add_quad(cellboxbounds.x0, cellboxbounds.y0, cellboxbounds.x1, cellboxbounds.y1, rgb_t::white, state.texture, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); // handle keyboard navigation before drawing @@ -943,12 +978,11 @@ static void gfxset_draw_item(running_machine &machine, gfx_element &gfx, int ind } 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; + std::swap(effx, effy); } // get a pointer to the start of this source row @@ -982,15 +1016,13 @@ static void tilemap_handler(mame_ui_manager &mui, render_container &container, u float titlewidth; float x0, y0; int mapboxwidth, mapboxheight; - int maxxscale, maxyscale; - UINT32 mapwidth, mapheight; // get the size of the tilemap itself tilemap_t *tilemap = mui.machine().tilemap().find(state.tilemap.which); - mapwidth = tilemap->width(); - mapheight = tilemap->height(); + UINT32 mapwidth = tilemap->width(); + UINT32 mapheight = tilemap->height(); if (state.tilemap.rotate & ORIENTATION_SWAP_XY) - { UINT32 temp = mapwidth; mapwidth = mapheight; mapheight = temp; } + std::swap(mapwidth, mapheight); // add a half character padding for the box chheight = mui.get_line_height(); @@ -1018,6 +1050,7 @@ static void tilemap_handler(mame_ui_manager &mui, render_container &container, u int pixelscale = state.tilemap.zoom; if (pixelscale == 0) { + int maxxscale, maxyscale; for (maxxscale = 1; mapwidth * (maxxscale + 1) < mapboxwidth; maxxscale++) { } for (maxyscale = 1; mapheight * (maxyscale + 1) < mapboxheight; maxyscale++) { } pixelscale = std::min(maxxscale, maxyscale); @@ -1039,8 +1072,40 @@ static void tilemap_handler(mame_ui_manager &mui, render_container &container, u boxbounds.y0 = mapboxbounds.y0 - 2.0f * chheight; boxbounds.y1 = mapboxbounds.y1 + 0.5f * chheight; - // figure out the title and expand the outer box to fit - const std::string title = string_format("TILEMAP %d/%d %dx%d OFFS %d,%d", state.tilemap.which, mui.machine().tilemap().count() - 1, mapwidth, mapheight, state.tilemap.xoffs, state.tilemap.yoffs); + // figure out the title + std::ostringstream title_buf; + util::stream_format(title_buf, "TILEMAP %d/%d", state.tilemap.which, mui.machine().tilemap().count() - 1); + + // if the mouse pointer is over a tile, add some info about its coordinates and color + INT32 mouse_target_x, mouse_target_y; + float mouse_x, mouse_y; + bool mouse_button; + render_target *mouse_target = mui.machine().ui_input().find_mouse(&mouse_target_x, &mouse_target_y, &mouse_button); + if (mouse_target != nullptr && mouse_target->map_point_container(mouse_target_x, mouse_target_y, container, mouse_x, mouse_y) + && mapboxbounds.x0 <= mouse_x && mapboxbounds.x1 > mouse_x + && mapboxbounds.y0 <= mouse_y && mapboxbounds.y1 > mouse_y) + { + int xpixel = (mouse_x - mapboxbounds.x0) * targwidth; + int ypixel = (mouse_y - mapboxbounds.y0) * targheight; + if (state.tilemap.rotate & ORIENTATION_FLIP_X) + xpixel = (mapboxwidth - 1) - xpixel; + if (state.tilemap.rotate & ORIENTATION_FLIP_Y) + ypixel = (mapboxheight - 1) - ypixel; + if (state.tilemap.rotate & ORIENTATION_SWAP_XY) + std::swap(xpixel, ypixel); + int col = ((xpixel / pixelscale + state.tilemap.xoffs) / tilemap->tilewidth()) % tilemap->cols(); + int row = ((ypixel / pixelscale + state.tilemap.yoffs) / tilemap->tileheight()) % tilemap->rows(); + int gfxnum, code, color; + tilemap->get_info_debug(col, row, gfxnum, code, color); + util::stream_format(title_buf, " @ %d,%d = GFX%d #%X:%X", + col * tilemap->tilewidth(), row * tilemap->tileheight(), + gfxnum, code, color); + } + else + util::stream_format(title_buf, " %dx%d OFFS %d,%d", tilemap->width(), tilemap->height(), state.tilemap.xoffs, state.tilemap.yoffs); + + // expand the outer box to fit the title + const std::string title = title_buf.str(); titlewidth = ui_font->string_width(chheight, mui.machine().render().ui_aspect(), title.c_str()); if (boxbounds.x1 - boxbounds.x0 < titlewidth + chwidth) { @@ -1081,9 +1146,6 @@ static void tilemap_handler(mame_ui_manager &mui, render_container &container, u static void tilemap_handle_keys(running_machine &machine, ui_gfx_state &state, int viswidth, int visheight) { - UINT32 mapwidth, mapheight; - int step; - // handle tilemap selection (open bracket,close bracket) if (machine.ui_input().pressed(IPT_UI_PREV_GROUP) && state.tilemap.which > 0) { state.tilemap.which--; state.bitmap_dirty = true; } @@ -1092,8 +1154,8 @@ static void tilemap_handle_keys(running_machine &machine, ui_gfx_state &state, i // cache some info in locals tilemap_t *tilemap = machine.tilemap().find(state.tilemap.which); - mapwidth = tilemap->width(); - mapheight = tilemap->height(); + UINT32 mapwidth = tilemap->width(); + UINT32 mapheight = tilemap->height(); // handle zoom (minus,plus) if (machine.ui_input().pressed(IPT_UI_ZOOM_OUT) && state.tilemap.zoom > 0) @@ -1127,18 +1189,42 @@ static void tilemap_handle_keys(running_machine &machine, ui_gfx_state &state, i state.bitmap_dirty = true; } - // handle navigation (up,down,left,right) - step = 8; + // handle navigation (up,down,left,right), taking orientation into account + int step = 8; // this may be applied more than once if multiple directions are pressed if (machine.input().code_pressed(KEYCODE_LSHIFT)) step = 1; if (machine.input().code_pressed(KEYCODE_LCONTROL)) step = 64; if (machine.ui_input().pressed_repeat(IPT_UI_UP, 4)) - { state.tilemap.yoffs -= step; state.bitmap_dirty = true; } + { + if (state.tilemap.rotate & ORIENTATION_SWAP_XY) + state.tilemap.xoffs -= (state.tilemap.rotate & ORIENTATION_FLIP_Y) ? -step : step; + else + state.tilemap.yoffs -= (state.tilemap.rotate & ORIENTATION_FLIP_Y) ? -step : step; + state.bitmap_dirty = true; + } if (machine.ui_input().pressed_repeat(IPT_UI_DOWN, 4)) - { state.tilemap.yoffs += step; state.bitmap_dirty = true; } + { + if (state.tilemap.rotate & ORIENTATION_SWAP_XY) + state.tilemap.xoffs += (state.tilemap.rotate & ORIENTATION_FLIP_Y) ? -step : step; + else + state.tilemap.yoffs += (state.tilemap.rotate & ORIENTATION_FLIP_Y) ? -step : step; + state.bitmap_dirty = true; + } if (machine.ui_input().pressed_repeat(IPT_UI_LEFT, 6)) - { state.tilemap.xoffs -= step; state.bitmap_dirty = true; } + { + if (state.tilemap.rotate & ORIENTATION_SWAP_XY) + state.tilemap.yoffs -= (state.tilemap.rotate & ORIENTATION_FLIP_X) ? -step : step; + else + state.tilemap.xoffs -= (state.tilemap.rotate & ORIENTATION_FLIP_X) ? -step : step; + state.bitmap_dirty = true; + } if (machine.ui_input().pressed_repeat(IPT_UI_RIGHT, 6)) - { state.tilemap.xoffs += step; state.bitmap_dirty = true; } + { + if (state.tilemap.rotate & ORIENTATION_SWAP_XY) + state.tilemap.yoffs += (state.tilemap.rotate & ORIENTATION_FLIP_X) ? -step : step; + else + state.tilemap.xoffs += (state.tilemap.rotate & ORIENTATION_FLIP_X) ? -step : step; + state.bitmap_dirty = true; + } // clamp within range while (state.tilemap.xoffs < 0) @@ -1161,7 +1247,7 @@ static void tilemap_update_bitmap(running_machine &machine, ui_gfx_state &state, { // swap the coordinates back if they were talking about a rotated surface if (state.tilemap.rotate & ORIENTATION_SWAP_XY) - { UINT32 temp = width; width = height; height = temp; } + std::swap(width, height); // realloc the bitmap if it is too small if (state.bitmap == nullptr || state.texture == nullptr || state.bitmap->width() != width || state.bitmap->height() != height) |