-
-
Notifications
You must be signed in to change notification settings - Fork 313
/
canvasview.cpp
3997 lines (3427 loc) · 123 KB
/
canvasview.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 canvasview.cpp
** \brief Template File
**
** \legal
** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
** Copyright (c) 2007, 2008 Chris Moore
** Copyright (c) 2009, 2011, 2012 Carlos López
** Copyright (c) 2009, 2011 Nikita Kitaev
** Copyright (c) 2012 Konstantin Dmitriev
**
** This file is part of Synfig.
**
** Synfig 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.
**
** Synfig 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.
**
** You should have received a copy of the GNU General Public License
** along with Synfig. If not, see <https://www.gnu.org/licenses/>.
** \endlegal
*/
/* ========================================================================= */
/* === H E A D E R S ======================================================= */
#ifdef USING_PCH
# include "pch.h"
#else
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <gui/canvasview.h>
#include <algorithm>
#include <cmath>
#include <glibmm/convert.h>
#include <glibmm/uriutils.h>
#include <gtkmm/eventbox.h>
#include <gtkmm/hvseparator.h>
#include <gtkmm/imagemenuitem.h>
#include <gtkmm/label.h>
#include <gtkmm/messagedialog.h>
#include <gtkmm/menuitem.h>
#include <gtkmm/radioaction.h>
#include <gtkmm/scrollbar.h>
#include <gtkmm/separatormenuitem.h>
#include <gtkmm/stock.h>
#include <gtkmm/stylecontext.h>
#include <gtkmm/toolbutton.h>
#include <gtkmm/toolitem.h>
#include <gui/app.h>
#include <gui/dials/keyframedial.h>
#include <gui/docks/dockbook.h>
#include <gui/docks/dockmanager.h>
#include <gui/docks/dock_toolbox.h>
#include <gui/eventkey.h>
#include <gui/exception_guard.h>
#include <gui/localization.h>
#include <gui/preview.h>
#include <gui/states/state_normal.h>
#include <gui/widgets/widget_canvastimeslider.h>
#include <gui/widgets/widget_enum.h>
#include <gui/workarea.h>
#include <pangomm.h>
#include <sstream>
#include <string>
#include <synfig/valuenodes/valuenode_animated.h>
#include <synfigapp/canvasinterface.h>
#include <synfigapp/main.h>
#include <synfigapp/inputdevice.h>
#include <synfigapp/selectionmanager.h>
#include <synfigapp/uimanager.h>
#endif
/* === U S I N G =========================================================== */
using namespace synfig;
using namespace synfigapp;
using namespace studio;
/* === M A C R O S ========================================================= */
#define DEFAULT_TIME_WINDOW_SIZE (10.0)
// use do { } while(0) to avoid problems with: if (...) XXXXX_BUTTON(a, b, c);
#ifndef SMALL_BUTTON
#define SMALL_BUTTON(button, stockid, tooltip) \
do { \
button = manage(new class Gtk::Button()); \
icon=manage(new Gtk::Image(Gtk::StockID(stockid),iconsize)); \
button->add(*icon); \
button->set_tooltip_text(tooltip); \
icon->set_margin_start(0); \
icon->set_margin_end(0); \
icon->set_margin_top(0); \
icon->set_margin_bottom(0); \
icon->show(); \
button->set_relief(Gtk::RELIEF_NONE); \
button->show() \
} while(0)
#endif
#ifndef NORMAL_BUTTON
#define NORMAL_BUTTON(button, stockid, tooltip) \
do { \
button = manage(new class Gtk::Button()); \
icon=manage(new Gtk::Image(Gtk::StockID(stockid),Gtk::ICON_SIZE_BUTTON)); \
button->add(*icon); \
button->set_tooltip_text(tooltip); \
icon->set_margin_start(0); \
icon->set_margin_end(0); \
icon->set_margin_top(0); \
icon->set_margin_bottom(0); \
icon->show(); \
/*button->set_relief(Gtk::RELIEF_NONE);*/ \
button->show(); \
} while(0)
#endif
#define NEW_SMALL_BUTTON(x,y,z) \
Gtk::Button *SMALL_BUTTON(x,y,z)
#define NOT_IMPLEMENTED_SLOT \
sigc::mem_fun(*reinterpret_cast<CanvasViewUIInterface*>(get_ui_interface().get()),&CanvasViewUIInterface::not_implemented)
#define SLOT_EVENT(x) \
sigc::hide_return(sigc::bind(sigc::mem_fun(*this, &CanvasView::process_event_key), x))
/* === C L A S S E S ======================================================= */
class studio::CanvasViewUIInterface : public UIInterface
{
CanvasView *view;
private:
float cur_progress = 0.0;
public:
CanvasViewUIInterface(CanvasView *view):
view(view)
{
view->statusbar->push(_("Idle"));
view->progressbar->hide();
}
~CanvasViewUIInterface() { }
virtual Response confirmation(
const std::string &message,
const std::string &details,
const std::string &cancel,
const std::string &confirm,
Response dflt = RESPONSE_OK )
{
view->present();
//App::process_all_events();
Gtk::MessageDialog dialog(
*App::main_window,
message,
false,
Gtk::MESSAGE_WARNING,
Gtk::BUTTONS_NONE,
true
);
if (! details.empty())
dialog.set_secondary_text(details);
dialog.add_button(cancel, RESPONSE_CANCEL);
dialog.add_button(confirm, RESPONSE_OK);
dialog.set_default_response(dflt);
dialog.show_all();
int response = dialog.run();
if (response != RESPONSE_OK)
return RESPONSE_CANCEL;
return RESPONSE_OK;
}
virtual Response yes_no_cancel(
const std::string &message,
const std::string &details,
const std::string &button1,
const std::string &button2,
const std::string &button3,
Response dflt=RESPONSE_YES )
{
view->present();
//App::process_all_events();
Gtk::MessageDialog dialog(
*App::main_window,
message,
false,
Gtk::MESSAGE_QUESTION,
Gtk::BUTTONS_NONE,
true
);
dialog.set_secondary_text(details);
dialog.add_button(button1, RESPONSE_NO);
dialog.add_button(button2, RESPONSE_CANCEL);
dialog.add_button(button3, RESPONSE_YES);
dialog.set_default_response(dflt);
dialog.show();
int response = dialog.run();
if (response != RESPONSE_YES && response != RESPONSE_NO)
return RESPONSE_CANCEL;
return Response(response);
}
virtual bool
task(const std::string &task)
{
if(!view->is_playing())
{
view->statusbar->pop();
view->statusbar->push(task);
view->statusbar->set_tooltip_text(task);
}
//App::process_all_events();
if(view->cancel){return false;}
return true;
}
virtual bool
error(const std::string &err)
{
view->statusbar->push(_("ERROR"));
// If we are in the process of canceling,
// then just go ahead and return false --
// don't bother displaying a dialog
if(view->cancel)return false;
Gtk::MessageDialog dialog(*App::main_window, err, false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_CLOSE, true);
dialog.show();
dialog.run();
view->statusbar->pop();
return true;
}
virtual bool
warning(const std::string &err)
{
view->statusbar->pop();
view->statusbar->push(err);
//App::process_all_events();
if(view->cancel)return false;
return true;
}
virtual bool
amount_complete(int current, int total)
{
float temp = (float)current/(float)total;
if(temp >= 1.0)
{
view->statusbar->show();
view->progressbar->hide();
}
else if(fabs(temp-cur_progress) >= 0.01)
{
cur_progress = temp;
view->statusbar->hide();
view->progressbar->show();
view->progressbar->set_fraction(cur_progress);
studio::App::process_all_events();
return true;
}
if(!view->is_playing())
{
if(!view->working_depth)
{
if(current)
view->stopbutton->set_sensitive(true);
else
view->stopbutton->set_sensitive(false);
}
float x((float)current/(float)total);
if(x<0)x=0;
else if(x>1)x=1;
}
//App::process_all_events();
if(view->cancel){/*view->cancel=false;*/return false;}
return true;
}
void
not_implemented()
{ error(_("Feature not yet implemented")); }
};
class studio::CanvasViewSelectionManager : public SelectionManager
{
CanvasView *view;
CanvasView::LayerTreeModel layer_tree_model;
CanvasView::ChildrenTreeModel children_tree_model;
public:
CanvasViewSelectionManager(CanvasView *view): view(view) { }
private:
void _set_selected_layer(const Layer::Handle &layer)
{ view->layer_tree->select_layer(layer); }
public:
//! Returns the number of layers selected.
virtual int get_selected_layer_count()const
{ return get_selected_layers().size(); }
//! Returns a list of the currently selected layers.
virtual LayerList get_selected_layers()const
{
if(!view->layer_tree) { error("%s:%d canvas_view.layer_tree not defined!?", __FILE__, __LINE__); return LayerList(); }
return view->layer_tree->get_selected_layers();
}
//! Returns the first layer selected or an empty handle if none are selected.
virtual Layer::Handle get_selected_layer()const
{
if(!view->layer_tree) { error("%s:%d canvas_view.layer_tree not defined!?", __FILE__, __LINE__); return 0; }
return view->layer_tree->get_selected_layer();
}
//! Sets which layers should be selected
virtual void set_selected_layers(const LayerList &layer_list)
{
if(!view->layer_tree) { error("%s:%d canvas_view.layer_tree not defined!?", __FILE__, __LINE__); return; }
view->layer_tree->select_layers(layer_list);
}
//! Sets which layer should be selected.
virtual void set_selected_layer(const Layer::Handle &layer)
{
if(!view->layer_tree) { error("canvas_view.layer_tree not defined!?"); return; }
view->layer_tree->select_layer(layer);
}
//! Clears the layer selection list
virtual void clear_selected_layers()
{
if(!view->layer_tree) return;
view->layer_tree->clear_selected_layers();
}
virtual LayerList get_expanded_layers()const
{
if(!view->layer_tree) { error("%s:%d canvas_view.layer_tree not defined!?", __FILE__, __LINE__); return LayerList(); }
return view->layer_tree->get_expanded_layers();
}
virtual void set_expanded_layers(const LayerList &layer_list)
{
if(!view->layer_tree) { error("%s:%d canvas_view.layer_tree not defined!?", __FILE__, __LINE__); return; }
view->layer_tree->expand_layers(layer_list);
}
//! Returns the number of value_nodes selected.
virtual int get_selected_children_count()const
{ return get_selected_children().size(); }
static inline void __child_grabber(const Gtk::TreeModel::iterator& iter, ChildrenList* ret)
{
const CanvasView::ChildrenTreeModel children_tree_model;
ValueDesc value_desc((*iter)[children_tree_model.value_desc]);
if(value_desc)
ret->push_back(value_desc);
}
//! Returns a list of the currently selected value_nodes.
virtual ChildrenList get_selected_children()const
{
if(!view->children_tree) return ChildrenList();
Glib::RefPtr<Gtk::TreeSelection> selection=view->children_tree->get_selection();
if(!selection)
return ChildrenList();
ChildrenList ret;
selection->selected_foreach_iter( sigc::bind(
sigc::ptr_fun( &CanvasViewSelectionManager::__child_grabber ),
&ret ));
return ret;
}
//! Returns the first value_node selected or an empty handle if none are selected.
virtual ChildrenList::value_type get_selected_child()const
{
if(!view->children_tree) return ChildrenList::value_type();
ChildrenList children(get_selected_children());
if(children.empty())
return ChildrenList::value_type();
return children.front();
}
//! Sets which value_nodes should be selected
virtual void set_selected_children(const ChildrenList &/*children_list*/) { }
//! Sets which value_node should be selected. Empty handle if none.
virtual void set_selected_child(const ChildrenList::value_type &/*child*/) { }
//! Clears the value_node selection list
virtual void clear_selected_children() { }
int get_selected_layer_parameter_count()const
{ return get_selected_layer_parameters().size(); }
LayerParamList get_selected_layer_parameters()const
{
if(!view->layer_tree) return LayerParamList();
Glib::RefPtr<Gtk::TreeSelection> selection=view->layer_tree->get_selection();
if(!selection)
return LayerParamList();
LayerParamList ret;
Gtk::TreeModel::Children children = view->layer_tree_store()->children();
for(Gtk::TreeModel::Children::const_iterator i = children.begin(); i != children.end(); ++i)
for(Gtk::TreeModel::Children::const_iterator j = i->children().begin(); j != i->children().end(); ++j)
if(selection->is_selected(*j))
ret.push_back(LayerParam((*j)[layer_tree_model.layer], (Glib::ustring)(*j)[layer_tree_model.id]));
return ret;
}
LayerParam get_selected_layer_parameter() const
{
if(!view->layer_tree) return LayerParam();
return get_selected_layer_parameters().front();
}
void set_selected_layer_parameters(const LayerParamList &/*layer_param_list*/) { }
void set_selected_layer_param(const LayerParam &/*layer_param*/) { }
void clear_selected_layer_parameters() { }
}; // END of class SelectionManager
CanvasView::IsWorking::IsWorking(CanvasView &canvas_view_):
canvas_view_(canvas_view_)
{
if(!canvas_view_.working_depth)
canvas_view_.stopbutton->set_sensitive(true);
canvas_view_.working_depth++;
canvas_view_.cancel=false;
}
CanvasView::IsWorking::~IsWorking()
{
canvas_view_.working_depth--;
if(!canvas_view_.working_depth)
canvas_view_.stopbutton->set_sensitive(false);
}
CanvasView::IsWorking::operator bool()const
{
if(canvas_view_.cancel)
return false;
return true;
}
/* === M E T H O D S ======================================================= */
LockDucks::LockDucks(const CanvasView::Handle &canvas_view):
canvas_view_handle(canvas_view.get()),
canvas_view(canvas_view.get())
{
if (!this->canvas_view) return;
++(this->canvas_view->ducks_locks);
}
LockDucks::LockDucks(CanvasView &canvas_view):
canvas_view(&canvas_view)
{
if (!this->canvas_view) return;
++(this->canvas_view->ducks_locks);
}
LockDucks::~LockDucks() {
if (!canvas_view) return;
SYNFIG_EXCEPTION_GUARD_BEGIN()
if (--(canvas_view->ducks_locks) == 0) {
if (canvas_view->ducks_rebuild_requested)
canvas_view->rebuild_ducks();
else
if (canvas_view->ducks_rebuild_queue_requested)
canvas_view->queue_rebuild_ducks();
}
SYNFIG_EXCEPTION_GUARD_END()
}
CanvasView::ActivationIndex CanvasView::ActivationIndex::last__;
CanvasView::CanvasView(etl::loose_handle<Instance> instance,etl::handle<CanvasInterface> canvas_interface_):
Dockable(synfig::GUID().get_string(),_("Canvas View")),
work_area (),
activation_index_ (true),
smach_ (this),
instance_ (instance),
canvas_interface_ (canvas_interface_),
context_params_ (true),
time_model_ (new TimeModel()),
statusbar (manage(new class Gtk::Statusbar())),
progressbar (manage(new class Gtk::ProgressBar())),
jackbutton (NULL),
offset_widget (NULL),
toggleducksdial (Gtk::IconSize::from_name("synfig-small_icon_16x16")),
resolutiondial (Gtk::IconSize::from_name("synfig-small_icon_16x16")),
future_onion_adjustment_ (Gtk::Adjustment::create(0,0,ONION_SKIN_FUTURE,1,1,0)),
past_onion_adjustment_ (Gtk::Adjustment::create(1,0,ONION_SKIN_PAST,1,1,0)),
timeslider (manage(new Widget_CanvasTimeslider)),
widget_kf_list (manage(new Widget_Keyframe_List)),
ui_interface_ (new CanvasViewUIInterface(this)),
selection_manager_ (new CanvasViewSelectionManager(this)),
jack_enabled (false),
jack_actual_enabled (false),
jack_locks (0),
jack_enabled_in_preview (false),
#ifdef WITH_JACK
jack_client (NULL),
jack_synchronizing (true),
jack_is_playing (false),
jack_time (0),
toggling_jack (false),
#endif
ducks_locks (0),
ducks_rebuild_requested (false),
ducks_rebuild_queue_requested(false),
working_depth (0),
cancel (false),
canvas_properties (*App::main_window,canvas_interface_),
render_settings (*App::main_window,canvas_interface_),
waypoint_dialog (*App::main_window,canvas_interface_->get_canvas()),
keyframe_dialog (*App::main_window,canvas_interface_),
preview_dialog ()
{
// Make this toolbar small for space efficiency
get_style_context()->add_class("synfigstudio-efficient-workspace");
canvas_options = CanvasOptions::create(*App::main_window, this);
layer_tree=0;
children_tree=0;
toggling_ducks_=false;
toggling_animate_mode_=false;
changing_resolution_=false;
toggling_show_grid=false;
toggling_snap_grid=false;
toggling_show_guides=false;
toggling_snap_guides=false;
toggling_onion_skin=false;
toggling_onion_skin_keyframes=false;
toggling_background_rendering=false;
set_use_scrolled(false);
//info("Canvasview: Entered constructor");
// Minor hack
get_canvas()->set_time(0);
//layer_tree_store_->rebuild();
// Set up the UI and Selection managers
canvas_interface()->set_ui_interface(get_ui_interface());
canvas_interface()->set_selection_manager(get_selection_manager());
//info("Canvasview: Before big chunk of allocation and tabling stuff");
//create all allocated stuff for this canvas
Gtk::Widget *widget_work_area = create_work_area();
widget_work_area->set_margin_top(4);
init_menus();
Gtk::Widget *widget_top_bar = create_top_toolbar();
Gtk::Widget *widget_stopbutton = create_stop_button();
Gtk::Widget *widget_right_bar = create_right_toolbar();
Gtk::Widget *widget_time_bar = create_time_bar();
Gtk::Grid *layout_grid = manage(new Gtk::Grid());
layout_grid->attach(*widget_top_bar, 0, 0, 1, 1);
layout_grid->attach(*widget_stopbutton, 1, 0, 1, 1);
layout_grid->attach(*widget_right_bar, 1, 1, 1, 2);
layout_grid->attach(*widget_work_area, 0, 2, 1, 1);
layout_grid->attach(*widget_time_bar, 0, 3, 2, 1);
layout_grid->show();
Gtk::EventBox *event_box = manage(new Gtk::EventBox());
event_box->add(*layout_grid);
event_box->show();
event_box->signal_button_press_event().connect(sigc::mem_fun(*this,&CanvasView::on_button_press_event));
add(*event_box);
update_title();
smach_.set_default_state(&state_normal);
//info("Canvasview: Before Signals");
//SIGNALS
#define CONNECT(x, y) x().connect(sigc::mem_fun(*this, y))
CONNECT(canvas_interface()->signal_dirty_preview, &CanvasView::on_dirty_preview);
CONNECT(canvas_interface()->signal_mode_changed, &CanvasView::on_mode_changed);
CONNECT(canvas_interface()->signal_time_changed, &CanvasView::on_interface_time_changed);
#undef CONNECT
canvas_interface()->signal_id_changed().connect(sigc::mem_fun(*this,&CanvasView::on_id_changed));
canvas_interface()->signal_rend_desc_changed().connect(sigc::mem_fun(*this,&CanvasView::refresh_rend_desc));
waypoint_dialog.signal_changed().connect(sigc::mem_fun(*this,&CanvasView::on_waypoint_changed));
waypoint_dialog.signal_delete().connect(sigc::mem_fun(*this,&CanvasView::on_waypoint_delete));
//MODIFIED TIME ADJUSTMENT STUFF....
time_model()->signal_time_changed().connect(
sigc::mem_fun(*this, &CanvasView::on_time_changed));
time_model()->signal_visible_changed().connect(
sigc::mem_fun(*this, &CanvasView::refresh_time_window));
time_model()->signal_play_bounds_changed().connect(
sigc::mem_fun(*this, &CanvasView::refresh_time_window));
work_area->signal_layer_selected().connect(sigc::mem_fun(*this,&CanvasView::workarea_layer_selected));
work_area->signal_input_device_changed().connect(sigc::mem_fun(*this,&CanvasView::on_input_device_changed));
work_area->signal_meta_data_changed().connect(sigc::mem_fun(*this,&CanvasView::on_meta_data_changed));
canvas_interface()->signal_canvas_added().connect(
sigc::hide( sigc::mem_fun(*instance,&Instance::refresh_canvas_tree)));
canvas_interface()->signal_canvas_removed().connect(
sigc::hide( sigc::mem_fun(*instance,&Instance::refresh_canvas_tree)));
canvas_interface()->signal_layer_param_changed().connect(
sigc::hide(sigc::hide( SLOT_EVENT(EVENT_REFRESH_DUCKS))));
canvas_interface()->signal_keyframe_properties().connect(
sigc::mem_fun(*this,&CanvasView::show_keyframe_dialog));
//MUCH TIME STUFF TAKES PLACE IN HERE
refresh_rend_desc();
refresh_time_window();
std::vector<Gtk::TargetEntry> listTargets;
listTargets.push_back(Gtk::TargetEntry("text/uri-list"));
listTargets.push_back(Gtk::TargetEntry("text/plain"));
listTargets.push_back(Gtk::TargetEntry("STRING"));
drag_dest_set(listTargets);
signal_drag_data_received().connect(sigc::mem_fun(*this, &CanvasView::on_drop_drag_data_received));
hide_tables();
show();
instance->canvas_view_list().push_front(this);
instance->signal_canvas_view_created()(this);
//info("Canvasview: Constructor Done");
if (App::jack_is_locked())
jack_lock();
#ifdef WITH_JACK
jack_dispatcher.connect(sigc::mem_fun(*this, &CanvasView::on_jack_sync));
#endif
App::dock_manager->register_dockable(*this);
App::main_window->main_dock_book().add(*this);
time_model()->all_changed();
present();
App::set_selected_canvas_view(this);
}
CanvasView::~CanvasView()
{
SYNFIG_EXCEPTION_GUARD_BEGIN()
#ifdef WITH_JACK
set_jack_enabled(false);
#endif
App::dock_manager->unregister_dockable(*this);
signal_deleted()();
// I didn't find a proper way to check if actiongroup is already removed on CanvasView::deactivate
// So here is a quick-hack. This error is mostly invisible because it fails on App exiting
// but i didn't think it worth to spend time to it, because remove_action_group is deprecated
// and this code is required to rewrite.
if (!this->_action_group_removed)
App::ui_manager()->remove_action_group(action_group);
// Shut down the smach
smach_.egress();
smach_.set_default_state(0);
// We want to ensure that the UI_Manager and
// the selection manager get destructed right now.
ui_interface_.reset();
selection_manager_.reset();
// don't be calling on_dirty_preview once this object has been deleted;
// this was causing a crash before
canvas_interface()->signal_dirty_preview().clear();
delete canvas_options;
if (getenv("SYNFIG_DEBUG_DESTRUCTORS"))
info("CanvasView::~CanvasView(): Deleted");
SYNFIG_EXCEPTION_GUARD_END()
}
void CanvasView::save_all()
{
std::list<etl::handle<Instance> >::iterator iter;
for(iter=App::instance_list.begin();iter!=App::instance_list.end();iter++)
(*iter)->save();
}
void CanvasView::activate()
{
activation_index_.activate();
get_smach().process_event(EVENT_REFRESH_TOOL_OPTIONS);
App::ui_manager()->insert_action_group(action_group);
this->_action_group_removed = false;
update_title();
present();
grab_focus();
}
void CanvasView::deactivate()
{
get_smach().process_event(EVENT_YIELD_TOOL_OPTIONS);
App::ui_manager()->remove_action_group(action_group);
this->_action_group_removed = true;
update_title();
}
void CanvasView::present()
{
show(); // gtk_widget_show also checks visibility, so there is no need to call `is_visible()`
App::set_selected_canvas_view(this);
update_title();
Dockable::present();
}
void CanvasView::jack_lock()
{
++jack_locks;
#ifdef WITH_JACK
if (jack_locks == 1)
set_jack_enabled(get_jack_enabled());
#endif
}
void CanvasView::jack_unlock()
{
--jack_locks;
assert(jack_locks >= 0);
#ifdef WITH_JACK
if (jack_locks == 0)
set_jack_enabled(get_jack_enabled());
#endif
}
#ifdef WITH_JACK
void CanvasView::set_jack_enabled(bool value)
{
bool actual_value = value && !jack_is_locked();
if (jack_actual_enabled != actual_value) {
jack_actual_enabled = actual_value;
if (jack_actual_enabled)
{
// initialize jack
stop();
jack_client = jack_client_open("synfigstudiocanvas", JackNullOption, 0);
jack_set_sync_callback(jack_client, jack_sync_callback, this);
if (jack_activate(jack_client) != 0)
{
jack_client_close(jack_client);
jack_client = NULL;
jack_actual_enabled = false;
// make conditions to update button
jack_enabled = true;
value = false;
}
}
else
{
// deinitialize jack
jack_deactivate(jack_client);
jack_client_close(jack_client);
jack_client = NULL;
}
jackbutton->set_sensitive(!jack_is_locked());
}
if (jack_enabled != value)
{
jack_enabled = value;
Gtk::IconSize iconsize=Gtk::IconSize::from_name("synfig-small_icon_16x16");
Gtk::Image *icon;
offset_widget = jackdial->get_offsetwidget();
if (jackbutton->get_active() != jack_enabled)
jackbutton->set_active(jack_enabled);
if (jack_enabled)
{
icon = manage(new Gtk::Image(Gtk::StockID("synfig-jack"),iconsize));
jackbutton->remove();
jackbutton->add(*icon);
jackbutton->set_tooltip_text(_("Disable JACK"));
icon->set_margin_start(0);
icon->set_margin_end(0);
icon->set_margin_top(0);
icon->set_margin_bottom(0);
icon->show();
offset_widget->show();
}
else
{
icon = manage(new Gtk::Image(Gtk::StockID("synfig-jack"),iconsize));
jackbutton->remove();
jackbutton->add(*icon);
jackbutton->set_tooltip_text(_("Enable JACK"));
icon->set_margin_start(0);
icon->set_margin_end(0);
icon->set_margin_top(0);
icon->set_margin_bottom(0);
icon->show();
offset_widget->hide();
}
}
}
#endif
std::list<int>&
CanvasView::get_pixel_sizes()
{
// prime factors of 64 is 2, 2, 2, 2, 2, 2 - see TILE_SIZE in synfig-core/trunk/src/synfig/target_tile.h
// also see available low-res renderer engines in rendering::Renderer::initialize_renderers()
static int pixel_size_array[] = {2, 4, 8, 16};
static std::list<int> pixel_sizes(pixel_size_array, pixel_size_array + sizeof(pixel_size_array)/sizeof(int));
return pixel_sizes;
}
Gtk::Widget*
CanvasView::create_time_bar()
{
//Setup the keyframe list widget
widget_kf_list->set_time_model(time_model());
widget_kf_list->set_canvas_interface(canvas_interface());
widget_kf_list->show();
// Setup Time Slider
timeslider->set_canvas_view(this);
timeslider->set_can_focus(true);
timeslider->show();
// Setup Time Scroll
Gtk::Scrollbar *time_window_scroll = manage(new class Gtk::Scrollbar(time_model()->scroll_time_adjustment()));
time_window_scroll->set_tooltip_text(_("Moves the time window"));
//time_window_scroll->set_can_focus(true); // Uncomment this produce bad render of the HScroll
time_window_scroll->show();
timetrack = manage(new Gtk::Grid());
time_window_scroll->set_hexpand(true);
timetrack->attach(*time_window_scroll, 0, 0, 1, 1);
timeslider->set_hexpand(true);
timetrack->attach(*timeslider, 0, 1, 1, 1);
timeslider->set_hexpand(true);
timetrack->attach(*widget_kf_list, 0, 2, 1, 1);
timetrack->hide();
// Interpolation widget
widget_interpolation = manage(new Widget_Enum());
widget_interpolation->set_param_desc(
ParamDesc("interpolation")
.set_hint("enum")
.add_enum_value(INTERPOLATION_CLAMPED,"clamped",_("Clamped"))
.add_enum_value(INTERPOLATION_TCB,"auto",_("TCB"))
.add_enum_value(INTERPOLATION_CONSTANT,"constant",_("Constant"))
.add_enum_value(INTERPOLATION_HALT,"ease",_("Ease In/Out"))
.add_enum_value(INTERPOLATION_LINEAR,"linear",_("Linear"))
);
widget_interpolation->set_icon(0, Gtk::Button().render_icon_pixbuf(Gtk::StockID("synfig-interpolation_type_clamped"), Gtk::ICON_SIZE_MENU));
widget_interpolation->set_icon(1, Gtk::Button().render_icon_pixbuf(Gtk::StockID("synfig-interpolation_type_tcb"), Gtk::ICON_SIZE_MENU));
widget_interpolation->set_icon(2, Gtk::Button().render_icon_pixbuf(Gtk::StockID("synfig-interpolation_type_const"), Gtk::ICON_SIZE_MENU));
widget_interpolation->set_icon(3, Gtk::Button().render_icon_pixbuf(Gtk::StockID("synfig-interpolation_type_ease"), Gtk::ICON_SIZE_MENU));
widget_interpolation->set_icon(4, Gtk::Button().render_icon_pixbuf(Gtk::StockID("synfig-interpolation_type_linear"), Gtk::ICON_SIZE_MENU));
widget_interpolation->set_tooltip_text(_("Default Interpolation"));
widget_interpolation->set_popup_fixed_width(false);
widget_interpolation->set_hexpand(false);
widget_interpolation->show();
widget_interpolation->signal_changed().connect(sigc::mem_fun(*this, &CanvasView::on_interpolation_changed));
synfigapp::Main::signal_interpolation_changed().connect(sigc::mem_fun(*this, &CanvasView::interpolation_refresh));
synfigapp::Main::set_interpolation(INTERPOLATION_CLAMPED); // Clamped by default.
interpolation_refresh();
//Setup the Animation Mode Button and the Keyframe Lock button
{
Gtk::IconSize iconsize=Gtk::IconSize::from_name("synfig-small_icon_16x16");
Gtk::Image *icon = manage(new Gtk::Image(Gtk::StockID("synfig-animate_mode_off"), iconsize));
animatebutton = Gtk::manage(new class Gtk::ToggleButton());
animatebutton->set_tooltip_text(_("Turn on animate editing mode"));
icon->show();
// Set hotkey to toggle animate button on and off
auto accel_group = App::ui_manager()->get_accel_group();
animatebutton->set_accel_path("<Actions>/canvasview/animate", accel_group);
animatebutton->add(*icon);
animatebutton->signal_toggled().connect(sigc::mem_fun(*this, &CanvasView::toggle_animatebutton));
animatebutton->set_relief(Gtk::RELIEF_NONE);
animatebutton->show();
}
{
Gtk::IconSize iconsize=Gtk::IconSize::from_name("synfig-small_icon_16x16");
Gtk::Image *icon = manage(new Gtk::Image(Gtk::StockID("synfig-timetrack"), iconsize));
timetrackbutton = Gtk::manage(new class Gtk::ToggleButton());
timetrackbutton->set_tooltip_text(_("Toggle timebar"));
icon->show();
timetrackbutton->add(*icon);
timetrackbutton->signal_toggled().connect(sigc::mem_fun(*this, &CanvasView::toggle_timetrackbutton));
timetrackbutton->set_relief(Gtk::RELIEF_NONE);
timetrackbutton->show();
}
//Setup the current time widget
current_time_widget=manage(new Widget_Time);
current_time_widget->set_value(get_time());
current_time_widget->set_fps(get_canvas()->rend_desc().get_frame_rate());
current_time_widget->signal_value_changed().connect(
sigc::mem_fun(*this,&CanvasView::on_current_time_widget_changed)
);
current_time_widget->set_size_request(0,-1); // request horizontal shrink
current_time_widget->set_width_chars(5);
current_time_widget->set_tooltip_text(_("Current time"));
current_time_widget->show();
//Setup the FrameDial widget
framedial = manage(new class FrameDial());
//Setup end time widget
framedial->set_end_time(get_canvas()->rend_desc().get_frame_rate(), get_canvas()->rend_desc().get_time_end());
framedial->signal_seek_begin().connect(
sigc::mem_fun(*this, &CanvasView::on_seek_begin_pressed) );
framedial->signal_seek_prev_keyframe().connect(
sigc::mem_fun(*canvas_interface().get(), &CanvasInterface::jump_to_prev_keyframe));
framedial->signal_seek_prev_frame().connect(
sigc::bind(sigc::mem_fun(*canvas_interface().get(), &CanvasInterface::seek_frame), -1));
framedial->signal_play().connect(
sigc::mem_fun(*this, &CanvasView::on_play_pause_pressed));
framedial->signal_pause().connect(
sigc::mem_fun(*this, &CanvasView::on_play_pause_pressed));
framedial->signal_seek_next_frame().connect(
sigc::bind(sigc::mem_fun(*canvas_interface().get(), &CanvasInterface::seek_frame), 1));
framedial->signal_seek_next_keyframe().connect(
sigc::mem_fun(*canvas_interface().get(), &CanvasInterface::jump_to_next_keyframe));
framedial->signal_seek_end().connect(
sigc::mem_fun(*this, &CanvasView::on_seek_end_pressed) );
framedial->signal_end_time_changed().connect(
sigc::mem_fun(*this,&CanvasView::on_set_end_time_widget_changed));
framedial->signal_repeat().connect(
sigc::mem_fun(*time_model(), &TimeModel::set_play_repeat));
framedial->signal_bounds_enable().connect(
sigc::mem_fun(*time_model(), &TimeModel::set_play_bounds_enabled));
framedial->signal_bound_lower().connect(
sigc::bind(sigc::mem_fun(*time_model(), &TimeModel::set_play_bounds_enabled), true));
framedial->signal_bound_lower().connect(
sigc::mem_fun(*time_model(), &TimeModel::set_play_bounds_lower_to_current));
framedial->signal_bound_upper().connect(
sigc::bind(sigc::mem_fun(*time_model(), &TimeModel::set_play_bounds_enabled), true));
framedial->signal_bound_upper().connect(
sigc::mem_fun(*time_model(), &TimeModel::set_play_bounds_upper_to_current));
framedial->show();
Gtk::Separator *separator = manage(new Gtk::Separator());
separator->show();
//Setup the KeyFrameDial widget
KeyFrameDial *keyframedial = Gtk::manage(new class KeyFrameDial());
keyframedial->signal_toggle_keyframe_past().connect(sigc::mem_fun(*this, &CanvasView::toggle_past_keyframe_button));
keyframedial->signal_toggle_keyframe_future().connect(sigc::mem_fun(*this, &CanvasView::toggle_future_keyframe_button));