-
Notifications
You must be signed in to change notification settings - Fork 23
/
inspector.cpp
798 lines (666 loc) · 25.8 KB
/
inspector.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
// Inspector
#include "inspector.h"
#include "app.h"
#include "libs/imgui/imgui.h"
#include "widgets.h"
#include "editing.h"
#include "colors.h"
#include <opentimelineio/anyDictionary.h>
#include <opentimelineio/clip.h>
#include <opentimelineio/effect.h>
#include <opentimelineio/gap.h>
#include <opentimelineio/linearTimeWarp.h>
#include <opentimelineio/marker.h>
#include <opentimelineio/track.h>
#include <opentimelineio/transition.h>
#include <implot.h>
#include <TextEditor.h>
static const char* marker_color_names[] = {
"PINK", "RED", "ORANGE", "YELLOW",
"GREEN", "CYAN", "BLUE", "PURPLE",
"MAGENTA", "BLACK", "WHITE"
};
const TextEditor::LanguageDefinition& OTIOLanguageDef()
{
static bool inited = false;
static TextEditor::LanguageDefinition langDef;
if (!inited)
{
static const char* const keywords[] = {
"true", "false", "null"
};
for (auto& k : keywords)
langDef.mKeywords.insert(k);
static const char* const identifiers[] = {
"\"OTIO_SCHEMA\""
};
for (auto& k : identifiers)
{
TextEditor::Identifier id;
id.mDeclaration = "OpenTimelineIO Schema";
langDef.mIdentifiers.insert(std::make_pair(std::string(k), id));
}
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, TextEditor::PaletteIndex>("\\\"OTIO_SCHEMA\\\"", TextEditor::PaletteIndex::Identifier));
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, TextEditor::PaletteIndex>("\\\"(\\\\.|[^\\\"])*\\\"", TextEditor::PaletteIndex::String));
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, TextEditor::PaletteIndex>("[+-]?([0-9]+([.][0-9]*)?|[.][0-9]+)([eE][+-]?[0-9]+)?", TextEditor::PaletteIndex::Number));
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, TextEditor::PaletteIndex>("[a-zA-Z_][a-zA-Z0-9_]*", TextEditor::PaletteIndex::Identifier));
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, TextEditor::PaletteIndex>("[\\[\\]\\{\\}\\,\\:]", TextEditor::PaletteIndex::Punctuation));
langDef.mCommentStart = "/*";
langDef.mCommentEnd = "*/";
langDef.mSingleLineComment = "//";
langDef.mCaseSensitive = true;
langDef.mAutoIndentation = true;
langDef.mName = "JSON";
inited = true;
}
return langDef;
}
TextEditor jsonEditor;
TextEditor::LanguageDefinition otioLangDef = OTIOLanguageDef();
void UpdateJSONInspector() {
jsonEditor.SetReadOnly(true);
jsonEditor.SetLanguageDefinition(otioLangDef);
jsonEditor.SetText(appState.selected_text);
}
void DrawJSONInspector() {
jsonEditor.Render("JSON");
}
void DrawNonEditableTextField(const char* label, const char* format, ...) {
char tmp_str[1000];
va_list args;
va_start(args, format);
vsnprintf(tmp_str, sizeof(tmp_str), format, args);
va_end(args);
// Adjust style so the user can see that it is not editable
ImGui::PushStyleColor(
ImGuiCol_FrameBg,
ImGui::GetStyleColorVec4(ImGuiCol_TableHeaderBg));
ImGui::InputText(
label,
tmp_str,
sizeof(tmp_str),
ImGuiInputTextFlags_ReadOnly);
ImGui::PopStyleColor();
}
std::string DrawColorChooser(std::string current_color_name)
{
const char** color_choices = marker_color_names;
int num_color_choices = IM_ARRAYSIZE(marker_color_names);
int current_index = -1;
for (int i = 0; i < num_color_choices; i++) {
if (current_color_name == color_choices[i]) {
current_index = i;
break;
}
}
if (ImGui::Combo("Color", ¤t_index, color_choices, num_color_choices)) {
if (current_index >= 0 && current_index < num_color_choices) {
return color_choices[current_index];
}
}
return "";
}
bool DrawRationalTime(
const char* label,
otio::RationalTime* time,
bool allow_negative = false) {
if (time == NULL)
return false;
auto formatted = FormattedStringFromTime(*time);
if (appState.snap_to_frames) {
int val = floor(time->value()); // snap with floor()
if (ImGui::DragInt(
label,
&val,
0.1,
allow_negative ? INT_MIN : 0,
INT_MAX,
formatted.c_str())) {
*time = otio::RationalTime(val, time->rate());
return true;
}
} else {
float val = time->value();
if (ImGui::DragFloat(
label,
&val,
0.01,
allow_negative ? -FLT_MAX : 0,
FLT_MAX,
formatted.c_str())) {
*time = otio::RationalTime(val, time->rate());
return true;
}
}
return false;
/*
float vals[2];
vals[0] = time->value();
vals[1] = time->rate();
if (ImGui::DragFloat2(
label,
vals,
0.01,
allow_negative ? -FLT_MAX : 0, FLT_MAX,
FormattedStringFromTime(*time, false).c_str()))
{
*time = otio::RationalTime(vals[0], vals[1]);
return true;
}
return false;
*/
}
bool DrawTimeRange(
const char* label,
otio::TimeRange* range,
bool allow_negative = false) {
if (range == NULL)
return false;
otio::RationalTime start = range->start_time();
otio::RationalTime duration = range->duration();
bool changed = false;
ImGui::Text("%s", label);
ImGui::Indent();
char buf[100];
snprintf(buf, sizeof(buf), "Start##%s", label);
if (DrawRationalTime(buf, &start, allow_negative)) {
changed = true;
}
snprintf(buf, sizeof(buf), "Duration##%s", label);
if (DrawRationalTime(buf, &duration, false)) { // never negative
changed = true;
}
snprintf(buf, sizeof(buf), "End##%s", label);
DrawNonEditableTextField(
buf,
"%s",
FormattedStringFromTime(range->end_time_inclusive()).c_str());
ImGui::Unindent();
if (changed) {
*range = otio::TimeRange(start, duration);
}
return changed;
}
void DrawMetadataSubtree(std::string key, otio::AnyDictionary& metadata);
void DrawMetadataArray(std::string key, otio::AnyVector& vector);
void DrawMetadataRow(std::string key, std::any& value) {
std::type_info const& type = value.type();
if (type == typeid(otio::AnyDictionary)) {
auto dict = std::any_cast<otio::AnyDictionary>(value);
DrawMetadataSubtree(key, dict);
return;
}
if (type == typeid(otio::AnyVector)) {
auto vector = std::any_cast<otio::AnyVector>(value);
DrawMetadataArray(key, vector);
return;
}
std::string type_name = "<Unknown>";
std::string string_val = "<Unknown>";
otio::SerializableObject *selectable = nullptr;
if (type == typeid(std::string)) {
type_name = "string";
string_val = std::any_cast<std::string>(value);
}
else if (type == typeid(bool)) {
type_name = "bool";
string_val = std::any_cast<bool>(value) ? "true" : "false";
}
else if (type == typeid(int64_t)) {
type_name = "int64_t";
string_val = std::to_string(std::any_cast<int64_t>(value));
}
else if (type == typeid(double)) {
type_name = "double";
string_val = std::to_string(std::any_cast<double>(value));
}
else if (type == typeid(otio::RationalTime)) {
type_name = "otio::RationalTime";
auto time = std::any_cast<otio::RationalTime>(value);
string_val = FormattedStringFromTime(time);
}
else if (type == typeid(otio::SerializableObject::Retainer<otio::SerializableObjectWithMetadata>)) {
auto obj = std::any_cast<otio::SerializableObject::Retainer<otio::SerializableObjectWithMetadata>>(value);
type_name = Format("%s.%d", obj->schema_name().c_str(), obj->schema_version());
string_val = obj->name();
selectable = &*obj;
}
else if (type == typeid(otio::SerializableObject::Retainer<otio::SerializableObject>)) {
auto obj = std::any_cast<otio::SerializableObject::Retainer<otio::SerializableObject>>(value);
type_name = Format("%s.%d", obj->schema_name().c_str(), obj->schema_version());
selectable = &*obj;
}
// TODO: Handle these types also?
// TimeRange
// TimeTransform
// void
// char const *
// Imath::V2d
// Imath::Box2d
// SerializableObject::Retainer
ImGui::TableNextRow();
ImGui::TableNextColumn();
ImGui::TreeNodeEx(
key.c_str(),
ImGuiTreeNodeFlags_Leaf |
//ImGuiTreeNodeFlags_Bullet |
ImGuiTreeNodeFlags_NoTreePushOnOpen
| ImGuiTreeNodeFlags_SpanFullWidth | 0);
ImGui::TableNextColumn();
if (selectable != nullptr) {
ImGui::PushID(selectable);
if (ImGui::Button(string_val.c_str())) {
SelectObject(selectable);
}
ImGui::PopID();
}else{
ImGui::TextUnformatted(string_val.c_str());
}
ImGui::TableNextColumn();
ImGui::TextUnformatted(type_name.c_str());
}
void DrawMetadataRows(otio::AnyDictionary& metadata) {
for (auto& pair : metadata) {
const auto& key = pair.first;
auto& val = pair.second;
DrawMetadataRow(key, val);
}
}
void DrawMetadataSubtree(std::string key, otio::AnyDictionary& metadata) {
ImGui::TableNextRow();
ImGui::TableNextColumn();
bool open = ImGui::TreeNodeEx(
key.c_str(),
ImGuiTreeNodeFlags_DefaultOpen | ImGuiTreeNodeFlags_SpanFullWidth);
ImGui::TableNextColumn();
ImGui::TextDisabled("");
ImGui::TableNextColumn();
ImGui::TextDisabled("");
if (open) {
DrawMetadataRows(metadata);
ImGui::TreePop();
}
}
void DrawMetadataArray(std::string key, otio::AnyVector& vector) {
ImGui::TableNextRow();
ImGui::TableNextColumn();
bool open = ImGui::TreeNodeEx(
key.c_str(),
ImGuiTreeNodeFlags_DefaultOpen | ImGuiTreeNodeFlags_SpanFullWidth);
ImGui::TableNextColumn();
ImGui::TextDisabled("");
ImGui::TableNextColumn();
ImGui::TextDisabled("");
if (open) {
for (int i = 0; i < vector.size(); i++) {
DrawMetadataRow(Format("[%d]", i), vector[i]);
}
ImGui::TreePop();
}
}
void DrawMetadataTable(otio::AnyDictionary& metadata) {
static ImGuiTableFlags flags = ImGuiTableFlags_BordersV | ImGuiTableFlags_BordersOuterH
| ImGuiTableFlags_Resizable | ImGuiTableFlags_RowBg
| ImGuiTableFlags_NoBordersInBody | ImGuiTableFlags_Hideable;
if (ImGui::BeginTable("Metadata", 3, flags)) {
ImGui::TableSetupColumn("Key", ImGuiTableColumnFlags_NoHide);
ImGui::TableSetupColumn("Value");
ImGui::TableSetupColumn("Type");
ImGui::TableHeadersRow();
DrawMetadataRows(metadata);
ImGui::EndTable();
}
}
void DrawLinearTimeWarp(otio::LinearTimeWarp* timewarp, otio::Item* item) {
auto item_range = item->trimmed_range();
auto time_scalar = timewarp->time_scalar();
auto media_start = item_range.start_time();
auto media_duration = otio::RationalTime(
item_range.duration().value() * time_scalar,
item_range.duration().rate());
auto media_range = otio::TimeRange(media_start, media_duration);
// Special case for reverse timewarp
// TODO: Test to see if this works the way real NLEs handle reverse
// TODO: Specifically at -0.25 do you get the first 25% of media or the last?
if (time_scalar < 0.0f) {
// Reminder: media_duration is already negative
media_range = otio::TimeRange(media_start - media_duration, media_duration);
}
// x = output in clip/item time
// y = input in media time
ImPlotPoint control_points[2] {
ImPlotPoint(0, media_range.start_time().to_seconds()),
ImPlotPoint(
item_range.duration().to_seconds(),
media_range.end_time_exclusive().to_seconds())
};
ImPlotPoint* start = &control_points[0];
ImPlotPoint* end = &control_points[1];
// Helpful when debugging this code...
// ImGui::Text("Start: %f, %f", start->x, start->y);
// ImGui::Text("End: %f, %f", end->x, end->y);
// ImGui::Text("Duration: %f", media_range.duration().to_seconds());
const float line_width = 2;
const float knot_radius = 4;
const ImColor line_color = appTheme.colors[AppThemeCol_Item];
const ImColor knot_color = appTheme.colors[AppThemeCol_ItemSelected];
ImPlotFlags plot_flags = ImPlotFlags_NoTitle | ImPlotFlags_NoLegend | ImPlotFlags_NoInputs
| ImPlotFlags_NoMenus | ImPlotFlags_NoBoxSelect | ImPlotFlags_NoChild
| ImPlotFlags_NoFrame | ImPlotFlags_Equal | ImPlotFlags_None;
ImPlotDragToolFlags drag_flags = ImPlotDragToolFlags_NoInputs
| ImPlotDragToolFlags_None;
ImPlotAxisFlags ax_flags = ImPlotAxisFlags_Lock | ImPlotAxisFlags_None;
if (ImPlot::BeginPlot("##LinearTimeWarp", ImVec2(-1, 0), plot_flags)) {
ImPlot::SetupAxes("Output", "Media", ax_flags, ax_flags);
ImPlot::SetupAxesLimits(
fmin(start->x, end->x),
fmax(start->x, end->x),
fmin(start->y, end->y),
fmax(start->y, end->y),
ImGuiCond_Always);
ImPlot::SetNextLineStyle(line_color, line_width);
ImPlot::PlotLine(
"##Line",
&start->x,
&start->y,
2,
0,
0,
sizeof(ImPlotPoint));
// start handle
ImPlot::SetNextLineStyle(knot_color);
if (ImPlot::DragPoint(
0,
&start->x,
&start->y,
ImVec4(0, 0.9f, 0, 1),
knot_radius,
drag_flags)) {
;
}
// end handle
ImPlot::SetNextLineStyle(knot_color);
if (ImPlot::DragPoint(
3,
&end->x,
&end->y,
ImVec4(0, 0.9f, 0, 1),
knot_radius,
drag_flags)) {
;
}
ImPlot::EndPlot();
}
}
void DrawInspector() {
auto selected_object = appState.selected_object;
auto selected_context = appState.selected_context;
auto playhead = appState.playhead;
if (!selected_object) {
ImGui::Text("Nothing selected.");
return;
}
// This temporary variable is used only for a moment to convert
// between the datatypes that OTIO uses vs the one that ImGui widget uses.
char tmp_str[1000];
// If the selected Item has effects, lets show them in-line
// so the user doesn't have to click on each one separately
std::vector<otio::SerializableObject::Retainer<otio::Effect>> effects;
// SerializableObjectWithMetadata
if (const auto& obj = dynamic_cast<otio::SerializableObjectWithMetadata*>(
selected_object)) {
snprintf(tmp_str, sizeof(tmp_str), "%s", obj->name().c_str());
if (ImGui::InputText("Name", tmp_str, sizeof(tmp_str))) {
obj->set_name(tmp_str);
}
}
// SerializableObject (everything)
DrawNonEditableTextField(
"Schema",
"%s.%d",
selected_object->schema_name().c_str(),
selected_object->schema_version());
// Timeline
if (const auto& timeline = dynamic_cast<otio::Timeline*>(selected_object)) {
// Since global_start_time is optional, default to 0
// but take care not to *set* the value unless the user changes it.
auto rate = timeline->global_start_time().value_or(playhead).rate();
auto global_start_time = timeline->global_start_time().value_or(otio::RationalTime(0, rate));
// don't allow negative duration - but 0 is okay
if (DrawRationalTime("Global Start", &global_start_time, true)) {
timeline->set_global_start_time(global_start_time);
DetectPlayheadLimits();
}
}
// Item
if (const auto& item = dynamic_cast<otio::Item*>(selected_object)) {
bool is_gap = dynamic_cast<otio::Gap*>(selected_object);
if (!is_gap) {
auto item_color = GetItemColor(item);
item_color = DrawColorChooser(item_color);
if (item_color != "") {
SetItemColor(item, item_color);
}
}
auto trimmed_range = item->trimmed_range();
if (DrawTimeRange("Trimmed Range", &trimmed_range, true)) {
item->set_source_range(trimmed_range);
}
// Grab the effects list so we can display it later
effects = item->effects();
}
// Composition
if (const auto& comp = dynamic_cast<otio::Composition*>(selected_object)) {
DrawNonEditableTextField("Children", "%ld", comp->children().size());
}
// Transition
if (const auto& transition = dynamic_cast<otio::Transition*>(selected_object)) {
auto in_offset = transition->in_offset();
if (DrawRationalTime("In Offset", &in_offset, false)) {
transition->set_in_offset(in_offset);
}
auto out_offset = transition->out_offset();
if (DrawRationalTime("Out Offset", &out_offset, false)) {
transition->set_out_offset(out_offset);
}
DrawNonEditableTextField(
"Duration",
"%s",
FormattedStringFromTime(transition->duration()).c_str());
}
// Effects - either 1 selected, or a list of effects
auto effect_context = selected_context;
if (const auto& effect = dynamic_cast<otio::Effect*>(selected_object)) {
// Just one
effects.push_back(effect);
} else {
// A list of effects inside this object
effect_context = selected_object;
}
for (const auto effect : effects) {
ImGui::Text("Effect Name: %s", effect->effect_name().c_str());
if (const auto& timewarp = dynamic_cast<otio::LinearTimeWarp*>(effect.value)) {
float val = timewarp->time_scalar();
if (ImGui::DragFloat("Time Scale", &val, 0.01, -FLT_MAX, FLT_MAX)) {
timewarp->set_time_scalar(val);
}
if (const auto& item = dynamic_cast<otio::Item*>(effect_context)) {
DrawLinearTimeWarp(timewarp, item);
}
}
}
// Marker
if (const auto& marker = dynamic_cast<otio::Marker*>(selected_object)) {
auto rate = marker->marked_range().start_time().rate();
auto color_name = DrawColorChooser(marker->color());
if (color_name != "") {
marker->set_color(color_name);
}
ImGui::SameLine();
ImGui::PushStyleColor(ImGuiCol_Text, UIColorFromName(marker->color()));
ImGui::TextUnformatted("\xef\x80\xab");
ImGui::PopStyleColor();
auto marked_range = marker->marked_range();
if (DrawTimeRange("Marked Range", &marked_range, false)) {
marker->set_marked_range(marked_range);
}
}
// Track
if (const auto& track = dynamic_cast<otio::Track*>(selected_object)) {
DrawNonEditableTextField("Kind", "%s", track->kind().c_str());
}
// SerializableObjectWithMetadata
if (const auto& obj = dynamic_cast<otio::SerializableObjectWithMetadata*>(
selected_object)) {
auto& metadata = obj->metadata();
ImGui::TextUnformatted("Metadata:");
DrawMetadataTable(metadata);
}
}
void DrawMarkersInspector() {
// This temporary variable is used only for a moment to convert
// between the datatypes that OTIO uses vs the one that ImGui widget uses.
char tmp_str[1000];
typedef std::pair<otio::SerializableObject::Retainer<otio::Marker>, otio::SerializableObject::Retainer<otio::Item>> marker_parent_pair;
std::vector<marker_parent_pair> pairs;
auto root = appState.timeline->tracks();
auto global_start = appState.timeline->global_start_time().value_or(otio::RationalTime());
for (const auto& marker : root->markers()) {
pairs.push_back(marker_parent_pair(marker, root));
}
for (const auto& child :
appState.timeline->tracks()->find_children())
{
if (const auto& item = dynamic_cast<otio::Item*>(&*child))
{
for (const auto& marker : item->markers()) {
pairs.push_back(marker_parent_pair(marker, item));
}
}
}
auto selectable_flags = ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_AllowItemOverlap;
if (ImGui::BeginTable("Markers",
5,
// ImGuiTableFlags_Sortable |
ImGuiTableFlags_NoSavedSettings |
ImGuiTableFlags_Resizable |
ImGuiTableFlags_Reorderable |
ImGuiTableFlags_Hideable))
{
ImGui::TableSetupColumn("Local Time", ImGuiTableColumnFlags_DefaultHide | ImGuiTableColumnFlags_WidthFixed);
ImGui::TableSetupColumn("Global Time", ImGuiTableColumnFlags_WidthFixed);
ImGui::TableSetupColumn("Duration", ImGuiTableColumnFlags_DefaultHide | ImGuiTableColumnFlags_WidthFixed);
ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthStretch);
ImGui::TableSetupColumn("Item", ImGuiTableColumnFlags_WidthStretch);
ImGui::TableHeadersRow();
for (const auto& pair : pairs)
{
auto marker = pair.first;
auto parent = pair.second;
ImGui::PushID(marker.value);
ImGui::TableNextRow();
// Local Time
ImGui::TableNextColumn();
auto range = marker->marked_range();
ImGui::TextUnformatted(TimecodeStringFromTime(range.start_time()).c_str());
// Global Time
ImGui::TableNextColumn();
auto global_time = parent->transformed_time(range.start_time(), root) + global_start;
// Make this row selectable & jump the playhead when clicked
auto is_selected =
(appState.selected_object == marker) ||
(appState.selected_object == parent);
if (ImGui::Selectable(TimecodeStringFromTime(global_time).c_str(),
is_selected,
selectable_flags)) {
appState.playhead = global_time;
SelectObject(marker, parent);
appState.scroll_to_playhead = true;
}
// Duration
ImGui::TableNextColumn();
auto duration = range.duration();
ImGui::TextUnformatted(TimecodeStringFromTime(duration).c_str());
// Color + Name
ImGui::TableNextColumn();
ImGui::PushStyleColor(ImGuiCol_Text, UIColorFromName(marker->color()));
ImGui::TextUnformatted("\xef\x80\xab");
ImGui::PopStyleColor();
ImGui::SameLine();
ImGui::TextUnformatted(marker->name().c_str());
// Item
ImGui::TableNextColumn();
ImGui::TextUnformatted(parent->name().c_str());
ImGui::PopID();
}
}
ImGui::EndTable();
}
void DrawEffectsInspector() {
typedef std::pair<otio::SerializableObject::Retainer<otio::Effect>, otio::SerializableObject::Retainer<otio::Item>> effect_parent_pair;
std::vector<effect_parent_pair> pairs;
auto root = appState.timeline->tracks();
auto global_start = appState.timeline->global_start_time().value_or(otio::RationalTime());
for (const auto& effect : root->effects()) {
pairs.push_back(effect_parent_pair(effect, root));
}
for (const auto& child :
appState.timeline->tracks()->find_children())
{
if (const auto& item = dynamic_cast<otio::Item*>(&*child))
{
for (const auto& effect : item->effects()) {
pairs.push_back(effect_parent_pair(effect, item));
}
}
}
auto selectable_flags = ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_AllowItemOverlap;
if (ImGui::BeginTable("Effects",
4,
// ImGuiTableFlags_Sortable |
ImGuiTableFlags_NoSavedSettings |
ImGuiTableFlags_Resizable |
ImGuiTableFlags_Reorderable |
ImGuiTableFlags_Hideable))
{
ImGui::TableSetupColumn("Global Time", ImGuiTableColumnFlags_WidthFixed);
ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthStretch);
ImGui::TableSetupColumn("Effect", ImGuiTableColumnFlags_WidthStretch);
ImGui::TableSetupColumn("Item", ImGuiTableColumnFlags_WidthStretch);
ImGui::TableHeadersRow();
for (const auto& pair : pairs)
{
auto effect = pair.first;
auto parent = pair.second;
ImGui::PushID(effect.value);
ImGui::TableNextRow();
// Global Time
ImGui::TableNextColumn();
auto range = parent->trimmed_range();
auto global_time = parent->transformed_time(range.start_time(), root) + global_start;
// Make this row selectable & jump the playhead when clicked
auto is_selected =
(appState.selected_object == effect) ||
(appState.selected_object == parent);
if (ImGui::Selectable(TimecodeStringFromTime(global_time).c_str(),
is_selected,
selectable_flags)) {
printf("DEBUG: clicked %s\n", TimecodeStringFromTime(global_time).c_str());
appState.playhead = global_time;
SelectObject(effect, parent);
appState.scroll_to_playhead = true;
}
// Name
ImGui::TableNextColumn();
ImGui::TextUnformatted(effect->name().c_str());
// Effect
ImGui::TableNextColumn();
ImGui::TextUnformatted(effect->effect_name().c_str());
// Item
ImGui::TableNextColumn();
ImGui::TextUnformatted(parent->name().c_str());
ImGui::PopID();
}
}
ImGui::EndTable();
}