File: rcm_gdk.c

package info (click to toggle)
gimp 2.2.13-1etch4
  • links: PTS
  • area: main
  • in suites: etch
  • size: 94,832 kB
  • ctags: 47,113
  • sloc: ansic: 524,858; xml: 36,798; lisp: 9,870; sh: 9,409; makefile: 7,923; python: 2,674; perl: 2,589; yacc: 520; lex: 334
file content (163 lines) | stat: -rw-r--r-- 4,705 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 *
 * This is a plug-in for the GIMP.
 *
 * Colormap-Rotation plug-in. Exchanges two color ranges.
 *
 * Copyright (C) 1999 Sven Anders (anderss@fmi.uni-passau.de)
 *                    Based on code from Pavel Grinfeld (pavel@ml.com)
 *
 *
 * 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.
 */

/*----------------------------------------------------------------------------
 * Change log:
 *
 * Version 2.0, 04 April 1999.
 *  Nearly complete rewrite, made plug-in stable.
 *  (Works with GIMP 1.1 and GTK+ 1.2)
 *
 * Version 1.0, 27 March 1997.
 *  Initial (unstable) release by Pavel Grinfeld
 *
 *----------------------------------------------------------------------------*/

#include "config.h"

#include <stdio.h>
#include <stdlib.h>

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

#include "rcm.h"
#include "rcm_misc.h"
#include "rcm_dialog.h"
#include "rcm_gdk.h"


/* Global variables */

GdkGC *xor_gc;


/* Drawing routines */

void
rcm_draw_little_circle (GdkWindow *window,
			GdkGC     *color,
			gfloat     hue,
			gfloat     satur)
{
  gint x,y;

  x = GRAY_CENTER + GRAY_RADIUS * satur * cos(hue);
  y = GRAY_CENTER - GRAY_RADIUS * satur * sin(hue);

  gdk_draw_arc (window, color, 0, x-LITTLE_RADIUS, y-LITTLE_RADIUS,
                2*LITTLE_RADIUS, 2*LITTLE_RADIUS, 0, 360*64);
}

void
rcm_draw_large_circle (GdkWindow *window,
		       GdkGC     *color,
		       gfloat     gray_sat)
{
  gint x, y;

  x = GRAY_CENTER;
  y = GRAY_CENTER;

  gdk_draw_arc (window, color, 0,
                ROUND (x - GRAY_RADIUS * gray_sat),
                ROUND (y - GRAY_RADIUS * gray_sat),
                ROUND (2 * GRAY_RADIUS * gray_sat),
                ROUND (2 * GRAY_RADIUS * gray_sat),
                0, 360 * 64);
}


#define REL .8
#define DEL .1
#define TICK 10

void
rcm_draw_arrows (GdkWindow *window,
		 GdkGC     *color,
		 RcmAngle  *angle)
{
  gint   dist;
  gfloat alpha, beta, cw_ccw, delta;

  alpha  = angle->alpha;
  beta   = angle->beta;
  cw_ccw = angle->cw_ccw;
  delta  = angle_mod_2PI(beta - alpha);

  if (cw_ccw == -1)
    delta = delta - TP;

  gdk_draw_line (window,color,
                 CENTER,
                 CENTER,
                 ROUND (CENTER + RADIUS * cos(alpha)),
                 ROUND (CENTER - RADIUS * sin(alpha)));

  gdk_draw_line( window,color,
                 CENTER + RADIUS * cos(alpha),
                 CENTER - RADIUS * sin(alpha),
                 ROUND (CENTER + RADIUS * REL * cos(alpha - DEL)),
                 ROUND (CENTER - RADIUS * REL * sin(alpha - DEL)));

  gdk_draw_line (window,color,
                 CENTER + RADIUS * cos(alpha),
                 CENTER - RADIUS * sin(alpha),
                 ROUND (CENTER + RADIUS * REL * cos(alpha + DEL)),
                 ROUND (CENTER - RADIUS * REL * sin(alpha + DEL)));

  gdk_draw_line (window,color,
                 CENTER,
                 CENTER,
                 ROUND (CENTER + RADIUS * cos(beta)),
                 ROUND (CENTER - RADIUS * sin(beta)));

  gdk_draw_line (window,color,
                 CENTER + RADIUS * cos(beta),
                 CENTER - RADIUS * sin(beta),
                 ROUND (CENTER + RADIUS * REL * cos(beta - DEL)),
                 ROUND (CENTER - RADIUS * REL * sin(beta - DEL)));

  gdk_draw_line (window,color,
                 CENTER + RADIUS * cos(beta),
                 CENTER - RADIUS * sin(beta),
                 ROUND (CENTER + RADIUS * REL * cos(beta + DEL)),
                 ROUND (CENTER - RADIUS * REL * sin(beta + DEL)));

  dist   = RADIUS * EACH_OR_BOTH;

  gdk_draw_line (window,color,
                 CENTER + dist * cos(beta),
                 CENTER - dist * sin(beta),
                 ROUND (CENTER + dist * cos(beta) + cw_ccw * TICK * sin(beta)),
                 ROUND (CENTER - dist * sin(beta) + cw_ccw * TICK * cos(beta)));

  alpha *= 180 * 64 / G_PI;
  delta *= 180 * 64 / G_PI;

  gdk_draw_arc (window, color, 0, CENTER - dist, CENTER - dist,
		2*dist, 2*dist,	alpha, delta);
}