00001
00007 #ifndef INCL_SHAPELST
00008 #define INCL_SHAPELST 1
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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
00041
00042 class Shape_entry
00043 {
00044 friend class Shape_chooser;
00045 int index;
00046
00047 int shapenum, framenum;
00048 Rectangle box;
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
00060
00061 class Shape_chooser: public Object_browser, public Shape_draw
00062 {
00063 Shapes_vga_file *shapes_file;
00064 GtkWidget *sbar;
00065 guint sbar_sel;
00066 GtkWidget *fspin;
00067 GtkAdjustment *frame_adj;
00068 int framenum0;
00069 Shape_entry *info;
00070 int info_cnt;
00071 std::vector<short> row_indices;
00072 int row0;
00073 int nrows;
00074 bool frames_mode;
00075 int hoffset;
00076
00077 void (*sel_changed)();
00078
00079
00080 static std::vector<Editing_file*> editing_files;
00081 static int check_editing_timer;
00082
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();
00088 void select(int new_sel);
00089 virtual void render();
00090 virtual void set_background_color(guint32 c)
00091 { Shape_draw::set_background_color(c); }
00092 void render_frames();
00093 void scroll_to_frame();
00094 int next_row(int start);
00095 void goto_index(int index);
00096 virtual int get_selected_id()
00097 { return selected < 0 ? -1 : info[selected].shapenum; }
00098 void scroll_vertical(int newindex);
00099 void adjust_vscrollbar();
00100 void adjust_hscrollbar(int newmax);
00101 virtual GtkWidget *create_popup();
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();
00112 virtual void search(const char *srch, int dir);
00113 virtual void locate(bool upwards);
00114
00115 void unselect(bool need_render = true);
00116 int is_selected()
00117 { return selected >= 0; }
00118 void set_selected_callback(void (*fun)())
00119 { sel_changed = fun; }
00120
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
00130 gint configure(GdkEventConfigure *event);
00131
00132 static gint expose(GtkWidget *widget, GdkEventExpose *event,
00133 gpointer data);
00134
00135 gint mouse_press(GtkWidget *widget, GdkEventButton *event);
00136
00137 time_t export_png(const char *fname);
00138
00139 time_t export_png(const char *fname, Image_buffer8& img,
00140 int xoff, int yoff);
00141
00142 time_t export_tiled_png(const char *fname, int tiles, bool bycols);
00143 void edit_shape_info();
00144
00145 void edit_shape(int tiles = 0, bool bycols = false);
00146
00147
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
00153 static void export_frame(char *fname, gpointer user_data);
00154 static void import_frame(char *fname, gpointer user_data);
00155 void new_frame();
00156 void from_font_toggled(bool on);
00157 void new_shape();
00158 void create_new_shape();
00159 void del_frame();
00160
00161 static void drag_data_get(GtkWidget *widget, GdkDragContext *context,
00162 GtkSelectionData *data, guint info, guint time, gpointer data);
00163
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
00169 static void vscrolled(GtkAdjustment *adj, gpointer data);
00170 static void hscrolled(GtkAdjustment *adj, gpointer data);
00171
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
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