gimpressionist.c 5.64 KB
Newer Older
1 2 3
/* GIMP - The GNU Image Manipulation Program
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 *
4
 * This program is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation; either version 3 of the License, or
7 8 9 10 11 12 13 14
 * (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
15
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 17
 */

Manish Singh's avatar
Manish Singh committed
18
#include "config.h"
19 20 21 22

#include <libgimp/gimp.h>
#include <libgimp/gimpui.h>

Manish Singh's avatar
Manish Singh committed
23
#include "gimpressionist.h"
24
/*
25
 * The Page Specific Imports
26
 * */
27
#include "brush.h"
28 29
#include "color.h"
#include "general.h"
30
#include "orientation.h"
31
#include "orientmap.h"
32 33 34
#include "placement.h"
#include "preview.h"
#include "size.h"
35
#include "paper.h"
36
#include "presets.h"
37

Manish Singh's avatar
Manish Singh committed
38
#include "ppmtool.h"
39

40
#include "libgimp/stdplugins-intl.h"
41

42

43
static GtkWidget *dialog = NULL;
Manish Singh's avatar
Manish Singh committed
44

45 46
void
store_values (void)
Manish Singh's avatar
Manish Singh committed
47
{
48 49 50
  paper_store ();
  brush_store ();
  general_store ();
Manish Singh's avatar
Manish Singh committed
51 52
}

53 54
void
restore_values (void)
Manish Singh's avatar
Manish Singh committed
55
{
56 57 58 59 60 61 62 63 64
  brush_restore ();
  paper_restore ();
  orientation_restore ();
  size_restore ();
  place_restore ();
  general_restore ();
  color_restore ();

  update_orientmap_dialog ();
Manish Singh's avatar
Manish Singh committed
65 66
}

67 68 69 70
GtkWidget *
create_one_column_list (GtkWidget *parent,
                        void (*changed_cb) (GtkTreeSelection *selection,
                                            gpointer data))
71
{
72 73 74
  GtkListStore      *store;
  GtkTreeSelection  *selection;
  GtkCellRenderer   *renderer;
75
  GtkTreeViewColumn *column;
76
  GtkWidget         *swin, *view;
77 78 79

  swin = gtk_scrolled_window_new (NULL, NULL);
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swin),
80 81
                                  GTK_POLICY_AUTOMATIC,
                                  GTK_POLICY_AUTOMATIC);
82
  gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (swin),
83
                                       GTK_SHADOW_IN);
84 85
  gtk_box_pack_start (GTK_BOX (parent), swin, FALSE, FALSE, 0);
  gtk_widget_show (swin);
86
  gtk_widget_set_size_request (swin, 150,-1);
87 88 89 90 91

  store = gtk_list_store_new (1, G_TYPE_STRING);
  view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store));

  gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (view), FALSE);
92
  g_object_unref (store);
93 94 95 96
  gtk_widget_show (view);

  renderer = gtk_cell_renderer_text_new ();
  column = gtk_tree_view_column_new_with_attributes ("Preset", renderer,
97 98
                                                     "text", 0,
                                                     NULL);
99 100 101 102 103 104
  gtk_tree_view_append_column (GTK_TREE_VIEW (view), column);

  gtk_container_add (GTK_CONTAINER (swin), view);

  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
  gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
105
  g_signal_connect (selection, "changed", G_CALLBACK (changed_cb), NULL);
106 107 108 109

  return view;
}

110 111 112 113
static void
dialog_response (GtkWidget *widget,
                 gint       response_id,
                 gpointer   data)
Manish Singh's avatar
Manish Singh committed
114
{
115
  switch (response_id)
116
    {
117
    case GTK_RESPONSE_OK:
118
      store_values ();
119 120 121 122 123 124 125 126 127
      pcvals.run = TRUE;
      gtk_widget_destroy (widget);
      break;

    default:
      gtk_widget_destroy (widget);
      break;
    }
}
128

129 130 131 132
static GtkWidget *
create_dialog (void)
{
  GtkWidget *notebook;
133 134
  GtkWidget *hbox;
  GtkWidget *preview_box;
135

136
  gimp_ui_init (PLUG_IN_BINARY, TRUE);
Manish Singh's avatar
Manish Singh committed
137

138
  dialog = gimp_dialog_new (_("GIMPressionist"), PLUG_IN_ROLE,
139
                            NULL, 0,
140
                            gimp_standard_help_func, PLUG_IN_PROC,
Manish Singh's avatar
Manish Singh committed
141

142 143
                            GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                            GTK_STOCK_OK,     GTK_RESPONSE_OK,
144

145
                            NULL);
146

147
  gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
148 149 150 151
                                           GTK_RESPONSE_OK,
                                           GTK_RESPONSE_CANCEL,
                                           -1);

152
  gimp_window_set_transient (GTK_WINDOW (dialog));
153

154
  g_signal_connect (dialog, "response",
155 156
                    G_CALLBACK (dialog_response),
                    NULL);
157
  g_signal_connect (dialog, "destroy",
158 159
                    G_CALLBACK (gtk_main_quit),
                    NULL);
160

161
  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
162
  gtk_container_set_border_width (GTK_CONTAINER (hbox), 12);
163 164
  gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
                      hbox, TRUE, TRUE, 0);
165
  gtk_widget_show (hbox);
Manish Singh's avatar
Manish Singh committed
166

167 168 169
  preview_box = create_preview ();
  gtk_box_pack_start (GTK_BOX (hbox), preview_box, FALSE, FALSE, 0);
  gtk_widget_show (preview_box);
Manish Singh's avatar
Manish Singh committed
170 171

  notebook = gtk_notebook_new ();
172
  gtk_box_pack_start (GTK_BOX (hbox), notebook, TRUE, TRUE, 5);
173
  gtk_widget_show (notebook);
Manish Singh's avatar
Manish Singh committed
174

175 176 177 178 179 180 181 182
  create_presetpage (GTK_NOTEBOOK (notebook));
  create_paperpage (GTK_NOTEBOOK (notebook));
  create_brushpage (GTK_NOTEBOOK (notebook));
  create_orientationpage (GTK_NOTEBOOK (notebook));
  create_sizepage (GTK_NOTEBOOK (notebook));
  create_placementpage (GTK_NOTEBOOK (notebook));
  create_colorpage (GTK_NOTEBOOK (notebook));
  create_generalpage (GTK_NOTEBOOK (notebook));
Manish Singh's avatar
Manish Singh committed
183

184
  updatepreview (NULL, NULL);
Manish Singh's avatar
Manish Singh committed
185

186 187 188 189
  /*
   * This is to make sure the values from the pcvals will be reflected
   * in the GUI here. Otherwise they will be set to the defaults.
   * */
190
  restore_values ();
191

192
  gtk_widget_show (dialog);
Manish Singh's avatar
Manish Singh committed
193

194
  return dialog;
Manish Singh's avatar
Manish Singh committed
195 196
}

197 198
gint
create_gimpressionist (void)
Manish Singh's avatar
Manish Singh committed
199
{
200 201 202
  pcvals.run = FALSE;

  create_dialog ();
Manish Singh's avatar
Manish Singh committed
203

204
  gtk_main ();
Manish Singh's avatar
Manish Singh committed
205 206 207

  return pcvals.run;
}