static void palette_handler(mame_ui_manager &mui, render_container &container, ui_gfx_state &state) { device_palette_interface *palette = state.palette.interface; palette_device *paldev = dynamic_cast<palette_device *>(&palette->device()); int total = state.palette.which ? palette->indirect_entries() : palette->entries(); const rgb_t *raw_color = palette->palette()->entry_list_raw(); render_font *ui_font = mui.get_font(); 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 = mui.get_line_height(); chwidth = ui_font->char_width(chheight, mui.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; // compute the cell size float cellwidth = (cellboxbounds.x1 - cellboxbounds.x0) / (float)state.palette.columns; float cellheight = (cellboxbounds.y1 - cellboxbounds.y0) / (float)state.palette.columns; // figure out the title std::ostringstream title_buf; util::stream_format(title_buf, "'%s'", palette->device().tag()); if (palette->indirect_entries() > 0) title_buf << (state.palette.which ? _(" COLORS") : _(" PENS")); // if the mouse pointer is over one of our cells, add some info about the corresponding palette entry int32_t 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 index = state.palette.offset + int((mouse_x - cellboxbounds.x0) / cellwidth) + int((mouse_y - cellboxbounds.y0) / cellheight) * state.palette.columns; if (index < total) { util::stream_format(title_buf, " #%X", index); if (palette->indirect_entries() > 0 && !state.palette.which) util::stream_format(title_buf, " => %X", palette->pen_indirect(index)); else if (paldev != nullptr && paldev->basemem().base() != nullptr) util::stream_format(title_buf, " = %X", paldev->read_entry(index)); rgb_t col = state.palette.which ? palette->indirect_color(index) : raw_color[index]; util::stream_format(title_buf, " (R:%X G:%X B:%X)", col.r(), col.g(), col.b()); } } // 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) x0 = boxbounds.x0 - (0.5f - 0.5f * (titlewidth + chwidth)); // go ahead and draw the outer box now mui.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 (auto ch : title) { container.add_char(x0, y0, chheight, mui.machine().render().ui_aspect(), rgb_t::white(), *ui_font, ch); x0 += ui_font->char_width(chheight, mui.machine().render().ui_aspect(), ch); } // draw the top column headers skip = (int)(chwidth / cellwidth); for (x = 0; x < state.palette.columns; 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, mui.machine().render().ui_aspect(), rgb_t::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, rgb_t::white(), PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); } // draw the side column headers skip = (int)(chheight / cellheight); for (y = 0; y < state.palette.columns; y += 1 + skip) // only display if there is data to show if (state.palette.offset + y * state.palette.columns < 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, rgb_t::white(), PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); // draw the row header sprintf(buffer, "%5X", state.palette.offset + y * state.palette.columns); for (x = 4; x >= 0; x--) { x0 -= ui_font->char_width(chheight, mui.machine().render().ui_aspect(), buffer[x]); container.add_char(x0, y0 + 0.5f * (cellheight - chheight), chheight, mui.machine().render().ui_aspect(), rgb_t::white(), *ui_font, buffer[x]); } } // now add the rectangles for the colors for (y = 0; y < state.palette.columns; y++) for (x = 0; x < state.palette.columns; x++) { int index = state.palette.offset + y * state.palette.columns + x; if (index < total) { pen_t pen = state.palette.which ? palette->indirect_color(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(mui.machine(), state); }
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); }
static void palette_handler(running_machine &machine, render_container *container, ui_gfx_state &state) { palette_device *palette = state.palette.device; int total = state.palette.which ? palette->indirect_entries() : palette->entries(); const rgb_t *raw_color = palette->palette()->entry_list_raw(); render_font *ui_font = machine.ui().get_font(); float cellwidth, cellheight; float chwidth, chheight; float titlewidth; float x0, y0; render_bounds cellboxbounds; render_bounds boxbounds; int x, y, skip; char title[100]; // add a half character padding for the box chheight = machine.ui().get_line_height(); 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 const char *suffix = palette->indirect_entries() == 0 ? "" : state.palette.which ? " COLORS" : " PENS"; sprintf(title, "'%s'%s", palette->tag(), suffix); 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 machine.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.columns; cellheight = (cellboxbounds.y1 - cellboxbounds.y0) / (float)state.palette.columns; // draw the top column headers skip = (int)(chwidth / cellwidth); for (x = 0; x < state.palette.columns; 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.columns; y += 1 + skip) // only display if there is data to show if (state.palette.offset + y * state.palette.columns < 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.columns); 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.columns; y++) for (x = 0; x < state.palette.columns; x++) { int index = state.palette.offset + y * state.palette.columns + x; if (index < total) { pen_t pen = state.palette.which ? palette->indirect_color(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); }