mirror of
https://github.com/holub/mame
synced 2025-06-16 17:29:27 +03:00
ui: reducing the code for managing icons. (nw)
This commit is contained in:
parent
17eccd74d7
commit
fff33e90f8
@ -261,7 +261,6 @@ void ui_menu_dats_view::get_data_sw()
|
|||||||
std::vector<int> xstart;
|
std::vector<int> xstart;
|
||||||
std::vector<int> xend;
|
std::vector<int> xend;
|
||||||
std::string buffer;
|
std::string buffer;
|
||||||
std::vector<std::string> m_item;
|
|
||||||
if (m_items_list[m_actual].option == 0)
|
if (m_items_list[m_actual].option == 0)
|
||||||
buffer = m_swinfo->usage;
|
buffer = m_swinfo->usage;
|
||||||
else
|
else
|
||||||
|
@ -1321,7 +1321,7 @@ void ui_menu::init_ui(running_machine &machine)
|
|||||||
for (int i = 0; i < MAX_ICONS_RENDER; i++)
|
for (int i = 0; i < MAX_ICONS_RENDER; i++)
|
||||||
{
|
{
|
||||||
icons_bitmap[i] = auto_alloc(machine, bitmap_argb32);
|
icons_bitmap[i] = auto_alloc(machine, bitmap_argb32);
|
||||||
icons_texture[i] = mrender.texture_alloc();
|
icons_texture[i] = mrender.texture_alloc(render_texture::hq_scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
// create a texture for main menu background
|
// create a texture for main menu background
|
||||||
@ -2406,7 +2406,7 @@ void ui_menu::draw_common_arrow(float origx1, float origy1, float origx2, float
|
|||||||
void ui_menu::draw_icon(int linenum, void *selectedref, float x0, float y0)
|
void ui_menu::draw_icon(int linenum, void *selectedref, float x0, float y0)
|
||||||
{
|
{
|
||||||
static const game_driver *olddriver[MAX_ICONS_RENDER] = { nullptr };
|
static const game_driver *olddriver[MAX_ICONS_RENDER] = { nullptr };
|
||||||
float x1 = x0 + machine().ui().get_line_height() * container->manager().ui_aspect(container);
|
float x1 = x0 + machine().ui().get_line_height() * container->manager().ui_aspect();
|
||||||
float y1 = y0 + machine().ui().get_line_height();
|
float y1 = y0 + machine().ui().get_line_height();
|
||||||
const game_driver *driver = (const game_driver *)selectedref;
|
const game_driver *driver = (const game_driver *)selectedref;
|
||||||
|
|
||||||
@ -2432,72 +2432,23 @@ void ui_menu::draw_icon(int linenum, void *selectedref, float x0, float y0)
|
|||||||
while (path.next(curpath))
|
while (path.next(curpath))
|
||||||
searchstr.append(";").append(curpath.c_str()).append(PATH_SEPARATOR).append("icons");
|
searchstr.append(";").append(curpath.c_str()).append(PATH_SEPARATOR).append("icons");
|
||||||
|
|
||||||
bitmap_argb32 *tmp = auto_alloc(machine(), bitmap_argb32);
|
|
||||||
emu_file snapfile(searchstr.c_str(), OPEN_FLAG_READ);
|
emu_file snapfile(searchstr.c_str(), OPEN_FLAG_READ);
|
||||||
std::string fullname = std::string(driver->name).append(".ico");
|
std::string fullname = std::string(driver->name).append(".ico");
|
||||||
render_load_ico(*tmp, snapfile, nullptr, fullname.c_str());
|
render_load_ico(*icons_bitmap[linenum], snapfile, nullptr, fullname.c_str());
|
||||||
|
|
||||||
if (!tmp->valid() && cloneof)
|
if (!icons_bitmap[linenum]->valid() && cloneof)
|
||||||
{
|
{
|
||||||
fullname.assign(driver->parent).append(".ico");
|
fullname.assign(driver->parent).append(".ico");
|
||||||
render_load_ico(*tmp, snapfile, nullptr, fullname.c_str());
|
render_load_ico(*icons_bitmap[linenum], snapfile, nullptr, fullname.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tmp->valid())
|
if (icons_bitmap[linenum]->valid())
|
||||||
{
|
{
|
||||||
float panel_width = x1 - x0;
|
|
||||||
float panel_height = y1 - y0;
|
|
||||||
int screen_width = machine().render().ui_target().width();
|
|
||||||
int screen_height = machine().render().ui_target().height();
|
|
||||||
int panel_width_pixel = panel_width * screen_width;
|
|
||||||
int panel_height_pixel = panel_height * screen_height;
|
|
||||||
|
|
||||||
// Calculate resize ratios for resizing
|
|
||||||
float ratioW = (float)panel_width_pixel / tmp->width();
|
|
||||||
float ratioH = (float)panel_height_pixel / tmp->height();
|
|
||||||
int dest_xPixel = tmp->width();
|
|
||||||
int dest_yPixel = tmp->height();
|
|
||||||
|
|
||||||
if (ratioW < 1 || ratioH < 1)
|
|
||||||
{
|
|
||||||
// smaller ratio will ensure that the image fits in the view
|
|
||||||
float ratio = MIN(ratioW, ratioH);
|
|
||||||
dest_xPixel = tmp->width() * ratio;
|
|
||||||
dest_yPixel = tmp->height() * ratio;
|
|
||||||
}
|
|
||||||
|
|
||||||
bitmap_argb32 *dest_bitmap;
|
|
||||||
dest_bitmap = auto_alloc(machine(), bitmap_argb32);
|
|
||||||
|
|
||||||
// resample if necessary
|
|
||||||
if (dest_xPixel != tmp->width() || dest_yPixel != tmp->height())
|
|
||||||
{
|
|
||||||
dest_bitmap->allocate(dest_xPixel, dest_yPixel);
|
|
||||||
render_color color = { 1.0f, 1.0f, 1.0f, 1.0f };
|
|
||||||
render_resample_argb_bitmap_hq(*dest_bitmap, *tmp, color, true);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
dest_bitmap = tmp;
|
|
||||||
|
|
||||||
icons_bitmap[linenum]->reset();
|
|
||||||
icons_bitmap[linenum]->allocate(panel_width_pixel, panel_height_pixel);
|
|
||||||
|
|
||||||
for (int x = 0; x < dest_xPixel; x++)
|
|
||||||
for (int y = 0; y < dest_yPixel; y++)
|
|
||||||
icons_bitmap[linenum]->pix32(y, x) = dest_bitmap->pix32(y, x);
|
|
||||||
|
|
||||||
auto_free(machine(), dest_bitmap);
|
|
||||||
|
|
||||||
icons_texture[linenum]->set_bitmap(*icons_bitmap[linenum], icons_bitmap[linenum]->cliprect(), TEXFORMAT_ARGB32);
|
icons_texture[linenum]->set_bitmap(*icons_bitmap[linenum], icons_bitmap[linenum]->cliprect(), TEXFORMAT_ARGB32);
|
||||||
}
|
}
|
||||||
else {
|
else if (icons_bitmap[linenum] != nullptr)
|
||||||
if (icons_bitmap[linenum] != nullptr)
|
|
||||||
{
|
|
||||||
icons_bitmap[linenum]->reset();
|
icons_bitmap[linenum]->reset();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
auto_free(machine(), tmp);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (icons_bitmap[linenum] != nullptr && icons_bitmap[linenum]->valid())
|
if (icons_bitmap[linenum] != nullptr && icons_bitmap[linenum]->valid())
|
||||||
container->add_quad(x0, y0, x1, y1, ARGB_WHITE, icons_texture[linenum], PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_PACKABLE);
|
container->add_quad(x0, y0, x1, y1, ARGB_WHITE, icons_texture[linenum], PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_PACKABLE);
|
||||||
|
Loading…
Reference in New Issue
Block a user