Utility.cpp 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : G *
  23. * *
  24. * $Archive:: /Commando/Code/Tools/max2w3d/Utility.cpp $*
  25. * *
  26. * $Author:: Andre_a $*
  27. * *
  28. * $Modtime:: 5/08/00 11:51a $*
  29. * *
  30. * $Revision:: 3 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * wwGetAbsolutePath -- Returns the absolute path based on a relative one. *
  35. * wwInputBox -- Retrive a string from the user in a nice friendly manner. *
  36. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  37. /*
  38. ** Utility.cpp - Implementation of a some convenient features the WIN32 API provides
  39. ** that the MAXScript API doesn't.
  40. */
  41. #include <MaxScrpt.h>
  42. #include <Arrays.h>
  43. #include <Strings.h>
  44. #include <definsfn.h>
  45. #include "util.h"
  46. #include "InputDlg.h"
  47. /*
  48. ** Let MAXScript know we're implementing new built-in functions.
  49. */
  50. def_visible_primitive(get_absolute_path, "wwGetAbsolutePath");
  51. def_visible_primitive(input_box, "wwInputBox");
  52. /***********************************************************************************************
  53. * get_absolute_path_cf -- Returns the absolute path based on a relative one. *
  54. * *
  55. * wwGetAbsolutePath - Usage: wwGetAbsolutePath <relative_path> <context> *
  56. * *
  57. * INPUT: A string containing a relative path, and its context. *
  58. * *
  59. * OUTPUT: The equivalent absolute path. *
  60. * *
  61. * WARNINGS: *
  62. * *
  63. * HISTORY: *
  64. * 10/4/1999 AJA : Created. *
  65. *=============================================================================================*/
  66. Value * get_absolute_path_cf (Value **arg_list, int count)
  67. {
  68. // We want an array as an argument
  69. check_arg_count("wwGetAbsolutePath", 2, count);
  70. type_check(arg_list[0], String, "Relative path");
  71. type_check(arg_list[1], String, "Context");
  72. // Grab the arguments out of the array.
  73. char absolute[MAX_PATH];
  74. char *relative = arg_list[0]->to_string();
  75. char *context = arg_list[1]->to_string();
  76. // Turn the relative path into an absolute one.
  77. Create_Full_Path(absolute, context, relative);
  78. // Return the absolute path.
  79. one_typed_value_local(String *abs);
  80. vl.abs = new String(absolute);
  81. return_value(vl.abs);
  82. }
  83. /***********************************************************************************************
  84. * input_box_cf -- Retrive a string from the user in a nice friendly manner. *
  85. * *
  86. * wwInputBox - Usage: wwInputBox [caption:'caption'] [label:'label'] [value:'value'] *
  87. * *
  88. * INPUT: Three optional named arguments. If they are not given values, defaults are used. *
  89. * *
  90. * OUTPUT: Returns the string entered by the user. *
  91. * *
  92. * WARNINGS: *
  93. * *
  94. * HISTORY: *
  95. *=============================================================================================*/
  96. Value * input_box_cf (Value **arg_list, int count)
  97. {
  98. // Create the input box (but don't show it yet).
  99. InputDlg input_box(MAXScript_interface->GetMAXHWnd());
  100. Value *param = NULL;
  101. // Check the 'caption' parameter.
  102. param = key_arg(caption);
  103. if (param && param != &unsupplied)
  104. input_box.SetCaption(param->to_string());
  105. // Check the 'label' parameter.
  106. param = key_arg(label);
  107. if (param && param != &unsupplied)
  108. input_box.SetLabel(param->to_string());
  109. // Check the 'value' parameter.
  110. param = key_arg(value);
  111. if (param && param != &unsupplied)
  112. input_box.SetValue(param->to_string());
  113. // Show the dialog and let the user enter a value.
  114. if (input_box.DoModal() == IDCANCEL)
  115. return &undefined;
  116. // Return the value the user entered.
  117. one_typed_value_local(String *val);
  118. vl.val = new String(input_box.m_Value);
  119. return_value(vl.val);
  120. }