/branches/aleph-inio-branch/Source_Files/Misc/preferences_widgets_sdl.cpp

# · C++ · 117 lines · 55 code · 16 blank · 46 comment · 15 complexity · 1c9056621e62dd1dbfe122b083b0dfd9 MD5 · raw file

  1. /*
  2. Copyright (C) 1991-2001 and beyond by Bungie Studios, Inc.
  3. and the "Aleph One" developers.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. This license is contained in the file "COPYING",
  13. which is included with this source code; it is available online at
  14. http://www.gnu.org/licenses/gpl.html
  15. */
  16. /*
  17. * preferences_widgets_sdl.cpp - Preferences widgets, SDL specific
  18. *
  19. * Written in 2000 by Christian Bauer
  20. *
  21. * Ripped out of preferences_sdl.cpp/preferences_sdl.h into a new
  22. * file Mar 1, 2002 by Woody Zenfell, for sharing.
  23. */
  24. #include "preferences_widgets_sdl.h"
  25. /*
  26. * Environment dialog
  27. */
  28. void w_env_select::select_item_callback(void* arg) {
  29. w_env_select* obj = (w_env_select*) arg;
  30. obj->select_item(obj->parent);
  31. }
  32. void w_env_select::select_item(dialog *parent)
  33. {
  34. // Find available files
  35. vector<FileSpecifier> files;
  36. if (type == _typecode_theme) {
  37. // Theme, find by theme script
  38. FindThemes finder(files);
  39. vector<DirectorySpecifier>::const_iterator i = data_search_path.begin(), end = data_search_path.end();
  40. while (i != end) {
  41. FileSpecifier dir = *i + "Themes";
  42. finder.Find(dir, WILDCARD_TYPE);
  43. i++;
  44. }
  45. } else {
  46. // Map/phyics/shapes/sounds, find by type
  47. FindAllFiles finder(files);
  48. vector<DirectorySpecifier>::const_iterator i = data_search_path.begin(), end = data_search_path.end();
  49. while (i != end) {
  50. FileSpecifier dir = *i;
  51. finder.Find(dir, type);
  52. i++;
  53. }
  54. }
  55. // Create structured list of files
  56. vector<env_item> items;
  57. vector<FileSpecifier>::const_iterator i = files.begin(), end = files.end();
  58. string last_base;
  59. int indent_level = 0;
  60. for (i = files.begin(); i != end; i++) {
  61. string base, part;
  62. i->SplitPath(base, part);
  63. if (base != last_base) {
  64. // New directory
  65. FileSpecifier base_spec = base;
  66. // if (base_spec != global_dir && base_spec != local_dir) {
  67. // Subdirectory, insert name as unselectable item, put items on indentation level 1
  68. items.push_back(env_item(base_spec, 0, false));
  69. indent_level = 1;
  70. // } else {
  71. //
  72. // // Top-level directory, put items on indentation level 0
  73. // indent_level = 0;
  74. // }
  75. last_base = base;
  76. }
  77. items.push_back(env_item(*i, indent_level, true));
  78. }
  79. // Create dialog
  80. dialog d;
  81. d.add(new w_static_text(menu_title, TITLE_FONT, TITLE_COLOR));
  82. d.add(new w_spacer());
  83. w_env_list *list_w = new w_env_list(items, item.GetPath(), &d);
  84. d.add(list_w);
  85. d.add(new w_spacer());
  86. d.add(new w_button("CANCEL", dialog_cancel, &d));
  87. // Clear screen
  88. clear_screen();
  89. // Run dialog
  90. if (d.run() == 0) { // Accepted
  91. if (items.size())
  92. set_path(items[list_w->get_selection()].spec.GetPath());
  93. if(mCallback)
  94. mCallback(this);
  95. }
  96. }