Changed the "tagrelease" and "tagstable" make targets to use subversion. Also increme...
[synfig.git] / synfig-studio / tags / stable / src / gtkmm / iconcontroler.cpp
1 /* === S I N F G =========================================================== */
2 /*!     \file template.cpp
3 **      \brief Template File
4 **
5 **      $Id: iconcontroler.cpp,v 1.1.1.1 2005/01/07 03:34:36 darco Exp $
6 **
7 **      \legal
8 **      Copyright (c) 2002 Robert B. Quattlebaum Jr.
9 **
10 **      This software and associated documentation
11 **      are CONFIDENTIAL and PROPRIETARY property of
12 **      the above-mentioned copyright holder.
13 **
14 **      You may not copy, print, publish, or in any
15 **      other way distribute this software without
16 **      a prior written agreement with
17 **      the copyright holder.
18 **      \endlegal
19 */
20 /* ========================================================================= */
21
22 /* === H E A D E R S ======================================================= */
23
24 #ifdef USING_PCH
25 #       include "pch.h"
26 #else
27 #ifdef HAVE_CONFIG_H
28 #       include <config.h>
29 #endif
30
31 #include "iconcontroler.h"
32 #include <sinfg/valuenode_const.h>
33 #include <gtkmm/button.h>
34 #include <gtkmm/window.h>
35 #include <sinfgapp/action.h>
36
37 #endif
38
39 /* === U S I N G =========================================================== */
40
41 using namespace etl;
42 using namespace std;
43 using namespace studio;
44 using namespace sinfg;
45
46 /* === M A C R O S ========================================================= */
47
48 // Quick hack to keep stuff working until gettext support is added
49 #ifndef _
50 #define _(x)    (x)
51 #define N_(x)   (x)
52 #endif
53
54 #ifdef WIN32
55 #       ifdef IMAGE_DIR
56 #               undef IMAGE_DIR
57 #               define IMAGE_DIR "share\\pixmaps"
58 #       endif
59 #endif
60
61 #ifndef IMAGE_DIR
62 #       define IMAGE_DIR "/usr/local/share/pixmaps"
63 #endif
64
65
66 #ifndef IMAGE_EXT
67 #       define IMAGE_EXT        "png"
68 #endif
69
70 /* === M E T H O D S ======================================================= */
71
72 static Glib::RefPtr<Gdk::Pixbuf> _tree_pixbuf_table_value_type[(int)sinfg::ValueBase::TYPE_END];
73
74 IconControler::IconControler(const sinfg::String& basepath)
75 {
76         Gtk::IconSource icon_source;
77         icon_source.set_direction_wildcarded();
78         icon_source.set_state_wildcarded();
79         icon_source.set_size_wildcarded();
80         icon_factory=Gtk::IconFactory::create();
81
82         std::string path_to_icons;
83 #ifdef WIN32
84         path_to_icons=basepath+"/../"+IMAGE_DIR;
85 #else
86         path_to_icons=IMAGE_DIR;
87 #endif
88         path_to_icons+=ETL_DIRECTORY_SEPERATOR;
89
90         try{
91         Gtk::Window::set_default_icon_from_file(path_to_icons+"sinfg_icon."+IMAGE_EXT);
92         } catch(...)
93         {
94                 sinfg::warning("Unable to open "+path_to_icons+"sinfg_icon."+IMAGE_EXT);
95         }
96         
97 /*
98 #define INIT_STOCK_ICON(name,iconfile,desc)                                                     \
99         stock_##name=Gtk::StockItem(Gtk::StockID("sinfg-" #name),desc);                         \
100         Gtk::Stock::add(stock_##name);                                                          \
101         icon_source.set_filename(path_to_icons+iconfile);                                                       \
102         icon_##name.add_source(icon_source);                                            \
103         icon_factory->add(stock_##name.get_stock_id(),icon_##name)
104 */
105 #define INIT_STOCK_ICON(name,iconfile,desc){                                                    \
106         Gtk::StockItem stockitem(Gtk::StockID("sinfg-" #name),desc); \
107         Gtk::Stock::add(stockitem);                                                             \
108         Gtk::IconSet icon_set;                                                                  \
109         icon_source.set_filename(path_to_icons+iconfile);                                                       \
110         icon_set.add_source(icon_source);                                               \
111         icon_factory->add(stockitem.get_stock_id(),icon_set); \
112         }
113
114 #define INIT_STOCK_ICON_CLONE(name,stockid,desc){                                                       \
115         Gtk::StockItem stockitem(Gtk::StockID("sinfg-" #name),desc); \
116         Gtk::Stock::add(stockitem);                                                             \
117         Gtk::IconSet icon_set;                                                                  \
118         if(Gtk::Stock::lookup(stockitem.get_stock_id(),icon_set))       \
119         icon_factory->add(stockitem.get_stock_id(),icon_set); \
120         }
121
122 #define INIT_STOCK_ITEM(name,desc)                                                      \
123         stock_##name=Gtk::StockItem(Gtk::StockID("sinfg-" #name),desc);                         \
124         Gtk::Stock::add(stock_##name);                                                          
125
126         INIT_STOCK_ICON(swap_colors,"swap_colors_icon."IMAGE_EXT,_("Swap Colors"));
127         INIT_STOCK_ICON(canvas,"canvas_icon."IMAGE_EXT,_("Canvas"));
128         INIT_STOCK_ICON(value_node,"valuenode_icon."IMAGE_EXT,_("ValueNode"));
129         INIT_STOCK_ICON(real,"real_icon."IMAGE_EXT,_("Real"));
130         INIT_STOCK_ICON(integer,"integer_icon."IMAGE_EXT,_("Integer"));
131         INIT_STOCK_ICON(vector,"vector_icon."IMAGE_EXT,_("Vector"));
132         INIT_STOCK_ICON(color,"color_icon."IMAGE_EXT,_("Color"));
133         INIT_STOCK_ICON(angle,"angle_icon."IMAGE_EXT,_("Angle"));
134         INIT_STOCK_ICON(segment,"segment_icon."IMAGE_EXT,_("Segment"));
135         INIT_STOCK_ICON(about,"about_icon."IMAGE_EXT,_("About"));
136         INIT_STOCK_ICON(rename,"rename_icon."IMAGE_EXT,_("Rename"));
137         INIT_STOCK_ICON(list,"list_icon."IMAGE_EXT,_("Rename"));
138         INIT_STOCK_ICON(canvas_pointer,"canvas_pointer_icon."IMAGE_EXT,_("Rename"));
139         INIT_STOCK_ICON(string,"string_icon."IMAGE_EXT,_("Rename"));
140         INIT_STOCK_ICON(canvas_new,"canvas_icon."IMAGE_EXT,_("New Canvas"));
141         INIT_STOCK_ICON(saveall,"saveall_icon."IMAGE_EXT,_("Save All"));
142         INIT_STOCK_ICON(bool,"bool_icon."IMAGE_EXT,_("Bool"));
143         INIT_STOCK_ICON(layer,"layer_icon."IMAGE_EXT,_("Layer"));
144         INIT_STOCK_ICON(layer_pastecanvas,"pastecanvas_icon."IMAGE_EXT,_("PasteCanvas"));
145         INIT_STOCK_ICON(group,"group_icon."IMAGE_EXT,_("Group"));
146         INIT_STOCK_ICON(grid_enable,"grid_enable_icon."IMAGE_EXT,_("Show Grid"));
147         INIT_STOCK_ICON(grid_disable,"grid_disable_icon."IMAGE_EXT,_("Hide Grid"));
148         INIT_STOCK_ICON(grid_snap_enable,"grid_snap_enable_icon."IMAGE_EXT,_("Enable Grid Snap"));
149         INIT_STOCK_ICON(grid_snap_disable,"grid_snap_disable_icon."IMAGE_EXT,_("Disable Grid Snap"));
150         INIT_STOCK_ICON(duplicate,"duplicate_icon."IMAGE_EXT,_("Duplicate"));
151         INIT_STOCK_ICON(gradient,"gradient_icon."IMAGE_EXT,_("Gradient"));
152         INIT_STOCK_ICON(blinepoint,"blinepoint_icon."IMAGE_EXT,_("BLine Point"));
153
154         INIT_STOCK_ICON(clear_undo,"clear_undo_icon."IMAGE_EXT,_("Clear Undo Stack"));
155         INIT_STOCK_ICON(clear_redo,"clear_redo_icon."IMAGE_EXT,_("Clear Redo Stack"));
156
157         INIT_STOCK_ICON(children,"children_icon."IMAGE_EXT,_("Children"));
158         INIT_STOCK_ICON(keyframes,"keyframe_icon."IMAGE_EXT,_("Keyframes"));
159         INIT_STOCK_ICON(meta_data,"meta_data_icon."IMAGE_EXT,_("MetaData"));
160         INIT_STOCK_ICON(navigator,"navigator_icon."IMAGE_EXT,_("Navigator"));
161         INIT_STOCK_ICON(timetrack,"time_track_icon."IMAGE_EXT,_("Time Track"));
162
163         INIT_STOCK_ICON(keyframe_lock_all,"keyframe_lock_all."IMAGE_EXT,_("All Keyframes Locked"));
164         INIT_STOCK_ICON(keyframe_lock_past,"keyframe_lock_past."IMAGE_EXT,_("Past Keyframes Locked"));
165         INIT_STOCK_ICON(keyframe_lock_future,"keyframe_lock_future."IMAGE_EXT,_("Future Keyframes Locked"));
166         INIT_STOCK_ICON(keyframe_lock_none,"keyframe_lock_none."IMAGE_EXT,_("No Keyframes Locked"));
167
168         INIT_STOCK_ICON_CLONE(cvs_add,"gtk-add",_("CVS Add"));
169         INIT_STOCK_ICON_CLONE(cvs_update,"gtk-open",_("CVS Update"));
170         INIT_STOCK_ICON_CLONE(cvs_commit,"gtk-save",_("CVS Commit"));
171         INIT_STOCK_ICON_CLONE(cvs_revert,"gtk-revert",_("CVS Revert"));
172
173         // Tools
174         INIT_STOCK_ICON(normal,"normal_icon."IMAGE_EXT,_("Normal Tool"));
175         INIT_STOCK_ICON(polygon,"polygon_icon."IMAGE_EXT,_("Polygon Tool"));
176         INIT_STOCK_ICON(bline,"bline_icon."IMAGE_EXT,_("BLine Tool"));
177         INIT_STOCK_ICON(eyedrop,"eyedrop_icon."IMAGE_EXT,_("Eyedrop Tool"));
178         INIT_STOCK_ICON(fill,"fill_icon."IMAGE_EXT,_("Fill Tool"));
179         INIT_STOCK_ICON(draw,"draw_icon."IMAGE_EXT,_("Draw Tool"));
180         INIT_STOCK_ICON(sketch,"sketch_icon."IMAGE_EXT,_("Sketch Tool"));
181         INIT_STOCK_ICON(circle,"circle_icon."IMAGE_EXT,_("Circle Tool"));
182         INIT_STOCK_ICON(rectangle,"rectangle_icon."IMAGE_EXT,_("Rectangle Tool"));
183         INIT_STOCK_ICON(smooth_move,"smooth_move_icon."IMAGE_EXT,_("SmoothMove Tool"));
184         INIT_STOCK_ICON(scale,"scale_icon."IMAGE_EXT,_("Scale Tool"));
185         INIT_STOCK_ICON(width,"width_icon."IMAGE_EXT,_("Width Tool"));
186         INIT_STOCK_ICON(rotate,"rotate_icon."IMAGE_EXT,_("Rotate Tool"));
187         INIT_STOCK_ICON(zoom,"zoom_icon."IMAGE_EXT,_("Zoom Tool"));
188         INIT_STOCK_ICON(info,"info_icon."IMAGE_EXT,_("Info Tool"));
189         INIT_STOCK_ICON(mirror,"mirror_icon."IMAGE_EXT,_("Mirror Tool"));
190
191         icon_factory->add_default();
192         
193         Gtk::IconSize::register_new("sinfg-small_icon",12,12);
194         for(int i(0);i<(int)ValueBase::TYPE_END;i++)
195                 _tree_pixbuf_table_value_type[i]=Gtk::Button().render_icon(value_icon(ValueBase::Type(i)),Gtk::ICON_SIZE_SMALL_TOOLBAR);
196
197 }
198
199 IconControler::~IconControler()
200 {
201         for(int i(0);i<(int)ValueBase::TYPE_END;i++)
202                 _tree_pixbuf_table_value_type[i]=Glib::RefPtr<Gdk::Pixbuf>();
203
204         icon_factory->remove_default();
205 }
206
207 Gdk::Cursor
208 IconControler::get_normal_cursor()
209 {
210         return Gdk::Cursor(Gdk::TOP_LEFT_ARROW);
211 }
212
213 Gdk::Cursor
214 IconControler::get_tool_cursor(const Glib::ustring& name,const Glib::RefPtr<Gdk::Window>& window)
215 {
216         Glib::RefPtr<Gdk::Pixmap> pixmap;
217         DEBUGPOINT();
218         pixmap=Gdk::Pixmap::create(window, 64, 64, 8);
219         DEBUGPOINT();
220         pixmap->set_colormap(window->get_colormap());
221         //pixmap->set_colormap(Gdk::Colormap::create(pixmap->get_visual(),false));
222         DEBUGPOINT();
223         Glib::RefPtr<Gdk::Pixbuf> pixbuf;
224         DEBUGPOINT();
225         pixbuf=Gtk::Button().render_icon(Gtk::StockID("sinfg-"+name),Gtk::ICON_SIZE_SMALL_TOOLBAR);
226         DEBUGPOINT();
227
228         pixbuf->render_to_drawable_alpha(
229                 pixmap,
230                 0,0,    // SOURCE X,Y
231                 0,0,    // DEST X Y
232                 -1,-1,  // WIDTH HEIGHT
233                 Gdk::PIXBUF_ALPHA_FULL, // (ignored)
234                 64,             //int alpha_threshold,
235                 Gdk::RGB_DITHER_MAX,            //RgbDither dither,
236                 2,2     //int x_dither, int y_dither
237         );
238 /*
239         pixmap->draw_pixbuf(
240                 Glib::RefPtr<const Gdk::GC>(0), // GC
241                 pixbuf,
242                 0, 0, // Source X,Y
243                 0, 0, // Dest X,Y
244                 -1, -1, // Width, Height
245                 Gdk::RGB_DITHER_MAX, // Dither
246                 0,0 // Dither X,Y
247         );
248 */
249         DEBUGPOINT();
250         
251         Gdk::Color FG("#000000");
252         Gdk::Color BG("#FF00FF");
253         
254         DEBUGPOINT();
255         return Gdk::Cursor(pixmap, pixmap, FG, BG, 0, 0);
256 }
257
258 Gtk::StockID
259 studio::value_icon(sinfg::ValueBase::Type type)
260 {
261                 switch(type)
262                 {
263                 case ValueBase::TYPE_REAL:
264                         return Gtk::StockID("sinfg-real");
265                         break;
266                 case ValueBase::TYPE_INTEGER:
267                         return Gtk::StockID("sinfg-integer");
268                         break;
269                 case ValueBase::TYPE_BOOL:
270                         return Gtk::StockID("sinfg-bool");
271                         break;
272                 case ValueBase::TYPE_ANGLE:
273                         return Gtk::StockID("sinfg-angle");
274                         break;
275                 case ValueBase::TYPE_VECTOR:
276                         return Gtk::StockID("sinfg-vector");
277                         break;
278                 case ValueBase::TYPE_COLOR:
279                         return Gtk::StockID("sinfg-color");
280                         break;
281                 case ValueBase::TYPE_STRING:
282                         return Gtk::StockID("sinfg-string");
283                         break;
284                 case ValueBase::TYPE_CANVAS:
285                         return Gtk::StockID("sinfg-canvas_pointer");
286                         break;
287                 case ValueBase::TYPE_LIST:
288                         return Gtk::StockID("sinfg-list");
289                         break;
290                 case ValueBase::TYPE_SEGMENT:
291                         return Gtk::StockID("sinfg-segment");
292                         break;
293                 case ValueBase::TYPE_GRADIENT:
294                         return Gtk::StockID("sinfg-gradient");
295                         break;
296                 case ValueBase::TYPE_BLINEPOINT:
297                         return Gtk::StockID("sinfg-blinepoint");
298                         break;
299                 case ValueBase::TYPE_NIL:
300                 default:
301                         return Gtk::StockID("sinfg-unknown");
302                         break;
303                 }
304 }
305
306 Gtk::StockID
307 studio::valuenode_icon(etl::handle<sinfg::ValueNode> value_node)
308 {
309         if(handle<ValueNode_Const>::cast_dynamic(value_node))
310         {
311                 return value_icon(value_node->get_type());
312         }
313         else
314         {
315                 return Gtk::StockID("sinfg-value_node");                
316         }
317 }
318
319 Glib::RefPtr<Gdk::Pixbuf>
320 studio::get_tree_pixbuf(sinfg::ValueBase::Type type)
321 {
322         //return Gtk::Button().render_icon(value_icon(type),Gtk::ICON_SIZE_SMALL_TOOLBAR);
323         return _tree_pixbuf_table_value_type[int(type)];
324 }
325
326 Gtk::StockID
327 studio::get_action_stock_id(const sinfgapp::Action::BookEntry& action)
328 {
329         Gtk::StockID stock_id;
330         if(action.task=="raise")                        stock_id=Gtk::Stock::GO_UP;
331         else if(action.task=="lower")           stock_id=Gtk::Stock::GO_DOWN;
332         else if(action.task=="add")                     stock_id=Gtk::Stock::ADD;
333         else if(action.task=="insert")          stock_id=Gtk::Stock::ADD;
334         else if(action.task=="move_top")        stock_id=Gtk::Stock::GOTO_TOP;
335         else if(action.task=="move_bottom")     stock_id=Gtk::Stock::GOTO_BOTTOM;
336         else if(action.task=="remove")          stock_id=Gtk::Stock::DELETE;
337         else if(action.task=="set_on")          stock_id=Gtk::Stock::YES;
338         else if(action.task=="set_off")         stock_id=Gtk::Stock::NO;
339         else if(action.task=="remove")          stock_id=Gtk::Stock::DELETE;
340         else                                                            stock_id=Gtk::StockID("sinfg-"+action.task);
341         
342         return stock_id;
343 }
344
345 Gtk::StockID
346 studio::layer_icon(const sinfg::String &layer)
347 {
348         if(layer=="PasteCanvas" || layer=="pastecanvas")
349                 return Gtk::StockID("sinfg-layer_pastecanvas");
350         else if(layer=="rotate")
351                 return Gtk::StockID("sinfg-rotate");
352         else if(layer=="zoom")
353                 return Gtk::StockID("sinfg-zoom");
354         else if(layer=="region")
355                 return Gtk::StockID("sinfg-bline");
356         else if(layer=="polygon")
357                 return Gtk::StockID("sinfg-polygon");
358         else if(layer=="outline")
359                 return Gtk::StockID("sinfg-width");
360         else if(layer=="circle")
361                 return Gtk::StockID("sinfg-circle");
362         else if(layer=="rectangle")
363                 return Gtk::StockID("sinfg-rectangle");
364         else if(layer.find("gradient")!=String::npos)
365                 return Gtk::StockID("sinfg-gradient");
366         else
367                 return Gtk::StockID("sinfg-layer");
368 }
369
370 Glib::RefPtr<Gdk::Pixbuf>
371 studio::get_tree_pixbuf_layer(const sinfg::String &layer)
372 {
373         return Gtk::Button().render_icon(layer_icon(layer),Gtk::ICON_SIZE_SMALL_TOOLBAR);
374 }