shapelst.h

Go to the documentation of this file.
00001 
00007 #ifndef INCL_SHAPELST
00008 #define INCL_SHAPELST 1
00009 
00010 /*
00011 Copyright (C) 1999  Jeffrey S. Freedman
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 "objbrowse.h"
00029 #include "shapedraw.h"
00030 #include "rect.h"
00031 #include <vector>
00032 #include <ctime>
00033 
00034 class Vga_file;
00035 class Image_buffer8;
00036 class Shapes_vga_file;
00037 class Editing_file;
00038 
00039 /*
00040  *  Store information about an individual shape shown in the list.
00041  */
00042 class Shape_entry
00043   {
00044   friend class Shape_chooser;
00045   int index;      // Index in list.  Equals shapenum if
00046           //   not showing a 'group'.
00047   int shapenum, framenum;   // The given shape/frame.
00048   Rectangle box;      // Box where drawn.
00049   Shape_entry() {  }
00050   void set(int ind, int shnum, int frnum, int rx, int ry, int rw, int rh)
00051     {
00052     index = ind;
00053     shapenum = shnum; framenum = frnum;
00054     box = Rectangle(rx, ry, rw, rh);
00055     }
00056   };
00057 
00058 /*
00059  *  This class manages a list of shapes from an image file.
00060  */
00061 class Shape_chooser: public Object_browser, public Shape_draw
00062   {
00063   Shapes_vga_file *shapes_file; // Non-null if 'shapes.vga'.
00064   GtkWidget *sbar;    // Status bar.
00065   guint sbar_sel;     // Status bar context for selection.
00066   GtkWidget *fspin;   // Spin button for frame #.
00067   GtkAdjustment *frame_adj; // Adjustment for frame spin btn.
00068   int framenum0;      // Default frame # to display.
00069   Shape_entry *info;    // An entry for each shape drawn.
00070   int info_cnt;     // # entries in info.
00071   std::vector<short> row_indices; // Index at start of each row.
00072   int row0;     // Row # at top of window.
00073   int nrows;      // Last #rows rendered.
00074   bool frames_mode;   // Show all frames horizontally.
00075   int hoffset;      // Horizontal offset in pixels (when in
00076           //   frames_mode).
00077   void (*sel_changed)();    // Called when selection changes.
00078           // List of files being edited by an
00079           //   external program (Gimp, etc.)
00080   static std::vector<Editing_file*> editing_files;
00081   static int check_editing_timer; // For monitoring files being edited.
00082           // Blit onto screen.
00083   virtual void show(int x, int y, int w, int h);
00084   virtual void show()
00085     { Shape_chooser::show(0, 0, 
00086       draw->allocation.width, draw->allocation.height);}
00087   void tell_server_shape(); // Tell Exult what shape is selected.
00088   void select(int new_sel); // Show new selection.
00089   virtual void render();    // Draw list.
00090   virtual void set_background_color(guint32 c)
00091     { Shape_draw::set_background_color(c); }
00092   void render_frames();   // Show all frames.
00093   void scroll_to_frame();   // Scroll so sel. frame is visible.
00094   int next_row(int start);  // Down/up 1 row.
00095   void goto_index(int index); // Get desired index in view.
00096   virtual int get_selected_id()
00097     { return selected < 0 ? -1 : info[selected].shapenum; }
00098   void scroll_vertical(int newindex); // Scroll.
00099   void adjust_vscrollbar(); // Set new scroll amounts.
00100   void adjust_hscrollbar(int newmax);
00101   virtual GtkWidget *create_popup();  // Popup menu.
00102 public:
00103   Shape_chooser(Vga_file *i, unsigned char *palbuf, int w, int h,
00104         Shape_group *g = 0, Shape_file_info *fi = 0);
00105   virtual ~Shape_chooser();
00106   void set_shapes_file(Shapes_vga_file *sh)
00107     { shapes_file = sh; } 
00108   void set_framenum0(int f)
00109     { framenum0 = f; }
00110   void shape_dropped_here(int file, int shapenum, int framenum);
00111   int get_count();    // Get # shapes we can display.
00112   virtual void search(const char *srch, int dir);
00113   virtual void locate(bool upwards);  // Locate shape on game map.
00114           // Turn off selection.
00115   void unselect(bool need_render = true);
00116   int is_selected()   // Is a shape selected?
00117     { return selected >= 0; }
00118   void set_selected_callback(void (*fun)())
00119     { sel_changed = fun; }
00120           // Get selected shape, or return 0.
00121   int get_selected(int& shapenum, int& framenum)
00122     {
00123     if (selected == -1)
00124       return (0);
00125     shapenum = info[selected].shapenum;
00126     framenum = info[selected].framenum;
00127     return (1);
00128     }
00129           // Configure when created/resized.
00130   gint configure(GdkEventConfigure *event);
00131           // Blit to screen.
00132   static gint expose(GtkWidget *widget, GdkEventExpose *event,
00133               gpointer data);
00134           // Handle mouse press.
00135   gint mouse_press(GtkWidget *widget, GdkEventButton *event);
00136           // Export current frame as a PNG.
00137   time_t export_png(const char *fname);
00138           // Export given image as a PNG.
00139   time_t export_png(const char *fname, Image_buffer8& img,
00140               int xoff, int yoff);
00141           // Export frames tiled.
00142   time_t export_tiled_png(const char *fname, int tiles, bool bycols);
00143   void edit_shape_info();   // Edit selected shape's info.
00144           // Edit selected shape-frame.
00145   void edit_shape(int tiles = 0, bool bycols = false);
00146           // Deal with list of files being edited
00147           //   by an external prog. (Gimp).
00148   static gint check_editing_files_cb(gpointer data);
00149   static gint check_editing_files();
00150   static void read_back_edited(Editing_file *ed);
00151   static void clear_editing_files();
00152           // Import/export from file selector.
00153   static void export_frame(char *fname, gpointer user_data);
00154   static void import_frame(char *fname, gpointer user_data);
00155   void new_frame();   // Add/del.
00156   void from_font_toggled(bool on);
00157   void new_shape();
00158   void create_new_shape();
00159   void del_frame();
00160           // Give dragged shape.
00161   static void drag_data_get(GtkWidget *widget, GdkDragContext *context,
00162     GtkSelectionData *data, guint info, guint time, gpointer data);
00163           // Someone else selected.
00164   static gint selection_clear(GtkWidget *widget,
00165         GdkEventSelection *event, gpointer data);
00166   static gint drag_begin(GtkWidget *widget, GdkDragContext *context,
00167               gpointer data);
00168           // Handle scrollbar.
00169   static void vscrolled(GtkAdjustment *adj, gpointer data);
00170   static void hscrolled(GtkAdjustment *adj, gpointer data);
00171           // Handle spin-button for frames.
00172   static void frame_changed(GtkAdjustment *adj, gpointer data);
00173   static void all_frames_toggled(GtkToggleButton *btn,
00174                     gpointer user_data);
00175 #ifdef WIN32
00176   static gint win32_drag_motion(GtkWidget *widget, GdkEventMotion *event,
00177     gpointer data);
00178 #else
00179   static gint drag_motion(GtkWidget *widget, GdkEventMotion *event,
00180     gpointer data);
00181 #endif
00182           // Menu items:
00183   static void on_shapes_popup_info_activate(
00184           GtkMenuItem *item, gpointer udata);
00185   static void on_shapes_popup_edit_activate(
00186           GtkMenuItem *item, gpointer udata);
00187   static void on_shapes_popup_edtiles_activate(
00188           GtkMenuItem *item, gpointer udata);
00189   };
00190 
00191 #endif

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