home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2002 April / pcpro0402.iso / essentials / graphics / Gimp / gimp-src-20001226.exe / src / gimp / app / indicator_area.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-12-17  |  6.0 KB  |  204 lines

  1. /* The GIMP -- an image manipulation program
  2.  * Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3.  *
  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 2 of the License, or
  7.  * (at your option) any later version.
  8.  *
  9.  * This program is distributed in the hope that it will be useful,
  10.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.  * GNU General Public License for more details.
  13.  *
  14.  * You should have received a copy of the GNU General Public License
  15.  * along with this program; if not, write to the Free Software
  16.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17.  */
  18. #include "config.h"
  19.  
  20. #include <stdlib.h>
  21. #include <string.h>
  22.  
  23. #include <glib.h>
  24.  
  25. #include "apptypes.h"
  26.  
  27. #include "appenv.h"
  28. #include "brush_select.h"
  29. #include "gimpcontextpreview.h"
  30. #include "gimpdnd.h"
  31. #include "gradient_select.h"
  32. #include "indicator_area.h"
  33. #include "pattern_select.h"
  34.  
  35. #include "libgimp/gimpintl.h"
  36.  
  37. #define CELL_SIZE        23  /*  The size of the previews  */
  38. #define GRAD_CELL_WIDTH  48  /*  The width of the gradient preview  */
  39. #define GRAD_CELL_HEIGHT 12  /*  The height of the gradient preview  */
  40. #define CELL_PADDING      2  /*  How much between brush and pattern cells  */
  41.  
  42. /*  Static variables  */
  43. static GtkWidget *brush_preview;
  44. static GtkWidget *pattern_preview;
  45. static GtkWidget *gradient_preview;
  46.  
  47. static void
  48. brush_area_update (GimpContext *context,
  49.            GimpBrush   *brush,
  50.            gpointer     data)
  51. {
  52.   if (brush) 
  53.     gimp_context_preview_update (GIMP_CONTEXT_PREVIEW (brush_preview), brush);
  54. }
  55.  
  56. static void
  57. brush_preview_clicked (GtkWidget *widget, 
  58.                gpointer   data)
  59. {
  60.   brush_dialog_create ();
  61. }
  62.  
  63. static void
  64. brush_preview_drop_brush (GtkWidget *widget,
  65.               GimpBrush *brush,
  66.               gpointer   data)
  67. {
  68.   if (brush)
  69.     gimp_context_set_brush (gimp_context_get_user (), brush);
  70. }
  71.  
  72. static void
  73. pattern_area_update (GimpContext *context,
  74.              GPattern    *pattern,
  75.              gpointer     data)
  76. {
  77.   if (pattern) 
  78.     gimp_context_preview_update (GIMP_CONTEXT_PREVIEW (pattern_preview),
  79.                  pattern);
  80. }
  81.  
  82. static void
  83. pattern_preview_clicked (GtkWidget *widget, 
  84.              gpointer   data)
  85. {
  86.   pattern_dialog_create (); 
  87. }
  88.  
  89. static void
  90. pattern_preview_drop_pattern (GtkWidget *widget,
  91.                   GPattern  *pattern,
  92.                   gpointer   data)
  93. {
  94.   if (pattern)
  95.     gimp_context_set_pattern (gimp_context_get_user (), pattern);
  96. }
  97.  
  98. static void
  99. gradient_area_update (GimpContext *context,
  100.               gradient_t  *gradient,
  101.               gpointer     data)
  102. {
  103.   if (gradient)
  104.     gimp_context_preview_update (GIMP_CONTEXT_PREVIEW (gradient_preview),
  105.                  gradient);
  106. }
  107.  
  108. static void
  109. gradient_preview_clicked (GtkWidget *widget, 
  110.               gpointer   data)
  111. {
  112.   gradient_dialog_create ();
  113. }
  114.  
  115. static void
  116. gradient_preview_drop_gradient (GtkWidget  *widget,
  117.                 gradient_t *gradient,
  118.                 gpointer   data)
  119. {
  120.   if (gradient)
  121.     gimp_context_set_gradient (gimp_context_get_user (), gradient);
  122. }
  123.  
  124. GtkWidget *
  125. indicator_area_create (void)
  126. {
  127.   GimpContext *context;
  128.   GtkWidget *indicator_table;
  129.  
  130.   context = gimp_context_get_user ();
  131.  
  132.   indicator_table = gtk_table_new (2, 2, FALSE);
  133.   gtk_table_set_row_spacing (GTK_TABLE (indicator_table), 0, CELL_PADDING);
  134.   gtk_table_set_col_spacing (GTK_TABLE (indicator_table), 0, CELL_PADDING);
  135.  
  136.   brush_preview =
  137.     gimp_context_preview_new (GCP_BRUSH, 
  138.                   CELL_SIZE, CELL_SIZE, 
  139.                   TRUE, FALSE,
  140.                   (GimpDndDropBrushFunc) brush_preview_drop_brush,
  141.                   NULL);
  142.   gimp_help_set_help_data (brush_preview, 
  143.                _("The active brush.\n"
  144.                  "Click to open the Brushes Dialog."), NULL);
  145.   gtk_signal_connect (GTK_OBJECT (brush_preview), "clicked",
  146.               GTK_SIGNAL_FUNC (brush_preview_clicked),
  147.               NULL);
  148.   gtk_signal_connect (GTK_OBJECT (context), "brush_changed",
  149.               GTK_SIGNAL_FUNC (brush_area_update),
  150.               NULL);
  151.   gtk_table_attach_defaults (GTK_TABLE (indicator_table), brush_preview,
  152.                  0, 1, 0, 1);
  153.                             
  154.   pattern_preview =
  155.     gimp_context_preview_new (GCP_PATTERN, 
  156.                   CELL_SIZE, CELL_SIZE, 
  157.                   TRUE, FALSE,
  158.                   (GimpDndDropPatternFunc) pattern_preview_drop_pattern,
  159.                   NULL);
  160.   gimp_help_set_help_data (pattern_preview, 
  161.                _("The active pattern.\n"
  162.                  "Click to open the Patterns Dialog."), NULL);
  163.   gtk_signal_connect (GTK_OBJECT (pattern_preview), "clicked",
  164.               GTK_SIGNAL_FUNC (pattern_preview_clicked),
  165.               NULL);
  166.   gtk_signal_connect (GTK_OBJECT (context), "pattern_changed",
  167.               GTK_SIGNAL_FUNC (pattern_area_update),
  168.               NULL);
  169.   gtk_table_attach_defaults (GTK_TABLE (indicator_table), pattern_preview,
  170.                  1, 2, 0, 1);
  171.  
  172.   gradient_preview =
  173.     gimp_context_preview_new (GCP_GRADIENT, 
  174.                   GRAD_CELL_WIDTH,
  175.                   GRAD_CELL_HEIGHT, 
  176.                   TRUE, FALSE,
  177.                   (GimpDndDropGradientFunc) gradient_preview_drop_gradient,
  178.                   NULL);
  179.   gimp_help_set_help_data (gradient_preview, 
  180.                _("The active gradient.\n"
  181.                  "Click to open the Gradients Dialog."), NULL);
  182.   gtk_signal_connect (GTK_OBJECT (gradient_preview), "clicked",
  183.               GTK_SIGNAL_FUNC (gradient_preview_clicked),
  184.               NULL);
  185.   gtk_signal_connect (GTK_OBJECT (context), "gradient_changed",
  186.               GTK_SIGNAL_FUNC (gradient_area_update),
  187.               NULL);
  188.   gtk_table_attach_defaults (GTK_TABLE (indicator_table), gradient_preview,
  189.                  0, 2, 1, 2);
  190.  
  191.   brush_area_update (NULL, gimp_context_get_brush (context), NULL);
  192.   pattern_area_update (NULL, gimp_context_get_pattern (context), NULL);
  193.   gradient_area_update (NULL, gimp_context_get_gradient (context), NULL);
  194.  
  195.   gtk_widget_show (brush_preview);
  196.   gtk_widget_show (pattern_preview);
  197.   gtk_widget_show (gradient_preview);
  198.   gtk_widget_show (indicator_table);
  199.  
  200.   return (indicator_table);
  201. }
  202.  
  203.  
  204.