forked from RTimothyEdwards/magic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMWundo.c
210 lines (187 loc) · 4.74 KB
/
CMWundo.c
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/*
* CMWundo.c --
*
* Interface to the undo package for the color map editor.
*
* *********************************************************************
* * Copyright (C) 1985, 1990 Regents of the University of California. *
* * Permission to use, copy, modify, and distribute this *
* * software and its documentation for any purpose and without *
* * fee is hereby granted, provided that the above copyright *
* * notice appear in all copies. The University of California *
* * makes no representations about the suitability of this *
* * software for any purpose. It is provided "as is" without *
* * express or implied warranty. Export of this software outside *
* * of the United States of America may require an export license. *
* *********************************************************************
*/
#ifndef lint
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 $";
#endif /* not lint */
#include <stdio.h>
#include "utils/magic.h"
#include "utils/geometry.h"
#include "graphics/graphics.h"
#include "windows/windows.h"
#include "cmwind/cmwind.h"
#include "utils/undo.h"
/*
* Identifiers for the color map window editing
* operation.
*/
UndoType cmwUndoClientID;
/*
* Functions to play events forward/backward.
*/
void cmwUndoForw(), cmwUndoBack();
void cmwUndoStart(), cmwUndoDone();
/*
* A single undo event for the
* color map module.
*/
typedef struct
{
int cue_color; /* Index in color map */
int old_r, old_g, old_b; /* Old RGB */
int new_r, new_g, new_b; /* New RGB */
} colorUE;
/*
* Table of colors that were changed as a result
* of an undo/redo command.
*/
bool cmwColorsChanged[256];
/*
* ----------------------------------------------------------------------------
*
* CMWundoInit --
*
* Initialize the color map editor part of the undo package.
* Makes the functions contained in here known to the
* undo module.
*
* Results:
* None.
*
* Side effects:
* Calls the undo package.
*
* ----------------------------------------------------------------------------
*/
void
CMWundoInit()
{
cmwUndoClientID = UndoAddClient(cmwUndoStart, cmwUndoDone, NULL, NULL,
cmwUndoForw, cmwUndoBack, "color map");
}
/*
* ----------------------------------------------------------------------------
*
* cmwUndoForw --
* cmwUndoBack --
*
* Play forward/backward a colormap undo event.
*
* Results:
* None.
*
* Side effects:
* Modifies the colormap.
*
* ----------------------------------------------------------------------------
*/
void
cmwUndoForw(up)
colorUE *up;
{
(void) GrPutColor(up->cue_color, up->new_r, up->new_g, up->new_b);
cmwColorsChanged[up->cue_color] = TRUE;
}
void
cmwUndoBack(up)
colorUE *up;
{
(void) GrPutColor(up->cue_color, up->old_r, up->old_g, up->old_b);
cmwColorsChanged[up->cue_color] = TRUE;
}
/*
* ----------------------------------------------------------------------------
*
* cmwUndoColor --
*
* Record on the undo list a change in a color map entry.
*
* Results:
* None.
*
* Side effects:
* Updates the undo list.
*
* ----------------------------------------------------------------------------
*/
void
cmwUndoColor(color, oldr, oldg, oldb, newr, newg, newb)
int color;
int oldr, oldg, oldb;
int newr, newg, newb;
{
colorUE *up;
up = (colorUE *) UndoNewEvent(cmwUndoClientID, sizeof (colorUE));
if (up == (colorUE *) NULL)
return;
up->cue_color = color;
up->old_r = oldr;
up->old_g = oldg;
up->old_b = oldb;
up->new_r = newr;
up->new_g = newg;
up->new_b = newb;
}
/*
* ----------------------------------------------------------------------------
*
* cmwUndoStart --
*
* Initialization for undo/redo for the color map editor.
*
* Results:
* None.
*
* Side effects:
* Initializes cmwColorsChanged[].
*
* ----------------------------------------------------------------------------
*/
void
cmwUndoStart()
{
int i;
for (i = 0; i < 256; i++)
cmwColorsChanged[i] = FALSE;
}
/*
* ----------------------------------------------------------------------------
*
* cmwUndoDone --
*
* Termination for undo/redo for the color map editor.
* Forces redisplay of any of the windows containing colors that
* were changed.
*
* Results:
* None.
*
* Side effects:
* Causes redisplay.
*
* ----------------------------------------------------------------------------
*/
void
cmwUndoDone()
{
int i;
extern int cmwRedisplayFunc();
for (i = 0; i < 256; i++)
if (cmwColorsChanged[i])
(void) WindSearch(CMWclientID, (ClientData) NULL, (Rect *) NULL,
cmwRedisplayFunc, (ClientData) i);
}