This repository has been archived by the owner on Apr 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImpressionistUI.cpp
1006 lines (859 loc) · 37 KB
/
ImpressionistUI.cpp
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
//
// impressionistUI.h
//
// The user interface part for the program.
//
#include <FL/fl_ask.h>
#include <math.h>
#include "ImageUtils.hpp"
#include "impressionistDoc.h"
#include "impressionistUI.h"
/*
//------------------------------ Widget Examples
------------------------------------------------- Here is some example code for
all of the widgets that you may need to add to the project. You can copy and
paste these into your code and then change them to make them look how you want.
Descriptions for all of the widgets here can be found in links on the fltk help
session page.
//---------Window/Dialog and Menubar-----------------------------------
//----To install a window--------------------------
Fl_Window* myWindow = new Fl_Window(600, 300, "MyWindow");
myWindow->user_data((void*)(this)); // record self to be
used by static callback functions
// install menu bar
myMenubar = new Fl_Menu_Bar(0, 0, 600, 25);
Fl_Menu_Item ImpressionistUI::myMenuItems[] = {
{ "&File", 0, 0, 0, FL_SUBMENU },
{ "&Load...", FL_ALT + 'l', (Fl_Callback
*)ImpressionistUI::cb_load }, { "&Save...", FL_ALT + 's', (Fl_Callback
*)ImpressionistUI::cb_save }.
{ "&Quit", FL_ALT + 'q',
(Fl_Callback *)ImpressionistUI::cb_exit }, { 0 }, { "&Edit", 0, 0, 0,
FL_SUBMENU }, { "&Copy",FL_ALT + 'c', (Fl_Callback *)ImpressionistUI::cb_copy,
(void *)COPY }, { "&Cut", FL_ALT + 'x', (Fl_Callback
*)ImpressionistUI::cb_cut, (void *)CUT }, { "&Paste", FL_ALT + 'v',
(Fl_Callback *)ImpressionistUI::cb_paste, (void *)PASTE }, { 0 }, { "&Help",
0, 0, 0, FL_SUBMENU }, { "&About", FL_ALT + 'a', (Fl_Callback
*)ImpressionistUI::cb_about }, { 0 }, { 0 }
};
myMenubar->menu(myMenuItems);
m_mainWindow->end();
//----The window callback--------------------------
// One of the callbacks
void ImpressionistUI::cb_load(Fl_Menu_* o, void* v)
{
ImpressionistDoc *pDoc=whoami(o)->getDocument();
char* newfile = fl_file_chooser("Open File?", "*.bmp",
pDoc->getImageName() ); if (newfile != NULL) { pDoc->loadImage(newfile);
}
}
//------------Slider---------------------------------------
//----To install a slider--------------------------
Fl_Value_Slider * mySlider = new Fl_Value_Slider(10, 80, 300, 20, "My
Value"); mySlider->user_data((void*)(this)); // record self to be used by
static callback functions mySlider->type(FL_HOR_NICE_SLIDER);
mySlider->labelfont(FL_COURIER);
mySlider->labelsize(12);
mySlider->minimum(1);
mySlider->maximum(40);
mySlider->step(1);
mySlider->value(m_nMyValue);
mySlider->align(FL_ALIGN_RIGHT);
mySlider->callback(cb_MyValueSlides);
//----The slider callback--------------------------
void ImpressionistUI::cb_MyValueSlides(Fl_Widget* o, void* v)
{
((ImpressionistUI*)(o->user_data()))->m_nMyValue=int(
((Fl_Slider *)o)->value() ) ;
}
//------------Choice---------------------------------------
//----To install a choice--------------------------
Fl_Choice * myChoice = new Fl_Choice(50,10,150,25,"&myChoiceLabel");
myChoice->user_data((void*)(this)); // record self to be used by
static callback functions Fl_Menu_Item ImpressionistUI::myChoiceMenu[3+1] = {
{"one",FL_ALT+'p', (Fl_Callback *)ImpressionistUI::cb_myChoice, (void
*)ONE},
{"two",FL_ALT+'l', (Fl_Callback *)ImpressionistUI::cb_myChoice, (void
*)TWO},
{"three",FL_ALT+'c', (Fl_Callback *)ImpressionistUI::cb_myChoice,
(void *)THREE}, {0}
};
myChoice->menu(myChoiceMenu);
myChoice->callback(cb_myChoice);
//-----The choice callback-------------------------
void ImpressionistUI::cb_myChoice(Fl_Widget* o, void* v)
{
ImpressionistUI* pUI=((ImpressionistUI *)(o->user_data()));
ImpressionistDoc* pDoc=pUI->getDocument();
int type=(int)v;
pDoc->setMyType(type);
}
//------------Button---------------------------------------
//---To install a button---------------------------
Fl_Button* myButton = new Fl_Button(330,220,50,20,"&myButtonLabel");
myButton->user_data((void*)(this)); // record self to be used by
static callback functions myButton->callback(cb_myButton);
//---The button callback---------------------------
void ImpressionistUI::cb_myButton(Fl_Widget* o, void* v)
{
ImpressionistUI* pUI=((ImpressionistUI*)(o->user_data()));
ImpressionistDoc* pDoc = pUI->getDocument();
pDoc->startPainting();
}
//---------Light Button------------------------------------
//---To install a light button---------------------
Fl_Light_Button* myLightButton = new
Fl_Light_Button(240,10,150,25,"&myLightButtonLabel");
myLightButton->user_data((void*)(this)); // record self to be used by
static callback functions myLightButton->callback(cb_myLightButton);
//---The light button callback---------------------
void ImpressionistUI::cb_myLightButton(Fl_Widget* o, void* v)
{
ImpressionistUI *pUI=((ImpressionistUI*)(o->user_data()));
if (pUI->myBool==TRUE) pUI->myBool=FALSE;
else pUI->myBool=TRUE;
}
//----------Int Input--------------------------------------
//---To install an int input-----------------------
Fl_Int_Input* myInput = new Fl_Int_Input(200, 50, 5, 5, "&My Input");
myInput->user_data((void*)(this)); // record self to be used by static
callback functions myInput->callback(cb_myInput);
//---The int input callback------------------------
void ImpressionistUI::cb_myInput(Fl_Widget* o, void* v)
{
((ImpressionistUI*)(o->user_data()))->m_nMyInputValue=int(
((Fl_Int_Input *)o)->value() );
}
//------------------------------------------------------------------------------------------------
*/
//------------------------------------- Help Functions
//--------------------------------------------
//------------------------------------------------------------
// This returns the UI, given the menu item. It provides a
// link from the menu items to the UI
//------------------------------------------------------------
ImpressionistUI *ImpressionistUI::whoami(Fl_Menu_ *o) {
return ((ImpressionistUI *)(o->parent()->user_data()));
}
//--------------------------------- Callback Functions
//--------------------------------------------
//------------------------------------------------------------------
// Brings up a file chooser and then loads the chosen image
// This is called by the UI when the load image menu item is chosen
//------------------------------------------------------------------
void ImpressionistUI::cb_load_image(Fl_Menu_ *o, void *v) {
ImpressionistDoc *pDoc = whoami(o)->getDocument();
#if PROJ_DEBUG
char *newfile =
"/Users/dannylau/Program/COMP4411-Impressionist/images/babyraptor.bmp";
#else
char *newfile = fl_file_chooser("Open File?", "*.bmp", pDoc->getImageName());
#endif
if (newfile != NULL) {
pDoc->loadImage(newfile);
}
}
//------------------------------------------------------------------
// Brings up a file chooser and then saves the painted image
// This is called by the UI when the save image menu item is chosen
//------------------------------------------------------------------
void ImpressionistUI::cb_save_image(Fl_Menu_ *o, void *v) {
ImpressionistDoc *pDoc = whoami(o)->getDocument();
char *newfile = fl_file_chooser("Save File?", "*.bmp", "save.bmp");
if (newfile != NULL) {
pDoc->saveImage(newfile);
}
}
void ImpressionistUI::mosaic(Fl_Menu_ *o, void *v) {
ImpressionistDoc *pDoc = whoami(o)->getDocument();
char *dir = fl_dir_chooser("Open a bmp data set directory", "");
printf(dir);
fflush(stdout);
if (dir != NULL) {
pDoc->generate_mosaic(dir);
}
}
//-------------------------------------------------------------
// Brings up the paint dialog
// This is called by the UI when the brushes menu item
// is chosen
//-------------------------------------------------------------
void ImpressionistUI::cb_brushes(Fl_Menu_ *o, void *v) {
whoami(o)->m_brushDialog->show();
}
//------------------------------------------------------------
// Clears the paintview canvas.
// Called by the UI when the clear canvas menu item is chosen
//------------------------------------------------------------
void ImpressionistUI::cb_clear_canvas(Fl_Menu_ *o, void *v) {
ImpressionistDoc *pDoc = whoami(o)->getDocument();
pDoc->clear_canvas();
}
void ImpressionistUI::cb_undo(Fl_Menu_ *o, void *v) {
ImpressionistDoc *pDoc = whoami(o)->getDocument();
pDoc->undo_painting();
}
void ImpressionistUI::cb_dissolve_iamge(Fl_Menu_ *o, void *v) {
ImpressionistDoc *pDoc = whoami(o)->getDocument();
#ifdef PROJ_DEBUG
char *newfile =
"/Users/dannylau/Program/COMP4411-Impressionist/images/bean.bmp";
#else
char *newfile = fl_file_chooser("Open File?", "*.bmp", pDoc->getImageName());
#endif
Image src = Image::from(newfile);
debugger("w:%d h:%d", src.width, src.height);
// Image output = ImageUtils::dissolve(src, pDoc->m_pUI->m_origView->img);
pDoc->m_pUI->m_origView->dissolve(src);
}
void ImpressionistUI::cb_mural_image(Fl_Menu_ *o, void *v) {
ImpressionistDoc *pDoc = whoami(o)->getDocument();
OriginalView &view = *pDoc->m_pUI->m_origView;
if (!view.original_img.contain_content()) {
fl_alert("In order to use this function, you have to load an image first.");
return;
}
char *newfile = fl_file_chooser("Open File?", "*.bmp", pDoc->getImageName());
Image src = Image::from(newfile);
if (src.width != view.original_img.width ||
src.height != view.original_img.height) {
fl_alert("Dimension is not the same, please try again.");
return;
}
view.set_current_img(src);
}
void ImpressionistUI::cb_load_another_image(Fl_Menu_ *o, void *v) {
ImpressionistDoc &pDoc = *whoami(o)->getDocument();
OriginalView &view = *pDoc.m_pUI->m_origView;
if (!view.original_img.contain_content()) {
fl_alert("In order to use this function, you have to load an image first.");
return;
}
char *newfile = fl_file_chooser("Open File?", "*.bmp", pDoc.getImageName());
Image src = Image::from(newfile);
if (src.width != view.original_img.width ||
src.height != view.original_img.height) {
fl_alert("Dimension is not the same, please try again.");
return;
}
pDoc.another_image = src;
}
void ImpressionistUI::cb_load_video(Fl_Menu_ *o, void *v) {
ImpressionistDoc &pDoc = *whoami(o)->getDocument();
OriginalView &view = *pDoc.m_pUI->m_origView;
char *video_path =
fl_file_chooser("Open File?", "*.avi", pDoc.getImageName());
pDoc.loadVideo(video_path);
}
void ImpressionistUI::cb_swap_content(Fl_Menu_ *o, void *v) {
ImpressionistDoc *pDoc = whoami(o)->getDocument();
pDoc->swap_content();
}
void ImpressionistUI::cb_color_blending(Fl_Menu_ *o, void *v) {
whoami(o)->m_ColorDialog->show();
}
// bring up the filter interface dialog
void ImpressionistUI::cb_arbitrary_filter(Fl_Menu_ *o, void *v) {
whoami(o)->m_FilterInterface->show();
}
void ImpressionistUI::cb_autoPaint(Fl_Widget *o, void *v) {
ImpressionistDoc *pDoc = ((ImpressionistUI *)(o->user_data()))->getDocument();
pDoc->auto_paint();
}
void ImpressionistUI::cb_multiresPaint(Fl_Widget *o, void *v) {
ImpressionistDoc *pDoc = ((ImpressionistUI *)(o->user_data()))->getDocument();
pDoc->multires_paint();
}
void ImpressionistUI::cb_spacingUpdate(Fl_Widget *o, void *v) {
((ImpressionistUI *)(o->user_data()))
->setSpacing(int(((Fl_Slider *)o)->value()));
}
void ImpressionistUI::cb_autoPaintRandomize(Fl_Widget *o, void *v) {
((ImpressionistUI *)(o->user_data()))->setAutoPaintRandomize();
}
void ImpressionistUI::cb_load_alpha_image(Fl_Menu_ *o, void *v) {
ImpressionistDoc *pDoc = whoami(o)->getDocument();
char *newfile = fl_file_chooser("Open File?", "*.bmp", pDoc->getImageName());
if (newfile != NULL) {
pDoc->loadAlphaImage(newfile);
}
}
//------------------------------------------------------------
// Causes the Impressionist program to exit
// Called by the UI when the quit menu item is chosen
//------------------------------------------------------------
void ImpressionistUI::cb_exit(Fl_Menu_ *o, void *v) {
whoami(o)->m_mainWindow->hide();
whoami(o)->m_brushDialog->hide();
}
//-----------------------------------------------------------
// Brings up an about dialog box
// Called by the UI when the about menu item is chosen
//-----------------------------------------------------------
void ImpressionistUI::cb_about(Fl_Menu_ *o, void *v) {
fl_message("Impressionist FLTK version for CS341, Spring 2002");
}
//------- UI should keep track of the current for all the controls for answering
// the query from Doc ---------
//-------------------------------------------------------------
// Sets the type of brush to use to the one chosen in the brush
// choice.
// Called by the UI when a brush is chosen in the brush choice
//-------------------------------------------------------------
void ImpressionistUI::cb_brushChoice(Fl_Widget *o, void *v) {
ImpressionistUI *pUI = ((ImpressionistUI *)(o->user_data()));
ImpressionistDoc *pDoc = pUI->getDocument();
int type = (int)(size_t)v;
pDoc->setBrushType(type);
pDoc->m_pCurrentBrush->select();
}
void ImpressionistUI::cb_strokeDirectionChoice(Fl_Widget *o, void *v) {
ImpressionistUI *pUI = ((ImpressionistUI *)(o->user_data()));
pUI->m_direction = (StrokeDirection)(size_t)v;
}
//------------------------------------------------------------
// Clears the paintview canvas.
// Called by the UI when the clear canvas button is pushed
//------------------------------------------------------------
void ImpressionistUI::cb_clear_canvas_button(Fl_Widget *o, void *v) {
ImpressionistDoc *pDoc = ((ImpressionistUI *)(o->user_data()))->getDocument();
pDoc->clear_canvas();
}
//-----------------------------------------------------------
// Updates the brush size to use from the value of the size
// slider
// Called by the UI when the size slider is moved
//-----------------------------------------------------------
void ImpressionistUI::cb_sizeUpdate(Fl_Widget *o, void *v) {
((ImpressionistUI *)(o->user_data()))
->setSize(int(((Fl_Slider *)o)->value()));
}
void ImpressionistUI::cb_widthUpdate(Fl_Widget *o, void *v) {
((ImpressionistUI *)(o->user_data()))
->setWidth(int(((Fl_Slider *)o)->value()));
}
void ImpressionistUI::cb_angleUpdate(Fl_Widget *o, void *v) {
((ImpressionistUI *)(o->user_data()))
->setAngle(int(((Fl_Slider *)o)->value()));
}
void ImpressionistUI::cb_alphaUpdate(Fl_Widget *o, void *v) {
((ImpressionistUI *)(o->user_data()))
->setAlpha(float(((Fl_Slider *)o)->value()));
}
void ImpressionistUI::cb_curvatureUpdate(Fl_Widget *o, void *v) {
((ImpressionistUI *)(o->user_data()))
->setCurvature(float(((Fl_Slider *)o)->value()));
}
void ImpressionistUI::cb_toggleOriginalView(Fl_Widget *o, void *v) {
ImpressionistDoc *pDoc = ((ImpressionistUI *)(o->user_data()))->getDocument();
pDoc->toggleOriginalView();
}
void ImpressionistUI::cb_colorBlendingUpdate(Fl_Widget *o, void *v) {
((ImpressionistUI *)(o->user_data()))->setColorBlending();
}
void ImpressionistUI::cb_another_gradient(Fl_Widget *o, void *v) {
ImpressionistDoc *pDoc = ((ImpressionistUI *)(o->user_data()))->getDocument();
auto ui = *((ImpressionistUI *)(o->user_data()));
bool value = bool(((Fl_Check_Button *)o)->value());
if (!pDoc->another_image.contain_content() && v) {
ui.m_another_gradient_checkbox->clear();
ui.set_use_another_gradient(false);
} else {
ui.set_use_another_gradient(value);
}
}
void ImpressionistUI::cb_edge_clipping(Fl_Widget *o, void *v) {
ImpressionistDoc *pDoc = ((ImpressionistUI *)(o->user_data()))->getDocument();
auto ui = *((ImpressionistUI *)(o->user_data()));
bool value = bool(((Fl_Check_Button *)o)->value());
Image &original_image = pDoc->m_pUI->m_origView->original_img;
if (value) {
if (!pDoc->edge_image.contain_content() &&
original_image.contain_content()) {
// generate edge image
debugger("generate edge");
Image tmp = ImageUtils::generate_edge_image(original_image);
pDoc->edge_image = tmp;
} else if (!pDoc->edge_image.contain_content()) {
fl_alert("To enable edge clipping, you have to load an image first.");
ui.m_edge_clipping_checkbox->clear();
ui.set_edge_clipping(false);
}
ui.set_edge_clipping(true);
} else {
ui.set_edge_clipping(false);
}
}
void ImpressionistUI::cb_blurUpdate(Fl_Widget *o, void *v) {
((ImpressionistUI *)(o->user_data()))
->setBlurValue(int(((Fl_Slider *)o)->value()));
}
void ImpressionistUI::cb_transparencyUpdate(Fl_Widget *o, void *v) {
((ImpressionistUI *)(o->user_data()))
->setTransparency(float(((Fl_Slider *)o)->value()));
}
void ImpressionistUI::cb_arbFilterApply(Fl_Widget *o, void *v) {
((ImpressionistUI *)(o->user_data()))
->setFilterValues(); // put the filter value string into somewhere
// accessible
}
void ImpressionistUI::cb_arbFilterNormalize(Fl_Widget *o, void *v) {
((ImpressionistUI *)(o->user_data()))->setNormalize();
}
//---------------------------------- per instance functions
//--------------------------------------
//------------------------------------------------
// Return the ImpressionistDoc used
//------------------------------------------------
ImpressionistDoc *ImpressionistUI::getDocument() { return m_pDoc; }
//------------------------------------------------
// Draw the main window
//------------------------------------------------
void ImpressionistUI::show() {
m_mainWindow->show();
m_paintView->show();
m_origView->show();
}
//------------------------------------------------
// Change the paint and original window sizes to
// w by h
//------------------------------------------------
void ImpressionistUI::resize_windows(int w, int h) {
m_paintView->size(w, h);
m_origView->size(w, h);
}
//------------------------------------------------
// Set the ImpressionistDoc used by the UI to
// communicate with the brushes
//------------------------------------------------
void ImpressionistUI::setDocument(ImpressionistDoc *doc) {
m_pDoc = doc;
m_origView->m_pDoc = doc;
m_paintView->m_pDoc = doc;
}
//------------------------------------------------
// Return the brush size
//------------------------------------------------
int ImpressionistUI::getSize() { return m_nSize; }
int ImpressionistUI::getWidth() { return m_nWidth; }
int ImpressionistUI::getAngle() { return m_nAngle; }
float ImpressionistUI::getAlpha() { return m_fAlpha; }
float ImpressionistUI::getCurvature() { return m_nCurvature; }
int ImpressionistUI::getColorBlending() { return m_fColorBlending; }
int ImpressionistUI::getBlurValue() { return m_fBlur; }
int ImpressionistUI::getSpacing() { return m_nSpacing; }
int ImpressionistUI::getAutoPaintRandomize() { return m_nAutoPaintRandomize; }
float ImpressionistUI::getTransparency() { return m_cTransparency; }
//-------------------------------------------------
// Set the brush size
//-------------------------------------------------
void ImpressionistUI::setSize(int size) {
m_nSize = size;
if (size <= 40)
m_BrushSizeSlider->value(m_nSize);
}
void ImpressionistUI::setWidth(int width) {
m_nWidth = width;
if (width <= 40)
m_BrushWidthSlider->value(m_nWidth);
}
void ImpressionistUI::setAngle(int angle) {
if (angle < 0) {
angle += 360;
}
m_nAngle = angle;
if (angle <= 360)
m_BrushAngleSlider->value(m_nAngle);
}
void ImpressionistUI::setAlpha(float a) {
m_fAlpha = a;
if (a <= 1.0)
m_BrushAlphaSlider->value(m_fAlpha);
}
void ImpressionistUI::setCurvature(float a) {
m_nCurvature = a;
if (a <= 1.0)
m_BrushCurvatureSlider->value(m_nCurvature);
}
void ImpressionistUI::setColorBlending() {
m_fColorBlending = m_ColorBlending->value();
}
void ImpressionistUI::setBlurValue(int a) {
m_fBlur = a;
if (a <= 11)
if (a % 2)
m_BrushBlurSlider->value(m_fBlur);
else
m_BrushBlurSlider->value((int)m_fBlur + 1);
else
m_BrushBlurSlider->value(11);
}
void ImpressionistUI::setSpacing(int a) {
m_nSpacing = a;
if (a <= 16)
m_BrushSpacingSlider->value(m_nSpacing);
}
void ImpressionistUI::setAutoPaintRandomize() {
m_nAutoPaintRandomize = m_AutoPaintRandomize->value();
}
void ImpressionistUI::setTransparency(float a) {
m_cTransparency = a;
if (a <= 1.0)
m_CanvasTransparencySlider->value(m_cTransparency);
m_paintView->overlay_image.set_alpha(m_cTransparency);
m_paintView->refresh();
}
vector<double> ImpressionistUI::getUserColor() {
vector<double> rgb = {m_ColorChooser->r(), m_ColorChooser->g(),
m_ColorChooser->b()};
return rgb;
}
bool ImpressionistUI::get_use_another_gradient() {
debugger("get: %d", this->use_another_gradient);
return this->use_another_gradient;
}
void ImpressionistUI::set_use_another_gradient(bool v) {
debugger("set: %d", v);
this->use_another_gradient = v;
}
void ImpressionistUI::set_edge_clipping(bool v) {
debugger("set: %d", v);
this->enable_edge_clipping = v;
}
bool ImpressionistUI::get_edge_clipping() {
debugger("get: %d", this->enable_edge_clipping);
return this->enable_edge_clipping;
}
int ImpressionistUI::getRowNum() { return af_rownum; }
int ImpressionistUI::getColNum() { return af_colnum; }
int ImpressionistUI::getFilterValues(
char *a) { // return 0 if no changes to filter values
if (!filter_changed) {
return 0;
}
strcpy(a, af_values);
filter_changed = false;
return 1;
}
void ImpressionistUI::setRowNum() {
char rownum_str[10]{'0'};
strcpy(rownum_str, m_FilterRowNum->value());
af_rownum = atoi(rownum_str);
}
void ImpressionistUI::setColNum() {
char colnum_str[10]{'0'};
strcpy(colnum_str, m_FilterColNum->value());
af_colnum = atoi(colnum_str);
}
void ImpressionistUI::setFilterValues() {
strcpy(af_values, m_FilterValues->value());
filter_changed = true;
setRowNum();
setColNum();
printf("%s \n%d %d\n", af_values, af_rownum, af_colnum);
printf("Finish setFilterValues");
}
bool ImpressionistUI::getNormalize() { return (af_normalize == 1); }
void ImpressionistUI::setNormalize() {
af_normalize = m_FilterNormalize->value();
printf("af_normalize is %d\n", af_normalize);
}
// Main menu definition
Fl_Menu_Item ImpressionistUI::menuitems[] = {
{"&File", 0, 0, 0, FL_SUBMENU},
{"&Load Image...", FL_ALT + 'l',
(Fl_Callback *)ImpressionistUI::cb_load_image},
{"&Load Alpha Image...", FL_ALT + 'x',
(Fl_Callback *)ImpressionistUI::cb_load_alpha_image},
{"&Load Video...", FL_ALT + 'l',
(Fl_Callback *)ImpressionistUI::cb_load_video},
{"&Mosaic", FL_ALT + 'm', (Fl_Callback *)ImpressionistUI::mosaic},
{"&Save Image...", FL_ALT + 's',
(Fl_Callback *)ImpressionistUI::cb_save_image},
{"&Brushes...", FL_ALT + 'b', (Fl_Callback *)ImpressionistUI::cb_brushes},
{"&Undo", FL_ALT + 'u', (Fl_Callback *)ImpressionistUI::cb_undo, 0},
{"&Swap", FL_ALT + 's', (Fl_Callback *)ImpressionistUI::cb_swap_content, 0},
{"&Dissolve", FL_ALT + 'd',
(Fl_Callback *)ImpressionistUI::cb_dissolve_iamge, 0},
{"&New / Change Mural image", FL_ALT + 'N',
(Fl_Callback *)ImpressionistUI::cb_mural_image, 0},
{"&Another Image", FL_ALT + 'A',
(Fl_Callback *)ImpressionistUI::cb_load_another_image, 0},
{"&Color Blending", FL_ALT + 'k',
(Fl_Callback *)ImpressionistUI::cb_color_blending, 0},
{"&Custom Filter", FL_ALT + 'f',
(Fl_Callback *)ImpressionistUI::cb_arbitrary_filter, 0},
{"&Clear Canvas", FL_ALT + 'c',
(Fl_Callback *)ImpressionistUI::cb_clear_canvas, 0, FL_MENU_DIVIDER},
{"&Quit", FL_ALT + 'q', (Fl_Callback *)ImpressionistUI::cb_exit},
{0},
{"&Help", 0, 0, 0, FL_SUBMENU},
{"&About", FL_ALT + 'a', (Fl_Callback *)ImpressionistUI::cb_about},
{0},
{0}};
// Brush choice menu definition
Fl_Menu_Item ImpressionistUI::brushTypeMenu[NUM_BRUSH_TYPE + 1] = {
{"Points", FL_ALT + 'p', (Fl_Callback *)ImpressionistUI::cb_brushChoice,
(void *)BRUSH_POINTS},
{"Lines", FL_ALT + 'l', (Fl_Callback *)ImpressionistUI::cb_brushChoice,
(void *)BRUSH_LINES},
{"Circles", FL_ALT + 'c', (Fl_Callback *)ImpressionistUI::cb_brushChoice,
(void *)BRUSH_CIRCLES},
{"Scattered Points", FL_ALT + 'q',
(Fl_Callback *)ImpressionistUI::cb_brushChoice,
(void *)BRUSH_SCATTERED_POINTS},
{"Scattered Lines", FL_ALT + 'm',
(Fl_Callback *)ImpressionistUI::cb_brushChoice,
(void *)BRUSH_SCATTERED_LINES},
{"Scattered Circles", FL_ALT + 'd',
(Fl_Callback *)ImpressionistUI::cb_brushChoice,
(void *)BRUSH_SCATTERED_CIRCLES},
{"Fans", FL_ALT + 'f', (Fl_Callback *)ImpressionistUI::cb_brushChoice,
(void *)BRUSH_FANS},
{"Arcs", FL_ALT + 'r', (Fl_Callback *)ImpressionistUI::cb_brushChoice,
(void *)BRUSH_ARC},
{"Blurring Filter", FL_ALT + 'u',
(Fl_Callback *)ImpressionistUI::cb_brushChoice, (void *)BRUSH_FILTER},
{"Custom Filter", FL_ALT + 's',
(Fl_Callback *)ImpressionistUI::cb_brushChoice,
(void *)BRUSH_CUSTOM_FILTER},
{"Alpha-mapped", FL_ALT + 'a',
(Fl_Callback *)ImpressionistUI::cb_brushChoice, (void *)BRUSH_ALPHA},
{"Rubber", FL_ALT + 'r', (Fl_Callback *)ImpressionistUI::cb_brushChoice,
(void *)BRUSH_PULL_AS_RUBBER},
{"Curved", FL_ALT + 'v', (Fl_Callback *)ImpressionistUI::cb_brushChoice,
(void *)BRUSH_CURVED},
{0}};
Fl_Menu_Item
ImpressionistUI::strokeDirectionMenu[NUM_STROKE_DIRECTION_METHODS + 1] = {
{"Slider/Right Mouse", FL_ALT + 's',
(Fl_Callback *)ImpressionistUI::cb_strokeDirectionChoice,
(void *)SLIDER_RIGHT_MOUSE},
{"Gradient", FL_ALT + 'g',
(Fl_Callback *)ImpressionistUI::cb_strokeDirectionChoice,
(void *)GRADIENT_DIRECTION},
{"Brush Direction", FL_ALT + 'b',
(Fl_Callback *)ImpressionistUI::cb_strokeDirectionChoice,
(void *)BRUSH_DIRECTION},
{0}};
//----------------------------------------------------
// Constructor. Creates all of the widgets.
// Add new widgets here
//----------------------------------------------------
ImpressionistUI::ImpressionistUI() {
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
use_another_gradient = false;
// Create the main window
m_mainWindow = new Fl_Window(600, 300, "Impressionist");
m_mainWindow->user_data(
(void *)(this)); // record self to be used by static callback functions
// install menu bar
m_menubar = new Fl_Menu_Bar(0, 0, 600, 25);
m_menubar->menu(menuitems);
// Create a group that will hold two sub windows inside the main
// window
Fl_Group *group = new Fl_Group(0, 25, 600, 275);
// install paint view window
// install original view window
m_origView =
new OriginalView(0, 25, 300, 275, "This is the orig view"); // 300jon
m_origView->box(FL_DOWN_FRAME);
m_origView->deactivate();
m_paintView =
new PaintView(300, 25, 300, 275, "This is the paint view"); // 0jon
m_paintView->box(FL_DOWN_FRAME);
group->end();
Fl_Group::current()->resizable(group);
m_mainWindow->end();
// brush dialog definition
m_brushDialog = new Fl_Window(400, 430, "Brush Dialog");
// Add a brush type choice to the dialog
m_BrushTypeChoice = new Fl_Choice(50, 10, 150, 25, "&Brush");
m_BrushTypeChoice->user_data(
(void *)(this)); // record self to be used by static callback functions
m_BrushTypeChoice->menu(brushTypeMenu);
m_BrushTypeChoice->callback(cb_brushChoice);
// stroke direction
m_StrokeDirection = new Fl_Choice(115, 40, 150, 25, "&Stroke Direction");
m_StrokeDirection->user_data(
(void *)(this)); // record self to be used by static callback functions
m_StrokeDirection->menu(strokeDirectionMenu);
m_StrokeDirection->callback(cb_strokeDirectionChoice);
m_StrokeDirection->deactivate(); // match Point as default brush
m_ClearCanvasButton = new Fl_Button(240, 10, 150, 25, "&Clear Canvas");
m_ClearCanvasButton->user_data((void *)(this));
m_ClearCanvasButton->callback(cb_clear_canvas_button);
// Add brush size slider to the dialog
int y = 80;
m_BrushSizeSlider = new Fl_Value_Slider(10, y, 300, 20, "Size");
m_BrushSizeSlider->user_data(
(void *)(this)); // record self to be used by static callback functions
m_BrushSizeSlider->type(FL_HOR_NICE_SLIDER);
m_BrushSizeSlider->labelfont(FL_COURIER);
m_BrushSizeSlider->labelsize(12);
m_BrushSizeSlider->minimum(1);
m_BrushSizeSlider->maximum(40);
m_BrushSizeSlider->step(1);
m_BrushSizeSlider->value(m_nSize);
m_BrushSizeSlider->align(FL_ALIGN_RIGHT);
m_BrushSizeSlider->callback(cb_sizeUpdate);
m_BrushWidthSlider = new Fl_Value_Slider(10, y += 30, 300, 20, "Line Width");
m_BrushWidthSlider->user_data((void *)(this));
m_BrushWidthSlider->type(FL_HOR_NICE_SLIDER);
m_BrushWidthSlider->labelfont(FL_COURIER);
m_BrushWidthSlider->labelsize(12);
m_BrushWidthSlider->minimum(1);
m_BrushWidthSlider->maximum(40);
m_BrushWidthSlider->step(1);
m_BrushWidthSlider->value(m_nWidth);
m_BrushWidthSlider->align(FL_ALIGN_RIGHT);
m_BrushWidthSlider->callback(cb_widthUpdate);
m_BrushWidthSlider->deactivate(); // match Point as default brush
m_BrushAngleSlider = new Fl_Value_Slider(10, y += 30, 300, 20, "Line Angle");
m_BrushAngleSlider->user_data((void *)(this));
m_BrushAngleSlider->type(FL_HOR_NICE_SLIDER);
m_BrushAngleSlider->labelfont(FL_COURIER);
m_BrushAngleSlider->labelsize(12);
m_BrushAngleSlider->minimum(0);
m_BrushAngleSlider->maximum(360);
m_BrushAngleSlider->step(1);
m_BrushAngleSlider->value(m_nAngle);
m_BrushAngleSlider->align(FL_ALIGN_RIGHT);
m_BrushAngleSlider->callback(cb_angleUpdate);
m_BrushAngleSlider->deactivate(); // match Point as default brush
m_BrushAlphaSlider = new Fl_Value_Slider(10, y += 30, 300, 20, "Alpha");
m_BrushAlphaSlider->user_data(
(void *)(this)); // record self to be used by static callback functions
m_BrushAlphaSlider->type(FL_HOR_NICE_SLIDER);
m_BrushAlphaSlider->labelfont(FL_COURIER);
m_BrushAlphaSlider->labelsize(12);
m_BrushAlphaSlider->minimum(0.0);
m_BrushAlphaSlider->maximum(1.0);
m_BrushAlphaSlider->step(0.01);
m_BrushAlphaSlider->value(m_fAlpha);
m_BrushAlphaSlider->align(FL_ALIGN_RIGHT);
m_BrushAlphaSlider->callback(cb_alphaUpdate);
m_BrushCurvatureSlider =
new Fl_Value_Slider(10, y += 30, 300, 20, "Curvature");
m_BrushCurvatureSlider->user_data(
(void *)(this)); // record self to be used by static callback functions
m_BrushCurvatureSlider->type(FL_HOR_NICE_SLIDER);
m_BrushCurvatureSlider->labelfont(FL_COURIER);
m_BrushCurvatureSlider->labelsize(12);
m_BrushCurvatureSlider->minimum(0.0);
m_BrushCurvatureSlider->maximum(1.0);
m_BrushCurvatureSlider->step(0.01);
m_BrushCurvatureSlider->value(m_nCurvature);
m_BrushCurvatureSlider->align(FL_ALIGN_RIGHT);
m_BrushCurvatureSlider->callback(cb_curvatureUpdate);
m_BrushBlurSlider = new Fl_Value_Slider(10, y += 30, 300, 20, "Blurring");
m_BrushBlurSlider->user_data((void *)(this));
m_BrushBlurSlider->type(FL_HOR_NICE_SLIDER);
m_BrushBlurSlider->labelfont(FL_COURIER);
m_BrushBlurSlider->labelsize(12);
m_BrushBlurSlider->minimum(0);
m_BrushBlurSlider->maximum(10);
m_BrushBlurSlider->step(1);
m_BrushBlurSlider->value(m_fBlur);
m_BrushBlurSlider->align(FL_ALIGN_RIGHT);
m_BrushBlurSlider->callback(cb_blurUpdate);
m_BrushBlurSlider->deactivate(); // follow Point as default
// checkbox for color source (original picture or color blending)
m_ColorBlending = new Fl_Check_Button(10, y += 30, 20, 20, "Color Blending");
m_ColorBlending->user_data((void *)(this));
m_ColorBlending->labelfont(FL_COURIER);
m_ColorBlending->value(0);
m_ColorBlending->align(FL_ALIGN_RIGHT);
m_ColorBlending->callback(cb_colorBlendingUpdate);
// checkbox for using gradient from another image
m_another_gradient_checkbox =
new Fl_Check_Button(220, y, 20, 20, "Another Gradient");
m_another_gradient_checkbox->user_data((void *)(this));
m_another_gradient_checkbox->labelfont(FL_COURIER);
m_another_gradient_checkbox->value(0);
m_another_gradient_checkbox->align(FL_ALIGN_RIGHT);
m_another_gradient_checkbox->callback(cb_another_gradient);
m_edge_clipping_checkbox =
new Fl_Check_Button(220, y += 30, 20, 20, "Edge Clipping");
m_edge_clipping_checkbox->user_data((void *)(this));
m_edge_clipping_checkbox->labelfont(FL_COURIER);
m_edge_clipping_checkbox->value(0);
m_edge_clipping_checkbox->align(FL_ALIGN_RIGHT);
m_edge_clipping_checkbox->callback(cb_edge_clipping);
// autopainting section
// 1. spacing slider
m_BrushSpacingSlider = new Fl_Value_Slider(10, y += 30, 180, 20, "Spacing");
m_BrushSpacingSlider->user_data((void *)(this));
m_BrushSpacingSlider->type(FL_HOR_NICE_SLIDER);
m_BrushSpacingSlider->labelfont(FL_COURIER);
m_BrushSpacingSlider->labelsize(12);
m_BrushSpacingSlider->minimum(1);
m_BrushSpacingSlider->maximum(16);
m_BrushSpacingSlider->step(1);
m_BrushSpacingSlider->value(m_nSpacing);
m_BrushSpacingSlider->align(FL_ALIGN_RIGHT);
m_BrushSpacingSlider->callback(cb_spacingUpdate);
// 2. randomize checkbox
m_AutoPaintRandomize = new Fl_Check_Button(250, y, 20, 20, "Random");
m_AutoPaintRandomize->user_data((void *)(this));
m_AutoPaintRandomize->labelfont(FL_COURIER);
m_AutoPaintRandomize->value(m_nAutoPaintRandomize);
m_AutoPaintRandomize->align(FL_ALIGN_RIGHT);
m_AutoPaintRandomize->callback(cb_autoPaintRandomize);
// 3. button to paint
m_AutoPaint = new Fl_Button(340, y, 50, 25, "Paint");
m_AutoPaint->user_data((void *)(this));
m_AutoPaint->callback(cb_autoPaint);
m_MultiResPaint =
new Fl_Button(240, y += 30, 150, 25, "Multi-Resolution Paint");
m_MultiResPaint->user_data((void *)(this));
m_MultiResPaint->callback(cb_multiresPaint);
m_CanvasTransparencySlider =
new Fl_Value_Slider(10, y += 30, 300, 20, "Transparency");
m_CanvasTransparencySlider->user_data((void *)(this));
m_CanvasTransparencySlider->type(FL_HOR_NICE_SLIDER);
m_CanvasTransparencySlider->labelfont(FL_COURIER);
m_CanvasTransparencySlider->labelsize(12);
m_CanvasTransparencySlider->minimum(0.0);
m_CanvasTransparencySlider->maximum(1.0);
m_CanvasTransparencySlider->step(0.01);
m_CanvasTransparencySlider->value(m_cTransparency);
m_CanvasTransparencySlider->align(FL_ALIGN_RIGHT);
m_CanvasTransparencySlider->callback(cb_transparencyUpdate);
m_brushDialog->end();
// color dialog definition
m_ColorDialog = new Fl_Window(300, 150, "Color Dialog");
m_ColorChooser = new Fl_Color_Chooser(0, 0, 300, 143, "Choose Colors");
m_ColorDialog->end();
// arbitrary filter dialog definition
int fy = 20;
m_FilterInterface = new Fl_Window(500, 450, "Filter Interface");
m_FilterBuff = new Fl_Text_Buffer();
m_FilterDisp = new Fl_Text_Display(25, fy, 450, 100, "Instructions");
m_FilterDisp->buffer(m_FilterBuff);
m_FilterBuff->text(
"Enter the dimensions of the rectangular filter.\nThen, enter the filter "
"values separated with commas \nand each row on a new line.");
m_FilterDisp->deactivate();
m_FilterRowNum = new Fl_Int_Input(25, fy += 110, 30, 30, "# Rows");
m_FilterRowNum->labelfont(FL_COURIER);
m_FilterRowNum->align(FL_ALIGN_RIGHT);
m_FilterRowNum->user_data((void *)(this));
m_FilterColNum = new Fl_Int_Input(125, fy, 30, 30, "# Columns");
m_FilterColNum->labelfont(FL_COURIER);
m_FilterColNum->align(FL_ALIGN_RIGHT);
m_FilterColNum->user_data((void *)(this));
m_FilterNormalize = new Fl_Check_Button(250, fy, 30, 30, "Normalize");
m_FilterNormalize->user_data((void *)(this));
m_FilterNormalize->callback(cb_arbFilterNormalize);
m_FilterValues = new Fl_Multiline_Input(25, fy += 40, 450, 200);
m_FilterValues->user_data((void *)(this));
m_FilterApply = new Fl_Button(350, fy += 210, 100, 40, "Apply");
m_FilterApply->user_data((void *)(this));
m_FilterApply->callback(cb_arbFilterApply);
m_FilterInterface->end();