[80] | 1 | /********************************************************************** <BR>
|
---|
| 2 | This file is part of Crack dot Com's free source code release of
|
---|
| 3 | Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
|
---|
| 4 | information about compiling & licensing issues visit this URL</a>
|
---|
| 5 | <PRE> If that doesn't help, contact Jonathan Clark at
|
---|
| 6 | golgotha_source@usa.net (Subject should have "GOLG" in it)
|
---|
| 7 | ***********************************************************************/
|
---|
| 8 |
|
---|
| 9 | #include "lisp/li_init.hh"
|
---|
| 10 | #include "app/app.hh"
|
---|
| 11 | #include "file/get_filename.hh"
|
---|
| 12 | #include "m1_info.hh"
|
---|
| 13 | #include "max_object.hh"
|
---|
| 14 | #include "loaders/dir_save.hh"
|
---|
| 15 | #include "render.hh"
|
---|
| 16 |
|
---|
| 17 |
|
---|
| 18 | i4_str *m1_get_dir()
|
---|
| 19 | {
|
---|
| 20 | if (m1_info.obj && m1_info.models.size()>m1_info.current_model)
|
---|
| 21 | {
|
---|
| 22 | i4_filename_struct fn;
|
---|
| 23 | i4_split_path(m1_info.current_filename(), fn);
|
---|
| 24 | if (fn.path)
|
---|
| 25 | return new i4_str(fn.path);
|
---|
| 26 | else
|
---|
| 27 | return new i4_str(".");
|
---|
| 28 | }
|
---|
| 29 | else return new i4_str(".");
|
---|
| 30 | }
|
---|
| 31 |
|
---|
| 32 | li_object *m1_save(li_object *o, li_environment *env)
|
---|
| 33 | {
|
---|
| 34 | if (m1_info.obj && m1_info.models.size()>m1_info.current_model)
|
---|
| 35 | {
|
---|
| 36 | i4_file_class *fp=i4_open(m1_info.current_filename(), I4_WRITE);
|
---|
| 37 | if (fp)
|
---|
| 38 | {
|
---|
| 39 | m1_info.obj->update(0);
|
---|
| 40 | i4_saver_class *sfp=new i4_saver_class(fp);
|
---|
| 41 | m1_info.obj->save(sfp);
|
---|
| 42 | sfp->begin_data_write();
|
---|
| 43 | m1_info.obj->save(sfp);
|
---|
| 44 | delete fp;
|
---|
| 45 | }
|
---|
| 46 | }
|
---|
| 47 | return 0;
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 |
|
---|
| 51 |
|
---|
| 52 | class m1_saveas_handler_class : public i4_event_handler_class
|
---|
| 53 | {
|
---|
| 54 | public:
|
---|
| 55 | char *name() { return "saveas"; }
|
---|
| 56 | void receive_event(i4_event *ev)
|
---|
| 57 | {
|
---|
| 58 | CAST_PTR(f, i4_file_open_message_class, ev);
|
---|
| 59 | if (f->sub_type)
|
---|
| 60 | {
|
---|
| 61 | m1_info.set_current_filename(*f->filename);
|
---|
| 62 | m1_save(0,0);
|
---|
| 63 | }
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | } m1_saveas_handler;
|
---|
| 67 |
|
---|
| 68 |
|
---|
| 69 | li_object *m1_saveas(li_object *o, li_environment *env)
|
---|
| 70 | {
|
---|
| 71 | if (m1_info.obj && m1_info.models.size()>m1_info.current_model)
|
---|
| 72 | {
|
---|
| 73 | i4_str *sdir=m1_get_dir();
|
---|
| 74 | i4_create_file_save_dialog(i4_current_app->get_style(),
|
---|
| 75 | m1_info.current_filename(),
|
---|
| 76 | "Save As..",
|
---|
| 77 | *sdir,
|
---|
| 78 | "*.gmod",
|
---|
| 79 | "Golgotha MODel",
|
---|
| 80 | &m1_saveas_handler,
|
---|
| 81 | 1,0);
|
---|
| 82 | delete sdir;
|
---|
| 83 | }
|
---|
| 84 | return 0;
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 |
|
---|
| 88 |
|
---|
| 89 | class m1_open_handler_class : public i4_event_handler_class
|
---|
| 90 | {
|
---|
| 91 | public:
|
---|
| 92 | char *name() { return "open"; }
|
---|
| 93 | void receive_event(i4_event *ev)
|
---|
| 94 | {
|
---|
| 95 | CAST_PTR(f, i4_file_open_message_class, ev);
|
---|
| 96 | if (f->sub_type)
|
---|
| 97 | {
|
---|
| 98 | m1_info.set_current_filename(*f->filename);
|
---|
| 99 | m1_render_window->set_object(*m1_info.models[m1_info.current_model]);
|
---|
| 100 | }
|
---|
| 101 | }
|
---|
| 102 |
|
---|
| 103 | } m1_open_handler;
|
---|
| 104 |
|
---|
| 105 |
|
---|
| 106 | li_object *m1_open(li_object *o, li_environment *env)
|
---|
| 107 | {
|
---|
| 108 | if (o)
|
---|
| 109 | {
|
---|
| 110 | char buff[512];
|
---|
| 111 |
|
---|
| 112 | strcpy(buff, li_get_string(li_eval(li_car(o,env), env),env));
|
---|
| 113 |
|
---|
| 114 | m1_info.set_current_filename(buff);
|
---|
| 115 | m1_render_window->set_object(buff);
|
---|
| 116 | }
|
---|
| 117 | else
|
---|
| 118 | {
|
---|
| 119 | i4_str *sdir=m1_get_dir();
|
---|
| 120 | i4_create_file_open_dialog(i4_current_app->get_style(),
|
---|
| 121 | "Open..",
|
---|
| 122 | *sdir,
|
---|
| 123 | "*.gmod",
|
---|
| 124 | "Golgotha MODel",
|
---|
| 125 | &m1_open_handler,
|
---|
| 126 | 1,0);
|
---|
| 127 | delete sdir;
|
---|
| 128 | }
|
---|
| 129 | return 0;
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | li_automatic_add_function(m1_saveas, "saveas_model");
|
---|
| 133 | li_automatic_add_function(m1_save, "save_model");
|
---|
| 134 | li_automatic_add_function(m1_open, "open_model");
|
---|