trunk/src/emu/ui/barcode.c
| r242774 | r242775 | |
| 2 | 2 | |
| 3 | 3 | ui/barcode.c |
| 4 | 4 | |
| 5 | | MESS's "barcode reader" control |
| 5 | "Barcode Reader" control |
| 6 | 6 | |
| 7 | 7 | Copyright Nicola Salmoria and the MAME Team. |
| 8 | 8 | Visit http://mamedev.org for licensing and usage restrictions. |
| r242774 | r242775 | |
| 11 | 11 | |
| 12 | 12 | #include "emu.h" |
| 13 | 13 | #include "ui/ui.h" |
| 14 | | #include "ui/menu.h" |
| 15 | 14 | #include "ui/barcode.h" |
| 16 | 15 | |
| 17 | | |
| 18 | 16 | // itemrefs for key menu items |
| 19 | 17 | #define ITEMREF_NEW_BARCODE ((void *) 0x0001) |
| 20 | | #define ITEMREF_ENTER ((void *) 0x0002) |
| 18 | #define ITEMREF_ENTER_BARCODE ((void *) 0x0002) |
| 19 | #define ITEMREF_SELECT_READER ((void *) 0x0003) |
| 21 | 20 | |
| 22 | 21 | |
| 23 | 22 | /************************************************** |
| 24 | | |
| 25 | | BARCODE INPUT MENU |
| 26 | | |
| 23 | |
| 24 | BARCODE READER MENU |
| 25 | |
| 27 | 26 | **************************************************/ |
| 28 | 27 | |
| 29 | 28 | |
| r242774 | r242775 | |
| 31 | 30 | // ctor |
| 32 | 31 | //------------------------------------------------- |
| 33 | 32 | |
| 34 | | ui_menu_barcode_code::ui_menu_barcode_code(running_machine &machine, render_container *container, barcode_reader_device *reader) |
| 35 | | : ui_menu(machine, container) |
| 33 | ui_menu_barcode_reader::ui_menu_barcode_reader(running_machine &machine, render_container *container, barcode_reader_device *device) |
| 34 | : ui_menu_device_control<barcode_reader_device>(machine, container, device) |
| 36 | 35 | { |
| 37 | | m_reader = reader; |
| 38 | 36 | } |
| 39 | 37 | |
| 40 | 38 | |
| r242774 | r242775 | |
| 42 | 40 | // dtor |
| 43 | 41 | //------------------------------------------------- |
| 44 | 42 | |
| 45 | | ui_menu_barcode_code::~ui_menu_barcode_code() |
| 43 | ui_menu_barcode_reader::~ui_menu_barcode_reader() |
| 46 | 44 | { |
| 47 | 45 | } |
| 48 | 46 | |
| r242774 | r242775 | |
| 50 | 48 | // populate - populates the barcode input menu |
| 51 | 49 | //------------------------------------------------- |
| 52 | 50 | |
| 53 | | void ui_menu_barcode_code::populate() |
| 51 | void ui_menu_barcode_reader::populate() |
| 54 | 52 | { |
| 55 | | astring buffer; |
| 56 | | const char *new_barcode; |
| 53 | if (current_device()) |
| 54 | { |
| 55 | astring buffer; |
| 56 | const char *new_barcode; |
| 57 | 57 | |
| 58 | | // append the "New Barcode" item |
| 59 | | if (get_selection() == ITEMREF_NEW_BARCODE) |
| 60 | | { |
| 61 | | buffer.cat(m_barcode_buffer); |
| 62 | | new_barcode = buffer; |
| 63 | | } |
| 64 | | else |
| 65 | | { |
| 66 | | new_barcode = m_barcode_buffer; |
| 67 | | } |
| 58 | // selected device |
| 59 | item_append(current_display_name().cstr(), "", current_display_flags(), ITEMREF_SELECT_READER); |
| 68 | 60 | |
| 69 | | item_append("New Barcode:", new_barcode, 0, ITEMREF_NEW_BARCODE); |
| 70 | | |
| 71 | | // finish up the menu |
| 72 | | item_append(MENU_SEPARATOR_ITEM, NULL, 0, NULL); |
| 73 | | item_append("Enter Code", NULL, 0, ITEMREF_ENTER); |
| 74 | | |
| 75 | | customtop = machine().ui().get_line_height() + 3.0f * UI_BOX_TB_BORDER; |
| 61 | // append the "New Barcode" item |
| 62 | if (get_selection() == ITEMREF_NEW_BARCODE) |
| 63 | { |
| 64 | buffer.cat(m_barcode_buffer); |
| 65 | new_barcode = buffer; |
| 66 | } |
| 67 | else |
| 68 | { |
| 69 | new_barcode = m_barcode_buffer; |
| 70 | } |
| 71 | |
| 72 | item_append("New Barcode:", new_barcode, 0, ITEMREF_NEW_BARCODE); |
| 73 | |
| 74 | // finish up the menu |
| 75 | item_append(MENU_SEPARATOR_ITEM, NULL, 0, NULL); |
| 76 | item_append("Enter Code", NULL, 0, ITEMREF_ENTER_BARCODE); |
| 77 | |
| 78 | customtop = machine().ui().get_line_height() + 3.0f * UI_BOX_TB_BORDER; |
| 79 | } |
| 76 | 80 | } |
| 77 | 81 | |
| 78 | 82 | |
| r242774 | r242775 | |
| 80 | 84 | // handle - manages inputs in the barcode input menu |
| 81 | 85 | //------------------------------------------------- |
| 82 | 86 | |
| 83 | | void ui_menu_barcode_code::handle() |
| 87 | void ui_menu_barcode_reader::handle() |
| 84 | 88 | { |
| 89 | // rebuild the menu (so to update the selected device, if the user has pressed L or R) |
| 90 | reset(UI_MENU_RESET_REMEMBER_POSITION); |
| 91 | populate(); |
| 92 | |
| 85 | 93 | // process the menu |
| 86 | | const ui_menu_event *event = process(0); |
| 94 | const ui_menu_event *event = process(UI_MENU_PROCESS_LR_REPEAT); |
| 87 | 95 | |
| 88 | 96 | // process the event |
| 89 | 97 | if (event != NULL) |
| r242774 | r242775 | |
| 91 | 99 | // handle selections |
| 92 | 100 | switch (event->iptkey) |
| 93 | 101 | { |
| 102 | case IPT_UI_LEFT: |
| 103 | if (event->itemref == ITEMREF_SELECT_READER) |
| 104 | previous(); |
| 105 | break; |
| 106 | |
| 107 | case IPT_UI_RIGHT: |
| 108 | if (event->itemref == ITEMREF_SELECT_READER) |
| 109 | next(); |
| 110 | break; |
| 111 | |
| 94 | 112 | case IPT_UI_SELECT: |
| 95 | | if (event->itemref == ITEMREF_ENTER) |
| 113 | if (event->itemref == ITEMREF_ENTER_BARCODE) |
| 96 | 114 | { |
| 97 | 115 | astring tmp_file(m_barcode_buffer); |
| 98 | 116 | //printf("code %s\n", m_barcode_buffer); |
| 99 | | if (!m_reader->is_valid(tmp_file.len())) |
| 117 | if (!current_device()->is_valid(tmp_file.len())) |
| 100 | 118 | machine().ui().popup_time(5, "Barcode length invalid!"); |
| 101 | 119 | else |
| 102 | 120 | { |
| 103 | | m_reader->write_code(tmp_file.cstr(), tmp_file.len()); |
| 121 | current_device()->write_code(tmp_file.cstr(), tmp_file.len()); |
| 104 | 122 | // if sending was successful, reset char buffer |
| 105 | 123 | if (m_barcode_buffer[0] != '\0') |
| 106 | 124 | memset(m_barcode_buffer, '\0', ARRAY_LENGTH(m_barcode_buffer)); |
| r242774 | r242775 | |
| 134 | 152 | } |
| 135 | 153 | } |
| 136 | 154 | } |
| 137 | | |
| 138 | | |
| 139 | | |
| 140 | | /************************************************** |
| 141 | | |
| 142 | | READER MENU |
| 143 | | |
| 144 | | **************************************************/ |
| 145 | | |
| 146 | | //------------------------------------------------- |
| 147 | | // ctor |
| 148 | | //------------------------------------------------- |
| 149 | | |
| 150 | | ui_menu_barcode_reader::ui_menu_barcode_reader(running_machine &machine, render_container *container) |
| 151 | | : ui_menu(machine, container) |
| 152 | | { |
| 153 | | } |
| 154 | | |
| 155 | | //------------------------------------------------- |
| 156 | | // dtor |
| 157 | | //------------------------------------------------- |
| 158 | | |
| 159 | | ui_menu_barcode_reader::~ui_menu_barcode_reader() |
| 160 | | { |
| 161 | | } |
| 162 | | |
| 163 | | |
| 164 | | //------------------------------------------------- |
| 165 | | // populate - populates the barcode reader menu |
| 166 | | //------------------------------------------------- |
| 167 | | |
| 168 | | void ui_menu_barcode_reader::populate() |
| 169 | | { |
| 170 | | astring buffer; |
| 171 | | |
| 172 | | barcode_reader_device_iterator iter(machine().config().root_device()); |
| 173 | | for (const barcode_reader_device *bcreader = iter.first(); bcreader != NULL; bcreader = iter.next()) |
| 174 | | { |
| 175 | | char label[0x400]; |
| 176 | | sprintf(label,"[%s (%s)]",bcreader->name(),bcreader->basetag()); |
| 177 | | item_append(label, NULL, 0, (void *)bcreader); |
| 178 | | } |
| 179 | | } |
| 180 | | |
| 181 | | |
| 182 | | //------------------------------------------------- |
| 183 | | // handle - manages inputs in the barcode reader menu |
| 184 | | //------------------------------------------------- |
| 185 | | |
| 186 | | void ui_menu_barcode_reader::handle() |
| 187 | | { |
| 188 | | // process the menu |
| 189 | | const ui_menu_event *event = process(0); |
| 190 | | |
| 191 | | // process the event |
| 192 | | if (event != NULL && event->iptkey == IPT_UI_SELECT) |
| 193 | | { |
| 194 | | if (event->itemref != NULL) |
| 195 | | { |
| 196 | | ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_barcode_code(machine(), container, (barcode_reader_device *)event->itemref))); |
| 197 | | } |
| 198 | | |
| 199 | | } |
| 200 | | } |