-
Notifications
You must be signed in to change notification settings - Fork 0
/
AvColormapEditor.cc
2274 lines (1993 loc) · 61.6 KB
/
AvColormapEditor.cc
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//# Copyright (C) 1995-2002 Board of Trustees of the University of Illinois
//#
//# This software, both binary and source, is copyrighted by The
//# Board of Trustees of the University of Illinois. Ownership
//# remains with the University. You should have received a copy
//# of a licensing agreement with this software. See the file
//# "AIPSVIEW_COPYRIGHT", or contact the University at this address:
//#
//# The NCSA AipsView Visualization System
//# National Center for Supercomputing Applications
//# University of Illinois
//# 405 North Mathews Ave.
//# Urbana, IL 61801
//# --------------------------------------------------
//
// $Header: /home/cvs/aips++/code/trial/apps/aipsview/Attic/AvColormapEditor.cc,v 19.0 2003/07/16 05:46:52 aips2adm Exp $
//
// $Log: AvColormapEditor.cc,v $
// Revision 19.0 2003/07/16 05:46:52 aips2adm
// exhale: Base release 19.000.00
//
// Revision 18.0 2002/06/07 21:28:37 aips2adm
// exhale: Base release 18.000.00
//
// Revision 17.5 2002/01/30 22:33:56 hravlin
// Initialized some variables g++ thought might get used unset.
//
// Revision 17.4 2002/01/17 15:53:34 hravlin
// Make sure all of black_ is initialized.
//
// Revision 17.3 2002/01/14 16:52:12 hravlin
// Changed fallbacks arg to be const char *[].
//
// Revision 17.2 2002/01/09 20:23:06 hravlin
// Changed an assignment to hsv_ to 1 from -1.
// Add '&' to conditional checks around line 2130.
//
// Revision 17.1 2002/01/07 22:27:12 hravlin
// Removed check for __P.
//
// Revision 17.0 2001/11/12 19:42:06 aips2adm
// exhale: Base release 17.000.00
//
// Revision 16.0 2001/05/03 01:42:14 aips2adm
// exhale: Base release 16.000.00
//
// Revision 15.0 2000/10/26 17:09:05 aips2adm
// exhale: Base release 15.000.00
//
// Revision 14.1 2000/07/18 18:12:15 hravlin
// Changes to remove char * <- const char * compiler warnings.
//
// Revision 14.0 2000/03/23 16:07:55 aips2adm
// exhale: Base release 14.000.00
//
// Revision 13.5 1999/10/01 21:56:56 hravlin
// *** empty log message ***
//
// Revision 13.4 1999/09/28 19:09:04 hravlin
// Added check to prevent indirect recursion during TrueColor map updates.
//
// Revision 13.3 1999/09/15 22:09:30 hravlin
// Fixed a typo from previous checkin.
//
// Revision 13.2 1999/09/15 21:39:14 hravlin
// Added support for callback notification when colormap is edited and
// using global X values rather than root's.
// Also changes for new colormap handler.
//
// Revision 13.1 1999/08/25 19:57:06 hravlin
// Edits (mostly casts) to remove compiler warnings.
//
// Revision 13.0 1999/08/10 18:39:38 aips2adm
// exhale: Base release 13.000.00
//
// Revision 12.0 1999/07/15 00:22:01 aips2adm
// exhale: Base release 12.000.00
//
// Revision 11.0 1998/10/03 06:58:53 aips2adm
// exhale: Base release 11.000.00
//
// Revision 10.0 1998/07/20 17:52:34 aips2adm
// exhale: Base release 10.000.00
//
// Revision 9.3 1998/06/09 21:29:24 hr
// Fixed several type conversion warnings.
//
// Revision 9.2 1998/05/04 20:31:10 hr
// Removed an unused variable (dmy).
//
// Revision 9.1 1998/05/01 21:30:42 hr
// First attempt to deal with large colormaps - limit max width to 256.
// Use aipsview's colormap rather than root's.
//
// Revision 9.0 1997/08/25 21:25:37 aips2adm
// exhale: Base release 09.000.00
//
// Revision 8.0 1997/02/20 03:15:38 aips2adm
// exhale: Base release 08.000.00
//
// Revision 7.3 1997/02/05 17:32:58 hr
// The __P, g++ and math.h problem.
//
// Revision 7.2 1996/12/12 05:54:56 droberts
// Final update from monet archive.
//
// Revision 1.3 1996/08/19 20:04:04 pixton
// removed unused variables - now g++ -Wall warning free
//
// Revision 1.2 1996/08/14 17:29:00 hr
// Changes to remove g++ warnings (from bglenden).
//
// Revision 1.1 1996/07/11 21:31:21 pixton
// Automated Checkin
//
// Revision 1.16 1996/06/18 18:45:53 pixton
// Copyright Update
//
// Revision 1.15 1996/04/16 16:24:28 hr
// Some compilers can't handle initializations like:
// char * buffer[] = { "A","B","C" };
// Changing to "static char *..." works.
//
// Revision 1.14 1996/03/29 17:28:33 hr
// palette_ needed to be ref'ed and unref'ed.
//
// Revision 1.13 1996/03/14 18:13:12 baker
// Updated to derive from AvXColorApp rather than AvApp.
//
// Revision 1.12 1996/03/13 16:00:01 hr
// Moved "Options" submenu to last.
//
// Revision 1.11 1996/03/05 17:43:03 hr
// The label gadget for "Palette:" was using the wrong XmString creation
// routine and throwing away the resultant XmString.
//
// Revision 1.10 1995/10/27 19:10:01 hr
// Added a bunch of resources to widgets using our private colormap to try
// and avoid warning about not being able to allocate a color.
//
// Revision 1.9 1995/09/20 20:03:06 baker
// Release Beta 1.0
//
// Revision 1.9 1995/09/20 01:56:34 baker
// Release Beta 1.0
//
// Revision 1.8 1995/08/11 20:46:44 baker
// Added constructor to take fallback resources.
//
// Revision 1.7 1995/08/03 16:43:51 hr
// Changes to allow multiple user named palettes and to notify callbacks
// when changes are made.
//
// Revision 1.6 1995/07/18 17:27:17 hr
// 'Fixed' g++ warnings. Mostly don't do "for(int i...)".
//
// Revision 1.5 1995/07/17 21:32:53 hr
// Added destructor.
//
// Revision 1.4 1995/05/03 21:59:00 pixton
// fixed some problems with the colormap editor initialization.
// fixed bug preventing Pseudo-Contour from generating its RGB
// version after maps are tied together (as in greyscale-RGB mode)
//
// Revision 1.3 1995/04/17 17:38:10 pixton
// colormap now initialized to the "Rainbow" palette.
//
// Revision 1.2 1995/03/21 14:35:15 pixton
// Corrected map ruler line color. Previously used one of the colors
// in the modifiable map.
//
// Revision 1.1 1995/03/16 19:45:22 pixton
// Initial revision
//
//
//---------------------------------------------------------------------------
//
// ---------------------------
// | |
// | "Map" |
// |---------------------------|
// | |
// | "funcEditor 0" |
// | |
// |---------------------------|
// | |
// | "funcEditor 1" |
// | |
// |---------------------------|
// | |
// | "funcEditor 2" |
// | |
// |---------------------------|
// | |
// | "funcEditor 3" |
// | |
// |---------------------------|
//
#include <iostream.h>
#include <stdio.h>
//#include <malloc.h>
//#if defined(__GNUC__) && defined(__P) && !defined(__linux__)
//#undef __P
//#endif
#include <math.h>
#include <stdlib.h>
#include <Xm/Xm.h>
#include <Xm/BulletinB.h>
#include <Xm/DrawingA.h>
#include <Xm/FileSB.h>
#include <Xm/Form.h>
#include <Xm/Label.h>
#include <Xm/Label.h>
#include <Xm/PushB.h>
#include <Xm/RowColumn.h>
#include <Xm/Scale.h>
#include <Xm/SelectioB.h>
#include <Xm/Separator.h>
#include <Xm/TextF.h>
#include <Xm/ToggleB.h>
#include <X11/cursorfont.h>
#include <X11/Xlib.h>
#include <X11/IntrinsicP.h>
#include "AvColormap.h"
#include "AvColormapEditor.h"
#include "AvFunctionEditor.h"
#include "AvPointList2D.h"
#include "AvXPalette.h"
#include "AvApp.h"
#include <string.h>
#include <X11/keysym.h> // After AvColormapEditor.h
/*
String AvColormapEditor::fallback_resources[] =
{
"*workArea.panel.mapMgr.map.height: 60",
"*workArea.panel.graph1Mgr.height: 60",
"*workArea.panel.graph2Mgr.height: 60",
"*workArea.panel.graph3Mgr.height: 60",
"*workArea.panel.graph4Mgr.height: 60",
NULL
};
*/
#define MAP_HEIGHT 60
const char * AvColormapEditor::rgbGraphNames[] = { "R", "G", "B" };
const char * AvColormapEditor::hsvGraphNames[] = { "H", "S", "V" };
AvColormapEditor::AvColormapEditor
(char * appClass, int & argc, String * argv)
: AvXColorApp (appClass, argc, argv, NULL)
{
init (TRUE);
initMap();
show ();
XtAppMainLoop (appContext_);
}
AvColormapEditor::AvColormapEditor
(char * appClass, int & argc, String * argv, const char * fallbacks[])
: AvXColorApp (appClass, argc, argv, fallbacks)
{
init (TRUE);
initMap();
show ();
XtAppMainLoop (appContext_);
}
AvColormapEditor::AvColormapEditor (Widget parent, int buildInsideParent)
: AvXColorApp (parent, buildInsideParent)
{
init (FALSE);
initMap();
}
#define CBTEST_
#ifdef CBTEST
// Routines to help test multiple colormaps.
char *cbreason(const int n)
{static char buf[132];
buf[0] = '\0';
if(n & AvConductor::Destroyed)
strcat(buf, "Destroyed | ");
if(n & AvColormap::COMPONENT_CHANGED)
strcat(buf, "COMPONENT_CHANGED | ");
if(n & AvColormap::NAME_CHANGED)
strcat(buf, "NAME_CHANGED | ");
if(n & AvColormap::LENGTH_CHANGED)
strcat(buf, "LENGTH_CHANGED | ");
if(n & AvColormap::MODEL_CHANGED)
strcat(buf, "MODEL_CHANGED");
return buf;
}
char *cereason(const int n)
{static char buf[132];
buf[0] = '\0';
if(n & AvConductor::Destroyed)
strcat(buf, "Destroyed | ");
if(n & AvColormapEditor::NEW_COLORMAP)
strcat(buf, "NEW_COLORMAP");
return buf;
}
static void tst2(XtPointer , AvConductor *c, XtPointer )
{
AvColormap *map = (AvColormap *) c;
int mask = map->callbackReason();
printf("%s:: Reason: %s (0x%X)\n", map->name(),cbreason(mask), mask);
}
static void tst(XtPointer , AvConductor *c, XtPointer )
{
AvColormapEditor *ce = (AvColormapEditor *) c;
AvCECmap *map = ce->getLastColormap();
int mask = ce->callbackReason();
static Boolean first=TRUE;
if((mask & AvColormapEditor::COLORMAP_DESTROYED) != 0)
printf("%s Destroyed\n", map->name());
else
if((mask & AvColormapEditor::MAP_CHANGED) != 0)
printf("Using %s\n", ce->currentCmap()->name());
else
{ printf("%s Created\n", map->name());
int cbmask = AvColormap::COMPONENT_CHANGED |
AvColormap::NAME_CHANGED |
AvColormap::LENGTH_CHANGED |
AvColormap::MODEL_CHANGED |
AvConductor::Destroyed;
map->addCallback( tst2, cbmask, NULL, NULL);
if(first)
{ map = ce->getColormap(0);
map->addCallback( tst2, cbmask, NULL, NULL);
first = FALSE;
}
}
}
#endif
static const int MAXCMAPS=32; // Maximum # of cmaps we'll allow.
static int colormapCount=0; // # of colormaps 'new'd. Used for new names.
AvCECmap::AvCECmap(const int maxlen, const int len,
const char *name, Widget menuitem) :
AvColormap(maxlen, len)
{
mi_ = menuitem;
pan_ = 0.0;
zoom_ = 1.0;
setName(name); // Make sure widget label & name match.
}
AvCECmap::~AvCECmap()
{
//printf("Deleting widget %s (0x%X)\n", XtName(mi_), mi_);
XtUnmanageChild(mi_);
XtDestroyWidget(mi_);
}
void AvCECmap::setName(const char *newName)
{
if(newName == NULL)
return;
if(strcmp(newName, name()) != 0)
{ char *n = new char[strlen(newName)+1];
strcpy(n, newName);
AvUserComp::setLabelString(mi_, n);
delete [] n;
AvColormap::setName(newName);
}
}
void AvColormapEditor::show()
{
AvUserComp::show();
for (int i = 0; i < 4; i++) functionEditors_[i]->graphWidth(256);
// setSize(267, 434);
setSize(267, 464);
centerMap();
updateMap(FALSE);
drawMapRuler();
}
#ifdef CHANGENCOLORS
static char *USE_AVAILABLE = "Use available colors";
static char *USE_NOT_BW = "Use all but B/W";
static char *USE_ALL = "Use all colors";
#endif
//
// INITIALIZATION ONLY FUNCTION!!!!!!!!
//
void AvColormapEditor::buildMenus (int standAloneApp)
{
// make the editor's menu bar
AvMenu * fileMenu = new AvMenu (10);
fileMenu->add ("New", PUSH_BUTTON, FILE_MENU);
fileMenu->add ("Open...", PUSH_BUTTON, FILE_MENU);
fileMenu->add ("Save", PUSH_BUTTON, FILE_MENU);
fileMenu->add ("Save As...", PUSH_BUTTON, FILE_MENU);
fileMenu->add ("Delete", PUSH_BUTTON, FILE_MENU);
fileMenu->add ("", SEPARATOR);
if (standAloneApp)
fileMenu->add ("Quit", PUSH_BUTTON, FILE_MENU);
else
fileMenu->add ("Close", PUSH_BUTTON, FILE_MENU);
AvMenu * optionMenu = new AvMenu (15);
optionMenu->add ("Gray", PUSH_BUTTON, OPTIONS_MENU);
optionMenu->add ("RGB", PUSH_BUTTON, OPTIONS_MENU);
optionMenu->add ("HSV", PUSH_BUTTON, OPTIONS_MENU);
optionMenu->add ("", SEPARATOR);
optionMenu->add ("Show Alpha", PUSH_BUTTON, OPTIONS_MENU);
optionMenu->add ("", SEPARATOR);
optionMenu->add ("Reset Map", PUSH_BUTTON, OPTIONS_MENU);
if(readonlyColormap())
optionMenu->add ("Auto Update", TOGGLE_BUTTON, OPTIONS_MENU, NULL, autoUpdate_);
#ifdef CHANGENCOLORS
optionMenu->add ("", SEPARATOR);
optionMenu->add (USE_AVAILABLE, PUSH_BUTTON, OPTIONS_MENU);
optionMenu->add (USE_NOT_BW, PUSH_BUTTON, OPTIONS_MENU);
optionMenu->add (USE_ALL, PUSH_BUTTON, OPTIONS_MENU);
#endif
paletteMenu = new AvMenu (11 + MAXCMAPS);
paletteMenu->add ("Grayscale", PUSH_BUTTON, PALETTES_MENU);
paletteMenu->add ("Rainbow", PUSH_BUTTON, PALETTES_MENU);
paletteMenu->add ("Logarithmic", PUSH_BUTTON, PALETTES_MENU);
paletteMenu->add ("Pseudo-Contour", PUSH_BUTTON, PALETTES_MENU);
paletteMenu->add ("Multiple Ps-Contour", PUSH_BUTTON, PALETTES_MENU);
paletteMenu->add ("", SEPARATOR);
paletteMenu->add ("Copy to Clipboard", PUSH_BUTTON, PALETTES_MENU);
paletteMenu->add ("Copy from Clipboard", PUSH_BUTTON, PALETTES_MENU);
paletteMenu->add ("", SEPARATOR);
AvMenu * mainMenu = new AvMenu (3);
mainMenu->add ("File", SUBMENU_BUTTON, 0, fileMenu);
mainMenu->add ("Palettes", SUBMENU_BUTTON, 0, paletteMenu);
mainMenu->add ("Options", SUBMENU_BUTTON, 0, optionMenu);
makeMainMenu (mainMenu); // Inherited from AvApp
}
//
// Function values changed callbacks
//
void AvColormapEditor::graph0ChangedCB(AvColormapEditor * ce)
{
if (!ce->hsv() && ce->greyScale()) ce->relayFunctionData(0);
ce->updateMap();
ce->drawMapRuler();
}
void AvColormapEditor::graph1ChangedCB(AvColormapEditor * ce)
{
if (!ce->hsv() && ce->greyScale()) ce->relayFunctionData(1);
ce->updateMap();
ce->drawMapRuler();
}
void AvColormapEditor::graph2ChangedCB(AvColormapEditor * ce)
{
if (!ce->hsv() && ce->greyScale()) ce->relayFunctionData(1);
ce->updateMap();
ce->drawMapRuler();
}
void AvColormapEditor::graph3ChangedCB(AvColormapEditor * ce)
{
ce->updateMap();
ce->drawMapRuler();
}
void AvColormapEditor::buttonReleasedCB(AvColormapEditor * ce)
{
ce->changeDone();
}
// Called when some operation that changed the colormap has finished. If we're
// not in auto update mode and the colormap is readonly, this invokes any
// callbacks that are attached.
void AvColormapEditor::changeDone()
{
if(!autoUpdate() && readonlyColormap())
{ invokeCallbacks(MAP_EDITED);
}
}
//
// Function mode changed callbacks
//
void AvColormapEditor::graph0ModeChangedCB(AvColormapEditor * ce)
{ if (!ce->hsv() && ce->greyScale()) ce->relayModeChange(0); }
void AvColormapEditor::graph1ModeChangedCB(AvColormapEditor * ce)
{ if (!ce->hsv() && ce->greyScale()) ce->relayModeChange(1); }
void AvColormapEditor::graph2ModeChangedCB(AvColormapEditor * ce)
{ if (!ce->hsv() && ce->greyScale()) ce->relayModeChange(2); }
void AvColormapEditor::graph0RepeatChangedCB(AvColormapEditor * ce)
{ if (!ce->hsv() && ce->greyScale()) ce->relayRepeatChange(0); }
void AvColormapEditor::graph1RepeatChangedCB(AvColormapEditor * ce)
{ if (!ce->hsv() && ce->greyScale()) ce->relayRepeatChange(1); }
void AvColormapEditor::graph2RepeatChangedCB(AvColormapEditor * ce)
{ if (!ce->hsv() && ce->greyScale()) ce->relayRepeatChange(2); }
// Default "ColorView"
void AvColormapEditor::init (int standAloneApp)
{
palette_ = AvXColorApp::palette();
palette_->ref();
alpha_ = 0;
greyScale_ = 0;
active_ = 0;
hsv_ = 1;
lastPointerX_ = 0; // Not necessary, but complete
lastPointerY_ = 0;
grabbed_ = -1; // no control point grabbed
ignoreUpdateRequest_ = FALSE;
autoUpdate_ = FALSE; // Should be FALSE for PC and user's choice for
// TC colormaps.
busy_ = False; // Set to true to prevent recursion.
map_ = NULL;
buildMenus (standAloneApp);
strcpy (paletteDirectory_, getStringResource ("PaletteDirectory"));
XtVaSetValues (AvApp::parentWidget_, XmNtitle, "ColorView", NULL);
//
// Map Parameters Set
//
cursorShape_ = XC_pencil;
cursor_ = XCreateFontCursor (display_, cursorShape_);
// declare and set values needed for graph, map, and buttons draw areas
XGCValues gcv;
// XColor unused;
// gcv.background = BlackPixelOfScreen (screen_);
gcv.background = AvApp::blackPixel();
// gc_ = XCreateGC (display_, RootWindowOfScreen (screen_), GCBackground, &gcv);
gc_ = XCreateGC (display_, AvApp::referenceWindow(), GCBackground, &gcv);
gcv.function = GXor;
// xorGc_ = XCreateGC (display_, RootWindowOfScreen (screen_), GCFunction, &gcv);
xorGc_ = XCreateGC (display_, AvApp::referenceWindow(), GCFunction, &gcv);
// colormap to just get XColors needed for panel
Colormap colormap = AvXColorApp::colormap();
black_.flags = 0; // These are to keep memory checkers happy.
black_.pad = 0;
black_.red = black_.green = black_.blue = 0;
#if 0
XAllocNamedColor (display_, colormap, "black", &black_, &unused);
XAllocNamedColor (display_, colormap, "red", &RGBA_[0], &unused);
XAllocNamedColor (display_, colormap, "green4", &RGBA_[1], &unused);
XAllocNamedColor (display_, colormap, "blue", &RGBA_[2], &unused);
XAllocNamedColor (display_, colormap, "yellow", &yellow_, &unused);
XAllocNamedColor (display_, colormap, "gray80", &graphBackground_, &unused);
#else
{ unsigned long vindex, pindex;
palette_->allocNamedColor("black", vindex, pindex);
black_.pixel = pindex;
palette_->allocNamedColor("red", vindex, pindex);
RGBA_[0].pixel = pindex;
palette_->allocNamedColor("green4", vindex, pindex);
RGBA_[1].pixel = pindex;
palette_->allocNamedColor("blue", vindex, pindex);
RGBA_[2].pixel = pindex;
palette_->allocNamedColor("yellow", vindex, pindex);
yellow_.pixel = pindex;
palette_->allocNamedColor("gray80", vindex, pindex);
graphBackground_.pixel = pindex;
}
#endif
RGBA_[3] = black_;
//--------------------------------------------------------------------------
//
// Build Motif Panel
//
// Uses palette_->availableColors() to set the starting width of both the
// function to use and the graph. The one2one_ setting controls how the
// graph reacts to X axis resizing.
//
// baseWidget_ is an XmForm!!
//
//--------------------------------------------------------------------------
#define NOFIX256
#ifdef FIX256
int funcWidth = 256;
palette_->useSegment(2);
#else
int funcWidth = palette_->availableColors();
#endif
mapZoom_ = 1.0;
mapPan_ = funcWidth / 2.0;
XtVaSetValues(baseWidget_,
XmNtopAttachment, XmATTACH_FORM,
XmNbottomAttachment, XmATTACH_FORM,
XmNleftAttachment, XmATTACH_FORM,
XmNrightAttachment, XmATTACH_FORM,
XmNnoResize, False,
XmNresizePolicy, XmRESIZE_ANY,
XmNcolormap, colormap, // (not supposed to be settable here).
NULL);
//-----workArea_
workArea_ = XtVaCreateManagedWidget
("workArea", xmFormWidgetClass, baseWidget_,
XmNtopAttachment, XmATTACH_FORM,
XmNbottomAttachment, XmATTACH_FORM,
XmNleftAttachment, XmATTACH_FORM,
XmNrightAttachment, XmATTACH_FORM,
XmNnoResize, False,
XmNresizePolicy, XmRESIZE_ANY,
XmNcolormap, colormap, // Use our colormap.
NULL);
XtVaSetValues (mainWindow_, XmNworkWindow, workArea_, NULL);
//-----workArea_ | panel_
panel_ = XtVaCreateManagedWidget
("panel", xmRowColumnWidgetClass, workArea_,
XmNtopAttachment, XmATTACH_FORM,
XmNbottomAttachment, XmATTACH_FORM,
XmNleftAttachment, XmATTACH_FORM,
XmNrightAttachment, XmATTACH_FORM,
XmNresizeHeight, True,
XmNresizeWidth, True, NULL);
// A place to display the name of the current colormap
Widget nameMgr_ = XtVaCreateManagedWidget
("nameMgr", xmFormWidgetClass, panel_,
NULL);
char *palstr = Strdup("Palette:");
XmString xstr = XmStringCreateLocalized(palstr);
Widget colormapLabelW = XtVaCreateManagedWidget
("CmapLabel", xmLabelWidgetClass, nameMgr_,
XmNtopAttachment, XmATTACH_FORM,
XmNleftAttachment, XmATTACH_FORM,
XmNlabelString, xstr,
NULL);
delete [] palstr;
XmStringFree(xstr);
colormapNameW_ = XtVaCreateManagedWidget
("CmapName", xmTextFieldWidgetClass, nameMgr_,
XmNtopAttachment, XmATTACH_FORM,
XmNleftAttachment, XmATTACH_WIDGET,
XmNleftWidget, colormapLabelW,
// XmNrightAttachment, XmATTACH_WIDGET,
// XmNrightWidget, closeButton,
XmNrightAttachment, XmATTACH_FORM,
XmNhighlightThickness, 0,
XmNshadowThickness, 1,
XmNvalue, "Clipboard",
NULL);
XtAddEventHandler(colormapNameW_, KeyReleaseMask, FALSE,
(XtEventHandler) &AvColormapEditor::changeNameCB,
(XtPointer) this);
//-----workArea_ | panel_ | mapMgr
mapMgr_ = XtVaCreateManagedWidget
("mapMgr", xmFormWidgetClass, panel_,
XmNheight, MAP_HEIGHT,
NULL);
//-----workArea_ | panel_ | mapMgr | map_
// Pixel dmy = WhitePixelOfScreen(XtScreen(mapMgr_));
int mapwidth = funcWidth;
if(mapwidth > 256) mapwidth = 256;
map_ = XtVaCreateManagedWidget
("map", xmDrawingAreaWidgetClass, mapMgr_,
// XmNwidth, funcWidth,
XmNwidth, mapwidth,
XmNheight, 60, // Fallbacks not active!?!?!?
XmNforeground, black_.pixel, // don't remove
XmNbackground, graphBackground_.pixel, // don't remove
XmNcolormap, AvXColorApp::colormap(),
XmNresizePolicy, XmRESIZE_GROW, // Will Change!
#if 0
/* These are just to help keep away messages like:
Warning: Cannot allocate colormap entry for "gray"
*/
XmNforeground, dmy,
XmNborderWidth, 0,
XmNborderColor, dmy,
XmNbottomShadowColor, dmy,
XmNhighlightColor, dmy,
XmNtopShadowColor, dmy,
#endif
NULL);
static char graphTranslations[] =
"<BtnDown>: DrawingAreaInput() \n"
"<BtnUp>: DrawingAreaInput() \n"
"<BtnMotion>: DrawingAreaInput()";
XtAddCallback (map_, XmNexposeCallback,
(XtCallbackProc) &AvColormapEditor::mapExposedCB,
(XtPointer) this);
XtOverrideTranslations (map_,
XtParseTranslationTable (graphTranslations));
XtAddCallback (map_, XmNinputCallback,
(XtCallbackProc) &AvColormapEditor::mapInputCB,
(XtPointer) this);
XtAddEventHandler (map_, EnterWindowMask, 1,
(XtEventHandler) &AvColormapEditor::mapEnterEH,
(XtPointer) this);
XtAddEventHandler (map_, LeaveWindowMask, 1,
(XtEventHandler) &AvColormapEditor::mapLeaveEH,
(XtPointer) this);
//-----workArea_ | panel_ | mapRulMgr
Widget mapRulMgr = XtVaCreateManagedWidget
("mapMgr", xmRowColumnWidgetClass, panel_,
NULL);
//-----workArea_ | panel_ | mapRulMgr | mapRuler_
mapRuler_ = XtVaCreateManagedWidget
("mapRuler", xmDrawingAreaWidgetClass, mapRulMgr,
// XmNwidth, funcWidth,
XmNwidth, mapwidth,
XmNheight, 20,
XmNforeground, black_.pixel,
XmNbackground, graphBackground_.pixel,
XmNresizePolicy, XmRESIZE_GROW,
NULL);
XtAddCallback (mapRuler_, XmNexposeCallback,
(XtCallbackProc) &AvColormapEditor::mapRulerExposedCB,
(XtPointer) this);
//printf("map size = <%d, %d>\n", mapWidth(), mapHeight());
static const char * feLabels[] = {"H", "S", "V", "A"};
for (int i = 0; i < 4; i++)
{
// Required to keep the graph centered (no can do with xmForm)
// and to identify the graph below since funcEditor not an X widget
//
//-----workArea_ | panel_ | graph<i>Mgr
char name[20]; sprintf(name, "graph%dMgr", i);
graphMgr_[i] = XtVaCreateManagedWidget
(name, xmRowColumnWidgetClass, panel_,
XmNuserData, (XtPointer) i,
XmNresizeHeight, True,
XmNresizeWidth, True,
XmNleftAttachment, XmATTACH_FORM,
XmNrightAttachment, XmATTACH_FORM,
NULL);
// for graph enter - change cursor color and shape
XtAddEventHandler (graphMgr_[i], EnterWindowMask, 1,
(XtEventHandler) &AvColormapEditor::graphMgrEnterEH,
(XtPointer) this);
//-----workArea_ | panel_ | graph<i>Mgr | graph
functionEditors_[i] = new AvFunctionEditor(graphMgr_[i],
black_.pixel,
graphBackground_.pixel,
yellow_.pixel,
black_.pixel,
funcWidth);
functionEditors_[i]->label(feLabels[i]); // Set the label text
functionEditors_[i]->labelColor(RGBA_[i].pixel); // Set the label color
functionEditors_[i]->userData((XtPointer) this);
}
functionEditors_[0]->valueChangedCallback((void (*)(XtPointer)) graph0ChangedCB);
functionEditors_[1]->valueChangedCallback((void (*)(XtPointer)) graph1ChangedCB);
functionEditors_[2]->valueChangedCallback((void (*)(XtPointer)) graph2ChangedCB);
functionEditors_[3]->valueChangedCallback((void (*)(XtPointer)) graph3ChangedCB);
functionEditors_[0]->modeChangedCallback((void (*)(XtPointer)) graph0ModeChangedCB);
functionEditors_[1]->modeChangedCallback((void (*)(XtPointer)) graph1ModeChangedCB);
functionEditors_[2]->modeChangedCallback((void (*)(XtPointer)) graph2ModeChangedCB);
functionEditors_[0]->repeatChangedCallback((void (*)(XtPointer)) graph0RepeatChangedCB);
functionEditors_[1]->repeatChangedCallback((void (*)(XtPointer)) graph1RepeatChangedCB);
functionEditors_[2]->repeatChangedCallback((void (*)(XtPointer)) graph2RepeatChangedCB);
// If colormap is read only, data windows typically only get updated when mouse
// button is released. Don't bother with calling overhead when colormap is read write.
if(readonlyColormap())
{ functionEditors_[0]->buttonReleaseCallback((void (*)(XtPointer)) buttonReleasedCB);
functionEditors_[1]->buttonReleaseCallback((void (*)(XtPointer)) buttonReleasedCB);
functionEditors_[2]->buttonReleaseCallback((void (*)(XtPointer)) buttonReleasedCB);
}
if (!alpha_)
{
XtUnmanageChild(graphMgr_[3]);
}
}
//
// MENU RESPONSE
//
void AvColormapEditor::processMenu (char * buttonName, int choice, Widget mb)
{
// Routines that change the colormap (via the function editors) will
// result in changeNotify() being called several times. This turns off
// notification so it's done only once at the bottom.
disableNotify();
switch (choice)
{
case FILE_MENU:
if (!strcmp (buttonName, "New"))
useCmap(newCmap());
if (!strcmp (buttonName, "Open..."))
getFileNameFromUser ((AvProc) &AvColormapEditor::openMap,
"Select a palette", paletteDirectory_);
if (!strcmp (buttonName, "Save"))
{ if( (paletteDirectory_ == NULL) ||
(strcmp(paletteDirectory_, "NULL")==0))
saveColorMap(currentCmap()->name());
else
{int len = (int)(strlen(currentCmap()->name())
+
strlen(paletteDirectory_)) + 2;
char *name = new char[len];
strcpy(name, paletteDirectory_);
strcat(name, "/");
strcat(name, currentCmap()->name());
saveColorMap(name);
delete [] name;
}
}
else
if (!strcmp (buttonName, "Delete"))
{ //printf("[ ] New File\n");
deleteCurrentCmap();
}
else
if (!strcmp (buttonName, "Save As..."))
getFileNameFromUser ((AvProc) &AvColormapEditor::saveMap,
"Specify file name", paletteDirectory_);
if (!strcmp (buttonName, "Close"))
hide ();
if (!strcmp (buttonName, "Quit")) exit(0);
break;
case OPTIONS_MENU:
if (!strcmp (buttonName, "Gray")) grayScaleMode();
else
if (!strcmp (buttonName, "RGB")) rgbMode();
else
if (!strcmp (buttonName, "HSV")) hsvMode();
else
if (!strcmp (buttonName, "Show Alpha")) alphaMode(mb);
else
if (!strcmp (buttonName, "Reset Map"))
{
mapPan_ = nColors()/2.0;
mapZoom_ = 1.0;
updateMap();
drawMapRuler();
changeDone();
}
else
if (!strcmp (buttonName, "Auto Update"))
{ if(XmToggleButtonGetState(mb))
autoUpdate_ = TRUE;
else
autoUpdate_ = FALSE;
}
// resizeColors() is a member function which orders the ColormapEditor to
// adjust itself to support the integer parameter # of colors.
//
// For now the width of the function editors reflects the number of colors
// available.
#ifdef CHANGENCOLORS
else
if (!strcmp (buttonName, USE_AVAILABLE))
{ // For some reason, this doesn't work, but useSegment(1) does.
palette_->useSegment(0);
resetColors();
}
else
if (!strcmp (buttonName, USE_NOT_BW))
{
palette_->useSegment(1);
resetColors();
}
else
if (!strcmp (buttonName, USE_ALL))
{
palette_->useSegment(2);
resetColors();
}
#endif
break;
case PALETTES_MENU:
if (!strcmp (buttonName, "Copy to Clipboard"))
{ // Copy current values to Clipboard.
saveColormap(colormaps_[0]);
}
else
if (!strcmp (buttonName, "Copy from Clipboard"))
{ // Copy Clipboard to current.
restoreColormap(colormaps_[0], FALSE);
changeDone();
}
else
if(loadPalette(buttonName)) // Predefined palette.
{
redrawGraphs(); // Redraw & save.
changeDone();
}
else
{ int cmi; // User palette.
XtVaGetValues (mb, XmNuserData, &cmi, NULL);
useCmap(cmi);
redrawGraphs(FALSE); // Redraw/don't save.
changeDone();
}
// redrawGraphs(FALSE);
// refresh(FALSE);
break;
default:
AvXColorApp::processMenu (buttonName, choice, mb);
}
enableNotify();
}
#ifdef CHANGENCOLORS
// Set number of colors to use to n. If n<= 0, query the palette.
void AvColormapEditor::resetColors (const int num)
{
int n, i;
// # of colors to use.
n = (num <= 0) ? palette_->availableColors() : num;
printf("%d\n", n);
// Tell each function editor's ramp function to resize itself.
for(i=0; i< sizeof(functionEditors_)/sizeof(*functionEditors_); i++)
functionEditors_[i]->func()->resize(n);
// Now, redisplay.
redrawGraphs();
/* Need to get list of windows and:
1) Tell them data has been modified.
2) Tell them to resdisplay.
*/
}
#else
void AvColormapEditor::resetColors (const int ) {}
#endif
// Called only after init() by constructor
//
// initMap needs to initialize the map without triggering callbacks. The
// solution is to build temporary rampFunctions to compute the rainbow