Previous 15994 Revisions Next

r7991 Friday 7th May, 2010 at 17:24:23 UTC by Firewave
[NEWUI] Initial cleanup of input customization code
[src/mess/osd/windows]menu.c

src/mess/osd/windows/menu.c
r7990r7991
2323#include "opcntrl.h"
2424#include "strconv.h"
2525#include "utils.h"
26#include "png.h"
2726#include "debug/debugcpu.h"
2827#include "inptport.h"
2928#include "devices/cassette.h"
r7990r7991
135134//  artwork_get_inputscreen_customizations
136135//============================================================
137136
138int artwork_get_inputscreen_customizations(png_info *png, artwork_cust_type cust_type,
139   const char *section,
140   struct inputform_customization *customizations,
141   int customizations_length)
137int artwork_get_inputscreen_customizations(struct inputform_customization *customizations,   int customizations_length)
142138{
143   file_error filerr;
144   mame_file *file;
145   char buffer[1000];
146   char current_section[64];
147   char ipt_name[64];
148   char *p;
149   int x1, y1, x2, y2;
150   const char *png_filename;
151   const char *ini_filename;
152   int enabled = TRUE;
153   int item_count = 0;
154
155   static const char *const cust_files[] =
156   {
157      "ctrlr.png",      "ctrlr.ini",
158      "keyboard.png",      "keyboard.ini"
159      "misc.png",         "misc.ini"
160   };
161
162   if ((cust_type >= 0) && (cust_type < (ARRAY_LENGTH(cust_files) / 2)))
163   {
164      png_filename = cust_files[cust_type * 2 + 0];
165      ini_filename = cust_files[cust_type * 2 + 1];
166   }
167   else
168   {
169      png_filename = NULL;
170      ini_filename = NULL;
171   }
172
173   /* subtract one from the customizations length; so we can place IPT_END */
174   customizations_length--;
175
176   /* open the INI file, if available */
177   if (ini_filename)
178   {
179      filerr = mame_fopen(SEARCHPATH_ARTWORK, ini_filename, OPEN_FLAG_READ, &file);
180      if (filerr == FILERR_NONE)
181      {
182         /* loop until we run out of lines */
183         while (customizations_length && mame_fgets(buffer, sizeof(buffer), file))
184         {
185            /* strip off any comments */
186            p = strstr(buffer, "//");
187            if (p)
188               *p = 0;
189
190            /* section header? */
191            if (buffer[0] == '[')
192            {
193               strncpyz(current_section, &buffer[1],
194                  ARRAY_LENGTH(current_section));
195               p = strchr(current_section, ']');
196               if (!p)
197                  continue;
198               *p = '\0';
199               if (section)
200                  enabled = !mame_stricmp(current_section, section);
201               continue;
202            }
203
204            if (!enabled || sscanf(buffer, "%64s (%d,%d)-(%d,%d)", ipt_name, &x1, &y1, &x2, &y2) != 5)
205               continue;
206
207#if 0
208            /* temporarily disabled */
209            for (pik = input_keywords; pik->name[0]; pik++)
210            {
211               pik_name = pik->name;
212               if ((pik_name[0] == 'P') && (pik_name[1] == '1') && (pik_name[2] == '_'))
213                  pik_name += 3;
214
215               if (!strcmp(ipt_name, pik_name))
216               {
217                  if ((x1 > 0) && (y1 > 0) && (x2 > x1) && (y2 > y1))
218                  {
219                     customizations->ipt = pik->val;
220                     customizations->x = x1;
221                     customizations->y = y1;
222                     customizations->width = x2 - x1;
223                     customizations->height = y2 - y1;
224                     customizations++;
225                     customizations_length--;
226                     item_count++;
227                  }
228                  break;
229               }
230            }
231#endif
232         }
233         mame_fclose(file);
234      }
235   }
236
237139   /* terminate list */
238140   customizations->ipt = IPT_END;
239141   customizations->x = -1;
r7990r7991
241143   customizations->width = -1;
242144   customizations->height = -1;
243145
244   /* open the PNG, if available */
245   memset(png, 0, sizeof(*png));
246   if (png_filename && item_count > 0)
247   {
248      filerr = mame_fopen(SEARCHPATH_ARTWORK, ini_filename, OPEN_FLAG_READ, &file);
249      if (filerr == FILERR_NONE)
250      {
251         png_read_file(mame_core_file(file), png);
252         mame_fclose(file);
253      }
254   }
255   return item_count;
146   return 0;
256147}
257148
258149
r7990r7991
341232//  customize_input
342233//============================================================
343234
344static void customize_input(running_machine *machine, HWND wnd, const char *title, artwork_cust_type cust_type, int player, int inputclass, const char *section)
235static void customize_input(running_machine *machine, HWND wnd, const char *title, int player, int inputclass)
345236{
346237   dialog_box *dlg;
347238   const input_port_config *port;
348239   const input_field_config *field;
349   png_info png;
350240   struct inputform_customization customizations[128];
351241   RECT *pr;
352242   int this_inputclass, this_player, portslot_count, i;
r7990r7991
359249
360250   /* check to see if there is any custom artwork for this configure dialog,
361251     * and if so, retrieve the info */
362   portslot_count = artwork_get_inputscreen_customizations(&png, cust_type, section,
363      customizations, ARRAY_LENGTH(customizations));
252   portslot_count = artwork_get_inputscreen_customizations(customizations, ARRAY_LENGTH(customizations));
364253
365254   /* zero out the portslots that correspond to customizations */
366255   memset(portslots, 0, sizeof(portslots[0]) * portslot_count);
r7990r7991
370259   if (!dlg)
371260      goto done;
372261
373   if (png.width > 0)
374   {
375      win_dialog_add_image(dlg, &png);
376      win_dialog_add_separator(dlg);
377   }
378
379262   for (port = machine->portlist.first(); port != NULL; port = port->next)
380263   {
381264      for (field = port->fieldlist; field != NULL; field = field->next)
r7990r7991
456339
457340static void customize_joystick(running_machine *machine, HWND wnd, int joystick_num)
458341{
459   customize_input(machine, wnd, "Joysticks/Controllers", ARTWORK_CUSTTYPE_JOYSTICK, joystick_num, INPUT_CLASS_CONTROLLER, NULL);
342   customize_input(machine, wnd, "Joysticks/Controllers", joystick_num, INPUT_CLASS_CONTROLLER);
460343}
461344
462345
r7990r7991
467350
468351static void customize_keyboard(running_machine *machine, HWND wnd)
469352{
470   customize_input(machine, wnd, "Emulated Keyboard", ARTWORK_CUSTTYPE_KEYBOARD, 0, INPUT_CLASS_KEYBOARD, NULL);
353   customize_input(machine, wnd, "Emulated Keyboard", 0, INPUT_CLASS_KEYBOARD);
471354}
472355
473356
r7990r7991
478361
479362static void customize_miscinput(running_machine *machine, HWND wnd)
480363{
481   customize_input(machine, wnd, "Miscellaneous Input", ARTWORK_CUSTTYPE_MISC, 0, INPUT_CLASS_MISC, NULL);
364   customize_input(machine, wnd, "Miscellaneous Input", 0, INPUT_CLASS_MISC);
482365}
483366
484367
r7990r7991
487370//  customize_categorizedinput
488371//============================================================
489372
490static void customize_categorizedinput(running_machine *machine, HWND wnd, const char *section, int category)
373static void customize_categorizedinput(running_machine *machine, HWND wnd, int category)
491374{
492375   assert(category > 0);
493   customize_input(machine, wnd, "Input", ARTWORK_CUSTTYPE_JOYSTICK, category, INPUT_CLASS_CATEGORIZED, section);
376   customize_input(machine, wnd, "Input", category, INPUT_CLASS_CATEGORIZED);
494377}
495378
496379
r7990r7991
18911774   int dev_command;
18921775   running_device *img;
18931776   UINT16 category;
1894   const char *section;
18951777   const input_field_config *field;
18961778   const input_setting_config *setting;
18971779   LONG_PTR ptr = GetWindowLongPtr(wnd, GWLP_USERDATA);
r7990r7991
20901972               // customize the input type
20911973               input_field_get_user_settings(field, &settings);
20921974               category = 0;
2093               section = NULL;
20941975
20951976               for (setting = field->settinglist; setting != NULL; setting = setting->next)
20961977               {
20971978                  if (settings.value == setting->value)
20981979                  {
20991980                     category = setting->category;
2100                     section = setting->name;
21011981                  }
21021982               }
21031983               if (category)
2104                  customize_categorizedinput(window->machine, wnd, section, category);
1984                  customize_categorizedinput(window->machine, wnd, category);
21051985            }
21061986            else
21071987            {

Previous 15994 Revisions Next


© 1998-2018 The MESS Team