diff options
Diffstat (limited to 'src/emu/crsshair.cpp')
-rw-r--r-- | src/emu/crsshair.cpp | 46 |
1 files changed, 32 insertions, 14 deletions
diff --git a/src/emu/crsshair.cpp b/src/emu/crsshair.cpp index 6145e668a23..027d8828e32 100644 --- a/src/emu/crsshair.cpp +++ b/src/emu/crsshair.cpp @@ -9,11 +9,15 @@ ***************************************************************************/ #include "emu.h" +#include "crsshair.h" + +#include "config.h" #include "emuopts.h" +#include "render.h" #include "rendutil.h" -#include "config.h" +#include "screen.h" + #include "xmlfile.h" -#include "crsshair.h" @@ -168,32 +172,45 @@ void render_crosshair::set_default_bitmap() void render_crosshair::create_bitmap() { - int x, y; rgb_t color = m_player < ARRAY_LENGTH(crosshair_colors) ? crosshair_colors[m_player] : rgb_t::white(); // if we have a bitmap and texture for this player, kill it - if (m_bitmap == nullptr) + if (!m_bitmap) { m_bitmap = std::make_unique<bitmap_argb32>(); m_texture = m_machine.render().texture_alloc(render_texture::hq_scale); } + else + { + m_bitmap->reset(); + } emu_file crossfile(m_machine.options().crosshair_path(), OPEN_FLAG_READ); if (!m_name.empty()) { // look for user specified file - std::string filename = m_name + ".png"; - render_load_png(*m_bitmap, crossfile, nullptr, filename.c_str()); + if (crossfile.open(m_name + ".png") == osd_file::error::NONE) + { + render_load_png(*m_bitmap, crossfile); + crossfile.close(); + } } else { // look for default cross?.png in crsshair/game dir - std::string filename = string_format("cross%d.png", m_player + 1); - render_load_png(*m_bitmap, crossfile, m_machine.system().name, filename.c_str()); + std::string const filename = string_format("cross%d.png", m_player + 1); + if (crossfile.open(m_machine.system().name + (PATH_SEPARATOR + filename)) == osd_file::error::NONE) + { + render_load_png(*m_bitmap, crossfile); + crossfile.close(); + } // look for default cross?.png in crsshair dir - if (!m_bitmap->valid()) - render_load_png(*m_bitmap, crossfile, nullptr, filename.c_str()); + if (!m_bitmap->valid() && (crossfile.open(filename) == osd_file::error::NONE)) + { + render_load_png(*m_bitmap, crossfile); + crossfile.close(); + } } /* if that didn't work, use the built-in one */ @@ -204,14 +221,14 @@ void render_crosshair::create_bitmap() m_bitmap->fill(rgb_t(0x00,0xff,0xff,0xff)); /* extract the raw source data to it */ - for (y = 0; y < CROSSHAIR_RAW_SIZE / 2; y++) + for (int y = 0; y < CROSSHAIR_RAW_SIZE / 2; y++) { /* assume it is mirrored vertically */ - u32 *dest0 = &m_bitmap->pix32(y); - u32 *dest1 = &m_bitmap->pix32(CROSSHAIR_RAW_SIZE - 1 - y); + u32 *const dest0 = &m_bitmap->pix(y); + u32 *const dest1 = &m_bitmap->pix(CROSSHAIR_RAW_SIZE - 1 - y); /* extract to two rows simultaneously */ - for (x = 0; x < CROSSHAIR_RAW_SIZE; x++) + for (int x = 0; x < CROSSHAIR_RAW_SIZE; x++) if ((crosshair_raw_top[y * CROSSHAIR_RAW_ROWBYTES + x / 8] << (x % 8)) & 0x80) dest0[x] = dest1[x] = rgb_t(0xff,0x00,0x00,0x00) | color; } @@ -328,6 +345,7 @@ void render_crosshair::draw(render_container &container, u8 fade) crosshair_manager::crosshair_manager(running_machine &machine) : m_machine(machine) , m_usage(false) + , m_fade(0) , m_animation_counter(0) , m_auto_time(CROSSHAIR_VISIBILITY_AUTOTIME_DEFAULT) { |