1 /*
2 * CMWundo.c --
3 *
4 * Interface to the undo package for the color map editor.
5 *
6 * *********************************************************************
7 * * Copyright (C) 1985, 1990 Regents of the University of California. *
8 * * Permission to use, copy, modify, and distribute this *
9 * * software and its documentation for any purpose and without *
10 * * fee is hereby granted, provided that the above copyright *
11 * * notice appear in all copies. The University of California *
12 * * makes no representations about the suitability of this *
13 * * software for any purpose. It is provided "as is" without *
14 * * express or implied warranty. Export of this software outside *
15 * * of the United States of America may require an export license. *
16 * *********************************************************************
17 */
18
19 #ifndef lint
20 static char rcsid[] __attribute__ ((unused)) = "$Header: /usr/cvsroot/magic-8.0/cmwind/CMWundo.c,v 1.1.1.1 2008/02/03 20:43:50 tim Exp $";
21 #endif /* not lint */
22
23 #include <stdio.h>
24
25 #include "utils/magic.h"
26 #include "utils/geometry.h"
27 #include "graphics/graphics.h"
28 #include "windows/windows.h"
29 #include "cmwind/cmwind.h"
30 #include "utils/undo.h"
31
32 /*
33 * Identifiers for the color map window editing
34 * operation.
35 */
36 UndoType cmwUndoClientID;
37
38 /*
39 * Functions to play events forward/backward.
40 */
41 void cmwUndoForw(), cmwUndoBack();
42 void cmwUndoStart(), cmwUndoDone();
43
44 /*
45 * A single undo event for the
46 * color map module.
47 */
48 typedef struct
49 {
50 int cue_color; /* Index in color map */
51 int old_r, old_g, old_b; /* Old RGB */
52 int new_r, new_g, new_b; /* New RGB */
53 } colorUE;
54
55 /*
56 * Table of colors that were changed as a result
57 * of an undo/redo command.
58 */
59 bool cmwColorsChanged[256];
60
61 /*
62 * ----------------------------------------------------------------------------
63 *
64 * CMWundoInit --
65 *
66 * Initialize the color map editor part of the undo package.
67 * Makes the functions contained in here known to the
68 * undo module.
69 *
70 * Results:
71 * None.
72 *
73 * Side effects:
74 * Calls the undo package.
75 *
76 * ----------------------------------------------------------------------------
77 */
78
79 void
CMWundoInit()80 CMWundoInit()
81 {
82 cmwUndoClientID = UndoAddClient(cmwUndoStart, cmwUndoDone, NULL, NULL,
83 cmwUndoForw, cmwUndoBack, "color map");
84 }
85
86
87 /*
88 * ----------------------------------------------------------------------------
89 *
90 * cmwUndoForw --
91 * cmwUndoBack --
92 *
93 * Play forward/backward a colormap undo event.
94 *
95 * Results:
96 * None.
97 *
98 * Side effects:
99 * Modifies the colormap.
100 *
101 * ----------------------------------------------------------------------------
102 */
103
104 void
cmwUndoForw(up)105 cmwUndoForw(up)
106 colorUE *up;
107 {
108 (void) GrPutColor(up->cue_color, up->new_r, up->new_g, up->new_b);
109 cmwColorsChanged[up->cue_color] = TRUE;
110 }
111
112 void
cmwUndoBack(up)113 cmwUndoBack(up)
114 colorUE *up;
115 {
116 (void) GrPutColor(up->cue_color, up->old_r, up->old_g, up->old_b);
117 cmwColorsChanged[up->cue_color] = TRUE;
118 }
119
120 /*
121 * ----------------------------------------------------------------------------
122 *
123 * cmwUndoColor --
124 *
125 * Record on the undo list a change in a color map entry.
126 *
127 * Results:
128 * None.
129 *
130 * Side effects:
131 * Updates the undo list.
132 *
133 * ----------------------------------------------------------------------------
134 */
135
136 void
cmwUndoColor(color,oldr,oldg,oldb,newr,newg,newb)137 cmwUndoColor(color, oldr, oldg, oldb, newr, newg, newb)
138 int color;
139 int oldr, oldg, oldb;
140 int newr, newg, newb;
141 {
142 colorUE *up;
143
144 up = (colorUE *) UndoNewEvent(cmwUndoClientID, sizeof (colorUE));
145 if (up == (colorUE *) NULL)
146 return;
147
148 up->cue_color = color;
149 up->old_r = oldr;
150 up->old_g = oldg;
151 up->old_b = oldb;
152 up->new_r = newr;
153 up->new_g = newg;
154 up->new_b = newb;
155 }
156
157 /*
158 * ----------------------------------------------------------------------------
159 *
160 * cmwUndoStart --
161 *
162 * Initialization for undo/redo for the color map editor.
163 *
164 * Results:
165 * None.
166 *
167 * Side effects:
168 * Initializes cmwColorsChanged[].
169 *
170 * ----------------------------------------------------------------------------
171 */
172
173 void
cmwUndoStart()174 cmwUndoStart()
175 {
176 int i;
177
178 for (i = 0; i < 256; i++)
179 cmwColorsChanged[i] = FALSE;
180 }
181
182 /*
183 * ----------------------------------------------------------------------------
184 *
185 * cmwUndoDone --
186 *
187 * Termination for undo/redo for the color map editor.
188 * Forces redisplay of any of the windows containing colors that
189 * were changed.
190 *
191 * Results:
192 * None.
193 *
194 * Side effects:
195 * Causes redisplay.
196 *
197 * ----------------------------------------------------------------------------
198 */
199
200 void
cmwUndoDone()201 cmwUndoDone()
202 {
203 int i;
204 extern int cmwRedisplayFunc();
205
206 for (i = 0; i < 256; i++)
207 if (cmwColorsChanged[i])
208 (void) WindSearch(CMWclientID, (ClientData) NULL, (Rect *) NULL,
209 cmwRedisplayFunc, (ClientData) i);
210 }
211