1 /* hf_dialog_options.c - "Pot-pourri" of functions and structures
2 * for managing the HF dialogs - created from hf_wrapper.c on 2006-01-01
3 *
4 * Copyright (C) 2001, 2006, 2010 Patrice St-Gelais
5 * patrstg@users.sourceforge.net
6 * http://geomorph.sourceforge.net
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 */
22
23 #include "hf.h"
24 #include "hf_dialog_options.h"
25 #include "hf_wrapper.h"
26 #include "hf_filters_dialog.h"
27 #include "hf_creation_dialog.h"
28 #include "hf_tools_dialog.h"
29 #include "gl_preview.h"
30 #include "render.h"
31 #include "draw_tools_dialog.h"
32 #include "img_process_dialog.h"
33
34 extern gchar *DEFAULT_TERRAIN;
35
set_creation_container(hf_options_struct * hfo,GtkWidget * creation_container)36 void set_creation_container (hf_options_struct *hfo, GtkWidget *creation_container) {
37 gboolean already_set=FALSE;
38 if (hfo->creation_container)
39 already_set = TRUE;
40 if (!(creation_container && hfo))
41 return;
42 // printf("HFO->CREATION_CONTAINER in SET_CREATION_CONTAINER: %d->%d\n",hfo,creation_container);
43 if (GTK_WIDGET(creation_container))
44 if (GTK_IS_CONTAINER(creation_container))
45 hfo->creation_container = creation_container;
46 else
47 printf("SET_CREATION_CONTAINER: %d is not a container\n", creation_container);
48 else
49 printf("SET_CREATION_CONTAINER: %d is not a widget\n", creation_container);
50 if (!already_set)
51 gtk_box_pack_start(GTK_BOX(creation_container), hfo->fd_struct->filter_dialog, FALSE, FALSE, 0);
52 // gtk_container_add(GTK_CONTAINER(creation_container), hfo->fd_struct->filter_dialog);
53 }
54
hf_dialog_defaults(hf_options_struct * hfo)55 void hf_dialog_defaults (hf_options_struct *hfo) {
56 /*
57 printf("DEFAULT_TERRAIN: %s\n",DEFAULT_TERRAIN);
58 printf("HFO in DIALOG DEFAULTS: %d\n",hfo);
59 printf("CREATION_WIDGETS in DIALOG DEFAULTS: %d\n",hfo->creation_widgets);
60 printf("HF_TYPES_TOOLBAR in DIALOG DEFAULTS: %d\n",hfo->creation_widgets->hf_types_toolbar);
61 */
62 set_toolbar_button_from_label(hfo->creation_widgets->hf_types_toolbar, DEFAULT_TERRAIN, FALSE);
63 set_toolbar_button_from_label(hfo->creation_widgets->hf_types_toolbar, DEFAULT_TERRAIN, TRUE);
64 }
65
hf_options_dialog_new(GtkWidget * window,GtkWidget * creation_container,GtkTooltips * tooltips,gpointer widget_list,gpointer data,stack_struct * stack,gchar * doc_type,gpointer all_docs,GList * (* get_doc_list_from_type)(gpointer all_docs,gchar * doc_type))66 gpointer hf_options_dialog_new(GtkWidget *window,
67 GtkWidget *creation_container,
68 GtkTooltips *tooltips,
69 gpointer widget_list,
70 gpointer data,
71 stack_struct *stack,
72 gchar *doc_type, gpointer all_docs,
73 GList *(*get_doc_list_from_type) (gpointer all_docs, gchar *doc_type)) {
74 // Options structure related to the tools dialog,
75 // initialized once for all the documents
76 // doc_type, all_docs, get_doc_list_from_type: required for building a list of other available open documents
77 gint i;
78 hf_options_struct *hf_options;
79 hf_options = (hf_options_struct *) x_malloc(sizeof(hf_options_struct), "hf_options_struct");
80 hf_options->creation_container = creation_container;
81 hf_options->tools_window = window;
82 hf_options->tools_dialog = NULL;
83 hf_options->hfw_ptr_ptr = data;
84 hf_options->creation_widgets = (hf_creation_wdg_struct *) widget_list;
85 hf_options->all_docs = all_docs;
86 hf_options->doc_type = doc_type;
87 hf_options->get_doc_list_from_type = get_doc_list_from_type;
88 hf_options->current_tools = NULL;
89 hf_options->context = TRANSFORM_CONTEXT;
90 hf_options->last_creation_action = NULL;
91 hf_options->tooltips = tooltips;
92 hf_options->current_callb = NULL;
93 hf_options->current_calculation = NULL;
94 hf_options->current_options = NULL;
95 hf_options->current_dialog = NULL ;
96 hf_options->subdiv1_dialog = NULL;
97 hf_options->subdiv2_dialog = NULL;
98 hf_options->subdiv2_direct_upd = TRUE;
99 hf_options->waves_dialog = NULL;
100 hf_options->surfadd_dialog = NULL;
101 hf_options->uniform_value = (hf_type *) x_malloc(sizeof(hf_type), "hf_type (hf_options->uniform_value)");
102 (*hf_options->uniform_value) = 32767;
103 hf_options->uniform_dialog = NULL;
104 hf_options->subdiv1_options = NULL;
105 hf_options->subdiv2_options = NULL;
106 hf_options->surfadd_options = NULL;
107 hf_options->waves_options = NULL;
108 hf_options->wide_filter = NULL;
109 hf_options->medium_filter1 = NULL;
110 hf_options->medium_filter2 = NULL;
111 hf_options->sharp_filter = NULL;
112 hf_options->image_filter = NULL;
113 hf_options->gauss_filter = NULL;
114 hf_options->dist_matrix = dist_matrix_new(0);
115 hf_options->creation_fd_struct = filter_dialog_new(window,tooltips,data);
116 hf_options->fd_struct = hf_options->creation_fd_struct;
117 hf_options->doc_list = NULL;
118 // The default is to add the main filters dialog to the creation container
119 if (creation_container)
120 gtk_box_pack_start(GTK_BOX(creation_container), hf_options->fd_struct->filter_dialog, FALSE, FALSE, 0);
121 hf_options->flag_uniform_done = FALSE;
122 set_filter_defaults(hf_options->fd_struct);
123
124 hf_options->draw = NULL;
125
126 // Cursors
127 hf_options->default_cursor = gdk_cursor_new(GDK_LEFT_PTR);
128 hf_options->current_cursor = hf_options->default_cursor;
129 hf_options->pencil_cursor = gdk_cursor_new(GDK_PENCIL);
130 hf_options->watch_cursor = gdk_cursor_new(GDK_WATCH);
131 hf_options->fleur_cursor = gdk_cursor_new(GDK_FLEUR);
132 hf_options->hf_size = 0; // Initialized by hf_wrapper_new and size_callb
133 hf_options->img = NULL;
134 hf_options->need_tmp_buf = FALSE; // Flag: if we need temp buffer for brightness / contrast
135 // useful after an undo...
136
137 // OpenGL preview
138 hf_options->gl_defaults = gl_defaults_init ( );
139
140 for (i=0; i<GAUSS_LIST_LENGTH; i++)
141 hf_options->gauss_list[i] = NULL;
142
143 // Context management functions and data
144 // The pointer field is inherited from app.h
145 hf_options->stack = stack;
146
147 hf_options->primit_surf = NULL;
148 hf_options->fourier = fourier_dialog_new();
149 hf_options->render_str = render_struct_new();
150
151 set_stack_specific_fn (hf_options->stack, (gpointer) hf_specific_commit_or_reset);
152
153 return (gpointer) hf_options;
154 }
155
hf_options_dialog_free(gpointer hf_opt_ptr)156 void hf_options_dialog_free (gpointer hf_opt_ptr) {
157 gint i;
158 hf_options_struct *hf_opt = (hf_options_struct *) hf_opt_ptr;
159 if (!hf_opt) return;
160 // printf("HF_OPTIONS_DIALOG_FREE-1\n");
161 if (hf_opt->creation_widgets)
162 x_free(hf_opt->creation_widgets);
163 if (hf_opt->uniform_value)
164 x_free(hf_opt->uniform_value);
165 if (hf_opt->subdiv1_options)
166 x_free(hf_opt->subdiv1_options);
167 if (hf_opt->subdiv2_options)
168 x_free(hf_opt->subdiv2_options);
169 if (hf_opt->surfadd_options)
170 x_free(hf_opt->surfadd_options);
171 if (hf_opt->waves_options)
172 x_free(hf_opt->waves_options);
173 if (hf_opt->wide_filter)
174 filter_free(hf_opt->wide_filter);
175 if (hf_opt->medium_filter1)
176 filter_free(hf_opt->medium_filter1);
177 if (hf_opt->medium_filter2)
178 filter_free(hf_opt->medium_filter2);
179 if (hf_opt->sharp_filter)
180 filter_free(hf_opt->sharp_filter);
181 if (hf_opt->gauss_filter)
182 filter_free(hf_opt->gauss_filter);
183 for (i=0; i<GAUSS_LIST_LENGTH; i++)
184 if (hf_opt->gauss_list[i])
185 x_free(hf_opt->gauss_list[i]);
186 if (hf_opt->img)
187 img_dialog_free(hf_opt->img);
188 if (hf_opt->draw)
189 draw_tools_free(hf_opt->draw);
190 if (hf_opt->fourier)
191 fourier_dialog_free(hf_opt->fourier);
192 if (hf_opt->render_str)
193 x_free(hf_opt->render_str);
194 x_free(hf_opt);
195 // printf("HF_OPTIONS_DIALOG_FREE-4\n");
196 }
197
hf_specific_commit_or_reset(stack_struct * stack)198 void hf_specific_commit_or_reset (stack_struct *stack) {
199 hf_wrapper_struct *hfw;
200 // printf("HF_SPECIFIC_COMMIT_OR_RESET 1 on %p\n", stack->commit_data);
201 if (stack->commit_data) {
202 hfw = (hf_wrapper_struct *) stack->commit_data;
203 // printf("HF_SPECIFIC_COMMIT_OR_RESET 2 on %p: hf_buf= %p\n",hfw,hfw->hf_struct->hf_buf);
204 if (hfw->hf_options->img && hfw->hf_options->img->set_fn)
205 (*hfw->hf_options->img->set_fn) (hfw->hf_options->img);
206 set_render_buffer (hfw->hf_options->render_str, hfw->hf_struct->hf_buf, hfw->hf_struct->max_x,hfw->hf_struct->max_y);
207 hf_backup (hfw->hf_struct);
208 }
209 }
210
211 // Transitional function (for backward compatibility) - 2010.12.05
hf_commit_or_reset(hf_options_struct * hfo)212 void hf_commit_or_reset (hf_options_struct *hfo) {
213 if (hfo && hfo->stack)
214 commit_or_reset (hfo->stack);
215 }
216
217