chunklst.h

Go to the documentation of this file.
00001 
00007 #ifndef INCL_CHUNKLST
00008 #define INCL_CHUNKLST 1
00009 
00010 /*
00011 Copyright (C) 2001 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 <vector>
00029 #include "objbrowse.h"
00030 #include "rect.h"
00031 #include "shapedraw.h"
00032 
00033 class Image_buffer8;
00034 class Shape_group;
00035 #include <iosfwd>
00036 
00037 /*
00038  *  Store information about an individual chunk shown in the list.
00039  */
00040 class Chunk_info
00041   {
00042   friend class Chunk_chooser;
00043   int num;
00044   Rectangle box;      // Box where drawn.
00045   Chunk_info() {  }
00046   void set(int n, int rx, int ry, int rw, int rh)
00047     {
00048     num = n;
00049     box = Rectangle(rx, ry, rw, rh);
00050     }
00051   };
00052 
00053 /*
00054  *  This class manages the list of chunks.
00055  */
00056 class Chunk_chooser: public Object_browser, public Shape_draw
00057   {
00058   std::istream& chunkfile;  // Where chunks are read from (each is
00059           //   256 shape ID's = 512 bytes).
00060   GtkWidget *sbar;    // Status bar.
00061   guint sbar_sel;     // Status bar context for selection.
00062   int num_chunks;     // Total # of chunks.
00063           // List of chunks we've read in.
00064   std::vector<unsigned char *> chunklist;
00065   Chunk_info *info;   // An entry for each chunk drawn.
00066   int info_cnt;     // # entries in info.
00067   int locate_cx, locate_cy; // Last chunk found by 'locate'.
00068   bool drop_enabled;    // So we only do it once.
00069   int to_del;     // Terrain # to delete, or -1.
00070   void (*sel_changed)();    // Called when selection changes.
00071           // Blit onto screen.
00072   virtual void show(int x, int y, int w, int h);
00073   virtual void show()
00074     { Chunk_chooser::show(0, 0, 
00075       draw->allocation.width, draw->allocation.height);}
00076   void tell_server();
00077   void select(int new_sel); // Show new selection.
00078   virtual void render();    // Draw list.
00079   virtual void set_background_color(guint32 c)
00080     { Shape_draw::set_background_color(c); }
00081   virtual int get_selected_id()
00082     { return selected < 0 ? -1 : info[selected].num; }
00083   unsigned char *get_chunk(int chunknum);
00084   void update_num_chunks(int new_num_chunks);
00085   void set_chunk(unsigned char *data, int datalen);
00086   void render_chunk(int chunknum, int xoff, int yoff);
00087   void scroll(int newindex);  // Scroll.
00088   void scroll(bool upwards);
00089   void enable_controls();   // Enable/disable controls after sel.
00090           //   has changed.
00091   virtual GtkWidget *create_popup();  // Popup menu.
00092 public:
00093   Chunk_chooser(Vga_file *i, std::istream& cfile, unsigned char *palbuf, 
00094           int w, int h, Shape_group *g = 0);
00095   virtual ~Chunk_chooser();
00096   virtual bool server_response(int id, unsigned char *data, int datalen);
00097   virtual void end_terrain_editing();
00098           // Turn off selection.
00099   void unselect(bool need_render = true);
00100   int is_selected()   // Is a chunk selected?
00101     { return selected >= 0; }
00102   void set_selected_callback(void (*fun)())
00103     { sel_changed = fun; }
00104   int get_count();    // Get # chunks we can display.
00105           // Configure when created/resized.
00106   static gint configure(GtkWidget *widget, GdkEventConfigure *event,
00107               gpointer data);
00108           // Blit to screen.
00109   static gint expose(GtkWidget *widget, GdkEventExpose *event,
00110               gpointer data);
00111           // Handle mouse press.
00112   static gint mouse_press(GtkWidget *widget, GdkEventButton *event,
00113               gpointer data);
00114           // Give dragged chunk.
00115   static void drag_data_get(GtkWidget *widget, GdkDragContext *context,
00116     GtkSelectionData *data, guint info, guint time, gpointer data);
00117           // Someone else selected.
00118   static gint selection_clear(GtkWidget *widget,
00119         GdkEventSelection *event, gpointer data);
00120   static gint drag_begin(GtkWidget *widget, GdkDragContext *context,
00121               gpointer data);
00122           // Handler for drop.
00123   static void drag_data_received(GtkWidget *widget, 
00124     GdkDragContext *context, gint x, gint y, 
00125     GtkSelectionData *selection_data, guint info, guint time,
00126     gpointer udata);
00127   void enable_drop();
00128           // Handle scrollbar.
00129   static void scrolled(GtkAdjustment *adj, gpointer data);
00130   void locate(int dir);   // Locate terrain on game map.
00131   virtual void locate(bool upwards);
00132   void locate_response(unsigned char *data, int datalen);
00133   void insert(bool dup);    // Insert new chunk.
00134   void del();     // Delete current chunk.
00135   void insert_response(unsigned char *data, int datalen);
00136   void delete_response(unsigned char *data, int datalen);
00137   virtual void move(bool upwards);  // Move current selected chunk.
00138   void swap_response(unsigned char *data, int datalen);
00139 #ifdef WIN32
00140   static gint win32_drag_motion(GtkWidget *widget, GdkEventMotion *event,
00141     gpointer data);
00142 #else
00143   static gint drag_motion(GtkWidget *widget, GdkEventMotion *event,
00144     gpointer data);
00145 #endif
00146   };
00147 
00148 #endif

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