/
state_draw.cpp
2901 lines (2499 loc) · 94.7 KB
/
state_draw.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
/* === S Y N F I G ========================================================= */
/*! \file state_draw.cpp
** \brief Template File
**
** $Id$
**
** \legal
** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
** Copyright (c) 2007 Chris Moore
** Copyright (c) 2009 Nikita Kitaev
** Copyright (c) 2010 Carlos López
**
** This package 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 package 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.
** \endlegal
*/
/* ========================================================================= */
/* === H E A D E R S ======================================================= */
#ifdef USING_PCH
# include "pch.h"
#else
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <ETL/hermite>
#include <ETL/calculus>
#include <ETL/gaussian>
#include <synfig/valuenode_bline.h>
#include <synfig/valuenode_wplist.h>
#include <synfig/valuenode_composite.h>
#include <synfig/valuenode_dynamiclist.h>
#include <synfigapp/blineconvert.h>
#include <synfigapp/wplistconverter.h>
#include <synfigapp/main.h>
#include "widgets/widget_distance.h"
#include "widgets/widget_enum.h"
#include "event_mouse.h"
#include "event_layerclick.h"
#include "docks/dock_toolbox.h"
#include "docks/dialog_tooloptions.h"
#include "state_draw.h"
#include "state_stroke.h"
#include "state_normal.h"
#include "canvasview.h"
#include "workarea.h"
#include "app.h"
#include <utility>
#include <sigc++/connection.h>
#include "general.h"
#endif
/* === U S I N G =========================================================== */
using namespace std;
using namespace etl;
using namespace synfig;
using namespace studio;
/* === M A C R O S ========================================================= */
#ifndef LAYER_CREATION
#define LAYER_CREATION(button, stockid, tooltip) \
{ \
Gtk::Image *icon = manage(new Gtk::Image(Gtk::StockID(stockid), \
Gtk::ICON_SIZE_SMALL_TOOLBAR)); \
button.add(*icon); \
} \
button.set_relief(Gtk::RELIEF_NONE); \
button.set_tooltip_text(tooltip)
#endif
// indentation for options layout
#ifndef SPACING
#define SPACING(name, px) \
Gtk::Alignment *name = Gtk::manage(new Gtk::Alignment()); \
name->set_size_request(px)
#endif
#define GAP (3)
#define INDENTATION (6)
/* === G L O B A L S ======================================================= */
StateDraw studio::state_draw;
/* === C L A S S E S & S T R U C T S ======================================= */
class studio::StateDraw_Context : public sigc::trackable
{
typedef etl::smart_ptr<std::list<synfig::Point> > StrokeData;
typedef etl::smart_ptr<std::list<synfig::Real> > WidthData;
typedef list< pair<StrokeData,WidthData> > StrokeQueue;
StrokeQueue stroke_queue;
etl::handle<CanvasView> canvas_view_;
CanvasView::IsWorking is_working;
WorkArea::PushState push_state;
bool prev_table_status;
bool loop_;
int nested;
sigc::connection process_queue_connection;
ValueNode_BLine::Handle last_stroke;
synfig::String last_stroke_id;
Gtk::Menu menu;
std::list< etl::smart_ptr<std::list<synfig::Point> > > stroke_list;
void refresh_ducks();
void fill_last_stroke();
Smach::event_result fill_last_stroke_and_unselect_other_layers();
Smach::event_result new_bline(std::list<synfig::BLinePoint> bline, std::list<synfig::WidthPoint> wplist, bool loop_bline_flag,float radius);
Smach::event_result new_region(std::list<synfig::BLinePoint> bline,synfig::Real radius);
Smach::event_result extend_bline_from_begin(ValueNode_BLine::Handle value_node,std::list<synfig::BLinePoint> bline,std::list<synfig::WidthPoint> wplist,bool complete_loop);
Smach::event_result extend_bline_from_end(ValueNode_BLine::Handle value_node,std::list<synfig::BLinePoint> bline,std::list<synfig::WidthPoint> wplist,bool complete_loop);
void reverse_bline(std::list<synfig::BLinePoint> &bline);
void reverse_wplist(std::list<synfig::WidthPoint> &wplist);
//Toolbox settings
synfigapp::Settings& settings;
// holder of options
Gtk::Table options_table;
// title
Gtk::Label title_label;
// layer name:
Gtk::Label id_label;
Gtk::HBox id_box;
Gtk::Entry id_entry;
// layer types to create:
Gtk::Label layer_types_label;
Gtk::ToggleButton layer_region_togglebutton;
Gtk::ToggleButton layer_outline_togglebutton;
Gtk::ToggleButton layer_advanced_outline_togglebutton;
Gtk::HBox layer_types_box;
// blend method
Gtk::Label blend_label;
Gtk::HBox blend_box;
Widget_Enum blend_enum;
// opacity
Gtk::Label opacity_label;
Gtk::HScale opacity_hscl;
// brush size
Gtk::Label bline_width_label;
Widget_Distance bline_width_dist;
// pressure width
Gtk::Label pressure_width_label;
Gtk::CheckButton pressure_width_checkbutton;
Gtk::HBox pressure_width_box;
// min pressure, sub option of pressure width
Gtk::Label min_pressure_label;
Gtk::HBox min_pressure_label_box;
Gtk::CheckButton min_pressure_checkbutton;
Gtk::Adjustment min_pressure_adj;
Gtk::SpinButton min_pressure_spin;
Gtk::HBox min_pressure_box;
// smoothness
Gtk::Label smoothness_label;
Gtk::RadioButton::Group smoothness_group;
// local threshold
Gtk::RadioButton localthres_radiobutton;
Gtk::Adjustment localthres_adj;
Gtk::SpinButton localthres_spin;
Gtk::HBox localthres_box;
// golbal threshold
Gtk::RadioButton globalthres_radiobutton;
Gtk::Adjustment globalthres_adj;
Gtk::SpinButton globalthres_spin;
Gtk::HBox globalthres_box;
// width max error advanced outline layer
Gtk::Label width_max_error_label;
Gtk::HBox width_max_error_box;
Gtk::Adjustment width_max_error_adj;
Gtk::SpinButton width_max_error_spin;
// constructing control
// round ends
Gtk::Label round_ends_label;
Gtk::CheckButton round_ends_checkbutton;
Gtk::HBox round_ends_box;
// whether to loop new strokes which start and end in the same place
Gtk::Label auto_loop_label;
Gtk::CheckButton auto_loop_checkbutton;
Gtk::HBox auto_loop_box;
// whether to extend existing lines
Gtk::Label auto_extend_label;
Gtk::CheckButton auto_extend_checkbutton;
Gtk::HBox auto_extend_box;
// whether to link new ducks to existing ducks
Gtk::Label auto_link_label;
Gtk::CheckButton auto_link_checkbutton;
Gtk::HBox auto_link_box;
// feather size
Gtk::Label feather_label;
Widget_Distance feather_dist;
// auto export
Gtk::Label auto_export_label;
Gtk::CheckButton auto_export_checkbutton;
Gtk::HBox auto_export_box;
// toolbar buttons
Gtk::Button fill_last_stroke_button;
void UpdateUsePressure();
void UpdateCreateAdvancedOutline();
void UpdateSmoothness();
//Added by Adrian - data drive HOOOOO
synfigapp::BLineConverter blineconv;
synfigapp::WPListConverter wplistconv;
public:
synfig::String get_id()const { return id_entry.get_text(); }
void set_id(const synfig::String& x) { return id_entry.set_text(x); }
int get_blend()const { return blend_enum.get_value(); }
void set_blend(int x) { return blend_enum.set_value(x); }
Real get_opacity()const { return opacity_hscl.get_value(); }
void set_opacity(Real x) { opacity_hscl.set_value(x); }
Real get_bline_width() const {
return bline_width_dist.get_value().get(
Distance::SYSTEM_UNITS,
get_canvas_view()->get_canvas()->rend_desc()
);
}
void set_bline_width(Distance x) { return bline_width_dist.set_value(x);}
bool get_pressure_width_flag()const { return pressure_width_checkbutton.get_active(); }
void set_pressure_width_flag(bool x) { return pressure_width_checkbutton.set_active(x); }
bool get_auto_loop_flag()const { return auto_loop_checkbutton.get_active(); }
void set_auto_loop_flag(bool x) { return auto_loop_checkbutton.set_active(x); }
bool get_auto_extend_flag()const { return auto_extend_checkbutton.get_active(); }
void set_auto_extend_flag(bool x) { return auto_extend_checkbutton.set_active(x); }
bool get_auto_link_flag()const { return auto_link_checkbutton.get_active(); }
void set_auto_link_flag(bool x) { return auto_link_checkbutton.set_active(x); }
bool get_region_flag()const { return layer_region_togglebutton.get_active(); }
void set_region_flag(bool x) { return layer_region_togglebutton.set_active(x); }
bool get_outline_flag()const { return layer_outline_togglebutton.get_active(); }
void set_outline_flag(bool x) { return layer_outline_togglebutton.set_active(x); }
bool get_advanced_outline_flag()const { return layer_advanced_outline_togglebutton.get_active(); }
void set_advanced_outline_flag(bool x) { return layer_advanced_outline_togglebutton.set_active(x); }
bool get_auto_export_flag()const { return auto_export_checkbutton.get_active(); }
void set_auto_export_flag(bool x) { return auto_export_checkbutton.set_active(x); }
Real get_min_pressure() const { return min_pressure_adj.get_value(); }
void set_min_pressure(Real x) { return min_pressure_adj.set_value(x); }
Real get_feather_size() const {
return feather_dist.get_value().get(Distance::SYSTEM_UNITS,
get_canvas_view()->get_canvas()->rend_desc());
}
void set_feather_size(Distance x) { return feather_dist.set_value(x); }
Real get_gthres() const { return globalthres_adj.get_value(); }
void set_gthres(Real x) { return globalthres_adj.set_value(x); }
Real get_lthres() const { return localthres_adj.get_value(); }
void set_lthres(Real x) { return localthres_adj.set_value(x); }
Real get_width_max_error() const { return width_max_error_adj.get_value(); }
void set_width_max_error(Real x) { return width_max_error_adj.set_value(x); }
bool get_local_threshold_flag() const { return localthres_radiobutton.get_active(); }
void set_local_threshold_flag(bool x) { localthres_radiobutton.set_active(x); }
bool get_global_threshold_flag() const { return globalthres_radiobutton.get_active(); }
void set_global_threshold_flag(bool x) { globalthres_radiobutton.set_active(x); }
bool get_min_pressure_flag()const { return min_pressure_checkbutton.get_active(); }
void set_min_pressure_flag(bool x) { min_pressure_checkbutton.set_active(x); }
bool get_round_ends_flag()const { return round_ends_checkbutton.get_active();}
void set_round_ends_flag(bool x) {round_ends_checkbutton.set_active(x);}
void load_settings();
void save_settings();
void increment_id();
Smach::event_result event_stop_handler(const Smach::event& x);
Smach::event_result event_refresh_handler(const Smach::event& x);
Smach::event_result event_mouse_down_handler(const Smach::event& x);
Smach::event_result event_stroke(const Smach::event& x);
Smach::event_result event_refresh_tool_options(const Smach::event& x);
void refresh_tool_options();
Smach::event_result process_stroke(StrokeData stroke_data, WidthData width_data, bool region_flag=false);
bool process_queue();
StateDraw_Context(CanvasView* canvas_view);
~StateDraw_Context();
const etl::handle<CanvasView>& get_canvas_view()const{return canvas_view_;}
etl::handle<synfigapp::CanvasInterface> get_canvas_interface()const{return canvas_view_->canvas_interface();}
synfig::Time get_time()const { return get_canvas_interface()->get_time(); }
synfig::Canvas::Handle get_canvas()const{return canvas_view_->get_canvas();}
WorkArea * get_work_area()const{return canvas_view_->get_work_area();}
//void on_user_click(synfig::Point point);
// bool run();
}; // END of class StateDraw_Context
/* === M E T H O D S ======================================================= */
StateDraw::StateDraw():
Smach::state<StateDraw_Context>("draw")
{
insert(event_def(EVENT_STOP,&StateDraw_Context::event_stop_handler));
insert(event_def(EVENT_REFRESH,&StateDraw_Context::event_refresh_handler));
insert(event_def(EVENT_REFRESH_DUCKS,&StateDraw_Context::event_refresh_handler));
insert(event_def(EVENT_WORKAREA_MOUSE_BUTTON_DOWN,&StateDraw_Context::event_mouse_down_handler));
insert(event_def(EVENT_WORKAREA_STROKE,&StateDraw_Context::event_stroke));
insert(event_def(EVENT_REFRESH_TOOL_OPTIONS,&StateDraw_Context::event_refresh_tool_options));
}
StateDraw::~StateDraw()
{
}
void
StateDraw_Context::load_settings()
{
try
{
synfig::ChangeLocale change_locale(LC_NUMERIC, "C");
String value;
if(settings.get_value("draw.id",value))
set_id(value);
else
set_id("NewDrawing");
if(settings.get_value("draw.blend",value) && value != "")
set_blend(atoi(value.c_str()));
else
set_blend(0);//(int)Color::BLEND_COMPOSITE); //0 should be blend composites value
if(settings.get_value("draw.opacity",value))
set_opacity(atof(value.c_str()));
else
set_opacity(1);
if(settings.get_value("draw.bline_width",value) && value != "")
set_bline_width(Distance(atof(value.c_str()), Distance::SYSTEM_POINTS));
else
set_bline_width(Distance(1, Distance::SYSTEM_POINTS)); // default width
if(settings.get_value("draw.pressure_width",value) && value=="0")
set_pressure_width_flag(false);
else
set_pressure_width_flag(true);
if(settings.get_value("draw.auto_loop",value) && value=="0")
set_auto_loop_flag(false);
else
set_auto_loop_flag(true);
if(settings.get_value("draw.auto_extend",value) && value=="0")
set_auto_extend_flag(false);
else
set_auto_extend_flag(true);
if(settings.get_value("draw.auto_link",value) && value=="0")
set_auto_link_flag(false);
else
set_auto_link_flag(true);
if(settings.get_value("draw.region",value) && value=="0")
set_region_flag(false);
else
set_region_flag(true);
if(settings.get_value("draw.outline",value) && value=="0")
set_outline_flag(false);
else
set_outline_flag(true);
if(settings.get_value("draw.advanced_outline",value) && value=="0")
set_advanced_outline_flag(false);
else
set_advanced_outline_flag(true);
if(settings.get_value("draw.auto_export",value) && value=="1")
set_auto_export_flag(true);
else
set_auto_export_flag(false);
if(settings.get_value("draw.min_pressure_on",value) && value=="0")
set_min_pressure_flag(false);
else
set_min_pressure_flag(true);
if(settings.get_value("draw.min_pressure",value))
{
Real n = atof(value.c_str());
set_min_pressure(n);
}else
set_min_pressure(0);
if(settings.get_value("draw.feather",value))
set_feather_size(Distance(value.c_str()));
else
set_feather_size(Distance("0pt"));
if(settings.get_value("draw.gthreshold",value))
{
Real n = atof(value.c_str());
set_gthres(n);
}
if(settings.get_value("draw.widthmaxerror",value))
{
Real n = atof(value.c_str());
set_width_max_error(n);
}
if(settings.get_value("draw.lthreshold",value))
{
Real n = atof(value.c_str());
set_lthres(n);
}
if(settings.get_value("draw.localize",value) && value == "1")
//set_local_error_flag(true);
set_local_threshold_flag(true);
else
//set_local_error_flag(false);
//set_local_threshold_flag(false);
set_global_threshold_flag(true);
if(settings.get_value("draw.round_ends", value) && value == "1")
set_round_ends_flag(true);
else
set_round_ends_flag(false);
}
catch(...)
{
synfig::warning("State Draw: Caught exception when attempting to load settings.");
}
}
void
StateDraw_Context::save_settings()
{
try
{
synfig::ChangeLocale change_locale(LC_NUMERIC, "C");
settings.set_value("draw.id",get_id().c_str());
settings.set_value("draw.blend",strprintf("%d",get_blend()));
settings.set_value("draw.opacity",strprintf("%f",(float)get_opacity()));
settings.set_value("draw.bline_width", bline_width_dist.get_value().get_string());
settings.set_value("draw.pressure_width",get_pressure_width_flag()?"1":"0");
settings.set_value("draw.auto_loop",get_auto_loop_flag()?"1":"0");
settings.set_value("draw.auto_extend",get_auto_extend_flag()?"1":"0");
settings.set_value("draw.auto_link",get_auto_link_flag()?"1":"0");
settings.set_value("draw.region",get_region_flag()?"1":"0");
settings.set_value("draw.outline",get_outline_flag()?"1":"0");
settings.set_value("draw.advanced_outline",get_advanced_outline_flag()?"1":"0");
settings.set_value("draw.auto_export",get_auto_export_flag()?"1":"0");
settings.set_value("draw.min_pressure",strprintf("%f",get_min_pressure()));
settings.set_value("draw.feather",feather_dist.get_value().get_string());
settings.set_value("draw.min_pressure_on",get_min_pressure_flag()?"1":"0");
settings.set_value("draw.gthreshold",strprintf("%f",get_gthres()));
settings.set_value("draw.widthmaxerror",strprintf("%f",get_width_max_error()));
settings.set_value("draw.lthreshold",strprintf("%f",get_lthres()));
settings.set_value("draw.localize",get_local_threshold_flag()?"1":"0");
settings.set_value("draw.round_ends", get_round_ends_flag()?"1":"0");
}
catch(...)
{
synfig::warning("State Draw: Caught exception when attempting to save settings.");
}
}
void
StateDraw_Context::increment_id()
{
String id(get_id());
int number=1;
int digits=0;
if(id.empty())
id="Drawing";
// If there is a number
// already at the end of the
// id, then remove it.
if(id[id.size()-1]<='9' && id[id.size()-1]>='0')
{
// figure out how many digits it is
for (digits = 0;
(int)id.size()-1 >= digits && id[id.size()-1-digits] <= '9' && id[id.size()-1-digits] >= '0';
digits++)
;
String str_number;
str_number=String(id,id.size()-digits,id.size());
id=String(id,0,id.size()-digits);
// synfig::info("---------------- \"%s\"",str_number.c_str());
number=atoi(str_number.c_str());
}
else
{
number=1;
digits=3;
}
number++;
// Add the number back onto the id
{
const String format(strprintf("%%0%dd",digits));
id+=strprintf(format.c_str(),number);
}
// Set the ID
set_id(id);
}
StateDraw_Context::StateDraw_Context(CanvasView* canvas_view):
canvas_view_(canvas_view),
is_working(*canvas_view),
push_state(get_work_area()),
loop_(false),
settings(synfigapp::Main::get_selected_input_device()->settings()),
opacity_hscl(0.0f, 1.01f, 0.01f),
min_pressure_adj(0,0,1,0.01,0.1),
min_pressure_spin(min_pressure_adj,0.1,3),
localthres_adj(20, 1, 100000, 0.1, 1),
localthres_spin(localthres_adj, 0.1, 1),
globalthres_adj(.70f, 0.01, 10000, 0.01, 0.1),
globalthres_spin(globalthres_adj, 0.01, 3),
width_max_error_adj(1.0f, 0.01, 100.0, 0.1,1),
width_max_error_spin(width_max_error_adj, 0.01, 2),
fill_last_stroke_button(_("Fill Last Stroke"))
{
/* Set up the tool options dialog */
// 0, title
title_label.set_label(_("Drawing"));
Pango::AttrList list;
Pango::AttrInt attr = Pango::Attribute::create_attr_weight(Pango::WEIGHT_BOLD);
list.insert(attr);
title_label.set_attributes(list);
title_label.set_alignment(Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER);
// 1, layer name label and entry
id_label.set_label(_("Name:"));
id_label.set_alignment(Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER);
SPACING(id_gap, GAP);
id_box.pack_start(id_label, Gtk::PACK_SHRINK);
id_box.pack_start(*id_gap, Gtk::PACK_SHRINK);
id_box.pack_start(id_entry);
// 2, layer types creation
layer_types_label.set_label(_("Create:"));
layer_types_label.set_alignment(Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER);
LAYER_CREATION(layer_region_togglebutton,
("synfig-layer_geometry_region"), _("Create a region layer"));
LAYER_CREATION(layer_outline_togglebutton,
("synfig-layer_geometry_outline"), _("Create a outline layer"));
LAYER_CREATION(layer_advanced_outline_togglebutton,
("synfig-layer_geometry_advanced_outline"), _("Create a advanced outline layer"));
SPACING(layer_types_indent, INDENTATION);
layer_types_box.pack_start(*layer_types_indent, Gtk::PACK_SHRINK);
layer_types_box.pack_start(layer_region_togglebutton, Gtk::PACK_SHRINK);
layer_types_box.pack_start(layer_outline_togglebutton, Gtk::PACK_SHRINK);
layer_types_box.pack_start(layer_advanced_outline_togglebutton, Gtk::PACK_SHRINK);
// 3, blend method label and dropdown list
blend_label.set_label(_("Blend Method:"));
blend_label.set_alignment(Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER);
SPACING(blend_gap, GAP);
blend_box.pack_start(blend_label, Gtk::PACK_SHRINK);
blend_box.pack_start(*blend_gap, Gtk::PACK_SHRINK);
blend_enum.set_param_desc(ParamDesc(Color::BLEND_COMPOSITE,"blend_method")
.set_local_name(_("Blend Method"))
.set_description(_("Defines the blend method to be used for draws")));
// 4, opacity label and slider
opacity_label.set_label(_("Opacity:"));
opacity_label.set_alignment(Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER);
opacity_hscl.set_digits(2);
opacity_hscl.set_value_pos(Gtk::POS_LEFT);
opacity_hscl.set_tooltip_text(_("Opacity"));
// 5, brush size
bline_width_label.set_label(_("Brush Size:"));
bline_width_label.set_alignment(Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER);
bline_width_dist.set_digits(2);
bline_width_dist.set_range(0,10000000);
// 6, pressure width
pressure_width_label.set_label(_("Pressure Sensitive"));
pressure_width_label.set_alignment(Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER);
pressure_width_box.pack_start(pressure_width_label, Gtk::PACK_SHRINK);
pressure_width_box.pack_end(pressure_width_checkbutton, Gtk::PACK_SHRINK);
// 7, min pressure, sub option of pressure width
SPACING(min_pressure_indent, INDENTATION);
SPACING(min_pressure_gap, GAP);
min_pressure_label.set_label(_("Min Width:"));
min_pressure_label.set_alignment(Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER);
min_pressure_label_box.pack_start(*min_pressure_indent, Gtk::PACK_SHRINK);
min_pressure_label_box.pack_start(min_pressure_label, Gtk::PACK_SHRINK);
min_pressure_box.pack_end(min_pressure_checkbutton, Gtk::PACK_SHRINK);
min_pressure_box.pack_end(*min_pressure_gap, Gtk::PACK_SHRINK);
min_pressure_box.pack_end(min_pressure_spin);
// 8, Smoothness
smoothness_label.set_label(_("Smoothness"));
smoothness_label.set_alignment(Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER);
// 9, local threshold
SPACING(localthres_indent, INDENTATION);
localthres_box.pack_start(*localthres_indent, Gtk::PACK_SHRINK);
localthres_box.pack_start(localthres_radiobutton, Gtk::PACK_SHRINK);
localthres_radiobutton.set_label("Local:");
// 10, global threshold
SPACING(globalthres_indent, INDENTATION);
globalthres_box.pack_start(*globalthres_indent, Gtk::PACK_SHRINK);
globalthres_box.pack_start(globalthres_radiobutton, Gtk::PACK_SHRINK);
globalthres_radiobutton.set_label("Global:");
smoothness_group = localthres_radiobutton.get_group();
globalthres_radiobutton.set_group(smoothness_group);
// 11, width max error of advanced outline layer
width_max_error_label.set_label(_("Width Max Error:"));
SPACING(width_max_error_gap, GAP);
width_max_error_label.set_alignment(Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER);
width_max_error_box.pack_start(width_max_error_label, Gtk::PACK_SHRINK);
width_max_error_box.pack_start(*width_max_error_gap, Gtk::PACK_SHRINK);
// 12, round ends
round_ends_label.set_label(_("Round Ends"));
round_ends_label.set_alignment(Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER);
round_ends_box.pack_start(round_ends_label, Gtk::PACK_SHRINK);
round_ends_box.pack_end(round_ends_checkbutton, Gtk::PACK_SHRINK);
// 13, auto loop
auto_loop_label.set_label(_("Auto Loop"));
auto_loop_label.set_alignment(Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER);
auto_loop_box.pack_start(auto_loop_label, Gtk::PACK_SHRINK);
auto_loop_box.pack_end(auto_loop_checkbutton, Gtk::PACK_SHRINK);
// 14, auto extend
auto_extend_label.set_label(_("Auto Extend"));
auto_extend_label.set_alignment(Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER);
auto_extend_box.pack_start(auto_extend_label, Gtk::PACK_SHRINK);
auto_extend_box.pack_end(auto_extend_checkbutton, Gtk::PACK_SHRINK);
// 15, auto link
auto_link_label.set_label(_("Auto Link"));
auto_link_label.set_alignment(Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER);
auto_link_box.pack_start(auto_link_label, Gtk::PACK_SHRINK);
auto_link_box.pack_end(auto_link_checkbutton, Gtk::PACK_SHRINK);
// 16, feather
feather_label.set_label(_("Feather:"));
feather_label.set_alignment(Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER);
feather_dist.set_digits(2);
feather_dist.set_range(0,10000000);
// 17, auto export
auto_export_label.set_label(_("Auto Export"));
auto_export_label.set_alignment(Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER);
auto_export_box.pack_start(auto_export_label, Gtk::PACK_SHRINK);
auto_export_box.pack_end(auto_export_checkbutton, Gtk::PACK_SHRINK);
nested=0;
load_settings();
UpdateUsePressure();
UpdateCreateAdvancedOutline();
UpdateSmoothness();
// pack all options to the options_table
// 0, title
options_table.attach(title_label,
0, 2, 0, 1, Gtk::FILL, Gtk::FILL, 0, 0
);
// 1, name
options_table.attach(id_box,
0, 2, 1, 2, Gtk::FILL, Gtk::FILL, 0, 0
);
// 2, layer types creation
options_table.attach(layer_types_label,
0, 2, 2, 3, Gtk::FILL, Gtk::FILL, 0, 0
);
options_table.attach(layer_types_box,
0, 2, 3, 4, Gtk::FILL, Gtk::FILL, 0, 0
);
// 3, blend method
options_table.attach(blend_box,
0, 1, 4, 5, Gtk::EXPAND|Gtk::FILL, Gtk::FILL, 0, 0
);
options_table.attach(blend_enum,
1, 2, 4, 5, Gtk::EXPAND|Gtk::FILL, Gtk::FILL, 0, 0
);
// 4, opacity
options_table.attach(opacity_label,
0, 1, 5, 6, Gtk::EXPAND|Gtk::FILL, Gtk::FILL, 0, 0
);
options_table.attach(opacity_hscl,
1, 2, 5, 6, Gtk::EXPAND|Gtk::FILL, Gtk::FILL, 0, 0
);
// 5, brush size
options_table.attach(bline_width_label,
0, 1, 6, 7, Gtk::EXPAND|Gtk::FILL, Gtk::FILL, 0, 0
);
options_table.attach(bline_width_dist,
1, 2, 6, 7, Gtk::EXPAND|Gtk::FILL, Gtk::FILL, 0, 0
);
// 6, pressure width
options_table.attach(pressure_width_box,
0, 2, 7, 8, Gtk::EXPAND|Gtk::FILL, Gtk::FILL, 0, 0
);
// 7, min pressure, sub-option of pressure width
options_table.attach(min_pressure_label_box,
0, 1, 8, 9, Gtk::EXPAND|Gtk::FILL, Gtk::FILL, 0, 0
);
options_table.attach(min_pressure_box,
1, 2, 8, 9, Gtk::EXPAND|Gtk::FILL, Gtk::FILL, 0, 0
);
// 8, smoothness
options_table.attach(smoothness_label,
0, 2, 9, 10, Gtk::EXPAND|Gtk::FILL, Gtk::FILL, 0, 0
);
// 9, local threshold
options_table.attach(localthres_box,
0, 1, 10, 11, Gtk::EXPAND|Gtk::FILL, Gtk::FILL, 0, 0
);
options_table.attach(localthres_spin,
1, 2, 10, 11, Gtk::EXPAND|Gtk::FILL, Gtk::FILL, 0, 0
);
// 10, global threshold
options_table.attach(globalthres_box,
0, 1, 11, 12, Gtk::EXPAND|Gtk::FILL, Gtk::FILL, 0, 0
);
options_table.attach(globalthres_spin,
1, 2, 11, 12, Gtk::EXPAND|Gtk::FILL, Gtk::FILL, 0, 0
);
// 11, width max error of advanced outline layer
options_table.attach(width_max_error_box,
0, 1, 12, 13, Gtk::EXPAND|Gtk::FILL, Gtk::FILL, 0, 0
);
options_table.attach(width_max_error_spin,
1, 2, 12, 13, Gtk::EXPAND|Gtk::FILL, Gtk::FILL, 0, 0
);
// 12, round ends
options_table.attach(round_ends_box,
0, 2, 13, 14, Gtk::FILL, Gtk::FILL, 0, 0
);
// 13, auto loop
options_table.attach(auto_loop_box,
0, 2, 14, 15, Gtk::FILL, Gtk::FILL, 0, 0
);
// 14, auto extend
options_table.attach(auto_extend_box,
0, 2, 15, 16, Gtk::FILL, Gtk::FILL, 0, 0
);
// 15, auto link
options_table.attach(auto_link_box,
0, 2, 16, 17, Gtk::FILL, Gtk::FILL, 0, 0
);
// 16, feather
options_table.attach(feather_label,
0, 1, 17, 18, Gtk::FILL, Gtk::FILL, 0, 0
);
options_table.attach(feather_dist,
1, 2, 17, 18, Gtk::EXPAND|Gtk::FILL, Gtk::FILL, 0, 0
);
// 17, auto export
options_table.attach(auto_export_box,
0, 2, 18, 19, Gtk::FILL, Gtk::FILL, 0, 0
);
// fine-tune options layout
options_table.set_border_width(GAP*2); // border width
options_table.set_row_spacings(GAP); // row gap
options_table.set_row_spacing(0, GAP*2); // the gap between first and second row.
options_table.set_row_spacing(2, 1); // row gap between label and icon of layer type
options_table.set_row_spacing(19, 0); // the final row using border width of table
options_table.show_all();
fill_last_stroke_button.signal_pressed().connect(
sigc::mem_fun(*this, &StateDraw_Context::fill_last_stroke));
pressure_width_checkbutton.signal_toggled().connect(
sigc::mem_fun(*this, &StateDraw_Context::UpdateUsePressure));
layer_advanced_outline_togglebutton.signal_toggled().connect(
sigc::mem_fun(*this, &StateDraw_Context::UpdateCreateAdvancedOutline));
localthres_spin.signal_value_changed().connect(sigc::mem_fun(*this,
&StateDraw_Context::UpdateSmoothness));
globalthres_spin.signal_value_changed().connect(sigc::mem_fun(*this,
&StateDraw_Context::UpdateSmoothness));
refresh_tool_options();
App::dialog_tool_options->present();
// Hide all tangent and width ducks
get_work_area()->set_type_mask(get_work_area()->get_type_mask()-Duck::TYPE_TANGENT-Duck::TYPE_WIDTH);
get_canvas_view()->toggle_duck_mask(Duck::TYPE_NONE);
// Turn off layer clicking
get_work_area()->set_allow_layer_clicks(false);
// Turn off duck clicking
get_work_area()->set_allow_duck_clicks(false);
// Hide the tables if they are showing
prev_table_status=get_canvas_view()->tables_are_visible();
//if(prev_table_status)get_canvas_view()->hide_tables();
// Disable the time bar
get_canvas_view()->set_sensitive_timebar(false);
// Connect a signal
//get_work_area()->signal_user_click().connect(sigc::mem_fun(*this,&studio::StateDraw_Context::on_user_click));
get_work_area()->set_cursor(Gdk::PENCIL);
App::dock_toolbox->refresh();
refresh_ducks();
}
void
StateDraw_Context::UpdateUsePressure()
{
bool status(get_pressure_width_flag());
min_pressure_label.set_sensitive(status);
min_pressure_checkbutton.set_sensitive(status);
min_pressure_spin.set_sensitive(status);
}
void
StateDraw_Context::UpdateCreateAdvancedOutline()
{
width_max_error_label.set_sensitive(get_advanced_outline_flag());
width_max_error_spin.set_sensitive(get_advanced_outline_flag());
}
void
StateDraw_Context::UpdateSmoothness()
{
localthres_radiobutton.set_active(localthres_spin.is_focus());
globalthres_radiobutton.set_active(globalthres_spin.is_focus());
}
void
StateDraw_Context::refresh_tool_options()
{
App::dialog_tool_options->clear();
App::dialog_tool_options->set_widget(options_table);
App::dialog_tool_options->set_local_name(_("Draw Tool"));
App::dialog_tool_options->set_name("draw");
App::dialog_tool_options->add_button(
Gtk::StockID("synfig-fill"),
_("Fill Last Stroke")
)->signal_clicked().connect(
sigc::mem_fun(
*this,
&StateDraw_Context::fill_last_stroke));
}
Smach::event_result
StateDraw_Context::event_refresh_tool_options(const Smach::event& /*x*/)
{
refresh_tool_options();
return Smach::RESULT_ACCEPT;
}
StateDraw_Context::~StateDraw_Context()
{
save_settings();
App::dialog_tool_options->clear();
get_work_area()->reset_cursor();
// Enable the time bar
get_canvas_view()->set_sensitive_timebar(true);
// Bring back the tables if they were out before
if(prev_table_status)get_canvas_view()->show_tables();
// Refresh the work area
get_work_area()->queue_draw();
App::dock_toolbox->refresh();
}
Smach::event_result
StateDraw_Context::event_stop_handler(const Smach::event& /*x*/)
{
//throw Smach::egress_exception();
throw &state_normal;
return Smach::RESULT_OK;
}
Smach::event_result
StateDraw_Context::event_refresh_handler(const Smach::event& /*x*/)
{
refresh_ducks();
return Smach::RESULT_ACCEPT;
}