combo.h

Go to the documentation of this file.
00001 
00007 #ifndef INCL_COMBO_H
00008 #define INCL_COMBO_H  1
00009 
00010 /*
00011 Copyright (C) 2002 The Exult Team
00012 
00013 This program is free software; you can redistribute it and/or
00014 modify it under the terms of the GNU General Public License
00015 as published by the Free Software Foundation; either version 2
00016 of the License, or (at your option) any later version.
00017 
00018 This program is distributed in the hope that it will be useful,
00019 but WITHOUT ANY WARRANTY; without even the implied warranty of
00020 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021 GNU General Public License for more details.
00022 
00023 You should have received a copy of the GNU General Public License
00024 along with this program; if not, write to the Free Software
00025 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00026 */
00027 
00028 #include <string>
00029 #include <vector>
00030 #include "objbrowse.h"
00031 #include "shapedraw.h"
00032 #include "rect.h"
00033 
00034 class Shapes_vga_file;
00035 class Flex_file_info;
00036 
00037 /*
00038  *  A single object:
00039  */
00040 class Combo_member
00041   {
00042   short tx, ty, tz;   // Location (tile) rel. to top-left.
00043   short shapenum, framenum; // Object in shapes.vga.
00044 public:
00045   friend class Combo;
00046   friend class Combo_editor;
00047   friend class Combo_chooser;
00048   Combo_member(short x, short y, short z, short sh, short fr)
00049     : tx(x), ty(y), tz(z), shapenum(sh), framenum(fr)
00050     {  }
00051           // Return which makes better hot-spot.
00052   friend int hot_spot_compare(Combo_member& c0, Combo_member& c1);
00053   };
00054 
00055 /*
00056  *  A combination of objects.
00057  */
00058 class Combo
00059   {
00060   Shapes_vga_file *shapes_file; // Where shapes come from.
00061   std::vector<Combo_member *> members;  // Members of this combination.
00062   short hot_index;    // Index of obj. whose 'hot spot' we'll
00063           //   use.
00064   short starttx, startty;   // Offset represented by top-left.
00065   std::string name;   // Name given by user.
00066   Rectangle tilefoot;   // Footprint in tiles.
00067           // Get footprint of given member.
00068   Rectangle get_member_footprint(int i);
00069 public:
00070   friend class Combo_editor;
00071   friend class Combo_chooser;
00072   Combo(Shapes_vga_file *svga);
00073   Combo(const Combo& c2);   // Copy.
00074   ~Combo();
00075   Combo_member *get(int i)
00076     { return i >= 0 && i < members.size() ? members[i] : 0; }
00077           // Add a new object.
00078   void add(int tx, int ty, int tz, int shnum, int frnum);
00079   void remove(int i);   // Remove object #i.
00080           // Paint shapes in drawing area.
00081   void draw(Shape_draw *draw, int selected = -1, 
00082             int xoff = 0, int yoff = 0);
00083   int find(int mx, int my); // Find at mouse position.
00084           // Serialize:
00085   unsigned char *write(int& datalen);
00086   unsigned char *read(unsigned char *buf, int bufsize);
00087   };
00088 
00089 /*
00090  *  The 'combo editor' window:
00091  */
00092 class Combo_editor : public Shape_draw
00093   {
00094   GtkWidget *win;     // Main window.
00095   Combo *combo;     // Combo being edited.
00096   int selected;     // Index of selected item in combo.
00097   bool setting_controls;    // To avoid callbacks when setting.
00098   int file_index;     // Entry # in 'combos.flx', or -1 if
00099           //   new.
00100           // Set to edit existing combo.
00101   void set_combo(Combo *newcombo, int findex);
00102 public:
00103   friend class Combo_chooser;
00104   Combo_editor(Shapes_vga_file *svga, unsigned char *palbuf);
00105   ~Combo_editor();
00106   void show(bool tf);   // Show/hide.
00107   void render(GdkRectangle *area = 0);
00108   void set_controls();    // Set controls to selected entry.
00109           // Handle mouse.
00110   gint mouse_press(GdkEventButton *event);
00111   void set_order();   // Set selected to desired order.
00112   void set_position();    // Set selected to desired position.
00113           // Add object/shape picked from Exult.
00114   void add(unsigned char *data, int datalen);
00115   void remove();      // Remove selected.
00116   void save();      // Save it.
00117   bool is_visible()
00118     { return GTK_WIDGET_VISIBLE(win); }
00119   };
00120 
00121 /**********************************************************************
00122  *  Below are classes for the combo-browser.
00123  **********************************************************************/
00124 
00125 /*
00126  *  Store information about an individual combo shown in the list.
00127  */
00128 class Combo_info
00129   {
00130   friend class Combo_chooser;
00131   int num;
00132   Rectangle box;      // Box where drawn.
00133   Combo_info() {  }
00134   void set(int n, int rx, int ry, int rw, int rh)
00135     {
00136     num = n;
00137     box = Rectangle(rx, ry, rw, rh);
00138     }
00139   };
00140 
00141 /*
00142  *  This class manages the list of combos.
00143  */
00144 class Combo_chooser: public Object_browser, public Shape_draw
00145   {
00146   Flex_file_info *flex_info;  // Where file data is stored.
00147   std::vector<Combo *> combos;  // List of all combination-objects.
00148   GtkWidget *sbar;    // Status bar.
00149   guint sbar_sel;     // Status bar context for selection.
00150   int index0;     // Index (combo) # of leftmost in
00151           //   displayed list.
00152   Combo_info *info;   // An entry for each combo drawn.
00153   int info_cnt;     // # entries in info.
00154   void (*sel_changed)();    // Called when selection changes.
00155           // Blit onto screen.
00156   virtual void show(int x, int y, int w, int h);
00157   virtual void show()
00158     { Combo_chooser::show(0, 0, 
00159       draw->allocation.width, draw->allocation.height);}
00160   void select(int new_sel); // Show new selection.
00161   virtual void load();    // Load from file data.
00162   virtual void render();    // Draw list.
00163   virtual void set_background_color(guint32 c)
00164     { Shape_draw::set_background_color(c); }
00165   virtual int get_selected_id()
00166     { return selected < 0 ? -1 : info[selected].num; }
00167   void scroll(int newindex);  // Scroll.
00168   void scroll(bool upwards);
00169   void enable_controls();   // Enable/disable controls after sel.
00170           //   has changed.
00171 public:
00172   Combo_chooser(Vga_file *i, Flex_file_info *flinfo,
00173       unsigned char *palbuf, int w, int h,
00174             Shape_group *g = 0);
00175   virtual ~Combo_chooser();
00176           // Turn off selection.
00177   void unselect(bool need_render = true);
00178   int is_selected()   // Is a combo selected?
00179     { return selected >= 0; }
00180   void set_selected_callback(void (*fun)())
00181     { sel_changed = fun; }
00182   int get_count();    // Get # to show.
00183   int add(Combo *newcombo, int index);  // Add new combo.
00184   void remove();      // Remove selected.
00185   void edit();      // Edit selected.
00186           // Configure when created/resized.
00187   static gint configure(GtkWidget *widget, GdkEventConfigure *event,
00188               gpointer data);
00189           // Blit to screen.
00190   static gint expose(GtkWidget *widget, GdkEventExpose *event,
00191               gpointer data);
00192           // Handle mouse press.
00193   static gint mouse_press(GtkWidget *widget, GdkEventButton *event,
00194               gpointer data);
00195           // Give dragged combo.
00196   static void drag_data_get(GtkWidget *widget, GdkDragContext *context,
00197     GtkSelectionData *data, guint info, guint time, gpointer data);
00198           // Someone else selected.
00199   static gint selection_clear(GtkWidget *widget,
00200         GdkEventSelection *event, gpointer data);
00201   static gint drag_begin(GtkWidget *widget, GdkDragContext *context,
00202               gpointer data);
00203           // Handle scrollbar.
00204   static void scrolled(GtkAdjustment *adj, gpointer data);
00205   virtual void move(bool upwards);// Move current selected combo.
00206   virtual void search(const char *srch, int dir);
00207 #ifdef WIN32
00208   static gint win32_drag_motion(GtkWidget *widget, GdkEventMotion *event,
00209     gpointer data);
00210 #else
00211   static gint drag_motion(GtkWidget *widget, GdkEventMotion *event,
00212     gpointer data);
00213 #endif
00214   };
00215 
00216 
00217 #endif  /* INCL_COMBO_H */

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