New panel icons. Patch by Yu Chen (jcome)
[synfig.git] / synfig-studio / src / gui / iconcontroller.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file iconcontroller.cpp
3 **      \brief Template File
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **      Copyright (c) 2007, 2008 Chris Moore
10 **  Copyright (c) 2008 Paul Wise
11 **  Copyright (c) 2009 Gerco Ballintijn
12 **      Copyright (c) 2009 Carlos López
13 **      Copyright (c) 2009 Nikita Kitaev
14 **
15 **      This package is free software; you can redistribute it and/or
16 **      modify it under the terms of the GNU General Public License as
17 **      published by the Free Software Foundation; either version 2 of
18 **      the License, or (at your option) any later version.
19 **
20 **      This package is distributed in the hope that it will be useful,
21 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
22 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 **      General Public License for more details.
24 **      \endlegal
25 */
26 /* ========================================================================= */
27
28 /* === H E A D E R S ======================================================= */
29
30 #ifdef USING_PCH
31 #       include "pch.h"
32 #else
33 #ifdef HAVE_CONFIG_H
34 #       include <config.h>
35 #endif
36
37 #include "iconcontroller.h"
38 #include <synfig/valuenode_const.h>
39 #include <gtkmm/button.h>
40 #include <gtkmm/window.h>
41 #include <synfigapp/action.h>
42
43 #include "general.h"
44
45 #endif
46
47 /* === U S I N G =========================================================== */
48
49 using namespace etl;
50 using namespace std;
51 using namespace studio;
52 using namespace synfig;
53
54 /* === M A C R O S ========================================================= */
55
56 #ifdef WIN32
57 #       ifdef IMAGE_DIR
58 #               undef IMAGE_DIR
59 #               define IMAGE_DIR "share\\pixmaps"
60 #       endif
61 #endif
62
63 #ifndef IMAGE_DIR
64 #       define IMAGE_DIR "/usr/local/share/pixmaps"
65 #endif
66
67
68 #ifndef IMAGE_EXT
69 #       define IMAGE_EXT        "png"
70 #endif
71
72 /* === M E T H O D S ======================================================= */
73
74 static Glib::RefPtr<Gdk::Pixbuf> _tree_pixbuf_table_value_type[(int)synfig::ValueBase::TYPE_END];
75
76 #ifdef WIN32
77 IconController::IconController(const synfig::String& basepath)
78 #else
79 IconController::IconController(const synfig::String& /*basepath*/)
80 #endif
81 {
82         Gtk::IconSource icon_source;
83         icon_source.set_direction_wildcarded();
84         icon_source.set_state_wildcarded();
85         icon_source.set_size_wildcarded();
86         icon_factory=Gtk::IconFactory::create();
87
88         std::string path_to_icons;
89 #ifdef WIN32
90         path_to_icons=basepath+ETL_DIRECTORY_SEPARATOR+".."+ETL_DIRECTORY_SEPARATOR+IMAGE_DIR;
91 #else
92         path_to_icons=IMAGE_DIR;
93 #endif
94
95         char* synfig_root=getenv("SYNFIG_ROOT");
96         if(synfig_root) {
97                 path_to_icons=synfig_root;
98                 path_to_icons+=ETL_DIRECTORY_SEPARATOR;
99                 path_to_icons+="share";
100                 path_to_icons+=ETL_DIRECTORY_SEPARATOR;
101                 path_to_icons+="pixmaps";
102                 path_to_icons+=ETL_DIRECTORY_SEPARATOR;
103                 path_to_icons+="synfigstudio";
104         }
105         path_to_icons+=ETL_DIRECTORY_SEPARATOR;
106
107         try{
108         Gtk::Window::set_default_icon_from_file(path_to_icons+"synfig_icon."+IMAGE_EXT);
109         } catch(...)
110         {
111                 synfig::warning("Unable to open "+path_to_icons+"synfig_icon."+IMAGE_EXT);
112         }
113
114 #define INIT_STOCK_ICON(name,iconfile,desc){                                                    \
115         Gtk::StockItem stockitem(Gtk::StockID("synfig-" #name),desc); \
116         Gtk::Stock::add(stockitem);                                                             \
117         Gtk::IconSet icon_set;                                                                  \
118         icon_source.set_filename(path_to_icons+iconfile);                                                       \
119         icon_set.add_source(icon_source);                                               \
120         icon_factory->add(stockitem.get_stock_id(),icon_set); \
121         }
122
123 #define INIT_STOCK_ICON_CLONE(name,stockid,desc){                                                       \
124         Gtk::StockItem stockitem(Gtk::StockID("synfig-" #name),desc); \
125         Gtk::Stock::add(stockitem);                                                             \
126         Gtk::IconSet icon_set;                                                                  \
127         if(Gtk::Stock::lookup(stockitem.get_stock_id(),icon_set))       \
128         icon_factory->add(stockitem.get_stock_id(),icon_set); \
129         }
130
131 #define INIT_STOCK_ITEM(name,desc)                                                      \
132         stock_##name=Gtk::StockItem(Gtk::StockID("synfig-" #name),desc);                        \
133         Gtk::Stock::add(stock_##name);
134
135         // Types
136         INIT_STOCK_ICON(type_bool,"type_bool_icon."IMAGE_EXT,_("Bool"));
137         INIT_STOCK_ICON(type_integer,"type_integer_icon."IMAGE_EXT,_("Integer"));
138         INIT_STOCK_ICON(type_angle,"type_angle_icon."IMAGE_EXT,_("Angle"));
139         INIT_STOCK_ICON(type_time,"type_time_icon."IMAGE_EXT,_("Time"));
140         INIT_STOCK_ICON(type_real,"type_real_icon."IMAGE_EXT,_("Real"));
141         INIT_STOCK_ICON(type_vector,"type_vector_icon."IMAGE_EXT,_("Vector"));
142         INIT_STOCK_ICON(type_color,"type_color_icon."IMAGE_EXT,_("Color"));
143         INIT_STOCK_ICON(type_segment,"type_segment_icon."IMAGE_EXT,_("Segment"));
144         INIT_STOCK_ICON(type_blinepoint,"type_blinepoint_icon."IMAGE_EXT,_("BLine Point"));
145         INIT_STOCK_ICON(type_list,"type_list_icon."IMAGE_EXT,_("List"));
146         INIT_STOCK_ICON(type_string,"type_string_icon."IMAGE_EXT,_("String"));
147         INIT_STOCK_ICON(type_canvas,"type_canvas_icon."IMAGE_EXT,_("Canvas"));
148         INIT_STOCK_ICON(type_gradient,"type_gradient_icon."IMAGE_EXT,_("Gradient"))
149
150         // ToolBox Tools
151         INIT_STOCK_ICON(normal,"tool_normal_icon."IMAGE_EXT,_("Transform Tool"));
152         INIT_STOCK_ICON(polygon,"tool_polyline_icon."IMAGE_EXT,_("Polygon Tool"));
153         INIT_STOCK_ICON(bline,"tool_bline_icon."IMAGE_EXT,_("BLine Tool"));
154         INIT_STOCK_ICON(eyedrop,"tool_eyedrop_icon."IMAGE_EXT,_("Eyedrop Tool"));
155         INIT_STOCK_ICON(fill,"tool_fill_icon."IMAGE_EXT,_("Fill Tool"));
156         INIT_STOCK_ICON(draw,"tool_draw_icon."IMAGE_EXT,_("Draw Tool"));
157         INIT_STOCK_ICON(sketch,"tool_sketch_icon."IMAGE_EXT,_("Sketch Tool"));
158         INIT_STOCK_ICON(circle,"tool_circle_icon."IMAGE_EXT,_("Circle Tool"));
159         INIT_STOCK_ICON(rectangle,"tool_rectangle_icon."IMAGE_EXT,_("Rectangle Tool"));
160         INIT_STOCK_ICON(smooth_move,"tool_smooth_move_icon."IMAGE_EXT,_("SmoothMove Tool"));
161         INIT_STOCK_ICON(rotate,"tool_rotate_icon."IMAGE_EXT,"Rotate Tool");
162         INIT_STOCK_ICON(width,"tool_width_icon."IMAGE_EXT,_("Width Tool"));
163         INIT_STOCK_ICON(scale,"tool_scale_icon."IMAGE_EXT,"Scale Tool");
164         INIT_STOCK_ICON(zoom,"tool_zoom_icon."IMAGE_EXT,_("Zoom Tool"));
165         INIT_STOCK_ICON(mirror,"tool_mirror_icon."IMAGE_EXT,_("Mirror Tool"));
166         INIT_STOCK_ICON(text,"tool_text_icon."IMAGE_EXT,"Text Tool");
167         INIT_STOCK_ICON(gradient,"tool_gradient_icon."IMAGE_EXT,_("Gradient Tool"));
168         INIT_STOCK_ICON(star,"tool_star_icon."IMAGE_EXT,_("Star Tool"));
169         //ToolBox Others
170         INIT_STOCK_ICON(reset_colors,"reset_colors_icon."IMAGE_EXT,_("Reset Colors"));
171         INIT_STOCK_ICON(swap_colors,"swap_colors_icon."IMAGE_EXT,_("Swap Colors"));
172         INIT_STOCK_ICON(value_node,"valuenode_icon."IMAGE_EXT,_("ValueNode"));
173         INIT_STOCK_ICON(about,"about_icon."IMAGE_EXT,_("About"));
174         INIT_STOCK_ICON(rename,"rename_icon."IMAGE_EXT,_("Rename"));
175         INIT_STOCK_ICON(canvas,"canvas_icon."IMAGE_EXT,_("Canvas"));
176         INIT_STOCK_ICON(canvas_new,"canvas_icon."IMAGE_EXT,_("New Canvas"));
177         INIT_STOCK_ICON(saveall,"saveall_icon."IMAGE_EXT,_("Save All"));
178
179         // Layers
180         INIT_STOCK_ICON(layer,"layer_icon."IMAGE_EXT,_("Layer"));
181         // Blur Layers
182         INIT_STOCK_ICON(layer_blur_blur,"layer_blur_blur_icon."IMAGE_EXT,_("Blur Layer"));
183         INIT_STOCK_ICON(layer_blur_motion,"layer_blur_motion_icon."IMAGE_EXT,_("Motion Blur Layer"));
184         INIT_STOCK_ICON(layer_blur_radial,"layer_blur_radial_icon."IMAGE_EXT,_("Radial Blur Layer"));
185         // Distortion Layers
186         INIT_STOCK_ICON(layer_distortion_curvewarp,"layer_distortion_curvewarp_icon."IMAGE_EXT,_("Curve Warp Layer"));
187         INIT_STOCK_ICON(layer_distortion_insideout,"layer_distortion_insideout_icon."IMAGE_EXT,_("Inside Out Layer"));
188         INIT_STOCK_ICON(layer_distortion_noise,"layer_distortion_noise_icon."IMAGE_EXT,_("Noise Distort Layer"));
189         INIT_STOCK_ICON(layer_distortion_spherize,"layer_distortion_spherize_icon."IMAGE_EXT,_("Spherize Layer"));
190         INIT_STOCK_ICON(layer_distortion_stretch,"layer_distortion_stretch_icon."IMAGE_EXT,_("Stretch Layer"));
191         INIT_STOCK_ICON(layer_distortion_twirl,"layer_distortion_twirl_icon."IMAGE_EXT,_("Twirl Layer"));
192         INIT_STOCK_ICON(layer_distortion_warp,"layer_distortion_warp_icon."IMAGE_EXT,_("Warp Layer"));
193         // Example Layers
194         INIT_STOCK_ICON(layer_example_filledrectangle,"layer_example_filledrectangle_icon."IMAGE_EXT,_("Filled Rectangle Layer"));
195         INIT_STOCK_ICON(layer_example_metaballs,"layer_example_metaballs_icon."IMAGE_EXT,_("Metallballs Layer"));
196         INIT_STOCK_ICON(layer_example_simplecircle,"layer_example_simplecircle_icon."IMAGE_EXT,_("Simple Circle Layer"));
197         // Filter Layers
198         INIT_STOCK_ICON(layer_filter_clamp,"layer_filter_clamp_icon."IMAGE_EXT,_("Clamp Layer"));
199         INIT_STOCK_ICON(layer_filter_colorcorrect,"layer_filter_colorcorrect_icon."IMAGE_EXT,_("Color Correct Layer"));
200         INIT_STOCK_ICON(layer_filter_halftone2,"layer_filter_halftone2_icon."IMAGE_EXT,_("Halftone 2 Layer"));
201         INIT_STOCK_ICON(layer_filter_halftone3,"layer_filter_halftone3_icon."IMAGE_EXT,_("Halftone 3 Layer"));
202         INIT_STOCK_ICON(layer_filter_lumakey,"layer_filter_lumakey_icon."IMAGE_EXT,_("Luna Key Layer"));
203         // Fractal Layers
204         INIT_STOCK_ICON(layer_fractal_julia,"layer_fractal_julia_icon."IMAGE_EXT,_("Julia Set Layer"));
205         INIT_STOCK_ICON(layer_fractal_mandelbrot,"layer_fractal_mandelbrot_icon."IMAGE_EXT,_("Mandelbrot Set Layer"));
206         // Geometry Layers
207         INIT_STOCK_ICON(layer_geometry_checkerboard,"layer_geometry_checkerboard_icon."IMAGE_EXT,_("Checker Board Layer"));
208         INIT_STOCK_ICON(layer_geometry_circle,"layer_geometry_circle_icon."IMAGE_EXT,_("Circle Layer"));
209         INIT_STOCK_ICON(layer_geometry_outline,"layer_geometry_outline_icon."IMAGE_EXT,_("Outline Layer"));
210         INIT_STOCK_ICON(layer_geometry_polygon,"layer_geometry_polygon_icon."IMAGE_EXT,_("Polygon Layer"));
211         INIT_STOCK_ICON(layer_geometry_rectangle,"layer_geometry_rectangle_icon."IMAGE_EXT,_("Rectangle Layer"));
212         INIT_STOCK_ICON(layer_geometry_region,"layer_geometry_region_icon."IMAGE_EXT,_("Region Layer"));
213         INIT_STOCK_ICON(layer_geometry_solidcolor,"layer_geometry_solidcolor_icon."IMAGE_EXT,_("Solid Color Layer"));
214         INIT_STOCK_ICON(layer_geometry_star,"layer_geometry_star_icon."IMAGE_EXT,_("Star Layer"));
215         // Gradient Layers
216         INIT_STOCK_ICON(layer_gradient_conical,"layer_gradient_conical_icon."IMAGE_EXT,_("Conical Gradient Layer"));
217         INIT_STOCK_ICON(layer_gradient_curve,"layer_gradient_curve_icon."IMAGE_EXT,_("Curve Gradient Layer"));
218         INIT_STOCK_ICON(layer_gradient_noise,"layer_gradient_noise_icon."IMAGE_EXT,_("Noise Gradient Layer"));
219         INIT_STOCK_ICON(layer_gradient_lineal,"layer_gradient_lineal_icon."IMAGE_EXT,_("Linear Gradient Layer"));
220         INIT_STOCK_ICON(layer_gradient_radial,"layer_gradient_radial_icon."IMAGE_EXT,_("Radial Gradient Layer"));
221         INIT_STOCK_ICON(layer_gradient_spiral,"layer_gradient_spiral_icon."IMAGE_EXT,_("Spiral Gradient Layer"));
222         // Other Layers
223         INIT_STOCK_ICON(layer_other_duplicate,"layer_other_duplicate_icon."IMAGE_EXT,_("Duplicate Layer"));
224         INIT_STOCK_ICON(layer_other_importimage,"layer_other_importimage_icon."IMAGE_EXT,_("Import Image Layer"));
225         INIT_STOCK_ICON(layer_other_pastecanvas,"layer_other_pastecanvas_icon."IMAGE_EXT,_("Paste Canvas Layer"));
226         INIT_STOCK_ICON(layer_other_plant,"layer_other_plant_icon."IMAGE_EXT,_("Plant Layer"));
227         INIT_STOCK_ICON(layer_other_supersample,"layer_other_supersample_icon."IMAGE_EXT,_("Super Sample Layer"));
228         INIT_STOCK_ICON(layer_other_text,"layer_other_text_icon."IMAGE_EXT,_("Text Layer"));
229         INIT_STOCK_ICON(layer_other_timeloop,"layer_other_timeloop_icon."IMAGE_EXT,_("Time Loop Layer"));
230         INIT_STOCK_ICON(layer_other_xorpattern,"layer_other_xorpattern_icon."IMAGE_EXT,_("XOR Pattern Layer"));
231         // Stylize Layers
232         INIT_STOCK_ICON(layer_stylize_bevel,"layer_stylize_bevel_icon."IMAGE_EXT,_("Bevel Layer"));
233         INIT_STOCK_ICON(layer_stylize_shade,"layer_stylize_shade_icon."IMAGE_EXT,_("Shade Layer"));
234         // Transform Layers
235         INIT_STOCK_ICON(layer_transform_rotate,"layer_transform_rotate_icon."IMAGE_EXT,_("Rotate Layer"));
236         INIT_STOCK_ICON(layer_transform_translate,"layer_transform_translate_icon."IMAGE_EXT,_("Translate Layer"));
237         INIT_STOCK_ICON(layer_transform_zoom,"layer_transform_zoom_icon."IMAGE_EXT,_("Zoom Layer"));
238
239         INIT_STOCK_ICON(plant,"plant_icon."IMAGE_EXT,"");
240
241         INIT_STOCK_ICON(info,"info_icon."IMAGE_EXT,_("Info Tool"));
242         INIT_STOCK_ICON(group,"group_icon."IMAGE_EXT,_("Group"));
243
244         INIT_STOCK_ICON(grid_enable,"grid_enable_icon."IMAGE_EXT,_("Show Grid"));
245         INIT_STOCK_ICON(grid_disable,"grid_disable_icon."IMAGE_EXT,_("Hide Grid"));
246         INIT_STOCK_ICON(grid_snap_enable,"grid_snap_enable_icon."IMAGE_EXT,_("Enable Grid Snap"));
247         INIT_STOCK_ICON(grid_snap_disable,"grid_snap_disable_icon."IMAGE_EXT,_("Disable Grid Snap"));
248         INIT_STOCK_ICON(duplicate,"duplicate_icon."IMAGE_EXT,_("Duplicate"));
249         INIT_STOCK_ICON(encapsulate,"encapsulate_icon."IMAGE_EXT,_("Encapsulate"));
250         INIT_STOCK_ICON(select_all_child_layers,"select_all_child_layers_icon."IMAGE_EXT,_("Select All Child Layers"));
251
252         INIT_STOCK_ICON(clear_undo,"clear_undo_icon."IMAGE_EXT,_("Clear Undo Stack"));
253         INIT_STOCK_ICON(clear_redo,"clear_redo_icon."IMAGE_EXT,_("Clear Redo Stack"));
254
255         INIT_STOCK_ICON(children,"children_icon."IMAGE_EXT,_("Children"));
256         INIT_STOCK_ICON(curves,"curves_icon."IMAGE_EXT,_("Curves"));
257         INIT_STOCK_ICON(keyframes,"keyframe_icon."IMAGE_EXT,_("Keyframes"));
258         INIT_STOCK_ICON(meta_data,"meta_data_icon."IMAGE_EXT,_("MetaData"));
259         INIT_STOCK_ICON(navigator,"navigator_icon."IMAGE_EXT,_("Navigator"));
260         INIT_STOCK_ICON(timetrack,"time_track_icon."IMAGE_EXT,_("Time Track"));
261         INIT_STOCK_ICON(history,"history_icon."IMAGE_EXT,_("History"));
262         INIT_STOCK_ICON(palette,"palette_icon."IMAGE_EXT,_("Palette"));
263         INIT_STOCK_ICON(params,"params_icon."IMAGE_EXT,_("Parameters"));
264
265         INIT_STOCK_ICON(keyframe_lock_all,"keyframe_lock_all."IMAGE_EXT,_("All Keyframes Locked"));
266         INIT_STOCK_ICON(keyframe_lock_past,"keyframe_lock_past."IMAGE_EXT,_("Past Keyframes Locked"));
267         INIT_STOCK_ICON(keyframe_lock_future,"keyframe_lock_future."IMAGE_EXT,_("Future Keyframes Locked"));
268         INIT_STOCK_ICON(keyframe_lock_none,"keyframe_lock_none."IMAGE_EXT,_("No Keyframes Locked"));
269
270         INIT_STOCK_ICON(set_outline_color,"set_outline_color."IMAGE_EXT,_("Set as Outline"));
271         INIT_STOCK_ICON(set_fill_color,"set_fill_color."IMAGE_EXT,_("Set as Fill"));
272
273         INIT_STOCK_ICON(seek_begin,"seek_begin."IMAGE_EXT,_("Seek to Begin"));
274         INIT_STOCK_ICON(seek_prev_frame,"seek_prev_frame."IMAGE_EXT,_("Previous Frame"));
275         INIT_STOCK_ICON(seek_next_frame,"seek_next_frame."IMAGE_EXT,_("Next Frame"));
276         INIT_STOCK_ICON(seek_end,"seek_end."IMAGE_EXT,_("Seek to End"));
277         INIT_STOCK_ICON(add_to_group,"action_add_to_group_icon."IMAGE_EXT,_("Add Layer to Group"));
278         INIT_STOCK_ICON(remove_from_group,"action_remove_from_group_icon."IMAGE_EXT,_("Remove Layer from Group"));
279         INIT_STOCK_ICON(set_desc,"action_set_layer_description_icon."IMAGE_EXT,_("Set Layer Description"));
280         INIT_STOCK_ICON(export,"action_export_icon."IMAGE_EXT,_("Export Value Node"));
281         INIT_STOCK_ICON(unexport,"action_unexport_icon."IMAGE_EXT,_("Unexport Value Node"));
282
283         INIT_STOCK_ICON(toggle_duck_position,"duck_position_icon."IMAGE_EXT,_("Toggle position ducks"));
284         INIT_STOCK_ICON(toggle_duck_vertex,"duck_vertex_icon."IMAGE_EXT,_("Toggle vertex ducks"));
285         INIT_STOCK_ICON(toggle_duck_tangent,"duck_tangent_icon."IMAGE_EXT,_("Toggle tangent ducks"));
286         INIT_STOCK_ICON(toggle_duck_radius,"duck_radius_icon."IMAGE_EXT,_("Toggle radius ducks"));
287         INIT_STOCK_ICON(toggle_duck_width,"duck_width_icon."IMAGE_EXT,_("Toggle width ducks"));
288         INIT_STOCK_ICON(toggle_duck_angle,"duck_angle_icon."IMAGE_EXT,_("Toggle angle ducks"));
289
290         INIT_STOCK_ICON(toggle_show_grid,"show_grid_icon."IMAGE_EXT,_("Toggle show grid"));
291         INIT_STOCK_ICON(toggle_snap_grid,"snap_grid_icon."IMAGE_EXT,_("Toggle snap grid"));
292
293         INIT_STOCK_ICON(toggle_onion_skin,"onion_skin_icon."IMAGE_EXT,_("Toggle onion skin"));
294
295         INIT_STOCK_ICON(increase_resolution,"incr_resolution_icon."IMAGE_EXT,_("Increase resolution"));
296         INIT_STOCK_ICON(decrease_resolution,"decr_resolution_icon."IMAGE_EXT,_("Decrease resolution"));
297
298         INIT_STOCK_ICON(preview_options,"preview_options_icon."IMAGE_EXT,_("Preview Options Dialog"));
299         INIT_STOCK_ICON(render_options,"render_options_icon."IMAGE_EXT,_("Render Options Dialog"));
300
301         INIT_STOCK_ICON_CLONE(cvs_add,"gtk-add",_("CVS Add"));
302         INIT_STOCK_ICON_CLONE(cvs_update,"gtk-open",_("CVS Update"));
303         INIT_STOCK_ICON_CLONE(cvs_commit,"gtk-save",_("CVS Commit"));
304         INIT_STOCK_ICON_CLONE(cvs_revert,"gtk-revert",_("CVS Revert"));
305
306 #undef INIT_STOCK_ICON
307 #undef INIT_STOCK_ICON_CLONE
308
309         icon_factory->add_default();
310
311         Gtk::IconSize::register_new("synfig-small_icon",12,12);
312         Gtk::IconSize::register_new("synfig-small_icon_16x16",16,16);
313
314         for(int i(0);i<(int)ValueBase::TYPE_END;i++)
315                 _tree_pixbuf_table_value_type[i]=Gtk::Button().render_icon(value_icon(ValueBase::Type(i)),Gtk::ICON_SIZE_SMALL_TOOLBAR);
316
317 }
318
319 IconController::~IconController()
320 {
321         for(int i(0);i<(int)ValueBase::TYPE_END;i++)
322                 _tree_pixbuf_table_value_type[i]=Glib::RefPtr<Gdk::Pixbuf>();
323
324         icon_factory->remove_default();
325 }
326
327 Gdk::Cursor
328 IconController::get_normal_cursor()
329 {
330         return Gdk::Cursor(Gdk::TOP_LEFT_ARROW);
331 }
332
333 Gdk::Cursor
334 IconController::get_tool_cursor(const Glib::ustring& name,const Glib::RefPtr<Gdk::Window>& window)
335 {
336         //this function is never called
337         //it is commented out in WorkArea::refresh_cursor()
338         assert(0);
339         // \todo Do we still need it?
340
341         Glib::RefPtr<Gdk::Pixmap> pixmap;
342         pixmap=Gdk::Pixmap::create(window, 64, 64, 8);
343         pixmap->set_colormap(window->get_colormap());
344         //pixmap->set_colormap(Gdk::Colormap::create(pixmap->get_visual(),false));
345         Glib::RefPtr<Gdk::Pixbuf> pixbuf;
346         pixbuf=Gtk::Button().render_icon(Gtk::StockID("synfig-"+name),Gtk::ICON_SIZE_SMALL_TOOLBAR);
347
348         pixbuf->render_to_drawable_alpha(
349                 pixmap,
350                 0,0,    // SOURCE X,Y
351                 0,0,    // DEST X Y
352                 -1,-1,  // WIDTH HEIGHT
353                 Gdk::PIXBUF_ALPHA_FULL, // (ignored)
354                 64,             //int alpha_threshold,
355                 Gdk::RGB_DITHER_MAX,            //RgbDither dither,
356                 2,2     //int x_dither, int y_dither
357         );
358 /*
359         pixmap->draw_pixbuf(
360                 Glib::RefPtr<const Gdk::GC>(0), // GC
361                 pixbuf,
362                 0, 0, // Source X,Y
363                 0, 0, // Dest X,Y
364                 -1, -1, // Width, Height
365                 Gdk::RGB_DITHER_MAX, // Dither
366                 0,0 // Dither X,Y
367         );
368 */
369
370         Gdk::Color FG("#000000");
371         Gdk::Color BG("#FF00FF");
372
373         return Gdk::Cursor(pixmap, pixmap, FG, BG, 0, 0);
374 }
375
376 Gtk::StockID
377 studio::value_icon(synfig::ValueBase::Type type)
378 {
379                 switch(type)
380                 {
381                 case ValueBase::TYPE_BOOL:
382                         return Gtk::StockID("synfig-type_bool");
383                         break;
384                 case ValueBase::TYPE_INTEGER:
385                         return Gtk::StockID("synfig-type_integer");
386                         break;
387                 case ValueBase::TYPE_ANGLE:
388                         return Gtk::StockID("synfig-type_angle");
389                         break;
390                 case ValueBase::TYPE_TIME:
391                         return Gtk::StockID("synfig-type_time");
392                         break;
393                 case ValueBase::TYPE_REAL:
394                         return Gtk::StockID("synfig-type_real");
395                         break;
396                 case ValueBase::TYPE_VECTOR:
397                         return Gtk::StockID("synfig-type_vector");
398                         break;
399                 case ValueBase::TYPE_COLOR:
400                         return Gtk::StockID("synfig-type_color");
401                         break;
402                 case ValueBase::TYPE_SEGMENT:
403                         return Gtk::StockID("synfig-type_segment");
404                         break;
405                 case ValueBase::TYPE_BLINEPOINT:
406                         return Gtk::StockID("synfig-type_blinepoint");
407                         break;
408                 case ValueBase::TYPE_LIST:
409                         return Gtk::StockID("synfig-type_list");
410                         break;
411                 case ValueBase::TYPE_CANVAS:
412                         return Gtk::StockID("synfig-type_canvas");
413                         break;
414                 case ValueBase::TYPE_STRING:
415                         return Gtk::StockID("synfig-type_string");
416                         break;
417                 case ValueBase::TYPE_GRADIENT:
418                         return Gtk::StockID("synfig-type_gradient");
419                         break;
420                 case ValueBase::TYPE_NIL:
421                 default:
422                         return Gtk::StockID("synfig-unknown");
423                         break;
424                 }
425 }
426
427 Gtk::StockID
428 studio::valuenode_icon(etl::handle<synfig::ValueNode> value_node)
429 {
430         if(handle<ValueNode_Const>::cast_dynamic(value_node))
431         {
432                 return value_icon(value_node->get_type());
433         }
434         else
435         {
436                 return Gtk::StockID("synfig-value_node");
437         }
438 }
439
440 Glib::RefPtr<Gdk::Pixbuf>
441 studio::get_tree_pixbuf(synfig::ValueBase::Type type)
442 {
443         //return Gtk::Button().render_icon(value_icon(type),Gtk::ICON_SIZE_SMALL_TOOLBAR);
444         return _tree_pixbuf_table_value_type[int(type)];
445 }
446
447 #ifdef WIN32
448 #define TEMPORARY_DELETE_MACRO DELETE
449 #undef DELETE
450 #endif
451
452 Gtk::StockID
453 studio::get_action_stock_id(const synfigapp::Action::BookEntry& action)
454 {
455         Gtk::StockID stock_id;
456         if(action.task=="add")                          stock_id=Gtk::Stock::ADD;
457         else if(action.task=="connect")         stock_id=Gtk::Stock::CONNECT;
458         else if(action.task=="disconnect")      stock_id=Gtk::Stock::DISCONNECT;
459         else if(action.task=="insert")          stock_id=Gtk::Stock::ADD;
460         else if(action.task=="lower")           stock_id=Gtk::Stock::GO_DOWN;
461         else if(action.task=="move_bottom")     stock_id=Gtk::Stock::GOTO_BOTTOM;
462         else if(action.task=="move_top")        stock_id=Gtk::Stock::GOTO_TOP;
463         else if(action.task=="raise")           stock_id=Gtk::Stock::GO_UP;
464         else if(action.task=="remove")          stock_id=Gtk::Stock::DELETE;
465         else if(action.task=="set_off")         stock_id=Gtk::Stock::NO;
466         else if(action.task=="set_on")          stock_id=Gtk::Stock::YES;
467         else                                                            stock_id=Gtk::StockID("synfig-"+
468                                                                                                                           action.task);
469         return stock_id;
470 }
471
472 #ifdef WIN32
473 #define DELETE TEMPORARY_DELETE_MACRO
474 #undef TEMPORARY_DELETE_MACRO
475 #endif
476
477 Gtk::StockID
478 studio::layer_icon(const synfig::String &layer)
479 {
480         // Blur Layers
481         if(layer=="blur")
482                 return Gtk::StockID("synfig-layer_blur_blur");
483         else if(layer=="MotionBlur") // in the future should be "motion_blur"
484                 return Gtk::StockID("synfig-layer_blur_motion");
485         else if(layer=="radial_blur")
486                 return Gtk::StockID("synfig-layer_blur_radial");
487         // Distortion Layers
488         else if(layer=="curve_warp")
489                 return Gtk::StockID("synfig-layer_distortion_curvewarp");
490         else if(layer=="inside_out")
491                 return Gtk::StockID("synfig-layer_distortion_insideout");
492         else if(layer=="noise_distort")
493                 return Gtk::StockID("synfig-layer_distortion_noise");
494         else if(layer=="spherize")
495                 return Gtk::StockID("synfig-layer_distortion_spherize");
496         else if(layer=="stretch")
497                 return Gtk::StockID("synfig-layer_distortion_stretch");
498         else if(layer=="twirl")
499                 return Gtk::StockID("synfig-layer_distortion_twirl");
500         else if(layer=="warp")
501                 return Gtk::StockID("synfig-layer_distortion_warp");
502         // Example Layers
503         else if(layer=="filled_rectangle")
504                 return Gtk::StockID("synfig-layer_example_filledrectangle");
505         else if(layer=="metaballs")
506                 return Gtk::StockID("synfig-layer_example_metaballs");
507         else if(layer=="simple_circle")
508                 return Gtk::StockID("synfig-layer_example_simplecircle");
509         // Filter Layers
510         else if(layer=="clamp")
511                 return Gtk::StockID("synfig-layer_filter_clamp");
512         else if(layer=="colorcorrect")
513                 return Gtk::StockID("synfig-layer_filter_colorcorrect");
514         else if(layer=="halftone2")
515                 return Gtk::StockID("synfig-layer_filter_halftone2");
516         else if(layer=="halftone3")
517                 return Gtk::StockID("synfig-layer_filter_halftone3");
518         else if(layer=="lumakey")
519                 return Gtk::StockID("synfig-layer_filter_lumakey");
520         // Fractal Layers
521         else if(layer=="mandelbrot")
522                 return Gtk::StockID("synfig-layer_fractal_mandelbrot");
523         else if(layer=="julia")
524                 return Gtk::StockID("synfig-layer_fractal_julia");
525         // Geometry Layers
526         else if(layer=="checker_board")
527                 return Gtk::StockID("synfig-layer_geometry_checkerboard");
528         else if(layer=="circle")
529                 return Gtk::StockID("synfig-layer_geometry_circle");
530         else if(layer=="outline")
531                 return Gtk::StockID("synfig-layer_geometry_outline");
532         else if(layer=="polygon")
533                 return Gtk::StockID("synfig-layer_geometry_polygon");
534         else if(layer=="rectangle")
535                 return Gtk::StockID("synfig-layer_geometry_rectangle");
536         else if(layer=="region")
537                 return Gtk::StockID("synfig-layer_geometry_region");
538         else if(layer=="solid_color" || layer=="SolidColor")
539                 return Gtk::StockID("synfig-layer_geometry_solidcolor");
540         else if(layer=="star")
541                 return Gtk::StockID("synfig-layer_geometry_star");
542         // Gradient Layers
543         else if(layer=="conical_gradient")
544                 return Gtk::StockID("synfig-layer_gradient_conical");
545         else if(layer=="curve_gradient")
546                 return Gtk::StockID("synfig-layer_gradient_curve");
547         else if(layer=="noise")
548                 return Gtk::StockID("synfig-layer_gradient_noise");
549         else if(layer=="linear_gradient")
550                 return Gtk::StockID("synfig-layer_gradient_lineal");
551         else if(layer=="radial_gradient")
552                 return Gtk::StockID("synfig-layer_gradient_radial");
553         else if(layer=="spiral_gradient")
554                 return Gtk::StockID("synfig-layer_gradient_spiral");
555         // Other Layers
556         else if(layer=="duplicate")
557                 return Gtk::StockID("synfig-layer_other_duplicate");
558         else if(layer=="importimage" || layer=="import")
559                 return Gtk::StockID("synfig-layer_other_importimage");
560         else if(layer=="PasteCanvas" || layer=="pastecanvas" || layer=="paste_canvas")
561                 return Gtk::StockID("synfig-layer_other_pastecanvas");
562         else if(layer=="plant")
563                 return Gtk::StockID("synfig-layer_other_plant");
564         else if(layer=="super_sample")
565                 return Gtk::StockID("synfig-layer_other_supersample");
566         else if(layer=="text")
567                 return Gtk::StockID("synfig-layer_other_text");
568         else if(layer=="timeloop")
569                 return Gtk::StockID("synfig-layer_other_timeloop");
570         else if(layer=="xor_pattern")
571                 return Gtk::StockID("synfig-layer_other_xorpattern");
572         // Stylize Layers
573         else if(layer=="bevel")
574                 return Gtk::StockID("synfig-layer_stylize_bevel");
575         else if(layer=="shade")
576                 return Gtk::StockID("synfig-layer_stylize_shade");
577         // Transform Layers
578         else if(layer=="rotate")
579                 return Gtk::StockID("synfig-layer_transform_rotate");
580         else if(layer=="translate")
581                 return Gtk::StockID("synfig-layer_transform_translate");
582         else if(layer=="zoom")
583                 return Gtk::StockID("synfig-layer_transform_zoom");
584         else
585                 return Gtk::StockID("synfig-layer");
586 }
587
588 Glib::RefPtr<Gdk::Pixbuf>
589 studio::get_tree_pixbuf_layer(const synfig::String &layer)
590 {
591         return Gtk::Button().render_icon(layer_icon(layer),Gtk::ICON_SIZE_SMALL_TOOLBAR);
592 }