objedit.cc

Go to the documentation of this file.
00001 
00007 /*
00008 Copyright (C) 2000-2001 The Exult Team
00009 
00010 This program is free software; you can redistribute it and/or
00011 modify it under the terms of the GNU General Public License
00012 as published by the Free Software Foundation; either version 2
00013 of the License, or (at your option) any later version.
00014 
00015 This program is distributed in the hope that it will be useful,
00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 GNU General Public License for more details.
00019 
00020 You should have received a copy of the GNU General Public License
00021 along with this program; if not, write to the Free Software
00022 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00023 */
00024 
00025 #ifdef HAVE_CONFIG_H
00026 #  include <config.h>
00027 #endif
00028 
00029 #include "studio.h"
00030 #include "u7drag.h"
00031 #include "servemsg.h"
00032 #include "objserial.h"
00033 #include "exult_constants.h"
00034 #include "utils.h"
00035 #include "shapefile.h"
00036 #include "shapedraw.h"
00037 
00038 using std::cout;
00039 using std::endl;
00040 
00041 /*
00042  *  Object window's Okay button.
00043  */
00044 C_EXPORT void on_obj_okay_clicked
00045   (
00046   GtkButton *btn,
00047   gpointer user_data
00048   )
00049   {
00050   ExultStudio::get_instance()->save_obj_window();
00051   ExultStudio::get_instance()->close_obj_window();
00052   }
00053 
00054 /*
00055  *  Object window's Apply button.
00056  */
00057 C_EXPORT void on_obj_apply_clicked
00058   (
00059   GtkButton *btn,
00060   gpointer user_data
00061   )
00062   {
00063   ExultStudio::get_instance()->save_obj_window();
00064   }
00065 
00066 /*
00067  *  Object window's Cancel button.
00068  */
00069 C_EXPORT void on_obj_cancel_clicked
00070   (
00071   GtkButton *btn,
00072   gpointer user_data
00073   )
00074   {
00075   ExultStudio::get_instance()->close_obj_window();
00076   }
00077 
00078 /*
00079  *  Object window's close button.
00080  */
00081 C_EXPORT gboolean on_obj_window_delete_event
00082   (
00083   GtkWidget *widget,
00084   GdkEvent *event,
00085   gpointer user_data
00086   )
00087   {
00088   ExultStudio::get_instance()->close_obj_window();
00089   return TRUE;
00090   }
00091 
00092 /*
00093  *  Draw shape in object shape area.
00094  */
00095 C_EXPORT gboolean on_obj_draw_expose_event
00096   (
00097   GtkWidget *widget,    // The view window.
00098   GdkEventExpose *event,
00099   gpointer data     // ->Shape_chooser.
00100   )
00101   {
00102   ExultStudio::get_instance()->show_obj_shape(
00103     event->area.x, event->area.y, event->area.width,
00104               event->area.height);
00105   return (TRUE);
00106   }
00107 
00108 /*
00109  *  Object shape/frame # changed, so update shape displayed.
00110  */
00111 C_EXPORT gboolean on_obj_shape_changed
00112   (
00113   GtkWidget *widget,
00114   GdkEventFocus *event,
00115   gpointer user_data
00116   )
00117   {
00118   ExultStudio::get_instance()->show_obj_shape();
00119   return TRUE;
00120   }
00121 
00122 /*
00123  *  Object shape/frame # changed, so update shape displayed.
00124  */
00125 C_EXPORT gboolean on_obj_pos_changed
00126   (
00127   GtkWidget *widget,
00128   GdkEventFocus *event,
00129   gpointer user_data
00130   )
00131   {
00132   //++++Maybe later, change pos. immediately?
00133   return TRUE;
00134   }
00135 
00136 /*
00137  *  Callback for when a shape is dropped on the draw area.
00138  */
00139 
00140 static void Obj_shape_dropped
00141   (
00142   int file,     // U7_SHAPE_SHAPES.
00143   int shape,
00144   int frame,
00145   void *udata
00146   )
00147   {
00148   if (file == U7_SHAPE_SHAPES && shape >= 0 && shape < 1024)
00149     ((ExultStudio *) udata)->set_obj_shape(shape, frame);
00150   }
00151 
00152 #ifdef WIN32
00153 
00154 static void Drop_dragged_shape(int shape, int frame, int x, int y, void *data)
00155 {
00156   cout << "Dropped a shape: " << shape << "," << frame << " " << data << endl;
00157 
00158   Obj_shape_dropped(U7_SHAPE_SHAPES, shape, frame, data);
00159 }
00160 
00161 #endif
00162 
00163 
00164 /*
00165  *  Open the object-editing window.
00166  */
00167 
00168 void ExultStudio::open_obj_window
00169   (
00170   unsigned char *data,    // Serialized object.
00171   int datalen
00172   )
00173   {
00174   bool first_time = false;
00175   if (!objwin)      // First time?
00176     {
00177     first_time = true;
00178     objwin = glade_xml_get_widget( app_xml, "obj_window" );
00179     if (vgafile && palbuf)
00180       {
00181       obj_draw = new Shape_draw(vgafile->get_ifile(), palbuf,
00182           glade_xml_get_widget(app_xml, "obj_draw"));
00183       obj_draw->enable_drop(Obj_shape_dropped, this);
00184       }
00185     }
00186           // Init. obj address to null.
00187   gtk_object_set_user_data(GTK_OBJECT(objwin), 0);
00188   if (!init_obj_window(data, datalen))
00189     return;
00190   gtk_widget_show(objwin);
00191 #ifdef WIN32
00192   if (first_time || !objdnd)
00193     Windnd::CreateStudioDropDest(objdnd, objhwnd, Drop_dragged_shape, NULL, NULL, (void*) this);
00194 #endif
00195   }
00196 
00197 /*
00198  *  Close the object-editing window.
00199  */
00200 
00201 void ExultStudio::close_obj_window
00202   (
00203   )
00204   {
00205   if (objwin) {
00206     gtk_widget_hide(objwin);
00207 #ifdef WIN32
00208     Windnd::DestroyStudioDropDest(objdnd, objhwnd);
00209 #endif
00210   }
00211   }
00212 
00213 /*
00214  *  Init. the object editor with data from Exult.
00215  *
00216  *  Output: 0 if error (reported).
00217  */
00218 
00219 int ExultStudio::init_obj_window
00220   (
00221   unsigned char *data,
00222   int datalen
00223   )
00224   {
00225   unsigned long addr;
00226   int tx, ty, tz;
00227   int shape, frame, quality;
00228   std::string name;
00229   if (!Object_in(data, datalen, addr, tx, ty, tz, shape, frame,
00230     quality, name))
00231     {
00232     cout << "Error decoding object" << endl;
00233     return 0;
00234     }
00235           // Store address with window.
00236   gtk_object_set_user_data(GTK_OBJECT(objwin), (gpointer) addr);
00237           // Store name. (Not allowed to change.)
00238   set_entry("obj_name", name.c_str(), false);
00239           // Shape/frame, quality.
00240 //  set_entry("obj_shape", shape);
00241 //  set_entry("obj_frame", frame);
00242 //  set_entry("obj_quality", quality);
00243   set_spin("obj_shape", shape);
00244   set_spin("obj_frame", frame);
00245   set_spin("obj_quality", quality);
00246   set_spin("obj_x", tx);    // Position.
00247   set_spin("obj_y", ty);
00248   set_spin("obj_z", tz);
00249           // Set limit on frame #.
00250   GtkWidget *btn = glade_xml_get_widget(app_xml, "obj_frame");
00251   if (btn)
00252     {
00253     GtkAdjustment *adj = gtk_spin_button_get_adjustment(
00254             GTK_SPIN_BUTTON(btn));
00255     int nframes = vgafile->get_ifile()->get_num_frames(shape);
00256     adj->upper = nframes - 1;
00257     gtk_signal_emit_by_name(GTK_OBJECT(adj), "changed");
00258     }   
00259   return 1;
00260   }
00261 
00262 /*
00263  *  Send updated object info. back to Exult.
00264  *
00265  *  Output: 0 if error (reported).
00266  */
00267 
00268 int ExultStudio::save_obj_window
00269   (
00270   )
00271   {
00272   cout << "In save_obj_window()" << endl;
00273   unsigned char data[Exult_server::maxlength];
00274           // Get object address.
00275   unsigned long addr = (unsigned long) gtk_object_get_user_data(
00276               GTK_OBJECT(objwin));
00277   int tx = get_spin("obj_x"), ty = get_spin("obj_y"), 
00278       tz = get_spin("obj_z");
00279   std::string name(get_text_entry("obj_name"));
00280 //  int shape = get_num_entry("obj_shape");
00281 //  int frame = get_num_entry("obj_frame");
00282 //  int quality = get_num_entry("obj_quality");
00283   int shape = get_spin("obj_shape");
00284   int frame = get_spin("obj_frame");
00285   int quality = get_spin("obj_quality");
00286   
00287   if (Object_out(server_socket, Exult_server::obj, addr, tx, ty, tz, 
00288           shape, frame, quality, name) == -1)
00289     {
00290     cout << "Error sending object data to server" <<endl;
00291     return 0;
00292     }
00293   cout << "Sent object data to server" << endl;
00294   return 1;
00295   }
00296 
00297 /*
00298  *  Paint the shape in the draw area.
00299  */
00300 
00301 void ExultStudio::show_obj_shape
00302   (
00303   int x, int y, int w, int h  // Rectangle. w=-1 to show all.
00304   )
00305   {
00306   if (!obj_draw)
00307     return;
00308   obj_draw->configure();
00309           // Yes, this is kind of redundant...
00310   int shnum = get_num_entry("obj_shape");
00311   int frnum = get_num_entry("obj_frame");
00312   if (!shnum)     // Don't draw shape 0.
00313     shnum = -1;
00314   obj_draw->draw_shape_centered(shnum, frnum);
00315   if (w != -1)
00316     obj_draw->show(x, y, w, h);
00317   else
00318     obj_draw->show();
00319   }
00320 
00321 /*
00322  *  Set object shape.
00323  */
00324 
00325 void ExultStudio::set_obj_shape
00326   (
00327   int shape,
00328   int frame
00329   )
00330   {
00331   set_spin("obj_shape", shape);
00332   set_spin("obj_frame", frame);
00333   const char *nm = get_shape_name(shape);
00334   set_entry("obj_name", nm ? nm : "", false);
00335   show_obj_shape();
00336   }
00337 
00338 

Generated on Mon Jul 9 14:42:48 2007 for ExultEngine by  doxygen 1.5.1