harset=UTF-8 Content-Disposition: inline; filename="f329db261fa13458d344115fe69ab5196f0ae6d8..3c039af763e9b30b1349db80e03ec8d86022646d.patch" Last-Modified: Sat, 03 May 2025 04:03:30 GMT Expires: Tue, 01 May 2035 04:03:30 GMT From 3c039af763e9b30b1349db80e03ec8d86022646d Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Fri, 25 Mar 2016 09:59:48 +0100 Subject: Made menu for plugins (nw) --- src/emu/ui/miscmenu.cpp | 97 +++++++++++++++++++++++++++++++++++++++++++++++++ src/emu/ui/miscmenu.h | 13 +++++++ src/emu/ui/selgame.cpp | 13 ++++++- src/emu/ui/selgame.h | 1 + 4 files changed, 123 insertions(+), 1 deletion(-) diff --git a/src/emu/ui/miscmenu.cpp b/src/emu/ui/miscmenu.cpp index d890f4f4d35..97ab1cfa323 100644 --- a/src/emu/ui/miscmenu.cpp +++ b/src/emu/ui/miscmenu.cpp @@ -890,3 +890,100 @@ void ui_menu_machine_configure::custom_render(void *selectedref, float top, floa mui.draw_text_full(container, m_drv->description, x1, y1, x2 - x1, JUSTIFY_CENTER, WRAP_TRUNCATE, DRAW_NORMAL, UI_TEXT_COLOR, UI_TEXT_BG_COLOR, nullptr, nullptr); } + +//------------------------------------------------- +// ctor / dtor +//------------------------------------------------- + +ui_menu_plugins_configure::ui_menu_plugins_configure(running_machine &machine, render_container *container) + : ui_menu(machine, container) +{ +} + +ui_menu_plugins_configure::~ui_menu_plugins_configure() +{ + emu_file file_plugin(OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS); + if (file_plugin.open("plugin.ini") != osd_file::error::NONE) + throw emu_fatalerror("Unable to create file plugin.ini\n"); + // generate the updated INI + file_plugin.puts(machine().manager().plugins().output_ini().c_str()); +} + +//------------------------------------------------- +// handlethe options menu +//------------------------------------------------- + +void ui_menu_plugins_configure::handle() +{ + // process the menu + bool changed = false; + plugin_options& plugins = machine().manager().plugins(); + ui_menu::menu_stack->parent->process(UI_MENU_PROCESS_NOINPUT); + const ui_menu_event *m_event = process(UI_MENU_PROCESS_NOIMAGE); + if (m_event != nullptr && m_event->itemref != nullptr) + { + if (m_event->iptkey == IPT_UI_LEFT || m_event->iptkey == IPT_UI_RIGHT || m_event->iptkey == IPT_UI_SELECT) + { + int oldval = plugins.int_value((const char*)m_event->itemref); + std::string error_string; + plugins.set_value((const char*)m_event->itemref, oldval == 1 ? 0 : 1, OPTION_PRIORITY_CMDLINE, error_string); + changed = true; + } + } + if (changed) + reset(UI_MENU_RESET_REMEMBER_REF); +} + +//------------------------------------------------- +// populate +//------------------------------------------------- + +void ui_menu_plugins_configure::populate() +{ + plugin_options& plugins = machine().manager().plugins(); + + for (auto curentry = plugins.first(); curentry != nullptr; curentry = curentry->next()) + { + if (!curentry->is_header()) + { + auto enabled = std::string(curentry->value()) == "1"; + item_append(curentry->description(), enabled ? _("On") : _("Off"), + enabled ? MENU_FLAG_RIGHT_ARROW : MENU_FLAG_LEFT_ARROW, (void *)(FPTR)curentry->name()); + } + } + item_append(MENU_SEPARATOR_ITEM, nullptr, 0, nullptr); + customtop = machine().ui().get_line_height() + (3.0f * UI_BOX_TB_BORDER); +} + +//------------------------------------------------- +// perform our special rendering +//------------------------------------------------- + +void ui_menu_plugins_configure::custom_render(void *selectedref, float top, float bottom, float origx1, float origy1, float origx2, float origy2) +{ + float width; + ui_manager &mui = machine().ui(); + + mui.draw_text_full(container, _("Plugins"), 0.0f, 0.0f, 1.0f, JUSTIFY_CENTER, WRAP_TRUNCATE, + DRAW_NONE, ARGB_WHITE, ARGB_BLACK, &width, nullptr); + width += 2 * UI_BOX_LR_BORDER; + float maxwidth = MAX(origx2 - origx1, width); + + // compute our bounds + float x1 = 0.5f - 0.5f * maxwidth; + float x2 = x1 + maxwidth; + float y1 = origy1 - top; + float y2 = origy1 - UI_BOX_TB_BORDER; + + // draw a box + mui.draw_outlined_box(container, x1, y1, x2, y2, UI_GREEN_COLOR); + + // take off the borders + x1 += UI_BOX_LR_BORDER; + x2 -= UI_BOX_LR_BORDER; + y1 += UI_BOX_TB_BORDER; + + // draw the text within it + mui.draw_text_full(container, _("Plugins"), x1, y1, x2 - x1, JUSTIFY_CENTER, WRAP_TRUNCATE, + DRAW_NORMAL, UI_TEXT_COLOR, UI_TEXT_BG_COLOR, nullptr, nullptr); +} diff --git a/src/emu/ui/miscmenu.h b/src/emu/ui/miscmenu.h index f27c42ac82a..00a7ccf4edc 100644 --- a/src/emu/ui/miscmenu.h +++ b/src/emu/ui/miscmenu.h @@ -141,5 +141,18 @@ private: const game_driver *m_drv; }; +//------------------------------------------------- +// plugins configure menu +//------------------------------------------------- + +class ui_menu_plugins_configure : public ui_menu +{ +public: + ui_menu_plugins_configure(running_machine &machine, render_container *container); + virtual ~ui_menu_plugins_configure(); + virtual void populate() override; + virtual void handle() override; + virtual void custom_render(void *selectedref, float top, float bottom, float x, float y, float x2, float y2) override; +}; #endif /* __UI_MISCMENU_H__ */ diff --git a/src/emu/ui/selgame.cpp b/src/emu/ui/selgame.cpp index a823635c286..d7b6c5ad961 100644 --- a/src/emu/ui/selgame.cpp +++ b/src/emu/ui/selgame.cpp @@ -583,7 +583,8 @@ void ui_menu_select_game::populate() UINT32 flags_ui = MENU_FLAG_UI | MENU_FLAG_LEFT_ARROW | MENU_FLAG_RIGHT_ARROW; item_append(_("Configure Options"), nullptr, flags_ui, (void *)(FPTR)CONF_OPTS); item_append(_("Configure Machine"), nullptr, flags_ui, (void *)(FPTR)CONF_MACHINE); - skip_main_items = 2; + item_append(_("Plugins"), nullptr, flags_ui, (void *)(FPTR)CONF_PLUGINS); + skip_main_items = 3; } else skip_main_items = 0; @@ -1011,6 +1012,11 @@ void ui_menu_select_game::inkey_select(const ui_menu_event *m_event) else return; } + // special case for configure plugins + else if ((FPTR)driver == CONF_PLUGINS) + { + ui_menu::stack_push(global_alloc_clear(machine(), container)); + } // anything else is a driver else { @@ -1080,6 +1086,11 @@ void ui_menu_select_game::inkey_select_favorite(const ui_menu_event *m_event) else return; } + // special case for configure plugins + else if ((FPTR)ui_swinfo == CONF_PLUGINS) + { + ui_menu::stack_push(global_alloc_clear(machine(), container)); + } else if (ui_swinfo->startempty == 1) { // audit the game first to see if we're going to work diff --git a/src/emu/ui/selgame.h b/src/emu/ui/selgame.h index 474aa57ed8a..dd302ebf8bc 100644 --- a/src/emu/ui/selgame.h +++ b/src/emu/ui/selgame.h @@ -41,6 +41,7 @@ private: { CONF_OPTS = 1, CONF_MACHINE, + CONF_PLUGINS, }; enum { VISIBLE_GAMES_IN_SEARCH = 200 }; -- cgit v1.2.3-70-g09d2 f='#n50'>50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
/* zpipe.c: example of proper use of zlib's inflate() and deflate()
   Not copyrighted -- provided to the public domain
   Version 1.4  11 December 2005  Mark Adler */

/* Version history:
   1.0  30 Oct 2004  First version
   1.1   8 Nov 2004  Add void casting for unused return values
                     Use switch statement for inflate() return values
   1.2   9 Nov 2004  Add assertions to document zlib guarantees
   1.3   6 Apr 2005  Remove incorrect assertion in inf()
   1.4  11 Dec 2005  Add hack to avoid MSDOS end-of-line conversions
                     Avoid some compiler warnings for input and output buffers
 */

#include <stdio.h>
#include <string.h>
#include <assert.h>
#include "zlib.h"

#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
#  include <fcntl.h>
#  include <io.h>
#  define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY)
#else
#  define SET_BINARY_MODE(file)
#endif

#define CHUNK 16384

/* Compress from file source to file dest until EOF on source.
   def() returns Z_OK on success, Z_MEM_ERROR if memory could not be
   allocated for processing, Z_STREAM_ERROR if an invalid compression
   level is supplied, Z_VERSION_ERROR if the version of zlib.h and the
   version of the library linked do not match, or Z_ERRNO if there is
   an error reading or writing the files. */
int def(FILE *source, FILE *dest, int level)
{
    int ret, flush;
    unsigned have;
    z_stream strm;
    unsigned char in[CHUNK];
    unsigned char out[CHUNK];

    /* allocate deflate state */
    strm.zalloc = Z_NULL;
    strm.zfree = Z_NULL;
    strm.opaque = Z_NULL;
    ret = deflateInit(&strm, level);
    if (ret != Z_OK)
        return ret;

    /* compress until end of file */
    do {
        strm.avail_in = fread(in, 1, CHUNK, source);
        if (ferror(source)) {
            (void)deflateEnd(&strm);
            return Z_ERRNO;
        }
        flush = feof(source) ? Z_FINISH : Z_NO_FLUSH;
        strm.next_in = in;

        /* run deflate() on input until output buffer not full, finish
           compression if all of source has been read in */
        do {
            strm.avail_out = CHUNK;
            strm.next_out = out;
            ret = deflate(&strm, flush);    /* no bad return value */
            assert(ret != Z_STREAM_ERROR);  /* state not clobbered */
            have = CHUNK - strm.avail_out;
            if (fwrite(out, 1, have, dest) != have || ferror(dest)) {
                (void)deflateEnd(&strm);
                return Z_ERRNO;
            }
        } while (strm.avail_out == 0);
        assert(strm.avail_in == 0);     /* all input will be used */

        /* done when last data in file processed */
    } while (flush != Z_FINISH);
    assert(ret == Z_STREAM_END);        /* stream will be complete */

    /* clean up and return */
    (void)deflateEnd(&strm);
    return Z_OK;
}

/* Decompress from file source to file dest until stream ends or EOF.
   inf() returns Z_OK on success, Z_MEM_ERROR if memory could not be
   allocated for processing, Z_DATA_ERROR if the deflate data is
   invalid or incomplete, Z_VERSION_ERROR if the version of zlib.h and
   the version of the library linked do not match, or Z_ERRNO if there
   is an error reading or writing the files. */
int inf(FILE *source, FILE *dest)
{
    int ret;
    unsigned have;
    z_stream strm;
    unsigned char in[CHUNK];
    unsigned char out[CHUNK];

    /* allocate inflate state */
    strm.zalloc = Z_NULL;
    strm.zfree = Z_NULL;
    strm.opaque = Z_NULL;
    strm.avail_in = 0;
    strm.next_in = Z_NULL;
    ret = inflateInit(&strm);
    if (ret != Z_OK)
        return ret;

    /* decompress until deflate stream ends or end of file */
    do {
        strm.avail_in = fread(in, 1, CHUNK, source);
        if (ferror(source)) {
            (void)inflateEnd(&strm);
            return Z_ERRNO;
        }
        if (strm.avail_in == 0)
            break;
        strm.next_in = in;

        /* run inflate() on input until output buffer not full */
        do {
            strm.avail_out = CHUNK;
            strm.next_out = out;
            ret = inflate(&strm, Z_NO_FLUSH);
            assert(ret != Z_STREAM_ERROR);  /* state not clobbered */
            switch (ret) {
            case Z_NEED_DICT:
                ret = Z_DATA_ERROR;     /* and fall through */
            case Z_DATA_ERROR:
            case Z_MEM_ERROR:
                (void)inflateEnd(&strm);
                return ret;
            }
            have = CHUNK - strm.avail_out;
            if (fwrite(out, 1, have, dest) != have || ferror(dest)) {
                (void)inflateEnd(&strm);
                return Z_ERRNO;
            }
        } while (strm.avail_out == 0);

        /* done when inflate() says it's done */
    } while (ret != Z_STREAM_END);

    /* clean up and return */
    (void)inflateEnd(&strm);
    return ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR;
}

/* report a zlib or i/o error */
void zerr(int ret)
{
    fputs("zpipe: ", stderr);
    switch (ret) {
    case Z_ERRNO:
        if (ferror(stdin))
            fputs("error reading stdin\n", stderr);
        if (ferror(stdout))
            fputs("error writing stdout\n", stderr);
        break;
    case Z_STREAM_ERROR:
        fputs("invalid compression level\n", stderr);
        break;
    case Z_DATA_ERROR:
        fputs("invalid or incomplete deflate data\n", stderr);
        break;
    case Z_MEM_ERROR:
        fputs("out of memory\n", stderr);
        break;
    case Z_VERSION_ERROR:
        fputs("zlib version mismatch!\n", stderr);
    }
}

/* compress or decompress from stdin to stdout */
int main(int argc, char **argv)
{
    int ret;

    /* avoid end-of-line conversions */
    SET_BINARY_MODE(stdin);
    SET_BINARY_MODE(stdout);

    /* do compression if no arguments */
    if (argc == 1) {
        ret = def(stdin, stdout, Z_DEFAULT_COMPRESSION);
        if (ret != Z_OK)
            zerr(ret);
        return ret;
    }

    /* do decompression if -d specified */
    else if (argc == 2 && strcmp(argv[1], "-d") == 0) {
        ret = inf(stdin, stdout);
        if (ret != Z_OK)
            zerr(ret);
        return ret;
    }

    /* otherwise, report usage */
    else {
        fputs("zpipe usage: zpipe [-d] < source > dest\n", stderr);
        return 1;
    }
}