home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2002 April / pcpro0402.iso / essentials / graphics / Gimp / gimp-src-20001226.exe / src / gimp / plug-ins / rcm / rcm_gdk.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-02-01  |  4.8 KB  |  167 lines

  1. /*
  2.  * Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3.  *
  4.  * This is a plug-in for the GIMP.
  5.  *
  6.  * Colormap-Rotation plug-in. Exchanges two color ranges.
  7.  *
  8.  * Copyright (C) 1999 Sven Anders (anderss@fmi.uni-passau.de)
  9.  *                    Based on code from Pavel Grinfeld (pavel@ml.com)
  10.  *
  11.  *
  12.  * This program is free software; you can redistribute it and/or modify
  13.  * it under the terms of the GNU General Public License as published by
  14.  * the Free Software Foundation; either version 2 of the License, or
  15.  * (at your option) any later version.
  16.  *
  17.  * This program is distributed in the hope that it will be useful,
  18.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20.  * GNU General Public License for more details.
  21.  *
  22.  * You should have received a copy of the GNU General Public License
  23.  * along with this program; if not, write to the Free Software
  24.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  25.  */
  26.  
  27. /*-----------------------------------------------------------------------------------
  28.  * Change log:
  29.  * 
  30.  * Version 2.0, 04 April 1999.
  31.  *  Nearly complete rewrite, made plug-in stable.
  32.  *  (Works with GIMP 1.1 and GTK+ 1.2)
  33.  *
  34.  * Version 1.0, 27 March 1997.
  35.  *  Initial (unstable) release by Pavel Grinfeld
  36.  *
  37.  *-----------------------------------------------------------------------------------*/
  38.  
  39. #include <stdio.h>
  40. #include <stdlib.h>
  41. #include <math.h>
  42.  
  43. #include <gtk/gtk.h>
  44. #include <libgimp/gimp.h>
  45.  
  46. #include "rcm.h"
  47. #include "rcm_misc.h"
  48. #include "rcm_dialog.h"
  49. #include "rcm_gdk.h"
  50.  
  51. /*-----------------------------------------------------------------------------------*/
  52. /* Global variables */
  53. /*-----------------------------------------------------------------------------------*/
  54.  
  55. GdkGC *xor_gc;
  56.  
  57.  
  58. /*-----------------------------------------------------------------------------------*/
  59. /* Drawing routines */
  60. /*-----------------------------------------------------------------------------------*/
  61.  
  62. void 
  63. rcm_draw_little_circle (GdkWindow *window, 
  64.             GdkGC     *color, 
  65.             float      hue, 
  66.             float      satur)
  67. {
  68.   int x,y;
  69.  
  70.   x = GRAY_CENTER + GRAY_RADIUS * satur * cos(hue);
  71.   y = GRAY_CENTER - GRAY_RADIUS * satur * sin(hue);
  72.  
  73.   gdk_draw_arc(window, color, 0, x-LITTLE_RADIUS, y-LITTLE_RADIUS,
  74.            2*LITTLE_RADIUS, 2*LITTLE_RADIUS, 0, 360*64);
  75. }
  76.  
  77. /*-----------------------------------------------------------------------------------*/
  78.  
  79. void 
  80. rcm_draw_large_circle (GdkWindow *window, 
  81.                GdkGC     *color, 
  82.                float      gray_sat)
  83. {
  84.   int x, y;
  85.  
  86.   x = GRAY_CENTER;
  87.   y = GRAY_CENTER;
  88.  
  89.   gdk_draw_arc(window, color, 0,
  90.            ROUND (x - GRAY_RADIUS * gray_sat),
  91.            ROUND (y - GRAY_RADIUS * gray_sat),
  92.            ROUND (2 * GRAY_RADIUS * gray_sat),
  93.            ROUND (2 * GRAY_RADIUS * gray_sat),
  94.            0, 360 * 64);
  95. }
  96.  
  97. /*-----------------------------------------------------------------------------------*/
  98.  
  99. #define REL .8
  100. #define DEL .1
  101. #define TICK 10
  102.  
  103. void 
  104. rcm_draw_arrows (GdkWindow *window, 
  105.          GdkGC     *color, 
  106.          RcmAngle  *angle)
  107. {
  108.   int dist;
  109.   float alpha, beta, cw_ccw, delta;
  110.    
  111.   alpha = angle->alpha;
  112.   beta = angle->beta;
  113.   cw_ccw = angle->cw_ccw;
  114.   delta = angle_mod_2PI(beta - alpha);
  115.   if (cw_ccw == -1) delta = delta - TP;
  116.  
  117.   gdk_draw_line(window,color,
  118.         CENTER,
  119.         CENTER,
  120.         ROUND (CENTER + RADIUS * cos(alpha)),
  121.         ROUND (CENTER - RADIUS * sin(alpha)));
  122.  
  123.   gdk_draw_line(window,color,
  124.         CENTER + RADIUS * cos(alpha),
  125.         CENTER - RADIUS * sin(alpha),
  126.         ROUND (CENTER + RADIUS * REL * cos(alpha - DEL)),
  127.         ROUND (CENTER - RADIUS * REL * sin(alpha - DEL)));
  128.  
  129.   gdk_draw_line(window,color,
  130.         CENTER + RADIUS * cos(alpha),
  131.         CENTER - RADIUS * sin(alpha),
  132.         ROUND (CENTER + RADIUS * REL * cos(alpha + DEL)),
  133.         ROUND (CENTER - RADIUS * REL * sin(alpha + DEL)));
  134.  
  135.   gdk_draw_line(window,color,
  136.         CENTER,
  137.         CENTER,
  138.         ROUND (CENTER + RADIUS * cos(beta)),
  139.         ROUND (CENTER - RADIUS * sin(beta)));
  140.  
  141.   gdk_draw_line(window,color,
  142.         CENTER + RADIUS * cos(beta),
  143.         CENTER - RADIUS * sin(beta),
  144.         ROUND (CENTER + RADIUS * REL * cos(beta - DEL)),
  145.         ROUND (CENTER - RADIUS * REL * sin(beta - DEL)));
  146.  
  147.   gdk_draw_line(window,color,
  148.         CENTER + RADIUS * cos(beta),
  149.         CENTER - RADIUS * sin(beta),
  150.         ROUND (CENTER + RADIUS * REL * cos(beta + DEL)),
  151.         ROUND (CENTER - RADIUS * REL * sin(beta + DEL)));
  152.  
  153.   dist   = RADIUS * EACH_OR_BOTH;
  154.  
  155.   gdk_draw_line(window,color,
  156.         CENTER + dist * cos(beta),
  157.         CENTER - dist * sin(beta),
  158.         ROUND (CENTER + dist * cos(beta) + cw_ccw * TICK * sin(beta)),
  159.         ROUND (CENTER - dist * sin(beta) + cw_ccw * TICK * cos(beta)));
  160.  
  161.   alpha *= 180 * 64 / G_PI;
  162.   delta *= 180 * 64 / G_PI;
  163.  
  164.   gdk_draw_arc(window, color, 0, CENTER - dist, CENTER - dist,
  165.         2*dist, 2*dist,    alpha, delta);
  166. }
  167.