00001
00007 #ifndef INCL_CHUNKLST
00008 #define INCL_CHUNKLST 1
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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
00039
00040 class Chunk_info
00041 {
00042 friend class Chunk_chooser;
00043 int num;
00044 Rectangle box;
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
00055
00056 class Chunk_chooser: public Object_browser, public Shape_draw
00057 {
00058 std::istream& chunkfile;
00059
00060 GtkWidget *sbar;
00061 guint sbar_sel;
00062 int num_chunks;
00063
00064 std::vector<unsigned char *> chunklist;
00065 Chunk_info *info;
00066 int info_cnt;
00067 int locate_cx, locate_cy;
00068 bool drop_enabled;
00069 int to_del;
00070 void (*sel_changed)();
00071
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);
00078 virtual void render();
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);
00088 void scroll(bool upwards);
00089 void enable_controls();
00090
00091 virtual GtkWidget *create_popup();
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
00099 void unselect(bool need_render = true);
00100 int is_selected()
00101 { return selected >= 0; }
00102 void set_selected_callback(void (*fun)())
00103 { sel_changed = fun; }
00104 int get_count();
00105
00106 static gint configure(GtkWidget *widget, GdkEventConfigure *event,
00107 gpointer data);
00108
00109 static gint expose(GtkWidget *widget, GdkEventExpose *event,
00110 gpointer data);
00111
00112 static gint mouse_press(GtkWidget *widget, GdkEventButton *event,
00113 gpointer data);
00114
00115 static void drag_data_get(GtkWidget *widget, GdkDragContext *context,
00116 GtkSelectionData *data, guint info, guint time, gpointer data);
00117
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
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
00129 static void scrolled(GtkAdjustment *adj, gpointer data);
00130 void locate(int dir);
00131 virtual void locate(bool upwards);
00132 void locate_response(unsigned char *data, int datalen);
00133 void insert(bool dup);
00134 void del();
00135 void insert_response(unsigned char *data, int datalen);
00136 void delete_response(unsigned char *data, int datalen);
00137 virtual void move(bool upwards);
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