00001
00007 #ifndef INCL_COMBO_H
00008 #define INCL_COMBO_H 1
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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
00039
00040 class Combo_member
00041 {
00042 short tx, ty, tz;
00043 short shapenum, framenum;
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
00052 friend int hot_spot_compare(Combo_member& c0, Combo_member& c1);
00053 };
00054
00055
00056
00057
00058 class Combo
00059 {
00060 Shapes_vga_file *shapes_file;
00061 std::vector<Combo_member *> members;
00062 short hot_index;
00063
00064 short starttx, startty;
00065 std::string name;
00066 Rectangle tilefoot;
00067
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);
00074 ~Combo();
00075 Combo_member *get(int i)
00076 { return i >= 0 && i < members.size() ? members[i] : 0; }
00077
00078 void add(int tx, int ty, int tz, int shnum, int frnum);
00079 void remove(int i);
00080
00081 void draw(Shape_draw *draw, int selected = -1,
00082 int xoff = 0, int yoff = 0);
00083 int find(int mx, int my);
00084
00085 unsigned char *write(int& datalen);
00086 unsigned char *read(unsigned char *buf, int bufsize);
00087 };
00088
00089
00090
00091
00092 class Combo_editor : public Shape_draw
00093 {
00094 GtkWidget *win;
00095 Combo *combo;
00096 int selected;
00097 bool setting_controls;
00098 int file_index;
00099
00100
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);
00107 void render(GdkRectangle *area = 0);
00108 void set_controls();
00109
00110 gint mouse_press(GdkEventButton *event);
00111 void set_order();
00112 void set_position();
00113
00114 void add(unsigned char *data, int datalen);
00115 void remove();
00116 void save();
00117 bool is_visible()
00118 { return GTK_WIDGET_VISIBLE(win); }
00119 };
00120
00121
00122
00123
00124
00125
00126
00127
00128 class Combo_info
00129 {
00130 friend class Combo_chooser;
00131 int num;
00132 Rectangle box;
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
00143
00144 class Combo_chooser: public Object_browser, public Shape_draw
00145 {
00146 Flex_file_info *flex_info;
00147 std::vector<Combo *> combos;
00148 GtkWidget *sbar;
00149 guint sbar_sel;
00150 int index0;
00151
00152 Combo_info *info;
00153 int info_cnt;
00154 void (*sel_changed)();
00155
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);
00161 virtual void load();
00162 virtual void render();
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);
00168 void scroll(bool upwards);
00169 void enable_controls();
00170
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
00177 void unselect(bool need_render = true);
00178 int is_selected()
00179 { return selected >= 0; }
00180 void set_selected_callback(void (*fun)())
00181 { sel_changed = fun; }
00182 int get_count();
00183 int add(Combo *newcombo, int index);
00184 void remove();
00185 void edit();
00186
00187 static gint configure(GtkWidget *widget, GdkEventConfigure *event,
00188 gpointer data);
00189
00190 static gint expose(GtkWidget *widget, GdkEventExpose *event,
00191 gpointer data);
00192
00193 static gint mouse_press(GtkWidget *widget, GdkEventButton *event,
00194 gpointer data);
00195
00196 static void drag_data_get(GtkWidget *widget, GdkDragContext *context,
00197 GtkSelectionData *data, guint info, guint time, gpointer data);
00198
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
00204 static void scrolled(GtkAdjustment *adj, gpointer data);
00205 virtual void move(bool upwards);
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