paper.c 7.38 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/* GIMP - The GNU Image Manipulation Program
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 *
 * 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.
 */

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

Manish Singh's avatar
Manish Singh committed
21
#include <string.h>
22 23 24

#include <gtk/gtk.h>

25
#include <libgimp/gimp.h>
26 27
#include <libgimp/gimpui.h>

Manish Singh's avatar
Manish Singh committed
28 29
#include "gimpressionist.h"
#include "ppmtool.h"
30
#include "paper.h"
31 32

#include "libgimp/stdplugins-intl.h"
Manish Singh's avatar
Manish Singh committed
33 34


35 36 37
static GtkWidget *paper_preview       = NULL;
static GtkWidget *paper_invert        = NULL;
static GtkWidget *paper_list          = NULL;
38
static GtkObject *paper_relief_adjust = NULL;
39 40
static GtkObject *paper_scale_adjust  = NULL;
static GtkWidget *paper_overlay       = NULL;
41

42
static void paper_update_preview (void)
Manish Singh's avatar
Manish Singh committed
43
{
44 45 46 47
  gint     i, j;
  guchar  *buf, *paper_preview_buffer;
  gdouble  sc;
  ppm_t    p = {0, 0, NULL};
48

49
  ppm_load (pcvals.selected_paper, &p);
50 51
  sc = p.width > p.height ? p.width : p.height;
  sc = 100.0 / sc;
52 53
  resize (&p, p.width*sc,p.height*sc);

54
  paper_preview_buffer = g_new0 (guchar, 100*100);
55 56 57 58 59 60 61 62 63 64 65 66 67

  for (i = 0, buf = paper_preview_buffer; i < 100; i++, buf += 100)
    {
      gint k = i * p.width * 3;

      if (i < p.height)
        {
          for (j = 0; j < p.width; j++)
            buf[j] = p.col[k + j * 3];
          if (GTK_TOGGLE_BUTTON (paper_invert)->active)
            for (j = 0; j < p.width; j++)
              buf[j] = 255 - buf[j];
        }
Manish Singh's avatar
Manish Singh committed
68
    }
69 70 71 72 73 74
  gimp_preview_area_draw (GIMP_PREVIEW_AREA (paper_preview),
                          0, 0, 100, 100,
                          GIMP_GRAY_IMAGE,
                          paper_preview_buffer,
                          100);

75
  ppm_kill (&p);
76
  g_free (paper_preview_buffer);
77

78
  gtk_widget_queue_draw (paper_preview);
Manish Singh's avatar
Manish Singh committed
79 80
}

81 82 83
static void
paper_select (GtkTreeSelection *selection,
              gpointer          data)
Manish Singh's avatar
Manish Singh committed
84
{
85
  GtkTreeIter   iter;
86 87 88 89 90
  GtkTreeModel *model;

  if (gtk_tree_selection_get_selected (selection, &model, &iter))
    {
      gchar *paper;
Manish Singh's avatar
Manish Singh committed
91

92
      gtk_tree_model_get (model, &iter, 0, &paper, -1);
Manish Singh's avatar
Manish Singh committed
93

94 95 96 97
      if (paper)
        {
          gchar *fname = g_build_filename ("Paper", paper, NULL);

98 99
          g_strlcpy (pcvals.selected_paper,
                     fname, sizeof (pcvals.selected_paper));
100

101
          paper_update_preview ();
Manish Singh's avatar
Manish Singh committed
102

103 104 105
          g_free (fname);
          g_free (paper);
        }
106
    }
Manish Singh's avatar
Manish Singh committed
107 108
}

109 110
void
paper_restore (void)
111
{
112 113 114 115 116
  reselect (paper_list, pcvals.selected_paper);
  gtk_adjustment_set_value (GTK_ADJUSTMENT (paper_relief_adjust), pcvals.paper_relief);
  gtk_adjustment_set_value (GTK_ADJUSTMENT (paper_scale_adjust), pcvals.paper_scale);
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (paper_invert), pcvals.paper_invert);
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (paper_overlay), pcvals.paper_overlay);
117 118
}

119 120
void
paper_store (void)
121
{
122 123 124
  pcvals.paper_invert = GTK_TOGGLE_BUTTON (paper_invert)->active;
  pcvals.paper_invert = GTK_TOGGLE_BUTTON (paper_invert)->active;
  pcvals.paper_overlay = GTK_TOGGLE_BUTTON (paper_overlay)->active;
125 126
}

127 128
void
create_paperpage (GtkNotebook *notebook)
Manish Singh's avatar
Manish Singh committed
129
{
130 131 132 133
  GtkWidget         *box1, *thispage, *box2;
  GtkWidget        *label, *tmpw, *table;
  GtkWidget        *view;
  GtkWidget        *frame;
134
  GtkTreeSelection *selection;
135 136
  GtkTreeIter       iter;
  GtkListStore     *paper_store_list;
Manish Singh's avatar
Manish Singh committed
137

138
  label = gtk_label_new_with_mnemonic (_("P_aper"));
Manish Singh's avatar
Manish Singh committed
139

140
  thispage = gtk_vbox_new (FALSE, 12);
141
  gtk_container_set_border_width (GTK_CONTAINER (thispage), 12);
142
  gtk_widget_show (thispage);
Manish Singh's avatar
Manish Singh committed
143

144
  box1 = gtk_hbox_new (FALSE, 12);
145
  gtk_box_pack_start (GTK_BOX (thispage), box1, TRUE, TRUE, 0);
Manish Singh's avatar
Manish Singh committed
146 147
  gtk_widget_show (box1);

148
  paper_list = view = create_one_column_list (box1, paper_select);
149 150
  paper_store_list =
    GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (view)));
151
  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
Manish Singh's avatar
Manish Singh committed
152

153
  box2 = gtk_vbox_new (FALSE, 12);
154
  gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0);
Manish Singh's avatar
Manish Singh committed
155 156
  gtk_widget_show (box2);

157 158
  frame = gtk_frame_new (NULL);
  gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
159
  gtk_box_pack_start (GTK_BOX (box2), frame, FALSE, FALSE, 0);
160
  gtk_widget_show (frame);
Manish Singh's avatar
Manish Singh committed
161

162 163
  paper_preview = tmpw = gimp_preview_area_new ();
  gtk_widget_set_size_request (tmpw, 100, 100);
164
  gtk_container_add (GTK_CONTAINER (frame), tmpw);
165
  gtk_widget_show (tmpw);
Manish Singh's avatar
Manish Singh committed
166

167
  paper_invert = tmpw = gtk_check_button_new_with_mnemonic ( _("_Invert"));
Manish Singh's avatar
Manish Singh committed
168
  gtk_box_pack_start (GTK_BOX (box2), tmpw, FALSE, FALSE, 0);
169
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (tmpw), FALSE);
Manish Singh's avatar
Manish Singh committed
170
  gtk_widget_show (tmpw);
171
  g_signal_connect_swapped (tmpw, "clicked",
172
                            G_CALLBACK (paper_select), selection);
173
  gimp_help_set_help_data (tmpw, _("Inverts the Papers texture"), NULL);
174 175
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (tmpw),
                                pcvals.paper_invert);
Manish Singh's avatar
Manish Singh committed
176

177
  paper_overlay = tmpw = gtk_check_button_new_with_mnemonic ( _("O_verlay"));
Manish Singh's avatar
Manish Singh committed
178
  gtk_box_pack_start (GTK_BOX (box2), tmpw, FALSE, FALSE, 0);
179
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (tmpw), FALSE);
Manish Singh's avatar
Manish Singh committed
180
  gtk_widget_show (tmpw);
181
  gimp_help_set_help_data
182
    (tmpw, _("Applies the paper as it is (without embossing it)"), NULL);
183 184
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (tmpw),
                                pcvals.paper_overlay);
Manish Singh's avatar
Manish Singh committed
185

186 187 188
  table = gtk_table_new (2, 3, FALSE);
  gtk_table_set_col_spacings (GTK_TABLE (table), 6);
  gtk_table_set_row_spacings (GTK_TABLE (table), 6);
189
  gtk_box_pack_start (GTK_BOX (thispage), table, FALSE, FALSE, 0);
190 191
  gtk_widget_show (table);

192
  paper_scale_adjust =
193 194 195 196 197 198 199
    gimp_scale_entry_new (GTK_TABLE (table), 0, 0,
                          _("Scale:"),
                          150, -1, pcvals.paper_scale,
                          3.0, 150.0, 1.0, 10.0, 1,
                          TRUE, 0, 0,
                          _("Specifies the scale of the texture (in percent of original file)"),
                          NULL);
200
  g_signal_connect (paper_scale_adjust, "value-changed",
201
                    G_CALLBACK (gimp_double_adjustment_update),
202
                    &pcvals.paper_scale);
203

204
  paper_relief_adjust =
205 206 207 208 209 210 211
    gimp_scale_entry_new (GTK_TABLE (table), 0, 1,
                          _("Relief:"),
                          150, -1, pcvals.paper_relief,
                          0.0, 100.0, 1.0, 10.0, 1,
                          TRUE, 0, 0,
                          _("Specifies the amount of embossing to apply to the image (in percent)"),
                          NULL);
212
  g_signal_connect (paper_relief_adjust, "value-changed",
213
                    G_CALLBACK (gimp_double_adjustment_update),
214
                    &pcvals.paper_relief);
215

Manish Singh's avatar
Manish Singh committed
216

217
  if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (paper_store_list), &iter))
218 219
    gtk_tree_selection_select_iter (selection, &iter);

220 221
  paper_select (selection, NULL);
  readdirintolist ("Paper", view, pcvals.selected_paper);
222
  gtk_notebook_append_page_menu (notebook, thispage, label, NULL);
Manish Singh's avatar
Manish Singh committed
223
}