1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
|
/*
Copyright (C) 2003 by Sean David Fleming
sean@ivec.org
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
The GNU GPL can also be found at http://www.gnu.org
*/
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "gdis.h"
#include "coords.h"
#include "edit.h"
#include "file.h"
#include "matrix.h"
#include "opengl.h"
#include "dialog.h"
#include "interface.h"
#include "gui_image.h"
#include "folder.xpm"
#include "disk.xpm"
#include "arrow.xpm"
#include "axes.xpm"
#include "tools.xpm"
#include "palette.xpm"
#include "cross.xpm"
#include "geom.xpm"
#include "cell.xpm"
#include "camera.xpm"
#include "element.xpm"
#include "tb_animate.xpm"
#include "tb_diffraction.xpm"
#include "tb_isosurface.xpm"
#include "tb_surface.xpm"
#include "canvas_single.xpm"
#include "canvas_create.xpm"
#include "canvas_delete.xpm"
/* NEW: include a button to create a new model */
#include "plus.xpm"
extern struct sysenv_pak sysenv;
extern GtkWidget *window;
/****************************************/
/* write an image of the current canvas */
/****************************************/
void image_write(gpointer w)
{
GdkPixbuf *pixbuf;
GError *error=NULL;
pixbuf = gdk_pixbuf_get_from_drawable(NULL, w, NULL,
0, 0, 0, 0,
sysenv.width, sysenv.height);
gdk_pixbuf_save(pixbuf, sysenv.snapshot_filename, "jpeg",
&error, "quality", "90", NULL);
g_free(sysenv.snapshot_filename);
sysenv.snapshot = FALSE;
}
/****************************************/
/* callback to schedule a canvas export */
/****************************************/
void image_export(gchar *name)
{
g_assert(name != NULL);
dialog_destroy_type(FILE_SELECT);
/* FIXME - all GTK stuff (ie closing the file dialog/raising windows */
/* to the foreground etc.) will be done only AFTER this routine ends */
/* ie returns to the control of gtk_main_loop - so there is no way */
/* of preventing the dialog from getting in the way */
/* probably have to set a flag to do it after the next redraw_canvas() */
sysenv.snapshot = TRUE;
sysenv.snapshot_filename = g_build_filename(sysenv.cwd, name, NULL);
}
/*************************************************/
/* add a filename to active model's picture list */
/*************************************************/
void image_import(const gchar *name)
{
gchar *picture;
struct model_pak *model;
/* checks */
/* TODO - check file validity */
g_assert(name != NULL);
dialog_destroy_type(FILE_SELECT);
model = sysenv.active_model;
if (!model)
return;
picture = g_strdup(name);
model->picture_list = g_slist_append(model->picture_list, picture);
model->picture_active = picture;
model->graph_active = NULL;
/* updates */
tree_model_add(model);
redraw_canvas(SINGLE);
}
/***********************************/
/* get a filename for image export */
/***********************************/
void image_export_dialog(void)
{
if (sysenv.active_model)
file_dialog("Export image", NULL, FILE_SAVE,
(gpointer) image_export, PICTURE);
}
/*******************************************/
/* get a file dialog for picture selection */
/*******************************************/
void image_import_dialog(void)
{
if (sysenv.active_model)
file_dialog("Import picture", NULL, FILE_LOAD,
(gpointer) image_import, PICTURE);
}
/**************************************/
/* retrieve a standard image's pixbuf */
/**************************************/
gpointer image_table_lookup(const gchar *name)
{
return(g_hash_table_lookup(sysenv.image_table, name));
}
/******************************************/
/* setup the internal pixbuf lookup table */
/******************************************/
void image_table_init(void)
{
gint i;
gchar *name;
GdkPixbuf *pixbuf;
sysenv.image_table = g_hash_table_new(g_str_hash, g_str_equal);
for (i=0 ; i<IMAGE_LAST ; i++)
{
/* init the name and pixbuf data */
switch (i)
{
case IMAGE_ANIMATE:
pixbuf = gdk_pixbuf_new_from_xpm_data((const gchar **) tb_animate_xpm);
name = "image_animate";
break;
case IMAGE_ARROW:
pixbuf = gdk_pixbuf_new_from_xpm_data((const gchar **) arrow_xpm);
name = "image_arrow";
break;
case IMAGE_AXES:
pixbuf = gdk_pixbuf_new_from_xpm_data((const gchar **) axes_xpm);
name = "image_axes";
break;
case IMAGE_CANVAS_SINGLE:
pixbuf = gdk_pixbuf_new_from_xpm_data((const gchar **) canvas_single_xpm);
name = "image_canvas_single";
break;
case IMAGE_CANVAS_CREATE:
pixbuf = gdk_pixbuf_new_from_xpm_data((const gchar **) canvas_create_xpm);
name = "image_canvas_create";
break;
case IMAGE_CANVAS_DELETE:
pixbuf = gdk_pixbuf_new_from_xpm_data((const gchar **) canvas_delete_xpm);
name = "image_canvas_delete";
break;
case IMAGE_CAMERA:
pixbuf = gdk_pixbuf_new_from_xpm_data((const gchar **) camera_xpm);
name = "image_camera";
break;
case IMAGE_COMPASS:
pixbuf = gdk_pixbuf_new_from_xpm_data((const gchar **) geom_xpm);
name = "image_compass";
break;
case IMAGE_CROSS:
pixbuf = gdk_pixbuf_new_from_xpm_data((const gchar **) cross_xpm);
name = "image_cross";
break;
case IMAGE_DIFFRACTION:
pixbuf = gdk_pixbuf_new_from_xpm_data((const gchar **) tb_diffraction_xpm);
name = "image_diffraction";
break;
case IMAGE_DISK:
pixbuf = gdk_pixbuf_new_from_xpm_data((const gchar **) disk_xpm);
name = "image_disk";
break;
case IMAGE_ELEMENT:
pixbuf = gdk_pixbuf_new_from_xpm_data((const gchar **) element_xpm);
name = "image_element";
break;
case IMAGE_FOLDER:
pixbuf = gdk_pixbuf_new_from_xpm_data((const gchar **) folder_xpm);
name = "image_folder";
break;
case IMAGE_ISOSURFACE:
pixbuf = gdk_pixbuf_new_from_xpm_data((const gchar **) tb_isosurface_xpm);
name = "image_isosurface";
break;
case IMAGE_MEASURE:
pixbuf = gdk_pixbuf_new_from_xpm_data((const gchar **) geom_xpm);
name = "image_measure";
break;
case IMAGE_PERIODIC:
pixbuf = gdk_pixbuf_new_from_xpm_data((const gchar **) cell_xpm);
name = "image_periodic";
break;
case IMAGE_PALETTE:
pixbuf = gdk_pixbuf_new_from_xpm_data((const gchar **) palette_xpm);
name = "image_palette";
break;
case IMAGE_PLUS:
pixbuf = gdk_pixbuf_new_from_xpm_data((const gchar **) plus_xpm);
name = "image_plus";
break;
case IMAGE_SURFACE:
pixbuf = gdk_pixbuf_new_from_xpm_data((const gchar **) tb_surface_xpm);
name = "image_surface";
break;
case IMAGE_TOOLS:
pixbuf = gdk_pixbuf_new_from_xpm_data((const gchar **) tools_xpm);
name = "image_tools";
break;
default:
pixbuf = NULL;
name = NULL;
}
/* add the entry */
if (name && pixbuf)
g_hash_table_insert(sysenv.image_table, name, pixbuf);
}
}
|